/** * Create an OFAction to change the outer most vlan. * * @param sw switch object * @param newVlan final VLAN to be set on the packet * @return {@link OFAction} */ private OFAction actionReplaceVlan(final IOFSwitch sw, final int newVlan) { OFFactory factory = sw.getOFFactory(); OFOxms oxms = factory.oxms(); OFActions actions = factory.actions(); if (OF_12.compareTo(factory.getVersion()) == 0) { return actions.buildSetField().setField(oxms.buildVlanVid() .setValue(OFVlanVidMatch.ofRawVid((short) newVlan)) .build()).build(); } else { return actions.buildSetField().setField(oxms.buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(newVlan)) .build()).build(); } }
default OFFlowAdd transitFlowMod(int inputPort, int outputPort, int transitVlan, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan)) .build()) .setInstructions(singletonList( ofFactory.instructions().applyActions(singletonList( ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
default OFFlowAdd oneSwitchPopFlowMod(int inputPort, int outputPort, int inputVlan, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().popVlan(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd egressPopFlowMod(int inputPort, int outputPort, int transitVlan, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan)) .build()) .setInstructions(singletonList( ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().popVlan(), ofFactory.actions().popVlan(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd egressNoneFlowMod(int inputPort, int outputPort, int transitVlan, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan)) .build()) .setInstructions(singletonList( ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().popVlan(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) { ExtensionSelectorType type = extensionSelector.type(); if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) { VlanId vlanId = ((OfdpaMatchVlanVid) extensionSelector).vlanId(); // Special VLAN 0x0000/0x1FFF required by OFDPA if (vlanId.equals(VlanId.NONE)) { OFVlanVidMatch vid = OFVlanVidMatch.ofRawVid((short) 0x0000); OFVlanVidMatch mask = OFVlanVidMatch.ofRawVid((short) 0x1FFF); return factory.oxms().vlanVidMasked(vid, mask); // Normal case } else if (vlanId.equals(VlanId.ANY)) { return factory.oxms().vlanVidMasked(OFVlanVidMatch.PRESENT, OFVlanVidMatch.PRESENT); } else { return factory.oxms().vlanVid(OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vlanId.toShort()))); } } throw new UnsupportedOperationException( "Unexpected ExtensionSelector: " + extensionSelector.toString()); }
protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) { // The packet in match will only contain the port number. // We need to add in specifics for the hosts we're routing between. Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD); VlanVid vlan = VlanVid.ofVlan(eth.getVlanID()); MacAddress srcMac = eth.getSourceMACAddress(); MacAddress dstMac = eth.getDestinationMACAddress(); Match.Builder mb = sw.getOFFactory().buildMatch(); mb.setExact(MatchField.IN_PORT, inPort) .setExact(MatchField.ETH_SRC, srcMac) .setExact(MatchField.ETH_DST, dstMac); if (!vlan.equals(VlanVid.ZERO)) { mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan)); } return mb.build(); }
/** * Creates a Match based on an inputPort and VlanID. * NB1: that this match only matches on the outer most tag which must be of ether-type 0x8100. * NB2: vlanId of 0 means match on port, not vlan * * @param sw switch object * @param inputPort input port for the match * @param vlanId vlanID to match on; 0 means match on port * @return {@link Match} */ private Match matchFlow(final IOFSwitch sw, final int inputPort, final int vlanId) { Match.Builder mb = sw.getOFFactory().buildMatch(); // // Extra emphasis: vlan of 0 means match on port on not VLAN. // if (vlanId > 0) { mb.setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(vlanId)); } else { mb.setExact(MatchField.IN_PORT, OFPort.of(inputPort)); } return mb.build(); }
default OFFlowAdd oneSwitchReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int outputVlan, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(outputVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
default OFFlowAdd oneSwitchPushFlowMod(int inputPort, int outputPort, int outputVlan, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().buildPushVlan() .setEthertype(EthType.of(ETH_TYPE)) .build(), ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(outputVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd ingressMatchVlanIdFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(transitVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd egressPushFlowMod(int inputPort, int outputPort, int transitVlan, int outputVlan, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan)) .build()) .setInstructions(singletonList( ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(outputVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd ingressMatchVlanIdFlowMod(int inputPort, int outputPort, int inputVlan, int transitVlan, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().buildPushVlan() .setEthertype(EthType.of(ETH_TYPE)) .build(), ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(transitVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd ingressNoMatchVlanIdFlowMod(int inputPort, int outputPort, int transitVlan, long meterId, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .build()) .setInstructions(Arrays.asList( ofFactory.instructions().buildMeter().setMeterId(meterId).build(), ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().buildPushVlan() .setEthertype(EthType.of(ETH_TYPE)) .build(), ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(transitVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd egressPushFlowMod(int inputPort, int outputPort, int transitVlan, int outputVlan, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlan)) .build()) .setInstructions(singletonList( ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().popVlan(), ofFactory.actions().buildPushVlan() .setEthertype(EthType.of(ETH_TYPE)) .build(), ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(outputVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFFlowAdd egressReplaceFlowMod(int inputPort, int outputPort, int inputVlan, int outputVlan, long cookie) { return ofFactory.buildFlowAdd() .setCookie(U64.of(cookie & FLOW_COOKIE_MASK)) .setHardTimeout(FlowModUtils.INFINITE_TIMEOUT) .setIdleTimeout(FlowModUtils.INFINITE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setPriority(FlowModUtils.PRIORITY_VERY_HIGH) .setMatch(ofFactory.buildMatch() .setExact(MatchField.IN_PORT, OFPort.of(inputPort)) .setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(inputVlan)) .build()) .setInstructions(singletonList( ofFactory.instructions().applyActions(Arrays.asList( ofFactory.actions().popVlan(), ofFactory.actions().buildSetField() .setField(ofFactory.oxms().buildVlanVid() .setValue(OFVlanVidMatch.ofVlan(outputVlan)) .build()) .build(), ofFactory.actions().buildOutput() .setMaxLen(0xFFFFFFFF) .setPort(OFPort.of(outputPort)) .build())) .createBuilder() .build())) .setXid(0L) .build(); }
@Override public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) { ExtensionTreatmentType type = extensionTreatment.type(); if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) { VlanId vlanId = ((OfdpaSetVlanVid) extensionTreatment).vlanId(); // NOTE: OFDPA requires isPresent bit set to zero. OFVlanVidMatch match = OFVlanVidMatch.ofRawVid(vlanId.toShort()); return factory.actions().setField(factory.oxms().vlanVid(match)); } throw new UnsupportedOperationException( "Unexpected ExtensionTreatment: " + extensionTreatment.toString()); }
private OFAction buildL2Modification(Instruction i) { L2ModificationInstruction l2m = (L2ModificationInstruction) i; L2ModificationInstruction.ModEtherInstruction eth; OFOxm<?> oxm = null; switch (l2m.subtype()) { case ETH_DST: eth = (L2ModificationInstruction.ModEtherInstruction) l2m; oxm = factory.oxms().ethDst(MacAddress.of(eth.mac().toLong())); break; case ETH_SRC: eth = (L2ModificationInstruction.ModEtherInstruction) l2m; oxm = factory.oxms().ethSrc(MacAddress.of(eth.mac().toLong())); break; case VLAN_ID: L2ModificationInstruction.ModVlanIdInstruction vlanId = (L2ModificationInstruction.ModVlanIdInstruction) l2m; oxm = factory.oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort())); break; case VLAN_PCP: L2ModificationInstruction.ModVlanPcpInstruction vlanPcp = (L2ModificationInstruction.ModVlanPcpInstruction) l2m; oxm = factory.oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); break; case VLAN_POP: return factory.actions().popVlan(); case VLAN_PUSH: L2ModificationInstruction.PushHeaderInstructions pushVlanInstruction = (L2ModificationInstruction.PushHeaderInstructions) l2m; return factory.actions().pushVlan( EthType.of(pushVlanInstruction.ethernetType().toShort())); case MPLS_PUSH: L2ModificationInstruction.PushHeaderInstructions pushHeaderInstructions = (L2ModificationInstruction.PushHeaderInstructions) l2m; return factory.actions().pushMpls(EthType.of(pushHeaderInstructions .ethernetType().toShort())); case MPLS_POP: L2ModificationInstruction.PushHeaderInstructions popHeaderInstructions = (L2ModificationInstruction.PushHeaderInstructions) l2m; return factory.actions().popMpls(EthType.of(popHeaderInstructions .ethernetType().toShort())); case MPLS_LABEL: L2ModificationInstruction.ModMplsLabelInstruction mplsLabel = (L2ModificationInstruction.ModMplsLabelInstruction) l2m; oxm = factory.oxms().mplsLabel(U32.of(mplsLabel.label().toInt())); break; case MPLS_BOS: L2ModificationInstruction.ModMplsBosInstruction mplsBos = (L2ModificationInstruction.ModMplsBosInstruction) l2m; oxm = factory.oxms() .mplsBos(mplsBos.mplsBos() ? OFBooleanValue.TRUE : OFBooleanValue.FALSE); break; case DEC_MPLS_TTL: return factory.actions().decMplsTtl(); case TUNNEL_ID: L2ModificationInstruction.ModTunnelIdInstruction tunnelId = (L2ModificationInstruction.ModTunnelIdInstruction) l2m; oxm = factory.oxms().tunnelId(U64.of(tunnelId.tunnelId())); break; default: log.warn("Unimplemented action type {}.", l2m.subtype()); break; } if (oxm != null) { return factory.actions().buildSetField().setField(oxm).build(); } return null; }
/** * Instead of using the Firewall's routing decision Match, which might be as general * as "in_port" and inadvertently Match packets erroneously, construct a more * specific Match based on the deserialized OFPacketIn's payload, which has been * placed in the FloodlightContext already by the Controller. * * @param sw, the switch on which the packet was received * @param inPort, the ingress switch port on which the packet was received * @param cntx, the current context which contains the deserialized packet * @return a composed Match object based on the provided information */ protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) { // The packet in match will only contain the port number. // We need to add in specifics for the hosts we're routing between. Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD); VlanVid vlan = VlanVid.ofVlan(eth.getVlanID()); MacAddress srcMac = eth.getSourceMACAddress(); MacAddress dstMac = eth.getDestinationMACAddress(); // A retentive builder will remember all MatchFields of the parent the builder was generated from // With a normal builder, all parent MatchFields will be lost if any MatchFields are added, mod, del // TODO (This is a bug in Loxigen and the retentive builder is a workaround.) Match.Builder mb = sw.getOFFactory().buildMatch(); mb.setExact(MatchField.IN_PORT, inPort) .setExact(MatchField.ETH_SRC, srcMac) .setExact(MatchField.ETH_DST, dstMac); if (!vlan.equals(VlanVid.ZERO)) { mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan)); } // TODO Detect switch type and match to create hardware-implemented flow // TODO Set option in config file to support specific or MAC-only matches if (eth.getEtherType() == EthType.IPv4) { /* shallow check for equality is okay for EthType */ IPv4 ip = (IPv4) eth.getPayload(); IPv4Address srcIp = ip.getSourceAddress(); IPv4Address dstIp = ip.getDestinationAddress(); mb.setExact(MatchField.IPV4_SRC, srcIp) .setExact(MatchField.IPV4_DST, dstIp) .setExact(MatchField.ETH_TYPE, EthType.IPv4); if (ip.getProtocol().equals(IpProtocol.TCP)) { TCP tcp = (TCP) ip.getPayload(); mb.setExact(MatchField.IP_PROTO, IpProtocol.TCP) .setExact(MatchField.TCP_SRC, tcp.getSourcePort()) .setExact(MatchField.TCP_DST, tcp.getDestinationPort()); } else if (ip.getProtocol().equals(IpProtocol.UDP)) { UDP udp = (UDP) ip.getPayload(); mb.setExact(MatchField.IP_PROTO, IpProtocol.UDP) .setExact(MatchField.UDP_SRC, udp.getSourcePort()) .setExact(MatchField.UDP_DST, udp.getDestinationPort()); } } else if (eth.getEtherType() == EthType.ARP) { /* shallow check for equality is okay for EthType */ mb.setExact(MatchField.ETH_TYPE, EthType.ARP); } return mb.build(); }
/** * Instead of using the Firewall's routing decision Match, which might be as general * as "in_port" and inadvertently Match packets erroneously, construct a more * specific Match based on the deserialized OFPacketIn's payload, which has been * placed in the FloodlightContext already by the Controller. * * @param sw, the switch on which the packet was received * @param inPort, the ingress switch port on which the packet was received * @param cntx, the current context which contains the deserialized packet * @return a composed Match object based on the provided information */ protected Match createMatchFromPacket(IOFSwitch sw, OFPort inPort, FloodlightContext cntx) { // The packet in match will only contain the port number. // We need to add in specifics for the hosts we're routing between. Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD); VlanVid vlan = VlanVid.ofVlan(eth.getVlanID()); MacAddress srcMac = eth.getSourceMACAddress(); MacAddress dstMac = eth.getDestinationMACAddress(); Match.Builder mb = sw.getOFFactory().buildMatch(); mb.setExact(MatchField.IN_PORT, inPort); if (FLOWMOD_DEFAULT_MATCH_MAC) { mb.setExact(MatchField.ETH_SRC, srcMac) .setExact(MatchField.ETH_DST, dstMac); } if (FLOWMOD_DEFAULT_MATCH_VLAN) { if (!vlan.equals(VlanVid.ZERO)) { mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(vlan)); } } // TODO Detect switch type and match to create hardware-implemented flow // TODO Allow for IPv6 matches if (eth.getEtherType() == EthType.IPv4) { /* shallow check for equality is okay for EthType */ IPv4 ip = (IPv4) eth.getPayload(); IPv4Address srcIp = ip.getSourceAddress(); IPv4Address dstIp = ip.getDestinationAddress(); if (FLOWMOD_DEFAULT_MATCH_IP_ADDR) { mb.setExact(MatchField.ETH_TYPE, EthType.IPv4) .setExact(MatchField.IPV4_SRC, srcIp) .setExact(MatchField.IPV4_DST, dstIp); } if (FLOWMOD_DEFAULT_MATCH_TRANSPORT) { /* * Take care of the ethertype if not included earlier, * since it's a prerequisite for transport ports. */ if (!FLOWMOD_DEFAULT_MATCH_IP_ADDR) { mb.setExact(MatchField.ETH_TYPE, EthType.IPv4); } if (ip.getProtocol().equals(IpProtocol.TCP)) { TCP tcp = (TCP) ip.getPayload(); mb.setExact(MatchField.IP_PROTO, IpProtocol.TCP) .setExact(MatchField.TCP_SRC, tcp.getSourcePort()) .setExact(MatchField.TCP_DST, tcp.getDestinationPort()); } else if (ip.getProtocol().equals(IpProtocol.UDP)) { UDP udp = (UDP) ip.getPayload(); mb.setExact(MatchField.IP_PROTO, IpProtocol.UDP) .setExact(MatchField.UDP_SRC, udp.getSourcePort()) .setExact(MatchField.UDP_DST, udp.getDestinationPort()); } } } else if (eth.getEtherType() == EthType.ARP) { /* shallow check for equality is okay for EthType */ mb.setExact(MatchField.ETH_TYPE, EthType.ARP); } return mb.build(); }
private OFAction buildL2Modification(Instruction i) { L2ModificationInstruction l2m = (L2ModificationInstruction) i; L2ModificationInstruction.ModEtherInstruction eth; OFOxm<?> oxm = null; switch (l2m.subtype()) { case ETH_DST: eth = (L2ModificationInstruction.ModEtherInstruction) l2m; oxm = factory.oxms().ethDst(MacAddress.of(eth.mac().toLong())); break; case ETH_SRC: eth = (L2ModificationInstruction.ModEtherInstruction) l2m; oxm = factory.oxms().ethSrc(MacAddress.of(eth.mac().toLong())); break; case VLAN_ID: L2ModificationInstruction.ModVlanIdInstruction vlanId = (L2ModificationInstruction.ModVlanIdInstruction) l2m; oxm = factory.oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort())); break; case VLAN_PCP: L2ModificationInstruction.ModVlanPcpInstruction vlanPcp = (L2ModificationInstruction.ModVlanPcpInstruction) l2m; oxm = factory.oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); break; case VLAN_POP: return factory.actions().popVlan(); case VLAN_PUSH: L2ModificationInstruction.PushHeaderInstructions pushVlanInstruction = (L2ModificationInstruction.PushHeaderInstructions) l2m; return factory.actions().pushVlan( EthType.of(pushVlanInstruction.ethernetType())); case MPLS_PUSH: L2ModificationInstruction.PushHeaderInstructions pushHeaderInstructions = (L2ModificationInstruction.PushHeaderInstructions) l2m; return factory.actions().pushMpls(EthType.of(pushHeaderInstructions .ethernetType())); case MPLS_POP: L2ModificationInstruction.PushHeaderInstructions popHeaderInstructions = (L2ModificationInstruction.PushHeaderInstructions) l2m; return factory.actions().popMpls(EthType.of(popHeaderInstructions .ethernetType())); case MPLS_LABEL: L2ModificationInstruction.ModMplsLabelInstruction mplsLabel = (L2ModificationInstruction.ModMplsLabelInstruction) l2m; oxm = factory.oxms().mplsLabel(U32.of(mplsLabel.label() .longValue())); break; case DEC_MPLS_TTL: return factory.actions().decMplsTtl(); default: log.warn("Unimplemented action type {}.", l2m.subtype()); break; } if (oxm != null) { return factory.actions().buildSetField().setField(oxm).build(); } return null; }
private OFAction buildL2Modification(Instruction i) { L2ModificationInstruction l2m = (L2ModificationInstruction) i; L2ModificationInstruction.ModEtherInstruction eth; OFOxm<?> oxm = null; switch (l2m.subtype()) { case ETH_DST: eth = (L2ModificationInstruction.ModEtherInstruction) l2m; oxm = factory.oxms().ethDst(MacAddress.of(eth.mac().toLong())); break; case ETH_SRC: eth = (L2ModificationInstruction.ModEtherInstruction) l2m; oxm = factory.oxms().ethSrc(MacAddress.of(eth.mac().toLong())); break; case VLAN_ID: L2ModificationInstruction.ModVlanIdInstruction vlanId = (L2ModificationInstruction.ModVlanIdInstruction) l2m; oxm = factory.oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort())); break; case VLAN_PCP: L2ModificationInstruction.ModVlanPcpInstruction vlanPcp = (L2ModificationInstruction.ModVlanPcpInstruction) l2m; oxm = factory.oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); break; case VLAN_POP: return factory.actions().popVlan(); case VLAN_PUSH: L2ModificationInstruction.ModVlanHeaderInstruction pushVlanInstruction = (L2ModificationInstruction.ModVlanHeaderInstruction) l2m; return factory.actions().pushVlan( EthType.of(pushVlanInstruction.ethernetType().toShort())); case MPLS_PUSH: L2ModificationInstruction.ModMplsHeaderInstruction pushHeaderInstructions = (L2ModificationInstruction.ModMplsHeaderInstruction) l2m; return factory.actions().pushMpls(EthType.of(pushHeaderInstructions .ethernetType().toShort())); case MPLS_POP: L2ModificationInstruction.ModMplsHeaderInstruction popHeaderInstructions = (L2ModificationInstruction.ModMplsHeaderInstruction) l2m; return factory.actions().popMpls(EthType.of(popHeaderInstructions .ethernetType().toShort())); case MPLS_LABEL: L2ModificationInstruction.ModMplsLabelInstruction mplsLabel = (L2ModificationInstruction.ModMplsLabelInstruction) l2m; oxm = factory.oxms().mplsLabel(U32.of(mplsLabel.label().toInt())); break; case MPLS_BOS: L2ModificationInstruction.ModMplsBosInstruction mplsBos = (L2ModificationInstruction.ModMplsBosInstruction) l2m; oxm = factory.oxms() .mplsBos(mplsBos.mplsBos() ? OFBooleanValue.TRUE : OFBooleanValue.FALSE); break; case DEC_MPLS_TTL: return factory.actions().decMplsTtl(); case TUNNEL_ID: L2ModificationInstruction.ModTunnelIdInstruction tunnelId = (L2ModificationInstruction.ModTunnelIdInstruction) l2m; oxm = factory.oxms().tunnelId(U64.of(tunnelId.tunnelId())); break; default: log.warn("Unimplemented action type {}.", l2m.subtype()); break; } if (oxm != null) { return factory.actions().buildSetField().setField(oxm).build(); } return null; }