blob: c9c0537a003df50478095b2cc0d64faef43af2e3 [file] [log] [blame]
Avantika-Huawei56c11842016-04-28 00:56:56 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Avantika-Huawei56c11842016-04-28 00:56:56 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.provider.pcep.tunnel.impl;
17
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.core.Is.is;
20import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
21import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT;
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053022import static org.onosproject.pcep.server.PcepAnnotationKeys.BANDWIDTH;
23import static org.onosproject.pcep.server.PcepAnnotationKeys.LOCAL_LSP_ID;
24import static org.onosproject.pcep.server.PcepAnnotationKeys.LSP_SIG_TYPE;
25import static org.onosproject.pcep.server.PcepAnnotationKeys.PCC_TUNNEL_ID;
26import static org.onosproject.pcep.server.PcepAnnotationKeys.PLSP_ID;
27import static org.onosproject.pcep.server.PcepAnnotationKeys.DELEGATE;
28import static org.onosproject.pcep.server.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
29import static org.onosproject.pcep.server.PcepSyncStatus.SYNCED;
Priyanka B413fbe82016-05-26 11:44:45 +053030import static org.onosproject.net.Device.Type.ROUTER;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053031import static org.onosproject.net.Link.State.ACTIVE;
Priyanka B413fbe82016-05-26 11:44:45 +053032import static org.onosproject.net.MastershipRole.MASTER;
Avantika-Huawei56c11842016-04-28 00:56:56 +053033
34import java.io.IOException;
35import java.util.Collection;
36import java.util.Collections;
37import java.util.HashMap;
38import java.util.HashSet;
Priyanka B4c3b4512016-07-22 11:41:49 +053039import java.util.Iterator;
Priyanka B413fbe82016-05-26 11:44:45 +053040import java.util.LinkedList;
41import java.util.List;
42import java.util.concurrent.TimeUnit;
Avantika-Huawei56c11842016-04-28 00:56:56 +053043
44import org.jboss.netty.buffer.ChannelBuffer;
45import org.jboss.netty.buffer.ChannelBuffers;
46import org.junit.After;
47import org.junit.Before;
48import org.junit.Test;
Priyanka B413fbe82016-05-26 11:44:45 +053049import org.onlab.packet.ChassisId;
Avantika-Huawei56c11842016-04-28 00:56:56 +053050import org.onlab.packet.IpAddress;
51import org.onosproject.cfg.ComponentConfigAdapter;
52import org.onosproject.core.ApplicationId;
53import org.onosproject.incubator.net.tunnel.DefaultTunnel;
54import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
55import org.onosproject.incubator.net.tunnel.Tunnel;
Priyanka B413fbe82016-05-26 11:44:45 +053056import org.onosproject.incubator.net.tunnel.Tunnel.Type;
57import org.onosproject.incubator.net.tunnel.TunnelAdminService;
Avantika-Huawei56c11842016-04-28 00:56:56 +053058import org.onosproject.incubator.net.tunnel.TunnelDescription;
59import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
60import org.onosproject.incubator.net.tunnel.TunnelId;
61import org.onosproject.incubator.net.tunnel.TunnelName;
62import org.onosproject.incubator.net.tunnel.TunnelProvider;
63import org.onosproject.incubator.net.tunnel.TunnelProviderService;
64import org.onosproject.incubator.net.tunnel.Tunnel.State;
Priyanka B413fbe82016-05-26 11:44:45 +053065import org.onosproject.mastership.MastershipServiceAdapter;
66import org.onosproject.net.AnnotationKeys;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053067import org.onosproject.net.ConnectPoint;
Avantika-Huawei56c11842016-04-28 00:56:56 +053068import org.onosproject.net.DefaultAnnotations;
Priyanka B413fbe82016-05-26 11:44:45 +053069import org.onosproject.net.DefaultDevice;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053070import org.onosproject.net.DefaultLink;
Priyanka B413fbe82016-05-26 11:44:45 +053071import org.onosproject.net.Device;
72import org.onosproject.net.DeviceId;
Avantika-Huawei56c11842016-04-28 00:56:56 +053073import org.onosproject.net.ElementId;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053074import org.onosproject.net.Link;
Priyanka B413fbe82016-05-26 11:44:45 +053075import org.onosproject.net.MastershipRole;
Avantika-Huawei56c11842016-04-28 00:56:56 +053076import org.onosproject.net.Path;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053077import org.onosproject.net.PortNumber;
Avantika-Huawei56c11842016-04-28 00:56:56 +053078import org.onosproject.net.SparseAnnotations;
Priyanka B413fbe82016-05-26 11:44:45 +053079import org.onosproject.net.device.DeviceServiceAdapter;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053080import org.onosproject.net.link.LinkServiceAdapter;
Priyanka B413fbe82016-05-26 11:44:45 +053081import org.onosproject.net.provider.ProviderId;
Avantika-Huawei56c11842016-04-28 00:56:56 +053082import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
83import org.onosproject.pcepio.exceptions.PcepParseException;
84import org.onosproject.pcepio.protocol.PcepFactories;
85import org.onosproject.pcepio.protocol.PcepMessage;
86import org.onosproject.pcepio.protocol.PcepMessageReader;
Priyanka B413fbe82016-05-26 11:44:45 +053087import org.onosproject.pcepio.protocol.PcepVersion;
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053088import org.onosproject.pcep.server.ClientCapability;
89import org.onosproject.pcep.server.LspKey;
90import org.onosproject.pcep.server.PccId;
Avantika-Huawei56c11842016-04-28 00:56:56 +053091
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053092import com.google.common.collect.FluentIterable;
Avantika-Huawei56c11842016-04-28 00:56:56 +053093import com.google.common.collect.ImmutableSet;
94
95/**
96 * Tests handling of PCEP report message.
97 */
98public class PcepTunnelAddedTest {
99
Priyanka B413fbe82016-05-26 11:44:45 +0530100 public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
101 public static final String UNKOWN = "UNKOWN";
Avantika-Huawei56c11842016-04-28 00:56:56 +0530102 PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
103 private final MockTunnelProviderRegistryAdapter registry = new MockTunnelProviderRegistryAdapter();
104 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
105 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
106 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
107 private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
Priyanka B413fbe82016-05-26 11:44:45 +0530108 public final MockDeviceService deviceService = new MockDeviceService();
109 private final MockMasterShipService masterShipService = new MockMasterShipService();
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530110 private final MockLinkService linkService = new MockLinkService();
Priyanka B413fbe82016-05-26 11:44:45 +0530111 private final MockTunnelAdminService tunnelAdminService = new MockTunnelAdminService();
112
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530113 private class MockLinkService extends LinkServiceAdapter {
114 LinkedList<Link> links = new LinkedList<>();
115 void addLink(Link link) {
116 links.add(link);
117 }
118
119 @Override
120 public Iterable<Link> getActiveLinks() {
121
122 return FluentIterable.from(links)
123 .filter(input -> input.state() == ACTIVE);
124 }
125 }
126
Priyanka B413fbe82016-05-26 11:44:45 +0530127 private class MockTunnelAdminService implements TunnelAdminService {
128
129 @Override
130 public void removeTunnel(TunnelId tunnelId) {
131 // TODO Auto-generated method stub
132 }
133
134 @Override
135 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, ProviderId producerName) {
136 // TODO Auto-generated method stub
137 }
138
139 @Override
140 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Type type, ProviderId producerName) {
141 // TODO Auto-generated method stub
142 }
143
144 @Override
145 public void updateTunnel(Tunnel tunnel, Path path) {
146 if (tunnelService.tunnelIdAsKeyStore.containsKey(tunnel.tunnelId())) {
147 tunnelService.tunnelIdAsKeyStore.replace(tunnel.tunnelId(), tunnel);
148 }
149 }
tony-liu1abfb632016-11-09 15:22:51 +0800150
151 @Override
152 public void updateTunnelState(Tunnel tunnel, State state) {
153 // TODO Auto-generated method stub
154 }
Priyanka B413fbe82016-05-26 11:44:45 +0530155 }
156
157 private class MockMasterShipService extends MastershipServiceAdapter {
158 boolean set;
159
160 private void setMaster(boolean isMaster) {
161 this.set = isMaster;
162 }
163
164 @Override
165 public MastershipRole getLocalRole(DeviceId deviceId) {
166 return set ? MastershipRole.MASTER : MastershipRole.STANDBY;
167 }
168
169 @Override
170 public boolean isLocalMaster(DeviceId deviceId) {
171 return getLocalRole(deviceId) == MASTER;
172 }
173 }
174
175 private class MockDeviceService extends DeviceServiceAdapter {
176 List<Device> devices = new LinkedList<>();
177
178 private void addDevice(Device dev) {
179 devices.add(dev);
180 }
181
182 @Override
183 public Iterable<Device> getAvailableDevices() {
184 return devices;
185 }
186 }
Avantika-Huawei56c11842016-04-28 00:56:56 +0530187
188 private class MockTunnelProviderRegistryAdapter extends TunnelProviderRegistryAdapter {
189 public long tunnelIdCounter;
190
191 @Override
192 public TunnelProviderService register(TunnelProvider provider) {
193 this.provider = provider;
194 return new TestProviderService();
195 }
196
197 private class TestProviderService implements TunnelProviderService {
198
199 @Override
200 public TunnelProvider provider() {
201 return null;
202 }
203
204 @Override
205 public TunnelId tunnelAdded(TunnelDescription tunnel) {
Priyanka B413fbe82016-05-26 11:44:45 +0530206 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
207 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
208 tunnel.src(), tunnel.dst(),
209 tunnel.type(),
210 tunnel.groupId(),
211 id,
212 tunnel.tunnelName(),
213 tunnel.path(),
214 tunnel.resource(),
215 tunnel.annotations());
216 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
217 return id;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530218 }
219
220 @Override
221 public TunnelId tunnelAdded(TunnelDescription tunnel, State state) {
Priyanka B413fbe82016-05-26 11:44:45 +0530222 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
223 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
224 tunnel.src(), tunnel.dst(),
225 tunnel.type(),
226 tunnel.groupId(),
227 id,
228 tunnel.tunnelName(),
229 tunnel.path(),
230 tunnel.resource(),
231 tunnel.annotations());
232 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
233 return id;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530234 }
235
236 @Override
237 public void tunnelRemoved(TunnelDescription tunnel) {
238 }
239
240 @Override
241 public void tunnelUpdated(TunnelDescription tunnel) {
242 }
243
244 @Override
245 public void tunnelUpdated(TunnelDescription tunnel, State state) {
Priyanka B4c3b4512016-07-22 11:41:49 +0530246 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
247 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
248 tunnel.src(), tunnel.dst(),
249 tunnel.type(),
250 tunnel.groupId(),
251 id,
252 tunnel.tunnelName(),
253 tunnel.path(),
254 tunnel.resource(),
255 tunnel.annotations());
256 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530257 }
258
259 @Override
260 public Tunnel tunnelQueryById(TunnelId tunnelId) {
261 return null;
262 }
263 }
264 }
265
266 private class MockTunnelServiceAdapter extends TunnelServiceAdapter {
267 private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<>();
268 private int tunnelIdCounter = 0;
269
270 @Override
271 public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
272 TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
273 tunnelIdAsKeyStore.put(tunnelId, tunnel);
274 return tunnelId;
275 }
276
277 @Override
278 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
279 Collection<Tunnel> result = new HashSet<>();
280 Tunnel tunnel = null;
281 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
282 tunnel = tunnelIdAsKeyStore.get(tunnelId);
283
284 if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
285 result.add(tunnel);
286 }
287 }
288
289 return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
290 }
291
292 @Override
293 public Collection<Tunnel> queryAllTunnels() {
294 Collection<Tunnel> result = new HashSet<>();
295
296 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
297 result.add(tunnelIdAsKeyStore.get(tunnelId));
298 }
299
300 return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
301
302 }
303 }
304
305 @Before
306 public void preSetup() {
307 tunnelProvider.tunnelProviderRegistry = registry;
308 tunnelProvider.pcepClientController = controller;
309 tunnelProvider.controller = ctl;
Priyanka B413fbe82016-05-26 11:44:45 +0530310 tunnelProvider.deviceService = deviceService;
311 tunnelProvider.mastershipService = masterShipService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530312 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
313 tunnelProvider.cfgService = new ComponentConfigAdapter();
314 tunnelProvider.tunnelService = tunnelService;
Priyanka B413fbe82016-05-26 11:44:45 +0530315 tunnelProvider.tunnelAdminService = tunnelAdminService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530316 tunnelProvider.service = registry.register(tunnelProvider);
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530317 tunnelProvider.linkService = linkService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530318 tunnelProvider.activate();
319 }
320
321 /**
322 * Tests PCRpt msg with sync flag set.
323 */
324 @Test
325 public void tunnelProviderAddedTest1() throws PcepParseException, PcepOutOfBoundMessageException {
326 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
327 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
328 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
329 0x00, 0x00, 0x00, 0x02,
330 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
331 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
332 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
333 0x01, 0x01, 0x01, 0x01,
334 0x00, 0x01, 0x00, 0x01,
335 0x01, 0x01, 0x01, 0x01,
336 0x05, 0x05, 0x05, 0x05,
337
338 0x07, 0x10, 0x00, 0x14, //ERO object
339 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
340 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
341
342 0x08, 0x10, 0x00, 0x34, //RRO object
343 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
344 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
345 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
346 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
347 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
348 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
349 };
350
351 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
352 buffer.writeBytes(reportMsg);
353
354 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
355 PcepMessage message = reader.readFrom(buffer);
Priyanka B413fbe82016-05-26 11:44:45 +0530356
357 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
358 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
359 newBuilder.set(AnnotationKeys.TYPE, "L3");
360 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
361 UNKOWN, UNKOWN, UNKOWN,
362 UNKOWN, new ChassisId(),
363 newBuilder.build());
364
365 deviceService.addDevice(device);
366 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
367 new ClientCapability(true, true, true, true, true));
368 masterShipService.setMaster(true);
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530369 Link link = DefaultLink.builder()
370 .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
371 .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
372 .state(ACTIVE)
373 .type(Link.Type.DIRECT)
374 .providerId(ProviderId.NONE)
375 .build();
376 linkService.addLink(link);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530377 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
378
379 assertThat(registry.tunnelIdCounter, is((long) 1));
380 }
381
382 /**
383 * Tests updating an existing tunnel on receiving asynchronous PCRpt msg,
384 * i.e. without any SRP id.
385 */
386 @Test
387 public void tunnelProviderAddedTest2() throws PcepParseException, PcepOutOfBoundMessageException {
388 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x50,
389 0x21, 0x10, 0x00, 0x14, //SRP object
390 0x00, 0x00, 0x00, 0x00,
391 0x00, 0x00, 0x00, 0x00,
392 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
393 0x00, 0x00, 0x00, 0x02,
394 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, //LSP object
395 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path TLV
396 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
397 0x4e, 0x1f, 0x04, 0x00,
398 0x00, 0x01, 0x00, 0x01,
399 0x4e, 0x1f, 0x04, 0x00,
400 0x4e, 0x20, 0x04, 0x00,
401 0x07, 0x10, 0x00, 0x14, //ERO object
402 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, // ERO IPv4 sub objects
403 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
404 };
405
406 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
407 buffer.writeBytes(reportMsg);
408
409 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
410 PcepMessage message = reader.readFrom(buffer);
411
412 // create an existing tunnel.
413 IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e1f0400));
414 IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e200400));
415
416 SparseAnnotations annotations = DefaultAnnotations.builder()
417 .set(BANDWIDTH, (new Integer(1)).toString())
418 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
419 .set(PCC_TUNNEL_ID, String.valueOf(1))
420 .set(PLSP_ID, String.valueOf(1))
Priyanka B413fbe82016-05-26 11:44:45 +0530421 .set(LOCAL_LSP_ID, String.valueOf(1))
422 .set(DELEGATE, String.valueOf("true"))
423 .build();
Avantika-Huawei56c11842016-04-28 00:56:56 +0530424
425 Tunnel tunnel = new DefaultTunnel(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, INIT, null, null,
426 TunnelName.tunnelName("T123"), null, annotations);
427 tunnelService.setupTunnel(null, null, tunnel, null);
428
429 PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400));
Priyanka B413fbe82016-05-26 11:44:45 +0530430 PcepClientAdapter pc = new PcepClientAdapter();
431 pc.init(pccId, PcepVersion.PCEP_1);
432 masterShipService.setMaster(true);
433 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
434 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530435 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530436
437 // Process update message.
438 controller.processClientMessage(pccId, message);
439 assertThat(tunnelService.queryAllTunnels().size(), is(1));
440 }
441
442 /**
443 * Tests adding a new tunnel on receiving asynchronous PCRpt msg,
444 * i.e. without any SRP id.
445 */
446 @Test
447 public void tunnelProviderAddedTest3() throws PcepParseException, PcepOutOfBoundMessageException {
448 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
449 0x21, 0x10, 0x00, 0x14, //SRP object
450 0x00, 0x00, 0x00, 0x00,
451 0x00, 0x00, 0x00, 0x00,
452 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
453 0x00, 0x00, 0x00, 0x02,
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530454 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x1B, // LSP object
Avantika-Huawei56c11842016-04-28 00:56:56 +0530455 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
456 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
457 0x01, 0x01, 0x01, 0x01,
458 0x00, 0x01, 0x00, 0x01,
459 0x01, 0x01, 0x01, 0x01,
460 0x05, 0x05, 0x05, 0x05,
461
462 0x07, 0x10, 0x00, 0x14, //ERO object
463 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
464 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
465
466 0x08, 0x10, 0x00, 0x34, //RRO object
467 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
468 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
469 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
470 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
471 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
472 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
473 };
474
475 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
476 buffer.writeBytes(reportMsg);
477
478 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
479 PcepMessage message = reader.readFrom(buffer);
480
Priyanka B413fbe82016-05-26 11:44:45 +0530481 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
482 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
483 newBuilder.set(AnnotationKeys.TYPE, "L3");
484 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
485 UNKOWN, UNKOWN, UNKOWN,
486 UNKOWN, new ChassisId(),
487 newBuilder.build());
488
489 deviceService.addDevice(device);
490
Avantika-Huawei56c11842016-04-28 00:56:56 +0530491 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530492 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Priyanka B413fbe82016-05-26 11:44:45 +0530493 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
494
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530495 Link link = DefaultLink.builder()
496 .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
497 .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
498 .state(ACTIVE)
499 .type(Link.Type.DIRECT)
500 .providerId(ProviderId.NONE)
501 .build();
502 linkService.addLink(link);
Priyanka B413fbe82016-05-26 11:44:45 +0530503 PcepClientAdapter pc = new PcepClientAdapter();
504 pc.init(pccId, PcepVersion.PCEP_1);
505 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
506 masterShipService.setMaster(true);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530507 controller.processClientMessage(pccId, message);
508
509 assertThat(registry.tunnelIdCounter, is((long) 1));
510 }
511
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530512 /**
Priyanka B413fbe82016-05-26 11:44:45 +0530513 * Tests PCRpt msg with D flag set and delegated to non-master.
514 *
515 * @throws InterruptedException while waiting for delay
516 */
517 @Test
518 public void tunnelProviderAddedTest4() throws PcepParseException, PcepOutOfBoundMessageException,
519 InterruptedException {
520 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
521 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
522 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
523 0x00, 0x00, 0x00, 0x02,
524 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x02, //LSP object
525 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
526 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
527 0x01, 0x01, 0x01, 0x01,
528 0x00, 0x01, 0x00, 0x01,
529 0x01, 0x01, 0x01, 0x01,
530 0x05, 0x05, 0x05, 0x05,
531
532 0x07, 0x10, 0x00, 0x14, //ERO object
533 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
534 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
535
536 0x08, 0x10, 0x00, 0x34, //RRO object
537 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
538 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
539 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
540 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
541 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
542 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
543 };
544
545 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
546 buffer.writeBytes(reportMsg);
547
548 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
549 PcepMessage message = reader.readFrom(buffer);
550
551 //PCC 1.1.1.1, D=0, ONOS as master
552 masterShipService.setMaster(true);
553 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
554 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
555 newBuilder.set(AnnotationKeys.TYPE, "L3");
556 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
557 UNKOWN, UNKOWN, UNKOWN,
558 UNKOWN, new ChassisId(),
559 newBuilder.build());
560
561 deviceService.addDevice(device);
562 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
563 new ClientCapability(true, true, true, true, true));
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530564 Link link = DefaultLink.builder()
565 .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
566 .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
567 .state(ACTIVE)
568 .type(Link.Type.DIRECT)
569 .providerId(ProviderId.NONE)
570 .build();
571 linkService.addLink(link);
Priyanka B413fbe82016-05-26 11:44:45 +0530572 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
573 assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
574 is("false"));
575
576 //PCC 1.1.1.1, D=1, non-master
577 masterShipService.setMaster(false);
578
579 reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
580 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
581 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
582 0x00, 0x00, 0x00, 0x02,
583 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
584 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
585 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
586 0x01, 0x01, 0x01, 0x01,
587 0x00, 0x01, 0x00, 0x01,
588 0x01, 0x01, 0x01, 0x01,
589 0x05, 0x05, 0x05, 0x05,
590
591 0x07, 0x10, 0x00, 0x14, //ERO object
592 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
593 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
594
595 0x08, 0x10, 0x00, 0x34, //RRO object
596 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
597 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
598 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
599 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
600 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
601 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
602 };
603
604 buffer = ChannelBuffers.dynamicBuffer();
605 buffer.writeBytes(reportMsg);
606
607 reader = PcepFactories.getGenericReader();
608 message = reader.readFrom(buffer);
609
610 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
611 TimeUnit.MILLISECONDS.sleep(4000);
Priyanka B4c3b4512016-07-22 11:41:49 +0530612 assertThat(registry.tunnelIdCounter, is((long) 2));
613
614 Iterator<Tunnel> iterator = tunnelService.tunnelIdAsKeyStore.values().iterator();
615 iterator.next();
616 assertThat(iterator.next().annotations().value(DELEGATE),
Priyanka B413fbe82016-05-26 11:44:45 +0530617 is("true"));
618 }
619
620 /**
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530621 * Tests adding PCC Init LSP after LSP DB sync is over.
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530622 */
623 @Test
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530624 public void tunnelProviderAddedTest5() throws PcepParseException, PcepOutOfBoundMessageException {
625 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530626 0x21, 0x10, 0x00, 0x14, //SRP object
627 0x00, 0x00, 0x00, 0x00,
628 0x00, 0x00, 0x00, 0x00,
629 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530630 0x00, 0x00, 0x00, 0x02,
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530631 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530632 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530633 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
634 0x01, 0x01, 0x01, 0x01,
635 0x00, 0x01, 0x00, 0x01,
636 0x01, 0x01, 0x01, 0x01,
637 0x05, 0x05, 0x05, 0x05,
638
639 0x07, 0x10, 0x00, 0x14, //ERO object
640 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
641 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
642
643 0x08, 0x10, 0x00, 0x34, //RRO object
644 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
645 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
646 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
647 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
648 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
649 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
650 };
651
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530652 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
653 buffer.writeBytes(reportMsg);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530654
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530655 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
656 PcepMessage message = reader.readFrom(buffer);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530657
Priyanka B413fbe82016-05-26 11:44:45 +0530658 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
659 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
660 newBuilder.set(AnnotationKeys.TYPE, "L3");
661 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
662 UNKOWN, UNKOWN, UNKOWN,
663 UNKOWN, new ChassisId(),
664 newBuilder.build());
665
666 deviceService.addDevice(device);
667
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530668 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530669 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Priyanka B413fbe82016-05-26 11:44:45 +0530670 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
671
672 PcepClientAdapter pc = new PcepClientAdapter();
673 pc.init(pccId, PcepVersion.PCEP_1);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530674 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
Priyanka B413fbe82016-05-26 11:44:45 +0530675 masterShipService.setMaster(true);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530676 controller.processClientMessage(pccId, message);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530677
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530678 assertThat(registry.tunnelIdCounter, is((long) 0));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530679 }
680
Avantika-Huawei56c11842016-04-28 00:56:56 +0530681 @After
682 public void tearDown() throws IOException {
683 tunnelProvider.deactivate();
684 tunnelProvider.controller = null;
685 tunnelProvider.pcepClientController = null;
686 tunnelProvider.tunnelProviderRegistry = null;
687
688 tunnelProvider.pcepTunnelApiMapper = null;
689 tunnelProvider.cfgService = null;
690 tunnelProvider.tunnelService = null;
Priyanka B413fbe82016-05-26 11:44:45 +0530691 tunnelProvider.tunnelAdminService = null;
692 tunnelProvider.deviceService = null;
693 tunnelProvider.mastershipService = null;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530694 tunnelProvider.linkService = null;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530695 tunnelProvider.service = null;
696 }
697}