Add static factory method to create ConnectPoints from strings.

Change-Id: I743b4a4fb433ad07cf6f2cbed3da7b6e19a74ebb
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddFlowsCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddFlowsCommand.java
index 08f1fa4..c8d91d5 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddFlowsCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddFlowsCommand.java
@@ -63,7 +63,6 @@
 
     @Override
     protected void execute() {
-
         FlowRuleService flowService = get(FlowRuleService.class);
         DeviceService deviceService = get(DeviceService.class);
         CoreService coreService = get(CoreService.class);
@@ -99,7 +98,6 @@
         }
 
         for (int i = 0; i < num; i++) {
-
             latch = new CountDownLatch(2);
             flowService.apply(rules.build(new FlowRuleOperationsContext() {
 
@@ -121,7 +119,6 @@
                 }
             }));
 
-
             flowService.apply(remove.build(new FlowRuleOperationsContext() {
                 @Override
                 public void onSuccess(FlowRuleOperations ops) {
@@ -135,14 +132,8 @@
             }
 
         }
-
-
-
-
     }
 
-
-
     private Object json(ObjectMapper mapper, boolean isSuccess, ArrayList<Long> elapsed) {
         ObjectNode result = mapper.createObjectNode();
         result.put("Success", isSuccess);
@@ -159,6 +150,4 @@
             print("  Run %s : %s", i, elapsed.get(i));
         }
     }
-
-
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java b/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java
index 8396e9d..0983aff 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddMplsIntent.java
@@ -1,23 +1,18 @@
 package org.onosproject.cli.net;
 
-import java.util.List;
-import java.util.Optional;
-
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.commands.Option;
 import org.onlab.packet.MplsLabel;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.intent.Constraint;
 import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.intent.MplsIntent;
 
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
+import java.util.List;
+import java.util.Optional;
 
 /**
  * Installs MPLS intents.
@@ -53,19 +48,14 @@
     protected void execute() {
         IntentService service = get(IntentService.class);
 
-        DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
-        PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
-        ConnectPoint ingress = new ConnectPoint(ingressDeviceId,
-                                                ingressPortNumber);
+        ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
         Optional<MplsLabel> ingressLabel = Optional.empty();
         if (!ingressLabelString.isEmpty()) {
             ingressLabel = Optional
                     .ofNullable(MplsLabel.mplsLabel(parseInt(ingressLabelString)));
         }
 
-        DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
-        PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
-        ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
+        ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
 
         Optional<MplsLabel> egressLabel = Optional.empty();
         if (!ingressLabelString.isEmpty()) {
@@ -92,34 +82,6 @@
         service.submit(intent);
     }
 
-    /**
-     * Extracts the port number portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return port number as a string, empty string if the port is not found
-     */
-    public static String getPortNumber(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(slash + 1, deviceString.length());
-    }
-
-    /**
-     * Extracts the device ID portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return device ID string
-     */
-    public static String getDeviceId(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(0, slash);
-    }
-
     protected Integer parseInt(String value) {
         try {
             return Integer.parseInt(value);
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java
index 66083b8..dc792f4 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java
@@ -18,8 +18,6 @@
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.intent.Constraint;
@@ -31,9 +29,6 @@
 import java.util.List;
 import java.util.Set;
 
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
-
 /**
  * Installs connectivity intent between multiple ingress devices and a single egress device.
  */
@@ -55,16 +50,12 @@
         }
 
         String egressDeviceString = deviceStrings[deviceStrings.length - 1];
-        DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
-        PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
-        ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
-        Set<ConnectPoint> ingressPoints = new HashSet<>();
+        ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
 
+        Set<ConnectPoint> ingressPoints = new HashSet<>();
         for (int index = 0; index < deviceStrings.length - 1; index++) {
             String ingressDeviceString = deviceStrings[index];
-            DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
-            PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
-            ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
+            ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
             ingressPoints.add(ingress);
         }
 
@@ -85,32 +76,4 @@
         service.submit(intent);
         print("Multipoint to single point intent submitted:\n%s", intent.toString());
     }
-
-    /**
-     * Extracts the port number portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return port number as a string, empty string if the port is not found
-     */
-    private String getPortNumber(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(slash + 1, deviceString.length());
-    }
-
-    /**
-     * Extracts the device ID portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return device ID string
-     */
-    private String getDeviceId(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(0, slash);
-    }
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
index 4a9cac8..f0e2bd2 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
@@ -15,14 +15,9 @@
  */
 package org.onosproject.cli.net;
 
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
-
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.intent.Intent;
 import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.intent.OpticalConnectivityIntent;
@@ -48,13 +43,9 @@
     protected void execute() {
         IntentService service = get(IntentService.class);
 
-        DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
-        PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
-        ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
+        ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
 
-        DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
-        PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
-        ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
+        ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
 
         Intent intent = OpticalConnectivityIntent.builder()
                 .appId(appId())
@@ -65,32 +56,4 @@
         service.submit(intent);
         print("Optical intent submitted:\n%s", intent.toString());
     }
-
-    /**
-     * Extracts the port number portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return port number as a string, empty string if the port is not found
-     */
-    private String getPortNumber(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(slash + 1, deviceString.length());
-    }
-
-    /**
-     * Extracts the device ID portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return device ID string
-     */
-    private String getDeviceId(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(0, slash);
-    }
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddPointToPointIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddPointToPointIntentCommand.java
index e06a682..7c27dd3 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddPointToPointIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddPointToPointIntentCommand.java
@@ -15,13 +15,9 @@
  */
 package org.onosproject.cli.net;
 
-import java.util.List;
-
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.intent.Constraint;
@@ -29,8 +25,7 @@
 import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.intent.PointToPointIntent;
 
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
+import java.util.List;
 
 /**
  * Installs point-to-point connectivity intents.
@@ -49,18 +44,13 @@
               required = true, multiValued = false)
     String egressDeviceString = null;
 
-
     @Override
     protected void execute() {
         IntentService service = get(IntentService.class);
 
-        DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
-        PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
-        ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
+        ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
 
-        DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
-        PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
-        ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
+        ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
 
         TrafficSelector selector = buildTrafficSelector();
         TrafficTreatment treatment = buildTrafficTreatment();
@@ -80,32 +70,4 @@
         service.submit(intent);
         print("Point to point intent submitted:\n%s", intent.toString());
     }
-
-    /**
-     * Extracts the port number portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return port number as a string, empty string if the port is not found
-     */
-    public static String getPortNumber(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(slash + 1, deviceString.length());
-    }
-
-    /**
-     * Extracts the device ID portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return device ID string
-     */
-    public static String getDeviceId(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(0, slash);
-    }
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java
index cdf4a73..2939afa 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java
@@ -15,15 +15,9 @@
  */
 package org.onosproject.cli.net;
 
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
@@ -31,8 +25,9 @@
 import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.intent.SinglePointToMultiPointIntent;
 
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 /**
  * Installs connectivity intent between a single ingress device and multiple egress devices.
@@ -54,18 +49,12 @@
         }
 
         String ingressDeviceString = deviceStrings[0];
-        DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
-        PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
-        ConnectPoint ingressPoint = new ConnectPoint(ingressDeviceId,
-                                                     ingressPortNumber);
+        ConnectPoint ingressPoint = ConnectPoint.deviceConnectPoint(ingressDeviceString);
 
         Set<ConnectPoint> egressPoints = new HashSet<>();
         for (int index = 1; index < deviceStrings.length; index++) {
             String egressDeviceString = deviceStrings[index];
-            DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
-            PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
-            ConnectPoint egress = new ConnectPoint(egressDeviceId,
-                                                   egressPortNumber);
+            ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
             egressPoints.add(egress);
         }
 
@@ -88,32 +77,4 @@
         print("Single point to multipoint intent submitted:\n%s", intent.toString());
     }
 
-    /**
-     * Extracts the port number portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return port number as a string, empty string if the port is not found
-     */
-    private String getPortNumber(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(slash + 1, deviceString.length());
-    }
-
-    /**
-     * Extracts the device ID portion of the ConnectPoint.
-     *
-     * @param deviceString string representing the device/port
-     * @return device ID string
-     */
-    private String getDeviceId(String deviceString) {
-        int slash = deviceString.indexOf('/');
-        if (slash <= 0) {
-            return "";
-        }
-        return deviceString.substring(0, slash);
-    }
-
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/LinkDstCompleter.java b/cli/src/main/java/org/onosproject/cli/net/LinkDstCompleter.java
index 0f5ad07..626777e 100644
--- a/cli/src/main/java/org/onosproject/cli/net/LinkDstCompleter.java
+++ b/cli/src/main/java/org/onosproject/cli/net/LinkDstCompleter.java
@@ -25,11 +25,6 @@
 import java.util.List;
 import java.util.SortedSet;
 
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getDeviceId;
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getPortNumber;
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
-
 /**
  * Link destination end-point completer.
  */
@@ -49,8 +44,7 @@
         // Generate the device ID/port number identifiers
         SortedSet<String> strings = delegate.getStrings();
         try {
-            ConnectPoint src = new ConnectPoint(deviceId(getDeviceId(srcArg)),
-                                                portNumber(getPortNumber(srcArg)));
+            ConnectPoint src = ConnectPoint.deviceConnectPoint(srcArg);
             service.getEgressLinks(src)
                     .forEach(link -> strings.add(link.dst().elementId().toString() +
                                                          "/" + link.dst().port()));
diff --git a/cli/src/main/java/org/onosproject/cli/net/ResourceAllocationsCommand.java b/cli/src/main/java/org/onosproject/cli/net/ResourceAllocationsCommand.java
index d125399..d45be27f 100644
--- a/cli/src/main/java/org/onosproject/cli/net/ResourceAllocationsCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/ResourceAllocationsCommand.java
@@ -19,18 +19,11 @@
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.link.LinkService;
 import org.onosproject.net.resource.LinkResourceAllocations;
 import org.onosproject.net.resource.LinkResourceService;
 
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getDeviceId;
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getPortNumber;
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
-
 /**
  * Lists allocations by link.
  */
@@ -55,13 +48,9 @@
 
         Iterable<LinkResourceAllocations> itr = null;
         try {
-            DeviceId ingressDeviceId = deviceId(getDeviceId(srcString));
-            PortNumber ingressPortNumber = portNumber(getPortNumber(srcString));
-            ConnectPoint src = new ConnectPoint(ingressDeviceId, ingressPortNumber);
+            ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString);
 
-            DeviceId egressDeviceId = deviceId(getDeviceId(dstString));
-            PortNumber egressPortNumber = portNumber(getPortNumber(dstString));
-            ConnectPoint dst = new ConnectPoint(egressDeviceId, egressPortNumber);
+            ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString);
 
             Link link = linkService.getLink(src, dst);
 
diff --git a/cli/src/main/java/org/onosproject/cli/net/ResourceAvailableCommand.java b/cli/src/main/java/org/onosproject/cli/net/ResourceAvailableCommand.java
index 65416b2..42824ab 100644
--- a/cli/src/main/java/org/onosproject/cli/net/ResourceAvailableCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/ResourceAvailableCommand.java
@@ -19,18 +19,11 @@
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.link.LinkService;
 import org.onosproject.net.resource.LinkResourceService;
 import org.onosproject.net.resource.ResourceRequest;
 
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getDeviceId;
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getPortNumber;
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
-
 /**
  * Lists allocations by link.
  */
@@ -55,13 +48,9 @@
 
         Iterable<ResourceRequest> itr = null;
         try {
-            DeviceId ingressDeviceId = deviceId(getDeviceId(srcString));
-            PortNumber ingressPortNumber = portNumber(getPortNumber(srcString));
-            ConnectPoint src = new ConnectPoint(ingressDeviceId, ingressPortNumber);
+            ConnectPoint src = ConnectPoint.deviceConnectPoint(srcString);
 
-            DeviceId egressDeviceId = deviceId(getDeviceId(dstString));
-            PortNumber egressPortNumber = portNumber(getPortNumber(dstString));
-            ConnectPoint dst = new ConnectPoint(egressDeviceId, egressPortNumber);
+            ConnectPoint dst = ConnectPoint.deviceConnectPoint(dstString);
 
             Link link = linkService.getLink(src, dst);
 
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 621cb2d..b5ff42c 100644
--- a/core/api/src/main/java/org/onosproject/net/ConnectPoint.java
+++ b/core/api/src/main/java/org/onosproject/net/ConnectPoint.java
@@ -15,9 +15,12 @@
  */
 package org.onosproject.net;
 
+import com.google.common.base.MoreObjects;
+
 import java.util.Objects;
 
-import com.google.common.base.MoreObjects;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
  * Abstraction of a network connection point expressed as a pair of the
@@ -90,6 +93,42 @@
         return portNumber;
     }
 
+    /**
+     * Parse a device connect point from a string.
+     * The connect point should be in the format "deviceUri/portNumber".
+     *
+     * @param string string to parse
+     * @return a ConnectPoint based on the information in the string.
+     */
+    public static ConnectPoint deviceConnectPoint(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.portNumber(splitted[1]));
+    }
+
+    /**
+     * Parse a host connect point from a string.
+     * The connect point should be in the format "hostId/vlanId/portNumber".
+     *
+     * @param string string to parse
+     * @return a ConnectPoint based on the information in the string.
+     */
+    public static ConnectPoint hostConnectPoint(String string) {
+        checkNotNull(string);
+        String[] splitted = string.split("/");
+        checkArgument(splitted.length == 3,
+                      "Connect point must be in \"hostId/vlanId/portNumber\" format");
+
+        int lastSlash = string.lastIndexOf("/");
+
+        return new ConnectPoint(HostId.hostId(string.substring(0, lastSlash)),
+                                PortNumber.portNumber(string.substring(lastSlash + 1, string.length())));
+    }
+
     @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 9580481..2aecabd 100644
--- a/core/api/src/test/java/org/onosproject/net/ConnectPointTest.java
+++ b/core/api/src/test/java/org/onosproject/net/ConnectPointTest.java
@@ -18,12 +18,14 @@
 import com.google.common.testing.EqualsTester;
 import org.junit.Test;
 
+import static junit.framework.TestCase.fail;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.onosproject.net.DeviceId.deviceId;
 import static org.onosproject.net.PortNumber.portNumber;
 
 /**
- * Test of the connetion point entity.
+ * Test of the connection point entity.
  */
 public class ConnectPointTest {
 
@@ -39,7 +41,6 @@
         assertEquals("incorrect element id", P2, p.port());
     }
 
-
     @Test
     public void testEquality() {
         new EqualsTester()
@@ -48,4 +49,62 @@
                 .addEqualityGroup(new ConnectPoint(DID2, P1), new ConnectPoint(DID2, P1))
                 .testEquals();
     }
+
+    @Test
+    public void testParseDeviceConnectPoint() {
+        String cp = "of:0011223344556677/1";
+
+        ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(cp);
+        assertEquals("of:0011223344556677", connectPoint.deviceId().toString());
+        assertEquals("1", connectPoint.port().toString());
+
+        expectDeviceParseException("");
+        expectDeviceParseException("1/");
+        expectDeviceParseException("1/1/1");
+        expectDeviceParseException("of:0011223344556677/word");
+    }
+
+    /**
+     * Parse a device connect point and expect an exception to be thrown.
+     *
+     * @param string string to parse
+     */
+    private static void expectDeviceParseException(String string) {
+        try {
+            ConnectPoint.deviceConnectPoint(string);
+            fail("Expected exception was not thrown");
+        } catch (Exception e) {
+            assertTrue(true);
+        }
+    }
+
+    @Test
+    public void testParseHostConnectPoint() {
+        String cp = "16:3A:BD:6E:31:E4/-1/1";
+
+        ConnectPoint connectPoint = ConnectPoint.hostConnectPoint(cp);
+        assertEquals("16:3A:BD:6E:31:E4/-1", connectPoint.hostId().toString());
+        assertEquals("1", connectPoint.port().toString());
+
+        expectHostParseException("");
+        expectHostParseException("1/");
+        expectHostParseException("1/1");
+        expectHostParseException("1/1/1/1");
+        expectHostParseException("16:3A:BD:6E:31:E4/word/1");
+        expectHostParseException("16:3A:BD:6E:31:E4/1/word");
+    }
+
+    /**
+     * Parse a host connect point and expect an exception to be thrown.
+     *
+     * @param string string to parse
+     */
+    private static void expectHostParseException(String string) {
+        try {
+            ConnectPoint.hostConnectPoint(string);
+            fail("Expected exception was not thrown");
+        } catch (Exception e) {
+            assertTrue(true);
+        }
+    }
 }
diff --git a/providers/null/src/main/java/org/onosproject/provider/nil/cli/NullLinkCommand.java b/providers/null/src/main/java/org/onosproject/provider/nil/cli/NullLinkCommand.java
index 6018b8d..a76da3b 100644
--- a/providers/null/src/main/java/org/onosproject/provider/nil/cli/NullLinkCommand.java
+++ b/providers/null/src/main/java/org/onosproject/provider/nil/cli/NullLinkCommand.java
@@ -19,16 +19,10 @@
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.provider.nil.NullProviders;
 
 import static org.onosproject.cli.UpDownCompleter.DOWN;
 import static org.onosproject.cli.UpDownCompleter.UP;
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getDeviceId;
-import static org.onosproject.cli.net.AddPointToPointIntentCommand.getPortNumber;
-import static org.onosproject.net.DeviceId.deviceId;
-import static org.onosproject.net.PortNumber.portNumber;
 
 /**
  * Servers or repairs a simulated link.
@@ -55,13 +49,9 @@
         NullProviders service = get(NullProviders.class);
 
         try {
-            DeviceId oneId = deviceId(getDeviceId(one));
-            PortNumber onePort = portNumber(getPortNumber(one));
-            ConnectPoint onePoint = new ConnectPoint(oneId, onePort);
+            ConnectPoint onePoint = ConnectPoint.deviceConnectPoint(one);
 
-            DeviceId twoId = deviceId(getDeviceId(two));
-            PortNumber twoPort = portNumber(getPortNumber(two));
-            ConnectPoint twoPoint = new ConnectPoint(twoId, twoPort);
+            ConnectPoint twoPoint = ConnectPoint.deviceConnectPoint(two);
 
             if (cmd.equals(UP)) {
                 service.repairLink(onePoint, twoPoint);