- return matchBuilder;
- }
-
- /**
- * Method converts Openflow 1.3+ specific flow match to MD-SAL format flow
- * match
- *
- * @param swMatch source match
- * @param datapathid datapath id
- * @param ofVersion openflow version
- * @return md-sal match instance
- * @author avishnoi@in.ibm.com
- */
- public static MatchBuilder fromOFMatchToSALMatch(
- @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match swMatch,
- @Nonnull final BigInteger datapathid, @Nonnull final OpenflowVersion ofVersion) {
- return OfMatchToSALMatchConvertor(swMatch.getMatchEntry(), datapathid, ofVersion);
- }
-
- private static MatchBuilder OfMatchToSALMatchConvertor(final List<MatchEntry> swMatchList, final BigInteger datapathid,
- final OpenflowVersion ofVersion) {
-
- MatchBuilder matchBuilder = new MatchBuilder();
- EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
- VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
- IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
- TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
- UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
- SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
- Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
- Icmpv6MatchBuilder icmpv6MatchBuilder = new Icmpv6MatchBuilder();
- Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
- Ipv4MatchArbitraryBitMaskBuilder ipv4MatchArbitraryBitMaskBuilder = new Ipv4MatchArbitraryBitMaskBuilder();
- ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
- Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
- Ipv6MatchArbitraryBitMaskBuilder ipv6MatchArbitraryBitMaskBuilder = new Ipv6MatchArbitraryBitMaskBuilder();
- ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
- TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
- TcpFlagsMatchBuilder tcpFlagsMatchBuilder = new TcpFlagsMatchBuilder();
-
- for (MatchEntry ofMatch : swMatchList) {
-
- if (ofMatch.getOxmMatchField().equals(InPort.class)) {
- PortNumber portNumber = ((InPortCase) ofMatch.getMatchEntryValue()).getInPort().getPortNumber();
- if (portNumber != null) {
- matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid, portNumber.getValue(), ofVersion));
- }
- } else if (ofMatch.getOxmMatchField().equals(InPhyPort.class)) {
- PortNumber portNumber = ((InPhyPortCase) ofMatch.getMatchEntryValue()).getInPhyPort().getPortNumber();
- matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
- portNumber.getValue(), ofVersion));
- } else if (ofMatch.getOxmMatchField().equals(Metadata.class)) {
- MetadataBuilder metadataBuilder = new MetadataBuilder();
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.metadata._case.Metadata metadata = ((MetadataCase) ofMatch.getMatchEntryValue()).getMetadata();
- if (metadata != null) {
- metadataBuilder.setMetadata(new BigInteger(OFConstants.SIGNUM_UNSIGNED, metadata.getMetadata()));
- byte[] metadataMask = metadata.getMask();
- if (metadataMask != null) {
- metadataBuilder.setMetadataMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, metadataMask));
- }
- matchBuilder.setMetadata(metadataBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(EthSrc.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.src._case.EthSrc ethSrcCase = ((EthSrcCase) ofMatch.getMatchEntryValue()).getEthSrc();
- if (ethSrcCase != null) {
- EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
- ethSourceBuilder.setAddress(ethSrcCase.getMacAddress());
- byte[] mask = ethSrcCase.getMask();
- if (mask != null) {
- ethSourceBuilder.setMask(new MacAddress(macAddressToString(mask)));
- }
- ethMatchBuilder.setEthernetSource(ethSourceBuilder.build());
- matchBuilder.setEthernetMatch(ethMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(EthDst.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.dst._case.EthDst ethDstCase = ((EthDstCase) ofMatch.getMatchEntryValue()).getEthDst();
- if (ethDstCase != null) {
- EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
- ethDestinationBuilder.setAddress(ethDstCase.getMacAddress());
- byte[] destinationMask = ethDstCase.getMask();
- if (destinationMask != null) {
- ethDestinationBuilder.setMask(new MacAddress(macAddressToString(destinationMask)));
- }
- ethMatchBuilder.setEthernetDestination(ethDestinationBuilder.build());
- matchBuilder.setEthernetMatch(ethMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(EthType.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.type._case.EthType ethTypeCase = ((EthTypeCase) ofMatch.getMatchEntryValue()).getEthType();
- if (ethTypeCase != null) {
- EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
- ethTypeBuilder
- .setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType(
- (long) ethTypeCase.getEthType().getValue()));
- ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
- matchBuilder.setEthernetMatch(ethMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(VlanVid.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.vid._case.VlanVid vlanVid = ((VlanVidCase) ofMatch.getMatchEntryValue()).getVlanVid();
- if (vlanVid != null) {
- VlanIdBuilder vlanBuilder = new VlanIdBuilder();
- vlanBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(
- vlanVid.getVlanVid()))
- .setVlanIdPresent(vlanVid.isCfiBit());
- vlanBuilder.setVlanIdPresent(vlanVid.isCfiBit());
- vlanMatchBuilder.setVlanId(vlanBuilder.build());
-
- matchBuilder.setVlanMatch(vlanMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(VlanPcp.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.pcp._case.VlanPcp vlanPcp = ((VlanPcpCase) ofMatch.getMatchEntryValue()).getVlanPcp();
- if (vlanPcp != null) {
- vlanMatchBuilder
- .setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(
- vlanPcp.getVlanPcp()));
- matchBuilder.setVlanMatch(vlanMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(IpDscp.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ip.dscp._case.IpDscp ipDscp = ((IpDscpCase) ofMatch.getMatchEntryValue()).getIpDscp();
- if (ipDscp != null) {
- ipMatchBuilder.setIpDscp(new Dscp(ipDscp.getDscp().getValue()));
- matchBuilder.setIpMatch(ipMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(IpEcn.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ip.ecn._case.IpEcn ipEcn = ((IpEcnCase) ofMatch.getMatchEntryValue()).getIpEcn();
- if (ipEcn != null) {
- ipMatchBuilder.setIpEcn(ipEcn.getEcn());
- matchBuilder.setIpMatch(ipMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(IpProto.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ip.proto._case.IpProto ipProto = ((IpProtoCase) ofMatch.getMatchEntryValue()).getIpProto();
- Short protocolNumber = ipProto.getProtocolNumber();
- if (protocolNumber != null) {
- ipMatchBuilder.setIpProtocol(protocolNumber);
- matchBuilder.setIpMatch(ipMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(TcpSrc.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.src._case.TcpSrc tcpSrc = ((TcpSrcCase) ofMatch.getMatchEntryValue()).getTcpSrc();
- if (tcpSrc != null) {
- tcpMatchBuilder.setTcpSourcePort(tcpSrc.getPort());
- matchBuilder.setLayer4Match(tcpMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(TcpDst.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.dst._case.TcpDst tcpDst = ((TcpDstCase) ofMatch.getMatchEntryValue()).getTcpDst();
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber portNumber = tcpDst.getPort();
- if (portNumber != null) {
- tcpMatchBuilder.setTcpDestinationPort(portNumber);
- matchBuilder.setLayer4Match(tcpMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(UdpSrc.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.udp.src._case.UdpSrc udpSrc = ((UdpSrcCase) ofMatch.getMatchEntryValue()).getUdpSrc();
- if (udpSrc != null) {
- udpMatchBuilder.setUdpSourcePort(udpSrc.getPort());
- matchBuilder.setLayer4Match(udpMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(UdpDst.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.udp.dst._case.UdpDst udpDst = ((UdpDstCase) ofMatch.getMatchEntryValue()).getUdpDst();
- if (udpDst != null) {
- udpMatchBuilder.setUdpDestinationPort(udpDst.getPort());
- matchBuilder.setLayer4Match(udpMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(SctpSrc.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.sctp.src._case.SctpSrc sctpSrc = ((SctpSrcCase) ofMatch.getMatchEntryValue()).getSctpSrc();
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber portNumber = sctpSrc.getPort();
- if (portNumber != null) {
- sctpMatchBuilder.setSctpSourcePort(portNumber);
- matchBuilder.setLayer4Match(sctpMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(SctpDst.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.sctp.dst._case.SctpDst sctpDst = ((SctpDstCase) ofMatch.getMatchEntryValue()).getSctpDst();
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber portNumber = sctpDst.getPort();
- if (portNumber != null) {
- sctpMatchBuilder.setSctpDestinationPort(portNumber);
- matchBuilder.setLayer4Match(sctpMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(Icmpv4Type.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.type._case.Icmpv4Type icmpv4Type = ((Icmpv4TypeCase) ofMatch.getMatchEntryValue()).getIcmpv4Type();
- Short type = icmpv4Type.getIcmpv4Type();
- if (type != null) {
- icmpv4MatchBuilder.setIcmpv4Type(type);
- matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(Icmpv4Code.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.code._case.Icmpv4Code icmpv4Code = ((Icmpv4CodeCase) ofMatch.getMatchEntryValue()).getIcmpv4Code();
- Short v4code = icmpv4Code.getIcmpv4Code();
- if (v4code != null) {
- icmpv4MatchBuilder.setIcmpv4Code(v4code);
- matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(Icmpv6Type.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv6.type._case.Icmpv6Type icmpv6Type = ((Icmpv6TypeCase) ofMatch.getMatchEntryValue()).getIcmpv6Type();
- Short v6type = icmpv6Type.getIcmpv6Type();
- if (v6type != null) {
- icmpv6MatchBuilder.setIcmpv6Type(v6type);
- matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(Icmpv6Code.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv6.code._case.Icmpv6Code icmpv6Code = ((Icmpv6CodeCase) ofMatch.getMatchEntryValue()).getIcmpv6Code();
- Short v6code = icmpv6Code.getIcmpv6Code();
- if (v6code != null) {
- icmpv6MatchBuilder.setIcmpv6Code(v6code);
- matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.src._case.Ipv4Src ipv4Address = ((Ipv4SrcCase) ofMatch.getMatchEntryValue()).getIpv4Src();
- if (ipv4Address != null) {
- byte[] mask = ipv4Address.getMask();
- if (mask != null && IpConversionUtil.isArbitraryBitMask(mask)) {
- // case where ipv4dst is of type ipv4MatchBuilder and ipv4src is of type ipv4MatchArbitrary.
- // Needs to convert ipv4dst to ipv4MatchArbitrary.
- if (ipv4MatchBuilder.getIpv4Destination() != null) {
- Ipv4Prefix ipv4PrefixDestinationAddress = ipv4MatchBuilder.getIpv4Destination();
- Ipv4Address ipv4DstAddress = IpConversionUtil.extractIpv4Address(ipv4PrefixDestinationAddress);
- DottedQuad dstDottedQuadMask = IpConversionUtil.extractIpv4AddressMask(ipv4PrefixDestinationAddress);
- setDstIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, ofMatch,
- dstDottedQuadMask, ipv4DstAddress.getValue());
- }
- DottedQuad srcDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
- String stringIpv4SrcAddress = ipv4Address.getIpv4Address().getValue();
- setSrcIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, ofMatch,
- srcDottedQuadMask, stringIpv4SrcAddress);
- matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
- } else if (ipv4MatchArbitraryBitMaskBuilder.getIpv4DestinationAddressNoMask() != null) {
- /*
- Case where destination is of type ipv4MatchArbitraryBitMask already exists in Layer3Match,
- source which of type ipv4Match needs to be converted to ipv4MatchArbitraryBitMask.
- We convert 36.36.36.0/24 to 36.36.0/255.255.255.0
- expected output example:-
- <ipv4-destination>36.36.36.0/24</ipv4-destination>
- <ipv4-source-address-no-mask>36.36.36.0</ipv4-source-address-no-mask>
- <ipv4-source-arbitrary-bitmask>255.0.255.0</ipv4-source-arbitrary-bitmask>
- after conversion output example:-
- <ipv4-destination-address-no-mask>36.36.36.0</ipv4-destination-address-no-mask>
- <ipv4-destination-arbitrary-bitmask>255.255.255.0</ipv4-destination-arbitrary-bitmask>
- <ipv4-source-address-no-mask>36.36.36.0</ipv4-source-address-no-mask>
- <ipv4-source-arbitrary-bitmask>255.0.255.0</ipv4-source-arbitrary-bitmask>
- */
- DottedQuad srcDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
- String stringIpv4SrcAddress = ipv4Address.getIpv4Address().getValue();
- setSrcIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, ofMatch,
- srcDottedQuadMask, stringIpv4SrcAddress);
- matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
- } else {
- String stringIpv4SrcAddress = ipv4Address.getIpv4Address().getValue();
- setIpv4MatchBuilderFields(ipv4MatchBuilder, ofMatch, mask, stringIpv4SrcAddress);
- matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
- }
- }
- } else if (ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.dst._case.Ipv4Dst ipv4Address = ((Ipv4DstCase) ofMatch.getMatchEntryValue()).getIpv4Dst();
- if (ipv4Address != null) {
- byte[] mask = ipv4Address.getMask();
- if (mask != null && IpConversionUtil.isArbitraryBitMask(mask)) {
- // case where ipv4src is of type ipv4MatchBuilder and ipv4dst is of type ipv4MatchArbitrary.
- // Needs to convert ipv4src to ipv4MatchArbitrary.
- if (ipv4MatchBuilder.getIpv4Source() != null) {
- Ipv4Prefix ipv4PrefixSourceAddress = ipv4MatchBuilder.getIpv4Source();
- Ipv4Address ipv4SourceAddress = IpConversionUtil.extractIpv4Address(ipv4PrefixSourceAddress);
- DottedQuad srcDottedQuad = IpConversionUtil.extractIpv4AddressMask(ipv4PrefixSourceAddress);
- setSrcIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder,ofMatch,
- srcDottedQuad, ipv4SourceAddress.getValue());
- }
- DottedQuad dstDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
- String stringIpv4DstAddress = ipv4Address.getIpv4Address().getValue();
- setDstIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, ofMatch,
- dstDottedQuadMask, stringIpv4DstAddress);
- matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
- } else if (ipv4MatchArbitraryBitMaskBuilder.getIpv4SourceAddressNoMask() != null) {
- /*
- Case where source is of type ipv4MatchArbitraryBitMask already exists in Layer3Match,
- destination which of type ipv4Match needs to be converted to ipv4MatchArbitraryBitMask.
- We convert 36.36.36.0/24 to 36.36.0/255.255.255.0
- expected output example:-
- <ipv4-source>36.36.36.0/24</ipv4-source>
- <ipv4-destination-address-no-mask>36.36.36.0</ipv4-destination-address-no-mask>
- <ipv4-destination-arbitrary-bitmask>255.0.255.0</ipv4-destination-arbitrary-bitmask>
- after conversion output example:-
- <ipv4-source-address-no-mask>36.36.36.0</ipv4-source-address-no-mask>
- <ipv4-source-arbitrary-bitmask>255.255.255.0</ipv4-source-arbitrary-bitmask>
- <ipv4-destination-address-no-mask>36.36.36.0</ipv4-destination-address-no-mask>
- <ipv4-destination-arbitrary-bitmask>255.0.255.0</ipv4-destination-arbitrary-bitmask>
- */
- DottedQuad dstDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
- String stringIpv4DstAddress = ipv4Address.getIpv4Address().getValue();
- setDstIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, ofMatch,
- dstDottedQuadMask, stringIpv4DstAddress);
- matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
- }
- else {
- String ipv4PrefixStr = ipv4Address.getIpv4Address().getValue();
- setIpv4MatchBuilderFields(ipv4MatchBuilder, ofMatch, mask, ipv4PrefixStr);
- matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
- }
- }
- } else if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)
- || ofMatch.getOxmMatchField().equals(TunnelIpv4Src.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.dst._case.Ipv4Dst tunnelIpv4Dst = ((Ipv4DstCase) ofMatch.getMatchEntryValue()).getIpv4Dst();
- if (tunnelIpv4Dst != null) {
- String ipv4PrefixStr = tunnelIpv4Dst.getIpv4Address().getValue();
- byte[] mask = tunnelIpv4Dst.getMask();
- ipv4PrefixStr += IpConversionUtil.PREFIX_SEPARATOR + ByteBuffer.wrap(tunnelIpv4Dst.getMask()).getInt();
- setIpv4MatchBuilderFields(ipv4MatchBuilder, ofMatch, mask, ipv4PrefixStr);
- matchBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(TunnelIpv4Src.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.src._case.Ipv4Src tunnelIpv4Dst = ((Ipv4SrcCase) ofMatch.getMatchEntryValue()).getIpv4Src();
- if (tunnelIpv4Dst != null) {
- String ipv4PrefixStr = tunnelIpv4Dst.getIpv4Address().getValue();
- byte[] mask = tunnelIpv4Dst.getMask();
- ipv4PrefixStr += IpConversionUtil.PREFIX_SEPARATOR + ByteBuffer.wrap(tunnelIpv4Dst.getMask()).getInt();
- setIpv4MatchBuilderFields(ipv4MatchBuilder, ofMatch, mask, ipv4PrefixStr);
- matchBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(ArpOp.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.op._case.ArpOp arpOp = ((ArpOpCase) ofMatch.getMatchEntryValue()).getArpOp();
- if (arpOp != null) {
- arpMatchBuilder.setArpOp(arpOp.getOpCode());
-
- matchBuilder.setLayer3Match(arpMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(ArpSpa.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.spa._case.ArpSpa arpSpa = ((ArpSpaCase) ofMatch.getMatchEntryValue()).getArpSpa();
- if (arpSpa != null) {
- int mask = 32;
- if (null != arpSpa.getMask()){
- mask = IpConversionUtil.countBits(arpSpa.getMask());
- }
- Ipv4Prefix ipv4Prefix = IpConversionUtil.createPrefix(arpSpa.getIpv4Address(), mask);
- arpMatchBuilder.setArpSourceTransportAddress(ipv4Prefix);
- matchBuilder.setLayer3Match(arpMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(ArpTpa.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.tpa._case.ArpTpa arpTpa = ((ArpTpaCase) ofMatch.getMatchEntryValue()).getArpTpa();
- if (arpTpa != null) {
- int mask = 32;
- if (null != arpTpa.getMask()){
- mask = IpConversionUtil.countBits(arpTpa.getMask());
- }
- Ipv4Prefix ipv4Prefix = IpConversionUtil.createPrefix(arpTpa.getIpv4Address(), mask);
-
- arpMatchBuilder.setArpTargetTransportAddress(ipv4Prefix);
- matchBuilder.setLayer3Match(arpMatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(ArpSha.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.sha._case.ArpSha arpSha = ((ArpShaCase) ofMatch.getMatchEntryValue()).getArpSha();
- MacAddress macAddress = arpSha.getMacAddress();
- if (macAddress != null) {
- if (ofMatch.getOxmMatchField().equals(ArpSha.class)) {
- ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
- arpSourceHardwareAddressBuilder.setAddress(macAddress);
- byte[] mask = arpSha.getMask();
- if (mask != null) {
- arpSourceHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
- .macAddressToString(mask)));
- }
- arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
- matchBuilder.setLayer3Match(arpMatchBuilder.build());
- }
- }
- } else if (ofMatch.getOxmMatchField().equals(ArpTha.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.tha._case.ArpTha arpTha = ((ArpThaCase) ofMatch.getMatchEntryValue()).getArpTha();
- MacAddress macAddress = arpTha.getMacAddress();
- if (macAddress != null) {
- if (ofMatch.getOxmMatchField().equals(ArpTha.class)) {
- ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
- arpTargetHardwareAddressBuilder.setAddress(macAddress);
- byte[] mask = arpTha.getMask();
- if (mask != null) {
- arpTargetHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
- .macAddressToString(mask)));
- }
- arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
- matchBuilder.setLayer3Match(arpMatchBuilder.build());
- }
- }
- } else if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.src._case.Ipv6Src ipv6Address = ((Ipv6SrcCase) ofMatch.getMatchEntryValue()).getIpv6Src();
- if (ipv6Address != null) {
- byte[] mask = ipv6Address.getMask();
- if (mask != null && IpConversionUtil.isIpv6ArbitraryBitMask(mask)) {
- // case where ipv6dst is of type ipv6MatchBuilder and ipv6src is of type ipv6MatchArbitrary.
- // Need to convert ipv6dst to ipv6MatchArbitrary.
-
- if (ipv6MatchBuilder.getIpv6Destination() != null) {
- Ipv6Prefix ipv6PrefixDestinationAddress = ipv6MatchBuilder.getIpv6Destination();
- Ipv6Address ipv6DstAddress = IpConversionUtil.extractIpv6Address(ipv6PrefixDestinationAddress);
- Ipv6ArbitraryMask dstIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(
- IpConversionUtil.extractIpv6AddressMask(ipv6PrefixDestinationAddress));
- setDstIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, ofMatch,
- dstIpv6ArbitraryMask, IpConversionUtil.compressedIpv6Format(ipv6DstAddress.getValue()));
- }
- Ipv6ArbitraryMask srcIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(
- IpConversionUtil.createIpv6ArbitraryBitMask(mask));
- String stringIpv6SrcAddress = IpConversionUtil.compressedIpv6Format(ipv6Address.getIpv6Address().getValue());
- setSrcIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, ofMatch,
- srcIpv6ArbitraryMask, stringIpv6SrcAddress);
- matchBuilder.setLayer3Match(ipv6MatchArbitraryBitMaskBuilder.build());
- } else if (ipv6MatchArbitraryBitMaskBuilder.getIpv6DestinationAddressNoMask() != null) {
- /*
- TODO Change comments
- Case where destination is of type ipv6MatchArbitraryBitMask already exists in Layer3Match,
- source which of type ipv6Match needs to be converted to ipv4MatchArbitraryBitMask.
- We convert 1::/32 to 1::/FFFF:FFFF::
- example:-
- <ipv6-source>1::/32</ipv4-source>
- <ipv6-destination-address-no-mask>1::1</ipv6-destination-address-no-mask>
- <ipv6-destination-arbitrary-bitmask>FFFF::0001</ipv6-destination-arbitrary-bitmask>
- after conversion output example:-
- <ipv6-source-address-no-mask>1::</ipv6-source-address-no-mask>
- <ipv6-source-arbitrary-bitmask>FFFF:FFFF::</ipv6-source-arbitrary-bitmask>
- <ipv6-destination-address-no-mask>1::1</ipv6-destination-address-no-mask>
- <ipv6-destination-arbitrary-bitmask>FFFF::0001</ipv6-destination-arbitrary-bitmask>
- */
- Ipv6ArbitraryMask srcIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(
- IpConversionUtil.createIpv6ArbitraryBitMask(mask));
- String stringIpv6SrcAddress = IpConversionUtil.compressedIpv6Format(ipv6Address.getIpv6Address().getValue());
- setSrcIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, ofMatch,
- srcIpv6ArbitraryMask, stringIpv6SrcAddress);
- matchBuilder.setLayer3Match(ipv6MatchArbitraryBitMaskBuilder.build());
- } else {
- String stringIpv6SrcAddress = IpConversionUtil.compressedIpv6Format(ipv6Address.getIpv6Address().getValue());
- setIpv6MatchBuilderFields(ipv6MatchBuilder, ofMatch, mask, stringIpv6SrcAddress);
- matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
- }
- }
- } else if (ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.dst._case.Ipv6Dst ipv6Address = ((Ipv6DstCase) ofMatch.getMatchEntryValue()).getIpv6Dst();
- if (ipv6Address != null) {
- byte[] mask = ipv6Address.getMask();
- if (mask != null && IpConversionUtil.isIpv6ArbitraryBitMask(mask)) {
- // case where ipv6src is of type ipv6MatchBuilder and ipv6dst is of type ipv6MatchArbitrary.
- // Need to convert ipv6src to ipv6MatchArbitrary.
-
- if (ipv6MatchBuilder.getIpv6Source() != null) {
- Ipv6Prefix ipv6PrefixSourceAddress = ipv6MatchBuilder.getIpv6Source();
- Ipv6Address ipv6SrcAddress = IpConversionUtil.extractIpv6Address(ipv6PrefixSourceAddress);
- Ipv6ArbitraryMask srcIpv6Arbitrary = IpConversionUtil.compressedIpv6MaskFormat(
- IpConversionUtil.extractIpv6AddressMask(ipv6PrefixSourceAddress));
- setSrcIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, ofMatch,
- srcIpv6Arbitrary, IpConversionUtil.compressedIpv6Format(ipv6SrcAddress.getValue()));
- }
- Ipv6ArbitraryMask dstIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(
- IpConversionUtil.createIpv6ArbitraryBitMask(mask));
- String stringIpv6DstAddress = IpConversionUtil.compressedIpv6Format(ipv6Address.getIpv6Address().getValue());
- setDstIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, ofMatch,
- dstIpv6ArbitraryMask, stringIpv6DstAddress);
- matchBuilder.setLayer3Match(ipv6MatchArbitraryBitMaskBuilder.build());
- } else if (ipv6MatchArbitraryBitMaskBuilder.getIpv6SourceAddressNoMask() != null) {
- /*
- TODO Change comments
- Case where source is of type ipv4MatchArbitraryBitMask already exists in Layer3Match,
- source which of type ipv6Match needs to be converted to ipv6MatchArbitraryBitMask.
- We convert 1::/32 to 1::/FFFF:FFFF::
- example:-
- <ipv6-destination>1::/32</ipv6-destination>
- <ipv6-source-address-no-mask>1::1</ipv6-source-address-no-mask>
- <ipv6-source-arbitrary-bitmask>FFFF::0001</ipv6-source-arbitrary-bitmask>
- after conversion output example:-
- <ipv6-destination-address-no-mask>1::</ipv6-destination-address-no-mask>
- <ipv6-destination-arbitrary-bitmask>FFFF:FFFF::</ipv6-destination-arbitrary-bitmask>
- <ipv6-source-address-no-mask>1::1</ipv6-source-address-no-mask>
- <ipv6-source-arbitrary-bitmask>FFFF::0001</ipv6-source-arbitrary-bitmask>
- */
- Ipv6ArbitraryMask dstIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(
- IpConversionUtil.createIpv6ArbitraryBitMask(mask));
- String stringIpv6DstAddress = IpConversionUtil.compressedIpv6Format(ipv6Address.getIpv6Address().getValue());
- setDstIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, ofMatch,
- dstIpv6ArbitraryMask, stringIpv6DstAddress);
- matchBuilder.setLayer3Match(ipv6MatchArbitraryBitMaskBuilder.build());
- } else {
- String stringIpv6DstAddress = IpConversionUtil.compressedIpv6Format(ipv6Address.getIpv6Address().getValue());
- setIpv6MatchBuilderFields(ipv6MatchBuilder, ofMatch, mask, stringIpv6DstAddress);
- matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
- }
- }
- } else if (ofMatch.getOxmMatchField().equals(Ipv6Flabel.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.flabel._case.Ipv6Flabel ipv6Flabel = ((Ipv6FlabelCase) ofMatch.getMatchEntryValue()).getIpv6Flabel();
- if (ipv6Flabel != null) {
- Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
- ipv6LabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(ipv6Flabel.getIpv6Flabel()));
- byte[] mask = ipv6Flabel.getMask();
- if (mask != null) {
- ipv6LabelBuilder.setFlabelMask(new Ipv6FlowLabel(Long.valueOf(ByteUtil
- .bytesToUnsignedInt(mask))));
- }
- ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
- matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTarget.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.nd.target._case.Ipv6NdTarget ipv6NdTarget = ((Ipv6NdTargetCase) ofMatch.getMatchEntryValue()).getIpv6NdTarget();
- if (ipv6NdTarget != null) {
- ipv6MatchBuilder.setIpv6NdTarget(ipv6NdTarget.getIpv6Address());
- matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(Ipv6NdSll.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.nd.sll._case.Ipv6NdSll ipv6NdSll = ((Ipv6NdSllCase) ofMatch.getMatchEntryValue()).getIpv6NdSll();
- if (ipv6NdSll != null) {
- ipv6MatchBuilder.setIpv6NdSll(ipv6NdSll.getMacAddress());
- matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTll.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.nd.tll._case.Ipv6NdTll ipv6NdTll = ((Ipv6NdTllCase) ofMatch.getMatchEntryValue()).getIpv6NdTll();
- if (ipv6NdTll != null) {
- ipv6MatchBuilder.setIpv6NdTll(ipv6NdTll.getMacAddress());
- matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(Ipv6Exthdr.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.exthdr._case.Ipv6Exthdr ipv6Exthdr = ((Ipv6ExthdrCase) ofMatch.getMatchEntryValue()).getIpv6Exthdr();
- if (ipv6Exthdr != null) {
- Ipv6ExtHeaderBuilder ipv6ExtHeaderBuilder = new Ipv6ExtHeaderBuilder();
-
- Ipv6ExthdrFlags pField = ipv6Exthdr.getPseudoField();
- Integer bitmap = MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField);
-
- ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
- byte[] mask = ipv6Exthdr.getMask();
- if (mask != null) {
- ipv6ExtHeaderBuilder.setIpv6ExthdrMask(ByteUtil.bytesToUnsignedShort(mask));
- }
- ipv6MatchBuilder.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
- matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(MplsLabel.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.label._case.MplsLabel mplsLabel = ((MplsLabelCase) ofMatch.getMatchEntryValue()).getMplsLabel();
- if (mplsLabel != null) {
- protocolMatchFieldsBuilder.setMplsLabel(mplsLabel.getMplsLabel());
- matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(MplsBos.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.bos._case.MplsBos mplsBos = ((MplsBosCase) ofMatch.getMatchEntryValue()).getMplsBos();
- if (mplsBos != null) {
- protocolMatchFieldsBuilder.setMplsBos(mplsBos.isBos() ? (short) 1 : (short) 0);
- matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(MplsTc.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.tc._case.MplsTc mplsTc = ((MplsTcCase) ofMatch.getMatchEntryValue()).getMplsTc();
- if (mplsTc != null) {
- protocolMatchFieldsBuilder.setMplsTc(mplsTc.getTc());
- matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(PbbIsid.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.pbb.isid._case.PbbIsid pbbIsid = ((PbbIsidCase) ofMatch.getMatchEntryValue()).getPbbIsid();
- if (pbbIsid != null) {
- PbbBuilder pbbBuilder = new PbbBuilder();
- pbbBuilder.setPbbIsid(pbbIsid.getIsid());
- byte[] mask = pbbIsid.getMask();
- if (mask != null) {
- pbbBuilder.setPbbMask(ByteUtil.bytesToUnsignedMedium(mask));
- }
- protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
- matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(TunnelId.class)) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tunnel.id._case.TunnelId tunnelId = ((TunnelIdCase) ofMatch.getMatchEntryValue()).getTunnelId();
- TunnelBuilder tunnelBuilder = new TunnelBuilder();
- if (tunnelId.getTunnelId()!= null) {
- tunnelBuilder.setTunnelId(new BigInteger(OFConstants.SIGNUM_UNSIGNED, tunnelId.getTunnelId()));
- byte[] mask = tunnelId.getMask();
- if (null != mask) {
- tunnelBuilder.setTunnelMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, mask));
- }
- matchBuilder.setTunnel(tunnelBuilder.build());
- }
- } else if (ofMatch.getOxmMatchField().equals(TcpFlags.class)) {
- ExperimenterIdCase experimenterIdCase = ((ExperimenterIdCase) ofMatch.getMatchEntryValue());
- TcpFlagsContainer tcpFlagsContainer = experimenterIdCase.getAugmentation(TcpFlagsContainer.class);
-
- if (tcpFlagsContainer != null) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.
- approved.extensions.rev160802.oxm.container.match.entry.
- value.experimenter.id._case.TcpFlags tcpFlags = tcpFlagsContainer.getTcpFlags();
-
- tcpFlagsMatchBuilder.setTcpFlags(tcpFlags.getFlags());
- byte[] mask = tcpFlags.getMask();
- if (mask != null) {
- tcpFlagsMatchBuilder.setTcpFlagsMask(ByteUtil.bytesToUnsignedShort(mask));
- }
- matchBuilder.setTcpFlagsMatch(tcpFlagsMatchBuilder.build());
- }