blob: f78ce9d499e6c3685b5ddf154223b7d90b0f0936 [file] [log] [blame]
Ray Milkey85267002016-11-16 11:06:35 -08001/*
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 */
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053016package org.onosproject.pce.pceservice;
17
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.core.Is.is;
20import static org.onlab.graph.GraphPathSearch.ALL_PATHS;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053021import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED;
22import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053023import static org.onosproject.net.MastershipRole.MASTER;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053024import static org.onosproject.net.resource.Resources.continuous;
25import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING;
26import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
27import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING;
28import static org.onosproject.pce.pceservice.PathComputationTest.D1;
29import static org.onosproject.pce.pceservice.PathComputationTest.D2;
30import static org.onosproject.pce.pceservice.PathComputationTest.D3;
31import static org.onosproject.pce.pceservice.PathComputationTest.D4;
Priyanka B3f92c5a2016-05-27 10:14:16 +053032import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE1;
33import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2;
34import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3;
35import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053036import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID;
37import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053038import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST;
39import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053040
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053041import java.util.Collection;
42import java.util.Collections;
43import java.util.HashMap;
44import java.util.HashSet;
45import java.util.LinkedList;
46import java.util.List;
47import java.util.Set;
48import java.util.concurrent.atomic.AtomicLong;
49
50import org.junit.After;
51import org.junit.Before;
52import org.junit.Test;
53import org.onlab.graph.GraphPathSearch;
Priyanka B3f92c5a2016-05-27 10:14:16 +053054import org.onlab.junit.TestUtils;
55import org.onlab.junit.TestUtils.TestUtilsException;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053056import org.onlab.util.Bandwidth;
57import org.onosproject.common.DefaultTopologyGraph;
58import org.onosproject.core.ApplicationId;
59import org.onosproject.core.CoreServiceAdapter;
60import org.onosproject.core.DefaultApplicationId;
61import org.onosproject.core.IdGenerator;
Priyanka B3f92c5a2016-05-27 10:14:16 +053062import org.onosproject.event.Event;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053063import org.onosproject.incubator.net.tunnel.DefaultTunnel;
64import org.onosproject.incubator.net.tunnel.Tunnel;
65import org.onosproject.incubator.net.tunnel.Tunnel.State;
66import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
67import org.onosproject.incubator.net.tunnel.TunnelEvent;
68import org.onosproject.incubator.net.tunnel.TunnelId;
69import org.onosproject.incubator.net.tunnel.TunnelListener;
Priyanka B3f92c5a2016-05-27 10:14:16 +053070import org.onosproject.mastership.MastershipServiceAdapter;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053071import org.onosproject.net.AnnotationKeys;
72import org.onosproject.net.Annotations;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053073import org.onosproject.net.DefaultAnnotations;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053074import org.onosproject.net.DefaultAnnotations.Builder;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053075import org.onosproject.net.DefaultDevice;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053076import org.onosproject.net.Device;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053077import org.onosproject.net.DeviceId;
78import org.onosproject.net.ElementId;
79import org.onosproject.net.Link;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053080import org.onosproject.net.MastershipRole;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053081import org.onosproject.net.Path;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053082import org.onosproject.net.SparseAnnotations;
83import org.onosproject.net.intent.Constraint;
84import org.onosproject.net.intent.IntentId;
85import org.onosproject.net.intent.constraint.BandwidthConstraint;
Priyanka B3f92c5a2016-05-27 10:14:16 +053086import org.onosproject.net.link.LinkEvent;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053087import org.onosproject.net.provider.ProviderId;
88import org.onosproject.net.resource.Resource;
89import org.onosproject.net.topology.DefaultTopologyEdge;
90import org.onosproject.net.topology.DefaultTopologyVertex;
91import org.onosproject.net.topology.LinkWeight;
92import org.onosproject.net.topology.PathServiceAdapter;
93import org.onosproject.net.topology.Topology;
94import org.onosproject.net.topology.TopologyEdge;
Priyanka B3f92c5a2016-05-27 10:14:16 +053095import org.onosproject.net.topology.TopologyEvent;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053096import org.onosproject.net.topology.TopologyGraph;
Priyanka B3f92c5a2016-05-27 10:14:16 +053097import org.onosproject.net.topology.TopologyListener;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053098import org.onosproject.net.topology.TopologyServiceAdapter;
99import org.onosproject.net.topology.TopologyVertex;
Avantika-Huawei032a9872016-05-27 22:57:38 +0530100import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530101import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService;
102import org.onosproject.pce.pceservice.constraint.CostConstraint;
103import org.onosproject.pce.pcestore.api.PceStore;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530104import org.onosproject.pce.util.MockDeviceService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530105import org.onosproject.pce.util.PceStoreAdapter;
106import org.onosproject.pce.util.TunnelServiceAdapter;
Avantika-Huawei032a9872016-05-27 22:57:38 +0530107import org.onosproject.pcep.api.DeviceCapability;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530108import org.onosproject.store.service.TestStorageService;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530109
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530110import com.google.common.collect.ImmutableSet;
111
112/**
113 * Tests the functions of PceManager.
114 */
115public class PceManagerTest {
116
117 private PathComputationTest pathCompTest = new PathComputationTest();
118 private MockPathResourceService resourceService = pathCompTest.new MockPathResourceService();
119 private MockTopologyService topologyService = new MockTopologyService();
Priyanka B3f92c5a2016-05-27 10:14:16 +0530120 private MockMastershipService mastershipService = new MockMastershipService();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530121 private MockPathService pathService = new MockPathService();
122 private PceManager pceManager = new PceManager();
123 private MockCoreService coreService = new MockCoreService();
124 private MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
125 private TestStorageService storageService = new TestStorageService();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530126 private MockDeviceService deviceService = new MockDeviceService();
Avantika-Huawei032a9872016-05-27 22:57:38 +0530127 private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530128 private PceStore pceStore = new PceStoreAdapter();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530129
130 public static ProviderId providerId = new ProviderId("pce", "foo");
131 private static final String L3 = "L3";
132 private static final String LSRID = "lsrId";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530133 private static final String PCECC_CAPABILITY = "pceccCapability";
134 private static final String SR_CAPABILITY = "srCapability";
135 private static final String LABEL_STACK_CAPABILITY = "labelStackCapability";
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530136
137 private TopologyGraph graph = null;
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000138 private Device deviceD1, deviceD2, deviceD3, deviceD4;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530139 private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4;
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000140 private Link link1, link2, link3, link4;
Priyanka B413fbe82016-05-26 11:44:45 +0530141 protected static int flowsDownloaded;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530142 private TunnelListener tunnelListener;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530143 private TopologyListener listener;
144 private Topology topology;
145 private Set<TopologyEdge> edges;
146 private Set<TopologyVertex> vertexes;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530147
148 @Before
Priyanka B3f92c5a2016-05-27 10:14:16 +0530149 public void startUp() throws TestUtilsException {
150 listener = TestUtils.getField(pceManager, "topologyListener");
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530151 pceManager.pathService = pathService;
152 pceManager.resourceService = resourceService;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530153 pceManager.topologyService = topologyService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530154 pceManager.tunnelService = tunnelService;
155 pceManager.coreService = coreService;
156 pceManager.storageService = storageService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530157 pceManager.deviceService = deviceService;
Avantika-Huawei032a9872016-05-27 22:57:38 +0530158 pceManager.netCfgService = netConfigRegistry;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530159 pceManager.pceStore = pceStore;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530160 pceManager.mastershipService = mastershipService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530161 pceManager.activate();
162 }
163
Priyanka B3f92c5a2016-05-27 10:14:16 +0530164 private class MockMastershipService extends MastershipServiceAdapter {
165 @Override
166 public MastershipRole getLocalRole(DeviceId deviceId) {
167 return MASTER;
168 }
169
170 @Override
171 public boolean isLocalMaster(DeviceId deviceId) {
172 return getLocalRole(deviceId) == MASTER;
173 }
174 }
175
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530176 private void build4RouterTopo(boolean setCost, boolean setPceccCap, boolean setSrCap,
177 boolean setLabelStackCap, int bandwidth) {
Priyanka B3f92c5a2016-05-27 10:14:16 +0530178 link1 = PathComputationTest.addLink(DEVICE1, 10, DEVICE2, 20, setCost, 50);
179 link2 = PathComputationTest.addLink(DEVICE2, 30, DEVICE4, 40, setCost, 20);
180 link3 = PathComputationTest.addLink(DEVICE1, 80, DEVICE3, 70, setCost, 100);
181 link4 = PathComputationTest.addLink(DEVICE3, 60, DEVICE4, 50, setCost, 80);
182
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530183 Set<TopologyVertex> vertexes = new HashSet<TopologyVertex>();
184 vertexes.add(D1);
185 vertexes.add(D2);
186 vertexes.add(D3);
187 vertexes.add(D4);
188
Priyanka B3f92c5a2016-05-27 10:14:16 +0530189 this.vertexes = vertexes;
190
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530191 Set<TopologyEdge> edges = new HashSet<TopologyEdge>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530192 TopologyEdge edge1 = new DefaultTopologyEdge(D1, D2, link1);
193 edges.add(edge1);
194
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530195 TopologyEdge edge2 = new DefaultTopologyEdge(D2, D4, link2);
196 edges.add(edge2);
197
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530198 TopologyEdge edge3 = new DefaultTopologyEdge(D1, D3, link3);
199 edges.add(edge3);
200
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530201 TopologyEdge edge4 = new DefaultTopologyEdge(D3, D4, link4);
202 edges.add(edge4);
203
Priyanka B3f92c5a2016-05-27 10:14:16 +0530204 this.edges = edges;
205
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530206 graph = new DefaultTopologyGraph(vertexes, edges);
207
208 DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
209 DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder();
210 DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder();
211 DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder();
212
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530213 // Making L3 devices
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530214 builderDev1.set(AnnotationKeys.TYPE, L3);
215 builderDev1.set(LSRID, "1.1.1.1");
216
217 builderDev2.set(AnnotationKeys.TYPE, L3);
218 builderDev2.set(LSRID, "2.2.2.2");
219
220 builderDev3.set(AnnotationKeys.TYPE, L3);
221 builderDev3.set(LSRID, "3.3.3.3");
222
223 builderDev4.set(AnnotationKeys.TYPE, L3);
224 builderDev4.set(LSRID, "4.4.4.4");
225
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530226 deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build());
227 deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build());
228 deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build());
229 deviceD4 = new MockDevice(D4.deviceId(), builderDev4.build());
230
231 deviceService.addDevice(deviceD1);
232 deviceService.addDevice(deviceD2);
233 deviceService.addDevice(deviceD3);
234 deviceService.addDevice(deviceD4);
235
Avantika-Huawei032a9872016-05-27 22:57:38 +0530236 DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
237 device1Cap.setLabelStackCap(setLabelStackCap)
238 .setLocalLabelCap(setPceccCap)
239 .setSrCap(setSrCap)
240 .apply();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530241
Avantika-Huawei032a9872016-05-27 22:57:38 +0530242 DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
243 device2Cap.setLabelStackCap(setLabelStackCap)
244 .setLocalLabelCap(setPceccCap)
245 .setSrCap(setSrCap)
246 .apply();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530247
Avantika-Huawei032a9872016-05-27 22:57:38 +0530248 DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
249 device3Cap.setLabelStackCap(setLabelStackCap)
250 .setLocalLabelCap(setPceccCap)
251 .setSrCap(setSrCap)
252 .apply();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530253
Avantika-Huawei032a9872016-05-27 22:57:38 +0530254 DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
255 device4Cap.setLabelStackCap(setLabelStackCap)
256 .setLocalLabelCap(setPceccCap)
257 .setSrCap(setSrCap)
258 .apply();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530259
260 if (bandwidth != 0) {
261 List<Resource> resources = new LinkedList<>();
262 resources.add(continuous(link1.src().deviceId(), link1.src().port(), Bandwidth.class).resource(bandwidth));
263 resources.add(continuous(link2.src().deviceId(), link2.src().port(), Bandwidth.class).resource(bandwidth));
264 resources.add(continuous(link3.src().deviceId(), link3.src().port(), Bandwidth.class).resource(bandwidth));
265 resources.add(continuous(link4.src().deviceId(), link4.src().port(), Bandwidth.class).resource(bandwidth));
266
267 resources.add(continuous(link1.dst().deviceId(), link1.dst().port(), Bandwidth.class).resource(bandwidth));
268 resources.add(continuous(link2.dst().deviceId(), link2.dst().port(), Bandwidth.class).resource(bandwidth));
269 resources.add(continuous(link3.dst().deviceId(), link3.dst().port(), Bandwidth.class).resource(bandwidth));
270 resources.add(continuous(link4.dst().deviceId(), link4.dst().port(), Bandwidth.class).resource(bandwidth));
271
272 resourceService.allocate(IntentId.valueOf(bandwidth), resources);
273 }
274 }
275
276 /**
277 * Tests path success with (IGP) cost constraint for signalled LSP.
278 */
279 @Test
280 public void setupPathTest1() {
281 build4RouterTopo(true, false, false, false, 0); // IGP cost is set here.
282 List<Constraint> constraints = new LinkedList<Constraint>();
283 CostConstraint costConstraint = new CostConstraint(COST);
284 constraints.add(costConstraint);
285
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000286 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530287 assertThat(result, is(true));
288 }
289
290 /**
291 * Tests path failure with (IGP) cost constraint for signalled LSP.
292 */
293 @Test
294 public void setupPathTest2() {
295 build4RouterTopo(false, false, false, false, 0); // TE cost is set here, not IGP.
296 List<Constraint> constraints = new LinkedList<Constraint>();
297 CostConstraint costConstraint = new CostConstraint(COST);
298 constraints.add(costConstraint);
299
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000300 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530301 assertThat(result, is(false));
302 }
303
304 /**
305 * Tests path success with TE-cost constraint for signalled LSP.
306 */
307 @Test
308 public void setupPathTest3() {
309 build4RouterTopo(false, false, false, false, 0); // TE cost is set here.
310
311 List<Constraint> constraints = new LinkedList<Constraint>();
312 CostConstraint costConstraint = new CostConstraint(TE_COST);
313 constraints.add(costConstraint);
314
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000315 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530316 assertThat(result, is(true));
317 }
318
319 /**
320 * Tests path failure with TE-cost constraint for signalled LSP.
321 */
322 @Test
323 public void setupPathTest4() {
324 build4RouterTopo(true, false, false, false, 0); // IGP cost is set here, not TE.
325
326 List<Constraint> constraints = new LinkedList<Constraint>();
327 CostConstraint costConstraint = new CostConstraint(TE_COST);
328 constraints.add(costConstraint);
329
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000330 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530331 assertThat(result, is(false));
332 }
333
334 /**
335 * Tests path success with (IGP) cost constraint for non-SR non-signalled LSP.
336 */
337 @Test
338 public void setupPathTest5() {
339 build4RouterTopo(true, true, false, false, 0);
340
341 List<Constraint> constraints = new LinkedList<Constraint>();
342 CostConstraint costConstraint = new CostConstraint(COST);
343 constraints.add(costConstraint);
344
345 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000346 WITHOUT_SIGNALLING_AND_WITHOUT_SR);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530347 assertThat(result, is(true));
348 }
349
350 /**
351 * Tests path success with TE-cost constraint for non-SR non-sgnalled LSP.
352 */
353 @Test
354 public void setupPathTest6() {
355 build4RouterTopo(false, true, false, false, 0);
356
357 List<Constraint> constraints = new LinkedList<Constraint>();
358 CostConstraint costConstraint = new CostConstraint(TE_COST);
359 constraints.add(costConstraint);
360
361 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000362 WITHOUT_SIGNALLING_AND_WITHOUT_SR);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530363 assertThat(result, is(true));
364 }
365
366 /**
367 * Tests path failure with TE-cost constraint for non-SR non-signalled LSP(CR). Label capability not registered.
368 */
369 @Test
370 public void setupPathTest7() {
371 build4RouterTopo(true, false, false, false, 0);
372
373 List<Constraint> constraints = new LinkedList<Constraint>();
374 CostConstraint costConstraint = new CostConstraint(TE_COST);
375 constraints.add(costConstraint);
376
377 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000378 WITHOUT_SIGNALLING_AND_WITHOUT_SR);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530379 assertThat(result, is(false));
380 }
381
382 /**
383 * Tests path failure as bandwidth is requested but is not registered.
384 */
385 @Test
386 public void setupPathTest8() {
387 build4RouterTopo(true, false, false, false, 0);
388 List<Constraint> constraints = new LinkedList<Constraint>();
389 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
390 CostConstraint costConstraint = new CostConstraint(TE_COST);
391
392 constraints.add(costConstraint);
393 constraints.add(bwConstraint);
394
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000395 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530396 assertThat(result, is(false));
397 }
398
399 /**
400 * Tests path failure as bandwidth requested is more than registered.
401 */
402 @Test
403 public void setupPathTest9() {
404 build4RouterTopo(false, false, false, false, 5);
405 List<Constraint> constraints = new LinkedList<Constraint>();
406 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
407 CostConstraint costConstraint = new CostConstraint(TE_COST);
408
409 constraints.add(costConstraint);
410 constraints.add(bwConstraint);
411
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000412 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530413 assertThat(result, is(false));
414 }
415
416 /**
417 * Tests path setup failure(without signalling). Label capability is not present.
418 */
419 @Test
420 public void setupPathTest10() {
421 build4RouterTopo(false, false, false, false, 0);
422 List<Constraint> constraints = new LinkedList<Constraint>();
423 CostConstraint costConstraint = new CostConstraint(TE_COST);
424 constraints.add(costConstraint);
425
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000426 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530427 assertThat(result, is(false));
428 }
429
430 /**
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530431 * Tests path setup without signalling and with bandwidth reservation.
432 */
433 @Test
434 public void setupPathTest12() {
435 build4RouterTopo(false, true, true, true, 15);
436 List<Constraint> constraints = new LinkedList<Constraint>();
437 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
438 CostConstraint costConstraint = new CostConstraint(TE_COST);
439
440 constraints.add(costConstraint);
441 constraints.add(bwConstraint);
442
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000443 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530444 assertThat(result, is(true));
445 }
446
447 /**
448 * Tests path setup without cost/bandwidth constraints.
449 */
450 @Test
451 public void setupPathTest13() {
452 build4RouterTopo(false, false, false, false, 0);
453
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000454 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", null, WITH_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530455 assertThat(result, is(true));
456 }
457
458 /**
459 * Tests path update with increase in bandwidth.
460 */
461 @Test
462 public void updatePathTest1() {
463 build4RouterTopo(false, true, true, true, 100);
464
465 // Setup tunnel.
466 List<Constraint> constraints = new LinkedList<>();
467 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(60.0));
468 constraints.add(bwConstraint);
469 CostConstraint costConstraint = new CostConstraint(TE_COST);
470 constraints.add(costConstraint);
471
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000472 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530473 assertThat(result, is(true));
474
475 // Change constraint and update it.
476 constraints = new LinkedList<>();
477 bwConstraint = new BandwidthConstraint(Bandwidth.bps(50.0));
478 constraints.add(bwConstraint);
479 constraints.add(costConstraint);
480
481 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
482 assertThat(tunnels.size(), is(1));
483
484 Tunnel tunnel = tunnels.iterator().next();
485
486 // Stimulate the effect of LSP ids from protocol msg.
487 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", State.ACTIVE);
488
489 result = pceManager.updatePath(tunnel.tunnelId(), constraints);
490 assertThat(result, is(true));
491
492 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
493 assertThat(tunnels.size(), is(2));
494 }
495
496 /**
497 * Tests path update with decrease in bandwidth.
498 */
499 @Test
500 public void updatePathTest2() {
501 build4RouterTopo(false, true, true, true, 100);
502
503 // Setup tunnel.
504 List<Constraint> constraints = new LinkedList<Constraint>();
505 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(60.0));
506 constraints.add(bwConstraint);
507 CostConstraint costConstraint = new CostConstraint(TE_COST);
508 constraints.add(costConstraint);
509
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000510 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530511 assertThat(result, is(true));
512
513 // Change constraint and update it.
514 constraints.remove(bwConstraint);
515 bwConstraint = new BandwidthConstraint(Bandwidth.bps(70.0));
516 constraints.add(bwConstraint);
517
518 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
519 assertThat(tunnels.size(), is(1));
520
521 for (Tunnel tunnel : tunnels) {
522 result = pceManager.updatePath(tunnel.tunnelId(), constraints);
523 assertThat(result, is(true));
524 }
525
526 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
527 assertThat(tunnels.size(), is(2));
528 }
529
530 /**
531 * Tests path update without cost/bandwidth constraints.
532 */
533 @Test
534 public void updatePathTest3() {
535 build4RouterTopo(false, true, true, true, 100);
536
537 // Setup tunnel.
Priyanka B3fdb9dd2016-08-08 10:47:24 +0530538 List<Constraint> constraints = new LinkedList<Constraint>();
539 CostConstraint costConstraint = new CostConstraint(TE_COST);
540 constraints.add(costConstraint);
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000541 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530542 assertThat(result, is(true));
543
544 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
545 assertThat(tunnels.size(), is(1));
546
547 for (Tunnel tunnel : tunnels) {
548 result = pceManager.updatePath(tunnel.tunnelId(), null);
549 assertThat(result, is(true));
550 }
551
552 Iterable<Tunnel> queryTunnelResult = pceManager.queryAllPath();
553 assertThat((int) queryTunnelResult.spliterator().getExactSizeIfKnown(), is(2));
554 }
555
556 /**
557 * Tests path release.
558 */
559 @Test
560 public void releasePathTest1() {
561 build4RouterTopo(false, false, false, false, 5);
562 List<Constraint> constraints = new LinkedList<Constraint>();
563 CostConstraint costConstraint = new CostConstraint(TE_COST);
Priyanka B4c3b4512016-07-22 11:41:49 +0530564 BandwidthConstraint bwConst = new BandwidthConstraint(Bandwidth.bps(3));
565 constraints.add(bwConst);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530566 constraints.add(costConstraint);
567
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000568 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530569
570 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
571 assertThat(tunnels.size(), is(1));
572 boolean result;
573 for (Tunnel tunnel : tunnels) {
574 result = pceManager.releasePath(tunnel.tunnelId());
575 assertThat(result, is(true));
576 }
577 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
578 assertThat(tunnels.size(), is(0));
579 }
580
581 /**
582 * Tests path release failure.
583 */
584 @Test
585 public void releasePathTest2() {
586 build4RouterTopo(false, false, false, false, 5);
587 List<Constraint> constraints = new LinkedList<Constraint>();
588 CostConstraint costConstraint = new CostConstraint(TE_COST);
589 constraints.add(costConstraint);
590
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000591 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530592
593 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
594 assertThat(tunnels.size(), is(1));
595
596 // Random tunnel id.
597 boolean result = pceManager.releasePath(TunnelId.valueOf("111"));
598 assertThat(result, is(false));
599
600 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
601 assertThat(tunnels.size(), is(1));
602 }
603
604 /**
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530605 * Tests tunnel events added and removed.
606 */
607 @Test
608 public void tunnelEventTest1() {
609 build4RouterTopo(false, true, true, true, 15);
610 List<Constraint> constraints = new LinkedList<Constraint>();
611 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
612 CostConstraint costConstraint = new CostConstraint(TE_COST);
613
614 constraints.add(costConstraint);
615 constraints.add(bwConstraint);
616
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000617 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T1", constraints, SR_WITHOUT_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530618 assertThat(pceStore.getTunnelInfoCount(), is(1));
619
620 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
621
622 for (Tunnel tunnel : tunnels) {
623 TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
624 tunnelListener.event(event);
625
626 pceManager.releasePath(tunnel.tunnelId());
627
628 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel);
629 tunnelListener.event(event);
630 }
631
632 assertThat(pceStore.getTunnelInfoCount(), is(0));
633 }
634
635 /**
636 * Tests label allocation/removal in CR case based on tunnel event.
637 */
638 @Test
639 public void tunnelEventTest2() {
640 build4RouterTopo(false, true, true, true, 15);
641 List<Constraint> constraints = new LinkedList<Constraint>();
642 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
643 CostConstraint costConstraint = new CostConstraint(TE_COST);
644
645 constraints.add(costConstraint);
646 constraints.add(bwConstraint);
647
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000648 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints, WITHOUT_SIGNALLING_AND_WITHOUT_SR);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530649 assertThat(pceStore.getTunnelInfoCount(), is(1));
650
651 TunnelEvent event;
652 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
653 for (Tunnel tunnel : tunnels) {
654 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
655 tunnelListener.event(event);
656
657 // Stimulate the effect of LSP ids from protocol msg.
658 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", ESTABLISHED);
659 }
660
661 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
662 for (Tunnel tunnel : tunnels) {
663 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel);
664 tunnelListener.event(event);
665
666 pceManager.releasePath(tunnel.tunnelId());
667
668 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel);
669 tunnelListener.event(event);
670 }
671
672 assertThat(pceStore.getTunnelInfoCount(), is(0));
673 }
674
675 /**
676 * Tests handling UNSTABLE state based on tunnel event.
677 */
678 @Test
679 public void tunnelEventTest3() {
680 build4RouterTopo(false, true, true, true, 15);
681 List<Constraint> constraints = new LinkedList<Constraint>();
682 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
683 CostConstraint costConstraint = new CostConstraint(TE_COST);
684
685 constraints.add(costConstraint);
686 constraints.add(bwConstraint);
687
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000688 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints, WITHOUT_SIGNALLING_AND_WITHOUT_SR);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530689 assertThat(pceStore.getTunnelInfoCount(), is(1));
690 assertThat(pceStore.getFailedPathInfoCount(), is(0));
691
692 TunnelEvent event;
693 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
694 for (Tunnel tunnel : tunnels) {
695 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
696 tunnelListener.event(event);
697
698 // Stimulate the effect of LSP ids from protocol msg.
699 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", UNSTABLE);
700 }
701
702 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
703 for (Tunnel tunnel : tunnels) {
704 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel);
705 tunnelListener.event(event);
706 }
707 assertThat(pceStore.getTunnelInfoCount(), is(1));
708 assertThat(pceStore.getFailedPathInfoCount(), is(1));
709 }
710
Priyanka B3f92c5a2016-05-27 10:14:16 +0530711 /**
712 * Tests resilency when L2 link is down.
713 */
714 @Test
715 public void resilencyTest1() {
716 build4RouterTopo(true, false, false, false, 10);
717
718
719 List<Constraint> constraints = new LinkedList<Constraint>();
720 CostConstraint costConstraint = new CostConstraint(COST);
721 constraints.add(costConstraint);
722 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
723 constraints.add(localBwConst);
724
725 //Setup the path , tunnel created
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000726 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
Priyanka B3f92c5a2016-05-27 10:14:16 +0530727 assertThat(result, is(true));
728 assertThat(pceStore.getTunnelInfoCount(), is(1));
729 assertThat(pceStore.getFailedPathInfoCount(), is(0));
730
731 List<Event> reasons = new LinkedList<>();
732 final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
733 reasons.add(linkEvent);
734 final TopologyEvent event = new TopologyEvent(
735 TopologyEvent.Type.TOPOLOGY_CHANGED,
736 topology,
737 reasons);
738
739 //Change Topology : remove link2
740 Set<TopologyEdge> tempEdges = new HashSet<>();
741 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
742 topologyService.changeInTopology(getGraph(null, tempEdges));
743 listener.event(event);
744
745 List<Link> links = new LinkedList<>();
746 links.add(link3);
747 links.add(link4);
748
749 //Path is D1-D3-D4
750 assertThat(pathService.paths().iterator().next().links(), is(links));
751 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
752 }
753
754 /**
755 * Tests resilency when L2 and L4 link is down.
756 */
757 @Test
758 public void resilencyTest2() {
759 build4RouterTopo(true, false, false, false, 10);
760
761 List<Constraint> constraints = new LinkedList<Constraint>();
762 CostConstraint costConstraint = new CostConstraint(COST);
763 constraints.add(costConstraint);
764 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
765 constraints.add(localBwConst);
766
767 //Setup the path , tunnel created
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000768 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
Priyanka B3f92c5a2016-05-27 10:14:16 +0530769 assertThat(result, is(true));
770
771 List<Event> reasons = new LinkedList<>();
772 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
773 reasons.add(linkEvent);
774 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
775 reasons.add(linkEvent);
776 final TopologyEvent event = new TopologyEvent(
777 TopologyEvent.Type.TOPOLOGY_CHANGED,
778 topology,
779 reasons);
780
781 //Change Topology : remove link2 and link4
782 Set<TopologyEdge> tempEdges = new HashSet<>();
783 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
784 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
785 topologyService.changeInTopology(getGraph(null, tempEdges));
786 listener.event(event);
787
788 //No Path
789 assertThat(pathService.paths().size(), is(0));
790 }
791
792 /**
793 * Tests resilency when D2 device is down.
794 */
795 @Test
796 public void resilencyTest3() {
797 build4RouterTopo(true, false, false, false, 10);
798
799 List<Constraint> constraints = new LinkedList<Constraint>();
800 CostConstraint costConstraint = new CostConstraint(COST);
801 constraints.add(costConstraint);
802 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
803 constraints.add(localBwConst);
804
805 //Setup the path , tunnel created
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000806 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
Priyanka B3f92c5a2016-05-27 10:14:16 +0530807 assertThat(result, is(true));
808
809 List<Event> reasons = new LinkedList<>();
810 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
811 reasons.add(linkEvent);
812 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
813 reasons.add(linkEvent);
814 final TopologyEvent event = new TopologyEvent(
815 TopologyEvent.Type.TOPOLOGY_CHANGED,
816 topology,
817 reasons);
818
819 //Change Topology : remove link2 and link1
820 Set<TopologyEdge> tempEdges = new HashSet<>();
821 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
822 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
823 topologyService.changeInTopology(getGraph(null, tempEdges));
824 listener.event(event);
825
826 List<Link> links = new LinkedList<>();
827 links.add(link3);
828 links.add(link4);
829
830 //Path is D1-D3-D4
831 assertThat(pathService.paths().iterator().next().links(), is(links));
832 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
833 }
834
835 /**
836 * Tests resilency when ingress device is down.
837 */
838 @Test
839 public void resilencyTest4() {
840 build4RouterTopo(true, false, false, false, 10);
841
842 List<Constraint> constraints = new LinkedList<Constraint>();
843 CostConstraint costConstraint = new CostConstraint(COST);
844 constraints.add(costConstraint);
845 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
846 constraints.add(localBwConst);
847
848 //Setup the path , tunnel created
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000849 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
Priyanka B3f92c5a2016-05-27 10:14:16 +0530850 assertThat(result, is(true));
851
852 List<Event> reasons = new LinkedList<>();
853 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
854 reasons.add(linkEvent);
855 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
856 reasons.add(linkEvent);
857 final TopologyEvent event = new TopologyEvent(
858 TopologyEvent.Type.TOPOLOGY_CHANGED,
859 topology,
860 reasons);
861
862 //Change Topology : remove link2 and link1
863 Set<TopologyEdge> tempEdges = new HashSet<>();
864 tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
865 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
866 topologyService.changeInTopology(getGraph(null, tempEdges));
867 listener.event(event);
868
869 //No path
870 assertThat(pathService.paths().size(), is(0));
871 }
872
873 /**
874 * Tests resilency when D2 and D3 devices are down.
875 */
876 @Test
877 public void resilencyTest5() {
878 build4RouterTopo(true, false, false, false, 10);
879
880 List<Constraint> constraints = new LinkedList<Constraint>();
881 CostConstraint costConstraint = new CostConstraint(COST);
882 constraints.add(costConstraint);
883 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
884 constraints.add(localBwConst);
885
886 //Setup the path , tunnel created
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000887 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
Priyanka B3f92c5a2016-05-27 10:14:16 +0530888 assertThat(result, is(true));
889
890 List<Event> reasons = new LinkedList<>();
891 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
892 reasons.add(linkEvent);
893 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
894 reasons.add(linkEvent);
895 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
896 reasons.add(linkEvent);
897 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
898 reasons.add(linkEvent);
899
900 final TopologyEvent event = new TopologyEvent(
901 TopologyEvent.Type.TOPOLOGY_CHANGED,
902 topology,
903 reasons);
904
905 //Change Topology : remove device2, device3 and all links
906 Set<TopologyEdge> tempEdges = new HashSet<>();
907 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
908 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
909 tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
910 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
911 Set<TopologyVertex> tempVertexes = new HashSet<>();
912 tempVertexes.add(D2);
913 tempVertexes.add(D3);
914 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
915 listener.event(event);
916
917 //No path
918 assertThat(pathService.paths().size(), is(0));
919 }
920
921 /**
922 * Tests resilency when egress device is down.
923 */
924 @Test
925 public void resilencyTest6() {
926 build4RouterTopo(true, false, false, false, 10);
927
928 List<Constraint> constraints = new LinkedList<Constraint>();
929 CostConstraint costConstraint = new CostConstraint(COST);
930 constraints.add(costConstraint);
931 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
932 constraints.add(localBwConst);
933
934 //Setup the path , tunnel created
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000935 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
Priyanka B3f92c5a2016-05-27 10:14:16 +0530936 assertThat(result, is(true));
937
938 List<Event> reasons = new LinkedList<>();
939 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
940 reasons.add(linkEvent);
941 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
942 reasons.add(linkEvent);
943
944 final TopologyEvent event = new TopologyEvent(
945 TopologyEvent.Type.TOPOLOGY_CHANGED,
946 topology,
947 reasons);
948
949 //Change Topology : remove device4 , link2 and link4
950 Set<TopologyEdge> tempEdges = new HashSet<>();
951 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
952 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
953 Set<TopologyVertex> tempVertexes = new HashSet<>();
954 tempVertexes.add(D4);
955 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
956 listener.event(event);
957
958 //No path
959 assertThat(pathService.paths().size(), is(0));
960 }
961
962 /**
963 * Tests resilency when egress device is down.
964 */
965 @Test
966 public void resilencyTest7() {
967 build4RouterTopo(true, false, false, false, 10);
968
969 List<Constraint> constraints = new LinkedList<Constraint>();
970 CostConstraint costConstraint = new CostConstraint(COST);
971 constraints.add(costConstraint);
972 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
973 constraints.add(localBwConst);
974
975 //Setup the path , tunnel created
Priyankab-Huawei3946d732016-10-11 06:24:38 +0000976 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
Priyanka B3f92c5a2016-05-27 10:14:16 +0530977 assertThat(result, is(true));
978
979 List<Event> reasons = new LinkedList<>();
980 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
981 reasons.add(linkEvent);
982 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
983 reasons.add(linkEvent);
984
985 final TopologyEvent event = new TopologyEvent(
986 TopologyEvent.Type.TOPOLOGY_CHANGED,
987 topology,
988 reasons);
989
990 //Change Topology : remove device4 , link2 and link4
991 Set<TopologyEdge> tempEdges = new HashSet<>();
992 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
993 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
994 Set<TopologyVertex> tempVertexes = new HashSet<>();
995 tempVertexes.add(D4);
996 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
997 listener.event(event);
998
999 //No path
1000 assertThat(pathService.paths().size(), is(0));
1001 }
1002
1003 /**
1004 * Tests resilency when D2 device is suspended.
1005 */
1006 @Test
1007 public void resilencyTest8() {
1008 build4RouterTopo(true, false, false, false, 10);
1009
1010 List<Constraint> constraints = new LinkedList<Constraint>();
1011 CostConstraint costConstraint = new CostConstraint(COST);
1012 constraints.add(costConstraint);
1013 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1014 constraints.add(localBwConst);
1015
1016 //Setup the path , tunnel created
Priyankab-Huawei3946d732016-10-11 06:24:38 +00001017 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301018 assertThat(result, is(true));
1019
1020 List<Event> reasons = new LinkedList<>();
1021 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1022 reasons.add(linkEvent);
1023 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1024 reasons.add(linkEvent);
1025
1026 final TopologyEvent event = new TopologyEvent(
1027 TopologyEvent.Type.TOPOLOGY_CHANGED,
1028 topology,
1029 reasons);
1030
1031 //Change Topology : remove device2 , link1 and link2
1032 Set<TopologyEdge> tempEdges = new HashSet<>();
1033 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1034 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1035 Set<TopologyVertex> tempVertexes = new HashSet<>();
1036 tempVertexes.add(D2);
1037 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1038 listener.event(event);
1039
1040 List<Link> links = new LinkedList<>();
1041 links.add(link3);
1042 links.add(link4);
1043
1044 //Path is D1-D3-D4
1045 assertThat(pathService.paths().iterator().next().links(), is(links));
1046 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1047 }
1048
1049 /**
1050 * Tests resilency when D2 device availability is changed.
1051 */
1052 @Test
1053 public void resilencyTest11() {
1054 build4RouterTopo(true, false, false, false, 10);
1055
1056 List<Constraint> constraints = new LinkedList<Constraint>();
1057 CostConstraint costConstraint = new CostConstraint(COST);
1058 constraints.add(costConstraint);
1059 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1060 constraints.add(localBwConst);
1061
1062 //Setup the path , tunnel created
Priyankab-Huawei3946d732016-10-11 06:24:38 +00001063 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301064 assertThat(result, is(true));
1065
1066 List<Event> reasons = new LinkedList<>();
1067 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1068 reasons.add(linkEvent);
1069 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1070 reasons.add(linkEvent);
1071
1072 final TopologyEvent event = new TopologyEvent(
1073 TopologyEvent.Type.TOPOLOGY_CHANGED,
1074 topology,
1075 reasons);
1076
1077 //Change Topology : remove device2 , link1 and link2
1078 Set<TopologyEdge> tempEdges = new HashSet<>();
1079 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1080 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1081 Set<TopologyVertex> tempVertexes = new HashSet<>();
1082 tempVertexes.add(D2);
1083 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1084 listener.event(event);
1085
1086 List<Link> links = new LinkedList<>();
1087 links.add(link3);
1088 links.add(link4);
1089
1090 //Path is D1-D3-D4
1091 assertThat(pathService.paths().iterator().next().links(), is(links));
1092 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1093 }
1094
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301095 @After
1096 public void tearDown() {
1097 pceManager.deactivate();
1098 pceManager.pathService = null;
1099 pceManager.resourceService = null;
1100 pceManager.tunnelService = null;
1101 pceManager.coreService = null;
1102 pceManager.storageService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301103 pceManager.deviceService = null;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301104 pceManager.netCfgService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301105 pceManager.pceStore = null;
Priyanka B3f92c5a2016-05-27 10:14:16 +05301106 pceManager.topologyService = null;
1107 pceManager.mastershipService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301108 flowsDownloaded = 0;
1109 }
1110
1111 private class MockTopologyService extends TopologyServiceAdapter {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301112 private void changeInTopology(TopologyGraph graphModified) {
1113 graph = graphModified;
1114 }
1115
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301116 @Override
1117 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
1118 DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
1119 DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
1120 Set<TopologyVertex> vertices = graph.getVertexes();
1121 if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
1122 // src or dst not part of the current graph
1123 return ImmutableSet.of();
1124 }
1125
1126 GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = PathComputationTest.graphSearch()
1127 .search(graph, srcV, dstV, weight, ALL_PATHS);
1128 ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
1129 for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
1130 builder.add(PathComputationTest.networkPath(path));
1131 }
1132 return builder.build();
1133 }
1134 }
1135
Priyanka B3f92c5a2016-05-27 10:14:16 +05301136 private TopologyGraph getGraph(Set<TopologyVertex> removedVertex, Set<TopologyEdge> removedEdges) {
1137 if (removedVertex != null) {
1138 vertexes.remove(removedVertex);
1139 removedVertex.forEach(v ->
1140 {
1141 vertexes.remove(v);
1142 });
1143 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301144
Priyanka B3f92c5a2016-05-27 10:14:16 +05301145 if (removedEdges != null) {
1146 removedEdges.forEach(e ->
1147 {
1148 edges.remove(e);
1149 });
1150 }
1151
1152 return new DefaultTopologyGraph(vertexes, edges);
1153 }
1154
1155 private class MockPathService extends PathServiceAdapter {
1156 Set<Path> computedPaths;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301157 @Override
1158 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
1159 // If either edge is null, bail with no paths.
1160 if (src == null || dst == null) {
1161 return ImmutableSet.of();
1162 }
1163
1164 // Otherwise get all paths between the source and destination edge
1165 // devices.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301166 computedPaths = topologyService.getPaths(null, (DeviceId) src, (DeviceId) dst, weight);
1167 return computedPaths;
1168 }
1169
1170 private Set<Path> paths() {
1171 return computedPaths;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301172 }
1173 }
1174
1175 private class MockTunnelServiceAdapter extends TunnelServiceAdapter {
1176 private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<TunnelId, Tunnel>();
1177 private int tunnelIdCounter = 0;
1178
1179 @Override
1180 public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
1181 TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
1182 Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(),
1183 tunnel.state(), tunnel.groupId(), tunnelId, tunnel.tunnelName(),
1184 path, tunnel.annotations());
1185 tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert);
1186 return tunnelId;
1187 }
1188
1189 @Override
1190 public void addListener(TunnelListener listener) {
1191 tunnelListener = listener;
1192 }
1193
1194 /**
1195 * Stimulates the effect of receiving PLSP id and LSP id from protocol PCRpt msg.
1196 */
1197 public TunnelId updateTunnelWithLspIds(Tunnel tunnel, String pLspId, String localLspId, State state) {
1198 TunnelId tunnelId = tunnel.tunnelId();
1199 Builder annotationBuilder = DefaultAnnotations.builder();
1200 annotationBuilder.putAll(tunnel.annotations());
1201
1202 // PCRpt in response to PCInitate msg will carry PLSP id allocated by PCC.
1203 if (tunnel.annotations().value(PLSP_ID) == null) {
1204 annotationBuilder.set(PLSP_ID, pLspId);
1205 }
1206
1207 // Signalled LSPs will carry local LSP id allocated by signalling protocol(PCC).
1208 if (tunnel.annotations().value(LOCAL_LSP_ID) == null) {
1209 annotationBuilder.set(LOCAL_LSP_ID, localLspId);
1210 }
1211 SparseAnnotations annotations = annotationBuilder.build();
1212 tunnelIdAsKeyStore.remove(tunnelId, tunnel);
1213
1214 Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(),
1215 state, tunnel.groupId(), tunnelId, tunnel.tunnelName(),
1216 tunnel.path(), annotations);
1217
1218 tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert);
1219
1220 return tunnelId;
1221 }
1222
1223 @Override
1224 public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) {
1225 for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) {
1226 if (tunnelIdKey.equals(tunnelId)) {
1227 tunnelIdAsKeyStore.remove(tunnelId);
1228 return true;
1229 }
1230 }
1231 return false;
1232 }
1233
1234 @Override
1235 public Tunnel queryTunnel(TunnelId tunnelId) {
1236 for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) {
1237 if (tunnelIdKey.equals(tunnelId)) {
1238 return tunnelIdAsKeyStore.get(tunnelId);
1239 }
1240 }
1241 return null;
1242 }
1243
1244 @Override
1245 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
1246 Collection<Tunnel> result = new HashSet<Tunnel>();
1247 Tunnel tunnel = null;
1248 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1249 tunnel = tunnelIdAsKeyStore.get(tunnelId);
1250
1251 if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
1252 result.add(tunnel);
1253 }
1254 }
1255
1256 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
1257 }
1258
1259 @Override
1260 public Collection<Tunnel> queryTunnel(Tunnel.Type type) {
1261 Collection<Tunnel> result = new HashSet<Tunnel>();
1262
1263 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1264 result.add(tunnelIdAsKeyStore.get(tunnelId));
1265 }
1266
1267 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
1268 }
Priyanka B3f92c5a2016-05-27 10:14:16 +05301269
1270 @Override
1271 public Collection<Tunnel> queryAllTunnels() {
1272 Collection<Tunnel> result = new HashSet<Tunnel>();
1273
1274 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1275 result.add(tunnelIdAsKeyStore.get(tunnelId));
1276 }
1277
1278 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
1279 }
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301280
Priyanka B3f92c5a2016-05-27 10:14:16 +05301281 @Override
1282 public Iterable<Tunnel> getTunnels(DeviceId deviceId) {
1283 List<Tunnel> tunnelList = new LinkedList<>();
1284
1285 for (Tunnel t : tunnelIdAsKeyStore.values()) {
1286 for (Link l : t.path().links()) {
1287 if (l.src().deviceId().equals(deviceId) || l.dst().deviceId().equals(deviceId)) {
1288 tunnelList.add(t);
1289 break;
1290 }
1291 }
1292 }
1293 return tunnelList;
1294 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301295 }
1296
1297 public static class MockCoreService extends CoreServiceAdapter {
1298
1299 @Override
1300 public ApplicationId registerApplication(String name) {
1301 return new DefaultApplicationId(1, name);
1302 }
1303
1304 @Override
1305 public IdGenerator getIdGenerator(String topic) {
1306 return new IdGenerator() {
1307 private AtomicLong counter = new AtomicLong(0);
1308
1309 @Override
1310 public long getNewId() {
1311 return counter.getAndIncrement();
1312 }
1313 };
1314 }
1315 }
1316
1317 private class MockDevice extends DefaultDevice {
1318 MockDevice(DeviceId id, Annotations annotations) {
1319 super(null, id, null, null, null, null, null, null, annotations);
1320 }
1321 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301322}