blob: 602c3287e727d551f56db7b01643683ab89e2286 [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.
621 boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", null, WITH_SIGNALLING);
622 assertThat(result, is(true));
623
624 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
625 assertThat(tunnels.size(), is(1));
626
627 for (Tunnel tunnel : tunnels) {
628 result = pceManager.updatePath(tunnel.tunnelId(), null);
629 assertThat(result, is(true));
630 }
631
632 Iterable<Tunnel> queryTunnelResult = pceManager.queryAllPath();
633 assertThat((int) queryTunnelResult.spliterator().getExactSizeIfKnown(), is(2));
634 }
635
636 /**
637 * Tests path release.
638 */
639 @Test
640 public void releasePathTest1() {
641 build4RouterTopo(false, false, false, false, 5);
642 List<Constraint> constraints = new LinkedList<Constraint>();
643 CostConstraint costConstraint = new CostConstraint(TE_COST);
644 constraints.add(costConstraint);
645
646 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
647
648 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
649 assertThat(tunnels.size(), is(1));
650 boolean result;
651 for (Tunnel tunnel : tunnels) {
652 result = pceManager.releasePath(tunnel.tunnelId());
653 assertThat(result, is(true));
654 }
655 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
656 assertThat(tunnels.size(), is(0));
657 }
658
659 /**
660 * Tests path release failure.
661 */
662 @Test
663 public void releasePathTest2() {
664 build4RouterTopo(false, false, false, false, 5);
665 List<Constraint> constraints = new LinkedList<Constraint>();
666 CostConstraint costConstraint = new CostConstraint(TE_COST);
667 constraints.add(costConstraint);
668
669 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
670
671 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
672 assertThat(tunnels.size(), is(1));
673
674 // Random tunnel id.
675 boolean result = pceManager.releasePath(TunnelId.valueOf("111"));
676 assertThat(result, is(false));
677
678 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
679 assertThat(tunnels.size(), is(1));
680 }
681
682 /**
683 * Tests packet in to trigger label DB sync.
684 */
685 @Test
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530686 public void packetProcessingTest1() throws URISyntaxException {
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530687
688 build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc.
689
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530690 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
691 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
692
693 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
694 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
695
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530696 ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1));
697 ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2));
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530698
699 Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT)
700 .providerId(new ProviderId("eth", "1")).build();
701
702 LabelResourceId link1Label = LabelResourceId.labelResourceId(5204);
703 pceManager.pceStore.addAdjLabel(link1, link1Label);
704
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530705 TCP tcp = new TCP();
706 tcp.setDestinationPort(PCEP_PORT);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530707
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530708 IPv4 ipv4 = new IPv4();
709 ipv4.setProtocol(IPv4.PROTOCOL_TCP);
710 ipv4.setPayload(tcp);
711
712 Ethernet eth = new Ethernet();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530713 eth.setEtherType(Ethernet.TYPE_IPV4);
714 eth.setPayload(ipv4);
715
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530716 InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(),
717 PortNumber.portNumber(PCEP_PORT)),
718 eth, null);
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530719
720 pktProcessor.process(new MockPcepPacketContext(inPkt, null));
721 assertThat(flowsDownloaded, is(4));
722 }
723
724 /**
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530725 * Tests faulty packet in to trigger label DB sync.
726 */
727 @Test
728 public void packetProcessingTest2() throws URISyntaxException {
729
730 build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc.
731
732 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
733 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
734
735 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
736 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
737
738 ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1));
739 ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2));
740
741 Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT)
742 .providerId(new ProviderId("eth", "1")).build();
743
744 LabelResourceId link1Label = LabelResourceId.labelResourceId(5204);
745 pceManager.pceStore.addAdjLabel(link1, link1Label);
746
747 TCP tcp = new TCP(); // Not set the pcep port.
748 IPv4 ipv4 = new IPv4();
749 ipv4.setProtocol(IPv4.PROTOCOL_TCP);
750 ipv4.setPayload(tcp);
751
752 Ethernet eth = new Ethernet();
753 eth.setEtherType(Ethernet.TYPE_IPV4);
754 eth.setPayload(ipv4);
755
756 InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(),
757 PortNumber.portNumber(PCEP_PORT)),
758 eth, null);
759
760 pktProcessor.process(new MockPcepPacketContext(inPkt, null));
761 assertThat(flowsDownloaded, is(0));
762 }
763
764 /**
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530765 * Tests tunnel events added and removed.
766 */
767 @Test
768 public void tunnelEventTest1() {
769 build4RouterTopo(false, true, true, true, 15);
770 List<Constraint> constraints = new LinkedList<Constraint>();
771 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
772 CostConstraint costConstraint = new CostConstraint(TE_COST);
773
774 constraints.add(costConstraint);
775 constraints.add(bwConstraint);
776
777 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
778 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
779
780 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
781 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
782
783 LabelResourceId link1Label = LabelResourceId.labelResourceId(5202);
784 pceManager.pceStore.addAdjLabel(link1, link1Label);
785
786 LabelResourceId link2Label = LabelResourceId.labelResourceId(5203);
787 pceManager.pceStore.addAdjLabel(link2, link2Label);
788
789 LabelResourceId link3Label = LabelResourceId.labelResourceId(5204);
790 pceManager.pceStore.addAdjLabel(link3, link3Label);
791
792 LabelResourceId link4Label = LabelResourceId.labelResourceId(5205);
793 pceManager.pceStore.addAdjLabel(link4, link4Label);
794
795 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T1", constraints, SR_WITHOUT_SIGNALLING);
796 assertThat(pceStore.getTunnelInfoCount(), is(1));
797
798 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
799
800 for (Tunnel tunnel : tunnels) {
801 TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
802 tunnelListener.event(event);
803
804 pceManager.releasePath(tunnel.tunnelId());
805
806 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel);
807 tunnelListener.event(event);
808 }
809
810 assertThat(pceStore.getTunnelInfoCount(), is(0));
811 }
812
813 /**
814 * Tests label allocation/removal in CR case based on tunnel event.
815 */
816 @Test
817 public void tunnelEventTest2() {
818 build4RouterTopo(false, true, true, true, 15);
819 List<Constraint> constraints = new LinkedList<Constraint>();
820 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
821 CostConstraint costConstraint = new CostConstraint(TE_COST);
822
823 constraints.add(costConstraint);
824 constraints.add(bwConstraint);
825
826 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints, WITHOUT_SIGNALLING_AND_WITHOUT_SR);
827 assertThat(pceStore.getTunnelInfoCount(), is(1));
828
829 TunnelEvent event;
830 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
831 for (Tunnel tunnel : tunnels) {
832 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
833 tunnelListener.event(event);
834
835 // Stimulate the effect of LSP ids from protocol msg.
836 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", ESTABLISHED);
837 }
838
839 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
840 for (Tunnel tunnel : tunnels) {
841 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel);
842 tunnelListener.event(event);
843
844 pceManager.releasePath(tunnel.tunnelId());
845
846 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, tunnel);
847 tunnelListener.event(event);
848 }
849
850 assertThat(pceStore.getTunnelInfoCount(), is(0));
851 }
852
853 /**
854 * Tests handling UNSTABLE state based on tunnel event.
855 */
856 @Test
857 public void tunnelEventTest3() {
858 build4RouterTopo(false, true, true, true, 15);
859 List<Constraint> constraints = new LinkedList<Constraint>();
860 BandwidthConstraint bwConstraint = new BandwidthConstraint(Bandwidth.bps(10.0));
861 CostConstraint costConstraint = new CostConstraint(TE_COST);
862
863 constraints.add(costConstraint);
864 constraints.add(bwConstraint);
865
866 pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T2", constraints, WITHOUT_SIGNALLING_AND_WITHOUT_SR);
867 assertThat(pceStore.getTunnelInfoCount(), is(1));
868 assertThat(pceStore.getFailedPathInfoCount(), is(0));
869
870 TunnelEvent event;
871 Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
872 for (Tunnel tunnel : tunnels) {
873 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED, tunnel);
874 tunnelListener.event(event);
875
876 // Stimulate the effect of LSP ids from protocol msg.
877 tunnelService.updateTunnelWithLspIds(tunnel, "123", "1", UNSTABLE);
878 }
879
880 tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
881 for (Tunnel tunnel : tunnels) {
882 event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED, tunnel);
883 tunnelListener.event(event);
884 }
885 assertThat(pceStore.getTunnelInfoCount(), is(1));
886 assertThat(pceStore.getFailedPathInfoCount(), is(1));
887 }
888
Priyanka B3f92c5a2016-05-27 10:14:16 +0530889 /**
890 * Tests resilency when L2 link is down.
891 */
892 @Test
893 public void resilencyTest1() {
894 build4RouterTopo(true, false, false, false, 10);
895
896
897 List<Constraint> constraints = new LinkedList<Constraint>();
898 CostConstraint costConstraint = new CostConstraint(COST);
899 constraints.add(costConstraint);
900 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
901 constraints.add(localBwConst);
902
903 //Setup the path , tunnel created
904 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
905 assertThat(result, is(true));
906 assertThat(pceStore.getTunnelInfoCount(), is(1));
907 assertThat(pceStore.getFailedPathInfoCount(), is(0));
908
909 List<Event> reasons = new LinkedList<>();
910 final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
911 reasons.add(linkEvent);
912 final TopologyEvent event = new TopologyEvent(
913 TopologyEvent.Type.TOPOLOGY_CHANGED,
914 topology,
915 reasons);
916
917 //Change Topology : remove link2
918 Set<TopologyEdge> tempEdges = new HashSet<>();
919 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
920 topologyService.changeInTopology(getGraph(null, tempEdges));
921 listener.event(event);
922
923 List<Link> links = new LinkedList<>();
924 links.add(link3);
925 links.add(link4);
926
927 //Path is D1-D3-D4
928 assertThat(pathService.paths().iterator().next().links(), is(links));
929 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
930 }
931
932 /**
933 * Tests resilency when L2 and L4 link is down.
934 */
935 @Test
936 public void resilencyTest2() {
937 build4RouterTopo(true, false, false, false, 10);
938
939 List<Constraint> constraints = new LinkedList<Constraint>();
940 CostConstraint costConstraint = new CostConstraint(COST);
941 constraints.add(costConstraint);
942 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
943 constraints.add(localBwConst);
944
945 //Setup the path , tunnel created
946 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
947 assertThat(result, is(true));
948
949 List<Event> reasons = new LinkedList<>();
950 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
951 reasons.add(linkEvent);
952 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
953 reasons.add(linkEvent);
954 final TopologyEvent event = new TopologyEvent(
955 TopologyEvent.Type.TOPOLOGY_CHANGED,
956 topology,
957 reasons);
958
959 //Change Topology : remove link2 and link4
960 Set<TopologyEdge> tempEdges = new HashSet<>();
961 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
962 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
963 topologyService.changeInTopology(getGraph(null, tempEdges));
964 listener.event(event);
965
966 //No Path
967 assertThat(pathService.paths().size(), is(0));
968 }
969
970 /**
971 * Tests resilency when D2 device is down.
972 */
973 @Test
974 public void resilencyTest3() {
975 build4RouterTopo(true, false, false, false, 10);
976
977 List<Constraint> constraints = new LinkedList<Constraint>();
978 CostConstraint costConstraint = new CostConstraint(COST);
979 constraints.add(costConstraint);
980 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
981 constraints.add(localBwConst);
982
983 //Setup the path , tunnel created
984 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
985 assertThat(result, is(true));
986
987 List<Event> reasons = new LinkedList<>();
988 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
989 reasons.add(linkEvent);
990 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
991 reasons.add(linkEvent);
992 final TopologyEvent event = new TopologyEvent(
993 TopologyEvent.Type.TOPOLOGY_CHANGED,
994 topology,
995 reasons);
996
997 //Change Topology : remove link2 and link1
998 Set<TopologyEdge> tempEdges = new HashSet<>();
999 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1000 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1001 topologyService.changeInTopology(getGraph(null, tempEdges));
1002 listener.event(event);
1003
1004 List<Link> links = new LinkedList<>();
1005 links.add(link3);
1006 links.add(link4);
1007
1008 //Path is D1-D3-D4
1009 assertThat(pathService.paths().iterator().next().links(), is(links));
1010 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1011 }
1012
1013 /**
1014 * Tests resilency when ingress device is down.
1015 */
1016 @Test
1017 public void resilencyTest4() {
1018 build4RouterTopo(true, false, false, false, 10);
1019
1020 List<Constraint> constraints = new LinkedList<Constraint>();
1021 CostConstraint costConstraint = new CostConstraint(COST);
1022 constraints.add(costConstraint);
1023 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1024 constraints.add(localBwConst);
1025
1026 //Setup the path , tunnel created
1027 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1028 assertThat(result, is(true));
1029
1030 List<Event> reasons = new LinkedList<>();
1031 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1032 reasons.add(linkEvent);
1033 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1034 reasons.add(linkEvent);
1035 final TopologyEvent event = new TopologyEvent(
1036 TopologyEvent.Type.TOPOLOGY_CHANGED,
1037 topology,
1038 reasons);
1039
1040 //Change Topology : remove link2 and link1
1041 Set<TopologyEdge> tempEdges = new HashSet<>();
1042 tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
1043 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1044 topologyService.changeInTopology(getGraph(null, tempEdges));
1045 listener.event(event);
1046
1047 //No path
1048 assertThat(pathService.paths().size(), is(0));
1049 }
1050
1051 /**
1052 * Tests resilency when D2 and D3 devices are down.
1053 */
1054 @Test
1055 public void resilencyTest5() {
1056 build4RouterTopo(true, false, false, false, 10);
1057
1058 List<Constraint> constraints = new LinkedList<Constraint>();
1059 CostConstraint costConstraint = new CostConstraint(COST);
1060 constraints.add(costConstraint);
1061 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1062 constraints.add(localBwConst);
1063
1064 //Setup the path , tunnel created
1065 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1066 assertThat(result, is(true));
1067
1068 List<Event> reasons = new LinkedList<>();
1069 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1070 reasons.add(linkEvent);
1071 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1072 reasons.add(linkEvent);
1073 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1074 reasons.add(linkEvent);
1075 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1076 reasons.add(linkEvent);
1077
1078 final TopologyEvent event = new TopologyEvent(
1079 TopologyEvent.Type.TOPOLOGY_CHANGED,
1080 topology,
1081 reasons);
1082
1083 //Change Topology : remove device2, device3 and all links
1084 Set<TopologyEdge> tempEdges = new HashSet<>();
1085 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1086 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1087 tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
1088 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1089 Set<TopologyVertex> tempVertexes = new HashSet<>();
1090 tempVertexes.add(D2);
1091 tempVertexes.add(D3);
1092 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1093 listener.event(event);
1094
1095 //No path
1096 assertThat(pathService.paths().size(), is(0));
1097 }
1098
1099 /**
1100 * Tests resilency when egress device is down.
1101 */
1102 @Test
1103 public void resilencyTest6() {
1104 build4RouterTopo(true, false, false, false, 10);
1105
1106 List<Constraint> constraints = new LinkedList<Constraint>();
1107 CostConstraint costConstraint = new CostConstraint(COST);
1108 constraints.add(costConstraint);
1109 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1110 constraints.add(localBwConst);
1111
1112 //Setup the path , tunnel created
1113 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1114 assertThat(result, is(true));
1115
1116 List<Event> reasons = new LinkedList<>();
1117 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1118 reasons.add(linkEvent);
1119 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1120 reasons.add(linkEvent);
1121
1122 final TopologyEvent event = new TopologyEvent(
1123 TopologyEvent.Type.TOPOLOGY_CHANGED,
1124 topology,
1125 reasons);
1126
1127 //Change Topology : remove device4 , link2 and link4
1128 Set<TopologyEdge> tempEdges = new HashSet<>();
1129 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1130 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1131 Set<TopologyVertex> tempVertexes = new HashSet<>();
1132 tempVertexes.add(D4);
1133 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1134 listener.event(event);
1135
1136 //No path
1137 assertThat(pathService.paths().size(), is(0));
1138 }
1139
1140 /**
1141 * Tests resilency when egress device is down.
1142 */
1143 @Test
1144 public void resilencyTest7() {
1145 build4RouterTopo(true, false, false, false, 10);
1146
1147 List<Constraint> constraints = new LinkedList<Constraint>();
1148 CostConstraint costConstraint = new CostConstraint(COST);
1149 constraints.add(costConstraint);
1150 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1151 constraints.add(localBwConst);
1152
1153 //Setup the path , tunnel created
1154 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1155 assertThat(result, is(true));
1156
1157 List<Event> reasons = new LinkedList<>();
1158 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1159 reasons.add(linkEvent);
1160 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1161 reasons.add(linkEvent);
1162
1163 final TopologyEvent event = new TopologyEvent(
1164 TopologyEvent.Type.TOPOLOGY_CHANGED,
1165 topology,
1166 reasons);
1167
1168 //Change Topology : remove device4 , link2 and link4
1169 Set<TopologyEdge> tempEdges = new HashSet<>();
1170 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1171 tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1172 Set<TopologyVertex> tempVertexes = new HashSet<>();
1173 tempVertexes.add(D4);
1174 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1175 listener.event(event);
1176
1177 //No path
1178 assertThat(pathService.paths().size(), is(0));
1179 }
1180
1181 /**
1182 * Tests resilency when D2 device is suspended.
1183 */
1184 @Test
1185 public void resilencyTest8() {
1186 build4RouterTopo(true, false, false, false, 10);
1187
1188 List<Constraint> constraints = new LinkedList<Constraint>();
1189 CostConstraint costConstraint = new CostConstraint(COST);
1190 constraints.add(costConstraint);
1191 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1192 constraints.add(localBwConst);
1193
1194 //Setup the path , tunnel created
1195 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1196 assertThat(result, is(true));
1197
1198 List<Event> reasons = new LinkedList<>();
1199 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1200 reasons.add(linkEvent);
1201 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1202 reasons.add(linkEvent);
1203
1204 final TopologyEvent event = new TopologyEvent(
1205 TopologyEvent.Type.TOPOLOGY_CHANGED,
1206 topology,
1207 reasons);
1208
1209 //Change Topology : remove device2 , link1 and link2
1210 Set<TopologyEdge> tempEdges = new HashSet<>();
1211 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1212 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1213 Set<TopologyVertex> tempVertexes = new HashSet<>();
1214 tempVertexes.add(D2);
1215 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1216 listener.event(event);
1217
1218 List<Link> links = new LinkedList<>();
1219 links.add(link3);
1220 links.add(link4);
1221
1222 //Path is D1-D3-D4
1223 assertThat(pathService.paths().iterator().next().links(), is(links));
1224 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1225 }
1226
1227 /**
1228 * Tests resilency when D2 device availability is changed.
1229 */
1230 @Test
1231 public void resilencyTest11() {
1232 build4RouterTopo(true, false, false, false, 10);
1233
1234 List<Constraint> constraints = new LinkedList<Constraint>();
1235 CostConstraint costConstraint = new CostConstraint(COST);
1236 constraints.add(costConstraint);
1237 BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1238 constraints.add(localBwConst);
1239
1240 //Setup the path , tunnel created
1241 boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1242 assertThat(result, is(true));
1243
1244 List<Event> reasons = new LinkedList<>();
1245 LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1246 reasons.add(linkEvent);
1247 linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1248 reasons.add(linkEvent);
1249
1250 final TopologyEvent event = new TopologyEvent(
1251 TopologyEvent.Type.TOPOLOGY_CHANGED,
1252 topology,
1253 reasons);
1254
1255 //Change Topology : remove device2 , link1 and link2
1256 Set<TopologyEdge> tempEdges = new HashSet<>();
1257 tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1258 tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1259 Set<TopologyVertex> tempVertexes = new HashSet<>();
1260 tempVertexes.add(D2);
1261 topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1262 listener.event(event);
1263
1264 List<Link> links = new LinkedList<>();
1265 links.add(link3);
1266 links.add(link4);
1267
1268 //Path is D1-D3-D4
1269 assertThat(pathService.paths().iterator().next().links(), is(links));
1270 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1271 }
1272
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301273 /*
1274 * Tests node label allocation/removal in SR-TE case based on device event.
1275 */
1276 @Test
1277 public void deviceEventTest() {
1278 // Make four router topology with SR-TE capabilities.
1279 build4RouterTopo(true, false, true, true, 0);
1280
1281 // Add new L3 device
1282 DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
1283 builderDev5.set(AnnotationKeys.TYPE, L3);
1284 builderDev5.set(LSRID, "5.5.5.5");
1285
1286 Device dev5 = new MockDevice(DeviceId.deviceId("P005"), builderDev5.build());
1287 deviceService.addDevice(dev5);
1288
1289 // Add capability
1290 DeviceCapability device5Cap = netConfigRegistry.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class);
1291 device5Cap.setLabelStackCap(true)
1292 .setLocalLabelCap(false)
1293 .setSrCap(true)
1294 .apply();
1295
1296 // Get listener
1297 DeviceListener listener = deviceService.getListener();
1298
1299 // Generate Remove events
1300 deviceService.removeDevice(dev5);
1301 DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, dev5);
1302 listener.event(event);
1303
1304 assertThat(pceStore.getGlobalNodeLabel(dev5.id()), is(nullValue()));
1305 }
1306
1307 /**
1308 * Tests adjacency label allocation/removal in SR-TE case based on link event.
1309 */
1310 @Test
1311 public void linkEventTest() {
1312 // Make four router topology with SR-TE capabilities.
1313 build4RouterTopo(true, false, true, true, 0);
1314
1315 // Get listener
1316 LinkListener listener = linkService.getListener();
1317
1318 // Adding link3
1319 linkService.addLink(link3);
1320
1321 // Generate events
1322 LinkEvent event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link3);
1323 listener.event(event);
1324
1325 assertThat(pceStore.getAdjLabel(link3), is(notNullValue()));
1326
1327 // Adding link4
1328 linkService.addLink(link4);
1329
1330 event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link4);
1331 listener.event(event);
1332
1333 assertThat(pceStore.getAdjLabel(link4), is(notNullValue()));
1334
1335 // Remove link3
1336 linkService.removeLink(link3);
1337
1338 // Generate events
1339 event = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1340 listener.event(event);
1341
1342 assertThat(pceStore.getAdjLabel(link3), is(nullValue()));
1343
1344 // Remove link4
1345 linkService.removeLink(link4);
1346
1347 event = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1348 listener.event(event);
1349
1350 assertThat(pceStore.getAdjLabel(link4), is(nullValue()));
1351 }
1352
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301353 @After
1354 public void tearDown() {
1355 pceManager.deactivate();
1356 pceManager.pathService = null;
1357 pceManager.resourceService = null;
1358 pceManager.tunnelService = null;
1359 pceManager.coreService = null;
1360 pceManager.storageService = null;
1361 pceManager.packetService = null;
1362 pceManager.deviceService = null;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301363 pceManager.linkService = null;
1364 pceManager.netCfgService = null;
1365 pceManager.labelRsrcAdminService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301366 pceManager.labelRsrcService = null;
1367 pceManager.flowObjectiveService = null;
1368 pceManager.pceStore = null;
Priyanka B3f92c5a2016-05-27 10:14:16 +05301369 pceManager.topologyService = null;
1370 pceManager.mastershipService = null;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301371 flowsDownloaded = 0;
1372 }
1373
1374 private class MockTopologyService extends TopologyServiceAdapter {
Priyanka B3f92c5a2016-05-27 10:14:16 +05301375 private void changeInTopology(TopologyGraph graphModified) {
1376 graph = graphModified;
1377 }
1378
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301379 @Override
1380 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
1381 DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
1382 DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
1383 Set<TopologyVertex> vertices = graph.getVertexes();
1384 if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
1385 // src or dst not part of the current graph
1386 return ImmutableSet.of();
1387 }
1388
1389 GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = PathComputationTest.graphSearch()
1390 .search(graph, srcV, dstV, weight, ALL_PATHS);
1391 ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
1392 for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
1393 builder.add(PathComputationTest.networkPath(path));
1394 }
1395 return builder.build();
1396 }
1397 }
1398
Priyanka B3f92c5a2016-05-27 10:14:16 +05301399 private TopologyGraph getGraph(Set<TopologyVertex> removedVertex, Set<TopologyEdge> removedEdges) {
1400 if (removedVertex != null) {
1401 vertexes.remove(removedVertex);
1402 removedVertex.forEach(v ->
1403 {
1404 vertexes.remove(v);
1405 });
1406 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301407
Priyanka B3f92c5a2016-05-27 10:14:16 +05301408 if (removedEdges != null) {
1409 removedEdges.forEach(e ->
1410 {
1411 edges.remove(e);
1412 });
1413 }
1414
1415 return new DefaultTopologyGraph(vertexes, edges);
1416 }
1417
1418 private class MockPathService extends PathServiceAdapter {
1419 Set<Path> computedPaths;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301420 @Override
1421 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
1422 // If either edge is null, bail with no paths.
1423 if (src == null || dst == null) {
1424 return ImmutableSet.of();
1425 }
1426
1427 // Otherwise get all paths between the source and destination edge
1428 // devices.
Priyanka B3f92c5a2016-05-27 10:14:16 +05301429 computedPaths = topologyService.getPaths(null, (DeviceId) src, (DeviceId) dst, weight);
1430 return computedPaths;
1431 }
1432
1433 private Set<Path> paths() {
1434 return computedPaths;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301435 }
1436 }
1437
1438 private class MockTunnelServiceAdapter extends TunnelServiceAdapter {
1439 private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<TunnelId, Tunnel>();
1440 private int tunnelIdCounter = 0;
1441
1442 @Override
1443 public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
1444 TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
1445 Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(),
1446 tunnel.state(), tunnel.groupId(), tunnelId, tunnel.tunnelName(),
1447 path, tunnel.annotations());
1448 tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert);
1449 return tunnelId;
1450 }
1451
1452 @Override
1453 public void addListener(TunnelListener listener) {
1454 tunnelListener = listener;
1455 }
1456
1457 /**
1458 * Stimulates the effect of receiving PLSP id and LSP id from protocol PCRpt msg.
1459 */
1460 public TunnelId updateTunnelWithLspIds(Tunnel tunnel, String pLspId, String localLspId, State state) {
1461 TunnelId tunnelId = tunnel.tunnelId();
1462 Builder annotationBuilder = DefaultAnnotations.builder();
1463 annotationBuilder.putAll(tunnel.annotations());
1464
1465 // PCRpt in response to PCInitate msg will carry PLSP id allocated by PCC.
1466 if (tunnel.annotations().value(PLSP_ID) == null) {
1467 annotationBuilder.set(PLSP_ID, pLspId);
1468 }
1469
1470 // Signalled LSPs will carry local LSP id allocated by signalling protocol(PCC).
1471 if (tunnel.annotations().value(LOCAL_LSP_ID) == null) {
1472 annotationBuilder.set(LOCAL_LSP_ID, localLspId);
1473 }
1474 SparseAnnotations annotations = annotationBuilder.build();
1475 tunnelIdAsKeyStore.remove(tunnelId, tunnel);
1476
1477 Tunnel tunnelToInsert = new DefaultTunnel(tunnel.providerId(), tunnel.src(), tunnel.dst(), tunnel.type(),
1478 state, tunnel.groupId(), tunnelId, tunnel.tunnelName(),
1479 tunnel.path(), annotations);
1480
1481 tunnelIdAsKeyStore.put(tunnelId, tunnelToInsert);
1482
1483 return tunnelId;
1484 }
1485
1486 @Override
1487 public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) {
1488 for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) {
1489 if (tunnelIdKey.equals(tunnelId)) {
1490 tunnelIdAsKeyStore.remove(tunnelId);
1491 return true;
1492 }
1493 }
1494 return false;
1495 }
1496
1497 @Override
1498 public Tunnel queryTunnel(TunnelId tunnelId) {
1499 for (TunnelId tunnelIdKey : tunnelIdAsKeyStore.keySet()) {
1500 if (tunnelIdKey.equals(tunnelId)) {
1501 return tunnelIdAsKeyStore.get(tunnelId);
1502 }
1503 }
1504 return null;
1505 }
1506
1507 @Override
1508 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
1509 Collection<Tunnel> result = new HashSet<Tunnel>();
1510 Tunnel tunnel = null;
1511 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1512 tunnel = tunnelIdAsKeyStore.get(tunnelId);
1513
1514 if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
1515 result.add(tunnel);
1516 }
1517 }
1518
1519 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
1520 }
1521
1522 @Override
1523 public Collection<Tunnel> queryTunnel(Tunnel.Type type) {
1524 Collection<Tunnel> result = new HashSet<Tunnel>();
1525
1526 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1527 result.add(tunnelIdAsKeyStore.get(tunnelId));
1528 }
1529
1530 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
1531 }
Priyanka B3f92c5a2016-05-27 10:14:16 +05301532
1533 @Override
1534 public Collection<Tunnel> queryAllTunnels() {
1535 Collection<Tunnel> result = new HashSet<Tunnel>();
1536
1537 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1538 result.add(tunnelIdAsKeyStore.get(tunnelId));
1539 }
1540
1541 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
1542 }
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301543
Priyanka B3f92c5a2016-05-27 10:14:16 +05301544 @Override
1545 public Iterable<Tunnel> getTunnels(DeviceId deviceId) {
1546 List<Tunnel> tunnelList = new LinkedList<>();
1547
1548 for (Tunnel t : tunnelIdAsKeyStore.values()) {
1549 for (Link l : t.path().links()) {
1550 if (l.src().deviceId().equals(deviceId) || l.dst().deviceId().equals(deviceId)) {
1551 tunnelList.add(t);
1552 break;
1553 }
1554 }
1555 }
1556 return tunnelList;
1557 }
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301558 }
1559
1560 public static class MockCoreService extends CoreServiceAdapter {
1561
1562 @Override
1563 public ApplicationId registerApplication(String name) {
1564 return new DefaultApplicationId(1, name);
1565 }
1566
1567 @Override
1568 public IdGenerator getIdGenerator(String topic) {
1569 return new IdGenerator() {
1570 private AtomicLong counter = new AtomicLong(0);
1571
1572 @Override
1573 public long getNewId() {
1574 return counter.getAndIncrement();
1575 }
1576 };
1577 }
1578 }
1579
1580 private class MockDevice extends DefaultDevice {
1581 MockDevice(DeviceId id, Annotations annotations) {
1582 super(null, id, null, null, null, null, null, null, annotations);
1583 }
1584 }
1585
Avantika-Huaweidbdf7722016-05-21 14:20:31 +05301586 private PacketProcessor pktProcessor = null;
1587
1588 private class MockPacketService extends PacketServiceAdapter {
1589 @Override
1590 public void addProcessor(PacketProcessor processor, int priority) {
1591 pktProcessor = processor;
1592 }
1593 }
1594
1595 // Minimal PacketContext to make core and applications happy.
1596 final class MockPcepPacketContext extends DefaultPacketContext {
1597 private MockPcepPacketContext(InboundPacket inPkt, OutboundPacket outPkt) {
1598 super(System.currentTimeMillis(), inPkt, outPkt, false);
1599 }
1600
1601 @Override
1602 public void send() {
1603 }
1604 }
1605
1606 public static class MockFlowObjService extends FlowObjServiceAdapter {
1607 @Override
1608 public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
1609 ++flowsDownloaded;
1610 }
1611 }
1612}