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 { ...@@ -64,7 +64,7 @@ public class DistributedSetTest {
64 public void basicTests() { 64 public void basicTests() {
65 set1.add("item1"); 65 set1.add("item1");
66 assertEquals("The set name should match.", SETNAME, set1.name()); 66 assertEquals("The set name should match.", SETNAME, set1.name());
67 - assertEquals("The set name should match.", DistributedPrimitive.Type.SET, set1.primitiveType()); 67 + assertEquals("The set primitive type should match.", DistributedPrimitive.Type.SET, set1.primitiveType());
68 68
69 set1.add("item2"); 69 set1.add("item2");
70 set1.add("item3"); 70 set1.add("item3");
......
...@@ -27,7 +27,7 @@ import static com.google.common.base.MoreObjects.*; ...@@ -27,7 +27,7 @@ import static com.google.common.base.MoreObjects.*;
27 /** 27 /**
28 * Default representation of a virtual device. 28 * Default representation of a virtual device.
29 */ 29 */
30 -public class DefaultVirtualDevice extends DefaultDevice implements VirtualDevice { 30 +public final class DefaultVirtualDevice extends DefaultDevice implements VirtualDevice {
31 31
32 private static final String VIRTUAL = "virtual"; 32 private static final String VIRTUAL = "virtual";
33 private static final ProviderId PID = new ProviderId(VIRTUAL, VIRTUAL); 33 private static final ProviderId PID = new ProviderId(VIRTUAL, VIRTUAL);
...@@ -53,7 +53,7 @@ public class DefaultVirtualDevice extends DefaultDevice implements VirtualDevice ...@@ -53,7 +53,7 @@ public class DefaultVirtualDevice extends DefaultDevice implements VirtualDevice
53 53
54 @Override 54 @Override
55 public int hashCode() { 55 public int hashCode() {
56 - return 31 * super.hashCode() + networkId.hashCode(); 56 + return Objects.hash(networkId);
57 } 57 }
58 58
59 @Override 59 @Override
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.incubator.net.virtual;
18 +
19 +import org.onosproject.incubator.net.tunnel.TunnelId;
20 +import org.onosproject.net.ConnectPoint;
21 +import org.onosproject.net.DefaultAnnotations;
22 +import org.onosproject.net.DefaultLink;
23 +import org.onosproject.net.provider.ProviderId;
24 +
25 +import java.util.Objects;
26 +
27 +import static com.google.common.base.MoreObjects.toStringHelper;
28 +
29 +/**
30 + * Default representation of a virtual link.
31 + */
32 +public final class DefaultVirtualLink extends DefaultLink implements VirtualLink {
33 +
34 + private static final String VIRTUAL = "virtual";
35 + private static final ProviderId PID = new ProviderId(VIRTUAL, VIRTUAL);
36 +
37 + private final NetworkId networkId;
38 + private final TunnelId tunnelId;
39 +
40 + /**
41 + * Constructor for a default virtual link.
42 + *
43 + * @param networkId network identifier
44 + * @param src source connection point
45 + * @param dst destination connection point
46 + * @param tunnelId tunnel identifier
47 + */
48 + public DefaultVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) {
49 + super(PID, src, dst, Type.VIRTUAL, DefaultAnnotations.builder().build());
50 + this.networkId = networkId;
51 + this.tunnelId = tunnelId;
52 + }
53 +
54 + @Override
55 + public NetworkId networkId() {
56 + return networkId;
57 + }
58 +
59 + /**
60 + * Returns the tunnel identifier.
61 + *
62 + * @return tunnel identifier.
63 + */
64 + public TunnelId tunnelId() {
65 + return tunnelId;
66 + }
67 +
68 + @Override
69 + public int hashCode() {
70 + return Objects.hash(networkId, tunnelId);
71 + }
72 +
73 + @Override
74 + public boolean equals(Object obj) {
75 + if (this == obj) {
76 + return true;
77 + }
78 + if (obj instanceof DefaultVirtualLink) {
79 + DefaultVirtualLink that = (DefaultVirtualLink) obj;
80 + return super.equals(that) &&
81 + Objects.equals(this.networkId, that.networkId) &&
82 + Objects.equals(this.tunnelId, that.tunnelId);
83 + }
84 + return false;
85 + }
86 +
87 + @Override
88 + public String toString() {
89 + return toStringHelper(this).add("networkId", networkId).add("tunnelId", tunnelId).toString();
90 + }
91 +}
...@@ -22,7 +22,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; ...@@ -22,7 +22,7 @@ import static com.google.common.base.MoreObjects.toStringHelper;
22 /** 22 /**
23 * Default implementation of the virtual network descriptor. 23 * Default implementation of the virtual network descriptor.
24 */ 24 */
25 -public class DefaultVirtualNetwork implements VirtualNetwork { 25 +public final class DefaultVirtualNetwork implements VirtualNetwork {
26 26
27 private final NetworkId id; 27 private final NetworkId id;
28 private final TenantId tenantId; 28 private final TenantId tenantId;
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.incubator.net.virtual;
18 +
19 +import org.onosproject.net.DefaultAnnotations;
20 +import org.onosproject.net.DefaultPort;
21 +import org.onosproject.net.Device;
22 +import org.onosproject.net.Element;
23 +import org.onosproject.net.Port;
24 +import org.onosproject.net.PortNumber;
25 +
26 +import java.util.Objects;
27 +
28 +import static com.google.common.base.MoreObjects.toStringHelper;
29 +
30 +/**
31 + * Default representation of a virtual port.
32 + */
33 +public final class DefaultVirtualPort extends DefaultPort implements VirtualPort {
34 +
35 +
36 + private final NetworkId networkId;
37 + private final Port realizedBy;
38 +
39 + public DefaultVirtualPort(NetworkId networkId, Device device, PortNumber portNumber, Port realizedBy) {
40 + super((Element) device, portNumber, false, DefaultAnnotations.builder().build());
41 + this.networkId = networkId;
42 + this.realizedBy = realizedBy;
43 + }
44 +
45 + public NetworkId networkId() {
46 + return networkId;
47 + }
48 +
49 + @Override
50 + public Port realizedBy() {
51 + return realizedBy;
52 + }
53 +
54 + @Override
55 + public int hashCode() {
56 + return Objects.hash(networkId, realizedBy);
57 + }
58 +
59 + @Override
60 + public boolean equals(Object obj) {
61 + if (this == obj) {
62 + return true;
63 + }
64 + if (obj instanceof DefaultVirtualPort) {
65 + DefaultVirtualPort that = (DefaultVirtualPort) obj;
66 + return super.equals(that) &&
67 + Objects.equals(this.networkId, that.networkId) &&
68 + Objects.equals(this.realizedBy, that.realizedBy);
69 + }
70 + return false;
71 + }
72 +
73 + @Override
74 + public String toString() {
75 + return toStringHelper(this).add("networkId", networkId).add("realizedBy", realizedBy).toString();
76 + }
77 +
78 +}
...@@ -27,6 +27,11 @@ import java.util.Set; ...@@ -27,6 +27,11 @@ import java.util.Set;
27 public interface VirtualNetworkService { 27 public interface VirtualNetworkService {
28 28
29 /** 29 /**
30 + * The topic used for obtaining globally unique ids.
31 + */
32 + String VIRTUAL_NETWORK_TOPIC = "virtual-network-ids";
33 +
34 + /**
30 * Returns a collection of all virtual networks created on behalf of the 35 * Returns a collection of all virtual networks created on behalf of the
31 * specified tenant. 36 * specified tenant.
32 * 37 *
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.incubator.net.virtual;
18 +
19 +import com.google.common.testing.EqualsTester;
20 +import org.junit.Test;
21 +import org.onosproject.net.DeviceId;
22 +
23 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
24 +
25 +/**
26 + * Test of the default virtual device model entity.
27 + */
28 +public class DefaultVirtualDeviceTest {
29 + final String deviceIdValue1 = "DEVICE_ID1";
30 + final String deviceIdValue2 = "DEVICE_ID2";
31 +
32 + /**
33 + * Checks that the DefaultVirtualDevice class is immutable.
34 + */
35 + @Test
36 + public void testImmutability() {
37 + assertThatClassIsImmutable(DefaultVirtualDevice.class);
38 + }
39 +
40 + @Test
41 + public void testEquality() {
42 + DefaultVirtualDevice device1 =
43 + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
44 + DefaultVirtualDevice device2 =
45 + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
46 + DefaultVirtualDevice device3 =
47 + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
48 + DefaultVirtualDevice device4 =
49 + new DefaultVirtualDevice(NetworkId.networkId(1), DeviceId.deviceId(deviceIdValue1));
50 +
51 + new EqualsTester().addEqualityGroup(device1, device2).addEqualityGroup(device3)
52 + .addEqualityGroup(device4).testEquals();
53 + }
54 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.incubator.net.virtual;
18 +
19 +import com.google.common.testing.EqualsTester;
20 +import org.junit.Test;
21 +import org.onosproject.incubator.net.tunnel.TunnelId;
22 +import org.onosproject.net.ConnectPoint;
23 +import org.onosproject.net.DeviceId;
24 +import org.onosproject.net.PortNumber;
25 +
26 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
27 +
28 +/**
29 + * Test of the default virtual link model entity.
30 + */
31 +public class DefaultVirtualLinkTest {
32 + final String deviceIdValue1 = "DEVICE_ID1";
33 + final String deviceIdValue2 = "DEVICE_ID2";
34 +
35 + /**
36 + * Checks that the DefaultVirtualLink class is immutable.
37 + */
38 + @Test
39 + public void testImmutability() {
40 + assertThatClassIsImmutable(DefaultVirtualLink.class);
41 + }
42 +
43 + @Test
44 + public void testEquality() {
45 + DefaultVirtualDevice device1 =
46 + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
47 + DefaultVirtualDevice device2 =
48 + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
49 + ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1));
50 + ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2));
51 +
52 + DefaultVirtualLink link1 = new DefaultVirtualLink(NetworkId.networkId(0), src, dst, TunnelId.valueOf(0));
53 + DefaultVirtualLink link2 = new DefaultVirtualLink(NetworkId.networkId(0), src, dst, TunnelId.valueOf(0));
54 + DefaultVirtualLink link3 = new DefaultVirtualLink(NetworkId.networkId(0), src, dst, TunnelId.valueOf(1));
55 + DefaultVirtualLink link4 = new DefaultVirtualLink(NetworkId.networkId(1), src, dst, TunnelId.valueOf(0));
56 +
57 + new EqualsTester().addEqualityGroup(link1, link2).addEqualityGroup(link3)
58 + .addEqualityGroup(link4).testEquals();
59 + }
60 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.incubator.net.virtual;
18 +
19 +import com.google.common.testing.EqualsTester;
20 +import org.junit.Test;
21 +
22 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
23 +
24 +/**
25 + * Test of the default virtual network model entity.
26 + */
27 +public class DefaultVirtualNetworkTest {
28 + final String tenantIdValue1 = "TENANT_ID1";
29 + final String tenantIdValue2 = "TENANT_ID2";
30 +
31 + /**
32 + * Checks that the DefaultVirtualNetwork class is immutable.
33 + */
34 + @Test
35 + public void testImmutability() {
36 + assertThatClassIsImmutable(DefaultVirtualNetwork.class);
37 + }
38 +
39 + @Test
40 + public void testEquality() {
41 + DefaultVirtualNetwork network1 =
42 + new DefaultVirtualNetwork(NetworkId.networkId(0), TenantId.tenantId(tenantIdValue1));
43 + DefaultVirtualNetwork network2 =
44 + new DefaultVirtualNetwork(NetworkId.networkId(0), TenantId.tenantId(tenantIdValue1));
45 + DefaultVirtualNetwork network3 =
46 + new DefaultVirtualNetwork(NetworkId.networkId(0), TenantId.tenantId(tenantIdValue2));
47 + DefaultVirtualNetwork network4 =
48 + new DefaultVirtualNetwork(NetworkId.networkId(1), TenantId.tenantId(tenantIdValue2));
49 +
50 + new EqualsTester().addEqualityGroup(network1, network2).addEqualityGroup(network3)
51 + .addEqualityGroup(network4).testEquals();
52 + }
53 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.incubator.net.virtual;
18 +
19 +import com.google.common.testing.EqualsTester;
20 +import org.junit.Test;
21 +import org.onosproject.net.DefaultPort;
22 +import org.onosproject.net.DeviceId;
23 +import org.onosproject.net.Port;
24 +import org.onosproject.net.PortNumber;
25 +
26 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
27 +
28 +/**
29 + * Test of the default virtual port model entity.
30 + */
31 +public class DefaultVirtualPortTest {
32 + final String deviceIdValue1 = "DEVICE_ID1";
33 + final String deviceIdValue2 = "DEVICE_ID2";
34 +
35 + /**
36 + * Checks that the DefaultVirtualPort class is immutable.
37 + */
38 + @Test
39 + public void testImmutability() {
40 + assertThatClassIsImmutable(DefaultVirtualPort.class);
41 + }
42 +
43 + @Test
44 + public void testEquality() {
45 + DefaultVirtualDevice device1 =
46 + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1));
47 + DefaultVirtualDevice device2 =
48 + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2));
49 +
50 + Port portA = new DefaultPort(device1, PortNumber.portNumber(1), true);
51 + Port portB = new DefaultPort(device1, PortNumber.portNumber(2), true);
52 + Port portC = new DefaultPort(device2, PortNumber.portNumber(2), true);
53 +
54 + DefaultVirtualPort port1 =
55 + new DefaultVirtualPort(NetworkId.networkId(0), device1, PortNumber.portNumber(1), portA);
56 + DefaultVirtualPort port2 =
57 + new DefaultVirtualPort(NetworkId.networkId(0), device1, PortNumber.portNumber(1), portA);
58 + DefaultVirtualPort port3 =
59 + new DefaultVirtualPort(NetworkId.networkId(0), device1, PortNumber.portNumber(2), portB);
60 + DefaultVirtualPort port4 =
61 + new DefaultVirtualPort(NetworkId.networkId(1), device2, PortNumber.portNumber(2), portC);
62 +
63 +
64 + new EqualsTester().addEqualityGroup(port1, port2).addEqualityGroup(port3)
65 + .addEqualityGroup(port4).testEquals();
66 + }
67 +}
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -70,19 +70,23 @@ public class VirtualNetworkManager ...@@ -70,19 +70,23 @@ public class VirtualNetworkManager
70 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 70 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
71 protected VirtualNetworkStore store; 71 protected VirtualNetworkStore store;
72 72
73 - private VirtualNetworkStoreDelegate delegate = new InternalStoreDelegate(); 73 + private VirtualNetworkStoreDelegate delegate = this::post;
74 74
75 // TODO: figure out how to coordinate "implementation" of a virtual network in a cluster 75 // TODO: figure out how to coordinate "implementation" of a virtual network in a cluster
76 76
77 @Activate 77 @Activate
78 protected void activate() { 78 protected void activate() {
79 store.setDelegate(delegate); 79 store.setDelegate(delegate);
80 + eventDispatcher.addSink(VirtualNetworkEvent.class, listenerRegistry);
81 +
80 log.info("Started"); 82 log.info("Started");
81 } 83 }
82 84
83 @Deactivate 85 @Deactivate
84 protected void deactivate() { 86 protected void deactivate() {
85 store.unsetDelegate(delegate); 87 store.unsetDelegate(delegate);
88 + eventDispatcher.removeSink(VirtualNetworkEvent.class);
89 +
86 log.info("Stopped"); 90 log.info("Stopped");
87 } 91 }
88 92
...@@ -211,13 +215,4 @@ public class VirtualNetworkManager ...@@ -211,13 +215,4 @@ public class VirtualNetworkManager
211 } 215 }
212 } 216 }
213 217
214 - // Auxiliary store delegate to receive notification about changes in
215 - // the virtual network configuration store state - by the store itself.
216 - private class InternalStoreDelegate implements VirtualNetworkStoreDelegate {
217 - @Override
218 - public void notify(VirtualNetworkEvent event) {
219 - post(event);
220 - }
221 - }
222 -
223 } 218 }
......