Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
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 | |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 15 | import com.fasterxml.jackson.databind.JsonNode; |
| 16 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 17 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 19 | import org.junit.After; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 22 | import org.onlab.junit.TestUtils; |
| 23 | import org.onlab.junit.TestUtils.TestUtilsException; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 24 | import org.onlab.packet.ChassisId; |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 25 | import org.onlab.packet.Ip4Address; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 26 | import org.onosproject.bgp.controller.BgpLinkListener; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 27 | import org.onosproject.bgp.controller.BgpNodeListener; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 28 | import org.onosproject.bgpio.exceptions.BgpParseException; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 29 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier; |
| 30 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 31 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier; |
| 32 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 33 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 34 | import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 35 | import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 36 | import org.onosproject.bgpio.types.AutonomousSystemTlv; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 37 | import org.onosproject.bgpio.types.BgpValueType; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 38 | import org.onosproject.bgpio.types.IsIsNonPseudonode; |
| 39 | import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv; |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 40 | import org.onosproject.bgpio.types.LinkStateAttributes; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 41 | import org.onosproject.bgpio.types.RouteDistinguisher; |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 42 | import org.onosproject.bgpio.types.attr.BgpAttrNodeFlagBitTlv; |
| 43 | import org.onosproject.bgpio.types.attr.BgpAttrNodeIsIsAreaId; |
| 44 | import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV4; |
| 45 | import org.onosproject.bgpio.types.attr.BgpLinkAttrIgpMetric; |
| 46 | import org.onosproject.bgpio.types.attr.BgpLinkAttrMaxLinkBandwidth; |
| 47 | import org.onosproject.bgpio.types.attr.BgpLinkAttrTeDefaultMetric; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 48 | import org.onosproject.bgpio.util.Constants; |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 49 | import org.onosproject.cluster.NodeId; |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 50 | import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; |
| 51 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 52 | import org.onosproject.incubator.net.resource.label.LabelResourcePool; |
| 53 | import org.onosproject.mastership.MastershipServiceAdapter; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 54 | import org.onosproject.net.ConnectPoint; |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 55 | import org.onosproject.net.DefaultAnnotations; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 56 | import org.onosproject.net.DefaultDevice; |
| 57 | import org.onosproject.net.DefaultLink; |
| 58 | import org.onosproject.net.Device; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 59 | import org.onosproject.net.DeviceId; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 60 | import org.onosproject.net.Link; |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 61 | import org.onosproject.net.LinkKey; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 62 | import org.onosproject.net.MastershipRole; |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 63 | import org.onosproject.net.PortNumber; |
| 64 | import org.onosproject.net.config.Config; |
| 65 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 66 | import org.onosproject.net.config.ConfigFactory; |
| 67 | import org.onosproject.net.config.NetworkConfigRegistryAdapter; |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 68 | import org.onosproject.net.config.basics.BandwidthCapacity; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 69 | import org.onosproject.net.device.DeviceDescription; |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 70 | import org.onosproject.net.device.DeviceEvent; |
| 71 | import org.onosproject.net.device.DeviceListener; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 72 | import org.onosproject.net.device.DeviceProvider; |
| 73 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 74 | import org.onosproject.net.device.DeviceProviderService; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 75 | import org.onosproject.net.device.DeviceServiceAdapter; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 76 | import org.onosproject.net.device.PortDescription; |
| 77 | import org.onosproject.net.device.PortStatistics; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 78 | import org.onosproject.net.link.LinkDescription; |
| 79 | import org.onosproject.net.link.LinkProvider; |
| 80 | import org.onosproject.net.link.LinkProviderRegistry; |
| 81 | import org.onosproject.net.link.LinkProviderService; |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 82 | import org.onosproject.net.link.LinkServiceAdapter; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 83 | import org.onosproject.net.provider.ProviderId; |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 84 | import org.onosproject.net.resource.Resource; |
| 85 | import org.onosproject.net.resource.ResourceAdminService; |
| 86 | import org.onosproject.net.resource.ResourceId; |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 87 | import org.onosproject.pcep.api.TeLinkConfig; |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 88 | |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 89 | import java.util.Collection; |
| 90 | import java.util.HashMap; |
| 91 | import java.util.HashSet; |
| 92 | import java.util.LinkedList; |
| 93 | import java.util.List; |
| 94 | import java.util.Map; |
| 95 | import java.util.Set; |
| 96 | import java.util.concurrent.CopyOnWriteArraySet; |
| 97 | |
| 98 | import static org.hamcrest.MatcherAssert.assertThat; |
| 99 | import static org.hamcrest.Matchers.nullValue; |
| 100 | import static org.hamcrest.core.Is.is; |
| 101 | import static org.hamcrest.core.IsNot.not; |
| 102 | import static org.onosproject.net.Link.State.ACTIVE; |
| 103 | import static org.onosproject.net.MastershipRole.MASTER; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 104 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 105 | /** |
| 106 | * Test for BGP topology provider. |
| 107 | */ |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 108 | public class BgpTopologyProviderTest { |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 109 | private static final DeviceId DID2 = DeviceId.deviceId("l3:rd=0::routinguniverse=0:asn=10"); |
Sho SHIMIZU | ca59694 | 2016-08-18 09:41:20 -0700 | [diff] [blame] | 110 | private static final String UNKNOWN = "unknown"; |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 111 | public static ProviderId providerId = new ProviderId("l3", "foo"); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 112 | private static final NodeId NODE1 = new NodeId("Master1"); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 113 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 114 | private final BgpTopologyProvider provider = new BgpTopologyProvider(); |
| 115 | private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry(); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 116 | private final TestLinkRegistry linkRegistry = new TestLinkRegistry(); |
| 117 | private final MockBgpController controller = new MockBgpController(); |
| 118 | private MockDeviceService deviceService = new MockDeviceService(); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 119 | private MockLinkService linkService = new MockLinkService(); |
| 120 | private MockMastershipService mastershipService = new MockMastershipService(); |
| 121 | private MockNetConfigRegistryAdapter networkConfigService = new MockNetConfigRegistryAdapter(); |
| 122 | private MockLabelResourceService labelResourceAdminService = new MockLabelResourceService(); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 123 | private Map<DeviceId, Device> deviceMap = new HashMap<>(); |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 124 | private DeviceListener listener; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 125 | |
| 126 | @Before |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 127 | public void startUp() throws TestUtilsException { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 128 | provider.deviceProviderRegistry = nodeRegistry; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 129 | provider.linkProviderRegistry = linkRegistry; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 130 | provider.controller = controller; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 131 | provider.deviceService = deviceService; |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 132 | provider.linkService = linkService; |
| 133 | provider.labelResourceAdminService = labelResourceAdminService; |
| 134 | provider.mastershipService = mastershipService; |
| 135 | provider.networkConfigService = networkConfigService; |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 136 | listener = TestUtils.getField(provider, "deviceListener"); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 137 | provider.activate(); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 138 | assertThat("device provider should be registered", not(nodeRegistry.provider)); |
| 139 | assertThat("link provider should be registered", not(linkRegistry.linkProvider)); |
| 140 | assertThat("node listener should be registered", not(controller.nodeListener)); |
| 141 | assertThat("link listener should be registered", not(controller.linkListener)); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | @After |
| 145 | public void tearDown() { |
| 146 | provider.deactivate(); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 147 | provider.controller = null; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 148 | provider.deviceService = null; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 149 | provider.deviceProviderRegistry = null; |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 150 | provider.linkService = null; |
| 151 | provider.mastershipService = null; |
| 152 | provider.networkConfigService = null; |
| 153 | provider.labelResourceAdminService = null; |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 154 | assertThat(controller.nodeListener, is(new HashSet<BgpNodeListener>())); |
| 155 | assertThat(controller.linkListener, is(new HashSet<BgpLinkListener>())); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 156 | } |
| 157 | |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 158 | private class MockLabelResourceService implements LabelResourceAdminService { |
| 159 | |
| 160 | Map<DeviceId, LabelResourcePool> resourcePool = new HashMap<>(); |
| 161 | |
| 162 | @Override |
| 163 | public boolean createDevicePool(DeviceId deviceId, LabelResourceId beginLabel, LabelResourceId endLabel) { |
| 164 | LabelResourcePool labelResource = new LabelResourcePool(deviceId.toString(), |
| 165 | beginLabel.labelId(), |
| 166 | endLabel.labelId()); |
| 167 | if (resourcePool.containsValue(labelResource)) { |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | resourcePool.put(deviceId, labelResource); |
| 172 | return true; |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public boolean createGlobalPool(LabelResourceId beginLabel, LabelResourceId endLabel) { |
| 177 | // TODO Auto-generated method stub |
| 178 | return false; |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public boolean destroyDevicePool(DeviceId deviceId) { |
| 183 | LabelResourcePool devicePool = resourcePool.get(deviceId); |
| 184 | |
| 185 | if (devicePool == null) { |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | resourcePool.remove(deviceId); |
| 190 | return true; |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public boolean destroyGlobalPool() { |
| 195 | // TODO Auto-generated method stub |
| 196 | return false; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | /* Mock test for device service */ |
| 201 | private class MockNetConfigRegistryAdapter extends NetworkConfigRegistryAdapter { |
| 202 | private ConfigFactory cfgFactory; |
| 203 | private Map<ConnectPoint, BandwidthCapacity> classConfig = new HashMap<>(); |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 204 | private Map<LinkKey, TeLinkConfig> teLinkConfig = new HashMap<>(); |
| 205 | |
| 206 | public Map<LinkKey, TeLinkConfig> getTeLinkConfig() { |
| 207 | return teLinkConfig; |
| 208 | } |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 209 | |
| 210 | @Override |
| 211 | public void registerConfigFactory(ConfigFactory configFactory) { |
| 212 | cfgFactory = configFactory; |
| 213 | } |
| 214 | |
| 215 | @Override |
| 216 | public void unregisterConfigFactory(ConfigFactory configFactory) { |
| 217 | cfgFactory = null; |
| 218 | } |
| 219 | |
| 220 | @Override |
| 221 | public <S, C extends Config<S>> C addConfig(S subject, Class<C> configClass) { |
| 222 | if (configClass == BandwidthCapacity.class) { |
| 223 | BandwidthCapacity devCap = new BandwidthCapacity(); |
| 224 | classConfig.put((ConnectPoint) subject, devCap); |
| 225 | |
| 226 | JsonNode node = new ObjectNode(new MockJsonNode()); |
| 227 | ObjectMapper mapper = new ObjectMapper(); |
| 228 | ConfigApplyDelegate delegate = new InternalApplyDelegate(); |
| 229 | devCap.init((ConnectPoint) subject, null, node, mapper, delegate); |
| 230 | return (C) devCap; |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 231 | } else if (configClass == TeLinkConfig.class) { |
| 232 | TeLinkConfig linkConfig = new TeLinkConfig(); |
| 233 | teLinkConfig.put((LinkKey) subject, linkConfig); |
| 234 | |
| 235 | JsonNode node = new ObjectNode(new MockJsonNode()); |
| 236 | ObjectMapper mapper = new ObjectMapper(); |
| 237 | ConfigApplyDelegate delegate = new InternalApplyDelegate(); |
| 238 | linkConfig.init((LinkKey) subject, null, node, mapper, delegate); |
| 239 | return (C) linkConfig; |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | return null; |
| 243 | } |
| 244 | |
| 245 | @Override |
| 246 | public <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass) { |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 247 | if (configClass == BandwidthCapacity.class) { |
| 248 | classConfig.remove(subject); |
| 249 | } else if (configClass == TeLinkConfig.class) { |
| 250 | teLinkConfig.remove(subject); |
| 251 | } |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | @Override |
| 255 | public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { |
| 256 | if (configClass == BandwidthCapacity.class) { |
| 257 | return (C) classConfig.get(subject); |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 258 | } else if (configClass == TeLinkConfig.class) { |
| 259 | return (C) teLinkConfig.get(subject); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 260 | } |
| 261 | return null; |
| 262 | } |
| 263 | |
| 264 | private class MockJsonNode extends JsonNodeFactory { |
| 265 | } |
| 266 | |
| 267 | // Auxiliary delegate to receive notifications about changes applied to |
| 268 | // the network configuration - by the apps. |
| 269 | private class InternalApplyDelegate implements ConfigApplyDelegate { |
| 270 | @Override |
| 271 | public void onApply(Config config) { |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | private class MockMastershipService extends MastershipServiceAdapter { |
| 277 | @Override |
| 278 | public MastershipRole getLocalRole(DeviceId deviceId) { |
| 279 | return MASTER; |
| 280 | } |
| 281 | |
| 282 | @Override |
| 283 | public boolean isLocalMaster(DeviceId deviceId) { |
| 284 | return getLocalRole(deviceId) == MASTER; |
| 285 | } |
| 286 | |
| 287 | @Override |
| 288 | public NodeId getMasterFor(DeviceId deviceId) { |
| 289 | return NODE1; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | private class MockResourceAdminService implements ResourceAdminService { |
| 294 | Map<ResourceId, List<Resource>> registeredRes = new HashMap<>(); |
| 295 | |
| 296 | @Override |
Sho SHIMIZU | ef835c9 | 2016-08-08 13:51:17 -0700 | [diff] [blame] | 297 | public boolean register(List<? extends Resource> resources) { |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 298 | for (Resource res : resources) { |
| 299 | List<Resource> resource = new LinkedList<>(); |
| 300 | resource.add(res); |
| 301 | if (registeredRes.containsKey(res.id())) { |
| 302 | resource.addAll(registeredRes.get(res.id())); |
| 303 | } |
| 304 | registeredRes.put(res.id(), resource); |
| 305 | } |
| 306 | return true; |
| 307 | } |
| 308 | |
| 309 | @Override |
Sho SHIMIZU | ef835c9 | 2016-08-08 13:51:17 -0700 | [diff] [blame] | 310 | public boolean unregister(List<? extends ResourceId> ids) { |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 311 | for (ResourceId id : ids) { |
| 312 | if (registeredRes.containsKey(id)) { |
| 313 | registeredRes.remove(id); |
| 314 | } else { |
| 315 | return false; |
| 316 | } |
| 317 | } |
| 318 | return true; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | private class MockLinkService extends LinkServiceAdapter { |
| 323 | |
| 324 | @Override |
| 325 | public Link getLink(ConnectPoint src, ConnectPoint dst) { |
| 326 | for (Link link : linkRegistry.links) { |
| 327 | if (link.src().equals(src) && link.dst().equals(dst)) { |
| 328 | return link; |
| 329 | } |
| 330 | } |
| 331 | return null; |
| 332 | } |
| 333 | } |
| 334 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 335 | /* Class implement device test registry */ |
| 336 | private class TestDeviceRegistry implements DeviceProviderRegistry { |
| 337 | DeviceProvider provider; |
| 338 | |
| 339 | Set<DeviceId> connected = new HashSet<>(); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 340 | Map<DeviceId, List<PortDescription>> portUpdated = new HashMap<>(); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 341 | |
| 342 | @Override |
| 343 | public DeviceProviderService register(DeviceProvider provider) { |
| 344 | this.provider = provider; |
| 345 | return new TestProviderService(); |
| 346 | } |
| 347 | |
| 348 | @Override |
| 349 | public void unregister(DeviceProvider provider) { |
| 350 | } |
| 351 | |
| 352 | @Override |
| 353 | public Set<ProviderId> getProviders() { |
| 354 | return null; |
| 355 | } |
| 356 | |
| 357 | private class TestProviderService implements DeviceProviderService { |
| 358 | |
| 359 | @Override |
| 360 | public DeviceProvider provider() { |
| 361 | return null; |
| 362 | } |
| 363 | |
| 364 | @Override |
| 365 | public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) { |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 366 | if (!deviceId.equals(DID2)) { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 367 | connected.add(deviceId); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 368 | Device device = new DefaultDevice(BgpTopologyProviderTest.providerId, deviceId, Device.Type.ROUTER, |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 369 | UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId(), deviceDescription.annotations()); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 370 | deviceMap.put(deviceId, device); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
| 374 | @Override |
| 375 | public void deviceDisconnected(DeviceId deviceId) { |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 376 | if (!deviceId.equals(DID2)) { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 377 | connected.remove(deviceId); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 378 | deviceMap.remove(deviceId); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) { |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 384 | portUpdated.put(deviceId, portDescriptions); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | @Override |
| 388 | public void portStatusChanged(DeviceId deviceId, PortDescription portDescription) { |
| 389 | // TODO Auto-generated method stub |
| 390 | |
| 391 | } |
| 392 | |
| 393 | @Override |
| 394 | public void receivedRoleReply(DeviceId deviceId, MastershipRole requested, MastershipRole response) { |
| 395 | // TODO Auto-generated method stub |
| 396 | |
| 397 | } |
| 398 | |
| 399 | @Override |
| 400 | public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) { |
| 401 | // TODO Auto-generated method stub |
| 402 | |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 407 | /* Class implement device test registry */ |
| 408 | private class TestLinkRegistry implements LinkProviderRegistry { |
| 409 | LinkProvider linkProvider; |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 410 | LinkedList<Link> links = new LinkedList<>(); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 411 | |
| 412 | @Override |
| 413 | public LinkProviderService register(LinkProvider provider) { |
| 414 | this.linkProvider = provider; |
| 415 | return new TestProviderService(); |
| 416 | } |
| 417 | |
| 418 | @Override |
| 419 | public void unregister(LinkProvider provider) { |
| 420 | // TODO Auto-generated method stub |
| 421 | } |
| 422 | |
| 423 | @Override |
| 424 | public Set<ProviderId> getProviders() { |
| 425 | return null; |
| 426 | } |
| 427 | |
| 428 | private class TestProviderService implements LinkProviderService { |
| 429 | |
| 430 | @Override |
| 431 | public void linkDetected(LinkDescription linkDescription) { |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 432 | links.add(DefaultLink.builder() |
| 433 | .src(linkDescription.src()) |
| 434 | .dst(linkDescription.dst()) |
| 435 | .state(ACTIVE) |
| 436 | .type(linkDescription.type()) |
| 437 | .providerId(BgpTopologyProviderTest.providerId) |
| 438 | .annotations(linkDescription.annotations()) |
| 439 | .build()); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | @Override |
| 443 | public void linkVanished(LinkDescription linkDescription) { |
| 444 | links.remove(DefaultLink.builder().src(linkDescription.src()) |
| 445 | .dst(linkDescription.dst()).state(ACTIVE).type(linkDescription.type()) |
| 446 | .providerId(BgpTopologyProviderTest.providerId).build()); |
| 447 | } |
| 448 | |
| 449 | @Override |
| 450 | public void linksVanished(ConnectPoint connectPoint) { |
| 451 | // TODO Auto-generated method stub |
| 452 | } |
| 453 | |
| 454 | @Override |
| 455 | public void linksVanished(DeviceId deviceId) { |
| 456 | // TODO Auto-generated method stub |
| 457 | } |
| 458 | |
| 459 | @Override |
| 460 | public LinkProvider provider() { |
| 461 | // TODO Auto-generated method stub |
| 462 | return null; |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | /* Test class for BGP controller */ |
| 468 | private class MockBgpController extends BgpControllerAdapter { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 469 | protected Set<BgpNodeListener> nodeListener = new CopyOnWriteArraySet<>(); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 470 | protected Set<BgpLinkListener> linkListener = new CopyOnWriteArraySet<>(); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 471 | |
| 472 | @Override |
| 473 | public void addListener(BgpNodeListener nodeListener) { |
| 474 | this.nodeListener.add(nodeListener); |
| 475 | } |
| 476 | |
| 477 | @Override |
| 478 | public void removeListener(BgpNodeListener nodeListener) { |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 479 | this.nodeListener.remove(nodeListener); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | @Override |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 483 | public void addLinkListener(BgpLinkListener linkListener) { |
| 484 | this.linkListener.add(linkListener); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | @Override |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 488 | public void removeLinkListener(BgpLinkListener linkListener) { |
| 489 | this.linkListener.remove(linkListener); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 490 | } |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 491 | } |
| 492 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 493 | /* Mock test for device service */ |
| 494 | private class MockDeviceService extends DeviceServiceAdapter { |
| 495 | @Override |
| 496 | public Device getDevice(DeviceId deviceId) { |
| 497 | return deviceMap.get(deviceId); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Validate node is added to the device validating URI, RIB should get updated properly. |
| 503 | */ |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 504 | @Test |
| 505 | public void bgpTopologyProviderTestAddDevice1() { |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 506 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 507 | BgpValueType tlv = new AutonomousSystemTlv(100); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 508 | short deslength = AutonomousSystemTlv.LENGTH; |
| 509 | short desType = AutonomousSystemTlv.TYPE; |
| 510 | |
| 511 | subTlvs.add(tlv); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 512 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 513 | desType)); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 514 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 515 | new RouteDistinguisher()); |
| 516 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 517 | PathAttrNlriDetails details = new PathAttrNlriDetails(); |
| 518 | details.setIdentifier(0); |
| 519 | details.setProtocolID(ProtocolType.DIRECT); |
| 520 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 521 | details.setPathAttribute(pathAttributes); |
| 522 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 523 | for (BgpNodeListener l : controller.nodeListener) { |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 524 | l.addNode(nodeNlri, details); |
| 525 | assertThat(nodeRegistry.connected.size(), is(1)); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 526 | l.deleteNode(nodeNlri); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 527 | assertThat(nodeRegistry.connected.size(), is(0)); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 531 | /** |
| 532 | * Validate node is not added to the device for invalid URI, RIB count should be zero. |
| 533 | */ |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 534 | @Test |
| 535 | public void bgpTopologyProviderTestAddDevice2() { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 536 | LinkedList<BgpValueType> subTlvs; |
| 537 | BgpValueType tlv = new AutonomousSystemTlv(10); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 538 | short deslength = AutonomousSystemTlv.LENGTH; |
| 539 | short desType = AutonomousSystemTlv.TYPE; |
| 540 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 541 | PathAttrNlriDetails details = new PathAttrNlriDetails(); |
| 542 | details.setIdentifier(0); |
| 543 | details.setProtocolID(ProtocolType.DIRECT); |
| 544 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 545 | details.setPathAttribute(pathAttributes); |
| 546 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 547 | subTlvs = new LinkedList<>(); |
| 548 | subTlvs.add(tlv); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 549 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 550 | desType)); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 551 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 552 | new RouteDistinguisher()); |
| 553 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 554 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 555 | for (BgpNodeListener l : controller.nodeListener) { |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 556 | l.addNode(nodeNlri, details); |
| 557 | assertThat(nodeRegistry.connected.size(), is(0)); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 558 | } |
| 559 | } |
| 560 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 561 | /** |
| 562 | * Delete node when node does not exist, RIB count should be zero. |
| 563 | */ |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 564 | @Test |
| 565 | public void bgpTopologyProviderTestAddDevice3() { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 566 | LinkedList<BgpValueType> subTlvs; |
| 567 | BgpValueType tlv = new AutonomousSystemTlv(10); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 568 | short deslength = AutonomousSystemTlv.LENGTH; |
| 569 | short desType = AutonomousSystemTlv.TYPE; |
| 570 | |
| 571 | subTlvs = new LinkedList<>(); |
| 572 | subTlvs.add(tlv); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 573 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 574 | desType)); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 575 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 576 | new RouteDistinguisher()); |
| 577 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 578 | for (BgpNodeListener l : controller.nodeListener) { |
| 579 | l.deleteNode(nodeNlri); |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 580 | assertThat(nodeRegistry.connected.size(), is(0)); |
| 581 | } |
| 582 | } |
| 583 | |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 584 | |
| 585 | /** |
| 586 | * Validate node is added to the device with all device annotations. |
| 587 | */ |
| 588 | @Test |
| 589 | public void bgpTopologyProviderTestAddDevice4() { |
| 590 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
| 591 | BgpValueType tlv = new AutonomousSystemTlv(100); |
| 592 | short deslength = AutonomousSystemTlv.LENGTH; |
| 593 | short desType = AutonomousSystemTlv.TYPE; |
| 594 | |
| 595 | subTlvs.add(tlv); |
| 596 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, |
| 597 | desType)); |
| 598 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
| 599 | new RouteDistinguisher()); |
| 600 | |
| 601 | PathAttrNlriDetails details = new PathAttrNlriDetails(); |
| 602 | details.setIdentifier(0); |
| 603 | details.setProtocolID(ProtocolType.DIRECT); |
| 604 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 605 | List<BgpValueType> linkStateAttr = new LinkedList<>(); |
| 606 | tlv = BgpAttrNodeFlagBitTlv.of(true, true, true, false); |
| 607 | linkStateAttr.add(tlv); |
| 608 | tlv = BgpAttrNodeIsIsAreaId.of(new byte[] {01, 01, 01, 01}); |
| 609 | linkStateAttr.add(tlv); |
| 610 | tlv = BgpAttrRouterIdV4.of(Ip4Address.valueOf("1.1.1.1"), LinkStateAttributes.ATTR_NODE_IPV4_LOCAL_ROUTER_ID); |
| 611 | linkStateAttr.add(tlv); |
| 612 | pathAttributes.add(new LinkStateAttributes(linkStateAttr)); |
| 613 | details.setPathAttribute(pathAttributes); |
| 614 | |
| 615 | for (BgpNodeListener l : controller.nodeListener) { |
| 616 | l.addNode(nodeNlri, details); |
| 617 | |
| 618 | assertThat(deviceMap.values().iterator().next().annotations().value(BgpTopologyProvider.ABR_BIT), |
| 619 | is("false")); |
| 620 | assertThat(deviceMap.values().iterator().next().annotations().value(BgpTopologyProvider.EXTERNAL_BIT), |
| 621 | is("true")); |
| 622 | assertThat(deviceMap.values().iterator().next().annotations().value(BgpTopologyProvider.INTERNAL_BIT), |
| 623 | is("false")); |
| 624 | assertThat(deviceMap.values().iterator().next().annotations().value(BgpTopologyProvider.PSEUDO), |
| 625 | is("false")); |
| 626 | assertThat(deviceMap.values().iterator().next().annotations().value(BgpTopologyProvider.AREAID).getBytes(), |
| 627 | is(new byte[] {01, 01, 01, 01})); |
| 628 | assertThat(deviceMap.values().iterator().next().annotations().value(BgpTopologyProvider.LSRID), |
| 629 | is("1.1.1.1")); |
| 630 | |
| 631 | assertThat(nodeRegistry.connected.size(), is(1)); |
| 632 | l.deleteNode(nodeNlri); |
| 633 | assertThat(nodeRegistry.connected.size(), is(0)); |
| 634 | } |
| 635 | } |
| 636 | |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 637 | /** |
| 638 | * Add a link and two devices. |
| 639 | * |
| 640 | * @throws BgpParseException while adding a link. |
| 641 | */ |
| 642 | @Test |
| 643 | public void bgpTopologyProviderTestAddLink1() throws BgpParseException { |
| 644 | LinkedList<BgpValueType> localTlvs = new LinkedList<>(); |
| 645 | LinkedList<BgpValueType> remoteTlvs = new LinkedList<>(); |
| 646 | LinkedList<BgpValueType> linkdes = new LinkedList<>(); |
| 647 | BgpValueType tlv = new AutonomousSystemTlv(10); |
| 648 | short deslength = AutonomousSystemTlv.LENGTH; |
| 649 | short desType = AutonomousSystemTlv.TYPE; |
| 650 | |
| 651 | localTlvs.add(tlv); |
| 652 | remoteTlvs.add(tlv); |
| 653 | tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20}); |
| 654 | localTlvs.add(tlv); |
| 655 | tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30}); |
| 656 | remoteTlvs.add(tlv); |
| 657 | NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType); |
| 658 | NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType); |
| 659 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode); |
| 660 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
| 661 | new RouteDistinguisher()); |
| 662 | |
| 663 | BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode); |
| 664 | BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false, |
| 665 | new RouteDistinguisher()); |
| 666 | |
| 667 | PathAttrNlriDetails details = new PathAttrNlriDetails(); |
| 668 | details.setIdentifier(0); |
| 669 | details.setProtocolID(ProtocolType.DIRECT); |
| 670 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 671 | details.setPathAttribute(pathAttributes); |
| 672 | |
| 673 | tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100); |
| 674 | linkdes.add(tlv); |
| 675 | BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes); |
| 676 | BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId, |
| 677 | new RouteDistinguisher(), false); |
| 678 | for (BgpNodeListener l : controller.nodeListener) { |
| 679 | l.addNode(nodeNlri, details); |
| 680 | assertThat(nodeRegistry.connected.size(), is(1)); |
| 681 | l.addNode(remNodeNlri, details); |
| 682 | assertThat(nodeRegistry.connected.size(), is(2)); |
| 683 | } |
| 684 | for (BgpLinkListener l : controller.linkListener) { |
| 685 | l.addLink(linkNlri, details); |
| 686 | assertThat(linkRegistry.links.size(), is(1)); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Add a link and delete a link. |
| 692 | * |
| 693 | * @throws BgpParseException while adding or removing the link |
| 694 | */ |
| 695 | @Test |
| 696 | public void bgpTopologyProviderTestAddLink2() throws BgpParseException { |
| 697 | LinkedList<BgpValueType> localTlvs = new LinkedList<>(); |
| 698 | LinkedList<BgpValueType> remoteTlvs = new LinkedList<>(); |
| 699 | LinkedList<BgpValueType> linkdes = new LinkedList<>(); |
| 700 | BgpValueType tlv = new AutonomousSystemTlv(10); |
| 701 | short deslength = AutonomousSystemTlv.LENGTH; |
| 702 | short desType = AutonomousSystemTlv.TYPE; |
| 703 | |
| 704 | localTlvs.add(tlv); |
| 705 | remoteTlvs.add(tlv); |
| 706 | tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20}); |
| 707 | localTlvs.add(tlv); |
| 708 | tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30}); |
| 709 | remoteTlvs.add(tlv); |
| 710 | NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType); |
| 711 | NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType); |
| 712 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode); |
| 713 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
| 714 | new RouteDistinguisher()); |
| 715 | |
| 716 | BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode); |
| 717 | BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false, |
| 718 | new RouteDistinguisher()); |
| 719 | |
| 720 | PathAttrNlriDetails details = new PathAttrNlriDetails(); |
| 721 | details.setIdentifier(0); |
| 722 | details.setProtocolID(ProtocolType.DIRECT); |
| 723 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 724 | details.setPathAttribute(pathAttributes); |
| 725 | |
| 726 | tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100); |
| 727 | linkdes.add(tlv); |
| 728 | BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes); |
| 729 | BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId, |
| 730 | new RouteDistinguisher(), false); |
| 731 | for (BgpNodeListener l : controller.nodeListener) { |
| 732 | l.addNode(nodeNlri, details); |
| 733 | assertThat(nodeRegistry.connected.size(), is(1)); |
| 734 | l.addNode(remNodeNlri, details); |
| 735 | assertThat(nodeRegistry.connected.size(), is(2)); |
| 736 | l.deleteNode(nodeNlri); |
| 737 | assertThat(nodeRegistry.connected.size(), is(1)); |
| 738 | } |
| 739 | for (BgpLinkListener l : controller.linkListener) { |
| 740 | l.addLink(linkNlri, details); |
| 741 | assertThat(linkRegistry.links.size(), is(1)); |
| 742 | l.deleteLink(linkNlri); |
| 743 | assertThat(linkRegistry.links.size(), is(0)); |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | /** |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 748 | * Add a link and delete a link with registering/unregistering bandwidth. |
| 749 | * |
| 750 | * @throws BgpParseException while adding or removing the link |
| 751 | * @throws InterruptedException while registering for bandwidth |
| 752 | */ |
| 753 | @Test |
| 754 | public void bgpTopologyProviderTestAddLink3() throws BgpParseException, InterruptedException { |
| 755 | LinkedList<BgpValueType> localTlvs = new LinkedList<>(); |
| 756 | LinkedList<BgpValueType> remoteTlvs = new LinkedList<>(); |
| 757 | LinkedList<BgpValueType> linkdes = new LinkedList<>(); |
| 758 | BgpValueType tlv = new AutonomousSystemTlv(10); |
| 759 | short deslength = AutonomousSystemTlv.LENGTH; |
| 760 | short desType = AutonomousSystemTlv.TYPE; |
| 761 | |
| 762 | localTlvs.add(tlv); |
| 763 | remoteTlvs.add(tlv); |
| 764 | tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20}); |
| 765 | localTlvs.add(tlv); |
| 766 | tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30}); |
| 767 | remoteTlvs.add(tlv); |
| 768 | NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType); |
| 769 | NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType); |
| 770 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode); |
| 771 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
| 772 | new RouteDistinguisher()); |
| 773 | |
| 774 | BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode); |
| 775 | BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false, |
| 776 | new RouteDistinguisher()); |
| 777 | |
| 778 | PathAttrNlriDetails details = new PathAttrNlriDetails(); |
| 779 | details.setIdentifier(0); |
| 780 | details.setProtocolID(ProtocolType.DIRECT); |
| 781 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 782 | details.setPathAttribute(pathAttributes); |
| 783 | |
| 784 | tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100); |
| 785 | linkdes.add(tlv); |
| 786 | BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes); |
| 787 | BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId, |
| 788 | new RouteDistinguisher(), false); |
| 789 | |
| 790 | for (BgpNodeListener l : controller.nodeListener) { |
| 791 | l.addNode(nodeNlri, details); |
| 792 | assertThat(nodeRegistry.connected.size(), is(1)); |
| 793 | l.addNode(remNodeNlri, details); |
| 794 | assertThat(nodeRegistry.connected.size(), is(2)); |
| 795 | l.deleteNode(remNodeNlri); |
| 796 | assertThat(nodeRegistry.connected.size(), is(1)); |
| 797 | } |
| 798 | |
| 799 | List<BgpValueType> linkPathAttributes = new LinkedList<>(); |
| 800 | List<BgpValueType> linkStateAttr = new LinkedList<>(); |
| 801 | tlv = BgpLinkAttrIgpMetric.of(10, 4); |
| 802 | linkStateAttr.add(tlv); |
| 803 | tlv = BgpLinkAttrTeDefaultMetric.of(20); |
| 804 | linkStateAttr.add(tlv); |
| 805 | tlv = BgpLinkAttrMaxLinkBandwidth.of(30, LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH); |
| 806 | linkStateAttr.add(tlv); |
| 807 | linkPathAttributes.add(new LinkStateAttributes(linkStateAttr)); |
| 808 | details.setPathAttribute(linkPathAttributes); |
| 809 | |
| 810 | for (BgpLinkListener l : controller.linkListener) { |
| 811 | l.addLink(linkNlri, details); |
| 812 | assertThat(linkRegistry.links.size(), is(1)); |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 813 | TeLinkConfig config = networkConfigService.getTeLinkConfig().get(LinkKey.linkKey(linkRegistry.links |
| 814 | .getFirst().src(), linkRegistry.links.getLast().dst())); |
| 815 | |
| 816 | assertThat(config.igpCost(), is(10)); |
| 817 | assertThat(config.teCost(), is(20)); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 818 | |
| 819 | l.deleteLink(linkNlri); |
| 820 | assertThat(linkRegistry.links.size(), is(0)); |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | /** |
Priyanka B | fc51c95 | 2016-03-26 14:30:33 +0530 | [diff] [blame] | 825 | * Invalid link. |
| 826 | * |
| 827 | * @throws BgpParseException while adding or deleting a link |
| 828 | */ |
| 829 | @Test |
| 830 | public void bgpTopologyProviderTestDeleteLink3() throws BgpParseException { |
| 831 | LinkedList<BgpValueType> localTlvs = new LinkedList<>(); |
| 832 | LinkedList<BgpValueType> remoteTlvs = new LinkedList<>(); |
| 833 | LinkedList<BgpValueType> linkdes = new LinkedList<>(); |
| 834 | BgpValueType tlv = new AutonomousSystemTlv(10); |
| 835 | short deslength = AutonomousSystemTlv.LENGTH; |
| 836 | short desType = AutonomousSystemTlv.TYPE; |
| 837 | |
| 838 | localTlvs.add(tlv); |
| 839 | remoteTlvs.add(tlv); |
| 840 | tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20}); |
| 841 | localTlvs.add(tlv); |
| 842 | tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30}); |
| 843 | remoteTlvs.add(tlv); |
| 844 | NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType); |
| 845 | NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType); |
| 846 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode); |
| 847 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
| 848 | new RouteDistinguisher()); |
| 849 | |
| 850 | BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode); |
| 851 | BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false, |
| 852 | new RouteDistinguisher()); |
| 853 | |
| 854 | PathAttrNlriDetails details = new PathAttrNlriDetails(); |
| 855 | details.setIdentifier(0); |
| 856 | details.setProtocolID(ProtocolType.DIRECT); |
| 857 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 858 | details.setPathAttribute(pathAttributes); |
| 859 | |
| 860 | tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100); |
| 861 | linkdes.add(tlv); |
| 862 | BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes); |
| 863 | BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId, |
| 864 | new RouteDistinguisher(), false); |
| 865 | for (BgpNodeListener l : controller.nodeListener) { |
| 866 | l.addNode(nodeNlri, details); |
| 867 | l.addNode(remNodeNlri, details); |
| 868 | assertThat(nodeRegistry.connected.size(), is(2)); |
| 869 | l.deleteNode(nodeNlri); |
| 870 | assertThat(nodeRegistry.connected.size(), is(1)); |
| 871 | } |
| 872 | for (BgpLinkListener l : controller.linkListener) { |
| 873 | l.deleteLink(linkNlri); |
| 874 | assertThat(linkRegistry.links.size(), is(0)); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 875 | } |
| 876 | } |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 877 | |
| 878 | /** |
| 879 | * Add device check label registration is done. |
| 880 | * |
| 881 | * @throws BgpParseException while adding a device |
| 882 | */ |
| 883 | @Test |
| 884 | public void bgpTopologyProviderDeviceTestLabel1() throws BgpParseException { |
| 885 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
| 886 | BgpValueType tlv = new AutonomousSystemTlv(100); |
| 887 | short deslength = AutonomousSystemTlv.LENGTH; |
| 888 | short desType = AutonomousSystemTlv.TYPE; |
| 889 | |
| 890 | subTlvs.add(tlv); |
| 891 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, |
| 892 | desType)); |
| 893 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
| 894 | new RouteDistinguisher()); |
| 895 | |
| 896 | PathAttrNlriDetails details = new PathAttrNlriDetails(); |
| 897 | details.setIdentifier(0); |
| 898 | details.setProtocolID(ProtocolType.DIRECT); |
| 899 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 900 | List<BgpValueType> linkStateAttributes = new LinkedList<>(); |
| 901 | tlv = BgpAttrRouterIdV4.of(Ip4Address.valueOf("1.1.1.1"), LinkStateAttributes.ATTR_NODE_IPV4_LOCAL_ROUTER_ID); |
| 902 | linkStateAttributes.add(tlv); |
| 903 | pathAttributes.add(new LinkStateAttributes(linkStateAttributes)); |
| 904 | details.setPathAttribute(pathAttributes); |
| 905 | |
| 906 | for (BgpNodeListener l : controller.nodeListener) { |
| 907 | l.addNode(nodeNlri, details); |
| 908 | assertThat(nodeRegistry.connected.size(), is(1)); |
| 909 | } |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 910 | DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 911 | |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 912 | newBuilder.set("lsrId", "1.1.1.1"); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 913 | |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 914 | Device device = new DefaultDevice(BgpTopologyProviderTest.providerId, nodeRegistry.connected.iterator().next(), |
| 915 | Device.Type.ROUTER, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId(), newBuilder.build()); |
| 916 | |
| 917 | DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 918 | listener.event(event); |
| 919 | assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(1)); |
| 920 | } |
| 921 | |
| 922 | /** |
| 923 | * Add device check label registration is done and delete node destroy label pool. |
| 924 | * |
| 925 | * @throws BgpParseException while adding a device |
| 926 | */ |
| 927 | @Test |
| 928 | public void bgpTopologyProviderDeviceTestLabel2() throws BgpParseException { |
| 929 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
| 930 | BgpValueType tlv = new AutonomousSystemTlv(100); |
| 931 | short deslength = AutonomousSystemTlv.LENGTH; |
| 932 | short desType = AutonomousSystemTlv.TYPE; |
| 933 | |
| 934 | subTlvs.add(tlv); |
| 935 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, |
| 936 | desType)); |
| 937 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
| 938 | new RouteDistinguisher()); |
| 939 | |
| 940 | PathAttrNlriDetails details = new PathAttrNlriDetails(); |
| 941 | details.setIdentifier(0); |
| 942 | details.setProtocolID(ProtocolType.DIRECT); |
| 943 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 944 | List<BgpValueType> linkStateAttributes = new LinkedList<>(); |
| 945 | tlv = BgpAttrRouterIdV4.of(Ip4Address.valueOf("1.1.1.1"), LinkStateAttributes.ATTR_NODE_IPV4_LOCAL_ROUTER_ID); |
| 946 | linkStateAttributes.add(tlv); |
| 947 | pathAttributes.add(new LinkStateAttributes(linkStateAttributes)); |
| 948 | details.setPathAttribute(pathAttributes); |
| 949 | |
| 950 | for (BgpNodeListener l : controller.nodeListener) { |
| 951 | l.addNode(nodeNlri, details); |
| 952 | assertThat(nodeRegistry.connected.size(), is(1)); |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 953 | |
| 954 | DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); |
| 955 | |
| 956 | newBuilder.set("lsrId", "1.1.1.1"); |
| 957 | |
| 958 | Device device = new DefaultDevice(BgpTopologyProviderTest.providerId, |
| 959 | nodeRegistry.connected.iterator().next(), Device.Type.ROUTER, UNKNOWN, |
| 960 | UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId(), newBuilder.build()); |
| 961 | |
| 962 | DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 963 | listener.event(event); |
| 964 | assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(1)); |
| 965 | |
| 966 | l.deleteNode(nodeNlri); |
| 967 | assertThat(nodeRegistry.connected.size(), is(0)); |
| 968 | assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(0)); |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | /** |
| 973 | * Add a link register bandwidth and remove link unregister bandwidth. |
| 974 | * |
| 975 | * @throws BgpParseException while registering/unregistering bandwidth |
| 976 | */ |
| 977 | @Test |
| 978 | public void bgpTopologyProviderDeviceTestLabel3() throws BgpParseException { |
| 979 | LinkedList<BgpValueType> localTlvs = new LinkedList<>(); |
| 980 | LinkedList<BgpValueType> remoteTlvs = new LinkedList<>(); |
| 981 | LinkedList<BgpValueType> linkdes = new LinkedList<>(); |
| 982 | BgpValueType tlv = new AutonomousSystemTlv(10); |
| 983 | short deslength = AutonomousSystemTlv.LENGTH; |
| 984 | short desType = AutonomousSystemTlv.TYPE; |
| 985 | |
| 986 | localTlvs.add(tlv); |
| 987 | remoteTlvs.add(tlv); |
| 988 | tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20}); |
| 989 | localTlvs.add(tlv); |
| 990 | tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30}); |
| 991 | remoteTlvs.add(tlv); |
| 992 | NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType); |
| 993 | NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType); |
| 994 | BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode); |
| 995 | BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, |
| 996 | new RouteDistinguisher()); |
| 997 | |
| 998 | BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode); |
| 999 | BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false, |
| 1000 | new RouteDistinguisher()); |
| 1001 | |
| 1002 | PathAttrNlriDetails details = new PathAttrNlriDetails(); |
| 1003 | details.setIdentifier(0); |
| 1004 | details.setProtocolID(ProtocolType.DIRECT); |
| 1005 | List<BgpValueType> pathAttributes = new LinkedList<>(); |
| 1006 | List<BgpValueType> linkStateAttributes = new LinkedList<>(); |
| 1007 | tlv = BgpAttrRouterIdV4.of(Ip4Address.valueOf("1.1.1.1"), LinkStateAttributes.ATTR_NODE_IPV4_LOCAL_ROUTER_ID); |
| 1008 | linkStateAttributes.add(tlv); |
| 1009 | pathAttributes.add(new LinkStateAttributes(linkStateAttributes)); |
| 1010 | details.setPathAttribute(pathAttributes); |
| 1011 | |
| 1012 | tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100); |
| 1013 | linkdes.add(tlv); |
| 1014 | BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes); |
| 1015 | BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId, |
| 1016 | new RouteDistinguisher(), false); |
| 1017 | |
| 1018 | for (BgpNodeListener l : controller.nodeListener) { |
| 1019 | l.addNode(nodeNlri, details); |
| 1020 | assertThat(nodeRegistry.connected.size(), is(1)); |
| 1021 | //Check label resource reserved for that device |
Priyanka B | 4c3b451 | 2016-07-22 11:41:49 +0530 | [diff] [blame] | 1022 | DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); |
| 1023 | |
| 1024 | newBuilder.set("lsrId", "1.1.1.1"); |
| 1025 | |
| 1026 | Device device = new DefaultDevice(BgpTopologyProviderTest.providerId, |
| 1027 | nodeRegistry.connected.iterator().next(), Device.Type.ROUTER, |
| 1028 | UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId(), newBuilder.build()); |
| 1029 | |
| 1030 | DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 1031 | listener.event(event); |
| 1032 | assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(1)); |
| 1033 | l.addNode(remNodeNlri, details); |
| 1034 | assertThat(nodeRegistry.connected.size(), is(2)); |
| 1035 | l.deleteNode(remNodeNlri); |
| 1036 | assertThat(nodeRegistry.connected.size(), is(1)); |
| 1037 | assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(1)); |
| 1038 | } |
| 1039 | |
| 1040 | List<BgpValueType> linkPathAttributes = new LinkedList<>(); |
| 1041 | List<BgpValueType> linkStateAttr = new LinkedList<>(); |
| 1042 | tlv = BgpLinkAttrIgpMetric.of(10, 4); |
| 1043 | linkStateAttr.add(tlv); |
| 1044 | tlv = BgpLinkAttrTeDefaultMetric.of(20); |
| 1045 | linkStateAttr.add(tlv); |
Priyanka B | c1e4e4c | 2016-07-01 14:57:19 +0530 | [diff] [blame] | 1046 | tlv = BgpLinkAttrMaxLinkBandwidth.of((float) 70 * 1_000_000L, |
| 1047 | LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 1048 | linkStateAttr.add(tlv); |
| 1049 | linkPathAttributes.add(new LinkStateAttributes(linkStateAttr)); |
| 1050 | details.setPathAttribute(linkPathAttributes); |
| 1051 | |
| 1052 | for (BgpLinkListener l : controller.linkListener) { |
| 1053 | l.addLink(linkNlri, details); |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 1054 | LinkKey linkKey = LinkKey.linkKey(linkRegistry.links.getFirst().src(), |
| 1055 | linkRegistry.links.getLast().dst()); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 1056 | assertThat(linkRegistry.links.size(), is(1)); |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 1057 | TeLinkConfig config = networkConfigService.getTeLinkConfig().get(linkKey); |
| 1058 | |
| 1059 | assertThat(config.igpCost(), is(10)); |
| 1060 | assertThat(config.teCost(), is(20)); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 1061 | |
| 1062 | ConnectPoint src = new ConnectPoint( |
| 1063 | DeviceId.deviceId("l3:rd=0::routinguniverse=0:asn=10:isoid=1414.1414.0014"), |
| 1064 | PortNumber.portNumber(4294967395L)); |
| 1065 | ConnectPoint dst = new ConnectPoint( |
| 1066 | DeviceId.deviceId("l3:rd=0::routinguniverse=0:asn=10:isoid=1e1e.1e1e.001e"), |
| 1067 | PortNumber.portNumber(4294967396L)); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 1068 | |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 1069 | assertThat(config.maxResvBandwidth(), is(70.0)); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 1070 | |
| 1071 | l.deleteLink(linkNlri); |
| 1072 | assertThat(linkRegistry.links.size(), is(0)); |
Satish K | 690d5cf | 2017-04-04 15:12:38 +0530 | [diff] [blame] | 1073 | config = networkConfigService.getTeLinkConfig().get(linkKey); |
| 1074 | assertThat(config, is(nullValue())); |
Priyanka B | 658aa698 | 2016-05-27 21:34:49 +0530 | [diff] [blame] | 1075 | } |
| 1076 | } |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 1077 | } |