(vCord) Add a convenience method for providing a list of physical device
Change-Id: Ibc33ced05ee15a068e06c531240fa5cb6af16e38
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkService.java
index 07775dd..06d164c 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkService.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkService.java
@@ -21,8 +21,11 @@
import org.onosproject.event.ListenerService;
import org.onosproject.net.DeviceId;
+import java.util.HashSet;
import java.util.Set;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* Service for querying virtual network inventory.
*/
@@ -85,6 +88,32 @@
Set<VirtualPort> getVirtualPorts(NetworkId networkId, DeviceId deviceId);
/**
+ * Returns list of physical device identifier mapping with the virtual
+ * device in the specified network. The physical devices are specified by
+ * port mapping mechanism.
+ *
+ * @param networkId network identifier
+ * @param virtualDevice the virtual device
+ * @return collection of the specified device's identifier
+ */
+ default Set<DeviceId> getPhysicalDevices(NetworkId networkId,
+ VirtualDevice virtualDevice) {
+ checkNotNull(networkId, "Network ID cannot be null");
+ checkNotNull(virtualDevice, "Virtual device cannot be null");
+ Set<VirtualPort> virtualPortSet =
+ getVirtualPorts(networkId, virtualDevice.id());
+ Set<DeviceId> physicalDeviceSet = new HashSet<>();
+
+ virtualPortSet.forEach(virtualPort -> {
+ if (virtualPort.realizedBy() != null) {
+ physicalDeviceSet.add(virtualPort.realizedBy().deviceId());
+ }
+ });
+
+ return physicalDeviceSet;
+ }
+
+ /**
* Returns implementation of the specified service class for operating
* in the context of the given network.
* <p>