synchronized void fail(DeviceId devId, Set<? extends FlowRule> failures) { hasFailed = true; pendingDevices.remove(devId); if (pendingDevices.isEmpty()) { operationsService.execute(this); } FlowRuleOperations.Builder failedOpsBuilder = FlowRuleOperations.builder(); failures.forEach(failedOpsBuilder::add); fops.callback().onError(failedOpsBuilder.build()); } }
@Override public void forward(ForwardingObjective forwardingObjective) { Collection<FlowRule> rules; FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder();
FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder();
@Override public void forward(ForwardingObjective fwd) { Collection<FlowRule> rules; FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder();
@Override public void forward(ForwardingObjective fwd) { Collection<FlowRule> rules; FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder();
@Override public void applyFlowRules(FlowRule... flowRules) { checkPermission(FLOWRULE_WRITE); FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); for (FlowRule flowRule : flowRules) { builder.add(flowRule); } apply(builder.build()); }
@Override public void removeFlowRules(FlowRule... flowRules) { checkPermission(FLOWRULE_WRITE); FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); for (FlowRule flowRule : flowRules) { builder.remove(flowRule); } apply(builder.build()); }
private void applyRules(boolean install, FlowRule flowRule) { FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder(); flowOpsBuilder = install ? flowOpsBuilder.add(flowRule) : flowOpsBuilder.remove(flowRule); flowRuleService.apply(flowOpsBuilder.build(new FlowRuleOperationsContext() { @Override public void onSuccess(FlowRuleOperations ops) { log.debug("Provisioned vni or forwarding table"); } @Override public void onError(FlowRuleOperations ops) { log.debug("Failed to privision vni or forwarding table"); } })); }
private void applyRules(boolean install, FlowRule rule) { FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); ops = install ? ops.add(rule) : ops.remove(rule); flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { @Override public void onSuccess(FlowRuleOperations ops) { log.info("ONOSW provisioned " + rule.tableId() + " table"); } @Override public void onError(FlowRuleOperations ops) { log.info("ONOSW failed to provision " + rule.tableId() + " table"); } })); }
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)); } })); }
private void applyRules(ForwardingObjective fwd, FlowRule.Builder inner, FlowRule.Builder outer) { FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); switch (fwd.op()) { case ADD: builder.add(inner.build()).add(outer.build()); break; case REMOVE: builder.remove(inner.build()).remove(outer.build()); break; case ADD_TO_EXISTING: break; case REMOVE_FROM_EXISTING: break; default: log.warn("Unknown forwarding operation: {}", fwd.op()); } applyFlowRules(builder, fwd); }
private void buildAndApplyRule(FilteringObjective filter, TrafficSelector selector, TrafficTreatment treatment) { FlowRule rule = DefaultFlowRule.builder() .fromApp(filter.appId()) .forDevice(deviceId) .forTable(0) .makePermanent() .withSelector(selector) .withTreatment(treatment) .withPriority(filter.priority()) .build(); FlowRuleOperations.Builder opsBuilder = FlowRuleOperations.builder(); switch (filter.type()) { case PERMIT: opsBuilder.add(rule); break; case DENY: opsBuilder.remove(rule); break; default: log.warn("Unknown filter type : {}", filter.type()); fail(filter, ObjectiveError.UNSUPPORTED); } applyFlowRules(opsBuilder, filter); }
protected void processIpTable() { //table miss entry FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(ACL_TABLE); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(LOWEST_PRIORITY) .fromApp(driverId) .makePermanent() .forTable(UNICAST_ROUTING_TABLE).build(); ops = ops.add(rule); flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { @Override public void onSuccess(FlowRuleOperations ops) { log.info("Initialized IP table"); } @Override public void onError(FlowRuleOperations ops) { log.info("Failed to initialize unicast IP table"); } })); }
private void processAclTable(boolean install) { TrafficSelector.Builder selector; TrafficTreatment.Builder treatment; FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); FlowRule rule; //Drop rule selector = DefaultTrafficSelector.builder(); treatment = DefaultTrafficTreatment.builder(); rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(DROP_PRIORITY) .fromApp(appId) .makePermanent() .forTable(ACL_TABLE).build(); ops = install ? ops.add(rule) : ops.remove(rule); flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { @Override public void onSuccess(FlowRuleOperations ops) { log.info("Provisioned ACL table"); } @Override public void onError(FlowRuleOperations ops) { log.info("Failed to provision ACL table"); } })); }
protected void processMulticastIpTable() { //table miss entry FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(ACL_TABLE); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(LOWEST_PRIORITY) .fromApp(driverId) .makePermanent() .forTable(MULTICAST_ROUTING_TABLE).build(); ops = ops.add(rule); flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { @Override public void onSuccess(FlowRuleOperations ops) { log.info("Initialized multicast IP table"); } @Override public void onError(FlowRuleOperations ops) { log.info("Failed to initialize multicast IP table"); } })); }
protected void processPortTable() { FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(VLAN_TABLE); FlowRule tmisse = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(LOWEST_PRIORITY) .fromApp(driverId) .makePermanent() .forTable(PORT_TABLE).build(); ops = ops.add(tmisse); flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { @Override public void onSuccess(FlowRuleOperations ops) { log.info("Initialized port table"); } @Override public void onError(FlowRuleOperations ops) { log.info("Failed to initialize port table"); } })); }
protected void processAclTable() { //table miss entry - catch all to executed action-set FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); selector = DefaultTrafficSelector.builder(); treatment = DefaultTrafficTreatment.builder(); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(LOWEST_PRIORITY) .fromApp(driverId) .makePermanent() .forTable(ACL_TABLE).build(); ops = ops.add(rule); flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { @Override public void onSuccess(FlowRuleOperations ops) { log.info("Initialized Acl table"); } @Override public void onError(FlowRuleOperations ops) { log.info("Failed to initialize Acl table"); } })); }
private void processBridgingTable() { //table miss entry FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); selector = DefaultTrafficSelector.builder(); treatment = DefaultTrafficTreatment.builder(); treatment.transition(ACL_TABLE); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(LOWEST_PRIORITY) .fromApp(driverId) .makePermanent() .forTable(BRIDGING_TABLE).build(); ops = ops.add(rule); flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { @Override public void onSuccess(FlowRuleOperations ops) { log.info("Initialized Bridging table"); } @Override public void onError(FlowRuleOperations ops) { log.info("Failed to initialize Bridging table"); } })); }
protected void processTmacTable() { //table miss entry FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); selector = DefaultTrafficSelector.builder(); treatment = DefaultTrafficTreatment.builder(); treatment.transition(BRIDGING_TABLE); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(LOWEST_PRIORITY) .fromApp(driverId) .makePermanent() .forTable(TMAC_TABLE).build(); ops = ops.add(rule); flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { @Override public void onSuccess(FlowRuleOperations ops) { log.info("Initialized tmac table"); } @Override public void onError(FlowRuleOperations ops) { log.info("Failed to initialize tmac table"); } })); }