BUG-1994: IP ToS bits match field for OF 1.0 61/11661/1
authorMichal Rehak <mirehak@cisco.com>
Mon, 29 Sep 2014 13:40:46 +0000 (15:40 +0200)
committerMichal Rehak <mirehak@cisco.com>
Mon, 29 Sep 2014 13:45:05 +0000 (15:45 +0200)
- fixed TOS conversion for match by OF-1.0

Change-Id: I57449e4b8413801e890e8add31819dbc39dc6190
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/ActionUtil.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/util/ActionUtilTest.java

index 4c45e06b0daa147865b41fb36894a1c2ea82dbbe..0bf080c5680ee9425b8578a3ddb26b2ad271290a 100644 (file)
@@ -11,6 +11,7 @@ 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;
@@ -43,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.
@@ -195,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;
index 18ef67a41143c3ced55df728e145ba1151e1c370..a416f59b5ec473d67703886bd427678f4a5078a5 100644 (file)
@@ -27,6 +27,14 @@ public final class ActionUtil {
     public static Short tosToDscp(short tosValue) {
         return (short) (tosValue >>> ActionUtil.ENC_FIELD_BIT_SIZE);
     }
+    
+    /**
+     * @param dscpValue TypeOfService value
+     * @return TOS value
+     */
+    public static Short dscpToTos(short dscpValue) {
+        return (short) (dscpValue << ActionUtil.ENC_FIELD_BIT_SIZE);
+    }
 
     
 }
index 2754739b6763597729db1a584bedc0ffab93e317..560d6a3fe535cac994d8e60a4369a32dba9bc168 100644 (file)
@@ -24,4 +24,14 @@ public class ActionUtilTest {
         Assert.assertEquals(63, ActionUtil.tosToDscp((short) 252).intValue());
     }
 
+    /**
+     * Test method for {@link org.opendaylight.openflowplugin.openflow.md.util.ActionUtil#dscpToTos(short)}.
+     */
+    @Test
+    public void testDscpToTos() {
+        Assert.assertEquals(0, ActionUtil.dscpToTos((short) 0).intValue());
+        Assert.assertEquals(4, ActionUtil.dscpToTos((short) 1).intValue());
+        Assert.assertEquals(16, ActionUtil.dscpToTos((short) 4).intValue());
+        Assert.assertEquals(252, ActionUtil.dscpToTos((short) 63).intValue());
+    }
 }