From 6972017f3024553bda17a9cd0683a40394b185ec Mon Sep 17 00:00:00 2001 From: Michal Rehak Date: Mon, 29 Sep 2014 15:40:46 +0200 Subject: [PATCH] BUG-1994: IP ToS bits match field for OF 1.0 - fixed TOS conversion for match by OF-1.0 Change-Id: I57449e4b8413801e890e8add31819dbc39dc6190 Signed-off-by: Michal Rehak --- .../sal/convertor/match/MatchConvertorV10Impl.java | 5 +++-- .../openflowplugin/openflow/md/util/ActionUtil.java | 8 ++++++++ .../openflow/md/util/ActionUtilTest.java | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java index 4c45e06b0d..0bf080c568 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java @@ -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 { * 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 { 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; 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 index 18ef67a411..a416f59b5e 100644 --- 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 @@ -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); + } } 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 index 2754739b67..560d6a3fe5 100644 --- 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 @@ -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()); + } } -- 2.36.6