Merge "Sal Models for meter table. Removed tab space from group models and formatted...
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / utils / IPProtocols.java
index 416018d98ed80d915d5e470c1db871436fc53e96..66e6e65706fc2b23a1498b589a4e94fafbe3e7bf 100644 (file)
@@ -23,14 +23,14 @@ import java.util.List;
 // Openflow 1.0 supports the IP Proto match only for ICMP, TCP and UDP
 public enum IPProtocols {
     ANY("any", 0),
-    /* HOPOPT("HOPOPT",0),
+    /*  HOPOPT("HOPOPT",0),
      */ICMP("ICMP", 1),
-    /* IGMP("IGMP",2),
+    /*  IGMP("IGMP",2),
      GGP("GGP",3),
      IPV4("IPv4",4),
      ST("ST",5),
      */TCP("TCP", 6),
-    /* CBT("CBT",7),
+    /*  CBT("CBT",7),
      EGP("EGP",8),
      IGP("IGP",9),
      BBNRCCMON("BBN-RCC-MON",10),
@@ -41,7 +41,7 @@ public enum IPProtocols {
      XNET("XNET",15),
      CHAOS("CHAOS",16),
      */UDP("UDP", 17),
-    /* MUX("MUX",18),
+    /*  MUX("MUX",18),
      DCNMEAS("DCN-MEAS",19),
      HMP("HMP",20),
      PRM("PRM",21),
@@ -82,7 +82,7 @@ public enum IPProtocols {
      TLSP("TLSP",56),
      SKIP("SKIP",57),
      */IPV6ICMP("IPv6-ICMP", 58);
-    /* IPV6NoNxt("IPv6-NoNxt",59),
+    /*  IPV6NoNxt("IPv6-NoNxt",59),
      IPV6Opts("IPv6-Opts",60),
      ANYHOST("ANY-HOST",61),
      CFTP("CFTP",62),
@@ -168,7 +168,8 @@ public enum IPProtocols {
      WESP("WESP",141),
      ROHC("ROHC",142);
      */
-    private static final String regexNumberString = "^[0-9]+$";
+    private static final String regexDecimalString = "^[0-9]{3}$";
+    private static final String regexHexString = "^(0(x|X))[0-9a-fA-F]{2}$";
     private String protocolName;
     private int protocolNumber;
 
@@ -215,7 +216,10 @@ public enum IPProtocols {
     }
 
     public static short getProtocolNumberShort(String name) {
-        if (name.matches(regexNumberString)) {
+        if (name.matches(regexHexString)) {
+            return Short.valueOf(Short.decode(name));
+        }
+        if (name.matches(regexDecimalString)) {
             return Short.valueOf(name);
         }
         for (IPProtocols proto : IPProtocols.values()) {
@@ -227,7 +231,10 @@ public enum IPProtocols {
     }
 
     public static int getProtocolNumberInt(String name) {
-        if (name.matches(regexNumberString)) {
+        if (name.matches(regexHexString)) {
+            return Integer.valueOf(Integer.decode(name));
+        }
+        if (name.matches(regexDecimalString)) {
             return Integer.valueOf(name);
         }
         for (IPProtocols proto : IPProtocols.values()) {
@@ -239,7 +246,10 @@ public enum IPProtocols {
     }
 
     public static byte getProtocolNumberByte(String name) {
-        if (name.matches(regexNumberString)) {
+        if (name.matches(regexHexString)) {
+            return Integer.valueOf(Integer.decode(name)).byteValue();
+        }
+        if (name.matches(regexDecimalString)) {
             return Integer.valueOf(name).byteValue();
         }
         for (IPProtocols proto : IPProtocols.values()) {