public ObjectNode encode(Objective objective, CodecContext context) { checkNotNull(objective, "Objective cannot be null"); ObjectNode result = context.mapper().createObjectNode() .put(ID, objective.id()) .put(OPERATION, objective.op().toString()) .put(PERMANENT, String.valueOf(objective.permanent())) .put(PRIORITY, objective.priority()) .put(TIMEOUT, objective.timeout()); if (objective.appId() != null) { result.put(APP_ID, objective.appId().toString()); } return result; }
@Override public void onSuccess(FlowRuleOperations ops) { objective.context().ifPresent(context -> context.onSuccess(objective)); }
int priority = obj.priority(); LogLevel logLevel = (obj.op() == Objective.Operation.VERIFY) ? LogLevel.TRACE : LogLevel.DEBUG; Tools.log(log, logLevel, "Dequeue {}", obj); if (error != null) { Set<PendingFlowObjective> removedForwards = pendingForwards.remove(obj.id()); List<PendingFlowObjective> removedNexts = pendingNexts.remove(obj.id()); .forEach(pendingObj -> pendingObj.context().ifPresent(c -> c.onError(pendingObj, error))); .forEach(pendingObj -> pendingObj.context().ifPresent(c -> c.onError(pendingObj, error))); NextObjQueueKey k = new NextObjQueueKey(deviceId, obj.id()); if (!Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) { nextObjQueueHead.invalidate(k);
int priority = obj.priority(); LogLevel logLevel = (obj.op() == Objective.Operation.VERIFY) ? LogLevel.TRACE : LogLevel.DEBUG; Tools.log(log, logLevel, "Enqueue {}", obj); queueSize = fwdObjQueue.get(k).size(); } else if (obj instanceof NextObjective) { NextObjQueueKey k = new NextObjQueueKey(deviceId, obj.id()); nextObjQueue.put(k, obj); queueSize = nextObjQueue.get(k).size();
Objective.Builder objBuilder = originalObjective.copy(); Optional<ObjectiveContext> originalContext = originalObjective.context(); ObjectiveContext context = new InOrderObjectiveContext(deviceId, originalContext.orElse(null)); switch (originalObjective.op()) { case ADD: objective = objBuilder.add(context); break; default: log.error("Unknown flow objecitve operation {}", originalObjective.op()); return;
for (PendingFlowObjective pf : pfwd) { pend.append("\n FwdId: ") .append(String.format("%11s", pf.flowObjective().id())) .append(", DeviceId: ") .append(pf.deviceId()) for (PendingFlowObjective pn : pnext) { pend.append("\n NextOp: ") .append(pn.flowObjective().op()) .append(", DeviceId: ") .append(pn.deviceId())
@Override public void run() { try { Pipeliner pipeliner = getDevicePipeliner(deviceId); if (pipeliner != null) { if (objective instanceof NextObjective) { nextToDevice.put(objective.id(), deviceId); pipeliner.next((NextObjective) objective); } else if (objective instanceof ForwardingObjective) { pipeliner.forward((ForwardingObjective) objective); } else { pipeliner.filter((FilteringObjective) objective); } //Attempts to check if pipeliner is null for retry attempts } else if (numAttempts < INSTALL_RETRY_ATTEMPTS) { Thread.sleep(INSTALL_RETRY_INTERVAL); executorService.execute(new ObjectiveInstaller(deviceId, objective, numAttempts + 1)); } else { // Otherwise we've tried a few times and failed, report an // error back to the user. objective.context().ifPresent( c -> c.onError(objective, ObjectiveError.NOPIPELINER)); } //Exception thrown } catch (Exception e) { log.warn("Exception while installing flow objective", e); } } }
if (ctx.objective.op() == Objective.Operation.ADD && ctx.objective instanceof NextObjective) { ((NextObjective.Builder) ctx.objective.copy()).addToExisting(ctx); ctx.setObjective(newObj, ctx.deviceId); ctx.increaseRetryValue(); break; case GROUPMISSING: if (ctx.objective.op() == Objective.Operation.ADD_TO_EXISTING) { NextObjective newObj = (NextObjective) ctx.objective.copy().add(ctx); ctx.setObjective(newObj, ctx.deviceId); ctx.increaseRetryValue(); flowObjectiveService.apply(ctx.deviceId, ctx.objective); } else if (ctx.objective.op() == Objective.Operation.REMOVE || ctx.objective.op() == Objective.Operation.REMOVE_FROM_EXISTING) {
private void installObjective(FlowRule.Builder ruleBuilder, Objective objective) { FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder(); switch (objective.op()) { case ADD: flowBuilder.add(ruleBuilder.build()); break; case REMOVE: flowBuilder.remove(ruleBuilder.build()); break; default: log.warn("Unknown operation {}", objective.op()); } flowRuleService.apply(flowBuilder.build(new FlowRuleOperationsContext() { @Override public void onSuccess(FlowRuleOperations ops) { objective.context().ifPresent(context -> context.onSuccess(objective)); } @Override public void onError(FlowRuleOperations ops) { objective.context() .ifPresent(context -> context.onError(objective, ObjectiveError.FLOWINSTALLATIONFAILED)); } })); }
if (nextId != null) { for (int j = 0; j < size; j++) { if (objectives.get(j).id() == nextId) { nxt = (NextObjective) objectives.get(j); break;
private FlowObjectiveInstallationContext buildObjectiveContext(Objective objective, DeviceId deviceId, Direction direction) { Objects.requireNonNull(objective); Objects.requireNonNull(deviceId); Objects.requireNonNull(direction); Objective.Builder builder = objective.copy(); FlowObjectiveInstallationContext ctx = new FlowObjectiveInstallationContext(); switch (direction) { case ADD: objective = builder.add(ctx); break; case REMOVE: objective = builder.remove(ctx); break; default: break; } ctx.setObjective(objective, deviceId); return ctx; }
/** * Submit the flow objective. Starting from this point on, the execution order is not guaranteed. * Therefore we must be certain that this method is called in-order. * * @param deviceId Device ID * @param obj Flow objective */ private void execute(DeviceId deviceId, Objective obj) { LogLevel logLevel = (obj.op() == Objective.Operation.VERIFY) ? LogLevel.TRACE : LogLevel.DEBUG; Tools.log(log, logLevel, "Submit objective installer, deviceId {}, obj {}", deviceId, obj); int priority = obj.priority(); if (obj instanceof FilteringObjective) { FilteringObjQueueKey k = new FilteringObjQueueKey(deviceId, priority, ((FilteringObjective) obj).key()); filtObjQueueHead.put(k, obj); super.filter(deviceId, (FilteringObjective) obj); } else if (obj instanceof ForwardingObjective) { ForwardingObjQueueKey k = new ForwardingObjQueueKey(deviceId, priority, ((ForwardingObjective) obj).selector()); fwdObjQueueHead.put(k, obj); super.forward(deviceId, (ForwardingObjective) obj); } else if (obj instanceof NextObjective) { NextObjQueueKey k = new NextObjQueueKey(deviceId, obj.id()); nextObjQueueHead.put(k, obj); super.next(deviceId, (NextObjective) obj); } else { log.error("Unknown flow objective instance: {}", obj.getClass().getName()); } }
@Override public void onError(FlowRuleOperations ops) { objective.context() .ifPresent(context -> context.onError(objective, ObjectiveError.FLOWINSTALLATIONFAILED)); } }));
private void pass(Objective obj) { obj.context().ifPresent(context -> context.onSuccess(obj)); }
private void fail(Objective obj, ObjectiveError error) { obj.context().ifPresent(context -> context.onError(obj, error)); }
protected static void pass(Objective obj) { obj.context().ifPresent(context -> context.onSuccess(obj)); }
private void fail(Objective obj, ObjectiveError error) { obj.context().ifPresent(context -> context.onError(obj, error)); } }
private void pass(Objective obj) { obj.context().ifPresent(context -> context.onSuccess(obj)); } }
private void pass(Objective obj) { obj.context().ifPresent(context -> context.onSuccess(obj)); }
private void fail(Objective obj, ObjectiveError error) { obj.context().ifPresent(context -> context.onError(obj, error)); }