Java Code Examples for org.onosproject.net.flow.TrafficTreatment#Builder
The following examples show how to use
org.onosproject.net.flow.TrafficTreatment#Builder .
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: OvsCorsaPipeline.java From onos with Apache License 2.0 | 6 votes |
@Override protected FlowRule.Builder processVlanFiler(FilteringObjective filt, VlanIdCriterion vlan, PortCriterion port) { log.debug("adding rule for VLAN: {}", vlan.vlanId()); TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); selector.matchVlanId(vlan.vlanId()); selector.matchInPort(port.port()); treatment.transition(ETHER_TABLE); treatment.deferred().popVlan(); return DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(CONTROLLER_PRIORITY) .makePermanent() .forTable(VLAN_TABLE); }
Example 2
Source File: CastorArpManager.java From onos with Apache License 2.0 | 6 votes |
/** * Forwards the ARP packet to the specified connect point via packet out. * * @param context The packet context */ private void forward(MessageContext context) { TrafficTreatment.Builder builder = null; Ethernet eth = context.packet(); ByteBuffer buf = ByteBuffer.wrap(eth.serialize()); IpAddress target = context.target(); String value = getMatchingConnectPoint(target); if (value != null) { ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(value); builder = DefaultTrafficTreatment.builder(); builder.setOutput(connectPoint.port()); packetService.emit(new DefaultOutboundPacket(connectPoint.deviceId(), builder.build(), buf)); } }
Example 3
Source File: K8sFlowRuleManager.java From onos with Apache License 2.0 | 6 votes |
@Override public void setUpTableMissEntry(DeviceId deviceId, int table) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.drop(); FlowRule flowRule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(DROP_PRIORITY) .fromApp(appId) .makePermanent() .forTable(table) .build(); applyRule(flowRule, true); }
Example 4
Source File: OvsCorsaPipeline.java From onos with Apache License 2.0 | 6 votes |
private void processCosTable(boolean install) { TrafficTreatment.Builder treatment = DefaultTrafficTreatment .builder() .transition(FIB_TABLE); TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(DROP_PRIORITY) .fromApp(appId) .makePermanent() .forTable(COS_MAP_TABLE).build(); processFlowRule(true, rule, "Provisioned cos table"); }
Example 5
Source File: ControlPlaneRedirectManagerTest.java From onos with Apache License 2.0 | 6 votes |
/** * Setup expectations on flowObjectiveService.next for NextObjective. * **/ private int modifyNextObjective(DeviceId deviceId, PortNumber portNumber, VlanId vlanId, boolean popVlan, boolean modifyFlag) { NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(1) .withType(NextObjective.Type.SIMPLE).fromApp(APPID); TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); if (popVlan) { ttBuilder.popVlan(); } ttBuilder.setOutput(portNumber); TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(); metabuilder.matchVlanId(vlanId); nextObjBuilder.withMeta(metabuilder.build()); nextObjBuilder.addTreatment(ttBuilder.build()); if (modifyFlag) { flowObjectiveService.next(deviceId, nextObjBuilder.add()); expectLastCall().once(); } else { flowObjectiveService.next(deviceId, nextObjBuilder.remove()); expectLastCall().once(); } return 1; }
Example 6
Source File: K8sNetworkPolicyHandler.java From onos with Apache License 2.0 | 6 votes |
private void setPolicyRulesBase(TrafficSelector.Builder sBuilder, TrafficTreatment.Builder tBuilder, int table, boolean install) { k8sNodeService.completeNodes().forEach(n -> { k8sFlowRuleService.setRule( appId, n.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_CIDR_RULE, table, install ); }); }
Example 7
Source File: OpenstackRoutingSnatIcmpHandler.java From onos with Apache License 2.0 | 5 votes |
private void sendReply(Ethernet icmpReply, InstancePort instPort) { TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder() .setOutput(instPort.portNumber()); String netId = instPort.networkId(); String segId = osNetworkService.segmentId(netId); switch (osNetworkService.networkType(netId)) { case VXLAN: case GRE: case GENEVE: tBuilder.setTunnelId(Long.valueOf(segId)); break; case VLAN: tBuilder.setVlanId(VlanId.vlanId(segId)); break; default: break; } OutboundPacket packet = new DefaultOutboundPacket( instPort.deviceId(), tBuilder.build(), ByteBuffer.wrap(icmpReply.serialize())); packetService.emit(packet); }
Example 8
Source File: OpenVSwitchPipeline.java From onos with Apache License 2.0 | 5 votes |
private void processSnatTable(boolean install) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(MAC_TABLE); treatment.add(Instructions.createOutput(PortNumber.CONTROLLER)); FlowRule rule; rule = DefaultFlowRule.builder().forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(TABLE_MISS_PRIORITY).fromApp(appId) .makePermanent().forTable(SNAT_TABLE).build(); applyRules(install, rule); }
Example 9
Source File: LinkCollectionCompiler.java From onos with Apache License 2.0 | 5 votes |
/** * Computes treatment and selector which will be used * in the flow representation (Rule, Objective). * * @param intent the intent to compile * @param inPort the input port of this device * @param deviceId the current device * @param outPorts the output ports of this device * @return the forwarding instruction object which encapsulates treatment and selector */ protected ForwardingInstructions createForwardingInstructions(LinkCollectionIntent intent, PortNumber inPort, DeviceId deviceId, Set<PortNumber> outPorts) { /* * We build an empty treatment and we initialize the selector with * the intent selector. */ TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment .builder(); TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector .builder(intent.selector()) .matchInPort(inPort); if (!intent.applyTreatmentOnEgress()) { manageMpIntent(selectorBuilder, treatmentBuilder, intent, inPort, deviceId, outPorts ); } else { manageSpIntent(selectorBuilder, treatmentBuilder, intent, deviceId, outPorts ); } /* * We return selector and treatment necessary to build the flow rule * or the flow objective. */ return new ForwardingInstructions(treatmentBuilder.build(), selectorBuilder.build()); }
Example 10
Source File: ControlPlaneRedirectManager.java From onos with Apache License 2.0 | 5 votes |
/** * Creates a next objective for forwarding to a port. Handles metadata for * some pipelines that require vlan information for egress port. * * @param deviceId the device on which the next objective is being created * @param portNumber the egress port * @param vlanId vlan information for egress port * @param popVlan if vlan tag should be popped or not * @param install true to create an add next objective, false to create a remove * next objective * @return nextId of the next objective created */ private int modifyNextObjective(DeviceId deviceId, PortNumber portNumber, VlanId vlanId, boolean popVlan, boolean install) { int nextId = flowObjectiveService.allocateNextId(); NextObjective.Builder nextObjBuilder = DefaultNextObjective .builder().withId(nextId) .withType(NextObjective.Type.SIMPLE) .fromApp(appId); TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); if (popVlan) { ttBuilder.popVlan(); } ttBuilder.setOutput(portNumber); // setup metadata to pass to nextObjective - indicate the vlan on egress // if needed by the switch pipeline. TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(); metabuilder.matchVlanId(vlanId); nextObjBuilder.withMeta(metabuilder.build()); nextObjBuilder.addTreatment(ttBuilder.build()); log.debug("Submitted next objective {} in device {} for port/vlan {}/{}", nextId, deviceId, portNumber, vlanId); if (install) { flowObjectiveService.next(deviceId, nextObjBuilder.add()); } else { flowObjectiveService.next(deviceId, nextObjBuilder.remove()); } return nextId; }
Example 11
Source File: OpenstackVtapManager.java From onos with Apache License 2.0 | 5 votes |
private void setOutputTableForTunnel(DeviceId deviceId, int tableId, PortNumber outPort, IpAddress serverIp, boolean install) { log.debug("setOutputTableForTunnel[{}]: deviceId={}, tableId={}, outPort={}, serverIp={}", install ? "add" : "remove", deviceId, tableId, outPort, serverIp); TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() .setOutput(outPort); if (tunnelNicira) { ExtensionTreatment extensionTreatment = buildTunnelExtension(deviceId, serverIp); if (extensionTreatment == null) { return; } treatment.extension(extensionTreatment, deviceId); } FlowRule flowRule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(PRIORITY_VTAP_OUTPUT_RULE) .makePermanent() .forTable(tableId) .fromApp(appId) .build(); log.debug("setOutputTableForTunnel flowRule={}, install={}", flowRule, install); applyFlowRule(flowRule, install); }
Example 12
Source File: SdnIpFibTest.java From onos with Apache License 2.0 | 4 votes |
private MultiPointToSinglePointIntent createIntentToThreeSrcOneTwo(IpPrefix ipPrefix) { // Build the expected treatment TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); treatmentBuilder.setEthDst(MAC3); // Build the expected egress FilteredConnectPoint FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(SW3_ETH1); // Build the expected selectors Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(); // Build the expected ingress FilteredConnectPoint for sw1 TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); selector.matchVlanId(VLAN10); selector.matchEthType(Ethernet.TYPE_IPV4); selector.matchIPDst(ipPrefix); FilteredConnectPoint ingressFilteredCP = new FilteredConnectPoint(SW1_ETH1, selector.build()); ingressFilteredCPs.add(ingressFilteredCP); // Build the expected ingress FilteredConnectPoint for sw2 selector = DefaultTrafficSelector.builder(); selector.matchVlanId(VLAN20); selector.matchEthType(Ethernet.TYPE_IPV4); selector.matchIPDst(ipPrefix); ingressFilteredCP = new FilteredConnectPoint(SW2_ETH1, selector.build()); ingressFilteredCPs.add(ingressFilteredCP); // Build the expected intent MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder() .appId(APPID) .key(Key.of(ipPrefix.toString(), APPID)) .filteredIngressPoints(ingressFilteredCPs) .filteredEgressPoint(egressFilteredCP) .treatment(treatmentBuilder.build()) .constraints(SdnIpFib.CONSTRAINTS) .build(); return intent; }
Example 13
Source File: RoutingRulePopulator.java From onos with Apache License 2.0 | 4 votes |
/** * Returns a Forwarding Objective builder for the MPLS rule that references * the desired Next Objective. Creates a DestinationSet that allows the * groupHandler to create or find the required next objective. * * @param targetSw the target sw * @param nextHops the set of next hops * @param phpRequired true if penultimate-hop-popping is required * @param isBos true if matched label is bottom-of-stack * @param meta metadata for creating next objective * @param routerIp the router ip representing the destination switch * @param destSw the destination sw * @return the mpls forwarding objective builder */ private ForwardingObjective.Builder getMplsForwardingObjective( DeviceId targetSw, Set<DeviceId> nextHops, boolean phpRequired, boolean isBos, TrafficSelector meta, IpAddress routerIp, int segmentId, DeviceId destSw) { ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective .builder().withFlag(ForwardingObjective.Flag.SPECIFIC); TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); DestinationSet ds = null; DestinationSet.DestinationSetType dstType = null; boolean simple = false; if (phpRequired) { // php case - pop should always be flow-action log.debug("getMplsForwardingObjective: php required"); tbuilder.deferred().copyTtlIn(); if (isBos) { if (routerIp.isIp4()) { tbuilder.deferred().popMpls(EthType.EtherType.IPV4.ethType()); } else { tbuilder.deferred().popMpls(EthType.EtherType.IPV6.ethType()); } tbuilder.decNwTtl(); // standard case -> BoS == True; pop results in IP packet and forwarding // is via an ECMP group ds = DestinationSet.createTypePopBos(destSw); } else { tbuilder.deferred().popMpls(EthType.EtherType.MPLS_UNICAST.ethType()) .decMplsTtl(); // double-label case -> BoS == False, pop results in MPLS packet // depending on configuration we can ECMP this packet or choose one output ds = DestinationSet.createTypePopNotBos(destSw); if (!srManager.getMplsEcmp()) { simple = true; } } } else { // swap with self case - SR CONTINUE log.debug("getMplsForwardingObjective: swap with self"); tbuilder.deferred().decMplsTtl(); // swap results in MPLS packet with same BoS bit regardless of bit value // depending on configuration we can ECMP this packet or choose one output // differentiate here between swap with not bos or swap with bos ds = isBos ? DestinationSet.createTypeSwapBos(segmentId, destSw) : DestinationSet.createTypeSwapNotBos(segmentId, destSw); if (!srManager.getMplsEcmp()) { simple = true; } } fwdBuilder.withTreatment(tbuilder.build()); log.debug("Trying to get a nextObjId for mpls rule on device:{} to ds:{}", targetSw, ds); DefaultGroupHandler gh = srManager.getGroupHandler(targetSw); if (gh == null) { log.warn("getNextObjectiveId query - groupHandler for device {} " + "not found", targetSw); return null; } Map<DeviceId, Set<DeviceId>> dstNextHops = new HashMap<>(); dstNextHops.put(destSw, nextHops); int nextId = gh.getNextObjectiveId(ds, dstNextHops, meta, simple); if (nextId <= 0) { log.warn("No next objective in {} for ds: {}", targetSw, ds); return null; } else { log.debug("nextObjId found:{} for mpls rule on device:{} to ds:{}", nextId, targetSw, ds); } fwdBuilder.nextStep(nextId); return fwdBuilder; }
Example 14
Source File: SdnIpFibTest.java From onos with Apache License 2.0 | 4 votes |
private MultiPointToSinglePointIntent createIntentToThreeSrcOneTwoFour(IpPrefix ipPrefix) { // Build the expected treatment TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); treatmentBuilder.setEthDst(MAC3); // Build the expected egress FilteredConnectPoint FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(SW3_ETH1); // Build the expected selectors Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(); // Build the expected ingress FilteredConnectPoint for sw1 TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); selector.matchVlanId(VLAN10); selector.matchEthType(Ethernet.TYPE_IPV4); selector.matchIPDst(ipPrefix); FilteredConnectPoint ingressFilteredCP = new FilteredConnectPoint(SW1_ETH1, selector.build()); ingressFilteredCPs.add(ingressFilteredCP); // Build the expected ingress FilteredConnectPoint for sw2 selector = DefaultTrafficSelector.builder(); selector.matchVlanId(VLAN20); selector.matchEthType(Ethernet.TYPE_IPV4); selector.matchIPDst(ipPrefix); ingressFilteredCP = new FilteredConnectPoint(SW2_ETH1, selector.build()); ingressFilteredCPs.add(ingressFilteredCP); // Build the expected ingress FilteredConnectPoint for sw4 selector = DefaultTrafficSelector.builder(); selector.matchEthType(Ethernet.TYPE_IPV4); selector.matchIPDst(ipPrefix); ingressFilteredCP = new FilteredConnectPoint(SW4_ETH1, selector.build()); ingressFilteredCPs.add(ingressFilteredCP); // Build the expected intent MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder() .appId(APPID) .key(Key.of(ipPrefix.toString(), APPID)) .filteredIngressPoints(ingressFilteredCPs) .filteredEgressPoint(egressFilteredCP) .treatment(treatmentBuilder.build()) .constraints(SdnIpFib.CONSTRAINTS) .build(); return intent; }
Example 15
Source File: PicaPipeline.java From onos with Apache License 2.0 | 4 votes |
private Collection<FlowRule> processVersatilesWithFilters( Filter filt, ForwardingObjective fwd) { Collection<FlowRule> flows = new ArrayList<FlowRule>(); // rule for ARP replies log.debug("adding ARP rule in ACL table"); TrafficSelector.Builder sel = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(); sel.matchInPort(filt.port()); sel.matchVlanId(filt.vlanId()); sel.matchEthDst(filt.mac()); sel.matchEthType(Ethernet.TYPE_ARP); treat.setOutput(PortNumber.CONTROLLER); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(sel.build()) .withTreatment(treat.build()) .withPriority(HIGHEST_PRIORITY) .fromApp(appId) .makePermanent() .forTable(ACL_TABLE).build(); flows.add(rule); // rule for ARP Broadcast sel = DefaultTrafficSelector.builder(); treat = DefaultTrafficTreatment.builder(); sel.matchInPort(filt.port()); sel.matchVlanId(filt.vlanId()); sel.matchEthDst(MacAddress.BROADCAST); sel.matchEthType(Ethernet.TYPE_ARP); treat.setOutput(PortNumber.CONTROLLER); rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(sel.build()) .withTreatment(treat.build()) .withPriority(HIGHEST_PRIORITY) .fromApp(appId) .makePermanent() .forTable(ACL_TABLE).build(); flows.add(rule); return flows; }
Example 16
Source File: DefaultGroupHandler.java From onos with Apache License 2.0 | 4 votes |
/** * Removes a single broadcast group from a given vlan id. * The group should be empty. * @param deviceId device Id to remove the group * @param portNum port number related to the group * @param vlanId vlan id of the broadcast group to remove * @param popVlan true if the TrafficTreatment involves pop vlan tag action */ public void removeBcastGroupFromVlan(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan) { VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId); if (!vlanNextObjStore.containsKey(key)) { log.debug("Broadcast group for device {} and subnet {} does not exist", deviceId, vlanId); return; } TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(vlanId).build(); int nextId = vlanNextObjStore.get(key); NextObjective.Builder nextObjBuilder = DefaultNextObjective .builder().withId(nextId) .withType(NextObjective.Type.BROADCAST).fromApp(appId) .withMeta(metadata); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); if (popVlan) { tBuilder.popVlan(); } tBuilder.setOutput(portNum); nextObjBuilder.addTreatment(tBuilder.build()); ObjectiveContext context = new DefaultObjectiveContext( (objective) -> log.debug("removeBroadcastGroupFromVlan removed " + "NextObj {} on {}", nextId, deviceId), (objective, error) -> { log.warn("removeBroadcastGroupFromVlan failed to remove NextObj {} on {}: {}", nextId, deviceId, error); srManager.invalidateNextObj(objective.id()); }); NextObjective nextObj = nextObjBuilder.remove(context); flowObjectiveService.next(deviceId, nextObj); log.debug("removeBcastGroupFromVlan: Submited next objective {} in device {}", nextId, deviceId); vlanNextObjStore.remove(key, nextId); }
Example 17
Source File: AbstractCorsaPipeline.java From onos with Apache License 2.0 | 4 votes |
protected TrafficTreatment.Builder processSpecificRoutingTreatment() { return DefaultTrafficTreatment.builder(); }
Example 18
Source File: OpenstackRoutingSnatHandler.java From onos with Apache License 2.0 | 4 votes |
private void setStatelessSnatUpstreamRules(String segmentId, Type networkType, IpAddress externalIp, ExternalPeerRouter externalPeerRouter, TpPort patPort, InboundPacket packetIn) { IPv4 iPacket = (IPv4) packetIn.parsed().getPayload(); TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchIPProtocol(iPacket.getProtocol()) .matchIPSrc(IpPrefix.valueOf(iPacket.getSourceAddress(), VM_PREFIX)) .matchIPDst(IpPrefix.valueOf(iPacket.getDestinationAddress(), VM_PREFIX)); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); switch (networkType) { case VXLAN: case GRE: case GENEVE: sBuilder.matchTunnelId(Long.parseLong(segmentId)); break; case VLAN: sBuilder.matchVlanId(VlanId.vlanId(segmentId)); tBuilder.popVlan(); break; default: final String error = String.format("%s %s", ERR_UNSUPPORTED_NET_TYPE, networkType.toString()); throw new IllegalStateException(error); } switch (iPacket.getProtocol()) { case IPv4.PROTOCOL_TCP: TCP tcpPacket = (TCP) iPacket.getPayload(); sBuilder.matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())) .matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort())); tBuilder.setTcpSrc(patPort).setEthDst(externalPeerRouter.macAddress()); break; case IPv4.PROTOCOL_UDP: UDP udpPacket = (UDP) iPacket.getPayload(); sBuilder.matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())) .matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort())); tBuilder.setUdpSrc(patPort).setEthDst(externalPeerRouter.macAddress()); break; default: log.debug("Unsupported IPv4 protocol {}"); break; } if (!externalPeerRouter.vlanId().equals(VlanId.NONE)) { tBuilder.pushVlan().setVlanId(externalPeerRouter.vlanId()); } tBuilder.setIpSrc(externalIp); osNodeService.completeNodes(GATEWAY).forEach(gNode -> { TrafficTreatment.Builder tmpBuilder = DefaultTrafficTreatment.builder(tBuilder.build()); tmpBuilder.setOutput(gNode.uplinkPortNum()); osFlowRuleService.setRule( appId, gNode.intgBridge(), sBuilder.build(), tmpBuilder.build(), PRIORITY_SNAT_RULE, GW_COMMON_TABLE, true); }); }
Example 19
Source File: Ofdpa2Pipeline.java From onos with Apache License 2.0 | 4 votes |
/** * In the OF-DPA 2.0 pipeline, egress forwarding objectives go to the * egress tables. * @param fwd the forwarding objective of type 'egress' * @return a collection of flow rules to be sent to the switch. An empty * collection may be returned if there is a problem in processing * the flow rule */ protected Collection<FlowRule> processEgress(ForwardingObjective fwd) { log.debug("Processing egress forwarding objective:{} in dev:{}", fwd, deviceId); List<FlowRule> rules = new ArrayList<>(); // Build selector TrafficSelector.Builder sb = DefaultTrafficSelector.builder(); VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) fwd.selector().getCriterion(Criterion.Type.VLAN_VID); if (vlanIdCriterion == null) { log.error("Egress forwarding objective:{} must include vlanId", fwd.id()); fail(fwd, ObjectiveError.BADPARAMS); return rules; } Optional<Instruction> outInstr = fwd.treatment().allInstructions().stream() .filter(instruction -> instruction instanceof OutputInstruction).findFirst(); if (!outInstr.isPresent()) { log.error("Egress forwarding objective:{} must include output port", fwd.id()); fail(fwd, ObjectiveError.BADPARAMS); return rules; } PortNumber portNumber = ((OutputInstruction) outInstr.get()).port(); sb.matchVlanId(vlanIdCriterion.vlanId()); OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber); sb.extension(actsetOutput, deviceId); sb.extension(new OfdpaMatchAllowVlanTranslation(ALLOW_VLAN_TRANSLATION), deviceId); // Build a flow rule for Egress VLAN Flow table TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); tb.transition(EGRESS_DSCP_PCP_REMARK_FLOW_TABLE); if (fwd.treatment() != null) { for (Instruction instr : fwd.treatment().allInstructions()) { if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2SubType.VLAN_ID) { tb.immediate().add(instr); } if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2SubType.VLAN_PUSH) { tb.immediate().pushVlan(); EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType(); if (ethType.equals(EtherType.QINQ.ethType())) { // Build a flow rule for Egress TPID Flow table TrafficSelector tpidSelector = DefaultTrafficSelector.builder() .extension(actsetOutput, deviceId) .matchVlanId(VlanId.ANY).build(); TrafficTreatment tpidTreatment = DefaultTrafficTreatment.builder() .extension(new Ofdpa3CopyField(COPY_FIELD_NBITS, COPY_FIELD_OFFSET, COPY_FIELD_OFFSET, OXM_ID_VLAN_VID, OXM_ID_PACKET_REG_1), deviceId) .popVlan() .pushVlan(EtherType.QINQ.ethType()) .extension(new Ofdpa3CopyField(COPY_FIELD_NBITS, COPY_FIELD_OFFSET, COPY_FIELD_OFFSET, OXM_ID_PACKET_REG_1, OXM_ID_VLAN_VID), deviceId) .build(); FlowRule.Builder tpidRuleBuilder = DefaultFlowRule.builder() .fromApp(fwd.appId()) .withPriority(fwd.priority()) .forDevice(deviceId) .withSelector(tpidSelector) .withTreatment(tpidTreatment) .makePermanent() .forTable(EGRESS_TPID_FLOW_TABLE); rules.add(tpidRuleBuilder.build()); } } } } FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() .fromApp(fwd.appId()) .withPriority(fwd.priority()) .forDevice(deviceId) .withSelector(sb.build()) .withTreatment(tb.build()) .makePermanent() .forTable(EGRESS_VLAN_FLOW_TABLE); rules.add(ruleBuilder.build()); return rules; }
Example 20
Source File: NokiaOltPipeline.java From onos with Apache License 2.0 | 3 votes |
private TrafficTreatment buildTreatment(Instruction... instructions) { TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); for (Instruction i : instructions) { tBuilder.add(i); } return tBuilder.build(); }