ONOS-2184 Adding VirtualHost support in Virtual Networks.
Change-Id: I1318f20a9b14f1f99dc8eb48b9660a208165bac1
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/DefaultVirtualHost.java b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/DefaultVirtualHost.java
new file mode 100644
index 0000000..2256fd3
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/DefaultVirtualHost.java
@@ -0,0 +1,85 @@
+/*
+ * 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.incubator.net.virtual;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultHost;
+import org.onosproject.net.HostId;
+import org.onosproject.net.HostLocation;
+import org.onosproject.net.provider.ProviderId;
+
+import java.util.Objects;
+import java.util.Set;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Default representation of a virtual host.
+ */
+public final class DefaultVirtualHost extends DefaultHost implements VirtualHost {
+
+ private static final String VIRTUAL = "virtual";
+ private static final ProviderId PID = new ProviderId(VIRTUAL, VIRTUAL);
+
+ private final NetworkId networkId;
+
+ /**
+ * Creates a virtual host attributed to the specified provider.
+ *
+ * @param networkId network identifier
+ * @param id host identifier
+ * @param mac host MAC address
+ * @param vlan host VLAN identifier
+ * @param location host location
+ * @param ips host IP addresses
+ */
+ public DefaultVirtualHost(NetworkId networkId, HostId id, MacAddress mac,
+ VlanId vlan, HostLocation location, Set<IpAddress> ips) {
+ super(PID, id, mac, vlan, location, ips, DefaultAnnotations.builder().build());
+ this.networkId = networkId;
+ }
+
+ @Override
+ public NetworkId networkId() {
+ return networkId;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(networkId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DefaultVirtualHost) {
+ DefaultVirtualHost that = (DefaultVirtualHost) obj;
+ return super.equals(that) && Objects.equals(this.networkId, that.networkId);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this).add("networkId", networkId).toString();
+ }
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkAdminService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkAdminService.java
index c903e61..04d1911 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkAdminService.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkAdminService.java
@@ -16,8 +16,13 @@
package org.onosproject.incubator.net.virtual;
import com.google.common.annotations.Beta;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
+import org.onosproject.net.HostId;
+import org.onosproject.net.HostLocation;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
@@ -74,7 +79,7 @@
*
* @param networkId network identifier
* @param deviceId device identifier
- * @return newly created device
+ * @return newly created virtual device
* @throws org.onlab.util.ItemNotFoundException if no such network found
*/
VirtualDevice createVirtualDevice(NetworkId networkId, DeviceId deviceId);
@@ -88,6 +93,30 @@
*/
void removeVirtualDevice(NetworkId networkId, DeviceId deviceId);
+ /**
+ * Creates a new virtual host within the specified network. The host id
+ * must be unique within the bounds of the network.
+ *
+ * @param networkId network identifier
+ * @param hostId host identifier
+ * @param mac mac address
+ * @param vlan vlan identifier
+ * @param location host location
+ * @param ips set of ip addresses
+ * @return newly created virtual host
+ * @throws org.onlab.util.ItemNotFoundException if no such network found
+ */
+ VirtualHost createVirtualHost(NetworkId networkId, HostId hostId, MacAddress mac,
+ VlanId vlan, HostLocation location, Set<IpAddress> ips);
+
+ /**
+ * Removes the specified virtual host.
+ *
+ * @param networkId network identifier
+ * @param hostId host identifier
+ * @throws org.onlab.util.ItemNotFoundException if no such network or host found
+ */
+ void removeVirtualHost(NetworkId networkId, HostId hostId);
/**
* Creates a new virtual link within the specified network.
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 ebe0b69..530c67a 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
@@ -51,6 +51,15 @@
Set<VirtualDevice> getVirtualDevices(NetworkId networkId);
/**
+ * Returns a collection of all virtual hosts in the specified network.
+ *
+ * @param networkId network identifier
+ * @return collection of hosts
+ * @throws org.onlab.util.ItemNotFoundException if no such network found
+ */
+ Set<VirtualHost> getVirtualHosts(NetworkId networkId);
+
+ /**
* Returns collection of all virtual links in the specified network.
*
* @param networkId network identifier
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkStore.java b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkStore.java
index 11bcc7b..c2bc250 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkStore.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkStore.java
@@ -15,9 +15,14 @@
*/
package org.onosproject.incubator.net.virtual;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
+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;
@@ -77,7 +82,7 @@
VirtualDevice addDevice(NetworkId networkId, DeviceId deviceId);
/**
- * Renmoves the specified virtual device from the given network.
+ * Removes the specified virtual device from the given network.
*
* @param networkId network identifier
* @param deviceId device identifier
@@ -85,6 +90,28 @@
void removeDevice(NetworkId networkId, DeviceId deviceId);
/**
+ * Adds a new virtual host to the store.
+ *
+ * @param networkId network identifier
+ * @param hostId host identifier
+ * @param mac mac address
+ * @param vlan vlan identifier
+ * @param location host location
+ * @param ips set of ip addresses
+ * @return the virtual host
+ */
+ VirtualHost addHost(NetworkId networkId, HostId hostId, MacAddress mac,
+ VlanId vlan, HostLocation location, Set<IpAddress> ips);
+
+ /**
+ * Removes the specified virtual host from the store.
+ *
+ * @param networkId network identifier
+ * @param hostId host identifier
+ */
+ void removeHost(NetworkId networkId, HostId hostId);
+
+ /**
* Adds a new virtual link.
*
* @param networkId network identifier
@@ -147,7 +174,7 @@
/**
* Returns the virtual network for the given network identifier.
*
- * @param networkId network identifier
+ * @param networkId network identifier
* @return the virtual network
*/
VirtualNetwork getNetwork(NetworkId networkId);
@@ -161,6 +188,14 @@
Set<VirtualDevice> getDevices(NetworkId networkId);
/**
+ * Returns the list of hosts in the specified virtual network.
+ *
+ * @param networkId network identifier
+ * @return set of virtual hosts
+ */
+ Set<VirtualHost> getHosts(NetworkId networkId);
+
+ /**
* Returns the list of virtual links in the specified virtual network.
*
* @param networkId network identifier