blob: 6962b49896f659688bc45914492022348fb6d232 [file] [log] [blame]
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301package org.onosproject.pce.pceservice;
2
3import static org.hamcrest.MatcherAssert.assertThat;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05304import static org.hamcrest.Matchers.notNullValue;
5import static org.hamcrest.Matchers.nullValue;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05306import static org.hamcrest.core.Is.is;
7import static org.onlab.graph.GraphPathSearch.ALL_PATHS;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05308import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED;
9import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053010import static org.onosproject.net.Link.State.ACTIVE;
11import static org.onosproject.net.Link.Type.DIRECT;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053012import static org.onosproject.net.MastershipRole.MASTER;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053013import static org.onosproject.net.resource.Resources.continuous;
14import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING;
15import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
16import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING;
17import static org.onosproject.pce.pceservice.PathComputationTest.D1;
18import static org.onosproject.pce.pceservice.PathComputationTest.D2;
19import static org.onosproject.pce.pceservice.PathComputationTest.D3;
20import static org.onosproject.pce.pceservice.PathComputationTest.D4;
Priyanka B3f92c5a2016-05-27 10:14:16 +053021import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE1;
22import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2;
23import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3;
24import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053025import static org.onosproject.pce.pceservice.PceManager.PCEP_PORT;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053026import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID;
27import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053028import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST;
29import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053030
31import java.net.URISyntaxException;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053032import java.util.Collection;
33import java.util.Collections;
34import java.util.HashMap;
35import java.util.HashSet;
36import java.util.LinkedList;
37import java.util.List;
38import java.util.Set;
39import java.util.concurrent.atomic.AtomicLong;
40
41import org.junit.After;
42import org.junit.Before;
43import org.junit.Test;
44import org.onlab.graph.GraphPathSearch;
Priyanka B3f92c5a2016-05-27 10:14:16 +053045import org.onlab.junit.TestUtils;
46import org.onlab.junit.TestUtils.TestUtilsException;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053047import org.onlab.packet.Ethernet;
48import org.onlab.packet.IPv4;
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +053049import org.onlab.packet.TCP;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053050import org.onlab.util.Bandwidth;
51import org.onosproject.common.DefaultTopologyGraph;
52import org.onosproject.core.ApplicationId;
53import org.onosproject.core.CoreServiceAdapter;
54import org.onosproject.core.DefaultApplicationId;
55import org.onosproject.core.IdGenerator;
Priyanka B3f92c5a2016-05-27 10:14:16 +053056import org.onosproject.event.Event;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053057import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053058import org.onosproject.incubator.net.resource.label.LabelResourceId;
59import org.onosproject.incubator.net.resource.label.LabelResourceService;
60import org.onosproject.incubator.net.tunnel.DefaultTunnel;
61import org.onosproject.incubator.net.tunnel.Tunnel;
62import org.onosproject.incubator.net.tunnel.Tunnel.State;
63import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
64import org.onosproject.incubator.net.tunnel.TunnelEvent;
65import org.onosproject.incubator.net.tunnel.TunnelId;
66import org.onosproject.incubator.net.tunnel.TunnelListener;
Priyanka B3f92c5a2016-05-27 10:14:16 +053067import org.onosproject.mastership.MastershipServiceAdapter;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053068import org.onosproject.net.AnnotationKeys;
69import org.onosproject.net.Annotations;
70import org.onosproject.net.ConnectPoint;
71import org.onosproject.net.DefaultAnnotations;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053072import org.onosproject.net.DefaultAnnotations.Builder;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053073import org.onosproject.net.DefaultDevice;
74import org.onosproject.net.DefaultLink;
75import org.onosproject.net.Device;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053076import org.onosproject.net.DeviceId;
77import org.onosproject.net.ElementId;
78import org.onosproject.net.Link;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053079import org.onosproject.net.MastershipRole;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053080import org.onosproject.net.Path;
81import org.onosproject.net.PortNumber;
82import org.onosproject.net.SparseAnnotations;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053083import org.onosproject.net.device.DeviceEvent;
84import org.onosproject.net.device.DeviceListener;
85import org.onosproject.net.flowobjective.ForwardingObjective;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053086import org.onosproject.net.intent.Constraint;
87import org.onosproject.net.intent.IntentId;
88import org.onosproject.net.intent.constraint.BandwidthConstraint;
Priyanka B3f92c5a2016-05-27 10:14:16 +053089import org.onosproject.net.link.LinkEvent;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053090import org.onosproject.net.link.LinkListener;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053091import org.onosproject.net.packet.DefaultInboundPacket;
92import org.onosproject.net.packet.DefaultPacketContext;
93import org.onosproject.net.packet.InboundPacket;
94import org.onosproject.net.packet.OutboundPacket;
95import org.onosproject.net.packet.PacketProcessor;
96import org.onosproject.net.packet.PacketService;
97import org.onosproject.net.packet.PacketServiceAdapter;
98import org.onosproject.net.provider.ProviderId;
99import org.onosproject.net.resource.Resource;
100import org.onosproject.net.topology.DefaultTopologyEdge;
101import org.onosproject.net.topology.DefaultTopologyVertex;
102import org.onosproject.net.topology.LinkWeight;
103import org.onosproject.net.topology.PathServiceAdapter;
104import org.onosproject.net.topology.Topology;
105import org.onosproject.net.topology.TopologyEdge;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530106import org.onosproject.net.topology.TopologyEvent;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530107import org.onosproject.net.topology.TopologyGraph;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530108import org.onosproject.net.topology.TopologyListener;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530109import org.onosproject.net.topology.TopologyServiceAdapter;
110import org.onosproject.net.topology.TopologyVertex;
Avantika-Huawei032a9872016-05-27 22:57:38 +0530111import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530112import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService;
113import org.onosproject.pce.pceservice.constraint.CostConstraint;
114import org.onosproject.pce.pcestore.api.PceStore;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530115import org.onosproject.pce.util.FlowObjServiceAdapter;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530116import org.onosproject.pce.util.LabelResourceAdapter;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530117import org.onosproject.pce.util.MockDeviceService;
118import org.onosproject.pce.util.MockLinkService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530119import org.onosproject.pce.util.PceStoreAdapter;
120import org.onosproject.pce.util.TunnelServiceAdapter;
Avantika-Huawei032a9872016-05-27 22:57:38 +0530121import org.onosproject.pcep.api.DeviceCapability;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530122import org.onosproject.store.service.TestStorageService;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530123
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530124import com.google.common.collect.ImmutableSet;
125
126/**
127 * Tests the functions of PceManager.
128 */
129public class PceManagerTest {
130
131 private PathComputationTest pathCompTest = new PathComputationTest();
132 private MockPathResourceService resourceService = pathCompTest.new MockPathResourceService();
133 private MockTopologyService topologyService = new MockTopologyService();
Priyanka B3f92c5a2016-05-27 10:14:16 +0530134 private MockMastershipService mastershipService = new MockMastershipService();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530135 private MockPathService pathService = new MockPathService();
136 private PceManager pceManager = new PceManager();
137 private MockCoreService coreService = new MockCoreService();
138 private MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
139 private TestStorageService storageService = new TestStorageService();
140 private PacketService packetService = new MockPacketService();
141 private MockDeviceService deviceService = new MockDeviceService();
Avantika-Huawei032a9872016-05-27 22:57:38 +0530142 private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter();
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530143 private MockLinkService linkService = new MockLinkService();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530144 private MockFlowObjService flowObjectiveService = new MockFlowObjService();
145 private PceStore pceStore = new PceStoreAdapter();
146 private LabelResourceService labelResourceService = new LabelResourceAdapter();
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530147 private LabelResourceAdminService labelRsrcAdminService = new LabelResourceAdapter();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530148
149 public static ProviderId providerId = new ProviderId("pce", "foo");
150 private static final String L3 = "L3";
151 private static final String LSRID = "lsrId";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530152 private static final String PCECC_CAPABILITY = "pceccCapability";
153 private static final String SR_CAPABILITY = "srCapability";
154 private static final String LABEL_STACK_CAPABILITY = "labelStackCapability";
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530155
156 private TopologyGraph graph = null;
157 private Device deviceD1, deviceD2, deviceD3, deviceD4;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530158 private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530159 private Link link1, link2, link3, link4;
Priyanka B413fbe82016-05-26 11:44:45 +0530160 protected static int flowsDownloaded;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530161 private TunnelListener tunnelListener;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530162 private TopologyListener listener;
163 private Topology topology;
164 private Set<TopologyEdge> edges;
165 private Set<TopologyVertex> vertexes;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530166
167 @Before
Priyanka B3f92c5a2016-05-27 10:14:16 +0530168 public void startUp() throws TestUtilsException {
169 listener = TestUtils.getField(pceManager, "topologyListener");
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530170 pceManager.pathService = pathService;
171 pceManager.resourceService = resourceService;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530172 pceManager.topologyService = topologyService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530173 pceManager.tunnelService = tunnelService;
174 pceManager.coreService = coreService;
175 pceManager.storageService = storageService;
176 pceManager.packetService = packetService;
177 pceManager.deviceService = deviceService;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530178 pceManager.linkService = linkService;
Avantika-Huawei032a9872016-05-27 22:57:38 +0530179 pceManager.netCfgService = netConfigRegistry;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530180 pceManager.labelRsrcAdminService = labelRsrcAdminService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530181 pceManager.labelRsrcService = labelResourceService;
182 pceManager.flowObjectiveService = flowObjectiveService;
183 pceManager.pceStore = pceStore;
Priyanka B3f92c5a2016-05-27 10:14:16 +0530184 pceManager.mastershipService = mastershipService;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530185 pceManager.activate();
186 }
187
Priyanka B3f92c5a2016-05-27 10:14:16 +0530188 private class MockMastershipService extends MastershipServiceAdapter {
189 @Override
190 public MastershipRole getLocalRole(DeviceId deviceId) {
191 return MASTER;
192 }
193
194 @Override
195 public boolean isLocalMaster(DeviceId deviceId) {
196 return getLocalRole(deviceId) == MASTER;
197 }
198 }
199
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530200 private void build4RouterTopo(boolean setCost, boolean setPceccCap, boolean setSrCap,
201 boolean setLabelStackCap, int bandwidth) {
Priyanka B3f92c5a2016-05-27 10:14:16 +0530202 link1 = PathComputationTest.addLink(DEVICE1, 10, DEVICE2, 20, setCost, 50);
203 link2 = PathComputationTest.addLink(DEVICE2, 30, DEVICE4, 40, setCost, 20);
204 link3 = PathComputationTest.addLink(DEVICE1, 80, DEVICE3, 70, setCost, 100);
205 link4 = PathComputationTest.addLink(DEVICE3, 60, DEVICE4, 50, setCost, 80);
206
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530207 Set<TopologyVertex> vertexes = new HashSet<TopologyVertex>();
208 vertexes.add(D1);
209 vertexes.add(D2);
210 vertexes.add(D3);
211 vertexes.add(D4);
212
Priyanka B3f92c5a2016-05-27 10:14:16 +0530213 this.vertexes = vertexes;
214
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530215 Set<TopologyEdge> edges = new HashSet<TopologyEdge>();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530216 TopologyEdge edge1 = new DefaultTopologyEdge(D1, D2, link1);
217 edges.add(edge1);
218
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530219 TopologyEdge edge2 = new DefaultTopologyEdge(D2, D4, link2);
220 edges.add(edge2);
221
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530222 TopologyEdge edge3 = new DefaultTopologyEdge(D1, D3, link3);
223 edges.add(edge3);
224
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530225 TopologyEdge edge4 = new DefaultTopologyEdge(D3, D4, link4);
226 edges.add(edge4);
227
Priyanka B3f92c5a2016-05-27 10:14:16 +0530228 this.edges = edges;
229
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530230 graph = new DefaultTopologyGraph(vertexes, edges);
231
232 DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
233 DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder();
234 DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder();
235 DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder();
236
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530237 // Making L3 devices
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530238 builderDev1.set(AnnotationKeys.TYPE, L3);
239 builderDev1.set(LSRID, "1.1.1.1");
240
241 builderDev2.set(AnnotationKeys.TYPE, L3);
242 builderDev2.set(LSRID, "2.2.2.2");
243
244 builderDev3.set(AnnotationKeys.TYPE, L3);
245 builderDev3.set(LSRID, "3.3.3.3");
246
247 builderDev4.set(AnnotationKeys.TYPE, L3);
248 builderDev4.set(LSRID, "4.4.4.4");
249
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530250 deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build());
251 deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build());
252 deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build());
253 deviceD4 = new MockDevice(D4.deviceId(), builderDev4.build());
254
255 deviceService.addDevice(deviceD1);
256 deviceService.addDevice(deviceD2);
257 deviceService.addDevice(deviceD3);
258 deviceService.addDevice(deviceD4);
259
Avantika-Huawei032a9872016-05-27 22:57:38 +0530260 DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
261 device1Cap.setLabelStackCap(setLabelStackCap)
262 .setLocalLabelCap(setPceccCap)
263 .setSrCap(setSrCap)
264 .apply();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530265
Avantika-Huawei032a9872016-05-27 22:57:38 +0530266 DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
267 device2Cap.setLabelStackCap(setLabelStackCap)
268 .setLocalLabelCap(setPceccCap)
269 .setSrCap(setSrCap)
270 .apply();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530271
Avantika-Huawei032a9872016-05-27 22:57:38 +0530272 DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
273 device3Cap.setLabelStackCap(setLabelStackCap)
274 .setLocalLabelCap(setPceccCap)
275 .setSrCap(setSrCap)
276 .apply();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530277
Avantika-Huawei032a9872016-05-27 22:57:38 +0530278 DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
279 device4Cap.setLabelStackCap(setLabelStackCap)
280 .setLocalLabelCap(setPceccCap)
281 .setSrCap(setSrCap)
282 .apply();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530283
284 if (bandwidth != 0) {
285 List<Resource> resources = new LinkedList<>();
286 resources.add(continuous(link1.src().deviceId(), link1.src().port(), Bandwidth.class).resource(bandwidth));
287 resources.add(continuous(link2.src().deviceId(), link2.src().port(), Bandwidth.class).resource(bandwidth));
288 resources.add(continuous(link3.src().deviceId(), link3.src().port(), Bandwidth.class).resource(bandwidth));
289 resources.add(continuous(link4.src().deviceId(), link4.src().port(), Bandwidth.class).resource(bandwidth));
290
291 resources.add(continuous(link1.dst().deviceId(), link1.dst().port(), Bandwidth.class).resource(bandwidth));
292 resources.add(continuous(link2.dst().deviceId(), link2.dst().port(), Bandwidth.class).resource(bandwidth));
293 resources.add(continuous(link3.dst().deviceId(), link3.dst().port(), Bandwidth.class).resource(bandwidth));
294 resources.add(continuous(link4.dst().deviceId(), link4.dst().port(), Bandwidth.class).resource(bandwidth));
295
296 resourceService.allocate(IntentId.valueOf(bandwidth), resources);
297 }
298 }
299
300 /**
301 * Tests path success with (IGP) cost constraint for signalled LSP.
302 */
303 @Test
304 public void setupPathTest1() {
305 build4RouterTopo(true, false, false, false, 0); // IGP cost is set here.
306 List<Constraint> constraints = new LinkedList<Constraint>();
307 CostConstraint costConstraint = new CostConstraint(COST);
308 constraints.add(costConstraint);
309
310 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
311 assertThat(result, is(true));
312 }
313
314 /**
315 * Tests path failure with (IGP) cost constraint for signalled LSP.
316 */
317 @Test
318 public void setupPathTest2() {
319 build4RouterTopo(false, false, false, false, 0); // TE cost is set here, not IGP.
320 List<Constraint> constraints = new LinkedList<Constraint>();
321 CostConstraint costConstraint = new CostConstraint(COST);
322 constraints.add(costConstraint);
323
324 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
325 assertThat(result, is(false));
326 }
327
328 /**
329 * Tests path success with TE-cost constraint for signalled LSP.
330 */
331 @Test
332 public void setupPathTest3() {
333 build4RouterTopo(false, false, false, false, 0); // TE cost is set here.
334
335 List<Constraint> constraints = new LinkedList<Constraint>();
336 CostConstraint costConstraint = new CostConstraint(TE_COST);
337 constraints.add(costConstraint);
338
339 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
340 assertThat(result, is(true));
341 }
342
343 /**
344 * Tests path failure with TE-cost constraint for signalled LSP.
345 */
346 @Test
347 public void setupPathTest4() {
348 build4RouterTopo(true, false, false, false, 0); // IGP cost is set here, not TE.
349
350 List<Constraint> constraints = new LinkedList<Constraint>();
351 CostConstraint costConstraint = new CostConstraint(TE_COST);
352 constraints.add(costConstraint);
353
354 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
355 assertThat(result, is(false));
356 }
357
358 /**
359 * Tests path success with (IGP) cost constraint for non-SR non-signalled LSP.
360 */
361 @Test
362 public void setupPathTest5() {
363 build4RouterTopo(true, true, false, false, 0);
364
365 List<Constraint> constraints = new LinkedList<Constraint>();
366 CostConstraint costConstraint = new CostConstraint(COST);
367 constraints.add(costConstraint);
368
369 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
370 WITHOUT_SIGNALLING_AND_WITHOUT_SR);
371 assertThat(result, is(true));
372 }
373
374 /**
375 * Tests path success with TE-cost constraint for non-SR non-sgnalled LSP.
376 */
377 @Test
378 public void setupPathTest6() {
379 build4RouterTopo(false, true, false, false, 0);
380
381 List<Constraint> constraints = new LinkedList<Constraint>();
382 CostConstraint costConstraint = new CostConstraint(TE_COST);
383 constraints.add(costConstraint);
384
385 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
386 WITHOUT_SIGNALLING_AND_WITHOUT_SR);
387 assertThat(result, is(true));
388 }
389
390 /**
391 * Tests path failure with TE-cost constraint for non-SR non-signalled LSP(CR). Label capability not registered.
392 */
393 @Test
394 public void setupPathTest7() {
395 build4RouterTopo(true, false, false, false, 0);
396
397 List<Constraint> constraints = new LinkedList<Constraint>();
398 CostConstraint costConstraint = new CostConstraint(TE_COST);
399 constraints.add(costConstraint);
400
401 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints,
402 WITHOUT_SIGNALLING_AND_WITHOUT_SR);
403 assertThat(result, is(false));
404 }
405
406 /**
407 * Tests path failure as bandwidth is requested but is not registered.
408 */
409 @Test
410 public void setupPathTest8() {
411 build4RouterTopo(true, false, false, false, 0);
412 List<Constraint> constraints = new LinkedList<Constraint>();
413 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
414 CostConstraint costConstraint = new CostConstraint(TE_COST);
415
416 constraints.add(costConstraint);
417 constraints.add(bwConstraint);
418
419 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
420 assertThat(result, is(false));
421 }
422
423 /**
424 * Tests path failure as bandwidth requested is more than registered.
425 */
426 @Test
427 public void setupPathTest9() {
428 build4RouterTopo(false, false, false, false, 5);
429 List<Constraint> constraints = new LinkedList<Constraint>();
430 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
431 CostConstraint costConstraint = new CostConstraint(TE_COST);
432
433 constraints.add(costConstraint);
434 constraints.add(bwConstraint);
435
436 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
437 assertThat(result, is(false));
438 }
439
440 /**
441 * Tests path setup failure(without signalling). Label capability is not present.
442 */
443 @Test
444 public void setupPathTest10() {
445 build4RouterTopo(false, false, false, false, 0);
446 List<Constraint> constraints = new LinkedList<Constraint>();
447 CostConstraint costConstraint = new CostConstraint(TE_COST);
448 constraints.add(costConstraint);
449
450 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING);
451 assertThat(result, is(false));
452 }
453
454 /**
455 * Tests path setup without failure for LSP with signalling and with bandwidth reservation.
456 */
457 @Test
458 public void setupPathTest11() {
459 build4RouterTopo(false, true, true, true, 15);
460 List<Constraint> constraints = new LinkedList<Constraint>();
461 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
462 CostConstraint costConstraint = new CostConstraint(TE_COST);
463
464 constraints.add(costConstraint);
465 constraints.add(bwConstraint);
466
467 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
468 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
469
470 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
471 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
472
473 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING);
474 assertThat(result, is(false));
475 }
476
477 /**
478 * Tests path setup without signalling and with bandwidth reservation.
479 */
480 @Test
481 public void setupPathTest12() {
482 build4RouterTopo(false, true, true, true, 15);
483 List<Constraint> constraints = new LinkedList<Constraint>();
484 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
485 CostConstraint costConstraint = new CostConstraint(TE_COST);
486
487 constraints.add(costConstraint);
488 constraints.add(bwConstraint);
489
490 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
491 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
492
493 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
494 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
495
496 LabelResourceId link1Label = LabelResourceId.labelResourceId(5202);
497 pceManager.pceStore.addAdjLabel(link1, link1Label);
498
499 LabelResourceId link2Label = LabelResourceId.labelResourceId(5203);
500 pceManager.pceStore.addAdjLabel(link2, link2Label);
501
502 LabelResourceId link3Label = LabelResourceId.labelResourceId(5204);
503 pceManager.pceStore.addAdjLabel(link3, link3Label);
504
505 LabelResourceId link4Label = LabelResourceId.labelResourceId(5205);
506 pceManager.pceStore.addAdjLabel(link4, link4Label);
507
508 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING);
509 assertThat(result, is(true));
510 }
511
512 /**
513 * Tests path setup without cost/bandwidth constraints.
514 */
515 @Test
516 public void setupPathTest13() {
517 build4RouterTopo(false, false, false, false, 0);
518
519 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", null, WITH_SIGNALLING);
520 assertThat(result, is(true));
521 }
522
523 /**
524 * Tests path update with increase in bandwidth.
525 */
526 @Test
527 public void updatePathTest1() {
528 build4RouterTopo(false, true, true, true, 100);
529
530 // Setup tunnel.
531 List<Constraint> constraints = new LinkedList<>();
532 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(60.0));
533 constraints.add(bwConstraint);
534 CostConstraint costConstraint = new CostConstraint(TE_COST);
535 constraints.add(costConstraint);
536
537 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
538 assertThat(result, is(true));
539
540 // Change constraint and update it.
541 constraints = new LinkedList<>();
542 bwConstraint = new BandwidthConstraint(Bandwidth.bps(50.0));
543 constraints.add(bwConstraint);
544 constraints.add(costConstraint);
545
546 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
547 assertThat(tunnels.size(), is(1));
548
549 Tunnel tunnel = tunnels.iterator().next();
550
551 // Stimulate the effect of LSP ids from protocol msg.
552 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", State.ACTIVE);
553
554 result = pceManager.updatePath(tunnel.tunnelId(), constraints);
555 assertThat(result, is(true));
556
557 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
558 assertThat(tunnels.size(), is(2));
559 }
560
561 /**
562 * Tests path update with decrease in bandwidth.
563 */
564 @Test
565 public void updatePathTest2() {
566 build4RouterTopo(false, true, true, true, 100);
567
568 // Setup tunnel.
569 List<Constraint> constraints = new LinkedList<Constraint>();
570 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(60.0));
571 constraints.add(bwConstraint);
572 CostConstraint costConstraint = new CostConstraint(TE_COST);
573 constraints.add(costConstraint);
574
575 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
576 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
577
578 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
579 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
580
581 LabelResourceId link1Label = LabelResourceId.labelResourceId(5202);
582 pceManager.pceStore.addAdjLabel(link1, link1Label);
583
584 LabelResourceId link2Label = LabelResourceId.labelResourceId(5203);
585 pceManager.pceStore.addAdjLabel(link2, link2Label);
586
587 LabelResourceId link3Label = LabelResourceId.labelResourceId(5204);
588 pceManager.pceStore.addAdjLabel(link3, link3Label);
589
590 LabelResourceId link4Label = LabelResourceId.labelResourceId(5205);
591 pceManager.pceStore.addAdjLabel(link4, link4Label);
592
593 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, SR_WITHOUT_SIGNALLING);
594 assertThat(result, is(true));
595
596 // Change constraint and update it.
597 constraints.remove(bwConstraint);
598 bwConstraint = new BandwidthConstraint(Bandwidth.bps(70.0));
599 constraints.add(bwConstraint);
600
601 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
602 assertThat(tunnels.size(), is(1));
603
604 for (Tunnel tunnel : tunnels) {
605 result = pceManager.updatePath(tunnel.tunnelId(), constraints);
606 assertThat(result, is(true));
607 }
608
609 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
610 assertThat(tunnels.size(), is(2));
611 }
612
613 /**
614 * Tests path update without cost/bandwidth constraints.
615 */
616 @Test
617 public void updatePathTest3() {
618 build4RouterTopo(false, true, true, true, 100);
619
620 // Setup tunnel.
Priyanka B3fdb9dd2016-08-08 10:47:24 +0530621 List<Constraint> constraints = new LinkedList<Constraint>();
622 CostConstraint costConstraint = new CostConstraint(TE_COST);
623 constraints.add(costConstraint);
624 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530625 assertThat(result, is(true));
626
627 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
628 assertThat(tunnels.size(), is(1));
629
630 for (Tunnel tunnel : tunnels) {
631 result = pceManager.updatePath(tunnel.tunnelId(), null);
632 assertThat(result, is(true));
633 }
634
635 Iterable<Tunnel> queryTunnelResult = pceManager.queryAllPath();
636 assertThat((int) queryTunnelResult.spliterator().getExactSizeIfKnown(), is(2));
637 }
638
639 /**
640 * Tests path release.
641 */
642 @Test
643 public void releasePathTest1() {
644 build4RouterTopo(false, false, false, false, 5);
645 List<Constraint> constraints = new LinkedList<Constraint>();
646 CostConstraint costConstraint = new CostConstraint(TE_COST);
Priyanka B4c3b4512016-07-22 11:41:49 +0530647 BandwidthConstraint bwConst = new BandwidthConstraint(Bandwidth.bps(3));
648 constraints.add(bwConst);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530649 constraints.add(costConstraint);
650
651 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
652
653 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
654 assertThat(tunnels.size(), is(1));
655 boolean result;
656 for (Tunnel tunnel : tunnels) {
657 result = pceManager.releasePath(tunnel.tunnelId());
658 assertThat(result, is(true));
659 }
660 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
661 assertThat(tunnels.size(), is(0));
662 }
663
664 /**
665 * Tests path release failure.
666 */
667 @Test
668 public void releasePathTest2() {
669 build4RouterTopo(false, false, false, false, 5);
670 List<Constraint> constraints = new LinkedList<Constraint>();
671 CostConstraint costConstraint = new CostConstraint(TE_COST);
672 constraints.add(costConstraint);
673
674 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
675
676 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
677 assertThat(tunnels.size(), is(1));
678
679 // Random tunnel id.
680 boolean result = pceManager.releasePath(TunnelId.valueOf("111"));
681 assertThat(result, is(false));
682
683 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
684 assertThat(tunnels.size(), is(1));
685 }
686
687 /**
688 * Tests packet in to trigger label DB sync.
689 */
690 @Test
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530691 public void packetProcessingTest1() throws URISyntaxException {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530692
693 build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc.
694
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530695 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
696 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
697
Avantika-Huawei28b53752016-06-23 17:04:49 +0530698 pceManager.pceStore.addLsrIdDevice(deviceD1.annotations().value(LSRID), deviceD1.id());
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530699 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
700 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
701
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530702 ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1));
703 ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530704
705 Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT)
706 .providerId(new ProviderId("eth", "1")).build();
707
708 LabelResourceId link1Label = LabelResourceId.labelResourceId(5204);
709 pceManager.pceStore.addAdjLabel(link1, link1Label);
710
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530711 TCP tcp = new TCP();
712 tcp.setDestinationPort(PCEP_PORT);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530713
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530714 IPv4 ipv4 = new IPv4();
715 ipv4.setProtocol(IPv4.PROTOCOL_TCP);
716 ipv4.setPayload(tcp);
717
718 Ethernet eth = new Ethernet();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530719 eth.setEtherType(Ethernet.TYPE_IPV4);
720 eth.setPayload(ipv4);
721
Avantika-Huawei28b53752016-06-23 17:04:49 +0530722 InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(DeviceId.deviceId("1.1.1.1"),
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530723 PortNumber.portNumber(PCEP_PORT)),
724 eth, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530725
726 pktProcessor.process(new MockPcepPacketContext(inPkt, null));
727 assertThat(flowsDownloaded, is(4));
728 }
729
730 /**
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530731 * Tests faulty packet in to trigger label DB sync.
732 */
733 @Test
734 public void packetProcessingTest2() throws URISyntaxException {
735
736 build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc.
737
738 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
739 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
740
741 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
742 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
743
744 ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1));
745 ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2));
746
747 Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT)
748 .providerId(new ProviderId("eth", "1")).build();
749
750 LabelResourceId link1Label = LabelResourceId.labelResourceId(5204);
751 pceManager.pceStore.addAdjLabel(link1, link1Label);
752
753 TCP tcp = new TCP(); // Not set the pcep port.
754 IPv4 ipv4 = new IPv4();
755 ipv4.setProtocol(IPv4.PROTOCOL_TCP);
756 ipv4.setPayload(tcp);
757
758 Ethernet eth = new Ethernet();
759 eth.setEtherType(Ethernet.TYPE_IPV4);
760 eth.setPayload(ipv4);
761
762 InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(),
763 PortNumber.portNumber(PCEP_PORT)),
764 eth, null);
765
766 pktProcessor.process(new MockPcepPacketContext(inPkt, null));
767 assertThat(flowsDownloaded, is(0));
768 }
769
770 /**
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530771 * Tests tunnel events added and removed.
772 */
773 @Test
774 public void tunnelEventTest1() {
775 build4RouterTopo(false, true, true, true, 15);
776 List<Constraint> constraints = new LinkedList<Constraint>();
777 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
778 CostConstraint costConstraint = new CostConstraint(TE_COST);
779
780 constraints.add(costConstraint);
781 constraints.add(bwConstraint);
782
783 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
784 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
785
786 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
787 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
788
789 LabelResourceId link1Label = LabelResourceId.labelResourceId(5202);
790 pceManager.pceStore.addAdjLabel(link1, link1Label);
791
792 LabelResourceId link2Label = LabelResourceId.labelResourceId(5203);
793 pceManager.pceStore.addAdjLabel(link2, link2Label);
794
795 LabelResourceId link3Label = LabelResourceId.labelResourceId(5204);
796 pceManager.pceStore.addAdjLabel(link3, link3Label);
797
798 LabelResourceId link4Label = LabelResourceId.labelResourceId(5205);
799 pceManager.pceStore.addAdjLabel(link4, link4Label);
800
801 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T1", constraints, SR_WITHOUT_SIGNALLING);
802 assertThat(pceStore.getTunnelInfoCount(), is(1));
803
804 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
805
806 for (Tunnel tunnel : tunnels) {
807 TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
808 tunnelListener.event(event);
809
810 pceManager.releasePath(tunnel.tunnelId());
811
812 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel);
813 tunnelListener.event(event);
814 }
815
816 assertThat(pceStore.getTunnelInfoCount(), is(0));
817 }
818
819 /**
820 * Tests label allocation/removal in CR case based on tunnel event.
821 */
822 @Test
823 public void tunnelEventTest2() {
824 build4RouterTopo(false, true, true, true, 15);
825 List<Constraint> constraints = new LinkedList<Constraint>();
826 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
827 CostConstraint costConstraint = new CostConstraint(TE_COST);
828
829 constraints.add(costConstraint);
830 constraints.add(bwConstraint);
831
832 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints, WITHOUT_SIGNALLING_AND_WITHOUT_SR);
833 assertThat(pceStore.getTunnelInfoCount(), is(1));
834
835 TunnelEvent event;
836 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
837 for (Tunnel tunnel : tunnels) {
838 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
839 tunnelListener.event(event);
840
841 // Stimulate the effect of LSP ids from protocol msg.
842 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", ESTABLISHED);
843 }
844
845 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
846 for (Tunnel tunnel : tunnels) {
847 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel);
848 tunnelListener.event(event);
849
850 pceManager.releasePath(tunnel.tunnelId());
851
852 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel);
853 tunnelListener.event(event);
854 }
855
856 assertThat(pceStore.getTunnelInfoCount(), is(0));
857 }
858
859 /**
860 * Tests handling UNSTABLE state based on tunnel event.
861 */
862 @Test
863 public void tunnelEventTest3() {
864 build4RouterTopo(false, true, true, true, 15);
865 List<Constraint> constraints = new LinkedList<Constraint>();
866 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
867 CostConstraint costConstraint = new CostConstraint(TE_COST);
868
869 constraints.add(costConstraint);
870 constraints.add(bwConstraint);
871
872 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints, WITHOUT_SIGNALLING_AND_WITHOUT_SR);
873 assertThat(pceStore.getTunnelInfoCount(), is(1));
874 assertThat(pceStore.getFailedPathInfoCount(), is(0));
875
876 TunnelEvent event;
877 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
878 for (Tunnel tunnel : tunnels) {
879 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
880 tunnelListener.event(event);
881
882 // Stimulate the effect of LSP ids from protocol msg.
883 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", UNSTABLE);
884 }
885
886 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
887 for (Tunnel tunnel : tunnels) {
888 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel);
889 tunnelListener.event(event);
890 }
891 assertThat(pceStore.getTunnelInfoCount(), is(1));
892 assertThat(pceStore.getFailedPathInfoCount(), is(1));
893 }
894
Priyanka B3f92c5a2016-05-27 10:14:16 +0530895 /**
896 * Tests resilency when L2 link is down.
897 */
898 @Test
899 public void resilencyTest1() {
900 build4RouterTopo(true, false, false, false, 10);
901
902
903 List<Constraint> constraints = new LinkedList<Constraint>();
904 CostConstraint costConstraint = new CostConstraint(COST);
905 constraints.add(costConstraint);
906 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
907 constraints.add(localBwConst);
908
909 //Setup the path , tunnel created
910 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
911 assertThat(result, is(true));
912 assertThat(pceStore.getTunnelInfoCount(), is(1));
913 assertThat(pceStore.getFailedPathInfoCount(), is(0));
914
915 List<Event> reasons = new LinkedList<>();
916 final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
917 reasons.add(linkEvent);
918 final TopologyEvent event = new TopologyEvent(
919 TopologyEvent.Type.TOPOLOGY_CHANGED,
920 topology,
921 reasons);
922
923 //Change Topology : remove link2
924 Set<TopologyEdge> tempEdges = new HashSet<>();
925 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
926 topologyService.changeInTopology(getGraph(null, tempEdges));
927 listener.event(event);
928
929 List<Link> links = new LinkedList<>();
930 links.add(link3);
931 links.add(link4);
932
933 //Path is D1-D3-D4
934 assertThat(pathService.paths().iterator().next().links(), is(links));
935 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
936 }
937
938 /**
939 * Tests resilency when L2 and L4 link is down.
940 */
941 @Test
942 public void resilencyTest2() {
943 build4RouterTopo(true, false, false, false, 10);
944
945 List<Constraint> constraints = new LinkedList<Constraint>();
946 CostConstraint costConstraint = new CostConstraint(COST);
947 constraints.add(costConstraint);
948 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
949 constraints.add(localBwConst);
950
951 //Setup the path , tunnel created
952 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
953 assertThat(result, is(true));
954
955 List<Event> reasons = new LinkedList<>();
956 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
957 reasons.add(linkEvent);
958 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
959 reasons.add(linkEvent);
960 final TopologyEvent event = new TopologyEvent(
961 TopologyEvent.Type.TOPOLOGY_CHANGED,
962 topology,
963 reasons);
964
965 //Change Topology : remove link2 and link4
966 Set<TopologyEdge> tempEdges = new HashSet<>();
967 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
968 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
969 topologyService.changeInTopology(getGraph(null, tempEdges));
970 listener.event(event);
971
972 //No Path
973 assertThat(pathService.paths().size(), is(0));
974 }
975
976 /**
977 * Tests resilency when D2 device is down.
978 */
979 @Test
980 public void resilencyTest3() {
981 build4RouterTopo(true, false, false, false, 10);
982
983 List<Constraint> constraints = new LinkedList<Constraint>();
984 CostConstraint costConstraint = new CostConstraint(COST);
985 constraints.add(costConstraint);
986 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
987 constraints.add(localBwConst);
988
989 //Setup the path , tunnel created
990 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
991 assertThat(result, is(true));
992
993 List<Event> reasons = new LinkedList<>();
994 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
995 reasons.add(linkEvent);
996 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
997 reasons.add(linkEvent);
998 final TopologyEvent event = new TopologyEvent(
999 TopologyEvent.Type.TOPOLOGY_CHANGED,
1000 topology,
1001 reasons);
1002
1003 //Change Topology : remove link2 and link1
1004 Set<TopologyEdge> tempEdges = new HashSet<>();
1005 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1006 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1007 topologyService.changeInTopology(getGraph(null, tempEdges));
1008 listener.event(event);
1009
1010 List<Link> links = new LinkedList<>();
1011 links.add(link3);
1012 links.add(link4);
1013
1014 //Path is D1-D3-D4
1015 assertThat(pathService.paths().iterator().next().links(), is(links));
1016 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1017 }
1018
1019 /**
1020 * Tests resilency when ingress device is down.
1021 */
1022 @Test
1023 public void resilencyTest4() {
1024 build4RouterTopo(true, false, false, false, 10);
1025
1026 List<Constraint> constraints = new LinkedList<Constraint>();
1027 CostConstraint costConstraint = new CostConstraint(COST);
1028 constraints.add(costConstraint);
1029 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1030 constraints.add(localBwConst);
1031
1032 //Setup the path , tunnel created
1033 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1034 assertThat(result, is(true));
1035
1036 List<Event> reasons = new LinkedList<>();
1037 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1038 reasons.add(linkEvent);
1039 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1040 reasons.add(linkEvent);
1041 final TopologyEvent event = new TopologyEvent(
1042 TopologyEvent.Type.TOPOLOGY_CHANGED,
1043 topology,
1044 reasons);
1045
1046 //Change Topology : remove link2 and link1
1047 Set<TopologyEdge> tempEdges = new HashSet<>();
1048 tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
1049 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1050 topologyService.changeInTopology(getGraph(null, tempEdges));
1051 listener.event(event);
1052
1053 //No path
1054 assertThat(pathService.paths().size(), is(0));
1055 }
1056
1057 /**
1058 * Tests resilency when D2 and D3 devices are down.
1059 */
1060 @Test
1061 public void resilencyTest5() {
1062 build4RouterTopo(true, false, false, false, 10);
1063
1064 List<Constraint> constraints = new LinkedList<Constraint>();
1065 CostConstraint costConstraint = new CostConstraint(COST);
1066 constraints.add(costConstraint);
1067 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1068 constraints.add(localBwConst);
1069
1070 //Setup the path , tunnel created
1071 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1072 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, link1);
1078 reasons.add(linkEvent);
1079 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1080 reasons.add(linkEvent);
1081 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1082 reasons.add(linkEvent);
1083
1084 final TopologyEvent event = new TopologyEvent(
1085 TopologyEvent.Type.TOPOLOGY_CHANGED,
1086 topology,
1087 reasons);
1088
1089 //Change Topology : remove device2, device3 and all links
1090 Set<TopologyEdge> tempEdges = new HashSet<>();
1091 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1092 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1093 tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
1094 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1095 Set<TopologyVertex> tempVertexes = new HashSet<>();
1096 tempVertexes.add(D2);
1097 tempVertexes.add(D3);
1098 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1099 listener.event(event);
1100
1101 //No path
1102 assertThat(pathService.paths().size(), is(0));
1103 }
1104
1105 /**
1106 * Tests resilency when egress device is down.
1107 */
1108 @Test
1109 public void resilencyTest6() {
1110 build4RouterTopo(true, false, false, false, 10);
1111
1112 List<Constraint> constraints = new LinkedList<Constraint>();
1113 CostConstraint costConstraint = new CostConstraint(COST);
1114 constraints.add(costConstraint);
1115 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1116 constraints.add(localBwConst);
1117
1118 //Setup the path , tunnel created
1119 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1120 assertThat(result, is(true));
1121
1122 List<Event> reasons = new LinkedList<>();
1123 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1124 reasons.add(linkEvent);
1125 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1126 reasons.add(linkEvent);
1127
1128 final TopologyEvent event = new TopologyEvent(
1129 TopologyEvent.Type.TOPOLOGY_CHANGED,
1130 topology,
1131 reasons);
1132
1133 //Change Topology : remove device4 , link2 and link4
1134 Set<TopologyEdge> tempEdges = new HashSet<>();
1135 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1136 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1137 Set<TopologyVertex> tempVertexes = new HashSet<>();
1138 tempVertexes.add(D4);
1139 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1140 listener.event(event);
1141
1142 //No path
1143 assertThat(pathService.paths().size(), is(0));
1144 }
1145
1146 /**
1147 * Tests resilency when egress device is down.
1148 */
1149 @Test
1150 public void resilencyTest7() {
1151 build4RouterTopo(true, false, false, false, 10);
1152
1153 List<Constraint> constraints = new LinkedList<Constraint>();
1154 CostConstraint costConstraint = new CostConstraint(COST);
1155 constraints.add(costConstraint);
1156 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1157 constraints.add(localBwConst);
1158
1159 //Setup the path , tunnel created
1160 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1161 assertThat(result, is(true));
1162
1163 List<Event> reasons = new LinkedList<>();
1164 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1165 reasons.add(linkEvent);
1166 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1167 reasons.add(linkEvent);
1168
1169 final TopologyEvent event = new TopologyEvent(
1170 TopologyEvent.Type.TOPOLOGY_CHANGED,
1171 topology,
1172 reasons);
1173
1174 //Change Topology : remove device4 , link2 and link4
1175 Set<TopologyEdge> tempEdges = new HashSet<>();
1176 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1177 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1178 Set<TopologyVertex> tempVertexes = new HashSet<>();
1179 tempVertexes.add(D4);
1180 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1181 listener.event(event);
1182
1183 //No path
1184 assertThat(pathService.paths().size(), is(0));
1185 }
1186
1187 /**
1188 * Tests resilency when D2 device is suspended.
1189 */
1190 @Test
1191 public void resilencyTest8() {
1192 build4RouterTopo(true, false, false, false, 10);
1193
1194 List<Constraint> constraints = new LinkedList<Constraint>();
1195 CostConstraint costConstraint = new CostConstraint(COST);
1196 constraints.add(costConstraint);
1197 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1198 constraints.add(localBwConst);
1199
1200 //Setup the path , tunnel created
1201 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1202 assertThat(result, is(true));
1203
1204 List<Event> reasons = new LinkedList<>();
1205 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1206 reasons.add(linkEvent);
1207 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1208 reasons.add(linkEvent);
1209
1210 final TopologyEvent event = new TopologyEvent(
1211 TopologyEvent.Type.TOPOLOGY_CHANGED,
1212 topology,
1213 reasons);
1214
1215 //Change Topology : remove device2 , link1 and link2
1216 Set<TopologyEdge> tempEdges = new HashSet<>();
1217 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1218 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1219 Set<TopologyVertex> tempVertexes = new HashSet<>();
1220 tempVertexes.add(D2);
1221 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1222 listener.event(event);
1223
1224 List<Link> links = new LinkedList<>();
1225 links.add(link3);
1226 links.add(link4);
1227
1228 //Path is D1-D3-D4
1229 assertThat(pathService.paths().iterator().next().links(), is(links));
1230 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1231 }
1232
1233 /**
1234 * Tests resilency when D2 device availability is changed.
1235 */
1236 @Test
1237 public void resilencyTest11() {
1238 build4RouterTopo(true, false, false, false, 10);
1239
1240 List<Constraint> constraints = new LinkedList<Constraint>();
1241 CostConstraint costConstraint = new CostConstraint(COST);
1242 constraints.add(costConstraint);
1243 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1244 constraints.add(localBwConst);
1245
1246 //Setup the path , tunnel created
1247 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1248 assertThat(result, is(true));
1249
1250 List<Event> reasons = new LinkedList<>();
1251 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1252 reasons.add(linkEvent);
1253 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1254 reasons.add(linkEvent);
1255
1256 final TopologyEvent event = new TopologyEvent(
1257 TopologyEvent.Type.TOPOLOGY_CHANGED,
1258 topology,
1259 reasons);
1260
1261 //Change Topology : remove device2 , link1 and link2
1262 Set<TopologyEdge> tempEdges = new HashSet<>();
1263 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1264 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1265 Set<TopologyVertex> tempVertexes = new HashSet<>();
1266 tempVertexes.add(D2);
1267 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1268 listener.event(event);
1269
1270 List<Link> links = new LinkedList<>();
1271 links.add(link3);
1272 links.add(link4);
1273
1274 //Path is D1-D3-D4
1275 assertThat(pathService.paths().iterator().next().links(), is(links));
1276 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1277 }
1278
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301279 /*
1280 * Tests node label allocation/removal in SR-TE case based on device event.
1281 */
1282 @Test
1283 public void deviceEventTest() {
1284 // Make four router topology with SR-TE capabilities.
1285 build4RouterTopo(true, false, true, true, 0);
1286
1287 // Add new L3 device
1288 DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
1289 builderDev5.set(AnnotationKeys.TYPE, L3);
1290 builderDev5.set(LSRID, "5.5.5.5");
1291
1292 Device dev5 = new MockDevice(DeviceId.deviceId("P005"), builderDev5.build());
1293 deviceService.addDevice(dev5);
1294
1295 // Add capability
1296 DeviceCapability device5Cap = netConfigRegistry.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class);
1297 device5Cap.setLabelStackCap(true)
1298 .setLocalLabelCap(false)
1299 .setSrCap(true)
1300 .apply();
1301
1302 // Get listener
1303 DeviceListener listener = deviceService.getListener();
1304
1305 // Generate Remove events
1306 deviceService.removeDevice(dev5);
1307 DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, dev5);
1308 listener.event(event);
1309
1310 assertThat(pceStore.getGlobalNodeLabel(dev5.id()), is(nullValue()));
1311 }
1312
1313 /**
1314 * Tests adjacency label allocation/removal in SR-TE case based on link event.
1315 */
1316 @Test
1317 public void linkEventTest() {
1318 // Make four router topology with SR-TE capabilities.
1319 build4RouterTopo(true, false, true, true, 0);
1320
1321 // Get listener
1322 LinkListener listener = linkService.getListener();
1323
1324 // Adding link3
1325 linkService.addLink(link3);
1326
1327 // Generate events
1328 LinkEvent event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link3);
1329 listener.event(event);
1330
1331 assertThat(pceStore.getAdjLabel(link3), is(notNullValue()));
1332
1333 // Adding link4
1334 linkService.addLink(link4);
1335
1336 event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link4);
1337 listener.event(event);
1338
1339 assertThat(pceStore.getAdjLabel(link4), is(notNullValue()));
1340
1341 // Remove link3
1342 linkService.removeLink(link3);
1343
1344 // Generate events
1345 event = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1346 listener.event(event);
1347
1348 assertThat(pceStore.getAdjLabel(link3), is(nullValue()));
1349
1350 // Remove link4
1351 linkService.removeLink(link4);
1352
1353 event = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1354 listener.event(event);
1355
1356 assertThat(pceStore.getAdjLabel(link4), is(nullValue()));
1357 }
1358
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301359 @After
1360 public void tearDown() {
1361 pceManager.deactivate();
1362 pceManager.pathService = null;
1363 pceManager.resourceService = null;
1364 pceManager.tunnelService = null;
1365 pceManager.coreService = null;
1366 pceManager.storageService = null;
1367 pceManager.packetService = null;
1368 pceManager.deviceService = null;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301369 pceManager.linkService = null;
1370 pceManager.netCfgService = null;
1371 pceManager.labelRsrcAdminService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301372 pceManager.labelRsrcService = null;
1373 pceManager.flowObjectiveService = null;
1374 pceManager.pceStore = null;
Priyanka B3f92c5a2016-05-27 10:14:16 +05301375 pceManager.topologyService = null;
1376 pceManager.mastershipService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301377 flowsDownloaded = 0;
1378 }
1379
1380 private class MockTopologyService extends TopologyServiceAdapter {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301381 private void changeInTopology(TopologyGraph graphModified) {
1382 graph = graphModified;
1383 }
1384
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301385 @Override
1386 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
1387 DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
1388 DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
1389 Set<TopologyVertex> vertices = graph.getVertexes();
1390 if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
1391 // src or dst not part of the current graph
1392 return ImmutableSet.of();
1393 }
1394
1395 GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = PathComputationTest.graphSearch()
1396 .search(graph, srcV, dstV, weight, ALL_PATHS);
1397 ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
1398 for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
1399 builder.add(PathComputationTest.networkPath(path));
1400 }
1401 return builder.build();
1402 }
1403 }
1404
Priyanka B3f92c5a2016-05-27 10:14:16 +05301405 private TopologyGraph getGraph(Set<TopologyVertex> removedVertex, Set<TopologyEdge> removedEdges) {
1406 if (removedVertex != null) {
1407 vertexes.remove(removedVertex);
1408 removedVertex.forEach(v ->
1409 {
1410 vertexes.remove(v);
1411 });
1412 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301413
Priyanka B3f92c5a2016-05-27 10:14:16 +05301414 if (removedEdges != null) {
1415 removedEdges.forEach(e ->
1416 {
1417 edges.remove(e);
1418 });
1419 }
1420
1421 return new DefaultTopologyGraph(vertexes, edges);
1422 }
1423
1424 private class MockPathService extends PathServiceAdapter {
1425 Set<Path> computedPaths;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301426 @Override
1427 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
1428 // If either edge is null, bail with no paths.
1429 if (src == null || dst == null) {
1430 return ImmutableSet.of();
1431 }
1432
1433 // Otherwise get all paths between the source and destination edge
1434 // devices.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301435 computedPaths = topologyService.getPaths(null, (DeviceId) src, (DeviceId) dst, weight);
1436 return computedPaths;
1437 }
1438
1439 private Set<Path> paths() {
1440 return computedPaths;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301441 }
1442 }
1443
1444 private class MockTunnelServiceAdapter extends TunnelServiceAdapter {
1445 private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<TunnelId, Tunnel>();
1446 private int tunnelIdCounter = 0;
1447
1448 @Override
1449 public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
1450 TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
1451 Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(),
1452 tunnel.state(), tunnel.groupId(), tunnelId, tunnel.tunnelName(),
1453 path, tunnel.annotations());
1454 tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert);
1455 return tunnelId;
1456 }
1457
1458 @Override
1459 public void addListener(TunnelListener listener) {
1460 tunnelListener = listener;
1461 }
1462
1463 /**
1464 * Stimulates the effect of receiving PLSP id and LSP id from protocol PCRpt msg.
1465 */
1466 public TunnelId updateTunnelWithLspIds(Tunnel tunnel, String pLspId, String localLspId, State state) {
1467 TunnelId tunnelId = tunnel.tunnelId();
1468 Builder annotationBuilder = DefaultAnnotations.builder();
1469 annotationBuilder.putAll(tunnel.annotations());
1470
1471 // PCRpt in response to PCInitate msg will carry PLSP id allocated by PCC.
1472 if (tunnel.annotations().value(PLSP_ID) == null) {
1473 annotationBuilder.set(PLSP_ID, pLspId);
1474 }
1475
1476 // Signalled LSPs will carry local LSP id allocated by signalling protocol(PCC).
1477 if (tunnel.annotations().value(LOCAL_LSP_ID) == null) {
1478 annotationBuilder.set(LOCAL_LSP_ID, localLspId);
1479 }
1480 SparseAnnotations annotations = annotationBuilder.build();
1481 tunnelIdAsKeyStore.remove(tunnelId, tunnel);
1482
1483 Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(),
1484 state, tunnel.groupId(), tunnelId, tunnel.tunnelName(),
1485 tunnel.path(), annotations);
1486
1487 tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert);
1488
1489 return tunnelId;
1490 }
1491
1492 @Override
1493 public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) {
1494 for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) {
1495 if (tunnelIdKey.equals(tunnelId)) {
1496 tunnelIdAsKeyStore.remove(tunnelId);
1497 return true;
1498 }
1499 }
1500 return false;
1501 }
1502
1503 @Override
1504 public Tunnel queryTunnel(TunnelId tunnelId) {
1505 for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) {
1506 if (tunnelIdKey.equals(tunnelId)) {
1507 return tunnelIdAsKeyStore.get(tunnelId);
1508 }
1509 }
1510 return null;
1511 }
1512
1513 @Override
1514 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
1515 Collection<Tunnel> result = new HashSet<Tunnel>();
1516 Tunnel tunnel = null;
1517 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1518 tunnel = tunnelIdAsKeyStore.get(tunnelId);
1519
1520 if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
1521 result.add(tunnel);
1522 }
1523 }
1524
1525 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
1526 }
1527
1528 @Override
1529 public Collection<Tunnel> queryTunnel(Tunnel.Type type) {
1530 Collection<Tunnel> result = new HashSet<Tunnel>();
1531
1532 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1533 result.add(tunnelIdAsKeyStore.get(tunnelId));
1534 }
1535
1536 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
1537 }
Priyanka B3f92c5a2016-05-27 10:14:16 +05301538
1539 @Override
1540 public Collection<Tunnel> queryAllTunnels() {
1541 Collection<Tunnel> result = new HashSet<Tunnel>();
1542
1543 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1544 result.add(tunnelIdAsKeyStore.get(tunnelId));
1545 }
1546
1547 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
1548 }
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301549
Priyanka B3f92c5a2016-05-27 10:14:16 +05301550 @Override
1551 public Iterable<Tunnel> getTunnels(DeviceId deviceId) {
1552 List<Tunnel> tunnelList = new LinkedList<>();
1553
1554 for (Tunnel t : tunnelIdAsKeyStore.values()) {
1555 for (Link l : t.path().links()) {
1556 if (l.src().deviceId().equals(deviceId) || l.dst().deviceId().equals(deviceId)) {
1557 tunnelList.add(t);
1558 break;
1559 }
1560 }
1561 }
1562 return tunnelList;
1563 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301564 }
1565
1566 public static class MockCoreService extends CoreServiceAdapter {
1567
1568 @Override
1569 public ApplicationId registerApplication(String name) {
1570 return new DefaultApplicationId(1, name);
1571 }
1572
1573 @Override
1574 public IdGenerator getIdGenerator(String topic) {
1575 return new IdGenerator() {
1576 private AtomicLong counter = new AtomicLong(0);
1577
1578 @Override
1579 public long getNewId() {
1580 return counter.getAndIncrement();
1581 }
1582 };
1583 }
1584 }
1585
1586 private class MockDevice extends DefaultDevice {
1587 MockDevice(DeviceId id, Annotations annotations) {
1588 super(null, id, null, null, null, null, null, null, annotations);
1589 }
1590 }
1591
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301592 private PacketProcessor pktProcessor = null;
1593
1594 private class MockPacketService extends PacketServiceAdapter {
1595 @Override
1596 public void addProcessor(PacketProcessor processor, int priority) {
1597 pktProcessor = processor;
1598 }
1599 }
1600
1601 // Minimal PacketContext to make core and applications happy.
1602 final class MockPcepPacketContext extends DefaultPacketContext {
1603 private MockPcepPacketContext(InboundPacket inPkt, OutboundPacket outPkt) {
1604 super(System.currentTimeMillis(), inPkt, outPkt, false);
1605 }
1606
1607 @Override
1608 public void send() {
1609 }
1610 }
1611
1612 public static class MockFlowObjService extends FlowObjServiceAdapter {
1613 @Override
1614 public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
1615 ++flowsDownloaded;
1616 }
1617 }
1618}