Brian Stanke
Committed by Gerrit Code Review

ONOS-4075 - Distributed virtual network store implementation,

and virtual network manager Junit tests.

Change-Id: Ic1f82822c894e3c394aa95df1e76ae59fe218120
......@@ -64,7 +64,7 @@ public class DistributedSetTest {
public void basicTests() {
set1.add("item1");
assertEquals("The set name should match.", SETNAME, set1.name());
assertEquals("The set name should match.", DistributedPrimitive.Type.SET, set1.primitiveType());
assertEquals("The set primitive type should match.", DistributedPrimitive.Type.SET, set1.primitiveType());
set1.add("item2");
set1.add("item3");
......
......@@ -27,7 +27,7 @@ import static com.google.common.base.MoreObjects.*;
/**
* Default representation of a virtual device.
*/
public class DefaultVirtualDevice extends DefaultDevice implements VirtualDevice {
public final class DefaultVirtualDevice extends DefaultDevice implements VirtualDevice {
private static final String VIRTUAL = "virtual";
private static final ProviderId PID = new ProviderId(VIRTUAL, VIRTUAL);
......@@ -53,7 +53,7 @@ public class DefaultVirtualDevice extends DefaultDevice implements VirtualDevice
@Override
public int hashCode() {
return 31 * super.hashCode() + networkId.hashCode();
return Objects.hash(networkId);
}
@Override
......
/*
* Copyright 2016 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.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.provider.ProviderId;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Default representation of a virtual link.
*/
public final class DefaultVirtualLink extends DefaultLink implements VirtualLink {
private static final String VIRTUAL = "virtual";
private static final ProviderId PID = new ProviderId(VIRTUAL, VIRTUAL);
private final NetworkId networkId;
private final TunnelId tunnelId;
/**
* Constructor for a default virtual link.
*
* @param networkId network identifier
* @param src source connection point
* @param dst destination connection point
* @param tunnelId tunnel identifier
*/
public DefaultVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) {
super(PID, src, dst, Type.VIRTUAL, DefaultAnnotations.builder().build());
this.networkId = networkId;
this.tunnelId = tunnelId;
}
@Override
public NetworkId networkId() {
return networkId;
}
/**
* Returns the tunnel identifier.
*
* @return tunnel identifier.
*/
public TunnelId tunnelId() {
return tunnelId;
}
@Override
public int hashCode() {
return Objects.hash(networkId, tunnelId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof DefaultVirtualLink) {
DefaultVirtualLink that = (DefaultVirtualLink) obj;
return super.equals(that) &&
Objects.equals(this.networkId, that.networkId) &&
Objects.equals(this.tunnelId, that.tunnelId);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this).add("networkId", networkId).add("tunnelId", tunnelId).toString();
}
}
......@@ -22,7 +22,7 @@ import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Default implementation of the virtual network descriptor.
*/
public class DefaultVirtualNetwork implements VirtualNetwork {
public final class DefaultVirtualNetwork implements VirtualNetwork {
private final NetworkId id;
private final TenantId tenantId;
......
/*
* Copyright 2016 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.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultPort;
import org.onosproject.net.Device;
import org.onosproject.net.Element;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Default representation of a virtual port.
*/
public final class DefaultVirtualPort extends DefaultPort implements VirtualPort {
private final NetworkId networkId;
private final Port realizedBy;
public DefaultVirtualPort(NetworkId networkId, Device device, PortNumber portNumber, Port realizedBy) {
super((Element) device, portNumber, false, DefaultAnnotations.builder().build());
this.networkId = networkId;
this.realizedBy = realizedBy;
}
public NetworkId networkId() {
return networkId;
}
@Override
public Port realizedBy() {
return realizedBy;
}
@Override
public int hashCode() {
return Objects.hash(networkId, realizedBy);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof DefaultVirtualPort) {
DefaultVirtualPort that = (DefaultVirtualPort) obj;
return super.equals(that) &&
Objects.equals(this.networkId, that.networkId) &&
Objects.equals(this.realizedBy, that.realizedBy);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this).add("networkId", networkId).add("realizedBy", realizedBy).toString();
}
}
......@@ -27,6 +27,11 @@ import java.util.Set;
public interface VirtualNetworkService {
/**
* The topic used for obtaining globally unique ids.
*/
String VIRTUAL_NETWORK_TOPIC = "virtual-network-ids";
/**
* Returns a collection of all virtual networks created on behalf of the
* specified tenant.
*
......
/*
* Copyright 2016 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.DeviceId;
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";
/**
* Checks that the DefaultVirtualDevice class is immutable.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(DefaultVirtualDevice.class);
}
@Test
public void testEquality() {
DefaultVirtualDevice device1 =
new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
DefaultVirtualDevice device2 =
new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
DefaultVirtualDevice device3 =
new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
DefaultVirtualDevice device4 =
new DefaultVirtualDevice(NetworkId.networkId(1), DeviceId.deviceId(deviceIdValue1));
new EqualsTester().addEqualityGroup(device1, device2).addEqualityGroup(device3)
.addEqualityGroup(device4).testEquals();
}
}
/*
* Copyright 2016 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.incubator.net.tunnel.TunnelId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
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";
/**
* Checks that the DefaultVirtualLink class is immutable.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(DefaultVirtualLink.class);
}
@Test
public void testEquality() {
DefaultVirtualDevice device1 =
new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
DefaultVirtualDevice device2 =
new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
DefaultVirtualLink link1 = new DefaultVirtualLink(NetworkId.networkId(0), src, dst, TunnelId.valueOf(0));
DefaultVirtualLink link2 = new DefaultVirtualLink(NetworkId.networkId(0), src, dst, TunnelId.valueOf(0));
DefaultVirtualLink link3 = new DefaultVirtualLink(NetworkId.networkId(0), src, dst, TunnelId.valueOf(1));
DefaultVirtualLink link4 = new DefaultVirtualLink(NetworkId.networkId(1), src, dst, TunnelId.valueOf(0));
new EqualsTester().addEqualityGroup(link1, link2).addEqualityGroup(link3)
.addEqualityGroup(link4).testEquals();
}
}
/*
* Copyright 2016 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 static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
/**
* Test of the default virtual network model entity.
*/
public class DefaultVirtualNetworkTest {
final String tenantIdValue1 = "TENANT_ID1";
final String tenantIdValue2 = "TENANT_ID2";
/**
* Checks that the DefaultVirtualNetwork class is immutable.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(DefaultVirtualNetwork.class);
}
@Test
public void testEquality() {
DefaultVirtualNetwork network1 =
new DefaultVirtualNetwork(NetworkId.networkId(0), TenantId.tenantId(tenantIdValue1));
DefaultVirtualNetwork network2 =
new DefaultVirtualNetwork(NetworkId.networkId(0), TenantId.tenantId(tenantIdValue1));
DefaultVirtualNetwork network3 =
new DefaultVirtualNetwork(NetworkId.networkId(0), TenantId.tenantId(tenantIdValue2));
DefaultVirtualNetwork network4 =
new DefaultVirtualNetwork(NetworkId.networkId(1), TenantId.tenantId(tenantIdValue2));
new EqualsTester().addEqualityGroup(network1, network2).addEqualityGroup(network3)
.addEqualityGroup(network4).testEquals();
}
}
/*
* Copyright 2016 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.DefaultPort;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
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";
/**
* Checks that the DefaultVirtualPort class is immutable.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(DefaultVirtualPort.class);
}
@Test
public void testEquality() {
DefaultVirtualDevice device1 =
new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
DefaultVirtualDevice device2 =
new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
Port portA = new DefaultPort(device1, PortNumber.portNumber(1), true);
Port portB = new DefaultPort(device1, PortNumber.portNumber(2), true);
Port portC = new DefaultPort(device2, PortNumber.portNumber(2), true);
DefaultVirtualPort port1 =
new DefaultVirtualPort(NetworkId.networkId(0), device1, PortNumber.portNumber(1), portA);
DefaultVirtualPort port2 =
new DefaultVirtualPort(NetworkId.networkId(0), device1, PortNumber.portNumber(1), portA);
DefaultVirtualPort port3 =
new DefaultVirtualPort(NetworkId.networkId(0), device1, PortNumber.portNumber(2), portB);
DefaultVirtualPort port4 =
new DefaultVirtualPort(NetworkId.networkId(1), device2, PortNumber.portNumber(2), portC);
new EqualsTester().addEqualityGroup(port1, port2).addEqualityGroup(port3)
.addEqualityGroup(port4).testEquals();
}
}
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2016 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.
......@@ -57,7 +57,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
@Service
public class VirtualNetworkManager
extends AbstractListenerProviderRegistry<VirtualNetworkEvent, VirtualNetworkListener,
VirtualNetworkProvider, VirtualNetworkProviderService>
VirtualNetworkProvider, VirtualNetworkProviderService>
implements VirtualNetworkService, VirtualNetworkAdminService, VirtualNetworkProviderRegistry {
private final Logger log = LoggerFactory.getLogger(getClass());
......@@ -70,19 +70,23 @@ public class VirtualNetworkManager
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected VirtualNetworkStore store;
private VirtualNetworkStoreDelegate delegate = new InternalStoreDelegate();
private VirtualNetworkStoreDelegate delegate = this::post;
// TODO: figure out how to coordinate "implementation" of a virtual network in a cluster
@Activate
protected void activate() {
store.setDelegate(delegate);
eventDispatcher.addSink(VirtualNetworkEvent.class, listenerRegistry);
log.info("Started");
}
@Deactivate
protected void deactivate() {
store.unsetDelegate(delegate);
eventDispatcher.removeSink(VirtualNetworkEvent.class);
log.info("Stopped");
}
......@@ -211,13 +215,4 @@ public class VirtualNetworkManager
}
}
// Auxiliary store delegate to receive notification about changes in
// the virtual network configuration store state - by the store itself.
private class InternalStoreDelegate implements VirtualNetworkStoreDelegate {
@Override
public void notify(VirtualNetworkEvent event) {
post(event);
}
}
}
......