Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 3 | * |
| 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 | */ |
| 13 | package org.onosproject.provider.bgp.topology.impl; |
| 14 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 15 | import static org.hamcrest.MatcherAssert.assertThat; |
| 16 | import static org.hamcrest.core.Is.is; |
| 17 | import static org.hamcrest.core.IsNot.not; |
| 18 | import static org.onosproject.net.Link.State.ACTIVE; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 19 | |
| 20 | import java.util.Collection; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 21 | import java.util.HashMap; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 22 | import java.util.HashSet; |
| 23 | import java.util.LinkedList; |
| 24 | import java.util.List; |
| 25 | import java.util.Map; |
| 26 | import java.util.Set; |
| 27 | import java.util.concurrent.CopyOnWriteArraySet; |
| 28 | |
| 29 | import org.junit.After; |
| 30 | import org.junit.Before; |
| 31 | import org.junit.Test; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 32 | import org.onlab.packet.ChassisId; |
| 33 | import org.onosproject.bgp.controller.BgpLinkListener; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 34 | import org.onosproject.bgp.controller.BgpNodeListener; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 35 | import org.onosproject.bgpio.exceptions.BgpParseException; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 36 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier; |
| 37 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 38 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier; |
| 39 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 40 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 41 | import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 42 | import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 43 | import org.onosproject.bgpio.types.AutonomousSystemTlv; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 44 | import org.onosproject.bgpio.types.BgpValueType; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 45 | import org.onosproject.bgpio.types.IsIsNonPseudonode; |
| 46 | import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 47 | import org.onosproject.bgpio.types.RouteDistinguisher; |
| 48 | import org.onosproject.bgpio.util.Constants; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 49 | import org.onosproject.net.ConnectPoint; |
| 50 | import org.onosproject.net.DefaultDevice; |
| 51 | import org.onosproject.net.DefaultLink; |
| 52 | import org.onosproject.net.Device; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 53 | import org.onosproject.net.DeviceId; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 54 | import org.onosproject.net.Link; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 55 | import org.onosproject.net.MastershipRole; |
| 56 | import org.onosproject.net.device.DeviceDescription; |
| 57 | import org.onosproject.net.device.DeviceProvider; |
| 58 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 59 | import org.onosproject.net.device.DeviceProviderService; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 60 | import org.onosproject.net.device.DeviceServiceAdapter; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 61 | import org.onosproject.net.device.PortDescription; |
| 62 | import org.onosproject.net.device.PortStatistics; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 63 | import org.onosproject.net.link.LinkDescription; |
| 64 | import org.onosproject.net.link.LinkProvider; |
| 65 | import org.onosproject.net.link.LinkProviderRegistry; |
| 66 | import org.onosproject.net.link.LinkProviderService; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 67 | import org.onosproject.net.provider.ProviderId; |
| 68 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 69 | /** |
| 70 | * Test for BGP topology provider. |
| 71 | */ |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 72 | public class BgpTopologyProviderTest { |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 73 | 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 VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 76 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 77 | private final BgpTopologyProvider provider = new BgpTopologyProvider(); |
| 78 | private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry(); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 79 | 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 VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 84 | |
| 85 | @Before |
| 86 | public void startUp() { |
| 87 | provider.deviceProviderRegistry = nodeRegistry; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 88 | provider.linkProviderRegistry = linkRegistry; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 89 | provider.controller = controller; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 90 | provider.deviceService = deviceService; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 91 | provider.activate(); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 92 | 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 VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @After |
| 99 | public void tearDown() { |
| 100 | provider.deactivate(); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 101 | provider.controller = null; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 102 | provider.deviceService = null; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 103 | provider.deviceProviderRegistry = null; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 104 | assertThat(controller.nodeListener, is(new HashSet<BgpNodeListener>())); |
| 105 | assertThat(controller.linkListener, is(new HashSet<BgpLinkListener>())); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 106 | } |
| 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 B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 138 | if (!deviceId.equals(DID2)) { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 139 | connected.add(deviceId); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 140 | Device device = new DefaultDevice(BgpTopologyProviderTest.providerId, deviceId, Device.Type.ROUTER, |
| 141 | UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId()); |
| 142 | deviceMap.put(deviceId, device); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | public void deviceDisconnected(DeviceId deviceId) { |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 148 | if (!deviceId.equals(DID2)) { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 149 | connected.remove(deviceId); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 150 | deviceMap.remove(deviceId); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 151 | } |
| 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 B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 180 | /* 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 VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 237 | protected Set<BgpNodeListener> nodeListener = new CopyOnWriteArraySet<>(); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 238 | protected Set<BgpLinkListener> linkListener = new CopyOnWriteArraySet<>(); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 239 | |
| 240 | @Override |
| 241 | public void addListener(BgpNodeListener nodeListener) { |
| 242 | this.nodeListener.add(nodeListener); |
| 243 | } |
| 244 | |
| 245 | @Override |
| 246 | public void removeListener(BgpNodeListener nodeListener) { |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 247 | this.nodeListener.remove(nodeListener); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | @Override |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 251 | public void addLinkListener(BgpLinkListener linkListener) { |
| 252 | this.linkListener.add(linkListener); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | @Override |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 256 | public void removeLinkListener(BgpLinkListener linkListener) { |
| 257 | this.linkListener.remove(linkListener); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 258 | } |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 259 | } |
| 260 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 261 | /* 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 VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 272 | @Test |
| 273 | public void bgpTopologyProviderTestAddDevice1() { |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 274 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 275 | BgpValueType tlv = new AutonomousSystemTlv(100); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 276 | short deslength = AutonomousSystemTlv.LENGTH; |
| 277 | short desType = AutonomousSystemTlv.TYPE; |
| 278 | |
| 279 | subTlvs.add(tlv); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 280 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 281 | desType)); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 282 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 283 | new RouteDistinguisher()); |
| 284 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 285 | 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 VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 291 | for (BgpNodeListener l : controller.nodeListener) { |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 292 | l.addNode(nodeNlri, details); |
| 293 | assertThat(nodeRegistry.connected.size(), is(1)); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 294 | l.deleteNode(nodeNlri); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 295 | assertThat(nodeRegistry.connected.size(), is(0)); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 299 | /** |
| 300 | * Validate node is not added to the device for invalid URI, RIB count should be zero. |
| 301 | */ |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 302 | @Test |
| 303 | public void bgpTopologyProviderTestAddDevice2() { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 304 | LinkedList<BgpValueType> subTlvs; |
| 305 | BgpValueType tlv = new AutonomousSystemTlv(10); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 306 | short deslength = AutonomousSystemTlv.LENGTH; |
| 307 | short desType = AutonomousSystemTlv.TYPE; |
| 308 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 309 | 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 VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 315 | subTlvs = new LinkedList<>(); |
| 316 | subTlvs.add(tlv); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 317 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 318 | desType)); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 319 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 320 | new RouteDistinguisher()); |
| 321 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 322 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 323 | for (BgpNodeListener l : controller.nodeListener) { |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 324 | l.addNode(nodeNlri, details); |
| 325 | assertThat(nodeRegistry.connected.size(), is(0)); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 329 | /** |
| 330 | * Delete node when node does not exist, RIB count should be zero. |
| 331 | */ |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 332 | @Test |
| 333 | public void bgpTopologyProviderTestAddDevice3() { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 334 | LinkedList<BgpValueType> subTlvs; |
| 335 | BgpValueType tlv = new AutonomousSystemTlv(10); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 336 | short deslength = AutonomousSystemTlv.LENGTH; |
| 337 | short desType = AutonomousSystemTlv.TYPE; |
| 338 | |
| 339 | subTlvs = new LinkedList<>(); |
| 340 | subTlvs.add(tlv); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 341 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 342 | desType)); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 343 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 344 | new RouteDistinguisher()); |
| 345 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 346 | for (BgpNodeListener l : controller.nodeListener) { |
| 347 | l.deleteNode(nodeNlri); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 348 | 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 VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 513 | } |
| 514 | } |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 515 | } |