In vnet CLI, separates virutal port creation and binding operations.
Original usage with specifiying a phyiscal port is also in supporting.

Changes.
1. vnet-create-port allow to create virtual port
   without a specific virtual port
2. vnet-bind-port command is added to newly bind or to update
3. Virtual binding point is changed from Port to ConnectPoint.

Change-Id: I4c8f9a2b9b2786ba519ead3559d7f005390fee86
diff --git a/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualPortBindCommand.java b/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualPortBindCommand.java
new file mode 100644
index 0000000..2eb0a56
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualPortBindCommand.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.cli.net.vnet;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.virtual.NetworkId;
+import org.onosproject.incubator.net.virtual.VirtualNetworkAdminService;
+import org.onosproject.incubator.net.virtual.VirtualNetworkService;
+import org.onosproject.incubator.net.virtual.VirtualPort;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceService;
+
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Binds an existing virtual port with a physical port.
+ */
+@Command(scope = "onos", name = "vnet-bind-port",
+        description = "Binds an existing virtual port with a physical port.")
+public class VirtualPortBindCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "networkId", description = "Network ID",
+            required = true, multiValued = false)
+    Long networkId = null;
+
+    @Argument(index = 1, name = "deviceId", description = "Virtual Device ID",
+            required = true, multiValued = false)
+    String deviceId = null;
+
+    @Argument(index = 2, name = "portNum", description = "Virtual device port number",
+            required = true, multiValued = false)
+    Integer portNum = null;
+
+    @Argument(index = 3, name = "physDeviceId", description = "Physical Device ID",
+            required = true, multiValued = false)
+    String physDeviceId = null;
+
+    @Argument(index = 4, name = "physPortNum", description = "Physical device port number",
+            required = true, multiValued = false)
+    Integer physPortNum = null;
+
+    @Override
+    protected void execute() {
+        VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
+        DeviceService deviceService = get(DeviceService.class);
+
+        VirtualPort vPort = getVirtualPort(PortNumber.portNumber(portNum));
+        checkNotNull(vPort, "The virtual Port does not exist");
+
+        ConnectPoint realizedBy = new ConnectPoint(DeviceId.deviceId(physDeviceId),
+                                      PortNumber.portNumber(physPortNum));
+        service.bindVirtualPort(NetworkId.networkId(networkId), DeviceId.deviceId(deviceId),
+                                  PortNumber.portNumber(portNum), realizedBy);
+        print("Virtual port is successfully bound.");
+    }
+
+    /**
+     * Returns the virtual port matching the device and port identifier.
+     *
+     * @param aPortNumber port identifier
+     * @return matching virtual port, or null.
+     */
+    private VirtualPort getVirtualPort(PortNumber aPortNumber) {
+        VirtualNetworkService service = get(VirtualNetworkService.class);
+        Set<VirtualPort> ports = service.getVirtualPorts(NetworkId.networkId(networkId),
+                                                    DeviceId.deviceId(deviceId));
+        return ports.stream().filter(p->p.number().equals(aPortNumber))
+                .findFirst().get();
+    }
+}
diff --git a/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualPortCreateCommand.java b/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualPortCreateCommand.java
index 0c2757c..c49e3c5 100644
--- a/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualPortCreateCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualPortCreateCommand.java
@@ -23,12 +23,8 @@
 import org.onosproject.incubator.net.virtual.VirtualDevice;
 import org.onosproject.incubator.net.virtual.VirtualNetworkAdminService;
 import org.onosproject.incubator.net.virtual.VirtualNetworkService;
-import org.onosproject.net.DefaultAnnotations;
-import org.onosproject.net.DefaultDevice;
-import org.onosproject.net.DefaultPort;
-import org.onosproject.net.Device;
+import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DeviceId;
-import org.onosproject.net.Port;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.device.DeviceService;
 
@@ -56,24 +52,29 @@
     Integer portNum = null;
 
     @Argument(index = 3, name = "physDeviceId", description = "Physical Device ID",
-            required = true, multiValued = false)
+            required = false, multiValued = false)
     String physDeviceId = null;
 
     @Argument(index = 4, name = "physPortNum", description = "Physical device port number",
-            required = true, multiValued = false)
+            required = false, multiValued = false)
     Integer physPortNum = null;
 
     @Override
     protected void execute() {
         VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
         DeviceService deviceService = get(DeviceService.class);
+
         VirtualDevice virtualDevice = getVirtualDevice(DeviceId.deviceId(deviceId));
         checkNotNull(virtualDevice, "The virtual device does not exist.");
 
-        DefaultAnnotations annotations = DefaultAnnotations.builder().build();
-        Device physDevice = new DefaultDevice(null, DeviceId.deviceId(physDeviceId),
-                                              null, null, null, null, null, null, annotations);
-        Port realizedBy = new DefaultPort(physDevice, PortNumber.portNumber(physPortNum), true);
+        ConnectPoint realizedBy = null;
+        if (physDeviceId != null && physPortNum != null) {
+            checkNotNull(physPortNum, "The physical port does not specified.");
+            realizedBy = new ConnectPoint(DeviceId.deviceId(physDeviceId),
+                                               PortNumber.portNumber(physPortNum));
+            checkNotNull(realizedBy, "The physical port does not exist.");
+        }
+
         service.createVirtualPort(NetworkId.networkId(networkId), DeviceId.deviceId(deviceId),
                                   PortNumber.portNumber(portNum), realizedBy);
         print("Virtual port successfully created.");
diff --git a/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualPortListCommand.java b/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualPortListCommand.java
index 0f1c99e..a35d22a 100644
--- a/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualPortListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualPortListCommand.java
@@ -62,7 +62,8 @@
         VirtualNetworkService service = get(VirtualNetworkService.class);
 
         List<VirtualPort> virtualPorts = new ArrayList<>();
-        virtualPorts.addAll(service.getVirtualPorts(NetworkId.networkId(networkId), DeviceId.deviceId(deviceId)));
+        virtualPorts.addAll(service.getVirtualPorts(NetworkId.networkId(networkId),
+                                                    DeviceId.deviceId(deviceId)));
         Collections.sort(virtualPorts, Comparators.VIRTUAL_PORT_COMPARATOR);
         return virtualPorts;
     }
@@ -73,7 +74,12 @@
      * @param virtualPort virtual port
      */
     private void printVirtualPort(VirtualPort virtualPort) {
-        print(FMT_VIRTUAL_PORT, virtualPort.number(),
-              virtualPort.realizedBy().element().id(), virtualPort.realizedBy().number());
+        if (virtualPort.realizedBy() == null) {
+            print(FMT_VIRTUAL_PORT, virtualPort.number(), "None", "None");
+        } else {
+            print(FMT_VIRTUAL_PORT, virtualPort.number(),
+                  virtualPort.realizedBy().deviceId(),
+                  virtualPort.realizedBy().port());
+        }
     }
 }
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 4da1d8b..69c52fe 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -694,6 +694,9 @@
             <action class="org.onosproject.cli.net.vnet.VirtualPortCreateCommand"/>
         </command>
         <command>
+            <action class="org.onosproject.cli.net.vnet.VirtualPortBindCommand"/>
+        </command>
+        <command>
             <action class="org.onosproject.cli.net.vnet.VirtualPortRemoveCommand"/>
         </command>
         <command>