Bump upstreams
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / MatchV10ResponseConvertor.java
index 790e4791dd2ab213d92d44ece3d85e67f12da975..662ff0d3a04fc41355881fccffc6244d92f2eef9 100644 (file)
@@ -5,10 +5,8 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
 
-import java.math.BigInteger;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Set;
@@ -33,12 +31,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10;
-import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 /**
- * Converts Openflow 1.0 specific flow match to MD-SAL format flow
- * match
+ * Converts Openflow 1.0 specific flow match to MD-SAL format flow match.
  *
+ * <p>
  * Example usage:
  * <pre>
  * {@code
@@ -61,86 +62,90 @@ public class MatchV10ResponseConvertor extends Convertor<MatchV10, MatchBuilder,
     }
 
     @Override
-    public MatchBuilder convert(MatchV10 source, VersionDatapathIdConvertorData datapathIdConvertorData) {
+    public MatchBuilder convert(final MatchV10 source, final VersionDatapathIdConvertorData datapathIdConvertorData) {
         MatchBuilder matchBuilder = new MatchBuilder();
         EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
         VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
         Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
         IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
         OpenflowVersion ofVersion = OpenflowVersion.get(datapathIdConvertorData.getVersion());
-        BigInteger datapathid = datapathIdConvertorData.getDatapathId();
+        Uint64 datapathid = datapathIdConvertorData.getDatapathId();
 
-        if (!source.getWildcards().isINPORT() && source.getInPort() != null) {
+        if (!source.getWildcards().getINPORT() && source.getInPort() != null) {
             matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
-                    (long) source.getInPort(), ofVersion));
+                    Uint32.valueOf(source.getInPort()), ofVersion));
         }
 
-        if (!source.getWildcards().isDLSRC() && source.getDlSrc() != null) {
+        if (!source.getWildcards().getDLSRC() && source.getDlSrc() != null) {
             EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
             ethSrcBuilder.setAddress(source.getDlSrc());
             ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
             matchBuilder.setEthernetMatch(ethMatchBuilder.build());
         }
-        if (!source.getWildcards().isDLDST() && source.getDlDst() != null) {
+        if (!source.getWildcards().getDLDST() && source.getDlDst() != null) {
             EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
             ethDstBuilder.setAddress(source.getDlDst());
             ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
             matchBuilder.setEthernetMatch(ethMatchBuilder.build());
         }
-        if (!source.getWildcards().isDLTYPE() && source.getDlType() != null) {
+        if (!source.getWildcards().getDLTYPE() && source.getDlType() != null) {
             EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
             ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType(
-                    (long) source.getDlType()));
+                    Uint32.valueOf(source.getDlType())));
             ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
             matchBuilder.setEthernetMatch(ethMatchBuilder.build());
         }
-        if (!source.getWildcards().isDLVLAN() && source.getDlVlan() != null) {
-            VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
-            int vlanId = (source.getDlVlan() == (0xffff)) ? 0 : source.getDlVlan();
-            vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
-            vlanIdBuilder.setVlanIdPresent(vlanId != 0);
-            vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
+        if (!source.getWildcards().getDLVLAN() && source.getDlVlan() != null) {
+            Uint16 vlanId = source.getDlVlan();
+            if (vlanId.toJava() == 0xffff) {
+                vlanId = Uint16.ZERO;
+            }
+
+            vlanMatchBuilder.setVlanId(new VlanIdBuilder()
+                .setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId))
+                .setVlanIdPresent(!Uint16.ZERO.equals(vlanId))
+                .build());
             matchBuilder.setVlanMatch(vlanMatchBuilder.build());
         }
-        if (!source.getWildcards().isDLVLANPCP() && source.getDlVlanPcp() != null) {
+        if (!source.getWildcards().getDLVLANPCP() && source.getDlVlanPcp() != null) {
             vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(
                     source.getDlVlanPcp()));
             matchBuilder.setVlanMatch(vlanMatchBuilder.build());
         }
-        if (!source.getWildcards().isDLTYPE() && source.getNwSrc() != null) {
+        if (!source.getWildcards().getDLTYPE() && source.getNwSrc() != null) {
             final Ipv4Prefix prefix;
             if (source.getNwSrcMask() != null) {
-                prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwSrc(), source.getNwSrcMask());
+                prefix = IetfInetUtil.ipv4PrefixFor(source.getNwSrc(), source.getNwSrcMask().toJava());
             } else {
                 //Openflow Spec : 1.3.2
                 //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
                 // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
                 // statistics response.
-                prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwSrc());
+                prefix = IetfInetUtil.ipv4PrefixFor(source.getNwSrc());
             }
             if (!NO_IP.equals(prefix.getValue())) {
                 ipv4MatchBuilder.setIpv4Source(prefix);
                 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
             }
         }
-        if (!source.getWildcards().isDLTYPE() && source.getNwDst() != null) {
+        if (!source.getWildcards().getDLTYPE() && source.getNwDst() != null) {
             final Ipv4Prefix prefix;
             if (source.getNwDstMask() != null) {
-                prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwDst(), source.getNwDstMask());
+                prefix = IetfInetUtil.ipv4PrefixFor(source.getNwDst(), source.getNwDstMask().toJava());
             } else {
                 //Openflow Spec : 1.3.2
                 //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
                 // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
                 // statistics response.
-                prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwDst());
+                prefix = IetfInetUtil.ipv4PrefixFor(source.getNwDst());
             }
             if (!NO_IP.equals(prefix.getValue())) {
                 ipv4MatchBuilder.setIpv4Destination(prefix);
                 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
             }
         }
-        if (!source.getWildcards().isNWPROTO() && source.getNwProto() != null) {
-            Short nwProto = source.getNwProto();
+        if (!source.getWildcards().getNWPROTO() && source.getNwProto() != null) {
+            Uint8 nwProto = source.getNwProto();
             ipMatchBuilder.setIpProtocol(nwProto);
             matchBuilder.setIpMatch(ipMatchBuilder.build());
 
@@ -148,16 +153,14 @@ public class MatchV10ResponseConvertor extends Convertor<MatchV10, MatchBuilder,
             if (proto == PROTO_TCP) {
                 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
                 boolean hasTcp = false;
-                if (!source.getWildcards().isTPSRC() && source.getTpSrc() != null) {
-                    tcpMatchBuilder
-                            .setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(
-                                    source.getTpSrc()));
+                if (!source.getWildcards().getTPSRC() && source.getTpSrc() != null) {
+                    tcpMatchBuilder.setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
+                            .inet.types.rev130715.PortNumber(source.getTpSrc()));
                     hasTcp = true;
                 }
-                if (!source.getWildcards().isTPDST() && source.getTpDst() != null) {
-                    tcpMatchBuilder
-                            .setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(
-                                    source.getTpDst()));
+                if (!source.getWildcards().getTPDST() && source.getTpDst() != null) {
+                    tcpMatchBuilder.setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
+                            .ietf.inet.types.rev130715.PortNumber(source.getTpDst()));
                     hasTcp = true;
                 }
 
@@ -167,16 +170,14 @@ public class MatchV10ResponseConvertor extends Convertor<MatchV10, MatchBuilder,
             } else if (proto == PROTO_UDP) {
                 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
                 boolean hasUdp = false;
-                if (!source.getWildcards().isTPSRC() && source.getTpSrc() != null) {
-                    udpMatchBuilder
-                            .setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(
-                                    source.getTpSrc()));
+                if (!source.getWildcards().getTPSRC() && source.getTpSrc() != null) {
+                    udpMatchBuilder.setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
+                            .inet.types.rev130715.PortNumber(source.getTpSrc()));
                     hasUdp = true;
                 }
-                if (!source.getWildcards().isTPDST() && source.getTpDst() != null) {
-                    udpMatchBuilder
-                            .setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(
-                                    source.getTpDst()));
+                if (!source.getWildcards().getTPDST() && source.getTpDst() != null) {
+                    udpMatchBuilder.setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
+                            .ietf.inet.types.rev130715.PortNumber(source.getTpDst()));
                     hasUdp = true;
                 }
 
@@ -186,17 +187,17 @@ public class MatchV10ResponseConvertor extends Convertor<MatchV10, MatchBuilder,
             } else if (proto == PROTO_ICMPV4) {
                 Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
                 boolean hasIcmpv4 = false;
-                if (!source.getWildcards().isTPSRC()) {
-                    Integer type = source.getTpSrc();
+                if (!source.getWildcards().getTPSRC()) {
+                    Uint16 type = source.getTpSrc();
                     if (type != null) {
-                        icmpv4MatchBuilder.setIcmpv4Type(type.shortValue());
+                        icmpv4MatchBuilder.setIcmpv4Type(type.toUint8());
                         hasIcmpv4 = true;
                     }
                 }
-                if (!source.getWildcards().isTPDST()) {
-                    Integer code = source.getTpDst();
+                if (!source.getWildcards().getTPDST()) {
+                    Uint16 code = source.getTpDst();
                     if (code != null) {
-                        icmpv4MatchBuilder.setIcmpv4Code(code.shortValue());
+                        icmpv4MatchBuilder.setIcmpv4Code(code.toUint8());
                         hasIcmpv4 = true;
                     }
                 }
@@ -206,9 +207,8 @@ public class MatchV10ResponseConvertor extends Convertor<MatchV10, MatchBuilder,
                 }
             }
         }
-        if (!source.getWildcards().isNWTOS() && source.getNwTos() != null) {
-            Short dscp = ActionUtil.tosToDscp(source.getNwTos());
-            ipMatchBuilder.setIpDscp(new Dscp(dscp));
+        if (!source.getWildcards().getNWTOS() && source.getNwTos() != null) {
+            ipMatchBuilder.setIpDscp(new Dscp(ActionUtil.tosToDscp(source.getNwTos())));
             matchBuilder.setIpMatch(ipMatchBuilder.build());
         }