Java Code Examples for org.onosproject.net.flowobjective.ForwardingObjective#op()
The following examples show how to use
org.onosproject.net.flowobjective.ForwardingObjective#op() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CiscoN9kPipeliner.java From onos with Apache License 2.0 | 6 votes |
private Optional<ForwardingObjective> forwardingObjectiveWithoutCleardDef(ForwardingObjective forwardingObjective) { TrafficTreatment treatment = trafficTreatmentWithoutClearedDeffered(forwardingObjective.treatment()); DefaultForwardingObjective.Builder foBuilder = (DefaultForwardingObjective.Builder) forwardingObjective.copy(); foBuilder.withTreatment(treatment); switch (forwardingObjective.op()) { case ADD: return Optional.of(foBuilder.add(forwardingObjective.context().orElse(null))); case REMOVE: return Optional.of(foBuilder.remove(forwardingObjective.context().orElse(null))); default: log.warn("Driver does not support other operations for forwarding objective"); return Optional.empty(); } }
Example 2
Source File: NokiaOltPipeline.java From onos with Apache License 2.0 | 6 votes |
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); }
Example 3
Source File: JuniperQfx5100Pipeliner.java From onos with Apache License 2.0 | 6 votes |
private Optional<ForwardingObjective> forwardingObjectiveWithoutCleardDef(ForwardingObjective forwardingObjective) { TrafficTreatment treatment = trafficTreatmentWithoutCleardDeffered(forwardingObjective.treatment()); DefaultForwardingObjective.Builder foBuilder = (DefaultForwardingObjective.Builder) forwardingObjective.copy(); foBuilder.withTreatment(treatment); switch (forwardingObjective.op()) { case ADD: return Optional.of(foBuilder.add(forwardingObjective.context().orElse(null))); case REMOVE: return Optional.of(foBuilder.remove(forwardingObjective.context().orElse(null))); default: log.warn("Driver Not support other operations for forwarding objective"); return Optional.empty(); } }
Example 4
Source File: AristaPipeliner.java From onos with Apache License 2.0 | 6 votes |
private Optional<ForwardingObjective> forwardingObjectiveWithoutCleardDef(ForwardingObjective forwardingObjective) { TrafficTreatment treatment = trafficTreatmentWithoutClearedDeffered(forwardingObjective.treatment()); DefaultForwardingObjective.Builder foBuilder = (DefaultForwardingObjective.Builder) forwardingObjective.copy(); foBuilder.withTreatment(treatment); switch (forwardingObjective.op()) { case ADD: return Optional.of(foBuilder.add(forwardingObjective.context().orElse(null))); case REMOVE: return Optional.of(foBuilder.remove(forwardingObjective.context().orElse(null))); default: log.warn("Driver Not support other operations for forwarding objective"); return Optional.empty(); } }
Example 5
Source File: AbstractCorsaPipeline.java From onos with Apache License 2.0 | 6 votes |
private ForwardingObjective preProcessVersatile(ForwardingObjective fwd) { // The Corsa devices don't support the clear deferred actions // so for now we have to filter this instruction for the fwd // objectives sent by the Packet Manager before to create the // flow rule if (fwd.treatment().clearedDeferred()) { // First we create a new treatment without the unsupported action TrafficTreatment.Builder noClearTreatment = DefaultTrafficTreatment.builder(); fwd.treatment().allInstructions().forEach(noClearTreatment::add); // Then we create a new forwarding objective without the unsupported action ForwardingObjective.Builder noClearFwd = DefaultForwardingObjective.builder(fwd); noClearFwd.withTreatment(noClearTreatment.build()); // According to the operation we substitute fwd with the correct objective switch (fwd.op()) { case ADD: fwd = noClearFwd.add(fwd.context().orElse(null)); break; case REMOVE: fwd = noClearFwd.remove(fwd.context().orElse(null)); break; default: log.warn("Unknown operation {}", fwd.op()); } } return fwd; }
Example 6
Source File: ForwardTable.java From onos with Apache License 2.0 | 6 votes |
public ForwardUpdateTable updateForward(ForwardingObjective forwardingObjective) { ForwardUpdateTable updates = new ForwardUpdateTable(); switch (forwardingObjective.op()) { case ADD: this.forwardMap.put(forwardingObjectiveHash(forwardingObjective), forwardingObjective); this.generatedParentForwardingObjectiveMap .put(forwardingObjectiveHash(forwardingObjective), new ArrayList<>()); updates.addObjectives.add(forwardingObjective); break; case REMOVE: if (this.forwardMap.remove(forwardingObjectiveHash(forwardingObjective)) != null) { updates.removeObjectives.add(forwardingObjective); } break; default: break; } return updates; }
Example 7
Source File: CorsaL2OverlayPipeline.java From onos with Apache License 2.0 | 5 votes |
@Override public void forward(ForwardingObjective fwd) { // The Corsa devices don't support the clear deferred actions // so for now we have to filter this instruction for the fwd // objectives sent by the Packet Manager before to create the // flow rule if (fwd.flag() == VERSATILE && fwd.treatment().clearedDeferred()) { // First we create a new treatment without the unsupported action TrafficTreatment.Builder noClearTreatment = DefaultTrafficTreatment.builder(); fwd.treatment().allInstructions().forEach(noClearTreatment::add); // Then we create a new forwarding objective without the unsupported action ForwardingObjective.Builder noClearFwd = DefaultForwardingObjective.builder(fwd); noClearFwd.withTreatment(noClearTreatment.build()); // According to the operation we substitute fwd with the correct objective switch (fwd.op()) { case ADD: fwd = noClearFwd.add(fwd.context().orElse(null)); break; case REMOVE: fwd = noClearFwd.remove(fwd.context().orElse(null)); break; default: log.warn("Unknown operation {}", fwd.op()); return; } } // Finally we send to the DefaultSingleTablePipeline for the real processing super.forward(fwd); }
Example 8
Source File: BasicPipelinerImpl.java From onos with Apache License 2.0 | 5 votes |
@Override public void forward(ForwardingObjective obj) { if (obj.treatment() == null) { obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED)); } // Simply create an equivalent FlowRule for table 0. final FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() .forTable(INGRESS_TABLE0_CONTROL_TABLE0) .forDevice(deviceId) .withSelector(obj.selector()) .fromApp(obj.appId()) .withPriority(obj.priority()) .withTreatment(obj.treatment()); if (obj.permanent()) { ruleBuilder.makePermanent(); } else { ruleBuilder.makeTemporary(obj.timeout()); } switch (obj.op()) { case ADD: flowRuleService.applyFlowRules(ruleBuilder.build()); break; case REMOVE: flowRuleService.removeFlowRules(ruleBuilder.build()); break; default: log.warn("Unknown operation {}", obj.op()); } obj.context().ifPresent(c -> c.onSuccess(obj)); }
Example 9
Source File: VirtualNetworkFlowObjectiveManager.java From onos with Apache License 2.0 | 5 votes |
@Override public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) { if (forwardingObjective.nextId() == null || forwardingObjective.op() == Objective.Operation.REMOVE || flowObjectiveStore.getNextGroup(forwardingObjective.nextId()) != null || !queueFwdObjective(deviceId, forwardingObjective)) { // fast path executorService.execute(new ObjectiveInstaller(deviceId, forwardingObjective)); } }
Example 10
Source File: MockFlowObjectiveService.java From onos with Apache License 2.0 | 5 votes |
@Override public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) { TrafficSelector selector = forwardingObjective.selector(); TrafficTreatment treatment = nextTable.get(forwardingObjective.nextId()); MacAddress macAddress = ((EthCriterion) selector.getCriterion(Criterion.Type.ETH_DST)).mac(); VlanId vlanId = ((VlanIdCriterion) selector.getCriterion(Criterion.Type.VLAN_VID)).vlanId(); boolean popVlan = treatment.allInstructions().stream() .filter(instruction -> instruction.type().equals(Instruction.Type.L2MODIFICATION)) .anyMatch(instruction -> ((L2ModificationInstruction) instruction).subtype() .equals(L2ModificationInstruction.L2SubType.VLAN_POP)); PortNumber portNumber = treatment.allInstructions().stream() .filter(instruction -> instruction.type().equals(Instruction.Type.OUTPUT)) .map(instruction -> ((Instructions.OutputInstruction) instruction).port()).findFirst().orElse(null); if (portNumber == null) { throw new IllegalArgumentException(); } Objective.Operation op = forwardingObjective.op(); MockBridgingTableKey btKey = new MockBridgingTableKey(deviceId, macAddress, vlanId); MockBridgingTableValue btValue = new MockBridgingTableValue(popVlan, portNumber); if (op.equals(Objective.Operation.ADD)) { bridgingTable.put(btKey, btValue); forwardingObjective.context().ifPresent(context -> context.onSuccess(forwardingObjective)); } else if (op.equals(Objective.Operation.REMOVE)) { bridgingTable.remove(btKey, btValue); forwardingObjective.context().ifPresent(context -> context.onSuccess(forwardingObjective)); } else { forwardingObjective.context().ifPresent(context -> context.onError(forwardingObjective, ObjectiveError.UNKNOWN)); throw new IllegalArgumentException(); } }
Example 11
Source File: PipelinerImpl.java From ngsdn-tutorial with Apache License 2.0 | 4 votes |
@Override public void forward(ForwardingObjective obj) { if (obj.treatment() == null) { obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED)); } // Whether this objective specifies an OUTPUT:CONTROLLER instruction. final boolean hasCloneToCpuAction = obj.treatment() .allInstructions().stream() .filter(i -> i.type().equals(OUTPUT)) .map(i -> (Instructions.OutputInstruction) i) .anyMatch(i -> i.port().equals(PortNumber.CONTROLLER)); if (!hasCloneToCpuAction) { // We support only objectives for clone to CPU behaviours (e.g. for // host and link discovery) obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED)); } // Create an equivalent FlowRule with same selector and clone_to_cpu action. final PiAction cloneToCpuAction = PiAction.builder() .withId(PiActionId.of(CLONE_TO_CPU)) .build(); final FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() .forTable(PiTableId.of(ACL_TABLE)) .forDevice(deviceId) .withSelector(obj.selector()) .fromApp(obj.appId()) .withPriority(obj.priority()) .withTreatment(DefaultTrafficTreatment.builder() .piTableAction(cloneToCpuAction).build()); if (obj.permanent()) { ruleBuilder.makePermanent(); } else { ruleBuilder.makeTemporary(obj.timeout()); } final GroupDescription cloneGroup = Utils.buildCloneGroup( obj.appId(), deviceId, CPU_CLONE_SESSION_ID, // Ports where to clone the packet. // Just controller in this case. Collections.singleton(PortNumber.CONTROLLER)); switch (obj.op()) { case ADD: flowRuleService.applyFlowRules(ruleBuilder.build()); groupService.addGroup(cloneGroup); break; case REMOVE: flowRuleService.removeFlowRules(ruleBuilder.build()); groupService.removeGroup(deviceId, cloneGroup.appCookie(), obj.appId()); break; default: log.warn("Unknown operation {}", obj.op()); } obj.context().ifPresent(c -> c.onSuccess(obj)); }
Example 12
Source File: PipelinerImpl.java From onos-p4-tutorial with Apache License 2.0 | 4 votes |
@Override public void forward(ForwardingObjective obj) { if (obj.treatment() == null) { obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED)); } // Whether this objective specifies an OUTPUT:CONTROLLER instruction. final boolean hasCloneToCpuAction = obj.treatment() .allInstructions().stream() .filter(i -> i.type().equals(OUTPUT)) .map(i -> (Instructions.OutputInstruction) i) .anyMatch(i -> i.port().equals(PortNumber.CONTROLLER)); if (!hasCloneToCpuAction) { // We support only objectives for clone to CPU behaviours (e.g. for // host and link discovery) obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED)); } // Create an equivalent FlowRule with same selector and clone_to_cpu action. final PiAction cloneToCpuAction = PiAction.builder() .withId(PiActionId.of(CLONE_TO_CPU)) .build(); final FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() .forTable(PiTableId.of(ACL_TABLE)) .forDevice(deviceId) .withSelector(obj.selector()) .fromApp(obj.appId()) .withPriority(obj.priority()) .withTreatment(DefaultTrafficTreatment.builder() .piTableAction(cloneToCpuAction).build()); if (obj.permanent()) { ruleBuilder.makePermanent(); } else { ruleBuilder.makeTemporary(obj.timeout()); } final GroupDescription cloneGroup = Utils.buildCloneGroup( obj.appId(), deviceId, CPU_CLONE_SESSION_ID, // Ports where to clone the packet. // Just controller in this case. Collections.singleton(PortNumber.CONTROLLER)); switch (obj.op()) { case ADD: flowRuleService.applyFlowRules(ruleBuilder.build()); groupService.addGroup(cloneGroup); break; case REMOVE: flowRuleService.removeFlowRules(ruleBuilder.build()); groupService.removeGroup(deviceId, cloneGroup.appCookie(), obj.appId()); break; default: log.warn("Unknown operation {}", obj.op()); } obj.context().ifPresent(c -> c.onSuccess(obj)); }
Example 13
Source File: PipelinerImpl.java From onos-p4-tutorial with Apache License 2.0 | 4 votes |
@Override public void forward(ForwardingObjective obj) { if (obj.treatment() == null) { obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED)); } // Whether this objective specifies an OUTPUT:CONTROLLER instruction. final boolean hasCloneToCpuAction = obj.treatment() .allInstructions().stream() .filter(i -> i.type().equals(OUTPUT)) .map(i -> (Instructions.OutputInstruction) i) .anyMatch(i -> i.port().equals(PortNumber.CONTROLLER)); if (!hasCloneToCpuAction) { // We support only objectives for clone to CPU behaviours (e.g. for // host and link discovery) obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED)); } // Create an equivalent FlowRule with same selector and clone_to_cpu action. final PiAction cloneToCpuAction = PiAction.builder() .withId(PiActionId.of(CLONE_TO_CPU)) .build(); final FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() .forTable(PiTableId.of(ACL_TABLE)) .forDevice(deviceId) .withSelector(obj.selector()) .fromApp(obj.appId()) .withPriority(obj.priority()) .withTreatment(DefaultTrafficTreatment.builder() .piTableAction(cloneToCpuAction).build()); if (obj.permanent()) { ruleBuilder.makePermanent(); } else { ruleBuilder.makeTemporary(obj.timeout()); } final GroupDescription cloneGroup = Utils.buildCloneGroup( obj.appId(), deviceId, CPU_CLONE_SESSION_ID, // Ports where to clone the packet. // Just controller in this case. Collections.singleton(PortNumber.CONTROLLER)); switch (obj.op()) { case ADD: flowRuleService.applyFlowRules(ruleBuilder.build()); groupService.addGroup(cloneGroup); break; case REMOVE: flowRuleService.removeFlowRules(ruleBuilder.build()); groupService.removeGroup(deviceId, cloneGroup.appCookie(), obj.appId()); break; default: log.warn("Unknown operation {}", obj.op()); } obj.context().ifPresent(c -> c.onSuccess(obj)); }