blob: 0db45cb98ef826e91862f631eff5627b9180f3a2 [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
Ray Milkeyd1c34da2018-06-22 18:10:53 -070018import com.google.common.collect.FluentIterable;
19import com.google.common.collect.ImmutableSet;
Avantika-Huawei56c11842016-04-28 00:56:56 +053020import org.jboss.netty.buffer.ChannelBuffer;
21import org.jboss.netty.buffer.ChannelBuffers;
22import org.junit.After;
23import org.junit.Before;
24import org.junit.Test;
Priyanka B413fbe82016-05-26 11:44:45 +053025import org.onlab.packet.ChassisId;
Avantika-Huawei56c11842016-04-28 00:56:56 +053026import org.onlab.packet.IpAddress;
27import org.onosproject.cfg.ComponentConfigAdapter;
28import org.onosproject.core.ApplicationId;
29import org.onosproject.incubator.net.tunnel.DefaultTunnel;
30import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
31import org.onosproject.incubator.net.tunnel.Tunnel;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070032import org.onosproject.incubator.net.tunnel.Tunnel.State;
Priyanka B413fbe82016-05-26 11:44:45 +053033import org.onosproject.incubator.net.tunnel.Tunnel.Type;
34import org.onosproject.incubator.net.tunnel.TunnelAdminService;
Avantika-Huawei56c11842016-04-28 00:56:56 +053035import org.onosproject.incubator.net.tunnel.TunnelDescription;
36import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
37import org.onosproject.incubator.net.tunnel.TunnelId;
38import org.onosproject.incubator.net.tunnel.TunnelName;
39import org.onosproject.incubator.net.tunnel.TunnelProvider;
40import org.onosproject.incubator.net.tunnel.TunnelProviderService;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070041import org.onosproject.incubator.net.tunnel.TunnelServiceAdapter;
Priyanka B413fbe82016-05-26 11:44:45 +053042import org.onosproject.mastership.MastershipServiceAdapter;
43import org.onosproject.net.AnnotationKeys;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053044import org.onosproject.net.ConnectPoint;
Avantika-Huawei56c11842016-04-28 00:56:56 +053045import org.onosproject.net.DefaultAnnotations;
Priyanka B413fbe82016-05-26 11:44:45 +053046import org.onosproject.net.DefaultDevice;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053047import org.onosproject.net.DefaultLink;
Priyanka B413fbe82016-05-26 11:44:45 +053048import org.onosproject.net.Device;
49import org.onosproject.net.DeviceId;
Avantika-Huawei56c11842016-04-28 00:56:56 +053050import org.onosproject.net.ElementId;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053051import org.onosproject.net.Link;
Priyanka B413fbe82016-05-26 11:44:45 +053052import org.onosproject.net.MastershipRole;
Avantika-Huawei56c11842016-04-28 00:56:56 +053053import org.onosproject.net.Path;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053054import org.onosproject.net.PortNumber;
Avantika-Huawei56c11842016-04-28 00:56:56 +053055import org.onosproject.net.SparseAnnotations;
Priyanka B413fbe82016-05-26 11:44:45 +053056import org.onosproject.net.device.DeviceServiceAdapter;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +053057import org.onosproject.net.link.LinkServiceAdapter;
Priyanka B413fbe82016-05-26 11:44:45 +053058import org.onosproject.net.provider.ProviderId;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070059import org.onosproject.pcep.api.PcepControllerAdapter;
60import org.onosproject.pcep.server.ClientCapability;
61import org.onosproject.pcep.server.LspKey;
62import org.onosproject.pcep.server.PccId;
63import org.onosproject.pcep.server.PcepClientAdapter;
64import org.onosproject.pcep.server.PcepClientControllerAdapter;
Avantika-Huawei56c11842016-04-28 00:56:56 +053065import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
66import org.onosproject.pcepio.exceptions.PcepParseException;
67import org.onosproject.pcepio.protocol.PcepFactories;
68import org.onosproject.pcepio.protocol.PcepMessage;
69import org.onosproject.pcepio.protocol.PcepMessageReader;
Priyanka B413fbe82016-05-26 11:44:45 +053070import org.onosproject.pcepio.protocol.PcepVersion;
Avantika-Huawei56c11842016-04-28 00:56:56 +053071
Ray Milkeyd1c34da2018-06-22 18:10:53 -070072import java.io.IOException;
73import java.util.Collection;
74import java.util.Collections;
75import java.util.HashMap;
76import java.util.HashSet;
77import java.util.Iterator;
78import java.util.LinkedList;
79import java.util.List;
80import java.util.concurrent.TimeUnit;
81
82import static org.hamcrest.MatcherAssert.assertThat;
83import static org.hamcrest.core.Is.is;
84import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT;
85import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
86import static org.onosproject.net.Device.Type.ROUTER;
87import static org.onosproject.net.Link.State.ACTIVE;
88import static org.onosproject.net.MastershipRole.MASTER;
89import static org.onosproject.pcep.server.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
90import static org.onosproject.pcep.server.PcepAnnotationKeys.BANDWIDTH;
91import static org.onosproject.pcep.server.PcepAnnotationKeys.DELEGATE;
92import static org.onosproject.pcep.server.PcepAnnotationKeys.LOCAL_LSP_ID;
93import static org.onosproject.pcep.server.PcepAnnotationKeys.LSP_SIG_TYPE;
94import static org.onosproject.pcep.server.PcepAnnotationKeys.PCC_TUNNEL_ID;
95import static org.onosproject.pcep.server.PcepAnnotationKeys.PLSP_ID;
96import static org.onosproject.pcep.server.PcepSyncStatus.SYNCED;
Avantika-Huawei56c11842016-04-28 00:56:56 +053097
98/**
99 * Tests handling of PCEP report message.
100 */
101public class PcepTunnelAddedTest {
102
Priyanka B413fbe82016-05-26 11:44:45 +0530103 public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
104 public static final String UNKOWN = "UNKOWN";
Avantika-Huawei56c11842016-04-28 00:56:56 +0530105 PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
106 private final MockTunnelProviderRegistryAdapter registry = new MockTunnelProviderRegistryAdapter();
107 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
108 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
109 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
110 private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
Priyanka B413fbe82016-05-26 11:44:45 +0530111 public final MockDeviceService deviceService = new MockDeviceService();
112 private final MockMasterShipService masterShipService = new MockMasterShipService();
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530113 private final MockLinkService linkService = new MockLinkService();
Priyanka B413fbe82016-05-26 11:44:45 +0530114 private final MockTunnelAdminService tunnelAdminService = new MockTunnelAdminService();
115
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530116 private class MockLinkService extends LinkServiceAdapter {
117 LinkedList<Link> links = new LinkedList<>();
118 void addLink(Link link) {
119 links.add(link);
120 }
121
122 @Override
123 public Iterable<Link> getActiveLinks() {
124
125 return FluentIterable.from(links)
126 .filter(input -> input.state() == ACTIVE);
127 }
128 }
129
Priyanka B413fbe82016-05-26 11:44:45 +0530130 private class MockTunnelAdminService implements TunnelAdminService {
131
132 @Override
133 public void removeTunnel(TunnelId tunnelId) {
134 // TODO Auto-generated method stub
135 }
136
137 @Override
138 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, ProviderId producerName) {
139 // TODO Auto-generated method stub
140 }
141
142 @Override
143 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Type type, ProviderId producerName) {
144 // TODO Auto-generated method stub
145 }
146
147 @Override
148 public void updateTunnel(Tunnel tunnel, Path path) {
149 if (tunnelService.tunnelIdAsKeyStore.containsKey(tunnel.tunnelId())) {
150 tunnelService.tunnelIdAsKeyStore.replace(tunnel.tunnelId(), tunnel);
151 }
152 }
tony-liu1abfb632016-11-09 15:22:51 +0800153
154 @Override
155 public void updateTunnelState(Tunnel tunnel, State state) {
156 // TODO Auto-generated method stub
157 }
Priyanka B413fbe82016-05-26 11:44:45 +0530158 }
159
160 private class MockMasterShipService extends MastershipServiceAdapter {
161 boolean set;
162
163 private void setMaster(boolean isMaster) {
164 this.set = isMaster;
165 }
166
167 @Override
168 public MastershipRole getLocalRole(DeviceId deviceId) {
169 return set ? MastershipRole.MASTER : MastershipRole.STANDBY;
170 }
171
172 @Override
173 public boolean isLocalMaster(DeviceId deviceId) {
174 return getLocalRole(deviceId) == MASTER;
175 }
176 }
177
178 private class MockDeviceService extends DeviceServiceAdapter {
179 List<Device> devices = new LinkedList<>();
180
181 private void addDevice(Device dev) {
182 devices.add(dev);
183 }
184
185 @Override
186 public Iterable<Device> getAvailableDevices() {
187 return devices;
188 }
189 }
Avantika-Huawei56c11842016-04-28 00:56:56 +0530190
191 private class MockTunnelProviderRegistryAdapter extends TunnelProviderRegistryAdapter {
192 public long tunnelIdCounter;
193
194 @Override
195 public TunnelProviderService register(TunnelProvider provider) {
196 this.provider = provider;
197 return new TestProviderService();
198 }
199
200 private class TestProviderService implements TunnelProviderService {
201
202 @Override
203 public TunnelProvider provider() {
204 return null;
205 }
206
207 @Override
208 public TunnelId tunnelAdded(TunnelDescription tunnel) {
Priyanka B413fbe82016-05-26 11:44:45 +0530209 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
210 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
211 tunnel.src(), tunnel.dst(),
212 tunnel.type(),
213 tunnel.groupId(),
214 id,
215 tunnel.tunnelName(),
216 tunnel.path(),
217 tunnel.resource(),
218 tunnel.annotations());
219 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
220 return id;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530221 }
222
223 @Override
224 public TunnelId tunnelAdded(TunnelDescription tunnel, State state) {
Priyanka B413fbe82016-05-26 11:44:45 +0530225 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
226 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
227 tunnel.src(), tunnel.dst(),
228 tunnel.type(),
229 tunnel.groupId(),
230 id,
231 tunnel.tunnelName(),
232 tunnel.path(),
233 tunnel.resource(),
234 tunnel.annotations());
235 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
236 return id;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530237 }
238
239 @Override
240 public void tunnelRemoved(TunnelDescription tunnel) {
241 }
242
243 @Override
244 public void tunnelUpdated(TunnelDescription tunnel) {
245 }
246
247 @Override
248 public void tunnelUpdated(TunnelDescription tunnel, State state) {
Priyanka B4c3b4512016-07-22 11:41:49 +0530249 TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
250 Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
251 tunnel.src(), tunnel.dst(),
252 tunnel.type(),
253 tunnel.groupId(),
254 id,
255 tunnel.tunnelName(),
256 tunnel.path(),
257 tunnel.resource(),
258 tunnel.annotations());
259 tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530260 }
261
262 @Override
263 public Tunnel tunnelQueryById(TunnelId tunnelId) {
264 return null;
265 }
266 }
267 }
268
269 private class MockTunnelServiceAdapter extends TunnelServiceAdapter {
270 private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<>();
271 private int tunnelIdCounter = 0;
272
273 @Override
274 public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
275 TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
276 tunnelIdAsKeyStore.put(tunnelId, tunnel);
277 return tunnelId;
278 }
279
280 @Override
281 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
282 Collection<Tunnel> result = new HashSet<>();
283 Tunnel tunnel = null;
284 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
285 tunnel = tunnelIdAsKeyStore.get(tunnelId);
286
287 if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
288 result.add(tunnel);
289 }
290 }
291
292 return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
293 }
294
295 @Override
296 public Collection<Tunnel> queryAllTunnels() {
297 Collection<Tunnel> result = new HashSet<>();
298
299 for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
300 result.add(tunnelIdAsKeyStore.get(tunnelId));
301 }
302
303 return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
304
305 }
306 }
307
308 @Before
309 public void preSetup() {
310 tunnelProvider.tunnelProviderRegistry = registry;
311 tunnelProvider.pcepClientController = controller;
312 tunnelProvider.controller = ctl;
Priyanka B413fbe82016-05-26 11:44:45 +0530313 tunnelProvider.deviceService = deviceService;
314 tunnelProvider.mastershipService = masterShipService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530315 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
316 tunnelProvider.cfgService = new ComponentConfigAdapter();
317 tunnelProvider.tunnelService = tunnelService;
Priyanka B413fbe82016-05-26 11:44:45 +0530318 tunnelProvider.tunnelAdminService = tunnelAdminService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530319 tunnelProvider.service = registry.register(tunnelProvider);
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530320 tunnelProvider.linkService = linkService;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530321 tunnelProvider.activate();
322 }
323
324 /**
325 * Tests PCRpt msg with sync flag set.
326 */
327 @Test
328 public void tunnelProviderAddedTest1() throws PcepParseException, PcepOutOfBoundMessageException {
329 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
330 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
331 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
332 0x00, 0x00, 0x00, 0x02,
333 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
334 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
335 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
336 0x01, 0x01, 0x01, 0x01,
337 0x00, 0x01, 0x00, 0x01,
338 0x01, 0x01, 0x01, 0x01,
339 0x05, 0x05, 0x05, 0x05,
340
341 0x07, 0x10, 0x00, 0x14, //ERO object
342 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
343 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
344
345 0x08, 0x10, 0x00, 0x34, //RRO object
346 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
347 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
348 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
349 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
350 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
351 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
352 };
353
354 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
355 buffer.writeBytes(reportMsg);
356
357 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
358 PcepMessage message = reader.readFrom(buffer);
Priyanka B413fbe82016-05-26 11:44:45 +0530359
360 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
361 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
362 newBuilder.set(AnnotationKeys.TYPE, "L3");
363 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
364 UNKOWN, UNKOWN, UNKOWN,
365 UNKOWN, new ChassisId(),
366 newBuilder.build());
367
368 deviceService.addDevice(device);
369 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
370 new ClientCapability(true, true, true, true, true));
371 masterShipService.setMaster(true);
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530372 Link link = DefaultLink.builder()
373 .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
374 .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
375 .state(ACTIVE)
376 .type(Link.Type.DIRECT)
377 .providerId(ProviderId.NONE)
378 .build();
379 linkService.addLink(link);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530380 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
381
382 assertThat(registry.tunnelIdCounter, is((long) 1));
383 }
384
385 /**
386 * Tests updating an existing tunnel on receiving asynchronous PCRpt msg,
387 * i.e. without any SRP id.
388 */
389 @Test
390 public void tunnelProviderAddedTest2() throws PcepParseException, PcepOutOfBoundMessageException {
391 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x50,
392 0x21, 0x10, 0x00, 0x14, //SRP object
393 0x00, 0x00, 0x00, 0x00,
394 0x00, 0x00, 0x00, 0x00,
395 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
396 0x00, 0x00, 0x00, 0x02,
397 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, //LSP object
398 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path TLV
399 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
400 0x4e, 0x1f, 0x04, 0x00,
401 0x00, 0x01, 0x00, 0x01,
402 0x4e, 0x1f, 0x04, 0x00,
403 0x4e, 0x20, 0x04, 0x00,
404 0x07, 0x10, 0x00, 0x14, //ERO object
405 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, // ERO IPv4 sub objects
406 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
407 };
408
409 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
410 buffer.writeBytes(reportMsg);
411
412 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
413 PcepMessage message = reader.readFrom(buffer);
414
415 // create an existing tunnel.
416 IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e1f0400));
417 IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e200400));
418
419 SparseAnnotations annotations = DefaultAnnotations.builder()
420 .set(BANDWIDTH, (new Integer(1)).toString())
421 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
422 .set(PCC_TUNNEL_ID, String.valueOf(1))
423 .set(PLSP_ID, String.valueOf(1))
Priyanka B413fbe82016-05-26 11:44:45 +0530424 .set(LOCAL_LSP_ID, String.valueOf(1))
425 .set(DELEGATE, String.valueOf("true"))
426 .build();
Avantika-Huawei56c11842016-04-28 00:56:56 +0530427
428 Tunnel tunnel = new DefaultTunnel(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, INIT, null, null,
429 TunnelName.tunnelName("T123"), null, annotations);
430 tunnelService.setupTunnel(null, null, tunnel, null);
431
432 PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400));
Priyanka B413fbe82016-05-26 11:44:45 +0530433 PcepClientAdapter pc = new PcepClientAdapter();
434 pc.init(pccId, PcepVersion.PCEP_1);
435 masterShipService.setMaster(true);
436 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
437 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530438 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530439
440 // Process update message.
441 controller.processClientMessage(pccId, message);
442 assertThat(tunnelService.queryAllTunnels().size(), is(1));
443 }
444
445 /**
446 * Tests adding a new tunnel on receiving asynchronous PCRpt msg,
447 * i.e. without any SRP id.
448 */
449 @Test
450 public void tunnelProviderAddedTest3() throws PcepParseException, PcepOutOfBoundMessageException {
451 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
452 0x21, 0x10, 0x00, 0x14, //SRP object
453 0x00, 0x00, 0x00, 0x00,
454 0x00, 0x00, 0x00, 0x00,
455 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
456 0x00, 0x00, 0x00, 0x02,
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530457 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x1B, // LSP object
Avantika-Huawei56c11842016-04-28 00:56:56 +0530458 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
459 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
460 0x01, 0x01, 0x01, 0x01,
461 0x00, 0x01, 0x00, 0x01,
462 0x01, 0x01, 0x01, 0x01,
463 0x05, 0x05, 0x05, 0x05,
464
465 0x07, 0x10, 0x00, 0x14, //ERO object
466 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
467 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
468
469 0x08, 0x10, 0x00, 0x34, //RRO object
470 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
471 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
472 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
473 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
474 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
475 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
476 };
477
478 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
479 buffer.writeBytes(reportMsg);
480
481 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
482 PcepMessage message = reader.readFrom(buffer);
483
Priyanka B413fbe82016-05-26 11:44:45 +0530484 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
485 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
486 newBuilder.set(AnnotationKeys.TYPE, "L3");
487 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
488 UNKOWN, UNKOWN, UNKOWN,
489 UNKOWN, new ChassisId(),
490 newBuilder.build());
491
492 deviceService.addDevice(device);
493
Avantika-Huawei56c11842016-04-28 00:56:56 +0530494 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530495 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Priyanka B413fbe82016-05-26 11:44:45 +0530496 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
497
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530498 Link link = DefaultLink.builder()
499 .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
500 .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
501 .state(ACTIVE)
502 .type(Link.Type.DIRECT)
503 .providerId(ProviderId.NONE)
504 .build();
505 linkService.addLink(link);
Priyanka B413fbe82016-05-26 11:44:45 +0530506 PcepClientAdapter pc = new PcepClientAdapter();
507 pc.init(pccId, PcepVersion.PCEP_1);
508 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
509 masterShipService.setMaster(true);
Avantika-Huawei56c11842016-04-28 00:56:56 +0530510 controller.processClientMessage(pccId, message);
511
512 assertThat(registry.tunnelIdCounter, is((long) 1));
513 }
514
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530515 /**
Priyanka B413fbe82016-05-26 11:44:45 +0530516 * Tests PCRpt msg with D flag set and delegated to non-master.
517 *
518 * @throws InterruptedException while waiting for delay
519 */
520 @Test
521 public void tunnelProviderAddedTest4() throws PcepParseException, PcepOutOfBoundMessageException,
522 InterruptedException {
523 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
524 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
525 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
526 0x00, 0x00, 0x00, 0x02,
527 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x02, //LSP object
528 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
529 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
530 0x01, 0x01, 0x01, 0x01,
531 0x00, 0x01, 0x00, 0x01,
532 0x01, 0x01, 0x01, 0x01,
533 0x05, 0x05, 0x05, 0x05,
534
535 0x07, 0x10, 0x00, 0x14, //ERO object
536 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
537 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
538
539 0x08, 0x10, 0x00, 0x34, //RRO object
540 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
541 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
542 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
543 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
544 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
545 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
546 };
547
548 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
549 buffer.writeBytes(reportMsg);
550
551 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
552 PcepMessage message = reader.readFrom(buffer);
553
554 //PCC 1.1.1.1, D=0, ONOS as master
555 masterShipService.setMaster(true);
556 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
557 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
558 newBuilder.set(AnnotationKeys.TYPE, "L3");
559 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
560 UNKOWN, UNKOWN, UNKOWN,
561 UNKOWN, new ChassisId(),
562 newBuilder.build());
563
564 deviceService.addDevice(device);
565 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
566 new ClientCapability(true, true, true, true, true));
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530567 Link link = DefaultLink.builder()
568 .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
569 .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
570 .state(ACTIVE)
571 .type(Link.Type.DIRECT)
572 .providerId(ProviderId.NONE)
573 .build();
574 linkService.addLink(link);
Priyanka B413fbe82016-05-26 11:44:45 +0530575 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
576 assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
577 is("false"));
578
579 //PCC 1.1.1.1, D=1, non-master
580 masterShipService.setMaster(false);
581
582 reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
583 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
584 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
585 0x00, 0x00, 0x00, 0x02,
586 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
587 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
588 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
589 0x01, 0x01, 0x01, 0x01,
590 0x00, 0x01, 0x00, 0x01,
591 0x01, 0x01, 0x01, 0x01,
592 0x05, 0x05, 0x05, 0x05,
593
594 0x07, 0x10, 0x00, 0x14, //ERO object
595 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
596 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
597
598 0x08, 0x10, 0x00, 0x34, //RRO object
599 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
600 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
601 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
602 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
603 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
604 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
605 };
606
607 buffer = ChannelBuffers.dynamicBuffer();
608 buffer.writeBytes(reportMsg);
609
610 reader = PcepFactories.getGenericReader();
611 message = reader.readFrom(buffer);
612
613 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
614 TimeUnit.MILLISECONDS.sleep(4000);
Priyanka B4c3b4512016-07-22 11:41:49 +0530615 assertThat(registry.tunnelIdCounter, is((long) 2));
616
617 Iterator<Tunnel> iterator = tunnelService.tunnelIdAsKeyStore.values().iterator();
618 iterator.next();
619 assertThat(iterator.next().annotations().value(DELEGATE),
Priyanka B413fbe82016-05-26 11:44:45 +0530620 is("true"));
621 }
622
623 /**
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530624 * Tests adding PCC Init LSP after LSP DB sync is over.
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530625 */
626 @Test
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530627 public void tunnelProviderAddedTest5() throws PcepParseException, PcepOutOfBoundMessageException {
628 byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530629 0x21, 0x10, 0x00, 0x14, //SRP object
630 0x00, 0x00, 0x00, 0x00,
631 0x00, 0x00, 0x00, 0x00,
632 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530633 0x00, 0x00, 0x00, 0x02,
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530634 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530635 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530636 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
637 0x01, 0x01, 0x01, 0x01,
638 0x00, 0x01, 0x00, 0x01,
639 0x01, 0x01, 0x01, 0x01,
640 0x05, 0x05, 0x05, 0x05,
641
642 0x07, 0x10, 0x00, 0x14, //ERO object
643 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
644 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
645
646 0x08, 0x10, 0x00, 0x34, //RRO object
647 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
648 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
649 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
650 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
651 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
652 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
653 };
654
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530655 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
656 buffer.writeBytes(reportMsg);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530657
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530658 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
659 PcepMessage message = reader.readFrom(buffer);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530660
Priyanka B413fbe82016-05-26 11:44:45 +0530661 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
662 newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
663 newBuilder.set(AnnotationKeys.TYPE, "L3");
664 Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
665 UNKOWN, UNKOWN, UNKOWN,
666 UNKOWN, new ChassisId(),
667 newBuilder.build());
668
669 deviceService.addDevice(device);
670
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530671 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530672 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
Priyanka B413fbe82016-05-26 11:44:45 +0530673 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
674
675 PcepClientAdapter pc = new PcepClientAdapter();
676 pc.init(pccId, PcepVersion.PCEP_1);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530677 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
Priyanka B413fbe82016-05-26 11:44:45 +0530678 masterShipService.setMaster(true);
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530679 controller.processClientMessage(pccId, message);
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530680
Avantika-Huaweid1e36bd2016-05-26 12:47:16 +0530681 assertThat(registry.tunnelIdCounter, is((long) 0));
Avantika-Huawei7f7376a2016-05-11 17:07:50 +0530682 }
683
Avantika-Huawei56c11842016-04-28 00:56:56 +0530684 @After
685 public void tearDown() throws IOException {
686 tunnelProvider.deactivate();
687 tunnelProvider.controller = null;
688 tunnelProvider.pcepClientController = null;
689 tunnelProvider.tunnelProviderRegistry = null;
690
691 tunnelProvider.pcepTunnelApiMapper = null;
692 tunnelProvider.cfgService = null;
693 tunnelProvider.tunnelService = null;
Priyanka B413fbe82016-05-26 11:44:45 +0530694 tunnelProvider.tunnelAdminService = null;
695 tunnelProvider.deviceService = null;
696 tunnelProvider.mastershipService = null;
Priyanka Bc1e4e4c2016-07-01 14:57:19 +0530697 tunnelProvider.linkService = null;
Avantika-Huawei56c11842016-04-28 00:56:56 +0530698 tunnelProvider.service = null;
699 }
700}