BUG-1994: IP ToS bits match field for OF 1.0
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / MatchConvertorV10Impl.java
index 64fa7233d8c01701570ec4a92512c2ddee87c42f..0bf080c5680ee9425b8578a3ddb26b2ad271290a 100644 (file)
@@ -8,7 +8,12 @@
 
 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
 
+import java.math.BigInteger;
+import java.util.Iterator;
+
+import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
+import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
@@ -25,9 +30,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
 
-import java.math.BigInteger;
-import java.util.Iterator;
-
 /**
  *
  */
@@ -42,7 +44,7 @@ public class MatchConvertorV10Impl implements MatchConvertor<MatchV10> {
      * The value 0xffff (OFP_VLAN_NONE) is used to indicate
      * that no VLAN ID is set for OF Flow.
      */
-    private static final int OFP_VLAN_NONE = (int) 0xffff;
+    private static final int OFP_VLAN_NONE = 0xffff;
 
     /**
      * Method builds openflow 1.0 specific match (MatchV10) from MD-SAL match.
@@ -79,44 +81,46 @@ public class MatchConvertorV10Impl implements MatchConvertor<MatchV10> {
         matchBuilder.setTpSrc(0);
         matchBuilder.setTpDst(0);
 
-        EthernetMatch ethernetMatch = match.getEthernetMatch();
-        if(ethernetMatch!= null){
-            _dLDST = convertEthernetDlDst(matchBuilder, ethernetMatch);
-            _dLSRC = convertEthernetDlSrc(matchBuilder, ethernetMatch);
-            _dLTYPE = convertEthernetDlType(matchBuilder, ethernetMatch);
-        }
-        VlanMatch vlanMatch = match.getVlanMatch();
-        if(vlanMatch!= null){
-            _dLVLAN = convertDlVlan(matchBuilder, vlanMatch);
-            _dLVLANPCP = convertDlVlanPcp(matchBuilder, vlanMatch);
-        }
-        NodeConnectorId inPort = match.getInPort();
-        if(inPort!=null){
-            _iNPORT = convertInPortMatch(matchBuilder, inPort);
-        }
-        Layer3Match l3Match = match.getLayer3Match();
-        if(l3Match != null){
-            if(l3Match instanceof Ipv4Match){
-                Ipv4Match ipv4 = (Ipv4Match)l3Match;
-                _tPSRC = convertL3Ipv4SrcMatch(matchBuilder, ipv4);
-                _tPDST = convertL3Ipv4DstMatch(matchBuilder, ipv4);
+        if (match != null) {
+            EthernetMatch ethernetMatch = match.getEthernetMatch();
+            if(ethernetMatch!= null){
+                _dLDST = convertEthernetDlDst(matchBuilder, ethernetMatch);
+                _dLSRC = convertEthernetDlSrc(matchBuilder, ethernetMatch);
+                _dLTYPE = convertEthernetDlType(matchBuilder, ethernetMatch);
             }
-        }
-        IpMatch ipMatch = match.getIpMatch();
-        if(ipMatch!=null){
-            _nWPROTO = convertNwProto(matchBuilder, ipMatch);
-            _nWTOS = convertNwTos(matchBuilder, ipMatch);
-        }
-        Layer4Match layer4Match = match.getLayer4Match();
-        if (layer4Match != null) {
-            if (layer4Match instanceof TcpMatch) {
-                TcpMatch tcpMatch = (TcpMatch) layer4Match;
-                _tPSRC = convertL4TpSrcMatch(matchBuilder, tcpMatch);
-                _tPDST = convertL4TpDstMatch(matchBuilder, tcpMatch);
-            } else if (layer4Match instanceof UdpMatch) {
-                UdpMatch udpMatch = (UdpMatch) layer4Match;
-                _tPSRC = convertL4UdpSrcMatch(matchBuilder, udpMatch);
-                _tPDST = convertL4UdpDstMatch(matchBuilder, udpMatch);
+            VlanMatch vlanMatch = match.getVlanMatch();
+            if(vlanMatch!= null){
+                _dLVLAN = convertDlVlan(matchBuilder, vlanMatch);
+                _dLVLANPCP = convertDlVlanPcp(matchBuilder, vlanMatch);
+            }
+            NodeConnectorId inPort = match.getInPort();
+            if(inPort!=null){
+                _iNPORT = convertInPortMatch(matchBuilder, inPort);
+            }
+            Layer3Match l3Match = match.getLayer3Match();
+            if(l3Match != null){
+                if(l3Match instanceof Ipv4Match){
+                    Ipv4Match ipv4 = (Ipv4Match)l3Match;
+                    _tPSRC = convertL3Ipv4SrcMatch(matchBuilder, ipv4);
+                    _tPDST = convertL3Ipv4DstMatch(matchBuilder, ipv4);
+                }
+            }
+            IpMatch ipMatch = match.getIpMatch();
+            if(ipMatch!=null){
+                _nWPROTO = convertNwProto(matchBuilder, ipMatch);
+                _nWTOS = convertNwTos(matchBuilder, ipMatch);
+            }
+            Layer4Match layer4Match = match.getLayer4Match();
+            if (layer4Match != null) {
+                if (layer4Match instanceof TcpMatch) {
+                    TcpMatch tcpMatch = (TcpMatch) layer4Match;
+                    _tPSRC = convertL4TpSrcMatch(matchBuilder, tcpMatch);
+                    _tPDST = convertL4TpDstMatch(matchBuilder, tcpMatch);
+                } else if (layer4Match instanceof UdpMatch) {
+                    UdpMatch udpMatch = (UdpMatch) layer4Match;
+                    _tPSRC = convertL4UdpSrcMatch(matchBuilder, udpMatch);
+                    _tPDST = convertL4UdpDstMatch(matchBuilder, udpMatch);
+                }
             }
         }
 
@@ -192,7 +196,7 @@ public class MatchConvertorV10Impl implements MatchConvertor<MatchV10> {
     private static boolean convertNwTos(final MatchV10Builder matchBuilder,
             final IpMatch ipMatch) {
         if (ipMatch.getIpDscp() != null) {
-            matchBuilder.setNwTos(ipMatch.getIpDscp().getValue());
+            matchBuilder.setNwTos(ActionUtil.dscpToTos(ipMatch.getIpDscp().getValue()));
             return false;
         }
         return true;
@@ -336,7 +340,7 @@ public class MatchConvertorV10Impl implements MatchConvertor<MatchV10> {
      */
     private static boolean convertInPortMatch(final MatchV10Builder matchBuilder, final NodeConnectorId inPort) {
         if (inPort != null) {
-            matchBuilder.setInPort(InventoryDataServiceUtil.portNumberfromNodeConnectorId(inPort).intValue());
+            matchBuilder.setInPort(InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF10, inPort).intValue());
             return false;
         }
         return true;