blob: d212fb4277bd60b19d3e08111f01ae1918ed8770 [file] [log] [blame]
Shashikanth VH1ca26ce2015-11-20 23:19:49 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Shashikanth VH1ca26ce2015-11-20 23:19:49 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5 * the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 * specific language governing permissions and limitations under the License.
12 */
13package org.onosproject.provider.bgp.topology.impl;
14
Priyanka Bfc51c952016-03-26 14:30:33 +053015import static org.hamcrest.MatcherAssert.assertThat;
16import static org.hamcrest.core.Is.is;
17import static org.hamcrest.core.IsNot.not;
18import static org.onosproject.net.Link.State.ACTIVE;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053019
20import java.util.Collection;
Priyanka Bfc51c952016-03-26 14:30:33 +053021import java.util.HashMap;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053022import java.util.HashSet;
23import java.util.LinkedList;
24import java.util.List;
25import java.util.Map;
26import java.util.Set;
27import java.util.concurrent.CopyOnWriteArraySet;
28
29import org.junit.After;
30import org.junit.Before;
31import org.junit.Test;
Priyanka Bfc51c952016-03-26 14:30:33 +053032import org.onlab.packet.ChassisId;
33import org.onosproject.bgp.controller.BgpLinkListener;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053034import org.onosproject.bgp.controller.BgpNodeListener;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053035import org.onosproject.bgpio.exceptions.BgpParseException;
Priyanka Bfc51c952016-03-26 14:30:33 +053036import org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier;
37import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053038import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier;
39import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
Priyanka Bfc51c952016-03-26 14:30:33 +053040import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053041import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors;
Priyanka Bfc51c952016-03-26 14:30:33 +053042import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053043import org.onosproject.bgpio.types.AutonomousSystemTlv;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053044import org.onosproject.bgpio.types.BgpValueType;
Priyanka Bfc51c952016-03-26 14:30:33 +053045import org.onosproject.bgpio.types.IsIsNonPseudonode;
46import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053047import org.onosproject.bgpio.types.RouteDistinguisher;
48import org.onosproject.bgpio.util.Constants;
Priyanka Bfc51c952016-03-26 14:30:33 +053049import org.onosproject.net.ConnectPoint;
50import org.onosproject.net.DefaultDevice;
51import org.onosproject.net.DefaultLink;
52import org.onosproject.net.Device;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053053import org.onosproject.net.DeviceId;
Priyanka Bfc51c952016-03-26 14:30:33 +053054import org.onosproject.net.Link;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053055import org.onosproject.net.MastershipRole;
56import org.onosproject.net.device.DeviceDescription;
57import org.onosproject.net.device.DeviceProvider;
58import org.onosproject.net.device.DeviceProviderRegistry;
59import org.onosproject.net.device.DeviceProviderService;
Priyanka Bfc51c952016-03-26 14:30:33 +053060import org.onosproject.net.device.DeviceServiceAdapter;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053061import org.onosproject.net.device.PortDescription;
62import org.onosproject.net.device.PortStatistics;
Priyanka Bfc51c952016-03-26 14:30:33 +053063import org.onosproject.net.link.LinkDescription;
64import org.onosproject.net.link.LinkProvider;
65import org.onosproject.net.link.LinkProviderRegistry;
66import org.onosproject.net.link.LinkProviderService;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053067import org.onosproject.net.provider.ProviderId;
68
Priyanka Bfc51c952016-03-26 14:30:33 +053069/**
70 * Test for BGP topology provider.
71 */
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053072public class BgpTopologyProviderTest {
Priyanka Bfc51c952016-03-26 14:30:33 +053073 private static final DeviceId DID2 = DeviceId.deviceId("bgp:rd=0::routinguniverse=0:asn=10");
74 private static final String UNKNOWN = new String("unknown");
75 public static ProviderId providerId = new ProviderId("bgp", "foo");
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053076
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053077 private final BgpTopologyProvider provider = new BgpTopologyProvider();
78 private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry();
Priyanka Bfc51c952016-03-26 14:30:33 +053079 private final TestLinkRegistry linkRegistry = new TestLinkRegistry();
80 private final MockBgpController controller = new MockBgpController();
81 private MockDeviceService deviceService = new MockDeviceService();
82 private Map<DeviceId, Device> deviceMap = new HashMap<>();
83
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053084
85 @Before
86 public void startUp() {
87 provider.deviceProviderRegistry = nodeRegistry;
Priyanka Bfc51c952016-03-26 14:30:33 +053088 provider.linkProviderRegistry = linkRegistry;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053089 provider.controller = controller;
Priyanka Bfc51c952016-03-26 14:30:33 +053090 provider.deviceService = deviceService;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053091 provider.activate();
Priyanka Bfc51c952016-03-26 14:30:33 +053092 assertThat("device provider should be registered", not(nodeRegistry.provider));
93 assertThat("link provider should be registered", not(linkRegistry.linkProvider));
94 assertThat("node listener should be registered", not(controller.nodeListener));
95 assertThat("link listener should be registered", not(controller.linkListener));
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053096 }
97
98 @After
99 public void tearDown() {
100 provider.deactivate();
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530101 provider.controller = null;
Priyanka Bfc51c952016-03-26 14:30:33 +0530102 provider.deviceService = null;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530103 provider.deviceProviderRegistry = null;
Priyanka Bfc51c952016-03-26 14:30:33 +0530104 assertThat(controller.nodeListener, is(new HashSet<BgpNodeListener>()));
105 assertThat(controller.linkListener, is(new HashSet<BgpLinkListener>()));
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530106 }
107
108 /* Class implement device test registry */
109 private class TestDeviceRegistry implements DeviceProviderRegistry {
110 DeviceProvider provider;
111
112 Set<DeviceId> connected = new HashSet<>();
113
114 @Override
115 public DeviceProviderService register(DeviceProvider provider) {
116 this.provider = provider;
117 return new TestProviderService();
118 }
119
120 @Override
121 public void unregister(DeviceProvider provider) {
122 }
123
124 @Override
125 public Set<ProviderId> getProviders() {
126 return null;
127 }
128
129 private class TestProviderService implements DeviceProviderService {
130
131 @Override
132 public DeviceProvider provider() {
133 return null;
134 }
135
136 @Override
137 public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) {
Priyanka Bfc51c952016-03-26 14:30:33 +0530138 if (!deviceId.equals(DID2)) {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530139 connected.add(deviceId);
Priyanka Bfc51c952016-03-26 14:30:33 +0530140 Device device = new DefaultDevice(BgpTopologyProviderTest.providerId, deviceId, Device.Type.ROUTER,
141 UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId());
142 deviceMap.put(deviceId, device);
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530143 }
144 }
145
146 @Override
147 public void deviceDisconnected(DeviceId deviceId) {
Priyanka Bfc51c952016-03-26 14:30:33 +0530148 if (!deviceId.equals(DID2)) {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530149 connected.remove(deviceId);
Priyanka Bfc51c952016-03-26 14:30:33 +0530150 deviceMap.remove(deviceId);
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530151 }
152 }
153
154 @Override
155 public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) {
156 // TODO Auto-generated method stub
157
158 }
159
160 @Override
161 public void portStatusChanged(DeviceId deviceId, PortDescription portDescription) {
162 // TODO Auto-generated method stub
163
164 }
165
166 @Override
167 public void receivedRoleReply(DeviceId deviceId, MastershipRole requested, MastershipRole response) {
168 // TODO Auto-generated method stub
169
170 }
171
172 @Override
173 public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) {
174 // TODO Auto-generated method stub
175
176 }
177 }
178 }
179
Priyanka Bfc51c952016-03-26 14:30:33 +0530180 /* Class implement device test registry */
181 private class TestLinkRegistry implements LinkProviderRegistry {
182 LinkProvider linkProvider;
183 Set<Link> links = new HashSet<>();
184
185 @Override
186 public LinkProviderService register(LinkProvider provider) {
187 this.linkProvider = provider;
188 return new TestProviderService();
189 }
190
191 @Override
192 public void unregister(LinkProvider provider) {
193 // TODO Auto-generated method stub
194 }
195
196 @Override
197 public Set<ProviderId> getProviders() {
198 return null;
199 }
200
201 private class TestProviderService implements LinkProviderService {
202
203 @Override
204 public void linkDetected(LinkDescription linkDescription) {
205 links.add(DefaultLink.builder().src(linkDescription.src())
206 .dst(linkDescription.dst()).state(ACTIVE).type(linkDescription.type())
207 .providerId(BgpTopologyProviderTest.providerId).build());
208 }
209
210 @Override
211 public void linkVanished(LinkDescription linkDescription) {
212 links.remove(DefaultLink.builder().src(linkDescription.src())
213 .dst(linkDescription.dst()).state(ACTIVE).type(linkDescription.type())
214 .providerId(BgpTopologyProviderTest.providerId).build());
215 }
216
217 @Override
218 public void linksVanished(ConnectPoint connectPoint) {
219 // TODO Auto-generated method stub
220 }
221
222 @Override
223 public void linksVanished(DeviceId deviceId) {
224 // TODO Auto-generated method stub
225 }
226
227 @Override
228 public LinkProvider provider() {
229 // TODO Auto-generated method stub
230 return null;
231 }
232 }
233 }
234
235 /* Test class for BGP controller */
236 private class MockBgpController extends BgpControllerAdapter {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530237 protected Set<BgpNodeListener> nodeListener = new CopyOnWriteArraySet<>();
Priyanka Bfc51c952016-03-26 14:30:33 +0530238 protected Set<BgpLinkListener> linkListener = new CopyOnWriteArraySet<>();
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530239
240 @Override
241 public void addListener(BgpNodeListener nodeListener) {
242 this.nodeListener.add(nodeListener);
243 }
244
245 @Override
246 public void removeListener(BgpNodeListener nodeListener) {
Priyanka Bfc51c952016-03-26 14:30:33 +0530247 this.nodeListener.remove(nodeListener);
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530248 }
249
250 @Override
Priyanka Bfc51c952016-03-26 14:30:33 +0530251 public void addLinkListener(BgpLinkListener linkListener) {
252 this.linkListener.add(linkListener);
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530253 }
254
255 @Override
Priyanka Bfc51c952016-03-26 14:30:33 +0530256 public void removeLinkListener(BgpLinkListener linkListener) {
257 this.linkListener.remove(linkListener);
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530258 }
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530259 }
260
Priyanka Bfc51c952016-03-26 14:30:33 +0530261 /* Mock test for device service */
262 private class MockDeviceService extends DeviceServiceAdapter {
263 @Override
264 public Device getDevice(DeviceId deviceId) {
265 return deviceMap.get(deviceId);
266 }
267 }
268
269 /**
270 * Validate node is added to the device validating URI, RIB should get updated properly.
271 */
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530272 @Test
273 public void bgpTopologyProviderTestAddDevice1() {
Priyanka Bfc51c952016-03-26 14:30:33 +0530274 LinkedList<BgpValueType> subTlvs = new LinkedList<>();
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530275 BgpValueType tlv = new AutonomousSystemTlv(100);
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530276 short deslength = AutonomousSystemTlv.LENGTH;
277 short desType = AutonomousSystemTlv.TYPE;
278
279 subTlvs.add(tlv);
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530280 BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength,
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530281 desType));
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530282 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530283 new RouteDistinguisher());
284
Priyanka Bfc51c952016-03-26 14:30:33 +0530285 PathAttrNlriDetails details = new PathAttrNlriDetails();
286 details.setIdentifier(0);
287 details.setProtocolID(ProtocolType.DIRECT);
288 List<BgpValueType> pathAttributes = new LinkedList<>();
289 details.setPathAttribute(pathAttributes);
290
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530291 for (BgpNodeListener l : controller.nodeListener) {
Priyanka Bfc51c952016-03-26 14:30:33 +0530292 l.addNode(nodeNlri, details);
293 assertThat(nodeRegistry.connected.size(), is(1));
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530294 l.deleteNode(nodeNlri);
Priyanka Bfc51c952016-03-26 14:30:33 +0530295 assertThat(nodeRegistry.connected.size(), is(0));
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530296 }
297 }
298
Priyanka Bfc51c952016-03-26 14:30:33 +0530299 /**
300 * Validate node is not added to the device for invalid URI, RIB count should be zero.
301 */
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530302 @Test
303 public void bgpTopologyProviderTestAddDevice2() {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530304 LinkedList<BgpValueType> subTlvs;
305 BgpValueType tlv = new AutonomousSystemTlv(10);
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530306 short deslength = AutonomousSystemTlv.LENGTH;
307 short desType = AutonomousSystemTlv.TYPE;
308
Priyanka Bfc51c952016-03-26 14:30:33 +0530309 PathAttrNlriDetails details = new PathAttrNlriDetails();
310 details.setIdentifier(0);
311 details.setProtocolID(ProtocolType.DIRECT);
312 List<BgpValueType> pathAttributes = new LinkedList<>();
313 details.setPathAttribute(pathAttributes);
314
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530315 subTlvs = new LinkedList<>();
316 subTlvs.add(tlv);
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530317 BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength,
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530318 desType));
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530319 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530320 new RouteDistinguisher());
321
Priyanka Bfc51c952016-03-26 14:30:33 +0530322
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530323 for (BgpNodeListener l : controller.nodeListener) {
Priyanka Bfc51c952016-03-26 14:30:33 +0530324 l.addNode(nodeNlri, details);
325 assertThat(nodeRegistry.connected.size(), is(0));
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530326 }
327 }
328
Priyanka Bfc51c952016-03-26 14:30:33 +0530329 /**
330 * Delete node when node does not exist, RIB count should be zero.
331 */
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530332 @Test
333 public void bgpTopologyProviderTestAddDevice3() {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530334 LinkedList<BgpValueType> subTlvs;
335 BgpValueType tlv = new AutonomousSystemTlv(10);
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530336 short deslength = AutonomousSystemTlv.LENGTH;
337 short desType = AutonomousSystemTlv.TYPE;
338
339 subTlvs = new LinkedList<>();
340 subTlvs.add(tlv);
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530341 BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength,
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530342 desType));
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +0530343 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530344 new RouteDistinguisher());
345
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530346 for (BgpNodeListener l : controller.nodeListener) {
347 l.deleteNode(nodeNlri);
Priyanka Bfc51c952016-03-26 14:30:33 +0530348 assertThat(nodeRegistry.connected.size(), is(0));
349 }
350 }
351
352 /**
353 * Add a link and two devices.
354 *
355 * @throws BgpParseException while adding a link.
356 */
357 @Test
358 public void bgpTopologyProviderTestAddLink1() throws BgpParseException {
359 LinkedList<BgpValueType> localTlvs = new LinkedList<>();
360 LinkedList<BgpValueType> remoteTlvs = new LinkedList<>();
361 LinkedList<BgpValueType> linkdes = new LinkedList<>();
362 BgpValueType tlv = new AutonomousSystemTlv(10);
363 short deslength = AutonomousSystemTlv.LENGTH;
364 short desType = AutonomousSystemTlv.TYPE;
365
366 localTlvs.add(tlv);
367 remoteTlvs.add(tlv);
368 tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20});
369 localTlvs.add(tlv);
370 tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30});
371 remoteTlvs.add(tlv);
372 NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType);
373 NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType);
374 BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode);
375 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
376 new RouteDistinguisher());
377
378 BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode);
379 BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false,
380 new RouteDistinguisher());
381
382 PathAttrNlriDetails details = new PathAttrNlriDetails();
383 details.setIdentifier(0);
384 details.setProtocolID(ProtocolType.DIRECT);
385 List<BgpValueType> pathAttributes = new LinkedList<>();
386 details.setPathAttribute(pathAttributes);
387
388 tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100);
389 linkdes.add(tlv);
390 BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes);
391 BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId,
392 new RouteDistinguisher(), false);
393 for (BgpNodeListener l : controller.nodeListener) {
394 l.addNode(nodeNlri, details);
395 assertThat(nodeRegistry.connected.size(), is(1));
396 l.addNode(remNodeNlri, details);
397 assertThat(nodeRegistry.connected.size(), is(2));
398 }
399 for (BgpLinkListener l : controller.linkListener) {
400 l.addLink(linkNlri, details);
401 assertThat(linkRegistry.links.size(), is(1));
402 }
403 }
404
405 /**
406 * Add a link and delete a link.
407 *
408 * @throws BgpParseException while adding or removing the link
409 */
410 @Test
411 public void bgpTopologyProviderTestAddLink2() throws BgpParseException {
412 LinkedList<BgpValueType> localTlvs = new LinkedList<>();
413 LinkedList<BgpValueType> remoteTlvs = new LinkedList<>();
414 LinkedList<BgpValueType> linkdes = new LinkedList<>();
415 BgpValueType tlv = new AutonomousSystemTlv(10);
416 short deslength = AutonomousSystemTlv.LENGTH;
417 short desType = AutonomousSystemTlv.TYPE;
418
419 localTlvs.add(tlv);
420 remoteTlvs.add(tlv);
421 tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20});
422 localTlvs.add(tlv);
423 tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30});
424 remoteTlvs.add(tlv);
425 NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType);
426 NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType);
427 BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode);
428 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
429 new RouteDistinguisher());
430
431 BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode);
432 BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false,
433 new RouteDistinguisher());
434
435 PathAttrNlriDetails details = new PathAttrNlriDetails();
436 details.setIdentifier(0);
437 details.setProtocolID(ProtocolType.DIRECT);
438 List<BgpValueType> pathAttributes = new LinkedList<>();
439 details.setPathAttribute(pathAttributes);
440
441 tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100);
442 linkdes.add(tlv);
443 BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes);
444 BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId,
445 new RouteDistinguisher(), false);
446 for (BgpNodeListener l : controller.nodeListener) {
447 l.addNode(nodeNlri, details);
448 assertThat(nodeRegistry.connected.size(), is(1));
449 l.addNode(remNodeNlri, details);
450 assertThat(nodeRegistry.connected.size(), is(2));
451 l.deleteNode(nodeNlri);
452 assertThat(nodeRegistry.connected.size(), is(1));
453 }
454 for (BgpLinkListener l : controller.linkListener) {
455 l.addLink(linkNlri, details);
456 assertThat(linkRegistry.links.size(), is(1));
457 l.deleteLink(linkNlri);
458 assertThat(linkRegistry.links.size(), is(0));
459 }
460 }
461
462 /**
463 * Invalid link.
464 *
465 * @throws BgpParseException while adding or deleting a link
466 */
467 @Test
468 public void bgpTopologyProviderTestDeleteLink3() throws BgpParseException {
469 LinkedList<BgpValueType> localTlvs = new LinkedList<>();
470 LinkedList<BgpValueType> remoteTlvs = new LinkedList<>();
471 LinkedList<BgpValueType> linkdes = new LinkedList<>();
472 BgpValueType tlv = new AutonomousSystemTlv(10);
473 short deslength = AutonomousSystemTlv.LENGTH;
474 short desType = AutonomousSystemTlv.TYPE;
475
476 localTlvs.add(tlv);
477 remoteTlvs.add(tlv);
478 tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20});
479 localTlvs.add(tlv);
480 tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30});
481 remoteTlvs.add(tlv);
482 NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType);
483 NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType);
484 BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode);
485 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
486 new RouteDistinguisher());
487
488 BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode);
489 BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false,
490 new RouteDistinguisher());
491
492 PathAttrNlriDetails details = new PathAttrNlriDetails();
493 details.setIdentifier(0);
494 details.setProtocolID(ProtocolType.DIRECT);
495 List<BgpValueType> pathAttributes = new LinkedList<>();
496 details.setPathAttribute(pathAttributes);
497
498 tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100);
499 linkdes.add(tlv);
500 BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes);
501 BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId,
502 new RouteDistinguisher(), false);
503 for (BgpNodeListener l : controller.nodeListener) {
504 l.addNode(nodeNlri, details);
505 l.addNode(remNodeNlri, details);
506 assertThat(nodeRegistry.connected.size(), is(2));
507 l.deleteNode(nodeNlri);
508 assertThat(nodeRegistry.connected.size(), is(1));
509 }
510 for (BgpLinkListener l : controller.linkListener) {
511 l.deleteLink(linkNlri);
512 assertThat(linkRegistry.links.size(), is(0));
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530513 }
514 }
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530515}