Fixed minimum values for TP_SRC/TP_DST match fields. 22/822/1
authorHideyuki Tai <h-tai@cd.jp.nec.com>
Wed, 7 Aug 2013 16:53:28 +0000 (12:53 -0400)
committerHideyuki Tai <h-tai@cd.jp.nec.com>
Wed, 7 Aug 2013 16:53:28 +0000 (12:53 -0400)
In OpenFlow 1.0, the tp_src and tp_dst match fields are used for transport source/destination ports or ICMP type/code.
Therefore, the range of the fields must include 0.

Change-Id: I7011109ced925e198ec2785f5ed9dc9a8e81623c
Signed-off-by: Hideyuki Tai <h-tai@cd.jp.nec.com>
opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java
opendaylight/forwardingrulesmanager/api/src/test/java/org/opendaylight/controller/forwardingrulesmanager/frmTest.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
opendaylight/web/flows/src/main/resources/js/page.js

index 1ac7cb2..5db7d32 100644 (file)
@@ -647,7 +647,7 @@ public class FlowConfig implements Serializable {
 
     public boolean isTpPortValid(String tpPort) {
         int port = Integer.decode(tpPort);
-        return ((port > 0) && (port <= 0xffff));
+        return ((port >= 0) && (port <= 0xffff));
     }
 
     public boolean isTimeoutValid(String timeout) {
index fc22ee7..176d8e9 100644 (file)
@@ -611,9 +611,15 @@ public class frmTest {
         Assert.assertFalse(status.isSuccess());
         Assert.assertTrue(status.getDescription().contains("Transport source port"));
 
+        fc.setSrcPort("0");
+        Assert.assertTrue(fc.validate(null).isSuccess());
+
         fc.setSrcPort("0x00ff");
         Assert.assertTrue(fc.validate(null).isSuccess());
 
+        fc.setSrcPort("0xffff");
+        Assert.assertTrue(fc.validate(null).isSuccess());
+
         fc.setDstPort("-1");
         status = fc.validate(null);
         Assert.assertFalse(status.isSuccess());
@@ -624,9 +630,15 @@ public class frmTest {
         Assert.assertFalse(status.isSuccess());
         Assert.assertTrue(status.getDescription().contains("Transport destination port"));
 
+        fc.setDstPort("0");
+        Assert.assertTrue(fc.validate(null).isSuccess());
+
         fc.setDstPort("0x00ff");
         Assert.assertTrue(fc.validate(null).isSuccess());
 
+        fc.setDstPort("0xffff");
+        Assert.assertTrue(fc.validate(null).isSuccess());
+
         fc.setSrcMac("abc");
         status = fc.validate(null);
         Assert.assertFalse(status.isSuccess());
index 1c96426..f4c8f4a 100644 (file)
@@ -34,8 +34,8 @@ public enum MatchType {
     NW_PROTO("nwProto", 1 << 9, Byte.class, 0, 0xff), // 1 byte
     NW_SRC("nwSrc", 1 << 10, InetAddress.class, 0, 0),
     NW_DST("nwDst", 1 << 11, InetAddress.class, 0, 0),
-    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, 0, 0xffff), // 2 bytes
+    TP_DST("tpDst", 1 << 13, Short.class, 0, 0xffff); // 2 bytes
 
     // Used to indicate that no VLAN ID is set.
     public static final short DL_VLAN_NONE = (short) 0;
index 55b5cab..ae78e1a 100644 (file)
@@ -137,6 +137,44 @@ public class MatchTest {
         Assert.assertTrue(o.equals(proto));
     }
 
+    @Test
+    public void testSetTpSrc() {
+        // Minimum value validation.
+        Match match = new Match();
+        short tp_src = 0;
+        match.setField(MatchType.TP_SRC, tp_src);
+
+        Object o = match.getField(MatchType.TP_SRC).getValue();
+        Assert.assertTrue(o.equals(tp_src));
+
+        // Maximum value validation.
+        match = new Match();
+        tp_src = (short) 0xffff;
+        match.setField(MatchType.TP_SRC, tp_src);
+
+        o = match.getField(MatchType.TP_SRC).getValue();
+        Assert.assertTrue(o.equals(tp_src));
+    }
+
+    @Test
+    public void testSetTpDst() {
+        // Minimum value validation.
+        Match match = new Match();
+        short tp_dst = 0;
+        match.setField(MatchType.TP_DST, tp_dst);
+
+        Object o = match.getField(MatchType.TP_DST).getValue();
+        Assert.assertTrue(o.equals(tp_dst));
+
+        // Maximum value validation.
+        match = new Match();
+        tp_dst = (short) 0xffff;
+        match.setField(MatchType.TP_DST, tp_dst);
+
+        o = match.getField(MatchType.TP_DST).getValue();
+        Assert.assertTrue(o.equals(tp_dst));
+    }
+
     @Test
     public void testMatchMask() {
         Match x = new Match();
index 59557dc..7ff54ed 100644 (file)
@@ -715,13 +715,13 @@ one.f.flows = {
                        var $label = one.lib.form.label("Source Port");
                        var $input = one.lib.form.input("Source Port");
                        $input.attr('id', one.f.flows.id.modal.form.srcPort);
-                       var $help = one.lib.form.help("Range: 1 - 65535");
+                       var $help = one.lib.form.help("Range: 0 - 65535");
                        $fieldset.append($label).append($input).append($help);
                        // dstPort
                        var $label = one.lib.form.label("Destination Port");
                        var $input = one.lib.form.input("Destination Port");
                        $input.attr('id', one.f.flows.id.modal.form.dstPort);
-                       var $help = one.lib.form.help("Range: 1 - 65535");
+                       var $help = one.lib.form.help("Range: 0 - 65535");
                        $fieldset.append($label).append($input).append($help);
                        // protocol
                        var $label = one.lib.form.label("Protocol");