blob: ce00b5e963e3025ca2cd8d98d0cfe4cda1562068 [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;
22import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.BANDWIDTH;
23import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LOCAL_LSP_ID;
24import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
25import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID;
26import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID;
Priyanka B413fbe82016-05-26 11:44:45 +053027import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.DELEGATE;
Avantika-Huawei56c11842016-04-28 00:56:56 +053028import static org.onosproject.provider.pcep.tunnel.impl.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;
31import static org.onosproject.net.MastershipRole.MASTER;
Avantika-Huawei56c11842016-04-28 00:56:56 +053032
33import java.io.IOException;
34import java.util.Collection;
35import java.util.Collections;
36import java.util.HashMap;
37import java.util.HashSet;
Priyanka B413fbe82016-05-26 11:44:45 +053038import java.util.LinkedList;
39import java.util.List;
40import java.util.concurrent.TimeUnit;
Avantika-Huawei56c11842016-04-28 00:56:56 +053041
42import org.jboss.netty.buffer.ChannelBuffer;
43import org.jboss.netty.buffer.ChannelBuffers;
44import org.junit.After;
45import org.junit.Before;
46import org.junit.Test;
Priyanka B413fbe82016-05-26 11:44:45 +053047import org.onlab.packet.ChassisId;
Avantika-Huawei56c11842016-04-28 00:56:56 +053048import org.onlab.packet.IpAddress;
49import org.onosproject.cfg.ComponentConfigAdapter;
50import org.onosproject.core.ApplicationId;
51import org.onosproject.incubator.net.tunnel.DefaultTunnel;
52import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
53import org.onosproject.incubator.net.tunnel.Tunnel;
Priyanka B413fbe82016-05-26 11:44:45 +053054import org.onosproject.incubator.net.tunnel.Tunnel.Type;
55import org.onosproject.incubator.net.tunnel.TunnelAdminService;
Avantika-Huawei56c11842016-04-28 00:56:56 +053056import org.onosproject.incubator.net.tunnel.TunnelDescription;
57import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
58import org.onosproject.incubator.net.tunnel.TunnelId;
59import org.onosproject.incubator.net.tunnel.TunnelName;
60import org.onosproject.incubator.net.tunnel.TunnelProvider;
61import org.onosproject.incubator.net.tunnel.TunnelProviderService;
62import org.onosproject.incubator.net.tunnel.Tunnel.State;
Priyanka B413fbe82016-05-26 11:44:45 +053063import org.onosproject.mastership.MastershipServiceAdapter;
64import org.onosproject.net.AnnotationKeys;
Avantika-Huawei56c11842016-04-28 00:56:56 +053065import org.onosproject.net.DefaultAnnotations;
Priyanka B413fbe82016-05-26 11:44:45 +053066import org.onosproject.net.DefaultDevice;
67import org.onosproject.net.Device;
68import org.onosproject.net.DeviceId;
Avantika-Huawei56c11842016-04-28 00:56:56 +053069import org.onosproject.net.ElementId;
Priyanka B413fbe82016-05-26 11:44:45 +053070import org.onosproject.net.MastershipRole;
Avantika-Huawei56c11842016-04-28 00:56:56 +053071import org.onosproject.net.Path;
72import org.onosproject.net.SparseAnnotations;
Priyanka B413fbe82016-05-26 11:44:45 +053073import org.onosproject.net.device.DeviceServiceAdapter;
74import org.onosproject.net.provider.ProviderId;
Avantika-Huawei56c11842016-04-28 00:56:56 +053075import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
76import org.onosproject.pcepio.exceptions.PcepParseException;
77import org.onosproject.pcepio.protocol.PcepFactories;
78import org.onosproject.pcepio.protocol.PcepMessage;
79import org.onosproject.pcepio.protocol.PcepMessageReader;
Priyanka B413fbe82016-05-26 11:44:45 +053080import org.onosproject.pcepio.protocol.PcepVersion;
Avantika-Huawei56c11842016-04-28 00:56:56 +053081import org.onosproject.pcep.controller.ClientCapability;
Priyanka B413fbe82016-05-26 11:44:45 +053082import org.onosproject.pcep.controller.LspKey;
Avantika-Huawei56c11842016-04-28 00:56:56 +053083import org.onosproject.pcep.controller.PccId;
84
85import com.google.common.collect.ImmutableSet;
86
87/**
88 * Tests handling of PCEP report message.
89 */
90public class PcepTunnelAddedTest {
91
Priyanka B413fbe82016-05-26 11:44:45 +053092 public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
93 public static final String UNKOWN = "UNKOWN";
Avantika-Huawei56c11842016-04-28 00:56:56 +053094 PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
95 private final MockTunnelProviderRegistryAdapter registry = new MockTunnelProviderRegistryAdapter();
96 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
97 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
98 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
99 private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
Priyanka B413fbe82016-05-26 11:44:45 +0530100 public final MockDeviceService deviceService = new MockDeviceService();
101 private final MockMasterShipService masterShipService = new MockMasterShipService();
102 private final MockTunnelAdminService tunnelAdminService = new MockTunnelAdminService();
103
104 private class MockTunnelAdminService implements TunnelAdminService {
105
106 @Override
107 public void removeTunnel(TunnelId tunnelId) {
108 // TODO Auto-generated method stub
109 }
110
111 @Override
112 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, ProviderId producerName) {
113 // TODO Auto-generated method stub
114 }
115
116 @Override
117 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Type type, ProviderId producerName) {
118 // TODO Auto-generated method stub
119 }
120
121 @Override
122 public void updateTunnel(Tunnel tunnel, Path path) {
123 if (tunnelService.tunnelIdAsKeyStore.containsKey(tunnel.tunnelId())) {
124 tunnelService.tunnelIdAsKeyStore.replace(tunnel.tunnelId(), tunnel);
125 }
126 }
127 }
128
129 private class MockMasterShipService extends MastershipServiceAdapter {
130 boolean set;
131
132 private void setMaster(boolean isMaster) {
133 this.set = isMaster;
134 }
135
136 @Override
137 public MastershipRole getLocalRole(DeviceId deviceId) {
138 return set ? MastershipRole.MASTER : MastershipRole.STANDBY;
139 }
140
141 @Override
142 public boolean isLocalMaster(DeviceId deviceId) {
143 return getLocalRole(deviceId) == MASTER;
144 }
145 }
146
147 private class MockDeviceService extends DeviceServiceAdapter {
148 List<Device> devices = new LinkedList<>();
149
150 private void addDevice(Device dev) {
151 devices.add(dev);
152 }
153
154 @Override
155 public Iterable<Device> getAvailableDevices() {
156 return devices;
157 }
158 }
Avantika-Huawei56c11842016-04-28 00:56:56 +0530159
160 private class MockTunnelProviderRegistryAdapter extends TunnelProviderRegistryAdapter {
161 public long tunnelIdCounter;
162
163 @Override
164 public TunnelProviderService register(TunnelProvider provider) {
165 this.provider = provider;
166 return new TestProviderService();
167 }
168
169 private class TestProviderService implements TunnelProviderService {
170
171 @Override
172 public TunnelProvider provider() {
173 return null;
174 }
175
176 @Override
177 public TunnelId tunnelAdded(TunnelDescription tunnel) {
Priyanka B413fbe82016-05-26 11:44:45 +0530178 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
179 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
180 tunnel.src(), tunnel.dst(),
181 tunnel.type(),
182 tunnel.groupId(),
183 id,
184 tunnel.tunnelName(),
185 tunnel.path(),
186 tunnel.resource(),
187 tunnel.annotations());
188 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
189 return id;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530190 }
191
192 @Override
193 public TunnelId tunnelAdded(TunnelDescription tunnel, State state) {
Priyanka B413fbe82016-05-26 11:44:45 +0530194 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
195 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
196 tunnel.src(), tunnel.dst(),
197 tunnel.type(),
198 tunnel.groupId(),
199 id,
200 tunnel.tunnelName(),
201 tunnel.path(),
202 tunnel.resource(),
203 tunnel.annotations());
204 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
205 return id;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530206 }
207
208 @Override
209 public void tunnelRemoved(TunnelDescription tunnel) {
210 }
211
212 @Override
213 public void tunnelUpdated(TunnelDescription tunnel) {
214 }
215
216 @Override
217 public void tunnelUpdated(TunnelDescription tunnel, State state) {
218 }
219
220 @Override
221 public Tunnel tunnelQueryById(TunnelId tunnelId) {
222 return null;
223 }
224 }
225 }
226
227 private class MockTunnelServiceAdapter extends TunnelServiceAdapter {
228 private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<>();
229 private int tunnelIdCounter = 0;
230
231 @Override
232 public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
233 TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
234 tunnelIdAsKeyStore.put(tunnelId, tunnel);
235 return tunnelId;
236 }
237
238 @Override
239 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
240 Collection<Tunnel> result = new HashSet<>();
241 Tunnel tunnel = null;
242 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
243 tunnel = tunnelIdAsKeyStore.get(tunnelId);
244
245 if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
246 result.add(tunnel);
247 }
248 }
249
250 return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
251 }
252
253 @Override
254 public Collection<Tunnel> queryAllTunnels() {
255 Collection<Tunnel> result = new HashSet<>();
256
257 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
258 result.add(tunnelIdAsKeyStore.get(tunnelId));
259 }
260
261 return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
262
263 }
264 }
265
266 @Before
267 public void preSetup() {
268 tunnelProvider.tunnelProviderRegistry = registry;
269 tunnelProvider.pcepClientController = controller;
270 tunnelProvider.controller = ctl;
Priyanka B413fbe82016-05-26 11:44:45 +0530271 tunnelProvider.deviceService = deviceService;
272 tunnelProvider.mastershipService = masterShipService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530273 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
274 tunnelProvider.cfgService = new ComponentConfigAdapter();
275 tunnelProvider.tunnelService = tunnelService;
Priyanka B413fbe82016-05-26 11:44:45 +0530276 tunnelProvider.tunnelAdminService = tunnelAdminService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530277 tunnelProvider.service = registry.register(tunnelProvider);
278 tunnelProvider.activate();
279 }
280
281 /**
282 * Tests PCRpt msg with sync flag set.
283 */
284 @Test
285 public void tunnelProviderAddedTest1() throws PcepParseException, PcepOutOfBoundMessageException {
286 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
287 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
288 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
289 0x00, 0x00, 0x00, 0x02,
290 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
291 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
292 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
293 0x01, 0x01, 0x01, 0x01,
294 0x00, 0x01, 0x00, 0x01,
295 0x01, 0x01, 0x01, 0x01,
296 0x05, 0x05, 0x05, 0x05,
297
298 0x07, 0x10, 0x00, 0x14, //ERO object
299 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
300 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
301
302 0x08, 0x10, 0x00, 0x34, //RRO object
303 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
304 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
305 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
306 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
307 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
308 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
309 };
310
311 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
312 buffer.writeBytes(reportMsg);
313
314 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
315 PcepMessage message = reader.readFrom(buffer);
Priyanka B413fbe82016-05-26 11:44:45 +0530316
317 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
318 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
319 newBuilder.set(AnnotationKeys.TYPE, "L3");
320 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
321 UNKOWN, UNKOWN, UNKOWN,
322 UNKOWN, new ChassisId(),
323 newBuilder.build());
324
325 deviceService.addDevice(device);
326 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
327 new ClientCapability(true, true, true, true, true));
328 masterShipService.setMaster(true);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530329 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
330
331 assertThat(registry.tunnelIdCounter, is((long) 1));
332 }
333
334 /**
335 * Tests updating an existing tunnel on receiving asynchronous PCRpt msg,
336 * i.e. without any SRP id.
337 */
338 @Test
339 public void tunnelProviderAddedTest2() throws PcepParseException, PcepOutOfBoundMessageException {
340 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x50,
341 0x21, 0x10, 0x00, 0x14, //SRP object
342 0x00, 0x00, 0x00, 0x00,
343 0x00, 0x00, 0x00, 0x00,
344 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
345 0x00, 0x00, 0x00, 0x02,
346 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, //LSP object
347 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path TLV
348 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
349 0x4e, 0x1f, 0x04, 0x00,
350 0x00, 0x01, 0x00, 0x01,
351 0x4e, 0x1f, 0x04, 0x00,
352 0x4e, 0x20, 0x04, 0x00,
353 0x07, 0x10, 0x00, 0x14, //ERO object
354 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, // ERO IPv4 sub objects
355 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
356 };
357
358 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
359 buffer.writeBytes(reportMsg);
360
361 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
362 PcepMessage message = reader.readFrom(buffer);
363
364 // create an existing tunnel.
365 IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e1f0400));
366 IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e200400));
367
368 SparseAnnotations annotations = DefaultAnnotations.builder()
369 .set(BANDWIDTH, (new Integer(1)).toString())
370 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
371 .set(PCC_TUNNEL_ID, String.valueOf(1))
372 .set(PLSP_ID, String.valueOf(1))
Priyanka B413fbe82016-05-26 11:44:45 +0530373 .set(LOCAL_LSP_ID, String.valueOf(1))
374 .set(DELEGATE, String.valueOf("true"))
375 .build();
Avantika-Huawei56c11842016-04-28 00:56:56 +0530376
377 Tunnel tunnel = new DefaultTunnel(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, INIT, null, null,
378 TunnelName.tunnelName("T123"), null, annotations);
379 tunnelService.setupTunnel(null, null, tunnel, null);
380
381 PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400));
Priyanka B413fbe82016-05-26 11:44:45 +0530382 PcepClientAdapter pc = new PcepClientAdapter();
383 pc.init(pccId, PcepVersion.PCEP_1);
384 masterShipService.setMaster(true);
385 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
386 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530387 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530388
389 // Process update message.
390 controller.processClientMessage(pccId, message);
391 assertThat(tunnelService.queryAllTunnels().size(), is(1));
392 }
393
394 /**
395 * Tests adding a new tunnel on receiving asynchronous PCRpt msg,
396 * i.e. without any SRP id.
397 */
398 @Test
399 public void tunnelProviderAddedTest3() throws PcepParseException, PcepOutOfBoundMessageException {
400 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
401 0x21, 0x10, 0x00, 0x14, //SRP object
402 0x00, 0x00, 0x00, 0x00,
403 0x00, 0x00, 0x00, 0x00,
404 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
405 0x00, 0x00, 0x00, 0x02,
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530406 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x1B, // LSP object
Avantika-Huawei56c11842016-04-28 00:56:56 +0530407 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
408 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
409 0x01, 0x01, 0x01, 0x01,
410 0x00, 0x01, 0x00, 0x01,
411 0x01, 0x01, 0x01, 0x01,
412 0x05, 0x05, 0x05, 0x05,
413
414 0x07, 0x10, 0x00, 0x14, //ERO object
415 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
416 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
417
418 0x08, 0x10, 0x00, 0x34, //RRO object
419 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
420 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
421 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
422 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
423 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
424 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
425 };
426
427 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
428 buffer.writeBytes(reportMsg);
429
430 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
431 PcepMessage message = reader.readFrom(buffer);
432
Priyanka B413fbe82016-05-26 11:44:45 +0530433 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
434 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
435 newBuilder.set(AnnotationKeys.TYPE, "L3");
436 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
437 UNKOWN, UNKOWN, UNKOWN,
438 UNKOWN, new ChassisId(),
439 newBuilder.build());
440
441 deviceService.addDevice(device);
442
Avantika-Huawei56c11842016-04-28 00:56:56 +0530443 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530444 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Priyanka B413fbe82016-05-26 11:44:45 +0530445 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
446
447 PcepClientAdapter pc = new PcepClientAdapter();
448 pc.init(pccId, PcepVersion.PCEP_1);
449 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
450 masterShipService.setMaster(true);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530451 controller.processClientMessage(pccId, message);
452
453 assertThat(registry.tunnelIdCounter, is((long) 1));
454 }
455
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530456 /**
Priyanka B413fbe82016-05-26 11:44:45 +0530457 * Tests PCRpt msg with D flag set and delegated to non-master.
458 *
459 * @throws InterruptedException while waiting for delay
460 */
461 @Test
462 public void tunnelProviderAddedTest4() throws PcepParseException, PcepOutOfBoundMessageException,
463 InterruptedException {
464 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
465 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
466 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
467 0x00, 0x00, 0x00, 0x02,
468 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x02, //LSP object
469 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
470 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
471 0x01, 0x01, 0x01, 0x01,
472 0x00, 0x01, 0x00, 0x01,
473 0x01, 0x01, 0x01, 0x01,
474 0x05, 0x05, 0x05, 0x05,
475
476 0x07, 0x10, 0x00, 0x14, //ERO object
477 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
478 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
479
480 0x08, 0x10, 0x00, 0x34, //RRO object
481 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
482 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
483 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
484 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
485 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
486 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
487 };
488
489 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
490 buffer.writeBytes(reportMsg);
491
492 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
493 PcepMessage message = reader.readFrom(buffer);
494
495 //PCC 1.1.1.1, D=0, ONOS as master
496 masterShipService.setMaster(true);
497 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
498 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
499 newBuilder.set(AnnotationKeys.TYPE, "L3");
500 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
501 UNKOWN, UNKOWN, UNKOWN,
502 UNKOWN, new ChassisId(),
503 newBuilder.build());
504
505 deviceService.addDevice(device);
506 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
507 new ClientCapability(true, true, true, true, true));
508 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
509 assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
510 is("false"));
511
512 //PCC 1.1.1.1, D=1, non-master
513 masterShipService.setMaster(false);
514
515 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, 0x03, //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 buffer = ChannelBuffers.dynamicBuffer();
541 buffer.writeBytes(reportMsg);
542
543 reader = PcepFactories.getGenericReader();
544 message = reader.readFrom(buffer);
545
546 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
547 TimeUnit.MILLISECONDS.sleep(4000);
548 assertThat(registry.tunnelIdCounter, is((long) 1));
549 assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
550 is("true"));
551 }
552
553 /**
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530554 * Tests adding PCC Init LSP after LSP DB sync is over.
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530555 */
556 @Test
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530557 public void tunnelProviderAddedTest5() throws PcepParseException, PcepOutOfBoundMessageException {
558 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530559 0x21, 0x10, 0x00, 0x14, //SRP object
560 0x00, 0x00, 0x00, 0x00,
561 0x00, 0x00, 0x00, 0x00,
562 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530563 0x00, 0x00, 0x00, 0x02,
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530564 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530565 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530566 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
567 0x01, 0x01, 0x01, 0x01,
568 0x00, 0x01, 0x00, 0x01,
569 0x01, 0x01, 0x01, 0x01,
570 0x05, 0x05, 0x05, 0x05,
571
572 0x07, 0x10, 0x00, 0x14, //ERO object
573 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
574 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
575
576 0x08, 0x10, 0x00, 0x34, //RRO object
577 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
578 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
579 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
580 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
581 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
582 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
583 };
584
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530585 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
586 buffer.writeBytes(reportMsg);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530587
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530588 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
589 PcepMessage message = reader.readFrom(buffer);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530590
Priyanka B413fbe82016-05-26 11:44:45 +0530591 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
592 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
593 newBuilder.set(AnnotationKeys.TYPE, "L3");
594 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
595 UNKOWN, UNKOWN, UNKOWN,
596 UNKOWN, new ChassisId(),
597 newBuilder.build());
598
599 deviceService.addDevice(device);
600
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530601 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530602 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Priyanka B413fbe82016-05-26 11:44:45 +0530603 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
604
605 PcepClientAdapter pc = new PcepClientAdapter();
606 pc.init(pccId, PcepVersion.PCEP_1);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530607 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
Priyanka B413fbe82016-05-26 11:44:45 +0530608 masterShipService.setMaster(true);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530609 controller.processClientMessage(pccId, message);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530610
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530611 assertThat(registry.tunnelIdCounter, is((long) 0));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530612 }
613
Avantika-Huawei56c11842016-04-28 00:56:56 +0530614 @After
615 public void tearDown() throws IOException {
616 tunnelProvider.deactivate();
617 tunnelProvider.controller = null;
618 tunnelProvider.pcepClientController = null;
619 tunnelProvider.tunnelProviderRegistry = null;
620
621 tunnelProvider.pcepTunnelApiMapper = null;
622 tunnelProvider.cfgService = null;
623 tunnelProvider.tunnelService = null;
Priyanka B413fbe82016-05-26 11:44:45 +0530624 tunnelProvider.tunnelAdminService = null;
625 tunnelProvider.deviceService = null;
626 tunnelProvider.mastershipService = null;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530627 tunnelProvider.service = null;
628 }
629}