Add fromString method to connect point

Change-Id: If90b7582b554896250571b9290fd639dfb7057d5
diff --git a/core/api/src/main/java/org/onosproject/net/ConnectPoint.java b/core/api/src/main/java/org/onosproject/net/ConnectPoint.java
index 9998a2f..c2959df 100644
--- a/core/api/src/main/java/org/onosproject/net/ConnectPoint.java
+++ b/core/api/src/main/java/org/onosproject/net/ConnectPoint.java
@@ -144,6 +144,23 @@
                                 PortNumber.portNumber(string.substring(lastSlash + 1, string.length())));
     }
 
+    /**
+     * Parse a device connect point from a string.
+     * The connect point should be in the same format as toString output.
+     *
+     * @param string string to parse
+     * @return a ConnectPoint based on the information in the string.
+     */
+    public static ConnectPoint fromString(String string) {
+        checkNotNull(string);
+        String[] splitted = string.split("/");
+        checkArgument(splitted.length == 2,
+                "Connect point must be in \"deviceUri/portNumber\" format");
+
+        return new ConnectPoint(DeviceId.deviceId(splitted[0]),
+                PortNumber.fromString(splitted[1]));
+    }
+
     @Override
     public int hashCode() {
         return Objects.hash(elementId, portNumber);
diff --git a/core/api/src/test/java/org/onosproject/net/ConnectPointTest.java b/core/api/src/test/java/org/onosproject/net/ConnectPointTest.java
index ff21fd8..f823093 100644
--- a/core/api/src/test/java/org/onosproject/net/ConnectPointTest.java
+++ b/core/api/src/test/java/org/onosproject/net/ConnectPointTest.java
@@ -71,6 +71,17 @@
         expectDeviceParseException("of:0011223344556677/word");
     }
 
+    @Test
+    public void testParseFromString() {
+        String cp = "netconf:127.0.0.1/[TYPE](1)";
+
+        ConnectPoint connectPoint = ConnectPoint.fromString(cp);
+        assertEquals("netconf:127.0.0.1", connectPoint.deviceId().toString());
+        assertEquals("[TYPE](1)", connectPoint.port().toString());
+        assertEquals(connectPoint, ConnectPoint.fromString(connectPoint.toString()));
+
+    }
+
     /**
      * Parse a device connect point and expect an exception to be thrown.
      *