blob: 17a62d8367acce2b9f6e4f6d0af32c798bb936be [file] [log] [blame]
Avantika-Huawei56c11842016-04-28 00:56:56 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
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;
Avantika-Huaweifc10dca2016-06-10 16:13:55 +053022import static org.onosproject.pcep.controller.PcepAnnotationKeys.BANDWIDTH;
23import static org.onosproject.pcep.controller.PcepAnnotationKeys.LOCAL_LSP_ID;
24import static org.onosproject.pcep.controller.PcepAnnotationKeys.LSP_SIG_TYPE;
25import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCC_TUNNEL_ID;
26import static org.onosproject.pcep.controller.PcepAnnotationKeys.PLSP_ID;
27import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE;
Avantika-Huawei3c2d3eb2016-06-22 09:34:00 +053028import static org.onosproject.pcep.controller.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
Avantika-Huawei7f7376a2016-05-11 17:07:50 +053029import static org.onosproject.pcep.controller.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;
Avantika-Huawei56c11842016-04-28 00:56:56 +053088import org.onosproject.pcep.controller.ClientCapability;
Priyanka B413fbe82016-05-26 11:44:45 +053089import org.onosproject.pcep.controller.LspKey;
Avantika-Huawei56c11842016-04-28 00:56:56 +053090import org.onosproject.pcep.controller.PccId;
91
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 }
150 }
151
152 private class MockMasterShipService extends MastershipServiceAdapter {
153 boolean set;
154
155 private void setMaster(boolean isMaster) {
156 this.set = isMaster;
157 }
158
159 @Override
160 public MastershipRole getLocalRole(DeviceId deviceId) {
161 return set ? MastershipRole.MASTER : MastershipRole.STANDBY;
162 }
163
164 @Override
165 public boolean isLocalMaster(DeviceId deviceId) {
166 return getLocalRole(deviceId) == MASTER;
167 }
168 }
169
170 private class MockDeviceService extends DeviceServiceAdapter {
171 List<Device> devices = new LinkedList<>();
172
173 private void addDevice(Device dev) {
174 devices.add(dev);
175 }
176
177 @Override
178 public Iterable<Device> getAvailableDevices() {
179 return devices;
180 }
181 }
Avantika-Huawei56c11842016-04-28 00:56:56 +0530182
183 private class MockTunnelProviderRegistryAdapter extends TunnelProviderRegistryAdapter {
184 public long tunnelIdCounter;
185
186 @Override
187 public TunnelProviderService register(TunnelProvider provider) {
188 this.provider = provider;
189 return new TestProviderService();
190 }
191
192 private class TestProviderService implements TunnelProviderService {
193
194 @Override
195 public TunnelProvider provider() {
196 return null;
197 }
198
199 @Override
200 public TunnelId tunnelAdded(TunnelDescription tunnel) {
Priyanka B413fbe82016-05-26 11:44:45 +0530201 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
202 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
203 tunnel.src(), tunnel.dst(),
204 tunnel.type(),
205 tunnel.groupId(),
206 id,
207 tunnel.tunnelName(),
208 tunnel.path(),
209 tunnel.resource(),
210 tunnel.annotations());
211 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
212 return id;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530213 }
214
215 @Override
216 public TunnelId tunnelAdded(TunnelDescription tunnel, State state) {
Priyanka B413fbe82016-05-26 11:44:45 +0530217 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
218 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
219 tunnel.src(), tunnel.dst(),
220 tunnel.type(),
221 tunnel.groupId(),
222 id,
223 tunnel.tunnelName(),
224 tunnel.path(),
225 tunnel.resource(),
226 tunnel.annotations());
227 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
228 return id;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530229 }
230
231 @Override
232 public void tunnelRemoved(TunnelDescription tunnel) {
233 }
234
235 @Override
236 public void tunnelUpdated(TunnelDescription tunnel) {
237 }
238
239 @Override
240 public void tunnelUpdated(TunnelDescription tunnel, State state) {
Priyanka B4c3b4512016-07-22 11:41:49 +0530241 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
242 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
243 tunnel.src(), tunnel.dst(),
244 tunnel.type(),
245 tunnel.groupId(),
246 id,
247 tunnel.tunnelName(),
248 tunnel.path(),
249 tunnel.resource(),
250 tunnel.annotations());
251 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530252 }
253
254 @Override
255 public Tunnel tunnelQueryById(TunnelId tunnelId) {
256 return null;
257 }
258 }
259 }
260
261 private class MockTunnelServiceAdapter extends TunnelServiceAdapter {
262 private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<>();
263 private int tunnelIdCounter = 0;
264
265 @Override
266 public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
267 TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
268 tunnelIdAsKeyStore.put(tunnelId, tunnel);
269 return tunnelId;
270 }
271
272 @Override
273 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
274 Collection<Tunnel> result = new HashSet<>();
275 Tunnel tunnel = null;
276 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
277 tunnel = tunnelIdAsKeyStore.get(tunnelId);
278
279 if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
280 result.add(tunnel);
281 }
282 }
283
284 return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
285 }
286
287 @Override
288 public Collection<Tunnel> queryAllTunnels() {
289 Collection<Tunnel> result = new HashSet<>();
290
291 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
292 result.add(tunnelIdAsKeyStore.get(tunnelId));
293 }
294
295 return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
296
297 }
298 }
299
300 @Before
301 public void preSetup() {
302 tunnelProvider.tunnelProviderRegistry = registry;
303 tunnelProvider.pcepClientController = controller;
304 tunnelProvider.controller = ctl;
Priyanka B413fbe82016-05-26 11:44:45 +0530305 tunnelProvider.deviceService = deviceService;
306 tunnelProvider.mastershipService = masterShipService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530307 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
308 tunnelProvider.cfgService = new ComponentConfigAdapter();
309 tunnelProvider.tunnelService = tunnelService;
Priyanka B413fbe82016-05-26 11:44:45 +0530310 tunnelProvider.tunnelAdminService = tunnelAdminService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530311 tunnelProvider.service = registry.register(tunnelProvider);
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530312 tunnelProvider.linkService = linkService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530313 tunnelProvider.activate();
314 }
315
316 /**
317 * Tests PCRpt msg with sync flag set.
318 */
319 @Test
320 public void tunnelProviderAddedTest1() throws PcepParseException, PcepOutOfBoundMessageException {
321 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
322 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
323 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
324 0x00, 0x00, 0x00, 0x02,
325 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
326 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
327 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
328 0x01, 0x01, 0x01, 0x01,
329 0x00, 0x01, 0x00, 0x01,
330 0x01, 0x01, 0x01, 0x01,
331 0x05, 0x05, 0x05, 0x05,
332
333 0x07, 0x10, 0x00, 0x14, //ERO object
334 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
335 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
336
337 0x08, 0x10, 0x00, 0x34, //RRO object
338 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
339 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
340 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
341 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
342 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
343 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
344 };
345
346 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
347 buffer.writeBytes(reportMsg);
348
349 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
350 PcepMessage message = reader.readFrom(buffer);
Priyanka B413fbe82016-05-26 11:44:45 +0530351
352 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
353 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
354 newBuilder.set(AnnotationKeys.TYPE, "L3");
355 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
356 UNKOWN, UNKOWN, UNKOWN,
357 UNKOWN, new ChassisId(),
358 newBuilder.build());
359
360 deviceService.addDevice(device);
361 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
362 new ClientCapability(true, true, true, true, true));
363 masterShipService.setMaster(true);
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530364 Link link = DefaultLink.builder()
365 .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
366 .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
367 .state(ACTIVE)
368 .type(Link.Type.DIRECT)
369 .providerId(ProviderId.NONE)
370 .build();
371 linkService.addLink(link);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530372 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
373
374 assertThat(registry.tunnelIdCounter, is((long) 1));
375 }
376
377 /**
378 * Tests updating an existing tunnel on receiving asynchronous PCRpt msg,
379 * i.e. without any SRP id.
380 */
381 @Test
382 public void tunnelProviderAddedTest2() throws PcepParseException, PcepOutOfBoundMessageException {
383 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x50,
384 0x21, 0x10, 0x00, 0x14, //SRP object
385 0x00, 0x00, 0x00, 0x00,
386 0x00, 0x00, 0x00, 0x00,
387 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
388 0x00, 0x00, 0x00, 0x02,
389 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, //LSP object
390 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path TLV
391 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
392 0x4e, 0x1f, 0x04, 0x00,
393 0x00, 0x01, 0x00, 0x01,
394 0x4e, 0x1f, 0x04, 0x00,
395 0x4e, 0x20, 0x04, 0x00,
396 0x07, 0x10, 0x00, 0x14, //ERO object
397 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, // ERO IPv4 sub objects
398 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
399 };
400
401 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
402 buffer.writeBytes(reportMsg);
403
404 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
405 PcepMessage message = reader.readFrom(buffer);
406
407 // create an existing tunnel.
408 IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e1f0400));
409 IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e200400));
410
411 SparseAnnotations annotations = DefaultAnnotations.builder()
412 .set(BANDWIDTH, (new Integer(1)).toString())
413 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
414 .set(PCC_TUNNEL_ID, String.valueOf(1))
415 .set(PLSP_ID, String.valueOf(1))
Priyanka B413fbe82016-05-26 11:44:45 +0530416 .set(LOCAL_LSP_ID, String.valueOf(1))
417 .set(DELEGATE, String.valueOf("true"))
418 .build();
Avantika-Huawei56c11842016-04-28 00:56:56 +0530419
420 Tunnel tunnel = new DefaultTunnel(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, INIT, null, null,
421 TunnelName.tunnelName("T123"), null, annotations);
422 tunnelService.setupTunnel(null, null, tunnel, null);
423
424 PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400));
Priyanka B413fbe82016-05-26 11:44:45 +0530425 PcepClientAdapter pc = new PcepClientAdapter();
426 pc.init(pccId, PcepVersion.PCEP_1);
427 masterShipService.setMaster(true);
428 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
429 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530430 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530431
432 // Process update message.
433 controller.processClientMessage(pccId, message);
434 assertThat(tunnelService.queryAllTunnels().size(), is(1));
435 }
436
437 /**
438 * Tests adding a new tunnel on receiving asynchronous PCRpt msg,
439 * i.e. without any SRP id.
440 */
441 @Test
442 public void tunnelProviderAddedTest3() throws PcepParseException, PcepOutOfBoundMessageException {
443 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
444 0x21, 0x10, 0x00, 0x14, //SRP object
445 0x00, 0x00, 0x00, 0x00,
446 0x00, 0x00, 0x00, 0x00,
447 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
448 0x00, 0x00, 0x00, 0x02,
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530449 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x1B, // LSP object
Avantika-Huawei56c11842016-04-28 00:56:56 +0530450 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
451 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
452 0x01, 0x01, 0x01, 0x01,
453 0x00, 0x01, 0x00, 0x01,
454 0x01, 0x01, 0x01, 0x01,
455 0x05, 0x05, 0x05, 0x05,
456
457 0x07, 0x10, 0x00, 0x14, //ERO object
458 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
459 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
460
461 0x08, 0x10, 0x00, 0x34, //RRO object
462 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
463 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
464 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
465 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
466 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
467 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
468 };
469
470 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
471 buffer.writeBytes(reportMsg);
472
473 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
474 PcepMessage message = reader.readFrom(buffer);
475
Priyanka B413fbe82016-05-26 11:44:45 +0530476 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
477 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
478 newBuilder.set(AnnotationKeys.TYPE, "L3");
479 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
480 UNKOWN, UNKOWN, UNKOWN,
481 UNKOWN, new ChassisId(),
482 newBuilder.build());
483
484 deviceService.addDevice(device);
485
Avantika-Huawei56c11842016-04-28 00:56:56 +0530486 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530487 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Priyanka B413fbe82016-05-26 11:44:45 +0530488 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
489
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530490 Link link = DefaultLink.builder()
491 .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
492 .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
493 .state(ACTIVE)
494 .type(Link.Type.DIRECT)
495 .providerId(ProviderId.NONE)
496 .build();
497 linkService.addLink(link);
Priyanka B413fbe82016-05-26 11:44:45 +0530498 PcepClientAdapter pc = new PcepClientAdapter();
499 pc.init(pccId, PcepVersion.PCEP_1);
500 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
501 masterShipService.setMaster(true);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530502 controller.processClientMessage(pccId, message);
503
504 assertThat(registry.tunnelIdCounter, is((long) 1));
505 }
506
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530507 /**
Priyanka B413fbe82016-05-26 11:44:45 +0530508 * Tests PCRpt msg with D flag set and delegated to non-master.
509 *
510 * @throws InterruptedException while waiting for delay
511 */
512 @Test
513 public void tunnelProviderAddedTest4() throws PcepParseException, PcepOutOfBoundMessageException,
514 InterruptedException {
515 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
516 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
517 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
518 0x00, 0x00, 0x00, 0x02,
519 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x02, //LSP object
520 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
521 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
522 0x01, 0x01, 0x01, 0x01,
523 0x00, 0x01, 0x00, 0x01,
524 0x01, 0x01, 0x01, 0x01,
525 0x05, 0x05, 0x05, 0x05,
526
527 0x07, 0x10, 0x00, 0x14, //ERO object
528 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
529 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
530
531 0x08, 0x10, 0x00, 0x34, //RRO object
532 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
533 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
534 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
535 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
536 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
537 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
538 };
539
540 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
541 buffer.writeBytes(reportMsg);
542
543 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
544 PcepMessage message = reader.readFrom(buffer);
545
546 //PCC 1.1.1.1, D=0, ONOS as master
547 masterShipService.setMaster(true);
548 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
549 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
550 newBuilder.set(AnnotationKeys.TYPE, "L3");
551 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
552 UNKOWN, UNKOWN, UNKOWN,
553 UNKOWN, new ChassisId(),
554 newBuilder.build());
555
556 deviceService.addDevice(device);
557 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
558 new ClientCapability(true, true, true, true, true));
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530559 Link link = DefaultLink.builder()
560 .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
561 .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
562 .state(ACTIVE)
563 .type(Link.Type.DIRECT)
564 .providerId(ProviderId.NONE)
565 .build();
566 linkService.addLink(link);
Priyanka B413fbe82016-05-26 11:44:45 +0530567 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
568 assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
569 is("false"));
570
571 //PCC 1.1.1.1, D=1, non-master
572 masterShipService.setMaster(false);
573
574 reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
575 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
576 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
577 0x00, 0x00, 0x00, 0x02,
578 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
579 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
580 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
581 0x01, 0x01, 0x01, 0x01,
582 0x00, 0x01, 0x00, 0x01,
583 0x01, 0x01, 0x01, 0x01,
584 0x05, 0x05, 0x05, 0x05,
585
586 0x07, 0x10, 0x00, 0x14, //ERO object
587 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
588 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
589
590 0x08, 0x10, 0x00, 0x34, //RRO object
591 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
592 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
593 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
594 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
595 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
596 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
597 };
598
599 buffer = ChannelBuffers.dynamicBuffer();
600 buffer.writeBytes(reportMsg);
601
602 reader = PcepFactories.getGenericReader();
603 message = reader.readFrom(buffer);
604
605 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
606 TimeUnit.MILLISECONDS.sleep(4000);
Priyanka B4c3b4512016-07-22 11:41:49 +0530607 assertThat(registry.tunnelIdCounter, is((long) 2));
608
609 Iterator<Tunnel> iterator = tunnelService.tunnelIdAsKeyStore.values().iterator();
610 iterator.next();
611 assertThat(iterator.next().annotations().value(DELEGATE),
Priyanka B413fbe82016-05-26 11:44:45 +0530612 is("true"));
613 }
614
615 /**
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530616 * Tests adding PCC Init LSP after LSP DB sync is over.
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530617 */
618 @Test
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530619 public void tunnelProviderAddedTest5() throws PcepParseException, PcepOutOfBoundMessageException {
620 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530621 0x21, 0x10, 0x00, 0x14, //SRP object
622 0x00, 0x00, 0x00, 0x00,
623 0x00, 0x00, 0x00, 0x00,
624 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530625 0x00, 0x00, 0x00, 0x02,
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530626 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530627 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530628 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
629 0x01, 0x01, 0x01, 0x01,
630 0x00, 0x01, 0x00, 0x01,
631 0x01, 0x01, 0x01, 0x01,
632 0x05, 0x05, 0x05, 0x05,
633
634 0x07, 0x10, 0x00, 0x14, //ERO object
635 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
636 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
637
638 0x08, 0x10, 0x00, 0x34, //RRO object
639 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
640 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
641 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
642 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
643 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
644 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
645 };
646
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530647 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
648 buffer.writeBytes(reportMsg);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530649
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530650 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
651 PcepMessage message = reader.readFrom(buffer);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530652
Priyanka B413fbe82016-05-26 11:44:45 +0530653 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
654 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
655 newBuilder.set(AnnotationKeys.TYPE, "L3");
656 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
657 UNKOWN, UNKOWN, UNKOWN,
658 UNKOWN, new ChassisId(),
659 newBuilder.build());
660
661 deviceService.addDevice(device);
662
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530663 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530664 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Priyanka B413fbe82016-05-26 11:44:45 +0530665 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
666
667 PcepClientAdapter pc = new PcepClientAdapter();
668 pc.init(pccId, PcepVersion.PCEP_1);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530669 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
Priyanka B413fbe82016-05-26 11:44:45 +0530670 masterShipService.setMaster(true);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530671 controller.processClientMessage(pccId, message);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530672
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530673 assertThat(registry.tunnelIdCounter, is((long) 0));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530674 }
675
Avantika-Huawei56c11842016-04-28 00:56:56 +0530676 @After
677 public void tearDown() throws IOException {
678 tunnelProvider.deactivate();
679 tunnelProvider.controller = null;
680 tunnelProvider.pcepClientController = null;
681 tunnelProvider.tunnelProviderRegistry = null;
682
683 tunnelProvider.pcepTunnelApiMapper = null;
684 tunnelProvider.cfgService = null;
685 tunnelProvider.tunnelService = null;
Priyanka B413fbe82016-05-26 11:44:45 +0530686 tunnelProvider.tunnelAdminService = null;
687 tunnelProvider.deviceService = null;
688 tunnelProvider.mastershipService = null;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530689 tunnelProvider.linkService = null;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530690 tunnelProvider.service = null;
691 }
692}