BUG-1759 ip-tos value 14/11114/2
authorMichal Rehak <mirehak@cisco.com>
Fri, 12 Sep 2014 13:48:06 +0000 (15:48 +0200)
committerEd Warnicke <eaw@cisco.com>
Tue, 16 Sep 2014 16:08:26 +0000 (16:08 +0000)
- added shift from tos to dscp fro OF-1.3

Change-Id: I4a2f8dc968aeda2538b56c3b9420e5d8cfe582a3
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertor.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/ActionUtil.java [new file with mode: 0644]
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/util/ActionUtilTest.java [new file with mode: 0644]

index 9aaf98da1c12bfc8588625e6561083992d7fbfdc..796b3e716430bc502178d9122ca70e4dc196c69c 100644 (file)
@@ -10,6 +10,7 @@
 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
 
 import com.google.common.collect.Ordering;
+
 import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
@@ -23,6 +24,7 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Ord
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
+import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
@@ -166,7 +168,7 @@ import java.util.List;
  */
 public final class ActionConvertor {
     private static final Logger logger = LoggerFactory.getLogger(ActionConvertor.class);
-
+    
     private ActionConvertor() {
         // NOOP
     }
@@ -616,7 +618,9 @@ public final class ActionConvertor {
             actionBuilder
                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
             List<MatchEntries> matchEntriesList = new ArrayList<>();
-            matchEntriesList.add(MatchConvertorImpl.toOfIpDscp(new Dscp(setnwtosaction.getTos().shortValue())));
+            matchEntriesList.add(MatchConvertorImpl.toOfIpDscp(new Dscp(
+                    ActionUtil.tosToDscp(setnwtosaction.getTos().shortValue())
+                    )));
             oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
             actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
             return actionBuilder.build();
diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/ActionUtil.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/ActionUtil.java
new file mode 100644 (file)
index 0000000..18ef67a
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+ * Copyright IBM Corporation, 2013.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.util;
+
+
+/**
+ * OF-action related utilities
+ */
+public final class ActionUtil {
+
+    /** http://en.wikipedia.org/wiki/IPv4#Packet_structure (end of octet number 1, bit 14.+15.) */
+    public static final int ENC_FIELD_BIT_SIZE = 2;
+
+    private ActionUtil() {
+        throw new AssertionError("ActionUtil is not expected to be instantiated.");
+    }
+
+    /**
+     * @param tosValue TypeOfService value
+     * @return DSCP value
+     */
+    public static Short tosToDscp(short tosValue) {
+        return (short) (tosValue >>> ActionUtil.ENC_FIELD_BIT_SIZE);
+    }
+
+    
+}
diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/util/ActionUtilTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/util/ActionUtilTest.java
new file mode 100644 (file)
index 0000000..2754739
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ * 
+ * This program and the accompanying materials are made available under the
+ * 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.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+/**
+ * test of {@link ActionUtil}
+ */
+public class ActionUtilTest {
+
+    /**
+     * Test method for {@link org.opendaylight.openflowplugin.openflow.md.util.ActionUtil#tosToDscp(short)}.
+     */
+    @Test
+    public void testTosToDscp() {
+        Assert.assertEquals(0, ActionUtil.tosToDscp((short) 1).intValue());
+        Assert.assertEquals(1, ActionUtil.tosToDscp((short) 4).intValue());
+        Assert.assertEquals(63, ActionUtil.tosToDscp((short) 252).intValue());
+    }
+
+}