blob: 95a464e36e2419b0078cadd2594d2d8e941d14ad [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;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070040import org.onosproject.incubator.net.tunnel.TunnelServiceAdapter;
Priyanka B3f92c5a2016-05-27 10:14:16 +053041import org.onosproject.mastership.MastershipServiceAdapter;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053042import org.onosproject.net.AnnotationKeys;
43import org.onosproject.net.Annotations;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053044import org.onosproject.net.DefaultAnnotations;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053045import org.onosproject.net.DefaultAnnotations.Builder;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053046import org.onosproject.net.DefaultDevice;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053047import org.onosproject.net.Device;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053048import org.onosproject.net.DeviceId;
49import org.onosproject.net.ElementId;
50import org.onosproject.net.Link;
Satish K2eb5d842017-04-04 16:28:37 +053051import org.onosproject.net.LinkKey;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053052import org.onosproject.net.MastershipRole;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053053import org.onosproject.net.Path;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053054import org.onosproject.net.SparseAnnotations;
55import org.onosproject.net.intent.Constraint;
Priyanka B3f92c5a2016-05-27 10:14:16 +053056import org.onosproject.net.link.LinkEvent;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053057import org.onosproject.net.provider.ProviderId;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053058import org.onosproject.net.topology.DefaultTopologyEdge;
59import org.onosproject.net.topology.DefaultTopologyVertex;
Ray Milkey7483e1b2018-02-07 15:43:01 -080060import org.onosproject.net.topology.LinkWeigher;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053061import org.onosproject.net.topology.PathServiceAdapter;
62import org.onosproject.net.topology.Topology;
63import org.onosproject.net.topology.TopologyEdge;
Priyanka B3f92c5a2016-05-27 10:14:16 +053064import org.onosproject.net.topology.TopologyEvent;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053065import org.onosproject.net.topology.TopologyGraph;
Priyanka B3f92c5a2016-05-27 10:14:16 +053066import org.onosproject.net.topology.TopologyListener;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053067import org.onosproject.net.topology.TopologyServiceAdapter;
68import org.onosproject.net.topology.TopologyVertex;
Avantika-Huawei032a9872016-05-27 22:57:38 +053069import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053070import org.onosproject.pce.pceservice.constraint.CostConstraint;
Satish K2eb5d842017-04-04 16:28:37 +053071import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053072import org.onosproject.pce.pcestore.api.PceStore;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053073import org.onosproject.pce.util.MockDeviceService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053074import org.onosproject.pce.util.PceStoreAdapter;
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;
Satish K2eb5d842017-04-04 16:28:37 +053095import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING;
96import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
97import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING;
98import static org.onosproject.pce.pceservice.PathComputationTest.D1;
99import static org.onosproject.pce.pceservice.PathComputationTest.D2;
100import static org.onosproject.pce.pceservice.PathComputationTest.D3;
101import static org.onosproject.pce.pceservice.PathComputationTest.D4;
102import static org.onosproject.pce.pceservice.PathComputationTest.D5;
103import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE1;
104import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2;
105import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3;
106import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4;
107import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE5;
108import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID;
109import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID;
110import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST;
111import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530112
113/**
114 * Tests the functions of PceManager.
115 */
116public class PceManagerTest {
117
118 private PathComputationTest pathCompTest = new PathComputationTest();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530119 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();
Satish K2eb5d842017-04-04 16:28:37 +0530127 private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530128 private PceStore pceStore = new PceStoreAdapter();
Satish K2eb5d842017-04-04 16:28:37 +0530129 private PathComputationTest.MockBandwidthMgmtService bandwidthMgmtService = new PathComputationTest
130 .MockBandwidthMgmtService();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530131
132 public static ProviderId providerId = new ProviderId("pce", "foo");
133 private static final String L3 = "L3";
134 private static final String LSRID = "lsrId";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530135 private static final String PCECC_CAPABILITY = "pceccCapability";
136 private static final String SR_CAPABILITY = "srCapability";
137 private static final String LABEL_STACK_CAPABILITY = "labelStackCapability";
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530138
139 private TopologyGraph graph = null;
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530140 private Device deviceD1, deviceD2, deviceD3, deviceD4, deviceD5;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530141 private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4;
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530142 private Link link1, link2, link3, link4, link5, link6;
Satish K2eb5d842017-04-04 16:28:37 +0530143 protected static int flowsDownloaded;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530144 private TunnelListener tunnelListener;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530145 private TopologyListener listener;
146 private Topology topology;
147 private Set<TopologyEdge> edges;
148 private Set<TopologyVertex> vertexes;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530149
150 @Before
Priyanka B3f92c5a2016-05-27 10:14:16 +0530151 public void startUp() throws TestUtilsException {
152 listener = TestUtils.getField(pceManager, "topologyListener");
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530153 pceManager.pathService = pathService;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530154 pceManager.topologyService = topologyService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530155 pceManager.tunnelService = tunnelService;
156 pceManager.coreService = coreService;
157 pceManager.storageService = storageService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530158 pceManager.deviceService = deviceService;
Avantika-Huawei032a9872016-05-27 22:57:38 +0530159 pceManager.netCfgService = netConfigRegistry;
Satish K2eb5d842017-04-04 16:28:37 +0530160 pceManager.netConfigRegistry = netConfigRegistry;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530161 pceManager.pceStore = pceStore;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530162 pceManager.mastershipService = mastershipService;
Satish K2eb5d842017-04-04 16:28:37 +0530163 pceManager.bandwidthMgmtService = bandwidthMgmtService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530164 pceManager.activate();
165 }
166
Priyanka B3f92c5a2016-05-27 10:14:16 +0530167 private class MockMastershipService extends MastershipServiceAdapter {
168 @Override
169 public MastershipRole getLocalRole(DeviceId deviceId) {
170 return MASTER;
171 }
172
173 @Override
174 public boolean isLocalMaster(DeviceId deviceId) {
175 return getLocalRole(deviceId) == MASTER;
176 }
177 }
178
Satish K2eb5d842017-04-04 16:28:37 +0530179 private void build4RouterTopo(boolean setCost, boolean setPceccCap, boolean setSrCap,
180 boolean setLabelStackCap, int bandwidth) {
Priyanka B3f92c5a2016-05-27 10:14:16 +0530181 link1 = PathComputationTest.addLink(DEVICE1, 10, DEVICE2, 20, setCost, 50);
182 link2 = PathComputationTest.addLink(DEVICE2, 30, DEVICE4, 40, setCost, 20);
183 link3 = PathComputationTest.addLink(DEVICE1, 80, DEVICE3, 70, setCost, 100);
184 link4 = PathComputationTest.addLink(DEVICE3, 60, DEVICE4, 50, setCost, 80);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530185 link5 = PathComputationTest.addLink(DEVICE2, 60, DEVICE5, 50, setCost, 80);
186 link6 = PathComputationTest.addLink(DEVICE4, 60, DEVICE5, 50, setCost, 80);
Priyanka B3f92c5a2016-05-27 10:14:16 +0530187
Satish K2eb5d842017-04-04 16:28:37 +0530188 if (setCost) {
189 TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class);
190 teLinkConfig.igpCost(50)
191 .apply();
192
193 TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class);
194 teLinkConfig2.igpCost(20)
195 .apply();
196
197 TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class);
198 teLinkConfig3.igpCost(100)
199 .apply();
200
201 TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class);
202 teLinkConfig4.igpCost(80)
203 .apply();
204
205 TeLinkConfig teLinkConfig5 = netConfigRegistry.addConfig(LinkKey.linkKey(link5), TeLinkConfig.class);
206 teLinkConfig5.igpCost(80)
207 .apply();
208
209 TeLinkConfig teLinkConfig6 = netConfigRegistry.addConfig(LinkKey.linkKey(link6), TeLinkConfig.class);
210 teLinkConfig6.igpCost(80)
211 .apply();
212 } else {
213 TeLinkConfig teLinkConfig = netConfigRegistry.addConfig(LinkKey.linkKey(link1), TeLinkConfig.class);
214 teLinkConfig.teCost(50)
215 .apply();
216
217
218 TeLinkConfig teLinkConfig2 = netConfigRegistry.addConfig(LinkKey.linkKey(link2), TeLinkConfig.class);
219 teLinkConfig2.teCost(20)
220 .apply();
221
222 TeLinkConfig teLinkConfig3 = netConfigRegistry.addConfig(LinkKey.linkKey(link3), TeLinkConfig.class);
223 teLinkConfig3.teCost(100)
224 .apply();
225
226 TeLinkConfig teLinkConfig4 = netConfigRegistry.addConfig(LinkKey.linkKey(link4), TeLinkConfig.class);
227 teLinkConfig4.teCost(80)
228 .apply();
229
230 TeLinkConfig teLinkConfig5 = netConfigRegistry.addConfig(LinkKey.linkKey(link5), TeLinkConfig.class);
231 teLinkConfig5.teCost(80)
232 .apply();
233
234 TeLinkConfig teLinkConfig6 = netConfigRegistry.addConfig(LinkKey.linkKey(link6), TeLinkConfig.class);
235 teLinkConfig6.teCost(80)
236 .apply();
237 }
238
239
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530240 Set<TopologyVertex> vertexes = new HashSet<TopologyVertex>();
241 vertexes.add(D1);
242 vertexes.add(D2);
243 vertexes.add(D3);
244 vertexes.add(D4);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530245 vertexes.add(D5);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530246
Priyanka B3f92c5a2016-05-27 10:14:16 +0530247 this.vertexes = vertexes;
248
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530249 Set<TopologyEdge> edges = new HashSet<TopologyEdge>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530250 TopologyEdge edge1 = new DefaultTopologyEdge(D1, D2, link1);
251 edges.add(edge1);
252
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530253 TopologyEdge edge2 = new DefaultTopologyEdge(D2, D4, link2);
254 edges.add(edge2);
255
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530256 TopologyEdge edge3 = new DefaultTopologyEdge(D1, D3, link3);
257 edges.add(edge3);
258
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530259 TopologyEdge edge4 = new DefaultTopologyEdge(D3, D4, link4);
260 edges.add(edge4);
261
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530262 TopologyEdge edge5 = new DefaultTopologyEdge(D2, D5, link5);
263 edges.add(edge5);
264
265 TopologyEdge edge6 = new DefaultTopologyEdge(D4, D5, link6);
266 edges.add(edge6);
267
Priyanka B3f92c5a2016-05-27 10:14:16 +0530268 this.edges = edges;
269
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530270 graph = new DefaultTopologyGraph(vertexes, edges);
271
272 DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
273 DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder();
274 DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder();
275 DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder();
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530276 DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530277
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530278 // Making L3 devices
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530279 builderDev1.set(AnnotationKeys.TYPE, L3);
280 builderDev1.set(LSRID, "1.1.1.1");
281
282 builderDev2.set(AnnotationKeys.TYPE, L3);
283 builderDev2.set(LSRID, "2.2.2.2");
284
285 builderDev3.set(AnnotationKeys.TYPE, L3);
286 builderDev3.set(LSRID, "3.3.3.3");
287
288 builderDev4.set(AnnotationKeys.TYPE, L3);
289 builderDev4.set(LSRID, "4.4.4.4");
290
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530291 builderDev5.set(AnnotationKeys.TYPE, L3);
292 builderDev5.set(LSRID, "5.5.5.5");
293
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530294 deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build());
295 deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build());
296 deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build());
297 deviceD4 = new MockDevice(D4.deviceId(), builderDev4.build());
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530298 deviceD5 = new MockDevice(D5.deviceId(), builderDev5.build());
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530299
300 deviceService.addDevice(deviceD1);
301 deviceService.addDevice(deviceD2);
302 deviceService.addDevice(deviceD3);
303 deviceService.addDevice(deviceD4);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530304 deviceService.addDevice(deviceD5);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530305
Satish K2eb5d842017-04-04 16:28:37 +0530306 DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
307 device1Cap.setLabelStackCap(setLabelStackCap)
308 .setLocalLabelCap(setPceccCap)
309 .setSrCap(setSrCap)
310 .apply();
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530311
Satish K2eb5d842017-04-04 16:28:37 +0530312 DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
313 device2Cap.setLabelStackCap(setLabelStackCap)
314 .setLocalLabelCap(setPceccCap)
315 .setSrCap(setSrCap)
316 .apply();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530317
Satish K2eb5d842017-04-04 16:28:37 +0530318 DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
319 device3Cap.setLabelStackCap(setLabelStackCap)
320 .setLocalLabelCap(setPceccCap)
321 .setSrCap(setSrCap)
322 .apply();
Andrey Komarov2398d962016-09-26 15:11:23 +0300323
Satish K2eb5d842017-04-04 16:28:37 +0530324 DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
325 device4Cap.setLabelStackCap(setLabelStackCap)
326 .setLocalLabelCap(setPceccCap)
327 .setSrCap(setSrCap)
328 .apply();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530329
Satish K2eb5d842017-04-04 16:28:37 +0530330 DeviceCapability device5Cap = netConfigRegistry.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class);
331 device4Cap.setLabelStackCap(setLabelStackCap)
Andrey Komarov2398d962016-09-26 15:11:23 +0300332 .setLocalLabelCap(setPceccCap)
333 .setSrCap(setSrCap)
334 .apply();
Satish K2eb5d842017-04-04 16:28:37 +0530335
336 if (bandwidth != 0) {
337 Set<Double> unreserved = new HashSet<>();
338 unreserved.add(new Double(bandwidth));
339
340 bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link1), unreserved);
341 bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link1), new Double(0));
342
343 bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link2), unreserved);
344 bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link2), new Double(0));
345
346 bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link3), unreserved);
347 bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link3), new Double(0));
348
349 bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link4), unreserved);
350 bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link4), new Double(0));
351
352 bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link5), unreserved);
353 bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link5), new Double(0));
354
355 bandwidthMgmtService.addUnreservedBw(LinkKey.linkKey(link6), unreserved);
356 bandwidthMgmtService.allocLocalReservedBw(LinkKey.linkKey(link6), new Double(0));
357 }
Andrey Komarov2398d962016-09-26 15:11:23 +0300358 }
359
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530360 /**
361 * Tests path success with (IGP) cost constraint for signalled LSP.
362 */
363 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530364 public void setupPathTest1() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530365 build4RouterTopo(true, false, false, false, 0); // IGP cost is set here.
Satish K2eb5d842017-04-04 16:28:37 +0530366 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530367 CostConstraint costConstraint = new CostConstraint(COST);
368 constraints.add(costConstraint);
369
Satish K2eb5d842017-04-04 16:28:37 +0530370 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530371 assertThat(result, is(true));
372 }
373
374 /**
375 * Tests path failure with (IGP) cost constraint for signalled LSP.
376 */
377 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530378 public void setupPathTest2() {
379 build4RouterTopo(false, false, false, false, 0); // TE cost is set here, not IGP.
380 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530381 CostConstraint costConstraint = new CostConstraint(COST);
382 constraints.add(costConstraint);
383
Satish K2eb5d842017-04-04 16:28:37 +0530384 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530385 assertThat(result, is(false));
386 }
387
388 /**
389 * Tests path success with TE-cost constraint for signalled LSP.
390 */
391 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530392 public void setupPathTest3() {
393 build4RouterTopo(false, false, false, false, 0); // TE cost is set here.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530394
Satish K2eb5d842017-04-04 16:28:37 +0530395 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530396 CostConstraint costConstraint = new CostConstraint(TE_COST);
397 constraints.add(costConstraint);
398
Satish K2eb5d842017-04-04 16:28:37 +0530399 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530400 assertThat(result, is(true));
401 }
402
403 /**
404 * Tests path failure with TE-cost constraint for signalled LSP.
405 */
406 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530407 public void setupPathTest4() {
408 build4RouterTopo(true, false, false, false, 0); // IGP cost is set here, not TE.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530409
Satish K2eb5d842017-04-04 16:28:37 +0530410 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530411 CostConstraint costConstraint = new CostConstraint(TE_COST);
412 constraints.add(costConstraint);
413
Satish K2eb5d842017-04-04 16:28:37 +0530414 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530415 assertThat(result, is(false));
416 }
417
418 /**
419 * Tests path success with (IGP) cost constraint for non-SR non-signalled LSP.
420 */
421 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530422 public void setupPathTest5() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530423 build4RouterTopo(true, true, false, false, 0);
424
Satish K2eb5d842017-04-04 16:28:37 +0530425 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530426 CostConstraint costConstraint = new CostConstraint(COST);
427 constraints.add(costConstraint);
428
Satish K2eb5d842017-04-04 16:28:37 +0530429 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
430 WITHOUT_SIGNALLING_AND_WITHOUT_SR, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530431 assertThat(result, is(true));
432 }
433
434 /**
435 * Tests path success with TE-cost constraint for non-SR non-sgnalled LSP.
436 */
437 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530438 public void setupPathTest6() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530439 build4RouterTopo(false, true, false, false, 0);
440
Satish K2eb5d842017-04-04 16:28:37 +0530441 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530442 CostConstraint costConstraint = new CostConstraint(TE_COST);
443 constraints.add(costConstraint);
444
Satish K2eb5d842017-04-04 16:28:37 +0530445 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
446 WITHOUT_SIGNALLING_AND_WITHOUT_SR, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530447 assertThat(result, is(true));
448 }
449
450 /**
Satish K2eb5d842017-04-04 16:28:37 +0530451 * 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 +0530452 */
453 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530454 public void setupPathTest7() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530455 build4RouterTopo(true, false, false, false, 0);
456
Satish K2eb5d842017-04-04 16:28:37 +0530457 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530458 CostConstraint costConstraint = new CostConstraint(TE_COST);
459 constraints.add(costConstraint);
460
Satish K2eb5d842017-04-04 16:28:37 +0530461 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
462 WITHOUT_SIGNALLING_AND_WITHOUT_SR, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530463 assertThat(result, is(false));
464 }
465
466 /**
467 * Tests path failure as bandwidth is requested but is not registered.
468 */
469 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530470 public void setupPathTest8() {
471 build4RouterTopo(true, false, false, false, 2);
472
Andrey Komarov2398d962016-09-26 15:11:23 +0300473 List<Constraint> constraints = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +0530474 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530475 CostConstraint costConstraint = new CostConstraint(TE_COST);
476
477 constraints.add(costConstraint);
478 constraints.add(bwConstraint);
479
Satish K2eb5d842017-04-04 16:28:37 +0530480 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
481 WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530482 assertThat(result, is(false));
483 }
484
485 /**
486 * Tests path failure as bandwidth requested is more than registered.
487 */
488 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530489 public void setupPathTest9() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530490 build4RouterTopo(false, false, false, false, 5);
Satish K2eb5d842017-04-04 16:28:37 +0530491 List<Constraint> constraints = new LinkedList<Constraint>();
492 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530493 CostConstraint costConstraint = new CostConstraint(TE_COST);
494
495 constraints.add(costConstraint);
496 constraints.add(bwConstraint);
497
Satish K2eb5d842017-04-04 16:28:37 +0530498 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123",
499 constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530500 assertThat(result, is(false));
501 }
502
503 /**
Satish K2eb5d842017-04-04 16:28:37 +0530504 * Tests path setup failure(without signalling). Label capability is not present.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530505 */
506 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530507 public void setupPathTest10() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530508 build4RouterTopo(false, false, false, false, 0);
Satish K2eb5d842017-04-04 16:28:37 +0530509 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530510 CostConstraint costConstraint = new CostConstraint(TE_COST);
511 constraints.add(costConstraint);
512
Satish K2eb5d842017-04-04 16:28:37 +0530513 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
514 SR_WITHOUT_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530515 assertThat(result, is(false));
516 }
517
518 /**
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530519 * Tests path setup without signalling and with bandwidth reservation.
520 */
521 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530522 public void setupPathTest12() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530523 build4RouterTopo(false, true, true, true, 15);
Satish K2eb5d842017-04-04 16:28:37 +0530524 List<Constraint> constraints = new LinkedList<Constraint>();
525 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530526 CostConstraint costConstraint = new CostConstraint(TE_COST);
527
528 constraints.add(costConstraint);
529 constraints.add(bwConstraint);
530
Satish K2eb5d842017-04-04 16:28:37 +0530531 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123",
532 constraints, SR_WITHOUT_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530533 assertThat(result, is(true));
534 }
535
536 /**
537 * Tests path setup without cost/bandwidth constraints.
538 */
539 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530540 public void setupPathTest13() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530541 build4RouterTopo(false, false, false, false, 0);
542
Satish K2eb5d842017-04-04 16:28:37 +0530543 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", null, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530544 assertThat(result, is(true));
545 }
546
547 /**
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530548 * Tests path setup with explicit path with loose node D2.
549 */
Satish K2eb5d842017-04-04 16:28:37 +0530550 @Test
551 public void setupPathTest14() {
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530552 build4RouterTopo(false, false, false, false, 0);
553
554 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
Satish K2eb5d842017-04-04 16:28:37 +0530555 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId());
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530556 explicitPathInfoList.add(obj);
557
Satish K2eb5d842017-04-04 16:28:37 +0530558 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", null, WITH_SIGNALLING,
559 explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530560
561 Tunnel tunnel = pceManager.queryAllPath().iterator().next();
562 List<Link> links = new LinkedList<>();
563 links.add(link1);
564 links.add(link2);
565
566 assertThat(result, is(true));
567 assertThat(tunnel.path().links().equals(links), is(true));
568 }
569
570 /**
571 * Tests path setup with explicit path with loose node D3.
572 */
Satish K2eb5d842017-04-04 16:28:37 +0530573 @Test
574 public void setupPathTest15() {
575 build4RouterTopo(false, false, false, false, 0);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530576
Satish K2eb5d842017-04-04 16:28:37 +0530577 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
578 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D3.deviceId());
579 explicitPathInfoList.add(obj);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530580
Satish K2eb5d842017-04-04 16:28:37 +0530581 boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING,
582 explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530583
Satish K2eb5d842017-04-04 16:28:37 +0530584 Tunnel tunnel = pceManager.queryAllPath().iterator().next();
585 List<Link> links = new LinkedList<>();
586 links.add(link3);
587 links.add(link4);
588 links.add(link6);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530589
Satish K2eb5d842017-04-04 16:28:37 +0530590 assertThat(result, is(true));
591 assertThat(tunnel.path().links().equals(links), is(true));
592 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530593
594 /**
595 * Tests path setup with explicit path with loose node D4 , D3 - path fails.
596 */
Satish K2eb5d842017-04-04 16:28:37 +0530597 @Test
598 public void setupPathTest16() {
599 build4RouterTopo(false, false, false, false, 0);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530600
Satish K2eb5d842017-04-04 16:28:37 +0530601 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
602 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D4.deviceId());
603 explicitPathInfoList.add(obj);
604 obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D3.deviceId());
605 explicitPathInfoList.add(obj);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530606
Satish K2eb5d842017-04-04 16:28:37 +0530607 boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING,
608 explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530609
Satish K2eb5d842017-04-04 16:28:37 +0530610 assertThat(result, is(false));
611 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530612
613 /**
Satish K2eb5d842017-04-04 16:28:37 +0530614 * Tests path setup with explicit path with strict node D2 - without reacble to src - path fails.
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530615 */
Satish K2eb5d842017-04-04 16:28:37 +0530616 @Test
617 public void setupPathTest17() {
618 build4RouterTopo(false, false, false, false, 0);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530619
Satish K2eb5d842017-04-04 16:28:37 +0530620 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
621 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId());
622 explicitPathInfoList.add(obj);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530623
Satish K2eb5d842017-04-04 16:28:37 +0530624 boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING,
625 explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530626
Satish K2eb5d842017-04-04 16:28:37 +0530627 assertThat(result, is(false));
628 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530629
630 /**
631 * Tests path setup with explicit path with loose node D2, strict D2.
632 */
Satish K2eb5d842017-04-04 16:28:37 +0530633 @Test
634 public void setupPathTest18() {
635 build4RouterTopo(false, false, false, false, 0);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530636
Satish K2eb5d842017-04-04 16:28:37 +0530637 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
638 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, D2.deviceId());
639 explicitPathInfoList.add(obj);
640 obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId());
641 explicitPathInfoList.add(obj);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530642
Satish K2eb5d842017-04-04 16:28:37 +0530643 boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING,
644 explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530645
Satish K2eb5d842017-04-04 16:28:37 +0530646 Tunnel tunnel = pceManager.queryAllPath().iterator().next();
647 List<Link> links = new LinkedList<>();
648 links.add(link1);
649 links.add(link5);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530650
Satish K2eb5d842017-04-04 16:28:37 +0530651 assertThat(result, is(true));
652 assertThat(tunnel.path().links().equals(links), is(true));
653 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530654
655 /**
656 * Tests path setup with explicit path with loose D1-D2, strict D2.
657 */
Satish K2eb5d842017-04-04 16:28:37 +0530658 @Test
659 public void setupPathTest19() {
660 build4RouterTopo(false, false, false, false, 0);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530661
Satish K2eb5d842017-04-04 16:28:37 +0530662 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
663 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, link1);
664 explicitPathInfoList.add(obj);
665 obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId());
666 explicitPathInfoList.add(obj);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530667
Satish K2eb5d842017-04-04 16:28:37 +0530668 boolean result = pceManager.setupPath(D1.deviceId(), D5.deviceId(), "T123", null, WITH_SIGNALLING,
669 explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530670
Satish K2eb5d842017-04-04 16:28:37 +0530671 Tunnel tunnel = pceManager.queryAllPath().iterator().next();
672 List<Link> links = new LinkedList<>();
673 links.add(link1);
674 links.add(link5);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530675
Satish K2eb5d842017-04-04 16:28:37 +0530676 assertThat(result, is(true));
677 assertThat(tunnel.path().links().equals(links), is(true));
678 }
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530679
680 /**
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530681 * Tests path update with increase in bandwidth.
682 */
683 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530684 public void updatePathTest1() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530685 build4RouterTopo(false, true, true, true, 100);
686
687 // Setup tunnel.
688 List<Constraint> constraints = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +0530689 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(60.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530690 constraints.add(bwConstraint);
691 CostConstraint costConstraint = new CostConstraint(TE_COST);
692 constraints.add(costConstraint);
693
Satish K2eb5d842017-04-04 16:28:37 +0530694 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
695 constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530696 assertThat(result, is(true));
697
698 // Change constraint and update it.
699 constraints = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +0530700 bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(50.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530701 constraints.add(bwConstraint);
702 constraints.add(costConstraint);
703
704 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
705 assertThat(tunnels.size(), is(1));
706
707 Tunnel tunnel = tunnels.iterator().next();
708
709 // Stimulate the effect of LSP ids from protocol msg.
710 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", State.ACTIVE);
711
712 result = pceManager.updatePath(tunnel.tunnelId(), constraints);
713 assertThat(result, is(true));
714
715 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
716 assertThat(tunnels.size(), is(2));
717 }
718
719 /**
720 * Tests path update with decrease in bandwidth.
721 */
722 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530723 public void updatePathTest2() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530724 build4RouterTopo(false, true, true, true, 100);
725
726 // Setup tunnel.
Satish K2eb5d842017-04-04 16:28:37 +0530727 List<Constraint> constraints = new LinkedList<Constraint>();
728 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(60.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530729 constraints.add(bwConstraint);
730 CostConstraint costConstraint = new CostConstraint(TE_COST);
731 constraints.add(costConstraint);
732
Satish K2eb5d842017-04-04 16:28:37 +0530733 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123",
734 constraints, SR_WITHOUT_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530735 assertThat(result, is(true));
736
737 // Change constraint and update it.
738 constraints.remove(bwConstraint);
Satish K2eb5d842017-04-04 16:28:37 +0530739 bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(70.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530740 constraints.add(bwConstraint);
741
742 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
743 assertThat(tunnels.size(), is(1));
744
745 for (Tunnel tunnel : tunnels) {
746 result = pceManager.updatePath(tunnel.tunnelId(), constraints);
747 assertThat(result, is(true));
748 }
749
750 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
751 assertThat(tunnels.size(), is(2));
752 }
753
754 /**
755 * Tests path update without cost/bandwidth constraints.
756 */
757 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530758 public void updatePathTest3() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530759 build4RouterTopo(false, true, true, true, 100);
760
761 // Setup tunnel.
Satish K2eb5d842017-04-04 16:28:37 +0530762 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3fdb9dd2016-08-08 10:47:24 +0530763 CostConstraint costConstraint = new CostConstraint(TE_COST);
764 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +0530765 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123",
766 constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530767 assertThat(result, is(true));
768
769 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
770 assertThat(tunnels.size(), is(1));
771
772 for (Tunnel tunnel : tunnels) {
773 result = pceManager.updatePath(tunnel.tunnelId(), null);
774 assertThat(result, is(true));
775 }
776
777 Iterable<Tunnel> queryTunnelResult = pceManager.queryAllPath();
Satish K2eb5d842017-04-04 16:28:37 +0530778 assertThat((int) queryTunnelResult.spliterator().getExactSizeIfKnown(), is(2));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530779 }
780
781 /**
Satish K2eb5d842017-04-04 16:28:37 +0530782 * Tests path update without cost/bandwidth constraints and with explicit path object.
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530783 */
784 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530785 public void updatePathTest4() {
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530786 build4RouterTopo(false, true, true, true, 100);
787
788 // Setup tunnel.
789 List<Constraint> constraints = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +0530790 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(60.0));
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530791 constraints.add(bwConstraint);
792 CostConstraint costConstraint = new CostConstraint(TE_COST);
793 constraints.add(costConstraint);
794
795 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
Satish K2eb5d842017-04-04 16:28:37 +0530796 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, link1);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530797 explicitPathInfoList.add(obj);
798 obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId());
799 explicitPathInfoList.add(obj);
800
Satish K2eb5d842017-04-04 16:28:37 +0530801 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
802 constraints, WITH_SIGNALLING, explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530803 assertThat(result, is(true));
804
805 // Change constraint and update it.
806 constraints = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +0530807 bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(50.0));
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530808 constraints.add(bwConstraint);
809 constraints.add(costConstraint);
810
811 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
812 assertThat(tunnels.size(), is(1));
813
814 Tunnel tunnel = tunnels.iterator().next();
815
816 // Stimulate the effect of LSP ids from protocol msg.
817 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", State.ACTIVE);
818
819 result = pceManager.updatePath(tunnel.tunnelId(), constraints);
820 assertThat(result, is(true));
821
822 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
823 assertThat(tunnels.size(), is(2));
824 }
825
826 /**
Satish K2eb5d842017-04-04 16:28:37 +0530827 * Tests path release.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530828 */
829 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530830 public void releasePathTest1() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530831 build4RouterTopo(false, false, false, false, 5);
Satish K2eb5d842017-04-04 16:28:37 +0530832 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530833 CostConstraint costConstraint = new CostConstraint(TE_COST);
Satish K2eb5d842017-04-04 16:28:37 +0530834 PceBandwidthConstraint bwConst = new PceBandwidthConstraint(Bandwidth.bps(3));
Priyanka B4c3b4512016-07-22 11:41:49 +0530835 constraints.add(bwConst);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530836 constraints.add(costConstraint);
837
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530838 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
839 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, link1);
840 explicitPathInfoList.add(obj);
841 obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId());
842 explicitPathInfoList.add(obj);
843
Satish K2eb5d842017-04-04 16:28:37 +0530844 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, explicitPathInfoList);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530845
846 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
847 assertThat(tunnels.size(), is(1));
848 boolean result;
849 for (Tunnel tunnel : tunnels) {
850 result = pceManager.releasePath(tunnel.tunnelId());
851 assertThat(result, is(true));
852 }
853 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
854 assertThat(tunnels.size(), is(0));
855 }
856
857 /**
858 * Tests path release failure.
859 */
860 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530861 public void releasePathTest2() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530862 build4RouterTopo(false, false, false, false, 5);
Satish K2eb5d842017-04-04 16:28:37 +0530863 List<Constraint> constraints = new LinkedList<Constraint>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530864 CostConstraint costConstraint = new CostConstraint(TE_COST);
865 constraints.add(costConstraint);
866
Satish K2eb5d842017-04-04 16:28:37 +0530867 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530868
869 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
870 assertThat(tunnels.size(), is(1));
871
872 // Random tunnel id.
873 boolean result = pceManager.releasePath(TunnelId.valueOf("111"));
874 assertThat(result, is(false));
875
876 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
877 assertThat(tunnels.size(), is(1));
878 }
879
880 /**
Satish K2eb5d842017-04-04 16:28:37 +0530881 * Tests path release failure.
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530882 */
883 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530884 public void releasePathTest3() {
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530885 build4RouterTopo(false, false, false, false, 5);
886 List<Constraint> constraints = new LinkedList<Constraint>();
887 CostConstraint costConstraint = new CostConstraint(TE_COST);
Satish K2eb5d842017-04-04 16:28:37 +0530888 PceBandwidthConstraint bwConst = new PceBandwidthConstraint(Bandwidth.bps(3));
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530889 constraints.add(bwConst);
890 constraints.add(costConstraint);
891
Satish K2eb5d842017-04-04 16:28:37 +0530892 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING, null);
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530893
894 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
895 assertThat(tunnels.size(), is(1));
896 boolean result;
897 for (Tunnel tunnel : tunnels) {
898 result = pceManager.releasePath(tunnel.tunnelId());
899 assertThat(result, is(true));
900 }
901 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
902 assertThat(tunnels.size(), is(0));
903 }
904
905 /**
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530906 * Tests tunnel events added and removed.
907 */
908 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530909 public void tunnelEventTest1() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530910 build4RouterTopo(false, true, true, true, 15);
Satish K2eb5d842017-04-04 16:28:37 +0530911 List<Constraint> constraints = new LinkedList<Constraint>();
912 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530913 CostConstraint costConstraint = new CostConstraint(TE_COST);
914
915 constraints.add(costConstraint);
916 constraints.add(bwConstraint);
917
Satish K2eb5d842017-04-04 16:28:37 +0530918 boolean isSuccess = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T1", constraints,
Andrey Komarov2398d962016-09-26 15:11:23 +0300919 SR_WITHOUT_SIGNALLING, null);
Satish K2eb5d842017-04-04 16:28:37 +0530920 assertThat(isSuccess, is(true));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530921
922 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
923
924 for (Tunnel tunnel : tunnels) {
Satish K2eb5d842017-04-04 16:28:37 +0530925 TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530926 tunnelListener.event(event);
927
Satish K2eb5d842017-04-04 16:28:37 +0530928 isSuccess = pceManager.releasePath(tunnel.tunnelId());
929 assertThat(isSuccess, is(true));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530930
931 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel);
932 tunnelListener.event(event);
933 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530934 }
935
936 /**
937 * Tests label allocation/removal in CR case based on tunnel event.
938 */
939 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530940 public void tunnelEventTest2() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530941 build4RouterTopo(false, true, true, true, 15);
Satish K2eb5d842017-04-04 16:28:37 +0530942 List<Constraint> constraints = new LinkedList<Constraint>();
943 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530944 CostConstraint costConstraint = new CostConstraint(TE_COST);
945
946 constraints.add(costConstraint);
947 constraints.add(bwConstraint);
948
Satish K2eb5d842017-04-04 16:28:37 +0530949 boolean isSuccess = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints,
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530950 WITHOUT_SIGNALLING_AND_WITHOUT_SR, null);
Satish K2eb5d842017-04-04 16:28:37 +0530951 assertThat(isSuccess, is(true));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530952
953 TunnelEvent event;
954 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
955 for (Tunnel tunnel : tunnels) {
956 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
957 tunnelListener.event(event);
958
959 // Stimulate the effect of LSP ids from protocol msg.
960 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", ESTABLISHED);
961 }
962
963 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
964 for (Tunnel tunnel : tunnels) {
965 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel);
966 tunnelListener.event(event);
967
Satish K2eb5d842017-04-04 16:28:37 +0530968 isSuccess = pceManager.releasePath(tunnel.tunnelId());
969 assertThat(isSuccess, is(true));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530970
971 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel);
972 tunnelListener.event(event);
973 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530974 }
975
976 /**
977 * Tests handling UNSTABLE state based on tunnel event.
978 */
979 @Test
Satish K2eb5d842017-04-04 16:28:37 +0530980 public void tunnelEventTest3() {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530981 build4RouterTopo(false, true, true, true, 15);
Satish K2eb5d842017-04-04 16:28:37 +0530982 List<Constraint> constraints = new LinkedList<Constraint>();
983 PceBandwidthConstraint bwConstraint = new PceBandwidthConstraint(Bandwidth.bps(10.0));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530984 CostConstraint costConstraint = new CostConstraint(TE_COST);
985
986 constraints.add(costConstraint);
987 constraints.add(bwConstraint);
988
Satish K2eb5d842017-04-04 16:28:37 +0530989 boolean isSuccess = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints,
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530990 WITHOUT_SIGNALLING_AND_WITHOUT_SR, null);
Satish K2eb5d842017-04-04 16:28:37 +0530991 assertThat(isSuccess, is(true));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530992 assertThat(pceStore.getFailedPathInfoCount(), is(0));
993
994 TunnelEvent event;
995 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
996 for (Tunnel tunnel : tunnels) {
997 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
998 tunnelListener.event(event);
999
1000 // Stimulate the effect of LSP ids from protocol msg.
1001 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", UNSTABLE);
1002 }
1003
1004 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
1005 for (Tunnel tunnel : tunnels) {
1006 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel);
1007 tunnelListener.event(event);
1008 }
Satish K2eb5d842017-04-04 16:28:37 +05301009
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301010 assertThat(pceStore.getFailedPathInfoCount(), is(1));
1011 }
1012
Priyanka B3f92c5a2016-05-27 10:14:16 +05301013 /**
Satish K2eb5d842017-04-04 16:28:37 +05301014 * Tests resilency when L2 link is down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301015 */
1016 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301017 public void resilencyTest1() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301018 build4RouterTopo(true, false, false, false, 10);
1019
1020
Satish K2eb5d842017-04-04 16:28:37 +05301021 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301022 CostConstraint costConstraint = new CostConstraint(COST);
1023 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301024 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301025 constraints.add(localBwConst);
1026
1027 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301028 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1029 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301030 assertThat(result, is(true));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301031 assertThat(pceStore.getFailedPathInfoCount(), is(0));
1032
1033 List<Event> reasons = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +05301034 final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301035 reasons.add(linkEvent);
1036 final TopologyEvent event = new TopologyEvent(
1037 TopologyEvent.Type.TOPOLOGY_CHANGED,
1038 topology,
1039 reasons);
1040
1041 //Change Topology : remove link2
1042 Set<TopologyEdge> tempEdges = new HashSet<>();
1043 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
Satish K2eb5d842017-04-04 16:28:37 +05301044 topologyService.changeInTopology(getGraph(null, tempEdges));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301045 listener.event(event);
1046
1047 List<Link> links = new LinkedList<>();
1048 links.add(link3);
1049 links.add(link4);
1050
1051 //Path is D1-D3-D4
1052 assertThat(pathService.paths().iterator().next().links(), is(links));
1053 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1054 }
1055
1056 /**
Satish K2eb5d842017-04-04 16:28:37 +05301057 * Tests resilency when L2 and L4 link is down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301058 */
1059 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301060 public void resilencyTest2() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301061 build4RouterTopo(true, false, false, false, 10);
1062
Satish K2eb5d842017-04-04 16:28:37 +05301063 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301064 CostConstraint costConstraint = new CostConstraint(COST);
1065 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301066 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301067 constraints.add(localBwConst);
1068
1069 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301070 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1071 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301072 assertThat(result, is(true));
1073
1074 List<Event> reasons = new LinkedList<>();
1075 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1076 reasons.add(linkEvent);
1077 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1078 reasons.add(linkEvent);
1079 final TopologyEvent event = new TopologyEvent(
1080 TopologyEvent.Type.TOPOLOGY_CHANGED,
1081 topology,
1082 reasons);
1083
1084 //Change Topology : remove link2 and link4
1085 Set<TopologyEdge> tempEdges = new HashSet<>();
1086 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1087 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
Satish K2eb5d842017-04-04 16:28:37 +05301088 topologyService.changeInTopology(getGraph(null, tempEdges));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301089 listener.event(event);
1090
1091 //No Path
1092 assertThat(pathService.paths().size(), is(0));
1093 }
1094
1095 /**
Satish K2eb5d842017-04-04 16:28:37 +05301096 * Tests resilency when D2 device is down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301097 */
1098 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301099 public void resilencyTest3() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301100 build4RouterTopo(true, false, false, false, 10);
1101
Satish K2eb5d842017-04-04 16:28:37 +05301102 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301103 CostConstraint costConstraint = new CostConstraint(COST);
1104 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301105 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301106 constraints.add(localBwConst);
1107
1108 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301109 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1110 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301111 assertThat(result, is(true));
1112
1113 List<Event> reasons = new LinkedList<>();
1114 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1115 reasons.add(linkEvent);
1116 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1117 reasons.add(linkEvent);
1118 final TopologyEvent event = new TopologyEvent(
1119 TopologyEvent.Type.TOPOLOGY_CHANGED,
1120 topology,
1121 reasons);
1122
1123 //Change Topology : remove link2 and link1
1124 Set<TopologyEdge> tempEdges = new HashSet<>();
1125 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1126 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
Satish K2eb5d842017-04-04 16:28:37 +05301127 topologyService.changeInTopology(getGraph(null, tempEdges));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301128 listener.event(event);
1129
1130 List<Link> links = new LinkedList<>();
1131 links.add(link3);
1132 links.add(link4);
1133
Satish K2eb5d842017-04-04 16:28:37 +05301134 Path path = tunnelService.queryAllTunnels().iterator().next().path();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301135 //Path is D1-D3-D4
Satish K2eb5d842017-04-04 16:28:37 +05301136 assertThat(path.links(), is(links));
1137 assertThat(path.cost(), is((double) 180));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301138 }
1139
1140 /**
Satish K2eb5d842017-04-04 16:28:37 +05301141 * Tests resilency when ingress device is down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301142 */
1143 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301144 public void resilencyTest4() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301145 build4RouterTopo(true, false, false, false, 10);
1146
Satish K2eb5d842017-04-04 16:28:37 +05301147 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301148 CostConstraint costConstraint = new CostConstraint(COST);
1149 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301150 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301151 constraints.add(localBwConst);
1152
1153 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301154 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1155 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301156 assertThat(result, is(true));
1157
1158 List<Event> reasons = new LinkedList<>();
1159 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1160 reasons.add(linkEvent);
1161 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1162 reasons.add(linkEvent);
1163 final TopologyEvent event = new TopologyEvent(
1164 TopologyEvent.Type.TOPOLOGY_CHANGED,
1165 topology,
1166 reasons);
1167
1168 //Change Topology : remove link2 and link1
1169 Set<TopologyEdge> tempEdges = new HashSet<>();
1170 tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
1171 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1172 topologyService.changeInTopology(getGraph(null, tempEdges));
1173 listener.event(event);
1174
1175 //No path
1176 assertThat(pathService.paths().size(), is(0));
1177 }
1178
1179 /**
Satish K2eb5d842017-04-04 16:28:37 +05301180 * Tests resilency when D2 and D3 devices are down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301181 */
1182 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301183 public void resilencyTest5() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301184 build4RouterTopo(true, false, false, false, 10);
1185
Satish K2eb5d842017-04-04 16:28:37 +05301186 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301187 CostConstraint costConstraint = new CostConstraint(COST);
1188 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301189 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301190 constraints.add(localBwConst);
1191
1192 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301193 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1194 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301195 assertThat(result, is(true));
1196
1197 List<Event> reasons = new LinkedList<>();
1198 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1199 reasons.add(linkEvent);
1200 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1201 reasons.add(linkEvent);
1202 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1203 reasons.add(linkEvent);
1204 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1205 reasons.add(linkEvent);
1206
1207 final TopologyEvent event = new TopologyEvent(
1208 TopologyEvent.Type.TOPOLOGY_CHANGED,
1209 topology,
1210 reasons);
1211
1212 //Change Topology : remove device2, device3 and all links
1213 Set<TopologyEdge> tempEdges = new HashSet<>();
1214 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1215 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1216 tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
1217 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1218 Set<TopologyVertex> tempVertexes = new HashSet<>();
1219 tempVertexes.add(D2);
1220 tempVertexes.add(D3);
1221 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1222 listener.event(event);
1223
1224 //No path
1225 assertThat(pathService.paths().size(), is(0));
1226 }
1227
1228 /**
Satish K2eb5d842017-04-04 16:28:37 +05301229 * Tests resilency when egress device is down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301230 */
1231 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301232 public void resilencyTest6() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301233 build4RouterTopo(true, false, false, false, 10);
1234
Satish K2eb5d842017-04-04 16:28:37 +05301235 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301236 CostConstraint costConstraint = new CostConstraint(COST);
1237 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301238 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301239 constraints.add(localBwConst);
1240
1241 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301242 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1243 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301244 assertThat(result, is(true));
1245
1246 List<Event> reasons = new LinkedList<>();
1247 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1248 reasons.add(linkEvent);
1249 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1250 reasons.add(linkEvent);
1251
1252 final TopologyEvent event = new TopologyEvent(
1253 TopologyEvent.Type.TOPOLOGY_CHANGED,
1254 topology,
1255 reasons);
1256
1257 //Change Topology : remove device4 , link2 and link4
1258 Set<TopologyEdge> tempEdges = new HashSet<>();
1259 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1260 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1261 Set<TopologyVertex> tempVertexes = new HashSet<>();
1262 tempVertexes.add(D4);
1263 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1264 listener.event(event);
1265
1266 //No path
1267 assertThat(pathService.paths().size(), is(0));
1268 }
1269
1270 /**
Satish K2eb5d842017-04-04 16:28:37 +05301271 * Tests resilency when egress device is down.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301272 */
1273 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301274 public void resilencyTest7() {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301275 build4RouterTopo(true, false, false, false, 10);
1276
Satish K2eb5d842017-04-04 16:28:37 +05301277 List<Constraint> constraints = new LinkedList<Constraint>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301278 CostConstraint costConstraint = new CostConstraint(COST);
1279 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301280 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301281 constraints.add(localBwConst);
1282
1283 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301284 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1285 constraints, WITH_SIGNALLING, null);
1286 assertThat(result, is(true));
1287
1288 List<Event> reasons = new LinkedList<>();
1289 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1290 reasons.add(linkEvent);
1291 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1292 reasons.add(linkEvent);
1293
1294 final TopologyEvent event = new TopologyEvent(
1295 TopologyEvent.Type.TOPOLOGY_CHANGED,
1296 topology,
1297 reasons);
1298
1299 //Change Topology : remove device4 , link2 and link4
1300 Set<TopologyEdge> tempEdges = new HashSet<>();
1301 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1302 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1303 Set<TopologyVertex> tempVertexes = new HashSet<>();
1304 tempVertexes.add(D4);
1305 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1306 listener.event(event);
1307
1308 //No path
1309 assertThat(pathService.paths().size(), is(0));
1310 }
1311
1312 /**
1313 * Tests resilency when D2 device is suspended.
1314 */
1315 @Test
1316 public void resilencyTest8() {
1317 build4RouterTopo(true, false, false, false, 10);
1318
1319 List<Constraint> constraints = new LinkedList<Constraint>();
1320 CostConstraint costConstraint = new CostConstraint(COST);
1321 constraints.add(costConstraint);
1322 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
1323 constraints.add(localBwConst);
1324
1325 //Setup the path , tunnel created
1326 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1327 constraints, WITH_SIGNALLING, null);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301328 assertThat(result, is(true));
1329
1330 List<Event> reasons = new LinkedList<>();
1331 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1332 reasons.add(linkEvent);
1333 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1334 reasons.add(linkEvent);
1335
1336 final TopologyEvent event = new TopologyEvent(
1337 TopologyEvent.Type.TOPOLOGY_CHANGED,
1338 topology,
1339 reasons);
1340
1341 //Change Topology : remove device2 , link1 and link2
1342 Set<TopologyEdge> tempEdges = new HashSet<>();
1343 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1344 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1345 Set<TopologyVertex> tempVertexes = new HashSet<>();
1346 tempVertexes.add(D2);
1347 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1348 listener.event(event);
1349
1350 List<Link> links = new LinkedList<>();
1351 links.add(link3);
1352 links.add(link4);
1353
Satish K2eb5d842017-04-04 16:28:37 +05301354 Path path = tunnelService.queryAllTunnels().iterator().next().path();
1355
Priyanka B3f92c5a2016-05-27 10:14:16 +05301356 //Path is D1-D3-D4
Satish K2eb5d842017-04-04 16:28:37 +05301357 assertThat(path.links(), is(links));
1358 assertThat(path.cost(), is((double) 180));
1359 }
1360
1361 /**
1362 * Tests resilency when D2 device availability is changed.
1363 */
1364 @Test
1365 public void resilencyTest11() {
1366 build4RouterTopo(true, false, false, false, 10);
1367
1368 List<Constraint> constraints = new LinkedList<Constraint>();
1369 CostConstraint costConstraint = new CostConstraint(COST);
1370 constraints.add(costConstraint);
1371 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
1372 constraints.add(localBwConst);
1373
1374 //Setup the path , tunnel created
1375 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1376 constraints, WITH_SIGNALLING, null);
1377 assertThat(result, is(true));
1378
1379 List<Event> reasons = new LinkedList<>();
1380 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1381 reasons.add(linkEvent);
1382 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1383 reasons.add(linkEvent);
1384
1385 final TopologyEvent event = new TopologyEvent(
1386 TopologyEvent.Type.TOPOLOGY_CHANGED,
1387 topology,
1388 reasons);
1389
1390 //Change Topology : remove device2 , link1 and link2
1391 Set<TopologyEdge> tempEdges = new HashSet<>();
1392 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1393 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1394 Set<TopologyVertex> tempVertexes = new HashSet<>();
1395 tempVertexes.add(D2);
1396 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1397 listener.event(event);
1398
1399 List<Link> links = new LinkedList<>();
1400 links.add(link3);
1401 links.add(link4);
1402
1403 Path path = tunnelService.queryAllTunnels().iterator().next().path();
1404
1405 //Path is D1-D3-D4
1406 assertThat(path.links(), is(links));
1407 assertThat(path.cost(), is((double) 180));
Priyanka B3f92c5a2016-05-27 10:14:16 +05301408 }
1409
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301410 /**
1411 * Tests resilency when link2 availability is changed.
1412 */
1413 @Test
Satish K2eb5d842017-04-04 16:28:37 +05301414 public void resilencyTest12() {
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301415 build4RouterTopo(true, false, false, false, 10);
1416
1417 List<Constraint> constraints = new LinkedList<Constraint>();
1418 CostConstraint costConstraint = new CostConstraint(COST);
1419 constraints.add(costConstraint);
Satish K2eb5d842017-04-04 16:28:37 +05301420 PceBandwidthConstraint localBwConst = new PceBandwidthConstraint(Bandwidth.bps(10));
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301421 constraints.add(localBwConst);
1422
1423 List<ExplicitPathInfo> explicitPathInfoList = Lists.newLinkedList();
Satish K2eb5d842017-04-04 16:28:37 +05301424 ExplicitPathInfo obj = new ExplicitPathInfo(ExplicitPathInfo.Type.LOOSE, link1);
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301425 explicitPathInfoList.add(obj);
1426 obj = new ExplicitPathInfo(ExplicitPathInfo.Type.STRICT, D2.deviceId());
1427 explicitPathInfoList.add(obj);
1428
1429 //Setup the path , tunnel created
Satish K2eb5d842017-04-04 16:28:37 +05301430 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123",
1431 constraints, WITH_SIGNALLING, explicitPathInfoList);
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301432 assertThat(result, is(true));
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301433 assertThat(pceStore.getFailedPathInfoCount(), is(0));
1434
1435 List<Event> reasons = new LinkedList<>();
Satish K2eb5d842017-04-04 16:28:37 +05301436 final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
Priyanka Bbae0eeb12016-11-30 11:59:48 +05301437 reasons.add(linkEvent);
1438 final TopologyEvent event = new TopologyEvent(
1439 TopologyEvent.Type.TOPOLOGY_CHANGED,
1440 topology,
1441 reasons);
1442
1443 //Change Topology : remove link2
1444 Set<TopologyEdge> tempEdges = new HashSet<>();
1445 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1446 topologyService.changeInTopology(getGraph(null, tempEdges));
1447 listener.event(event);
1448
1449 List<Link> links = new LinkedList<>();
1450 links.add(link3);
1451 links.add(link4);
1452
1453 //Path fails - no alternate path
1454 assertThat(pathService.paths().iterator().hasNext(), is(false));
1455 }
1456
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301457 @After
1458 public void tearDown() {
1459 pceManager.deactivate();
1460 pceManager.pathService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301461 pceManager.tunnelService = null;
1462 pceManager.coreService = null;
1463 pceManager.storageService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301464 pceManager.deviceService = null;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301465 pceManager.netCfgService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301466 pceManager.pceStore = null;
Priyanka B3f92c5a2016-05-27 10:14:16 +05301467 pceManager.topologyService = null;
1468 pceManager.mastershipService = null;
Satish K2eb5d842017-04-04 16:28:37 +05301469 flowsDownloaded = 0;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301470 }
1471
1472 private class MockTopologyService extends TopologyServiceAdapter {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301473 private void changeInTopology(TopologyGraph graphModified) {
1474 graph = graphModified;
1475 }
1476
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301477 @Override
Ray Milkey7483e1b2018-02-07 15:43:01 -08001478 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeigher weight) {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301479 DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
1480 DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
1481 Set<TopologyVertex> vertices = graph.getVertexes();
1482 if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
1483 // src or dst not part of the current graph
1484 return ImmutableSet.of();
1485 }
1486
Satish K2eb5d842017-04-04 16:28:37 +05301487 GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = PathComputationTest.graphSearch()
Ray Milkey7483e1b2018-02-07 15:43:01 -08001488 .search(graph, srcV, dstV, weight, ALL_PATHS);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301489 ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
1490 for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
1491 builder.add(PathComputationTest.networkPath(path));
1492 }
1493 return builder.build();
1494 }
1495 }
1496
Satish K2eb5d842017-04-04 16:28:37 +05301497 private TopologyGraph getGraph(Set<TopologyVertex> removedVertex, Set<TopologyEdge> removedEdges) {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301498 if (removedVertex != null) {
Satish K2eb5d842017-04-04 16:28:37 +05301499 vertexes.remove(removedVertex);
1500 removedVertex.forEach(new Consumer<TopologyVertex>() {
1501 @Override
1502 public void accept(TopologyVertex v) {
1503 vertexes.remove(v);
1504 }
1505 });
Priyanka B3f92c5a2016-05-27 10:14:16 +05301506 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301507
Priyanka B3f92c5a2016-05-27 10:14:16 +05301508 if (removedEdges != null) {
Satish K2eb5d842017-04-04 16:28:37 +05301509 removedEdges.forEach(new Consumer<TopologyEdge>() {
1510 @Override
1511 public void accept(TopologyEdge e) {
1512 edges.remove(e);
1513 }
1514 });
Priyanka B3f92c5a2016-05-27 10:14:16 +05301515 }
1516
1517 return new DefaultTopologyGraph(vertexes, edges);
1518 }
1519
1520 private class MockPathService extends PathServiceAdapter {
1521 Set<Path> computedPaths;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301522 @Override
Ray Milkey7483e1b2018-02-07 15:43:01 -08001523 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeigher weight) {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301524 // If either edge is null, bail with no paths.
1525 if (src == null || dst == null) {
1526 return ImmutableSet.of();
1527 }
1528
1529 // Otherwise get all paths between the source and destination edge
1530 // devices.
Satish K2eb5d842017-04-04 16:28:37 +05301531 computedPaths = topologyService.getPaths(null, (DeviceId) src, (DeviceId) dst, weight);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301532 return computedPaths;
1533 }
1534
1535 private Set<Path> paths() {
1536 return computedPaths;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301537 }
1538 }
1539
1540 private class MockTunnelServiceAdapter extends TunnelServiceAdapter {
Satish K2eb5d842017-04-04 16:28:37 +05301541 private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<TunnelId, Tunnel>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301542 private int tunnelIdCounter = 0;
1543
1544 @Override
Satish K2eb5d842017-04-04 16:28:37 +05301545 public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301546 TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
Satish K2eb5d842017-04-04 16:28:37 +05301547 Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(),
1548 tunnel.state(), tunnel.groupId(), tunnelId, tunnel.tunnelName(),
1549 path, tunnel.annotations());
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301550 tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert);
1551 return tunnelId;
1552 }
1553
1554 @Override
1555 public void addListener(TunnelListener listener) {
1556 tunnelListener = listener;
1557 }
1558
1559 /**
Satish K2eb5d842017-04-04 16:28:37 +05301560 * Stimulates the effect of receiving PLSP id and LSP id from protocol PCRpt msg.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301561 */
Satish K2eb5d842017-04-04 16:28:37 +05301562 public TunnelId updateTunnelWithLspIds(Tunnel tunnel, String pLspId, String localLspId, State state) {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301563 TunnelId tunnelId = tunnel.tunnelId();
1564 Builder annotationBuilder = DefaultAnnotations.builder();
1565 annotationBuilder.putAll(tunnel.annotations());
1566
Satish K2eb5d842017-04-04 16:28:37 +05301567 // PCRpt in response to PCInitate msg will carry PLSP id allocated by PCC.
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301568 if (tunnel.annotations().value(PLSP_ID) == null) {
1569 annotationBuilder.set(PLSP_ID, pLspId);
1570 }
1571
Satish K2eb5d842017-04-04 16:28:37 +05301572 // Signalled LSPs will carry local LSP id allocated by signalling protocol(PCC).
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301573 if (tunnel.annotations().value(LOCAL_LSP_ID) == null) {
1574 annotationBuilder.set(LOCAL_LSP_ID, localLspId);
1575 }
1576 SparseAnnotations annotations = annotationBuilder.build();
1577 tunnelIdAsKeyStore.remove(tunnelId, tunnel);
1578
Satish K2eb5d842017-04-04 16:28:37 +05301579 Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(),
1580 state, tunnel.groupId(), tunnelId, tunnel.tunnelName(),
1581 tunnel.path(), annotations);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301582
1583 tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert);
1584
1585 return tunnelId;
1586 }
1587
1588 @Override
1589 public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) {
1590 for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) {
1591 if (tunnelIdKey.equals(tunnelId)) {
1592 tunnelIdAsKeyStore.remove(tunnelId);
1593 return true;
1594 }
1595 }
1596 return false;
1597 }
1598
1599 @Override
1600 public Tunnel queryTunnel(TunnelId tunnelId) {
1601 for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) {
1602 if (tunnelIdKey.equals(tunnelId)) {
1603 return tunnelIdAsKeyStore.get(tunnelId);
1604 }
1605 }
1606 return null;
1607 }
1608
1609 @Override
Satish K2eb5d842017-04-04 16:28:37 +05301610 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
1611 Collection<Tunnel> result = new HashSet<Tunnel>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301612 Tunnel tunnel = null;
1613 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1614 tunnel = tunnelIdAsKeyStore.get(tunnelId);
1615
Satish K2eb5d842017-04-04 16:28:37 +05301616 if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301617 result.add(tunnel);
1618 }
1619 }
1620
Satish K2eb5d842017-04-04 16:28:37 +05301621 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301622 }
1623
1624 @Override
1625 public Collection<Tunnel> queryTunnel(Tunnel.Type type) {
Satish K2eb5d842017-04-04 16:28:37 +05301626 Collection<Tunnel> result = new HashSet<Tunnel>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301627
1628 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1629 result.add(tunnelIdAsKeyStore.get(tunnelId));
1630 }
1631
Satish K2eb5d842017-04-04 16:28:37 +05301632 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301633 }
Priyanka B3f92c5a2016-05-27 10:14:16 +05301634
1635 @Override
1636 public Collection<Tunnel> queryAllTunnels() {
Satish K2eb5d842017-04-04 16:28:37 +05301637 Collection<Tunnel> result = new HashSet<Tunnel>();
Priyanka B3f92c5a2016-05-27 10:14:16 +05301638
1639 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1640 result.add(tunnelIdAsKeyStore.get(tunnelId));
1641 }
1642
Satish K2eb5d842017-04-04 16:28:37 +05301643 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
Priyanka B3f92c5a2016-05-27 10:14:16 +05301644 }
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301645
Priyanka B3f92c5a2016-05-27 10:14:16 +05301646 @Override
1647 public Iterable<Tunnel> getTunnels(DeviceId deviceId) {
1648 List<Tunnel> tunnelList = new LinkedList<>();
1649
1650 for (Tunnel t : tunnelIdAsKeyStore.values()) {
1651 for (Link l : t.path().links()) {
Satish K2eb5d842017-04-04 16:28:37 +05301652 if (l.src().deviceId().equals(deviceId) || l.dst().deviceId().equals(deviceId)) {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301653 tunnelList.add(t);
1654 break;
1655 }
1656 }
1657 }
1658 return tunnelList;
1659 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301660 }
1661
1662 public static class MockCoreService extends CoreServiceAdapter {
1663
1664 @Override
1665 public ApplicationId registerApplication(String name) {
1666 return new DefaultApplicationId(1, name);
1667 }
1668
1669 @Override
1670 public IdGenerator getIdGenerator(String topic) {
1671 return new IdGenerator() {
1672 private AtomicLong counter = new AtomicLong(0);
1673
1674 @Override
1675 public long getNewId() {
1676 return counter.getAndIncrement();
1677 }
1678 };
1679 }
1680 }
1681
1682 private class MockDevice extends DefaultDevice {
1683 MockDevice(DeviceId id, Annotations annotations) {
1684 super(null, id, null, null, null, null, null, null, annotations);
1685 }
1686 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301687}