Fixed a bug that failed specifying the value 0 on VLAN ID field for a match condition... 47/747/1
authorHideyuki Tai <h-tai@cd.jp.nec.com>
Tue, 30 Jul 2013 17:03:10 +0000 (13:03 -0400)
committerHideyuki Tai <h-tai@cd.jp.nec.com>
Tue, 30 Jul 2013 17:03:10 +0000 (13:03 -0400)
- Fixed MatchType class to allow the value 0 on VLAN ID field for VLAN untagged frames.
- Changed FlowConverter class to convert the value 0 on VLAN ID field of SAL Flow into the value 0xffff of OF Flow, and vice-versa.

Signed-off-by: Hideyuki Tai <h-tai@cd.jp.nec.com>
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java
opendaylight/protocol_plugins/openflow/src/test/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerServiceTest.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchType.java
opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/match/MatchTest.java

index 756a6895dc06e19ef0fbcbd85314c3fb0abdc645..2b8f6553d61cb6202f0576b92b4b5890bc30e7f5 100644 (file)
@@ -76,6 +76,13 @@ import org.slf4j.LoggerFactory;
 public class FlowConverter {
     protected static final Logger logger = LoggerFactory
             .getLogger(FlowConverter.class);
 public class FlowConverter {
     protected static final Logger logger = LoggerFactory
             .getLogger(FlowConverter.class);
+
+    /*
+     * The value 0xffff (OFP_VLAN_NONE) is used to indicate
+     * that no VLAN ID is set for OF Flow.
+     */
+    private static final short OFP_VLAN_NONE = (short) 0xffff;
+
     private Flow flow; // SAL Flow
     private OFMatch ofMatch; // OF 1.0 match or OF 1.0 + IPv6 extension match
     private List<OFAction> actionsList; // OF 1.0 actions
     private Flow flow; // SAL Flow
     private OFMatch ofMatch; // OF 1.0 match or OF 1.0 + IPv6 extension match
     private List<OFAction> actionsList; // OF 1.0 actions
@@ -143,6 +150,9 @@ public class FlowConverter {
             if (match.isPresent(MatchType.DL_VLAN)) {
                 short vlan = (Short) match.getField(MatchType.DL_VLAN)
                         .getValue();
             if (match.isPresent(MatchType.DL_VLAN)) {
                 short vlan = (Short) match.getField(MatchType.DL_VLAN)
                         .getValue();
+                if (vlan == MatchType.DL_VLAN_NONE) {
+                    vlan = OFP_VLAN_NONE;
+                }
                 if (!isIPv6) {
                     ofMatch.setDataLayerVirtualLan(vlan);
                     wildcards &= ~OFMatch.OFPFW_DL_VLAN;
                 if (!isIPv6) {
                     ofMatch.setDataLayerVirtualLan(vlan);
                     wildcards &= ~OFMatch.OFPFW_DL_VLAN;
@@ -514,9 +524,13 @@ public class FlowConverter {
                         salMatch.setField(new MatchField(MatchType.DL_TYPE,
                                 ofMatch.getDataLayerType()));
                     }
                         salMatch.setField(new MatchField(MatchType.DL_TYPE,
                                 ofMatch.getDataLayerType()));
                     }
-                    if (ofMatch.getDataLayerVirtualLan() != 0) {
+                    short vlan = ofMatch.getDataLayerVirtualLan();
+                    if (vlan != 0) {
+                        if (vlan == OFP_VLAN_NONE) {
+                            vlan = MatchType.DL_VLAN_NONE;
+                        }
                         salMatch.setField(new MatchField(MatchType.DL_VLAN,
                         salMatch.setField(new MatchField(MatchType.DL_VLAN,
-                                ofMatch.getDataLayerVirtualLan()));
+                                vlan));
                     }
                     if (ofMatch.getDataLayerVirtualLanPriorityCodePoint() != 0) {
                         salMatch.setField(MatchType.DL_VLAN_PR, ofMatch
                     }
                     if (ofMatch.getDataLayerVirtualLanPriorityCodePoint() != 0) {
                         salMatch.setField(MatchType.DL_VLAN_PR, ofMatch
@@ -582,9 +596,13 @@ public class FlowConverter {
                         salMatch.setField(new MatchField(MatchType.DL_TYPE,
                                 v6Match.getDataLayerType()));
                     }
                         salMatch.setField(new MatchField(MatchType.DL_TYPE,
                                 v6Match.getDataLayerType()));
                     }
-                    if (v6Match.getDataLayerVirtualLan() != 0) {
+                    short vlan = v6Match.getDataLayerVirtualLan();
+                    if (vlan != 0) {
+                        if (vlan == OFP_VLAN_NONE) {
+                            vlan = MatchType.DL_VLAN_NONE;
+                        }
                         salMatch.setField(new MatchField(MatchType.DL_VLAN,
                         salMatch.setField(new MatchField(MatchType.DL_VLAN,
-                                v6Match.getDataLayerVirtualLan()));
+                                vlan));
                     }
                     if (v6Match.getDataLayerVirtualLanPriorityCodePoint() != 0) {
                         salMatch.setField(MatchType.DL_VLAN_PR, v6Match
                     }
                     if (v6Match.getDataLayerVirtualLanPriorityCodePoint() != 0) {
                         salMatch.setField(MatchType.DL_VLAN_PR, v6Match
index 297223392ded7f0cac8620381011089222cd406d..ad225d94ddb7653fc223d3323079796d90278fa7 100644 (file)
@@ -179,6 +179,55 @@ public class FlowProgrammerServiceTest {
         }
     }
 
         }
     }
 
+    @Test
+    public void testVlanNoneIdFlowConversion() throws Exception {
+        Node node = NodeCreator.createOFNode(1000l);
+
+        /*
+         * The value 0 is used to indicate that no VLAN ID is set
+         * for SAL Flow.
+         */
+        short vlan = (short) 0;
+
+        /*
+         * Create a SAL Flow aFlow
+         */
+        Match match = new Match();
+        match.setField(MatchType.DL_VLAN, vlan);
+
+        List<Action> actions = new ArrayList<Action>();
+
+        Flow aFlow = new Flow(match, actions);
+
+        /*
+         * Convert the SAL aFlow to OF Flow
+         */
+        FlowConverter salToOF = new FlowConverter(aFlow);
+        OFMatch ofMatch = salToOF.getOFMatch();
+        List<OFAction> ofActions = salToOF.getOFActions();
+
+        /*
+         * The value 0xffff (OFP_VLAN_NONE) is used to indicate
+         * that no VLAN ID is set for OF Flow.
+         */
+        Assert.assertEquals((short) 0xffff, ofMatch.getDataLayerVirtualLan());
+
+        /*
+         * Convert the OF Flow to SAL Flow bFlow
+         */
+        FlowConverter ofToSal = new FlowConverter(ofMatch, ofActions);
+        Flow bFlow = ofToSal.getFlow(node);
+        Match bMatch = bFlow.getMatch();
+
+        /*
+         * Verify the converted SAL flow bFlow is equivalent to the original SAL Flow
+         */
+        Assert
+                .assertTrue(((Short) match.getField(MatchType.DL_VLAN)
+                        .getValue()).equals((Short) bMatch.getField(
+                        MatchType.DL_VLAN).getValue()));
+    }
+
     @Test
     public void testV6toSALFlowConversion() throws Exception {
         Node node = NodeCreator.createOFNode(12l);
     @Test
     public void testV6toSALFlowConversion() throws Exception {
         Node node = NodeCreator.createOFNode(12l);
index 85e505671ef177627c84bff640f2a7596d66b441..1c964267b130d8b9f82d5e3726cc446683dbc4bd 100644 (file)
@@ -25,7 +25,7 @@ public enum MatchType {
     IN_PORT("inPort", 1 << 0, NodeConnector.class, 1, 0),
     DL_SRC("dlSrc", 1 << 1, Byte[].class, 0, 0xffffffffffffL),
     DL_DST("dlDst", 1 << 2, Byte[].class, 0, 0xffffffffffffL),
     IN_PORT("inPort", 1 << 0, NodeConnector.class, 1, 0),
     DL_SRC("dlSrc", 1 << 1, Byte[].class, 0, 0xffffffffffffL),
     DL_DST("dlDst", 1 << 2, Byte[].class, 0, 0xffffffffffffL),
-    DL_VLAN("dlVlan", 1 << 3, Short.class, 1, 0xfff), // 2 bytes
+    DL_VLAN("dlVlan", 1 << 3, Short.class, 0, 0xfff), // 2 bytes
     DL_VLAN_PR("dlVlanPriority", 1 << 4, Byte.class, 0, 0x7), // 3 bits
     DL_OUTER_VLAN("dlOuterVlan", 1 << 5, Short.class, 1, 0xfff),
     DL_OUTER_VLAN_PR("dlOuterVlanPriority", 1 << 6, Short.class, 0, 0x7),
     DL_VLAN_PR("dlVlanPriority", 1 << 4, Byte.class, 0, 0x7), // 3 bits
     DL_OUTER_VLAN("dlOuterVlan", 1 << 5, Short.class, 1, 0xfff),
     DL_OUTER_VLAN_PR("dlOuterVlanPriority", 1 << 6, Short.class, 0, 0x7),
@@ -37,6 +37,9 @@ public enum MatchType {
     TP_SRC("tpSrc", 1 << 12, Short.class, 1, 0xffff), // 2 bytes
     TP_DST("tpDst", 1 << 13, Short.class, 1, 0xffff); // 2 bytes
 
     TP_SRC("tpSrc", 1 << 12, Short.class, 1, 0xffff), // 2 bytes
     TP_DST("tpDst", 1 << 13, Short.class, 1, 0xffff); // 2 bytes
 
+    // Used to indicate that no VLAN ID is set.
+    public static final short DL_VLAN_NONE = (short) 0;
+
     private String id;
     private int index;
     private Class<?> dataType;
     private String id;
     private int index;
     private Class<?> dataType;
index cfa53fb7f37c052f2562ae94f5e03792cf386ebb..55b5cabf11c30f11a54ba1e10769e864106441a2 100644 (file)
@@ -474,4 +474,15 @@ public class MatchTest {
         Assert.assertTrue(flipflip.equals(flipped));
 
     }
         Assert.assertTrue(flipflip.equals(flipped));
 
     }
+
+    @Test
+    public void testVlanNone() throws Exception {
+        // The value 0 is used to indicate that no VLAN ID is set
+        short vlan = (short) 0;
+        MatchField field = new MatchField(MatchType.DL_VLAN, vlan);
+
+        Assert.assertTrue(field != null);
+        Assert.assertTrue(field.getValue().equals(new Short(vlan)));
+        Assert.assertTrue(field.isValid());
+    }
 }
 }