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
diff --git a/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualDeviceTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualDeviceTest.java
index 04ba6a9..1fd97e3 100644
--- a/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualDeviceTest.java
+++ b/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualDeviceTest.java
@@ -18,16 +18,14 @@
import com.google.common.testing.EqualsTester;
import org.junit.Test;
-import org.onosproject.net.DeviceId;
+import org.onosproject.net.TestDeviceParams;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
/**
* Test of the default virtual device model entity.
*/
-public class DefaultVirtualDeviceTest {
- final String deviceIdValue1 = "DEVICE_ID1";
- final String deviceIdValue2 = "DEVICE_ID2";
+public class DefaultVirtualDeviceTest extends TestDeviceParams {
/**
* Checks that the DefaultVirtualDevice class is immutable.
@@ -40,13 +38,13 @@
@Test
public void testEquality() {
DefaultVirtualDevice device1 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID1);
DefaultVirtualDevice device2 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID1);
DefaultVirtualDevice device3 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID2);
DefaultVirtualDevice device4 =
- new DefaultVirtualDevice(NetworkId.networkId(1), DeviceId.deviceId(deviceIdValue1));
+ new DefaultVirtualDevice(NetworkId.networkId(1), DID1);
new EqualsTester().addEqualityGroup(device1, device2).addEqualityGroup(device3)
.addEqualityGroup(device4).testEquals();
diff --git a/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualHostTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualHostTest.java
new file mode 100644
index 0000000..461088f
--- /dev/null
+++ b/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualHostTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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 com.google.common.testing.EqualsTester;
+import org.junit.Test;
+import org.onosproject.net.TestDeviceParams;
+
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
+/**
+ * Test of the default virtual host model entity.
+ */
+public class DefaultVirtualHostTest extends TestDeviceParams {
+
+ /**
+ * Checks that the DefaultVirtualHost class is immutable.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(DefaultVirtualHost.class);
+ }
+
+ /**
+ * Tests the DefaultVirtualHost equality method.
+ */
+ @Test
+ public void testEquality() {
+ DefaultVirtualHost host1 =
+ new DefaultVirtualHost(NetworkId.networkId(0), HID1, MAC1, VLAN1, LOC1, IPSET1);
+ DefaultVirtualHost host2 =
+ new DefaultVirtualHost(NetworkId.networkId(0), HID1, MAC1, VLAN1, LOC1, IPSET1);
+ DefaultVirtualHost host3 =
+ new DefaultVirtualHost(NetworkId.networkId(0), HID2, MAC1, VLAN1, LOC1, IPSET1);
+ DefaultVirtualHost host4 =
+ new DefaultVirtualHost(NetworkId.networkId(1), HID2, MAC1, VLAN1, LOC1, IPSET1);
+
+ new EqualsTester().addEqualityGroup(host1, host2).addEqualityGroup(host3)
+ .addEqualityGroup(host4).testEquals();
+ }
+}
diff --git a/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualLinkTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualLinkTest.java
index 71e214a..00b1db0 100644
--- a/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualLinkTest.java
+++ b/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualLinkTest.java
@@ -20,17 +20,15 @@
import org.junit.Test;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
+import org.onosproject.net.TestDeviceParams;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
/**
* Test of the default virtual link model entity.
*/
-public class DefaultVirtualLinkTest {
- final String deviceIdValue1 = "DEVICE_ID1";
- final String deviceIdValue2 = "DEVICE_ID2";
+public class DefaultVirtualLinkTest extends TestDeviceParams {
/**
* Checks that the DefaultVirtualLink class is immutable.
@@ -46,9 +44,9 @@
@Test(expected = NullPointerException.class)
public void testBuilderNullSrc() {
DefaultVirtualDevice device1 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID1);
DefaultVirtualDevice device2 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID2);
ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
@@ -63,9 +61,9 @@
@Test(expected = NullPointerException.class)
public void testBuilderNullDst() {
DefaultVirtualDevice device1 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID1);
DefaultVirtualDevice device2 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID2);
ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
@@ -80,9 +78,9 @@
@Test(expected = NullPointerException.class)
public void testBuilderNullNetworkId() {
DefaultVirtualDevice device1 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID1);
DefaultVirtualDevice device2 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID2);
ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
@@ -97,9 +95,9 @@
@Test
public void testEquality() {
DefaultVirtualDevice device1 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID1);
DefaultVirtualDevice device2 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID2);
ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
diff --git a/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualPortTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualPortTest.java
index da560f9..6b83e3a 100644
--- a/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualPortTest.java
+++ b/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/DefaultVirtualPortTest.java
@@ -19,18 +19,16 @@
import com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.net.DefaultPort;
-import org.onosproject.net.DeviceId;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
+import org.onosproject.net.TestDeviceParams;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
/**
* Test of the default virtual port model entity.
*/
-public class DefaultVirtualPortTest {
- final String deviceIdValue1 = "DEVICE_ID1";
- final String deviceIdValue2 = "DEVICE_ID2";
+public class DefaultVirtualPortTest extends TestDeviceParams {
/**
* Checks that the DefaultVirtualPort class is immutable.
@@ -43,9 +41,9 @@
@Test
public void testEquality() {
DefaultVirtualDevice device1 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID1);
DefaultVirtualDevice device2 =
- new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
+ new DefaultVirtualDevice(NetworkId.networkId(0), DID2);
Port portA = new DefaultPort(device1, PortNumber.portNumber(1), true);
Port portB = new DefaultPort(device1, PortNumber.portNumber(2), true);