blob: 85eacbcbf4b26bb87841060bc4815a5f88cacbbd [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 B413fbe82016-05-26 11:44:45 +053039import java.util.LinkedList;
40import java.util.List;
41import java.util.concurrent.TimeUnit;
Avantika-Huawei56c11842016-04-28 00:56:56 +053042
43import org.jboss.netty.buffer.ChannelBuffer;
44import org.jboss.netty.buffer.ChannelBuffers;
45import org.junit.After;
46import org.junit.Before;
47import org.junit.Test;
Priyanka B413fbe82016-05-26 11:44:45 +053048import org.onlab.packet.ChassisId;
Avantika-Huawei56c11842016-04-28 00:56:56 +053049import org.onlab.packet.IpAddress;
50import org.onosproject.cfg.ComponentConfigAdapter;
51import org.onosproject.core.ApplicationId;
52import org.onosproject.incubator.net.tunnel.DefaultTunnel;
53import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
54import org.onosproject.incubator.net.tunnel.Tunnel;
Priyanka B413fbe82016-05-26 11:44:45 +053055import org.onosproject.incubator.net.tunnel.Tunnel.Type;
56import org.onosproject.incubator.net.tunnel.TunnelAdminService;
Avantika-Huawei56c11842016-04-28 00:56:56 +053057import org.onosproject.incubator.net.tunnel.TunnelDescription;
58import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
59import org.onosproject.incubator.net.tunnel.TunnelId;
60import org.onosproject.incubator.net.tunnel.TunnelName;
61import org.onosproject.incubator.net.tunnel.TunnelProvider;
62import org.onosproject.incubator.net.tunnel.TunnelProviderService;
63import org.onosproject.incubator.net.tunnel.Tunnel.State;
Priyanka B413fbe82016-05-26 11:44:45 +053064import org.onosproject.mastership.MastershipServiceAdapter;
65import org.onosproject.net.AnnotationKeys;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053066import org.onosproject.net.ConnectPoint;
Avantika-Huawei56c11842016-04-28 00:56:56 +053067import org.onosproject.net.DefaultAnnotations;
Priyanka B413fbe82016-05-26 11:44:45 +053068import org.onosproject.net.DefaultDevice;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053069import org.onosproject.net.DefaultLink;
Priyanka B413fbe82016-05-26 11:44:45 +053070import org.onosproject.net.Device;
71import org.onosproject.net.DeviceId;
Avantika-Huawei56c11842016-04-28 00:56:56 +053072import org.onosproject.net.ElementId;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053073import org.onosproject.net.Link;
Priyanka B413fbe82016-05-26 11:44:45 +053074import org.onosproject.net.MastershipRole;
Avantika-Huawei56c11842016-04-28 00:56:56 +053075import org.onosproject.net.Path;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053076import org.onosproject.net.PortNumber;
Avantika-Huawei56c11842016-04-28 00:56:56 +053077import org.onosproject.net.SparseAnnotations;
Priyanka B413fbe82016-05-26 11:44:45 +053078import org.onosproject.net.device.DeviceServiceAdapter;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053079import org.onosproject.net.link.LinkServiceAdapter;
Priyanka B413fbe82016-05-26 11:44:45 +053080import org.onosproject.net.provider.ProviderId;
Avantika-Huawei56c11842016-04-28 00:56:56 +053081import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
82import org.onosproject.pcepio.exceptions.PcepParseException;
83import org.onosproject.pcepio.protocol.PcepFactories;
84import org.onosproject.pcepio.protocol.PcepMessage;
85import org.onosproject.pcepio.protocol.PcepMessageReader;
Priyanka B413fbe82016-05-26 11:44:45 +053086import org.onosproject.pcepio.protocol.PcepVersion;
Avantika-Huawei56c11842016-04-28 00:56:56 +053087import org.onosproject.pcep.controller.ClientCapability;
Priyanka B413fbe82016-05-26 11:44:45 +053088import org.onosproject.pcep.controller.LspKey;
Avantika-Huawei56c11842016-04-28 00:56:56 +053089import org.onosproject.pcep.controller.PccId;
90
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053091import com.google.common.collect.FluentIterable;
Avantika-Huawei56c11842016-04-28 00:56:56 +053092import com.google.common.collect.ImmutableSet;
93
94/**
95 * Tests handling of PCEP report message.
96 */
97public class PcepTunnelAddedTest {
98
Priyanka B413fbe82016-05-26 11:44:45 +053099 public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
100 public static final String UNKOWN = "UNKOWN";
Avantika-Huawei56c11842016-04-28 00:56:56 +0530101 PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
102 private final MockTunnelProviderRegistryAdapter registry = new MockTunnelProviderRegistryAdapter();
103 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
104 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
105 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
106 private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
Priyanka B413fbe82016-05-26 11:44:45 +0530107 public final MockDeviceService deviceService = new MockDeviceService();
108 private final MockMasterShipService masterShipService = new MockMasterShipService();
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530109 private final MockLinkService linkService = new MockLinkService();
Priyanka B413fbe82016-05-26 11:44:45 +0530110 private final MockTunnelAdminService tunnelAdminService = new MockTunnelAdminService();
111
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530112 private class MockLinkService extends LinkServiceAdapter {
113 LinkedList<Link> links = new LinkedList<>();
114 void addLink(Link link) {
115 links.add(link);
116 }
117
118 @Override
119 public Iterable<Link> getActiveLinks() {
120
121 return FluentIterable.from(links)
122 .filter(input -> input.state() == ACTIVE);
123 }
124 }
125
Priyanka B413fbe82016-05-26 11:44:45 +0530126 private class MockTunnelAdminService implements TunnelAdminService {
127
128 @Override
129 public void removeTunnel(TunnelId tunnelId) {
130 // TODO Auto-generated method stub
131 }
132
133 @Override
134 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, ProviderId producerName) {
135 // TODO Auto-generated method stub
136 }
137
138 @Override
139 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Type type, ProviderId producerName) {
140 // TODO Auto-generated method stub
141 }
142
143 @Override
144 public void updateTunnel(Tunnel tunnel, Path path) {
145 if (tunnelService.tunnelIdAsKeyStore.containsKey(tunnel.tunnelId())) {
146 tunnelService.tunnelIdAsKeyStore.replace(tunnel.tunnelId(), tunnel);
147 }
148 }
149 }
150
151 private class MockMasterShipService extends MastershipServiceAdapter {
152 boolean set;
153
154 private void setMaster(boolean isMaster) {
155 this.set = isMaster;
156 }
157
158 @Override
159 public MastershipRole getLocalRole(DeviceId deviceId) {
160 return set ? MastershipRole.MASTER : MastershipRole.STANDBY;
161 }
162
163 @Override
164 public boolean isLocalMaster(DeviceId deviceId) {
165 return getLocalRole(deviceId) == MASTER;
166 }
167 }
168
169 private class MockDeviceService extends DeviceServiceAdapter {
170 List<Device> devices = new LinkedList<>();
171
172 private void addDevice(Device dev) {
173 devices.add(dev);
174 }
175
176 @Override
177 public Iterable<Device> getAvailableDevices() {
178 return devices;
179 }
180 }
Avantika-Huawei56c11842016-04-28 00:56:56 +0530181
182 private class MockTunnelProviderRegistryAdapter extends TunnelProviderRegistryAdapter {
183 public long tunnelIdCounter;
184
185 @Override
186 public TunnelProviderService register(TunnelProvider provider) {
187 this.provider = provider;
188 return new TestProviderService();
189 }
190
191 private class TestProviderService implements TunnelProviderService {
192
193 @Override
194 public TunnelProvider provider() {
195 return null;
196 }
197
198 @Override
199 public TunnelId tunnelAdded(TunnelDescription tunnel) {
Priyanka B413fbe82016-05-26 11:44:45 +0530200 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
201 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
202 tunnel.src(), tunnel.dst(),
203 tunnel.type(),
204 tunnel.groupId(),
205 id,
206 tunnel.tunnelName(),
207 tunnel.path(),
208 tunnel.resource(),
209 tunnel.annotations());
210 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
211 return id;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530212 }
213
214 @Override
215 public TunnelId tunnelAdded(TunnelDescription tunnel, State state) {
Priyanka B413fbe82016-05-26 11:44:45 +0530216 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
217 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
218 tunnel.src(), tunnel.dst(),
219 tunnel.type(),
220 tunnel.groupId(),
221 id,
222 tunnel.tunnelName(),
223 tunnel.path(),
224 tunnel.resource(),
225 tunnel.annotations());
226 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
227 return id;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530228 }
229
230 @Override
231 public void tunnelRemoved(TunnelDescription tunnel) {
232 }
233
234 @Override
235 public void tunnelUpdated(TunnelDescription tunnel) {
236 }
237
238 @Override
239 public void tunnelUpdated(TunnelDescription tunnel, State state) {
240 }
241
242 @Override
243 public Tunnel tunnelQueryById(TunnelId tunnelId) {
244 return null;
245 }
246 }
247 }
248
249 private class MockTunnelServiceAdapter extends TunnelServiceAdapter {
250 private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<>();
251 private int tunnelIdCounter = 0;
252
253 @Override
254 public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
255 TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
256 tunnelIdAsKeyStore.put(tunnelId, tunnel);
257 return tunnelId;
258 }
259
260 @Override
261 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
262 Collection<Tunnel> result = new HashSet<>();
263 Tunnel tunnel = null;
264 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
265 tunnel = tunnelIdAsKeyStore.get(tunnelId);
266
267 if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
268 result.add(tunnel);
269 }
270 }
271
272 return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
273 }
274
275 @Override
276 public Collection<Tunnel> queryAllTunnels() {
277 Collection<Tunnel> result = new HashSet<>();
278
279 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
280 result.add(tunnelIdAsKeyStore.get(tunnelId));
281 }
282
283 return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
284
285 }
286 }
287
288 @Before
289 public void preSetup() {
290 tunnelProvider.tunnelProviderRegistry = registry;
291 tunnelProvider.pcepClientController = controller;
292 tunnelProvider.controller = ctl;
Priyanka B413fbe82016-05-26 11:44:45 +0530293 tunnelProvider.deviceService = deviceService;
294 tunnelProvider.mastershipService = masterShipService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530295 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
296 tunnelProvider.cfgService = new ComponentConfigAdapter();
297 tunnelProvider.tunnelService = tunnelService;
Priyanka B413fbe82016-05-26 11:44:45 +0530298 tunnelProvider.tunnelAdminService = tunnelAdminService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530299 tunnelProvider.service = registry.register(tunnelProvider);
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530300 tunnelProvider.linkService = linkService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530301 tunnelProvider.activate();
302 }
303
304 /**
305 * Tests PCRpt msg with sync flag set.
306 */
307 @Test
308 public void tunnelProviderAddedTest1() throws PcepParseException, PcepOutOfBoundMessageException {
309 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
310 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
311 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
312 0x00, 0x00, 0x00, 0x02,
313 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
314 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
315 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
316 0x01, 0x01, 0x01, 0x01,
317 0x00, 0x01, 0x00, 0x01,
318 0x01, 0x01, 0x01, 0x01,
319 0x05, 0x05, 0x05, 0x05,
320
321 0x07, 0x10, 0x00, 0x14, //ERO object
322 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
323 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
324
325 0x08, 0x10, 0x00, 0x34, //RRO object
326 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
327 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
328 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
329 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
330 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
331 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
332 };
333
334 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
335 buffer.writeBytes(reportMsg);
336
337 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
338 PcepMessage message = reader.readFrom(buffer);
Priyanka B413fbe82016-05-26 11:44:45 +0530339
340 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
341 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
342 newBuilder.set(AnnotationKeys.TYPE, "L3");
343 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
344 UNKOWN, UNKOWN, UNKOWN,
345 UNKOWN, new ChassisId(),
346 newBuilder.build());
347
348 deviceService.addDevice(device);
349 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
350 new ClientCapability(true, true, true, true, true));
351 masterShipService.setMaster(true);
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530352 Link link = DefaultLink.builder()
353 .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
354 .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
355 .state(ACTIVE)
356 .type(Link.Type.DIRECT)
357 .providerId(ProviderId.NONE)
358 .build();
359 linkService.addLink(link);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530360 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
361
362 assertThat(registry.tunnelIdCounter, is((long) 1));
363 }
364
365 /**
366 * Tests updating an existing tunnel on receiving asynchronous PCRpt msg,
367 * i.e. without any SRP id.
368 */
369 @Test
370 public void tunnelProviderAddedTest2() throws PcepParseException, PcepOutOfBoundMessageException {
371 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x50,
372 0x21, 0x10, 0x00, 0x14, //SRP object
373 0x00, 0x00, 0x00, 0x00,
374 0x00, 0x00, 0x00, 0x00,
375 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
376 0x00, 0x00, 0x00, 0x02,
377 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, //LSP object
378 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path TLV
379 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
380 0x4e, 0x1f, 0x04, 0x00,
381 0x00, 0x01, 0x00, 0x01,
382 0x4e, 0x1f, 0x04, 0x00,
383 0x4e, 0x20, 0x04, 0x00,
384 0x07, 0x10, 0x00, 0x14, //ERO object
385 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, // ERO IPv4 sub objects
386 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
387 };
388
389 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
390 buffer.writeBytes(reportMsg);
391
392 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
393 PcepMessage message = reader.readFrom(buffer);
394
395 // create an existing tunnel.
396 IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e1f0400));
397 IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e200400));
398
399 SparseAnnotations annotations = DefaultAnnotations.builder()
400 .set(BANDWIDTH, (new Integer(1)).toString())
401 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
402 .set(PCC_TUNNEL_ID, String.valueOf(1))
403 .set(PLSP_ID, String.valueOf(1))
Priyanka B413fbe82016-05-26 11:44:45 +0530404 .set(LOCAL_LSP_ID, String.valueOf(1))
405 .set(DELEGATE, String.valueOf("true"))
406 .build();
Avantika-Huawei56c11842016-04-28 00:56:56 +0530407
408 Tunnel tunnel = new DefaultTunnel(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, INIT, null, null,
409 TunnelName.tunnelName("T123"), null, annotations);
410 tunnelService.setupTunnel(null, null, tunnel, null);
411
412 PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400));
Priyanka B413fbe82016-05-26 11:44:45 +0530413 PcepClientAdapter pc = new PcepClientAdapter();
414 pc.init(pccId, PcepVersion.PCEP_1);
415 masterShipService.setMaster(true);
416 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
417 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530418 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530419
420 // Process update message.
421 controller.processClientMessage(pccId, message);
422 assertThat(tunnelService.queryAllTunnels().size(), is(1));
423 }
424
425 /**
426 * Tests adding a new tunnel on receiving asynchronous PCRpt msg,
427 * i.e. without any SRP id.
428 */
429 @Test
430 public void tunnelProviderAddedTest3() throws PcepParseException, PcepOutOfBoundMessageException {
431 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
432 0x21, 0x10, 0x00, 0x14, //SRP object
433 0x00, 0x00, 0x00, 0x00,
434 0x00, 0x00, 0x00, 0x00,
435 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
436 0x00, 0x00, 0x00, 0x02,
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530437 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x1B, // LSP object
Avantika-Huawei56c11842016-04-28 00:56:56 +0530438 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
439 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
440 0x01, 0x01, 0x01, 0x01,
441 0x00, 0x01, 0x00, 0x01,
442 0x01, 0x01, 0x01, 0x01,
443 0x05, 0x05, 0x05, 0x05,
444
445 0x07, 0x10, 0x00, 0x14, //ERO object
446 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
447 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
448
449 0x08, 0x10, 0x00, 0x34, //RRO object
450 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
451 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
452 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
453 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
454 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
455 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
456 };
457
458 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
459 buffer.writeBytes(reportMsg);
460
461 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
462 PcepMessage message = reader.readFrom(buffer);
463
Priyanka B413fbe82016-05-26 11:44:45 +0530464 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
465 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
466 newBuilder.set(AnnotationKeys.TYPE, "L3");
467 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
468 UNKOWN, UNKOWN, UNKOWN,
469 UNKOWN, new ChassisId(),
470 newBuilder.build());
471
472 deviceService.addDevice(device);
473
Avantika-Huawei56c11842016-04-28 00:56:56 +0530474 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530475 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Priyanka B413fbe82016-05-26 11:44:45 +0530476 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
477
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530478 Link link = DefaultLink.builder()
479 .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
480 .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
481 .state(ACTIVE)
482 .type(Link.Type.DIRECT)
483 .providerId(ProviderId.NONE)
484 .build();
485 linkService.addLink(link);
Priyanka B413fbe82016-05-26 11:44:45 +0530486 PcepClientAdapter pc = new PcepClientAdapter();
487 pc.init(pccId, PcepVersion.PCEP_1);
488 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
489 masterShipService.setMaster(true);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530490 controller.processClientMessage(pccId, message);
491
492 assertThat(registry.tunnelIdCounter, is((long) 1));
493 }
494
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530495 /**
Priyanka B413fbe82016-05-26 11:44:45 +0530496 * Tests PCRpt msg with D flag set and delegated to non-master.
497 *
498 * @throws InterruptedException while waiting for delay
499 */
500 @Test
501 public void tunnelProviderAddedTest4() throws PcepParseException, PcepOutOfBoundMessageException,
502 InterruptedException {
503 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
504 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
505 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
506 0x00, 0x00, 0x00, 0x02,
507 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x02, //LSP object
508 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
509 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
510 0x01, 0x01, 0x01, 0x01,
511 0x00, 0x01, 0x00, 0x01,
512 0x01, 0x01, 0x01, 0x01,
513 0x05, 0x05, 0x05, 0x05,
514
515 0x07, 0x10, 0x00, 0x14, //ERO object
516 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
517 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
518
519 0x08, 0x10, 0x00, 0x34, //RRO object
520 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
521 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
522 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
523 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
524 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
525 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
526 };
527
528 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
529 buffer.writeBytes(reportMsg);
530
531 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
532 PcepMessage message = reader.readFrom(buffer);
533
534 //PCC 1.1.1.1, D=0, ONOS as master
535 masterShipService.setMaster(true);
536 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
537 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
538 newBuilder.set(AnnotationKeys.TYPE, "L3");
539 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
540 UNKOWN, UNKOWN, UNKOWN,
541 UNKOWN, new ChassisId(),
542 newBuilder.build());
543
544 deviceService.addDevice(device);
545 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
546 new ClientCapability(true, true, true, true, true));
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530547 Link link = DefaultLink.builder()
548 .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
549 .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
550 .state(ACTIVE)
551 .type(Link.Type.DIRECT)
552 .providerId(ProviderId.NONE)
553 .build();
554 linkService.addLink(link);
Priyanka B413fbe82016-05-26 11:44:45 +0530555 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
556 assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
557 is("false"));
558
559 //PCC 1.1.1.1, D=1, non-master
560 masterShipService.setMaster(false);
561
562 reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
563 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
564 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
565 0x00, 0x00, 0x00, 0x02,
566 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
567 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
568 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
569 0x01, 0x01, 0x01, 0x01,
570 0x00, 0x01, 0x00, 0x01,
571 0x01, 0x01, 0x01, 0x01,
572 0x05, 0x05, 0x05, 0x05,
573
574 0x07, 0x10, 0x00, 0x14, //ERO object
575 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
576 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
577
578 0x08, 0x10, 0x00, 0x34, //RRO object
579 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
580 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
581 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
582 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
583 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
584 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
585 };
586
587 buffer = ChannelBuffers.dynamicBuffer();
588 buffer.writeBytes(reportMsg);
589
590 reader = PcepFactories.getGenericReader();
591 message = reader.readFrom(buffer);
592
593 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
594 TimeUnit.MILLISECONDS.sleep(4000);
595 assertThat(registry.tunnelIdCounter, is((long) 1));
596 assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
597 is("true"));
598 }
599
600 /**
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530601 * Tests adding PCC Init LSP after LSP DB sync is over.
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530602 */
603 @Test
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530604 public void tunnelProviderAddedTest5() throws PcepParseException, PcepOutOfBoundMessageException {
605 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530606 0x21, 0x10, 0x00, 0x14, //SRP object
607 0x00, 0x00, 0x00, 0x00,
608 0x00, 0x00, 0x00, 0x00,
609 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530610 0x00, 0x00, 0x00, 0x02,
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530611 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530612 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530613 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
614 0x01, 0x01, 0x01, 0x01,
615 0x00, 0x01, 0x00, 0x01,
616 0x01, 0x01, 0x01, 0x01,
617 0x05, 0x05, 0x05, 0x05,
618
619 0x07, 0x10, 0x00, 0x14, //ERO object
620 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
621 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
622
623 0x08, 0x10, 0x00, 0x34, //RRO object
624 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
625 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
626 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
627 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
628 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
629 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
630 };
631
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530632 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
633 buffer.writeBytes(reportMsg);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530634
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530635 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
636 PcepMessage message = reader.readFrom(buffer);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530637
Priyanka B413fbe82016-05-26 11:44:45 +0530638 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
639 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
640 newBuilder.set(AnnotationKeys.TYPE, "L3");
641 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
642 UNKOWN, UNKOWN, UNKOWN,
643 UNKOWN, new ChassisId(),
644 newBuilder.build());
645
646 deviceService.addDevice(device);
647
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530648 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530649 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Priyanka B413fbe82016-05-26 11:44:45 +0530650 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
651
652 PcepClientAdapter pc = new PcepClientAdapter();
653 pc.init(pccId, PcepVersion.PCEP_1);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530654 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
Priyanka B413fbe82016-05-26 11:44:45 +0530655 masterShipService.setMaster(true);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530656 controller.processClientMessage(pccId, message);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530657
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530658 assertThat(registry.tunnelIdCounter, is((long) 0));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530659 }
660
Avantika-Huawei56c11842016-04-28 00:56:56 +0530661 @After
662 public void tearDown() throws IOException {
663 tunnelProvider.deactivate();
664 tunnelProvider.controller = null;
665 tunnelProvider.pcepClientController = null;
666 tunnelProvider.tunnelProviderRegistry = null;
667
668 tunnelProvider.pcepTunnelApiMapper = null;
669 tunnelProvider.cfgService = null;
670 tunnelProvider.tunnelService = null;
Priyanka B413fbe82016-05-26 11:44:45 +0530671 tunnelProvider.tunnelAdminService = null;
672 tunnelProvider.deviceService = null;
673 tunnelProvider.mastershipService = null;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530674 tunnelProvider.linkService = null;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530675 tunnelProvider.service = null;
676 }
677}