blob: 432ffb65d5af00e7a8b7d5d109571ab7f056e84f [file] [log] [blame]
Ray Milkey85267002016-11-16 11:06:35 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Ray Milkey85267002016-11-16 11:06:35 -08003 *
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
Satish K2eb5d842017-04-04 16:28:37 +053018import com.google.common.collect.ImmutableSet;
Priyanka Bbae0eeb12016-11-30 11:59:48 +053019import com.google.common.collect.Lists;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053020import org.junit.After;
21import org.junit.Before;
22import org.junit.Test;
23import org.onlab.graph.GraphPathSearch;
Priyanka B3f92c5a2016-05-27 10:14:16 +053024import org.onlab.junit.TestUtils;
25import org.onlab.junit.TestUtils.TestUtilsException;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053026import org.onlab.util.Bandwidth;
27import org.onosproject.common.DefaultTopologyGraph;
28import org.onosproject.core.ApplicationId;
29import org.onosproject.core.CoreServiceAdapter;
30import org.onosproject.core.DefaultApplicationId;
31import org.onosproject.core.IdGenerator;
Priyanka B3f92c5a2016-05-27 10:14:16 +053032import org.onosproject.event.Event;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053033import org.onosproject.incubator.net.tunnel.DefaultTunnel;
34import org.onosproject.incubator.net.tunnel.Tunnel;
35import org.onosproject.incubator.net.tunnel.Tunnel.State;
36import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
37import org.onosproject.incubator.net.tunnel.TunnelEvent;
38import org.onosproject.incubator.net.tunnel.TunnelId;
39import org.onosproject.incubator.net.tunnel.TunnelListener;
Priyanka B3f92c5a2016-05-27 10:14:16 +053040import org.onosproject.mastership.MastershipServiceAdapter;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053041import org.onosproject.net.AnnotationKeys;
42import org.onosproject.net.Annotations;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053043import org.onosproject.net.DefaultAnnotations;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053044import org.onosproject.net.DefaultAnnotations.Builder;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053045import org.onosproject.net.DefaultDevice;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053046import org.onosproject.net.Device;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053047import org.onosproject.net.DeviceId;
48import org.onosproject.net.ElementId;
49import org.onosproject.net.Link;
Satish K2eb5d842017-04-04 16:28:37 +053050import org.onosproject.net.LinkKey;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053051import org.onosproject.net.MastershipRole;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053052import org.onosproject.net.Path;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053053import org.onosproject.net.SparseAnnotations;
54import org.onosproject.net.intent.Constraint;
Priyanka B3f92c5a2016-05-27 10:14:16 +053055import org.onosproject.net.link.LinkEvent;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053056import org.onosproject.net.provider.ProviderId;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053057import org.onosproject.net.topology.DefaultTopologyEdge;
58import org.onosproject.net.topology.DefaultTopologyVertex;
59import org.onosproject.net.topology.LinkWeight;
60import org.onosproject.net.topology.PathServiceAdapter;
61import org.onosproject.net.topology.Topology;
62import org.onosproject.net.topology.TopologyEdge;
Priyanka B3f92c5a2016-05-27 10:14:16 +053063import org.onosproject.net.topology.TopologyEvent;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053064import org.onosproject.net.topology.TopologyGraph;
Priyanka B3f92c5a2016-05-27 10:14:16 +053065import org.onosproject.net.topology.TopologyListener;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053066import org.onosproject.net.topology.TopologyServiceAdapter;
67import org.onosproject.net.topology.TopologyVertex;
Avantika-Huawei032a9872016-05-27 22:57:38 +053068import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053069import org.onosproject.pce.pceservice.constraint.CostConstraint;
Satish K2eb5d842017-04-04 16:28:37 +053070import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053071import org.onosproject.pce.pcestore.api.PceStore;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053072import org.onosproject.pce.util.MockDeviceService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053073import org.onosproject.pce.util.PceStoreAdapter;
74import org.onosproject.pce.util.TunnelServiceAdapter;
Avantika-Huawei032a9872016-05-27 22:57:38 +053075import org.onosproject.pcep.api.DeviceCapability;
Satish K2eb5d842017-04-04 16:28:37 +053076import org.onosproject.pcep.api.TeLinkConfig;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053077import org.onosproject.store.service.TestStorageService;
Priyanka B3f92c5a2016-05-27 10:14:16 +053078
Satish K2eb5d842017-04-04 16:28:37 +053079import java.util.Collection;
80import java.util.Collections;
81import java.util.HashMap;
82import java.util.HashSet;
83import java.util.LinkedList;
84import java.util.List;
85import java.util.Set;
86import java.util.concurrent.atomic.AtomicLong;
87import java.util.function.Consumer;
88
89import static org.hamcrest.MatcherAssert.assertThat;
90import static org.hamcrest.core.Is.is;
91import static org.onlab.graph.GraphPathSearch.ALL_PATHS;
92import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED;
93import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
94import static org.onosproject.net.MastershipRole.MASTER;
95import static org.onosproject.net.topology.AdapterLinkWeigher.adapt;
96import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING;
97import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
98import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING;
99import static org.onosproject.pce.pceservice.PathComputationTest.D1;
100import static org.onosproject.pce.pceservice.PathComputationTest.D2;
101import static org.onosproject.pce.pceservice.PathComputationTest.D3;
102import static org.onosproject.pce.pceservice.PathComputationTest.D4;
103import static org.onosproject.pce.pceservice.PathComputationTest.D5;
104import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE1;
105import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2;
106import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3;
107import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4;
108import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE5;
109import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID;
110import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID;
111import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST;
112import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530113
114/**
115 * Tests the functions of PceManager.
116 */
117public class PceManagerTest {
118
119 private PathComputationTest pathCompTest = new PathComputationTest();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530120 private MockTopologyService topologyService = new MockTopologyService();
Priyanka B3f92c5a2016-05-27 10:14:16 +0530121 private MockMastershipService mastershipService = new MockMastershipService();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530122 private MockPathService pathService = new MockPathService();
123 private PceManager pceManager = new PceManager();
124 private MockCoreService coreService = new MockCoreService();
125 private MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
126 private TestStorageService storageService = new TestStorageService();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530127 private MockDeviceService deviceService = new MockDeviceService();
Satish K2eb5d842017-04-04 16:28:37 +0530128 private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530129 private PceStore pceStore = new PceStoreAdapter();
Satish K2eb5d842017-04-04 16:28:37 +0530130 private PathComputationTest.MockBandwidthMgmtService bandwidthMgmtService = new PathComputationTest
131 .MockBandwidthMgmtService();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530132
133 public static ProviderId providerId = new ProviderId("pce", "foo");
134 private static final String L3 = "L3";
135 private static final String LSRID = "lsrId";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530136 private static final String PCECC_CAPABILITY = "pceccCapability";
137 private static final String SR_CAPABILITY = "srCapability";
138 private static final String LABEL_STACK_CAPABILITY = "labelStackCapability";
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530139
140 private TopologyGraph graph = null;
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530141 private Device deviceD1, deviceD2, deviceD3, deviceD4, deviceD5;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530142 private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4;
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530143 private Link link1, link2, link3, link4, link5, link6;
Satish K2eb5d842017-04-04 16:28:37 +0530144 protected static int flowsDownloaded;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530145 private TunnelListener tunnelListener;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530146 private TopologyListener listener;
147 private Topology topology;
148 private Set<TopologyEdge> edges;
149 private Set<TopologyVertex> vertexes;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530150
151 @Before
Priyanka B3f92c5a2016-05-27 10:14:16 +0530152 public void startUp() throws TestUtilsException {
153 listener = TestUtils.getField(pceManager, "topologyListener");
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530154 pceManager.pathService = pathService;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530155 pceManager.topologyService = topologyService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530156 pceManager.tunnelService = tunnelService;
157 pceManager.coreService = coreService;
158 pceManager.storageService = storageService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530159 pceManager.deviceService = deviceService;
Avantika-Huawei032a9872016-05-27 22:57:38 +0530160 pceManager.netCfgService = netConfigRegistry;
Satish K2eb5d842017-04-04 16:28:37 +0530161 pceManager.netConfigRegistry = netConfigRegistry;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530162 pceManager.pceStore = pceStore;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530163 pceManager.mastershipService = mastershipService;
Satish K2eb5d842017-04-04 16:28:37 +0530164 pceManager.bandwidthMgmtService = bandwidthMgmtService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530165 pceManager.activate();
166 }
167
Priyanka B3f92c5a2016-05-27 10:14:16 +0530168 private class MockMastershipService extends MastershipServiceAdapter {
169 @Override
170 public MastershipRole getLocalRole(DeviceId deviceId) {
171 return MASTER;
172 }
173
174 @Override
175 public boolean isLocalMaster(DeviceId deviceId) {
176 return getLocalRole(deviceId) == MASTER;
177 }
178 }
179
Satish K2eb5d842017-04-04 16:28:37 +0530180 private void build4RouterTopo(boolean setCost, boolean setPceccCap, boolean setSrCap,
181 boolean setLabelStackCap, int bandwidth) {
Priyanka B3f92c5a2016-05-27 10:14:16 +0530182 link1 = PathComputationTest.addLink(DEVICE1, 10, DEVICE2, 20, setCost, 50);
183 link2 = PathComputationTest.addLink(DEVICE2, 30, DEVICE4, 40, setCost, 20);
184 link3 = PathComputationTest.addLink(DEVICE1, 80, DEVICE3, 70, setCost, 100);
185 link4 = PathComputationTest.addLink(DEVICE3, 60, DEVICE4, 50, setCost, 80);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530186 link5 = PathComputationTest.addLink(DEVICE2, 60, DEVICE5, 50, setCost, 80);
187 link6 = PathComputationTest.addLink(DEVICE4, 60, DEVICE5, 50, setCost, 80);
Priyanka B3f92c5a2016-05-27 10:14:16 +0530188
Satish K2eb5d842017-04-04 16:28:37 +0530189 if (setCost) {
190 TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class);
191 teLinkConfig.igpCost(50)
192 .apply();
193
194 TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class);
195 teLinkConfig2.igpCost(20)
196 .apply();
197
198 TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class);
199 teLinkConfig3.igpCost(100)
200 .apply();
201
202 TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class);
203 teLinkConfig4.igpCost(80)
204 .apply();
205
206 TeLinkConfig teLinkConfig5 = netConfigRegistry.addConfig(LinkKey.linkKey(link5), TeLinkConfig.class);
207 teLinkConfig5.igpCost(80)
208 .apply();
209
210 TeLinkConfig teLinkConfig6 = netConfigRegistry.addConfig(LinkKey.linkKey(link6), TeLinkConfig.class);
211 teLinkConfig6.igpCost(80)
212 .apply();
213 } else {
214 TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class);
215 teLinkConfig.teCost(50)
216 .apply();
217
218
219 TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class);
220 teLinkConfig2.teCost(20)
221 .apply();
222
223 TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class);
224 teLinkConfig3.teCost(100)
225 .apply();
226
227 TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class);
228 teLinkConfig4.teCost(80)
229 .apply();
230
231 TeLinkConfig teLinkConfig5 = netConfigRegistry.addConfig(LinkKey.linkKey(link5), TeLinkConfig.class);
232 teLinkConfig5.teCost(80)
233 .apply();
234
235 TeLinkConfig teLinkConfig6 = netConfigRegistry.addConfig(LinkKey.linkKey(link6), TeLinkConfig.class);
236 teLinkConfig6.teCost(80)
237 .apply();
238 }
239
240
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530241 Set<TopologyVertex> vertexes = new HashSet<TopologyVertex>();
242 vertexes.add(D1);
243 vertexes.add(D2);
244 vertexes.add(D3);
245 vertexes.add(D4);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530246 vertexes.add(D5);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530247
Priyanka B3f92c5a2016-05-27 10:14:16 +0530248 this.vertexes = vertexes;
249
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530250 Set<TopologyEdge> edges = new HashSet<TopologyEdge>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530251 TopologyEdge edge1 = new DefaultTopologyEdge(D1, D2, link1);
252 edges.add(edge1);
253
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530254 TopologyEdge edge2 = new DefaultTopologyEdge(D2, D4, link2);
255 edges.add(edge2);
256
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530257 TopologyEdge edge3 = new DefaultTopologyEdge(D1, D3, link3);
258 edges.add(edge3);
259
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530260 TopologyEdge edge4 = new DefaultTopologyEdge(D3, D4, link4);
261 edges.add(edge4);
262
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530263 TopologyEdge edge5 = new DefaultTopologyEdge(D2, D5, link5);
264 edges.add(edge5);
265
266 TopologyEdge edge6 = new DefaultTopologyEdge(D4, D5, link6);
267 edges.add(edge6);
268
Priyanka B3f92c5a2016-05-27 10:14:16 +0530269 this.edges = edges;
270
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530271 graph = new DefaultTopologyGraph(vertexes, edges);
272
273 DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
274 DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder();
275 DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder();
276 DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder();
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530277 DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530278
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530279 // Making L3 devices
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530280 builderDev1.set(AnnotationKeys.TYPE, L3);
281 builderDev1.set(LSRID, "1.1.1.1");
282
283 builderDev2.set(AnnotationKeys.TYPE, L3);
284 builderDev2.set(LSRID, "2.2.2.2");
285
286 builderDev3.set(AnnotationKeys.TYPE, L3);
287 builderDev3.set(LSRID, "3.3.3.3");
288
289 builderDev4.set(AnnotationKeys.TYPE, L3);
290 builderDev4.set(LSRID, "4.4.4.4");
291
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530292 builderDev5.set(AnnotationKeys.TYPE, L3);
293 builderDev5.set(LSRID, "5.5.5.5");
294
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530295 deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build());
296 deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build());
297 deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build());
298 deviceD4 = new MockDevice(D4.deviceId(), builderDev4.build());
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530299 deviceD5 = new MockDevice(D5.deviceId(), builderDev5.build());
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530300
301 deviceService.addDevice(deviceD1);
302 deviceService.addDevice(deviceD2);
303 deviceService.addDevice(deviceD3);
304 deviceService.addDevice(deviceD4);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530305 deviceService.addDevice(deviceD5);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530306
Satish K2eb5d842017-04-04 16:28:37 +0530307 DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
308 device1Cap.setLabelStackCap(setLabelStackCap)
309 .setLocalLabelCap(setPceccCap)
310 .setSrCap(setSrCap)
311 .apply();
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530312
Satish K2eb5d842017-04-04 16:28:37 +0530313 DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
314 device2Cap.setLabelStackCap(setLabelStackCap)
315 .setLocalLabelCap(setPceccCap)
316 .setSrCap(setSrCap)
317 .apply();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530318
Satish K2eb5d842017-04-04 16:28:37 +0530319 DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
320 device3Cap.setLabelStackCap(setLabelStackCap)
321 .setLocalLabelCap(setPceccCap)
322 .setSrCap(setSrCap)
323 .apply();
Andrey Komarov2398d962016-09-26 15:11:23 +0300324
Satish K2eb5d842017-04-04 16:28:37 +0530325 DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
326 device4Cap.setLabelStackCap(setLabelStackCap)
327 .setLocalLabelCap(setPceccCap)
328 .setSrCap(setSrCap)
329 .apply();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530330
Satish K2eb5d842017-04-04 16:28:37 +0530331 DeviceCapability device5Cap = netConfigRegistry.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class);
332 device4Cap.setLabelStackCap(setLabelStackCap)
Andrey Komarov2398d962016-09-26 15:11:23 +0300333 .setLocalLabelCap(setPceccCap)
334 .setSrCap(setSrCap)
335 .apply();
Satish K2eb5d842017-04-04 16:28:37 +0530336
337 if (bandwidth != 0) {
338 Set<Double> unreserved = new HashSet<>();
339 unreserved.add(new Double(bandwidth));
340
341 bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link1), unreserved);
342 bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link1), new Double(0));
343
344 bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link2), unreserved);
345 bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link2), new Double(0));
346
347 bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link3), unreserved);
348 bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link3), new Double(0));
349
350 bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link4), unreserved);
351 bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link4), new Double(0));
352
353 bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link5), unreserved);
354 bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link5), new Double(0));
355
356 bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link6), unreserved);
357 bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link6), new Double(0));
358 }
Andrey Komarov2398d962016-09-26 15:11:23 +0300359 }
360
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530361 /**
362 * Tests path success with (IGP) cost constraint for signalled LSP.
363 */
364 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530365 public void setupPathTest1() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530366 build4RouterTopo(true, false, false, false, 0); // IGP cost is set here.
Satish K2eb5d842017-04-04 16:28:37 +0530367 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530368 CostConstraint costConstraint = new CostConstraint(COST);
369 constraints.add(costConstraint);
370
Satish K2eb5d842017-04-04 16:28:37 +0530371 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530372 assertThat(result, is(true));
373 }
374
375 /**
376 * Tests path failure with (IGP) cost constraint for signalled LSP.
377 */
378 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530379 public void setupPathTest2() {
380 build4RouterTopo(false, false, false, false, 0); // TE cost is set here, not IGP.
381 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530382 CostConstraint costConstraint = new CostConstraint(COST);
383 constraints.add(costConstraint);
384
Satish K2eb5d842017-04-04 16:28:37 +0530385 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530386 assertThat(result, is(false));
387 }
388
389 /**
390 * Tests path success with TE-cost constraint for signalled LSP.
391 */
392 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530393 public void setupPathTest3() {
394 build4RouterTopo(false, false, false, false, 0); // TE cost is set here.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530395
Satish K2eb5d842017-04-04 16:28:37 +0530396 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530397 CostConstraint costConstraint = new CostConstraint(TE_COST);
398 constraints.add(costConstraint);
399
Satish K2eb5d842017-04-04 16:28:37 +0530400 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530401 assertThat(result, is(true));
402 }
403
404 /**
405 * Tests path failure with TE-cost constraint for signalled LSP.
406 */
407 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530408 public void setupPathTest4() {
409 build4RouterTopo(true, false, false, false, 0); // IGP cost is set here, not TE.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530410
Satish K2eb5d842017-04-04 16:28:37 +0530411 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530412 CostConstraint costConstraint = new CostConstraint(TE_COST);
413 constraints.add(costConstraint);
414
Satish K2eb5d842017-04-04 16:28:37 +0530415 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530416 assertThat(result, is(false));
417 }
418
419 /**
420 * Tests path success with (IGP) cost constraint for non-SR non-signalled LSP.
421 */
422 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530423 public void setupPathTest5() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530424 build4RouterTopo(true, true, false, false, 0);
425
Satish K2eb5d842017-04-04 16:28:37 +0530426 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530427 CostConstraint costConstraint = new CostConstraint(COST);
428 constraints.add(costConstraint);
429
Satish K2eb5d842017-04-04 16:28:37 +0530430 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
431 WITHOUT_SIGNALLING_AND_WITHOUT_SR, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530432 assertThat(result, is(true));
433 }
434
435 /**
436 * Tests path success with TE-cost constraint for non-SR non-sgnalled LSP.
437 */
438 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530439 public void setupPathTest6() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530440 build4RouterTopo(false, true, false, false, 0);
441
Satish K2eb5d842017-04-04 16:28:37 +0530442 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530443 CostConstraint costConstraint = new CostConstraint(TE_COST);
444 constraints.add(costConstraint);
445
Satish K2eb5d842017-04-04 16:28:37 +0530446 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
447 WITHOUT_SIGNALLING_AND_WITHOUT_SR, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530448 assertThat(result, is(true));
449 }
450
451 /**
Satish K2eb5d842017-04-04 16:28:37 +0530452 * Tests path failure with TE-cost constraint for non-SR non-signalled LSP(CR). Label capability not registered.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530453 */
454 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530455 public void setupPathTest7() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530456 build4RouterTopo(true, false, false, false, 0);
457
Satish K2eb5d842017-04-04 16:28:37 +0530458 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530459 CostConstraint costConstraint = new CostConstraint(TE_COST);
460 constraints.add(costConstraint);
461
Satish K2eb5d842017-04-04 16:28:37 +0530462 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
463 WITHOUT_SIGNALLING_AND_WITHOUT_SR, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530464 assertThat(result, is(false));
465 }
466
467 /**
468 * Tests path failure as bandwidth is requested but is not registered.
469 */
470 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530471 public void setupPathTest8() {
472 build4RouterTopo(true, false, false, false, 2);
473
Andrey Komarov2398d962016-09-26 15:11:23 +0300474 List<Constraint> constraints = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +0530475 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530476 CostConstraint costConstraint = new CostConstraint(TE_COST);
477
478 constraints.add(costConstraint);
479 constraints.add(bwConstraint);
480
Satish K2eb5d842017-04-04 16:28:37 +0530481 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
482 WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530483 assertThat(result, is(false));
484 }
485
486 /**
487 * Tests path failure as bandwidth requested is more than registered.
488 */
489 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530490 public void setupPathTest9() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530491 build4RouterTopo(false, false, false, false, 5);
Satish K2eb5d842017-04-04 16:28:37 +0530492 List<Constraint> constraints = new LinkedList<Constraint>();
493 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530494 CostConstraint costConstraint = new CostConstraint(TE_COST);
495
496 constraints.add(costConstraint);
497 constraints.add(bwConstraint);
498
Satish K2eb5d842017-04-04 16:28:37 +0530499 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123",
500 constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530501 assertThat(result, is(false));
502 }
503
504 /**
Satish K2eb5d842017-04-04 16:28:37 +0530505 * Tests path setup failure(without signalling). Label capability is not present.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530506 */
507 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530508 public void setupPathTest10() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530509 build4RouterTopo(false, false, false, false, 0);
Satish K2eb5d842017-04-04 16:28:37 +0530510 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530511 CostConstraint costConstraint = new CostConstraint(TE_COST);
512 constraints.add(costConstraint);
513
Satish K2eb5d842017-04-04 16:28:37 +0530514 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
515 SR_WITHOUT_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530516 assertThat(result, is(false));
517 }
518
519 /**
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530520 * Tests path setup without signalling and with bandwidth reservation.
521 */
522 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530523 public void setupPathTest12() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530524 build4RouterTopo(false, true, true, true, 15);
Satish K2eb5d842017-04-04 16:28:37 +0530525 List<Constraint> constraints = new LinkedList<Constraint>();
526 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530527 CostConstraint costConstraint = new CostConstraint(TE_COST);
528
529 constraints.add(costConstraint);
530 constraints.add(bwConstraint);
531
Satish K2eb5d842017-04-04 16:28:37 +0530532 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123",
533 constraints, SR_WITHOUT_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530534 assertThat(result, is(true));
535 }
536
537 /**
538 * Tests path setup without cost/bandwidth constraints.
539 */
540 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530541 public void setupPathTest13() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530542 build4RouterTopo(false, false, false, false, 0);
543
Satish K2eb5d842017-04-04 16:28:37 +0530544 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", null, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530545 assertThat(result, is(true));
546 }
547
548 /**
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530549 * Tests path setup with explicit path with loose node D2.
550 */
Satish K2eb5d842017-04-04 16:28:37 +0530551 @Test
552 public void setupPathTest14() {
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530553 build4RouterTopo(false, false, false, false, 0);
554
555 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
Satish K2eb5d842017-04-04 16:28:37 +0530556 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId());
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530557 explicitPathInfoList.add(obj);
558
Satish K2eb5d842017-04-04 16:28:37 +0530559 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", null, WITH_SIGNALLING,
560 explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530561
562 Tunnel tunnel = pceManager.queryAllPath().iterator().next();
563 List<Link> links = new LinkedList<>();
564 links.add(link1);
565 links.add(link2);
566
567 assertThat(result, is(true));
568 assertThat(tunnel.path().links().equals(links), is(true));
569 }
570
571 /**
572 * Tests path setup with explicit path with loose node D3.
573 */
Satish K2eb5d842017-04-04 16:28:37 +0530574 @Test
575 public void setupPathTest15() {
576 build4RouterTopo(false, false, false, false, 0);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530577
Satish K2eb5d842017-04-04 16:28:37 +0530578 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
579 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D3.deviceId());
580 explicitPathInfoList.add(obj);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530581
Satish K2eb5d842017-04-04 16:28:37 +0530582 boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING,
583 explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530584
Satish K2eb5d842017-04-04 16:28:37 +0530585 Tunnel tunnel = pceManager.queryAllPath().iterator().next();
586 List<Link> links = new LinkedList<>();
587 links.add(link3);
588 links.add(link4);
589 links.add(link6);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530590
Satish K2eb5d842017-04-04 16:28:37 +0530591 assertThat(result, is(true));
592 assertThat(tunnel.path().links().equals(links), is(true));
593 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530594
595 /**
596 * Tests path setup with explicit path with loose node D4 , D3 - path fails.
597 */
Satish K2eb5d842017-04-04 16:28:37 +0530598 @Test
599 public void setupPathTest16() {
600 build4RouterTopo(false, false, false, false, 0);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530601
Satish K2eb5d842017-04-04 16:28:37 +0530602 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
603 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D4.deviceId());
604 explicitPathInfoList.add(obj);
605 obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D3.deviceId());
606 explicitPathInfoList.add(obj);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530607
Satish K2eb5d842017-04-04 16:28:37 +0530608 boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING,
609 explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530610
Satish K2eb5d842017-04-04 16:28:37 +0530611 assertThat(result, is(false));
612 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530613
614 /**
Satish K2eb5d842017-04-04 16:28:37 +0530615 * Tests path setup with explicit path with strict node D2 - without reacble to src - path fails.
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530616 */
Satish K2eb5d842017-04-04 16:28:37 +0530617 @Test
618 public void setupPathTest17() {
619 build4RouterTopo(false, false, false, false, 0);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530620
Satish K2eb5d842017-04-04 16:28:37 +0530621 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
622 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId());
623 explicitPathInfoList.add(obj);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530624
Satish K2eb5d842017-04-04 16:28:37 +0530625 boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING,
626 explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530627
Satish K2eb5d842017-04-04 16:28:37 +0530628 assertThat(result, is(false));
629 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530630
631 /**
632 * Tests path setup with explicit path with loose node D2, strict D2.
633 */
Satish K2eb5d842017-04-04 16:28:37 +0530634 @Test
635 public void setupPathTest18() {
636 build4RouterTopo(false, false, false, false, 0);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530637
Satish K2eb5d842017-04-04 16:28:37 +0530638 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
639 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId());
640 explicitPathInfoList.add(obj);
641 obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId());
642 explicitPathInfoList.add(obj);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530643
Satish K2eb5d842017-04-04 16:28:37 +0530644 boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING,
645 explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530646
Satish K2eb5d842017-04-04 16:28:37 +0530647 Tunnel tunnel = pceManager.queryAllPath().iterator().next();
648 List<Link> links = new LinkedList<>();
649 links.add(link1);
650 links.add(link5);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530651
Satish K2eb5d842017-04-04 16:28:37 +0530652 assertThat(result, is(true));
653 assertThat(tunnel.path().links().equals(links), is(true));
654 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530655
656 /**
657 * Tests path setup with explicit path with loose D1-D2, strict D2.
658 */
Satish K2eb5d842017-04-04 16:28:37 +0530659 @Test
660 public void setupPathTest19() {
661 build4RouterTopo(false, false, false, false, 0);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530662
Satish K2eb5d842017-04-04 16:28:37 +0530663 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
664 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, link1);
665 explicitPathInfoList.add(obj);
666 obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId());
667 explicitPathInfoList.add(obj);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530668
Satish K2eb5d842017-04-04 16:28:37 +0530669 boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING,
670 explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530671
Satish K2eb5d842017-04-04 16:28:37 +0530672 Tunnel tunnel = pceManager.queryAllPath().iterator().next();
673 List<Link> links = new LinkedList<>();
674 links.add(link1);
675 links.add(link5);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530676
Satish K2eb5d842017-04-04 16:28:37 +0530677 assertThat(result, is(true));
678 assertThat(tunnel.path().links().equals(links), is(true));
679 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530680
681 /**
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530682 * Tests path update with increase in bandwidth.
683 */
684 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530685 public void updatePathTest1() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530686 build4RouterTopo(false, true, true, true, 100);
687
688 // Setup tunnel.
689 List<Constraint> constraints = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +0530690 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(60.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530691 constraints.add(bwConstraint);
692 CostConstraint costConstraint = new CostConstraint(TE_COST);
693 constraints.add(costConstraint);
694
Satish K2eb5d842017-04-04 16:28:37 +0530695 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
696 constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530697 assertThat(result, is(true));
698
699 // Change constraint and update it.
700 constraints = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +0530701 bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(50.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530702 constraints.add(bwConstraint);
703 constraints.add(costConstraint);
704
705 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
706 assertThat(tunnels.size(), is(1));
707
708 Tunnel tunnel = tunnels.iterator().next();
709
710 // Stimulate the effect of LSP ids from protocol msg.
711 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", State.ACTIVE);
712
713 result = pceManager.updatePath(tunnel.tunnelId(), constraints);
714 assertThat(result, is(true));
715
716 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
717 assertThat(tunnels.size(), is(2));
718 }
719
720 /**
721 * Tests path update with decrease in bandwidth.
722 */
723 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530724 public void updatePathTest2() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530725 build4RouterTopo(false, true, true, true, 100);
726
727 // Setup tunnel.
Satish K2eb5d842017-04-04 16:28:37 +0530728 List<Constraint> constraints = new LinkedList<Constraint>();
729 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(60.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530730 constraints.add(bwConstraint);
731 CostConstraint costConstraint = new CostConstraint(TE_COST);
732 constraints.add(costConstraint);
733
Satish K2eb5d842017-04-04 16:28:37 +0530734 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123",
735 constraints, SR_WITHOUT_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530736 assertThat(result, is(true));
737
738 // Change constraint and update it.
739 constraints.remove(bwConstraint);
Satish K2eb5d842017-04-04 16:28:37 +0530740 bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(70.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530741 constraints.add(bwConstraint);
742
743 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
744 assertThat(tunnels.size(), is(1));
745
746 for (Tunnel tunnel : tunnels) {
747 result = pceManager.updatePath(tunnel.tunnelId(), constraints);
748 assertThat(result, is(true));
749 }
750
751 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
752 assertThat(tunnels.size(), is(2));
753 }
754
755 /**
756 * Tests path update without cost/bandwidth constraints.
757 */
758 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530759 public void updatePathTest3() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530760 build4RouterTopo(false, true, true, true, 100);
761
762 // Setup tunnel.
Satish K2eb5d842017-04-04 16:28:37 +0530763 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3fdb9dd2016-08-08 10:47:24 +0530764 CostConstraint costConstraint = new CostConstraint(TE_COST);
765 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +0530766 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123",
767 constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530768 assertThat(result, is(true));
769
770 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
771 assertThat(tunnels.size(), is(1));
772
773 for (Tunnel tunnel : tunnels) {
774 result = pceManager.updatePath(tunnel.tunnelId(), null);
775 assertThat(result, is(true));
776 }
777
778 Iterable<Tunnel> queryTunnelResult = pceManager.queryAllPath();
Satish K2eb5d842017-04-04 16:28:37 +0530779 assertThat((int) queryTunnelResult.spliterator().getExactSizeIfKnown(), is(2));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530780 }
781
782 /**
Satish K2eb5d842017-04-04 16:28:37 +0530783 * Tests path update without cost/bandwidth constraints and with explicit path object.
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530784 */
785 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530786 public void updatePathTest4() {
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530787 build4RouterTopo(false, true, true, true, 100);
788
789 // Setup tunnel.
790 List<Constraint> constraints = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +0530791 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(60.0));
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530792 constraints.add(bwConstraint);
793 CostConstraint costConstraint = new CostConstraint(TE_COST);
794 constraints.add(costConstraint);
795
796 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
Satish K2eb5d842017-04-04 16:28:37 +0530797 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, link1);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530798 explicitPathInfoList.add(obj);
799 obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId());
800 explicitPathInfoList.add(obj);
801
Satish K2eb5d842017-04-04 16:28:37 +0530802 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
803 constraints, WITH_SIGNALLING, explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530804 assertThat(result, is(true));
805
806 // Change constraint and update it.
807 constraints = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +0530808 bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(50.0));
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530809 constraints.add(bwConstraint);
810 constraints.add(costConstraint);
811
812 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
813 assertThat(tunnels.size(), is(1));
814
815 Tunnel tunnel = tunnels.iterator().next();
816
817 // Stimulate the effect of LSP ids from protocol msg.
818 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", State.ACTIVE);
819
820 result = pceManager.updatePath(tunnel.tunnelId(), constraints);
821 assertThat(result, is(true));
822
823 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
824 assertThat(tunnels.size(), is(2));
825 }
826
827 /**
Satish K2eb5d842017-04-04 16:28:37 +0530828 * Tests path release.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530829 */
830 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530831 public void releasePathTest1() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530832 build4RouterTopo(false, false, false, false, 5);
Satish K2eb5d842017-04-04 16:28:37 +0530833 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530834 CostConstraint costConstraint = new CostConstraint(TE_COST);
Satish K2eb5d842017-04-04 16:28:37 +0530835 PceBandwidthConstraint bwConst = new PceBandwidthConstraint(Bandwidth.bps(3));
Priyanka B4c3b4512016-07-22 11:41:49 +0530836 constraints.add(bwConst);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530837 constraints.add(costConstraint);
838
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530839 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
840 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, link1);
841 explicitPathInfoList.add(obj);
842 obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId());
843 explicitPathInfoList.add(obj);
844
Satish K2eb5d842017-04-04 16:28:37 +0530845 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, explicitPathInfoList);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530846
847 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
848 assertThat(tunnels.size(), is(1));
849 boolean result;
850 for (Tunnel tunnel : tunnels) {
851 result = pceManager.releasePath(tunnel.tunnelId());
852 assertThat(result, is(true));
853 }
854 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
855 assertThat(tunnels.size(), is(0));
856 }
857
858 /**
859 * Tests path release failure.
860 */
861 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530862 public void releasePathTest2() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530863 build4RouterTopo(false, false, false, false, 5);
Satish K2eb5d842017-04-04 16:28:37 +0530864 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530865 CostConstraint costConstraint = new CostConstraint(TE_COST);
866 constraints.add(costConstraint);
867
Satish K2eb5d842017-04-04 16:28:37 +0530868 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530869
870 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
871 assertThat(tunnels.size(), is(1));
872
873 // Random tunnel id.
874 boolean result = pceManager.releasePath(TunnelId.valueOf("111"));
875 assertThat(result, is(false));
876
877 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
878 assertThat(tunnels.size(), is(1));
879 }
880
881 /**
Satish K2eb5d842017-04-04 16:28:37 +0530882 * Tests path release failure.
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530883 */
884 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530885 public void releasePathTest3() {
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530886 build4RouterTopo(false, false, false, false, 5);
887 List<Constraint> constraints = new LinkedList<Constraint>();
888 CostConstraint costConstraint = new CostConstraint(TE_COST);
Satish K2eb5d842017-04-04 16:28:37 +0530889 PceBandwidthConstraint bwConst = new PceBandwidthConstraint(Bandwidth.bps(3));
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530890 constraints.add(bwConst);
891 constraints.add(costConstraint);
892
Satish K2eb5d842017-04-04 16:28:37 +0530893 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530894
895 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
896 assertThat(tunnels.size(), is(1));
897 boolean result;
898 for (Tunnel tunnel : tunnels) {
899 result = pceManager.releasePath(tunnel.tunnelId());
900 assertThat(result, is(true));
901 }
902 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
903 assertThat(tunnels.size(), is(0));
904 }
905
906 /**
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530907 * Tests tunnel events added and removed.
908 */
909 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530910 public void tunnelEventTest1() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530911 build4RouterTopo(false, true, true, true, 15);
Satish K2eb5d842017-04-04 16:28:37 +0530912 List<Constraint> constraints = new LinkedList<Constraint>();
913 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530914 CostConstraint costConstraint = new CostConstraint(TE_COST);
915
916 constraints.add(costConstraint);
917 constraints.add(bwConstraint);
918
Satish K2eb5d842017-04-04 16:28:37 +0530919 boolean isSuccess = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T1", constraints,
Andrey Komarov2398d962016-09-26 15:11:23 +0300920 SR_WITHOUT_SIGNALLING, null);
Satish K2eb5d842017-04-04 16:28:37 +0530921 assertThat(isSuccess, is(true));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530922
923 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
924
925 for (Tunnel tunnel : tunnels) {
Satish K2eb5d842017-04-04 16:28:37 +0530926 TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530927 tunnelListener.event(event);
928
Satish K2eb5d842017-04-04 16:28:37 +0530929 isSuccess = pceManager.releasePath(tunnel.tunnelId());
930 assertThat(isSuccess, is(true));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530931
932 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel);
933 tunnelListener.event(event);
934 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530935 }
936
937 /**
938 * Tests label allocation/removal in CR case based on tunnel event.
939 */
940 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530941 public void tunnelEventTest2() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530942 build4RouterTopo(false, true, true, true, 15);
Satish K2eb5d842017-04-04 16:28:37 +0530943 List<Constraint> constraints = new LinkedList<Constraint>();
944 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530945 CostConstraint costConstraint = new CostConstraint(TE_COST);
946
947 constraints.add(costConstraint);
948 constraints.add(bwConstraint);
949
Satish K2eb5d842017-04-04 16:28:37 +0530950 boolean isSuccess = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints,
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530951 WITHOUT_SIGNALLING_AND_WITHOUT_SR, null);
Satish K2eb5d842017-04-04 16:28:37 +0530952 assertThat(isSuccess, is(true));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530953
954 TunnelEvent event;
955 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
956 for (Tunnel tunnel : tunnels) {
957 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
958 tunnelListener.event(event);
959
960 // Stimulate the effect of LSP ids from protocol msg.
961 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", ESTABLISHED);
962 }
963
964 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
965 for (Tunnel tunnel : tunnels) {
966 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel);
967 tunnelListener.event(event);
968
Satish K2eb5d842017-04-04 16:28:37 +0530969 isSuccess = pceManager.releasePath(tunnel.tunnelId());
970 assertThat(isSuccess, is(true));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530971
972 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel);
973 tunnelListener.event(event);
974 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530975 }
976
977 /**
978 * Tests handling UNSTABLE state based on tunnel event.
979 */
980 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530981 public void tunnelEventTest3() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530982 build4RouterTopo(false, true, true, true, 15);
Satish K2eb5d842017-04-04 16:28:37 +0530983 List<Constraint> constraints = new LinkedList<Constraint>();
984 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530985 CostConstraint costConstraint = new CostConstraint(TE_COST);
986
987 constraints.add(costConstraint);
988 constraints.add(bwConstraint);
989
Satish K2eb5d842017-04-04 16:28:37 +0530990 boolean isSuccess = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints,
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530991 WITHOUT_SIGNALLING_AND_WITHOUT_SR, null);
Satish K2eb5d842017-04-04 16:28:37 +0530992 assertThat(isSuccess, is(true));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530993 assertThat(pceStore.getFailedPathInfoCount(), is(0));
994
995 TunnelEvent event;
996 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
997 for (Tunnel tunnel : tunnels) {
998 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
999 tunnelListener.event(event);
1000
1001 // Stimulate the effect of LSP ids from protocol msg.
1002 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", UNSTABLE);
1003 }
1004
1005 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
1006 for (Tunnel tunnel : tunnels) {
1007 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel);
1008 tunnelListener.event(event);
1009 }
Satish K2eb5d842017-04-04 16:28:37 +05301010
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301011 assertThat(pceStore.getFailedPathInfoCount(), is(1));
1012 }
1013
Priyanka B3f92c5a2016-05-27 10:14:16 +05301014 /**
Satish K2eb5d842017-04-04 16:28:37 +05301015 * Tests resilency when L2 link is down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301016 */
1017 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301018 public void resilencyTest1() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301019 build4RouterTopo(true, false, false, false, 10);
1020
1021
Satish K2eb5d842017-04-04 16:28:37 +05301022 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301023 CostConstraint costConstraint = new CostConstraint(COST);
1024 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301025 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301026 constraints.add(localBwConst);
1027
1028 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301029 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1030 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301031 assertThat(result, is(true));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301032 assertThat(pceStore.getFailedPathInfoCount(), is(0));
1033
1034 List<Event> reasons = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +05301035 final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301036 reasons.add(linkEvent);
1037 final TopologyEvent event = new TopologyEvent(
1038 TopologyEvent.Type.TOPOLOGY_CHANGED,
1039 topology,
1040 reasons);
1041
1042 //Change Topology : remove link2
1043 Set<TopologyEdge> tempEdges = new HashSet<>();
1044 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
Satish K2eb5d842017-04-04 16:28:37 +05301045 topologyService.changeInTopology(getGraph(null, tempEdges));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301046 listener.event(event);
1047
1048 List<Link> links = new LinkedList<>();
1049 links.add(link3);
1050 links.add(link4);
1051
1052 //Path is D1-D3-D4
1053 assertThat(pathService.paths().iterator().next().links(), is(links));
1054 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1055 }
1056
1057 /**
Satish K2eb5d842017-04-04 16:28:37 +05301058 * Tests resilency when L2 and L4 link is down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301059 */
1060 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301061 public void resilencyTest2() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301062 build4RouterTopo(true, false, false, false, 10);
1063
Satish K2eb5d842017-04-04 16:28:37 +05301064 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301065 CostConstraint costConstraint = new CostConstraint(COST);
1066 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301067 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301068 constraints.add(localBwConst);
1069
1070 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301071 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1072 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301073 assertThat(result, is(true));
1074
1075 List<Event> reasons = new LinkedList<>();
1076 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1077 reasons.add(linkEvent);
1078 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1079 reasons.add(linkEvent);
1080 final TopologyEvent event = new TopologyEvent(
1081 TopologyEvent.Type.TOPOLOGY_CHANGED,
1082 topology,
1083 reasons);
1084
1085 //Change Topology : remove link2 and link4
1086 Set<TopologyEdge> tempEdges = new HashSet<>();
1087 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1088 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
Satish K2eb5d842017-04-04 16:28:37 +05301089 topologyService.changeInTopology(getGraph(null, tempEdges));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301090 listener.event(event);
1091
1092 //No Path
1093 assertThat(pathService.paths().size(), is(0));
1094 }
1095
1096 /**
Satish K2eb5d842017-04-04 16:28:37 +05301097 * Tests resilency when D2 device is down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301098 */
1099 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301100 public void resilencyTest3() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301101 build4RouterTopo(true, false, false, false, 10);
1102
Satish K2eb5d842017-04-04 16:28:37 +05301103 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301104 CostConstraint costConstraint = new CostConstraint(COST);
1105 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301106 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301107 constraints.add(localBwConst);
1108
1109 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301110 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1111 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301112 assertThat(result, is(true));
1113
1114 List<Event> reasons = new LinkedList<>();
1115 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1116 reasons.add(linkEvent);
1117 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1118 reasons.add(linkEvent);
1119 final TopologyEvent event = new TopologyEvent(
1120 TopologyEvent.Type.TOPOLOGY_CHANGED,
1121 topology,
1122 reasons);
1123
1124 //Change Topology : remove link2 and link1
1125 Set<TopologyEdge> tempEdges = new HashSet<>();
1126 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1127 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
Satish K2eb5d842017-04-04 16:28:37 +05301128 topologyService.changeInTopology(getGraph(null, tempEdges));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301129 listener.event(event);
1130
1131 List<Link> links = new LinkedList<>();
1132 links.add(link3);
1133 links.add(link4);
1134
Satish K2eb5d842017-04-04 16:28:37 +05301135 Path path = tunnelService.queryAllTunnels().iterator().next().path();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301136 //Path is D1-D3-D4
Satish K2eb5d842017-04-04 16:28:37 +05301137 assertThat(path.links(), is(links));
1138 assertThat(path.cost(), is((double) 180));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301139 }
1140
1141 /**
Satish K2eb5d842017-04-04 16:28:37 +05301142 * Tests resilency when ingress device is down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301143 */
1144 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301145 public void resilencyTest4() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301146 build4RouterTopo(true, false, false, false, 10);
1147
Satish K2eb5d842017-04-04 16:28:37 +05301148 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301149 CostConstraint costConstraint = new CostConstraint(COST);
1150 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301151 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301152 constraints.add(localBwConst);
1153
1154 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301155 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1156 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301157 assertThat(result, is(true));
1158
1159 List<Event> reasons = new LinkedList<>();
1160 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1161 reasons.add(linkEvent);
1162 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1163 reasons.add(linkEvent);
1164 final TopologyEvent event = new TopologyEvent(
1165 TopologyEvent.Type.TOPOLOGY_CHANGED,
1166 topology,
1167 reasons);
1168
1169 //Change Topology : remove link2 and link1
1170 Set<TopologyEdge> tempEdges = new HashSet<>();
1171 tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
1172 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1173 topologyService.changeInTopology(getGraph(null, tempEdges));
1174 listener.event(event);
1175
1176 //No path
1177 assertThat(pathService.paths().size(), is(0));
1178 }
1179
1180 /**
Satish K2eb5d842017-04-04 16:28:37 +05301181 * Tests resilency when D2 and D3 devices are down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301182 */
1183 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301184 public void resilencyTest5() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301185 build4RouterTopo(true, false, false, false, 10);
1186
Satish K2eb5d842017-04-04 16:28:37 +05301187 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301188 CostConstraint costConstraint = new CostConstraint(COST);
1189 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301190 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301191 constraints.add(localBwConst);
1192
1193 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301194 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1195 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301196 assertThat(result, is(true));
1197
1198 List<Event> reasons = new LinkedList<>();
1199 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1200 reasons.add(linkEvent);
1201 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1202 reasons.add(linkEvent);
1203 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1204 reasons.add(linkEvent);
1205 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1206 reasons.add(linkEvent);
1207
1208 final TopologyEvent event = new TopologyEvent(
1209 TopologyEvent.Type.TOPOLOGY_CHANGED,
1210 topology,
1211 reasons);
1212
1213 //Change Topology : remove device2, device3 and all links
1214 Set<TopologyEdge> tempEdges = new HashSet<>();
1215 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1216 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1217 tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
1218 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1219 Set<TopologyVertex> tempVertexes = new HashSet<>();
1220 tempVertexes.add(D2);
1221 tempVertexes.add(D3);
1222 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1223 listener.event(event);
1224
1225 //No path
1226 assertThat(pathService.paths().size(), is(0));
1227 }
1228
1229 /**
Satish K2eb5d842017-04-04 16:28:37 +05301230 * Tests resilency when egress device is down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301231 */
1232 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301233 public void resilencyTest6() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301234 build4RouterTopo(true, false, false, false, 10);
1235
Satish K2eb5d842017-04-04 16:28:37 +05301236 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301237 CostConstraint costConstraint = new CostConstraint(COST);
1238 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301239 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301240 constraints.add(localBwConst);
1241
1242 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301243 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1244 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301245 assertThat(result, is(true));
1246
1247 List<Event> reasons = new LinkedList<>();
1248 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1249 reasons.add(linkEvent);
1250 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1251 reasons.add(linkEvent);
1252
1253 final TopologyEvent event = new TopologyEvent(
1254 TopologyEvent.Type.TOPOLOGY_CHANGED,
1255 topology,
1256 reasons);
1257
1258 //Change Topology : remove device4 , link2 and link4
1259 Set<TopologyEdge> tempEdges = new HashSet<>();
1260 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1261 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1262 Set<TopologyVertex> tempVertexes = new HashSet<>();
1263 tempVertexes.add(D4);
1264 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1265 listener.event(event);
1266
1267 //No path
1268 assertThat(pathService.paths().size(), is(0));
1269 }
1270
1271 /**
Satish K2eb5d842017-04-04 16:28:37 +05301272 * Tests resilency when egress device is down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301273 */
1274 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301275 public void resilencyTest7() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301276 build4RouterTopo(true, false, false, false, 10);
1277
Satish K2eb5d842017-04-04 16:28:37 +05301278 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301279 CostConstraint costConstraint = new CostConstraint(COST);
1280 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301281 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301282 constraints.add(localBwConst);
1283
1284 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301285 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1286 constraints, WITH_SIGNALLING, null);
1287 assertThat(result, is(true));
1288
1289 List<Event> reasons = new LinkedList<>();
1290 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1291 reasons.add(linkEvent);
1292 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1293 reasons.add(linkEvent);
1294
1295 final TopologyEvent event = new TopologyEvent(
1296 TopologyEvent.Type.TOPOLOGY_CHANGED,
1297 topology,
1298 reasons);
1299
1300 //Change Topology : remove device4 , link2 and link4
1301 Set<TopologyEdge> tempEdges = new HashSet<>();
1302 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1303 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1304 Set<TopologyVertex> tempVertexes = new HashSet<>();
1305 tempVertexes.add(D4);
1306 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1307 listener.event(event);
1308
1309 //No path
1310 assertThat(pathService.paths().size(), is(0));
1311 }
1312
1313 /**
1314 * Tests resilency when D2 device is suspended.
1315 */
1316 @Test
1317 public void resilencyTest8() {
1318 build4RouterTopo(true, false, false, false, 10);
1319
1320 List<Constraint> constraints = new LinkedList<Constraint>();
1321 CostConstraint costConstraint = new CostConstraint(COST);
1322 constraints.add(costConstraint);
1323 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
1324 constraints.add(localBwConst);
1325
1326 //Setup the path , tunnel created
1327 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1328 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301329 assertThat(result, is(true));
1330
1331 List<Event> reasons = new LinkedList<>();
1332 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1333 reasons.add(linkEvent);
1334 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1335 reasons.add(linkEvent);
1336
1337 final TopologyEvent event = new TopologyEvent(
1338 TopologyEvent.Type.TOPOLOGY_CHANGED,
1339 topology,
1340 reasons);
1341
1342 //Change Topology : remove device2 , link1 and link2
1343 Set<TopologyEdge> tempEdges = new HashSet<>();
1344 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1345 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1346 Set<TopologyVertex> tempVertexes = new HashSet<>();
1347 tempVertexes.add(D2);
1348 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1349 listener.event(event);
1350
1351 List<Link> links = new LinkedList<>();
1352 links.add(link3);
1353 links.add(link4);
1354
Satish K2eb5d842017-04-04 16:28:37 +05301355 Path path = tunnelService.queryAllTunnels().iterator().next().path();
1356
Priyanka B3f92c5a2016-05-27 10:14:16 +05301357 //Path is D1-D3-D4
Satish K2eb5d842017-04-04 16:28:37 +05301358 assertThat(path.links(), is(links));
1359 assertThat(path.cost(), is((double) 180));
1360 }
1361
1362 /**
1363 * Tests resilency when D2 device availability is changed.
1364 */
1365 @Test
1366 public void resilencyTest11() {
1367 build4RouterTopo(true, false, false, false, 10);
1368
1369 List<Constraint> constraints = new LinkedList<Constraint>();
1370 CostConstraint costConstraint = new CostConstraint(COST);
1371 constraints.add(costConstraint);
1372 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
1373 constraints.add(localBwConst);
1374
1375 //Setup the path , tunnel created
1376 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1377 constraints, WITH_SIGNALLING, null);
1378 assertThat(result, is(true));
1379
1380 List<Event> reasons = new LinkedList<>();
1381 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1382 reasons.add(linkEvent);
1383 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1384 reasons.add(linkEvent);
1385
1386 final TopologyEvent event = new TopologyEvent(
1387 TopologyEvent.Type.TOPOLOGY_CHANGED,
1388 topology,
1389 reasons);
1390
1391 //Change Topology : remove device2 , link1 and link2
1392 Set<TopologyEdge> tempEdges = new HashSet<>();
1393 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1394 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1395 Set<TopologyVertex> tempVertexes = new HashSet<>();
1396 tempVertexes.add(D2);
1397 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1398 listener.event(event);
1399
1400 List<Link> links = new LinkedList<>();
1401 links.add(link3);
1402 links.add(link4);
1403
1404 Path path = tunnelService.queryAllTunnels().iterator().next().path();
1405
1406 //Path is D1-D3-D4
1407 assertThat(path.links(), is(links));
1408 assertThat(path.cost(), is((double) 180));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301409 }
1410
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301411 /**
1412 * Tests resilency when link2 availability is changed.
1413 */
1414 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301415 public void resilencyTest12() {
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301416 build4RouterTopo(true, false, false, false, 10);
1417
1418 List<Constraint> constraints = new LinkedList<Constraint>();
1419 CostConstraint costConstraint = new CostConstraint(COST);
1420 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301421 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301422 constraints.add(localBwConst);
1423
1424 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
Satish K2eb5d842017-04-04 16:28:37 +05301425 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, link1);
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301426 explicitPathInfoList.add(obj);
1427 obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId());
1428 explicitPathInfoList.add(obj);
1429
1430 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301431 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1432 constraints, WITH_SIGNALLING, explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301433 assertThat(result, is(true));
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301434 assertThat(pceStore.getFailedPathInfoCount(), is(0));
1435
1436 List<Event> reasons = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +05301437 final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301438 reasons.add(linkEvent);
1439 final TopologyEvent event = new TopologyEvent(
1440 TopologyEvent.Type.TOPOLOGY_CHANGED,
1441 topology,
1442 reasons);
1443
1444 //Change Topology : remove link2
1445 Set<TopologyEdge> tempEdges = new HashSet<>();
1446 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1447 topologyService.changeInTopology(getGraph(null, tempEdges));
1448 listener.event(event);
1449
1450 List<Link> links = new LinkedList<>();
1451 links.add(link3);
1452 links.add(link4);
1453
1454 //Path fails - no alternate path
1455 assertThat(pathService.paths().iterator().hasNext(), is(false));
1456 }
1457
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301458 @After
1459 public void tearDown() {
1460 pceManager.deactivate();
1461 pceManager.pathService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301462 pceManager.tunnelService = null;
1463 pceManager.coreService = null;
1464 pceManager.storageService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301465 pceManager.deviceService = null;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301466 pceManager.netCfgService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301467 pceManager.pceStore = null;
Priyanka B3f92c5a2016-05-27 10:14:16 +05301468 pceManager.topologyService = null;
1469 pceManager.mastershipService = null;
Satish K2eb5d842017-04-04 16:28:37 +05301470 flowsDownloaded = 0;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301471 }
1472
1473 private class MockTopologyService extends TopologyServiceAdapter {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301474 private void changeInTopology(TopologyGraph graphModified) {
1475 graph = graphModified;
1476 }
1477
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301478 @Override
Satish K2eb5d842017-04-04 16:28:37 +05301479 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301480 DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
1481 DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
1482 Set<TopologyVertex> vertices = graph.getVertexes();
1483 if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
1484 // src or dst not part of the current graph
1485 return ImmutableSet.of();
1486 }
1487
Satish K2eb5d842017-04-04 16:28:37 +05301488 GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = PathComputationTest.graphSearch()
1489 .search(graph, srcV, dstV, adapt(weight), ALL_PATHS);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301490 ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
1491 for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
1492 builder.add(PathComputationTest.networkPath(path));
1493 }
1494 return builder.build();
1495 }
1496 }
1497
Satish K2eb5d842017-04-04 16:28:37 +05301498 private TopologyGraph getGraph(Set<TopologyVertex> removedVertex, Set<TopologyEdge> removedEdges) {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301499 if (removedVertex != null) {
Satish K2eb5d842017-04-04 16:28:37 +05301500 vertexes.remove(removedVertex);
1501 removedVertex.forEach(new Consumer<TopologyVertex>() {
1502 @Override
1503 public void accept(TopologyVertex v) {
1504 vertexes.remove(v);
1505 }
1506 });
Priyanka B3f92c5a2016-05-27 10:14:16 +05301507 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301508
Priyanka B3f92c5a2016-05-27 10:14:16 +05301509 if (removedEdges != null) {
Satish K2eb5d842017-04-04 16:28:37 +05301510 removedEdges.forEach(new Consumer<TopologyEdge>() {
1511 @Override
1512 public void accept(TopologyEdge e) {
1513 edges.remove(e);
1514 }
1515 });
Priyanka B3f92c5a2016-05-27 10:14:16 +05301516 }
1517
1518 return new DefaultTopologyGraph(vertexes, edges);
1519 }
1520
1521 private class MockPathService extends PathServiceAdapter {
1522 Set<Path> computedPaths;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301523 @Override
1524 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
1525 // If either edge is null, bail with no paths.
1526 if (src == null || dst == null) {
1527 return ImmutableSet.of();
1528 }
1529
1530 // Otherwise get all paths between the source and destination edge
1531 // devices.
Satish K2eb5d842017-04-04 16:28:37 +05301532 computedPaths = topologyService.getPaths(null, (DeviceId) src, (DeviceId) dst, weight);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301533 return computedPaths;
1534 }
1535
1536 private Set<Path> paths() {
1537 return computedPaths;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301538 }
1539 }
1540
1541 private class MockTunnelServiceAdapter extends TunnelServiceAdapter {
Satish K2eb5d842017-04-04 16:28:37 +05301542 private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<TunnelId, Tunnel>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301543 private int tunnelIdCounter = 0;
1544
1545 @Override
Satish K2eb5d842017-04-04 16:28:37 +05301546 public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301547 TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
Satish K2eb5d842017-04-04 16:28:37 +05301548 Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(),
1549 tunnel.state(), tunnel.groupId(), tunnelId, tunnel.tunnelName(),
1550 path, tunnel.annotations());
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301551 tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert);
1552 return tunnelId;
1553 }
1554
1555 @Override
1556 public void addListener(TunnelListener listener) {
1557 tunnelListener = listener;
1558 }
1559
1560 /**
Satish K2eb5d842017-04-04 16:28:37 +05301561 * Stimulates the effect of receiving PLSP id and LSP id from protocol PCRpt msg.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301562 */
Satish K2eb5d842017-04-04 16:28:37 +05301563 public TunnelId updateTunnelWithLspIds(Tunnel tunnel, String pLspId, String localLspId, State state) {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301564 TunnelId tunnelId = tunnel.tunnelId();
1565 Builder annotationBuilder = DefaultAnnotations.builder();
1566 annotationBuilder.putAll(tunnel.annotations());
1567
Satish K2eb5d842017-04-04 16:28:37 +05301568 // PCRpt in response to PCInitate msg will carry PLSP id allocated by PCC.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301569 if (tunnel.annotations().value(PLSP_ID) == null) {
1570 annotationBuilder.set(PLSP_ID, pLspId);
1571 }
1572
Satish K2eb5d842017-04-04 16:28:37 +05301573 // Signalled LSPs will carry local LSP id allocated by signalling protocol(PCC).
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301574 if (tunnel.annotations().value(LOCAL_LSP_ID) == null) {
1575 annotationBuilder.set(LOCAL_LSP_ID, localLspId);
1576 }
1577 SparseAnnotations annotations = annotationBuilder.build();
1578 tunnelIdAsKeyStore.remove(tunnelId, tunnel);
1579
Satish K2eb5d842017-04-04 16:28:37 +05301580 Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(),
1581 state, tunnel.groupId(), tunnelId, tunnel.tunnelName(),
1582 tunnel.path(), annotations);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301583
1584 tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert);
1585
1586 return tunnelId;
1587 }
1588
1589 @Override
1590 public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) {
1591 for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) {
1592 if (tunnelIdKey.equals(tunnelId)) {
1593 tunnelIdAsKeyStore.remove(tunnelId);
1594 return true;
1595 }
1596 }
1597 return false;
1598 }
1599
1600 @Override
1601 public Tunnel queryTunnel(TunnelId tunnelId) {
1602 for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) {
1603 if (tunnelIdKey.equals(tunnelId)) {
1604 return tunnelIdAsKeyStore.get(tunnelId);
1605 }
1606 }
1607 return null;
1608 }
1609
1610 @Override
Satish K2eb5d842017-04-04 16:28:37 +05301611 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
1612 Collection<Tunnel> result = new HashSet<Tunnel>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301613 Tunnel tunnel = null;
1614 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1615 tunnel = tunnelIdAsKeyStore.get(tunnelId);
1616
Satish K2eb5d842017-04-04 16:28:37 +05301617 if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301618 result.add(tunnel);
1619 }
1620 }
1621
Satish K2eb5d842017-04-04 16:28:37 +05301622 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301623 }
1624
1625 @Override
1626 public Collection<Tunnel> queryTunnel(Tunnel.Type type) {
Satish K2eb5d842017-04-04 16:28:37 +05301627 Collection<Tunnel> result = new HashSet<Tunnel>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301628
1629 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1630 result.add(tunnelIdAsKeyStore.get(tunnelId));
1631 }
1632
Satish K2eb5d842017-04-04 16:28:37 +05301633 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301634 }
Priyanka B3f92c5a2016-05-27 10:14:16 +05301635
1636 @Override
1637 public Collection<Tunnel> queryAllTunnels() {
Satish K2eb5d842017-04-04 16:28:37 +05301638 Collection<Tunnel> result = new HashSet<Tunnel>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301639
1640 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1641 result.add(tunnelIdAsKeyStore.get(tunnelId));
1642 }
1643
Satish K2eb5d842017-04-04 16:28:37 +05301644 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301645 }
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301646
Priyanka B3f92c5a2016-05-27 10:14:16 +05301647 @Override
1648 public Iterable<Tunnel> getTunnels(DeviceId deviceId) {
1649 List<Tunnel> tunnelList = new LinkedList<>();
1650
1651 for (Tunnel t : tunnelIdAsKeyStore.values()) {
1652 for (Link l : t.path().links()) {
Satish K2eb5d842017-04-04 16:28:37 +05301653 if (l.src().deviceId().equals(deviceId) || l.dst().deviceId().equals(deviceId)) {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301654 tunnelList.add(t);
1655 break;
1656 }
1657 }
1658 }
1659 return tunnelList;
1660 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301661 }
1662
1663 public static class MockCoreService extends CoreServiceAdapter {
1664
1665 @Override
1666 public ApplicationId registerApplication(String name) {
1667 return new DefaultApplicationId(1, name);
1668 }
1669
1670 @Override
1671 public IdGenerator getIdGenerator(String topic) {
1672 return new IdGenerator() {
1673 private AtomicLong counter = new AtomicLong(0);
1674
1675 @Override
1676 public long getNewId() {
1677 return counter.getAndIncrement();
1678 }
1679 };
1680 }
1681 }
1682
1683 private class MockDevice extends DefaultDevice {
1684 MockDevice(DeviceId id, Annotations annotations) {
1685 super(null, id, null, null, null, null, null, null, annotations);
1686 }
1687 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301688}