Committed by
Gerrit Code Review
ONOS-2184 - initial impl. of virtual network path service; move path related me…
…thods from PathManager to AbstractPathService (since they are reused for VirtualNetworkPathService). Change-Id: Ib4211d69a15c23a50de420b771877bb659539c22
Showing
6 changed files
with
323 additions
and
3 deletions
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
... | @@ -18,6 +18,7 @@ package org.onosproject.net.topology.impl; | ... | @@ -18,6 +18,7 @@ package org.onosproject.net.topology.impl; |
18 | import org.junit.After; | 18 | import org.junit.After; |
19 | import org.junit.Before; | 19 | import org.junit.Before; |
20 | import org.junit.Test; | 20 | import org.junit.Test; |
21 | +import org.onlab.junit.TestUtils; | ||
21 | import org.onosproject.net.DeviceId; | 22 | import org.onosproject.net.DeviceId; |
22 | import org.onosproject.net.ElementId; | 23 | import org.onosproject.net.ElementId; |
23 | import org.onosproject.net.Host; | 24 | import org.onosproject.net.Host; |
... | @@ -53,11 +54,11 @@ public class PathManagerTest { | ... | @@ -53,11 +54,11 @@ public class PathManagerTest { |
53 | private FakeHostMgr fakeHostMgr = new FakeHostMgr(); | 54 | private FakeHostMgr fakeHostMgr = new FakeHostMgr(); |
54 | 55 | ||
55 | @Before | 56 | @Before |
56 | - public void setUp() { | 57 | + public void setUp() throws Exception { |
57 | mgr = new PathManager(); | 58 | mgr = new PathManager(); |
58 | service = mgr; | 59 | service = mgr; |
59 | - mgr.topologyService = fakeTopoMgr; | 60 | + TestUtils.setField(mgr, "topologyService", fakeTopoMgr); |
60 | - mgr.hostService = fakeHostMgr; | 61 | + TestUtils.setField(mgr, "hostService", fakeHostMgr); |
61 | mgr.activate(); | 62 | mgr.activate(); |
62 | } | 63 | } |
63 | 64 | ... | ... |
... | @@ -61,6 +61,7 @@ import org.onosproject.net.intent.IntentState; | ... | @@ -61,6 +61,7 @@ import org.onosproject.net.intent.IntentState; |
61 | import org.onosproject.net.link.LinkService; | 61 | import org.onosproject.net.link.LinkService; |
62 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; | 62 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; |
63 | import org.onosproject.net.provider.AbstractProviderService; | 63 | import org.onosproject.net.provider.AbstractProviderService; |
64 | +import org.onosproject.net.topology.PathService; | ||
64 | import org.onosproject.net.topology.TopologyService; | 65 | import org.onosproject.net.topology.TopologyService; |
65 | import org.slf4j.Logger; | 66 | import org.slf4j.Logger; |
66 | import org.slf4j.LoggerFactory; | 67 | import org.slf4j.LoggerFactory; |
... | @@ -371,6 +372,8 @@ public class VirtualNetworkManager | ... | @@ -371,6 +372,8 @@ public class VirtualNetworkManager |
371 | service = new VirtualNetworkIntentService(this, network, new DefaultServiceDirectory()); | 372 | service = new VirtualNetworkIntentService(this, network, new DefaultServiceDirectory()); |
372 | } else if (serviceKey.serviceClass.equals(HostService.class)) { | 373 | } else if (serviceKey.serviceClass.equals(HostService.class)) { |
373 | service = new VirtualNetworkHostService(this, network); | 374 | service = new VirtualNetworkHostService(this, network); |
375 | + } else if (serviceKey.serviceClass.equals(PathService.class)) { | ||
376 | + service = new VirtualNetworkPathService(this, network); | ||
374 | } else { | 377 | } else { |
375 | return null; | 378 | return null; |
376 | } | 379 | } | ... | ... |
1 | +/* | ||
2 | + * | ||
3 | + * * Copyright 2016-present Open Networking Laboratory | ||
4 | + * * | ||
5 | + * * Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + * * you may not use this file except in compliance with the License. | ||
7 | + * * You may obtain a copy of the License at | ||
8 | + * * | ||
9 | + * * http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + * * | ||
11 | + * * Unless required by applicable law or agreed to in writing, software | ||
12 | + * * distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + * * See the License for the specific language governing permissions and | ||
15 | + * * limitations under the License. | ||
16 | + * | ||
17 | + */ | ||
18 | + | ||
19 | +package org.onosproject.incubator.net.virtual.impl; | ||
20 | + | ||
21 | +import org.onosproject.incubator.net.virtual.VirtualNetwork; | ||
22 | +import org.onosproject.incubator.net.virtual.VirtualNetworkService; | ||
23 | +import org.onosproject.net.DisjointPath; | ||
24 | +import org.onosproject.net.ElementId; | ||
25 | +import org.onosproject.net.Link; | ||
26 | +import org.onosproject.net.Path; | ||
27 | +import org.onosproject.net.host.HostService; | ||
28 | +import org.onosproject.net.topology.LinkWeight; | ||
29 | +import org.onosproject.net.topology.PathService; | ||
30 | +import org.onosproject.net.topology.AbstractPathService; | ||
31 | +import org.onosproject.net.topology.TopologyService; | ||
32 | + | ||
33 | +import java.util.Map; | ||
34 | +import java.util.Set; | ||
35 | + | ||
36 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
37 | + | ||
38 | +/** | ||
39 | + * Path service implementation built on the virtual network service. | ||
40 | + */ | ||
41 | +public class VirtualNetworkPathService extends AbstractPathService | ||
42 | + implements PathService, VnetService { | ||
43 | + | ||
44 | + private static final String NETWORK_NULL = "Network ID cannot be null"; | ||
45 | + | ||
46 | + private final VirtualNetwork network; | ||
47 | + | ||
48 | + /** | ||
49 | + * Creates a new virtual network path service object. | ||
50 | + * | ||
51 | + * @param virtualNetworkManager virtual network manager service | ||
52 | + * @param network virtual network | ||
53 | + */ | ||
54 | + | ||
55 | + public VirtualNetworkPathService(VirtualNetworkService virtualNetworkManager, VirtualNetwork network) { | ||
56 | + checkNotNull(network, NETWORK_NULL); | ||
57 | + this.network = network; | ||
58 | + topologyService = virtualNetworkManager.get(network.id(), TopologyService.class); | ||
59 | + hostService = virtualNetworkManager.get(network.id(), HostService.class); | ||
60 | + } | ||
61 | + | ||
62 | + @Override | ||
63 | + public Set<Path> getPaths(ElementId src, ElementId dst) { | ||
64 | + return getPaths(src, dst, null); | ||
65 | + } | ||
66 | + | ||
67 | + @Override | ||
68 | + public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst) { | ||
69 | + return getDisjointPaths(src, dst, (LinkWeight) null); | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
73 | + public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, Map<Link, Object> riskProfile) { | ||
74 | + return getDisjointPaths(src, dst, null, riskProfile); | ||
75 | + } | ||
76 | + | ||
77 | + @Override | ||
78 | + public VirtualNetwork network() { | ||
79 | + return network; | ||
80 | + } | ||
81 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present 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.impl; | ||
18 | + | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onlab.junit.TestUtils; | ||
23 | +import org.onosproject.common.event.impl.TestEventDispatcher; | ||
24 | +import org.onosproject.core.CoreService; | ||
25 | +import org.onosproject.incubator.net.virtual.TenantId; | ||
26 | +import org.onosproject.incubator.net.virtual.VirtualDevice; | ||
27 | +import org.onosproject.incubator.net.virtual.VirtualLink; | ||
28 | +import org.onosproject.incubator.net.virtual.VirtualNetwork; | ||
29 | +import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore; | ||
30 | +import org.onosproject.net.ConnectPoint; | ||
31 | +import org.onosproject.net.DefaultPort; | ||
32 | +import org.onosproject.net.DeviceId; | ||
33 | +import org.onosproject.net.DisjointPath; | ||
34 | +import org.onosproject.net.ElementId; | ||
35 | +import org.onosproject.net.Link; | ||
36 | +import org.onosproject.net.NetTestTools; | ||
37 | +import org.onosproject.net.Path; | ||
38 | +import org.onosproject.net.PortNumber; | ||
39 | +import org.onosproject.net.TestDeviceParams; | ||
40 | +import org.onosproject.net.intent.FakeIntentManager; | ||
41 | +import org.onosproject.net.intent.TestableIntentService; | ||
42 | +import org.onosproject.net.topology.LinkWeight; | ||
43 | +import org.onosproject.net.topology.PathService; | ||
44 | +import org.onosproject.store.service.TestStorageService; | ||
45 | + | ||
46 | +import java.util.Set; | ||
47 | + | ||
48 | +import static org.junit.Assert.assertEquals; | ||
49 | + | ||
50 | +/** | ||
51 | + * Junit tests for VirtualNetworkPathService. | ||
52 | + */ | ||
53 | +public class VirtualNetworkPathServiceTest extends TestDeviceParams { | ||
54 | + private final String tenantIdValue1 = "TENANT_ID1"; | ||
55 | + | ||
56 | + private VirtualNetworkManager manager; | ||
57 | + private DistributedVirtualNetworkStore virtualNetworkManagerStore; | ||
58 | + private final TestableIntentService intentService = new FakeIntentManager(); | ||
59 | + | ||
60 | + @Before | ||
61 | + public void setUp() throws Exception { | ||
62 | + virtualNetworkManagerStore = new DistributedVirtualNetworkStore(); | ||
63 | + | ||
64 | + CoreService coreService = new TestCoreService(); | ||
65 | + virtualNetworkManagerStore.setCoreService(coreService); | ||
66 | + TestUtils.setField(virtualNetworkManagerStore, "storageService", new TestStorageService()); | ||
67 | + virtualNetworkManagerStore.activate(); | ||
68 | + | ||
69 | + manager = new VirtualNetworkManager(); | ||
70 | + manager.store = virtualNetworkManagerStore; | ||
71 | + manager.intentService = intentService; | ||
72 | + NetTestTools.injectEventDispatcher(manager, new TestEventDispatcher()); | ||
73 | + manager.activate(); | ||
74 | + } | ||
75 | + | ||
76 | + @After | ||
77 | + public void tearDown() { | ||
78 | + virtualNetworkManagerStore.deactivate(); | ||
79 | + manager.deactivate(); | ||
80 | + NetTestTools.injectEventDispatcher(manager, null); | ||
81 | + } | ||
82 | + | ||
83 | + /** | ||
84 | + * Sets up an empty virtual network (no devices, links). | ||
85 | + * | ||
86 | + * @return virtual network | ||
87 | + */ | ||
88 | + private VirtualNetwork setupEmptyVnet() { | ||
89 | + manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | ||
90 | + return manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | ||
91 | + } | ||
92 | + | ||
93 | + /** | ||
94 | + * Creates a virtual network for further testing. | ||
95 | + * | ||
96 | + * @return virtual network | ||
97 | + */ | ||
98 | + private VirtualNetwork setupVnet() { | ||
99 | + manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | ||
100 | + VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | ||
101 | + VirtualDevice virtualDevice1 = | ||
102 | + manager.createVirtualDevice(virtualNetwork.id(), DID1); | ||
103 | + VirtualDevice virtualDevice2 = | ||
104 | + manager.createVirtualDevice(virtualNetwork.id(), DID2); | ||
105 | + VirtualDevice virtualDevice3 = | ||
106 | + manager.createVirtualDevice(virtualNetwork.id(), DID3); | ||
107 | + VirtualDevice virtualDevice4 = | ||
108 | + manager.createVirtualDevice(virtualNetwork.id(), DID4); | ||
109 | + | ||
110 | + ConnectPoint cp11 = createConnectPointAndVirtualPort(virtualNetwork, virtualDevice1, 1); | ||
111 | + ConnectPoint cp12 = createConnectPointAndVirtualPort(virtualNetwork, virtualDevice1, 2); | ||
112 | + ConnectPoint cp23 = createConnectPointAndVirtualPort(virtualNetwork, virtualDevice2, 3); | ||
113 | + ConnectPoint cp24 = createConnectPointAndVirtualPort(virtualNetwork, virtualDevice2, 4); | ||
114 | + ConnectPoint cp35 = createConnectPointAndVirtualPort(virtualNetwork, virtualDevice3, 5); | ||
115 | + ConnectPoint cp36 = createConnectPointAndVirtualPort(virtualNetwork, virtualDevice3, 6); | ||
116 | + VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), cp11, cp23); | ||
117 | + virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE); | ||
118 | + VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), cp23, cp11); | ||
119 | + virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE); | ||
120 | + VirtualLink link3 = manager.createVirtualLink(virtualNetwork.id(), cp24, cp35); | ||
121 | + virtualNetworkManagerStore.updateLink(link3, link3.tunnelId(), Link.State.ACTIVE); | ||
122 | + VirtualLink link4 = manager.createVirtualLink(virtualNetwork.id(), cp35, cp24); | ||
123 | + virtualNetworkManagerStore.updateLink(link4, link4.tunnelId(), Link.State.ACTIVE); | ||
124 | + VirtualLink link5 = manager.createVirtualLink(virtualNetwork.id(), cp12, cp36); | ||
125 | + virtualNetworkManagerStore.updateLink(link5, link5.tunnelId(), Link.State.ACTIVE); | ||
126 | + VirtualLink link6 = manager.createVirtualLink(virtualNetwork.id(), cp36, cp12); | ||
127 | + virtualNetworkManagerStore.updateLink(link6, link6.tunnelId(), Link.State.ACTIVE); | ||
128 | + | ||
129 | + return virtualNetwork; | ||
130 | + } | ||
131 | + | ||
132 | + /** | ||
133 | + * Creates a connect point and related virtual port. | ||
134 | + * | ||
135 | + * @param vnet virtual network | ||
136 | + * @param vDev virtual device | ||
137 | + * @param portNumber port number | ||
138 | + * @return connect point | ||
139 | + */ | ||
140 | + private ConnectPoint createConnectPointAndVirtualPort( | ||
141 | + VirtualNetwork vnet, VirtualDevice vDev, long portNumber) { | ||
142 | + ConnectPoint cp = new ConnectPoint(vDev.id(), PortNumber.portNumber(portNumber)); | ||
143 | + manager.createVirtualPort(vnet.id(), cp.deviceId(), cp.port(), | ||
144 | + new DefaultPort(vDev, cp.port(), true)); | ||
145 | + return cp; | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Tests getPaths(), getDisjointPaths() | ||
150 | + * on a non-empty virtual network. | ||
151 | + */ | ||
152 | + @Test | ||
153 | + public void testGetPathsOnNonEmptyVnet() { | ||
154 | + VirtualNetwork vnet = setupVnet(); | ||
155 | + PathService pathService = manager.get(vnet.id(), PathService.class); | ||
156 | + | ||
157 | + // src and dest are in vnet and are connected by a virtual link | ||
158 | + Set<Path> paths = pathService.getPaths(DID1, DID3); | ||
159 | + validatePaths(paths, 1, 1, DID1, DID3, 1.0); | ||
160 | + | ||
161 | + LinkWeight linkWeight = edge -> 2.0; | ||
162 | + paths = pathService.getPaths(DID1, DID3, linkWeight); | ||
163 | + validatePaths(paths, 1, 1, DID1, DID3, 2.0); | ||
164 | + | ||
165 | + Set<DisjointPath> disjointPaths = pathService.getDisjointPaths(DID1, DID3); | ||
166 | + validatePaths(disjointPaths, 1, 1, DID1, DID3, 1.0); | ||
167 | + | ||
168 | + disjointPaths = pathService.getDisjointPaths(DID1, DID3, linkWeight); | ||
169 | + validatePaths(disjointPaths, 1, 1, DID1, DID3, 2.0); | ||
170 | + | ||
171 | + // src and dest are in vnet but are not connected | ||
172 | + paths = pathService.getPaths(DID4, DID3); | ||
173 | + assertEquals("incorrect path count", 0, paths.size()); | ||
174 | + | ||
175 | + disjointPaths = pathService.getDisjointPaths(DID4, DID3); | ||
176 | + assertEquals("incorrect path count", 0, disjointPaths.size()); | ||
177 | + | ||
178 | + // src is in vnet, but dest is not in vnet. | ||
179 | + DeviceId nonExistentDeviceId = DeviceId.deviceId("nonExistentDevice"); | ||
180 | + paths = pathService.getPaths(DID2, nonExistentDeviceId); | ||
181 | + assertEquals("incorrect path count", 0, paths.size()); | ||
182 | + | ||
183 | + disjointPaths = pathService.getDisjointPaths(DID2, nonExistentDeviceId); | ||
184 | + assertEquals("incorrect path count", 0, disjointPaths.size()); | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * Tests getPaths(), getDisjointPaths() | ||
189 | + * on an empty virtual network. | ||
190 | + */ | ||
191 | + @Test | ||
192 | + public void testGetPathsOnEmptyVnet() { | ||
193 | + VirtualNetwork vnet = setupEmptyVnet(); | ||
194 | + PathService pathService = manager.get(vnet.id(), PathService.class); | ||
195 | + | ||
196 | + Set<Path> paths = pathService.getPaths(DID1, DID3); | ||
197 | + assertEquals("incorrect path count", 0, paths.size()); | ||
198 | + | ||
199 | + Set<DisjointPath> disjointPaths = pathService.getDisjointPaths(DID1, DID3); | ||
200 | + assertEquals("incorrect path count", 0, disjointPaths.size()); | ||
201 | + } | ||
202 | + | ||
203 | + /** | ||
204 | + * Tests getPaths() using a null source device on an empty virtual network. | ||
205 | + */ | ||
206 | + @Test(expected = NullPointerException.class) | ||
207 | + public void testGetPathsWithNullSrc() { | ||
208 | + VirtualNetwork vnet = setupEmptyVnet(); | ||
209 | + PathService pathService = manager.get(vnet.id(), PathService.class); | ||
210 | + pathService.getPaths(null, DID3); | ||
211 | + } | ||
212 | + | ||
213 | + /** | ||
214 | + * Tests getPaths() using a null destination device on a non-empty virtual network. | ||
215 | + */ | ||
216 | + @Test(expected = NullPointerException.class) | ||
217 | + public void testGetPathsWithNullDest() { | ||
218 | + VirtualNetwork vnet = setupVnet(); | ||
219 | + PathService pathService = manager.get(vnet.id(), PathService.class); | ||
220 | + pathService.getPaths(DID1, null); | ||
221 | + } | ||
222 | + | ||
223 | + | ||
224 | + // Makes sure the set of paths meets basic expectations. | ||
225 | + private void validatePaths(Set<? extends Path> paths, int count, int length, | ||
226 | + ElementId src, ElementId dst, double cost) { | ||
227 | + assertEquals("incorrect path count", count, paths.size()); | ||
228 | + for (Path path : paths) { | ||
229 | + assertEquals("incorrect length", length, path.links().size()); | ||
230 | + assertEquals("incorrect source", src, path.src().elementId()); | ||
231 | + assertEquals("incorrect destination", dst, path.dst().elementId()); | ||
232 | + assertEquals("incorrect cost", cost, path.cost(), 0); | ||
233 | + } | ||
234 | + } | ||
235 | +} |
-
Please register or login to post a comment