Added CLI completion for IP protocol types.

Also modified IpProto and EthType field parsing to allow the user to supply
either a string value (e.g. "ICMP", "ARP") or the protocol number.

Change-Id: I8f19bebe53c2a7dbdc7570fdc08f979b2c0851cb
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/EthType.java b/cli/src/main/java/org/onlab/onos/cli/net/EthType.java
index 368c7b2..2e46aea 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/EthType.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/EthType.java
@@ -38,7 +38,7 @@
     /**
      * Constructs an EthType with the given value.
      *
-     * @param value value to use when this EthType is seen.
+     * @param value value to use when this EthType is seen
      */
     private EthType(short value) {
         this.value = value;
@@ -52,4 +52,31 @@
     public short value() {
         return this.value;
     }
+
+    /**
+     * Parse a string input that could contain an EthType value. The value
+     * may appear in the string either as a known protocol name (one of the
+     * values of this enum), or a numeric protocol value.
+     *
+     * @param input the input string to parse
+     * @return the numeric value of the parsed Ethernet type
+     * @throws IllegalArgumentException if the input string does not contain a
+     * value that can be parsed into an Ethernet type
+     */
+    public static short parseFromString(String input) {
+        try {
+            return valueOf(input).value();
+        } catch (IllegalArgumentException e) {
+            // The input is not a known Ethernet type name, let's see if it's an
+            // Ethernet type value (short). We parse with Integer to handle
+            // unsigned values correctly.
+            try {
+                return (short) Integer.parseInt(input);
+            } catch (NumberFormatException e1) {
+                throw new IllegalArgumentException(
+                        "EthType value must be either a string protocol name"
+                        + " or a 16-bit protocol value");
+            }
+        }
+    }
 }