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/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/DistributedVirtualNetworkStore.java b/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/DistributedVirtualNetworkStore.java
index eb4e8b3..9007c21 100644
--- a/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/DistributedVirtualNetworkStore.java
+++ b/incubator/store/src/main/java/org/onosproject/incubator/store/virtual/impl/DistributedVirtualNetworkStore.java
@@ -53,7 +53,6 @@
import org.onosproject.net.HostId;
import org.onosproject.net.HostLocation;
import org.onosproject.net.Link;
-import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentData;
@@ -517,21 +516,53 @@
}
@Override
- public VirtualPort addPort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber, Port realizedBy) {
+ public VirtualPort addPort(NetworkId networkId, DeviceId deviceId,
+ PortNumber portNumber, ConnectPoint realizedBy) {
checkState(networkExists(networkId), "The network has not been added.");
Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId);
+
if (virtualPortSet == null) {
virtualPortSet = new HashSet<>();
}
+
Device device = deviceIdVirtualDeviceMap.get(deviceId);
checkNotNull(device, "The device has not been created for deviceId: " + deviceId);
- VirtualPort virtualPort = new DefaultVirtualPort(networkId, device, portNumber, realizedBy);
+
+ boolean exist = virtualPortSet.stream().anyMatch(
+ p -> p.element().id().equals(deviceId) &&
+ p.number().equals(portNumber));
+ checkState(!exist, "The requested Port Number is already in use");
+
+ VirtualPort virtualPort = new DefaultVirtualPort(networkId, device,
+ portNumber, realizedBy);
virtualPortSet.add(virtualPort);
networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
return virtualPort;
}
@Override
+ public void bindPort(NetworkId networkId, DeviceId deviceId,
+ PortNumber portNumber, ConnectPoint realizedBy) {
+
+ Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap
+ .get(networkId);
+
+ VirtualPort vPort = virtualPortSet.stream().filter(
+ p -> p.element().id().equals(deviceId) &&
+ p.number().equals(portNumber)).findFirst().get();
+ checkNotNull(vPort, "The virtual port has not been added.");
+
+ Device device = deviceIdVirtualDeviceMap.get(deviceId);
+ checkNotNull(device, "The device has not been created for deviceId: "
+ + deviceId);
+
+ virtualPortSet.remove(vPort);
+ vPort = new DefaultVirtualPort(networkId, device, portNumber, realizedBy);
+ virtualPortSet.add(vPort);
+ networkIdVirtualPortSetMap.put(networkId, virtualPortSet);
+ }
+
+ @Override
public void removePort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber) {
checkState(networkExists(networkId), "The network has not been added.");