Java Code Examples for org.onosproject.net.flow.DefaultTrafficTreatment#builder()
The following examples show how to use
org.onosproject.net.flow.DefaultTrafficTreatment#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: OplinkPowerConfigUtil.java From onos with Apache License 2.0 | 6 votes |
/** * Replace flow with new flow containing Oplink attenuation extension instruction. Also resets metrics. * * @param flowEntry flow entry * @param power power value */ private void addAttenuation(FlowEntry flowEntry, long power) { FlowRule.Builder flowBuilder = new DefaultFlowRule.Builder() .withCookie(flowEntry.id().value()) .withPriority(flowEntry.priority()) .forDevice(flowEntry.deviceId()) .forTable(flowEntry.tableId()); if (flowEntry.isPermanent()) { flowBuilder.makePermanent(); } else { flowBuilder.makeTemporary(flowEntry.timeout()); } flowBuilder.withSelector(flowEntry.selector()); // Copy original instructions and add attenuation instruction TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); flowEntry.treatment().allInstructions().forEach(ins -> treatmentBuilder.add(ins)); final DriverHandler handler = behaviour.handler(); treatmentBuilder.add(Instructions.extension(new OplinkAttenuation((int) power), handler.data().deviceId())); flowBuilder.withTreatment(treatmentBuilder.build()); FlowRuleService service = handler.get(FlowRuleService.class); service.applyFlowRules(flowBuilder.build()); }
Example 2
Source File: ClassifierServiceImpl.java From onos with Apache License 2.0 | 6 votes |
@Override public void programExportPortArpClassifierRules(Port exportPort, DeviceId deviceId, Operation type) { TrafficSelector selector = DefaultTrafficSelector.builder() .matchEthType(EtherType.ARP.ethType().toShort()) .matchInPort(exportPort.number()).build(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.add(Instructions.createOutput(PortNumber.CONTROLLER)); ForwardingObjective.Builder objective = DefaultForwardingObjective .builder().withTreatment(treatment.build()) .withSelector(selector).fromApp(appId).withFlag(Flag.SPECIFIC) .withPriority(L3_CLASSIFIER_PRIORITY); if (type.equals(Objective.Operation.ADD)) { flowObjectiveService.forward(deviceId, objective.add()); } else { flowObjectiveService.forward(deviceId, objective.remove()); } }
Example 3
Source File: VirtualNetworkGroupManagerTest.java From onos with Apache License 2.0 | 6 votes |
private Group createSouthboundGroupEntry(GroupId gId, List<PortNumber> ports, long referenceCount, DeviceId deviceId) { List<PortNumber> outPorts = new ArrayList<>(); outPorts.addAll(ports); List<GroupBucket> buckets = new ArrayList<>(); for (PortNumber portNumber : outPorts) { TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); tBuilder.setOutput(portNumber) .setEthDst(MacAddress.valueOf("00:00:00:00:00:02")) .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) .pushMpls() .setMpls(MplsLabel.mplsLabel(106)); buckets.add(DefaultGroupBucket.createSelectGroupBucket( tBuilder.build())); } GroupBuckets groupBuckets = new GroupBuckets(buckets); StoredGroupEntry group = new DefaultGroup( gId, deviceId, Group.Type.SELECT, groupBuckets); group.setReferenceCount(referenceCount); return group; }
Example 4
Source File: OpenstackFlowRuleManager.java From onos with Apache License 2.0 | 6 votes |
private void setFlatJumpRuleForPatchPort(DeviceId deviceId, PortNumber portNumber, short ethType) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); selector.matchInPort(portNumber) .matchEthType(ethType); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(STAT_FLAT_OUTBOUND_TABLE); FlowRule flowRuleForIp = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(PRIORITY_FLAT_JUMP_UPSTREAM_RULE) .fromApp(appId) .makePermanent() .forTable(DHCP_TABLE) .build(); applyRule(flowRuleForIp, true); }
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: K8sFlowRuleManager.java From onos with Apache License 2.0 | 6 votes |
@Override public void connectTables(DeviceId deviceId, int fromTable, int toTable) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(toTable); FlowRule flowRule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(DROP_PRIORITY) .fromApp(appId) .makePermanent() .forTable(fromTable) .build(); applyRule(flowRule, true); }
Example 7
Source File: OpenstackVtapManager.java From onos with Apache License 2.0 | 6 votes |
private void setOutputTableForDrop(DeviceId deviceId, int tableId, boolean install) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); FlowRule flowRule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(PRIORITY_VTAP_OUTPUT_DROP) .makePermanent() .forTable(tableId) .fromApp(appId) .build(); applyFlowRule(flowRule, install); }
Example 8
Source File: RoutingRulePopulator.java From onos with Apache License 2.0 | 5 votes |
private ForwardingObjective.Builder dad6FwdObjective(PortNumber port, int priority) { TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); sBuilder.matchEthType(TYPE_IPV6) .matchIPv6Src(Ip6Address.ZERO.toIpPrefix()); // TODO CORD-1672 Fix this when OFDPA can distinguish ::/0 and ::/128 correctly // .matchIPProtocol(PROTOCOL_ICMP6) // .matchIcmpv6Type(NEIGHBOR_SOLICITATION); if (port != null) { sBuilder.matchInPort(port); } TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); tBuilder.wipeDeferred(); return fwdObjBuilder(sBuilder.build(), tBuilder.build(), priority); }
Example 9
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 10
Source File: DefaultNeighbourMessageActions.java From onos with Apache License 2.0 | 5 votes |
/** * Outputs a packet out a specific port. * * @param packet packet to send * @param outPort port to send it out */ private void sendTo(ByteBuffer packet, ConnectPoint outPort) { if (!edgeService.isEdgePoint(outPort)) { // Sanity check to make sure we don't send the packet out an // internal port and create a loop (could happen due to // misconfiguration). return; } TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); builder.setOutput(outPort.port()); packetService.emit(new DefaultOutboundPacket(outPort.deviceId(), builder.build(), packet)); }
Example 11
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 12
Source File: Ofdpa2Pipeline.java From onos with Apache License 2.0 | 5 votes |
/** * Builds TMAC rules for IPv6 packets. * * @param ethCriterion dst mac matching * @param vidCriterion vlan id assigned to the port * @param ofdpaMatchVlanVid OFDPA vlan id matching * @param applicationId application id * @param pnum port number * @return TMAC rule for IPV6 packets */ private FlowRule buildTmacRuleForIpv6(EthCriterion ethCriterion, VlanIdCriterion vidCriterion, OfdpaMatchVlanVid ofdpaMatchVlanVid, ApplicationId applicationId, PortNumber pnum) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); if (pnum != null) { if (matchInPortTmacTable()) { selector.matchInPort(pnum); } else { log.debug("Pipeline does not support IN_PORT matching in TMAC table, " + "ignoring the IN_PORT criteria"); } } if (vidCriterion != null) { if (requireVlanExtensions()) { selector.extension(ofdpaMatchVlanVid, deviceId); } else { selector.matchVlanId(vidCriterion.vlanId()); } } selector.matchEthType(Ethernet.TYPE_IPV6); selector.matchEthDst(ethCriterion.mac()); treatment.transition(UNICAST_ROUTING_TABLE); return DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(DEFAULT_PRIORITY) .fromApp(applicationId) .makePermanent() .forTable(TMAC_TABLE).build(); }
Example 13
Source File: OFAgentVirtualGroupBucketEntryBuilder.java From onos with Apache License 2.0 | 5 votes |
private TrafficTreatment buildTreatment(List<OFAction> actions) { DriverHandler driverHandler = getDriver(dpid); TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); // If this is a drop rule if (actions.isEmpty()) { builder.drop(); return builder.build(); } return FlowEntryBuilder.configureTreatmentBuilder(actions, builder, driverHandler, DeviceId.deviceId(Dpid.uri(dpid))).build(); }
Example 14
Source File: SimpleFabricRouting.java From onos with Apache License 2.0 | 5 votes |
private FlowRule generateLocalSubnetIpBctFlowRule(DeviceId deviceId, IpPrefix prefix, FabricNetwork fabricNetwork) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); IpPrefix bctPrefix; if (prefix.isIp4()) { bctPrefix = Ip4Prefix.valueOf(prefix.getIp4Prefix().address().toInt() | ~Ip4Address.makeMaskPrefix(prefix.prefixLength()).toInt(), Ip4Address.BIT_LENGTH); selector.matchEthType(Ethernet.TYPE_IPV4); selector.matchIPDst(bctPrefix); } else { byte[] p = prefix.getIp6Prefix().address().toOctets(); byte[] m = Ip6Address.makeMaskPrefix(prefix.prefixLength()).toOctets(); for (int i = 0; i < p.length; i++) { p[i] |= ~m[i]; } bctPrefix = Ip6Prefix.valueOf(p, Ip6Address.BIT_LENGTH); selector.matchEthType(Ethernet.TYPE_IPV6); selector.matchIPv6Dst(bctPrefix); } TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); Set<ConnectPoint> newEgressPoints = new HashSet<>(); for (Interface iface : fabricNetwork.interfaces()) { if (iface.connectPoint().deviceId().equals(deviceId)) { treatment.setOutput(iface.connectPoint().port()); } } FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withPriority(reactivePriority(true, true, bctPrefix.prefixLength())) .withSelector(selector.build()) .withTreatment(treatment.build()) .fromApp(appId) .makePermanent() .forTable(0).build(); return rule; }
Example 15
Source File: OvsOfdpaPipeline.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 */ @Override 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 Instructions.OutputInstruction).findFirst(); if (!outInstr.isPresent()) { log.error("Egress forwarding objective:{} must include output port", fwd.id()); fail(fwd, ObjectiveError.BADPARAMS); return rules; } PortNumber portNumber = ((Instructions.OutputInstruction) outInstr.get()).port(); sb.matchVlanId(vlanIdCriterion.vlanId()); OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber); sb.extension(actsetOutput, deviceId); // Build a flow rule for Egress VLAN Flow table TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); tb.transition(UNICAST_ROUTING_TABLE_1); if (fwd.treatment() != null) { for (Instruction instr : fwd.treatment().allInstructions()) { if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) { tb.immediate().add(instr); } if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) { EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType(); tb.immediate().pushVlan(ethType); } } } 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_IN_INGRESS); rules.add(ruleBuilder.build()); return rules; }
Example 16
Source File: OpenstackRoutingHandler.java From onos with Apache License 2.0 | 4 votes |
private void setRulesToGatewayWithDstIp(OpenstackNode osNode, OpenstackNode sourceNatGateway, String segmentId, IpAddress dstIp, Type networkType, boolean install) { TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchIPDst(dstIp.getIp4Address().toIpPrefix()); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); switch (networkType) { case VXLAN: case GRE: case GENEVE: sBuilder.matchTunnelId(Long.parseLong(segmentId)); PortNumber portNum = tunnelPortNumByNetType(networkType, osNode); tBuilder.extension(buildExtension( deviceService, osNode.intgBridge(), sourceNatGateway.dataIp().getIp4Address()), osNode.intgBridge()) .setOutput(portNum); break; case VLAN: sBuilder.matchVlanId(VlanId.vlanId(segmentId)); tBuilder.setOutput(osNode.vlanPortNum()); break; default: break; } osFlowRuleService.setRule( appId, osNode.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_SWITCHING_RULE, ROUTING_TABLE, install); }
Example 17
Source File: PeerConnectivityManagerTest.java From onos with Apache License 2.0 | 4 votes |
/** * Constructs a BGP intent and put it into the intentList. * <p/> * The purpose of this method is too simplify the setUpBgpIntents() method, * and to make the setUpBgpIntents() easy to read. * * @param srcVlanId ingress VlanId * @param dstVlanId egress VlanId * @param srcPrefix source IP prefix to match * @param dstPrefix destination IP prefix to match * @param srcTcpPort source TCP port to match * @param dstTcpPort destination TCP port to match * @param srcConnectPoint source connect point for PointToPointIntent * @param dstConnectPoint destination connect point for PointToPointIntent */ private void bgpPathintentConstructor(VlanId srcVlanId, VlanId dstVlanId, String srcPrefix, String dstPrefix, Short srcTcpPort, Short dstTcpPort, ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) { TrafficSelector.Builder builder = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchIPProtocol(IPv4.PROTOCOL_TCP) .matchIPSrc(IpPrefix.valueOf(srcPrefix)) .matchIPDst(IpPrefix.valueOf(dstPrefix)); if (!srcVlanId.equals(VlanId.NONE)) { builder.matchVlanId(srcVlanId); } TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); if (!dstVlanId.equals(VlanId.NONE)) { treatment.setVlanId(dstVlanId); } if (srcTcpPort != null) { builder.matchTcpSrc(TpPort.tpPort(srcTcpPort)); } if (dstTcpPort != null) { builder.matchTcpDst(TpPort.tpPort(dstTcpPort)); } Key key = Key.of(srcPrefix.split("/")[0] + "-" + dstPrefix.split("/")[0] + "-" + ((srcTcpPort == null) ? "dst" : "src"), APPID); PointToPointIntent intent = PointToPointIntent.builder() .appId(APPID) .key(key) .selector(builder.build()) .treatment(treatment.build()) .filteredIngressPoint(new FilteredConnectPoint(srcConnectPoint)) .filteredEgressPoint(new FilteredConnectPoint(dstConnectPoint)) .build(); intentList.add(intent); }
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: Ofdpa3Pipeline.java From onos with Apache License 2.0 | 4 votes |
/** * Internal implementation of processDoubleVlanIdFilter. * * @param portCriterion port on device for which this filter is programmed * @param innerVidCriterion inner vlan * @param outerVidCriterion outer vlan * @param popVlan true if outer vlan header needs to be removed * @param applicationId for application programming this filter * @return flow rules for port-vlan filters */ private List<FlowRule> processDoubleVlanIdFilter(PortCriterion portCriterion, VlanIdCriterion innerVidCriterion, VlanIdCriterion outerVidCriterion, boolean popVlan, ApplicationId applicationId) { TrafficSelector.Builder outerSelector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder outerTreatment = DefaultTrafficTreatment.builder(); TrafficSelector.Builder innerSelector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder innerTreatment = DefaultTrafficTreatment.builder(); VlanId outerVlanId = outerVidCriterion.vlanId(); VlanId innerVlanId = innerVidCriterion.vlanId(); PortNumber portNumber = portCriterion.port(); // Check arguments if (PortNumber.ALL.equals(portNumber) || outerVlanId.equals(VlanId.NONE) || innerVlanId.equals(VlanId.NONE)) { log.warn("Incomplete Filtering Objective. " + "VLAN Table cannot be programmed for {}", deviceId); return ImmutableList.of(); } else { outerSelector.matchInPort(portNumber); innerSelector.matchInPort(portNumber); outerTreatment.transition(VLAN_1_TABLE); innerTreatment.transition(TMAC_TABLE); if (requireVlanExtensions()) { OfdpaMatchVlanVid ofdpaOuterMatchVlanVid = new OfdpaMatchVlanVid(outerVlanId); outerSelector.extension(ofdpaOuterMatchVlanVid, deviceId); OfdpaMatchVlanVid ofdpaInnerMatchVlanVid = new OfdpaMatchVlanVid(innerVlanId); innerSelector.extension(ofdpaInnerMatchVlanVid, deviceId); } else { outerSelector.matchVlanId(outerVlanId); innerSelector.matchVlanId(innerVlanId); } innerSelector.extension(new Ofdpa3MatchOvid(outerVlanId), deviceId); outerTreatment.extension(new Ofdpa3SetOvid(outerVlanId), deviceId); if (popVlan) { outerTreatment.popVlan(); } } FlowRule outerRule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(outerSelector.build()) .withTreatment(outerTreatment.build()) .withPriority(DEFAULT_PRIORITY) .fromApp(applicationId) .makePermanent() .forTable(VLAN_TABLE) .build(); FlowRule innerRule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(innerSelector.build()) .withTreatment(innerTreatment.build()) .withPriority(DEFAULT_PRIORITY) .fromApp(applicationId) .makePermanent() .forTable(VLAN_1_TABLE) .build(); return ImmutableList.of(outerRule, innerRule); }
Example 20
Source File: Ofdpa2GroupHandler.java From onos with Apache License 2.0 | 4 votes |
private GroupInfo prepareL3UnicastGroup(NextObjective nextObj, NextGroup next) { ImmutableList.Builder<GroupInfo> groupInfoBuilder = ImmutableList.builder(); TrafficTreatment treatment = nextObj.next().iterator().next(); VlanId assignedVlan = readVlanFromSelector(nextObj.meta()); if (assignedVlan == null) { log.warn("VLAN ID required by next obj is missing. Abort."); return null; } List<GroupInfo> l2GroupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan); GroupDescription l2InterfaceGroupDesc = l2GroupInfos.get(0).innerMostGroupDesc(); GroupKey l2groupkey = l2InterfaceGroupDesc.appCookie(); TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder(); VlanId vlanid = null; MacAddress srcMac; MacAddress dstMac; for (Instruction ins : treatment.allInstructions()) { if (ins.type() == Instruction.Type.L2MODIFICATION) { L2ModificationInstruction l2ins = (L2ModificationInstruction) ins; switch (l2ins.subtype()) { case ETH_DST: dstMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac(); outerTtb.setEthDst(dstMac); break; case ETH_SRC: srcMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac(); outerTtb.setEthSrc(srcMac); break; case VLAN_ID: vlanid = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId(); outerTtb.setVlanId(vlanid); break; default: break; } } else { log.debug("Driver does not handle this type of TrafficTreatment" + " instruction in l2l3chain: {} - {}", ins.type(), ins); } } GroupId l2groupId = new GroupId(l2InterfaceGroupDesc.givenGroupId()); outerTtb.group(l2groupId); // we need the top level group's key to point the flow to it List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); GroupKey l3groupkey = gkeys.get(0).peekFirst(); GroupId grpId = groupService.getGroup(deviceId, l3groupkey).id(); int l3groupId = grpId.id(); // create the l3unicast group description to wait for the // l2 interface group to be processed GroupBucket l3UnicastGroupBucket = DefaultGroupBucket.createIndirectGroupBucket(outerTtb.build()); GroupDescription l3UnicastGroupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList( l3UnicastGroupBucket)), l3groupkey, l3groupId, nextObj.appId()); // store l2groupkey with the groupChainElem for the outer-group that depends on it GroupChainElem gce = new GroupChainElem(l3UnicastGroupDescription, 1, false, deviceId); updatePendingGroups(l2groupkey, gce); log.debug("Trying L3-Interface: device:{} gid:{} gkey:{} nextid:{}", deviceId, Integer.toHexString(l3groupId), l3groupkey, nextObj.id()); groupInfoBuilder.add(new GroupInfo(l2InterfaceGroupDesc, l3UnicastGroupDescription)); return groupInfoBuilder.build().iterator().next(); }