Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014-2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.bgp; |
| 17 | |
| 18 | import com.google.common.net.InetAddresses; |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 19 | |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 20 | import org.jboss.netty.bootstrap.ClientBootstrap; |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 21 | import org.jboss.netty.buffer.ChannelBuffer; |
| 22 | import org.jboss.netty.buffer.ChannelBuffers; |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 23 | import org.jboss.netty.channel.Channel; |
| 24 | import org.jboss.netty.channel.ChannelFactory; |
| 25 | import org.jboss.netty.channel.ChannelPipeline; |
| 26 | import org.jboss.netty.channel.ChannelPipelineFactory; |
| 27 | import org.jboss.netty.channel.Channels; |
| 28 | import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; |
| 29 | import org.junit.After; |
| 30 | import org.junit.Before; |
| 31 | import org.junit.Test; |
| 32 | |
| 33 | import static org.hamcrest.core.Is.is; |
| 34 | import static org.junit.Assert.assertThat; |
| 35 | |
| 36 | import org.onlab.junit.TestUtils; |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 37 | import org.onlab.junit.TestUtils.TestUtilsException; |
| 38 | import org.onlab.packet.Ip4Address; |
| 39 | import org.onlab.packet.IpAddress; |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 40 | |
| 41 | import java.net.InetAddress; |
| 42 | import java.net.InetSocketAddress; |
| 43 | import java.net.SocketAddress; |
| 44 | import java.util.LinkedList; |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 45 | import java.util.Map; |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 46 | import java.util.concurrent.Executors; |
| 47 | import java.util.concurrent.TimeUnit; |
| 48 | |
| 49 | import org.slf4j.Logger; |
| 50 | import org.slf4j.LoggerFactory; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 51 | import org.onosproject.bgp.controller.BgpCfg; |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 52 | import org.onosproject.bgp.controller.BgpId; |
| 53 | import org.onosproject.bgp.controller.impl.AdjRibIn; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 54 | import org.onosproject.bgp.controller.impl.BgpControllerImpl; |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 55 | import org.onosproject.bgp.controller.impl.BgpLocalRibImpl; |
| 56 | import org.onosproject.bgp.controller.impl.BgpPeerImpl; |
| 57 | import org.onosproject.bgp.controller.impl.VpnAdjRibIn; |
| 58 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier; |
| 59 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier; |
| 60 | import org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier; |
| 61 | import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; |
| 62 | import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; |
| 63 | import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib; |
| 64 | import org.onosproject.bgpio.types.AutonomousSystemTlv; |
| 65 | import org.onosproject.bgpio.types.BgpLSIdentifierTlv; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 66 | import org.onosproject.bgpio.types.BgpValueType; |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 67 | import org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv; |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 68 | import org.onosproject.bgpio.types.IPReachabilityInformationTlv; |
| 69 | import org.onosproject.bgpio.types.IPv4AddressTlv; |
| 70 | import org.onosproject.bgpio.types.IsIsNonPseudonode; |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 71 | import org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv; |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 72 | import org.onosproject.bgpio.types.IsIsPseudonode; |
| 73 | import org.onosproject.bgpio.types.RouteDistinguisher; |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Test case for BGPControllerImpl. |
| 77 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 78 | public class BgpControllerImplTest { |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 79 | |
| 80 | protected static final Logger log = LoggerFactory |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 81 | .getLogger(BgpControllerImplTest.class); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 82 | |
| 83 | private static final String IP_LOOPBACK_ID1 = "127.0.0.1"; |
| 84 | |
| 85 | private static final int MESSAGE_TIMEOUT_MS = 3000; |
| 86 | public byte version; |
| 87 | public short asNumber; |
| 88 | public short holdTime; |
| 89 | public int bgpId = InetAddresses.coerceToInteger(InetAddresses.forString(IP_LOOPBACK_ID1)); |
| 90 | public boolean isLargeAsCapabilitySet = false; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 91 | public LinkedList<BgpValueType> capabilityTlv = new LinkedList<>(); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 92 | |
| 93 | @Before |
| 94 | public void setUp() throws Exception { |
| 95 | peer1 = new BgpPeerTest(version, asNumber, |
| 96 | holdTime, bgpId, isLargeAsCapabilitySet, |
| 97 | capabilityTlv); |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 98 | peer2 = new BgpPeerTest(version, asNumber, |
| 99 | holdTime, bgpId, isLargeAsCapabilitySet, |
| 100 | capabilityTlv); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 101 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 102 | bgpControllerImpl = new BgpControllerImpl(); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 103 | |
| 104 | // NOTE: We use port 0 to bind on any available port |
| 105 | bgpControllerImpl.controller().setBgpPortNum(); |
| 106 | bgpControllerImpl.activate(); |
| 107 | |
| 108 | Channel serverChannel = TestUtils.getField(bgpControllerImpl.controller(), |
| 109 | "serverChannel"); |
| 110 | SocketAddress socketAddress = serverChannel.getLocalAddress(); |
| 111 | InetSocketAddress inetSocketAddress = |
| 112 | (InetSocketAddress) socketAddress; |
| 113 | InetAddress connectToAddress = InetAddresses.forString("127.0.0.1"); |
| 114 | connectToSocket = new InetSocketAddress(connectToAddress, |
| 115 | inetSocketAddress.getPort()); |
| 116 | |
| 117 | bgpControllerImpl.getConfig().setRouterId("1.1.1.1"); |
| 118 | bgpControllerImpl.getConfig().setAsNumber(200); |
| 119 | bgpControllerImpl.getConfig().setHoldTime((short) 120); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 120 | bgpControllerImpl.getConfig().setState(BgpCfg.State.IP_AS_CONFIGURED); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 121 | |
| 122 | bgpControllerImpl.getConfig().addPeer("127.0.0.1", 200); |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 123 | bgpControllerImpl.getConfig().addPeer("127.0.0.9", 200); |
| 124 | bgpControllerImpl.getConfig().addPeer("127.0.0.33", 200); |
| 125 | bgpControllerImpl.getConfig().addPeer("127.0.0.10", 200); |
| 126 | bgpControllerImpl.getConfig().addPeer("127.0.0.20", 200); |
| 127 | bgpControllerImpl.getConfig().addPeer("127.0.0.30", 200); |
| 128 | bgpControllerImpl.getConfig().addPeer("127.0.0.40", 200); |
| 129 | bgpControllerImpl.getConfig().addPeer("127.0.0.50", 200); |
| 130 | bgpControllerImpl.getConfig().addPeer("127.0.0.60", 200); |
| 131 | bgpControllerImpl.getConfig().addPeer("127.0.0.70", 200); |
| 132 | bgpControllerImpl.getConfig().addPeer("127.0.0.80", 200); |
| 133 | bgpControllerImpl.getConfig().addPeer("127.0.0.90", 200); |
| 134 | bgpControllerImpl.getConfig().addPeer("127.0.0.91", 200); |
| 135 | bgpControllerImpl.getConfig().addPeer("127.0.0.92", 200); |
| 136 | bgpControllerImpl.getConfig().addPeer("127.0.0.99", 200); |
| 137 | bgpControllerImpl.getConfig().addPeer("127.0.0.94", 200); |
| 138 | bgpControllerImpl.getConfig().addPeer("127.0.0.95", 200); |
| 139 | bgpControllerImpl.getConfig().addPeer("127.0.0.35", 200); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | @After |
| 143 | public void tearDown() throws Exception { |
| 144 | bgpControllerImpl.deactivate(); |
| 145 | bgpControllerImpl = null; |
| 146 | } |
| 147 | |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 148 | private BgpControllerImpl bgpControllerImpl; |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 149 | |
| 150 | BgpPeerTest peer1; |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 151 | BgpPeerTest peer2; |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 152 | // The socket that the remote peers should connect to |
| 153 | private InetSocketAddress connectToSocket; |
| 154 | |
| 155 | @Test |
| 156 | public void bgpOpenMessageTest1() throws InterruptedException { |
| 157 | peer1.peerChannelHandler.asNumber = 200; |
| 158 | peer1.peerChannelHandler.version = 4; |
| 159 | peer1.peerChannelHandler.holdTime = 120; |
| 160 | peer1.connect(connectToSocket); |
| 161 | boolean result; |
| 162 | result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await( |
| 163 | MESSAGE_TIMEOUT_MS, |
| 164 | TimeUnit.MILLISECONDS); |
| 165 | assertThat(result, is(true)); |
| 166 | result = peer1.peerFrameDecoder.receivedKeepaliveMessageLatch.await( |
| 167 | MESSAGE_TIMEOUT_MS, |
| 168 | TimeUnit.MILLISECONDS); |
| 169 | assertThat(result, is(true)); |
| 170 | } |
| 171 | |
| 172 | @Test |
| 173 | public void bgpOpenMessageTest2() throws InterruptedException { |
| 174 | // Open message with as number which is not configured at peer |
| 175 | peer1.peerChannelHandler.asNumber = 500; |
| 176 | peer1.peerChannelHandler.version = 4; |
| 177 | peer1.peerChannelHandler.holdTime = 120; |
| 178 | peer1.connect(connectToSocket); |
| 179 | |
| 180 | boolean result; |
| 181 | result = peer1.peerFrameDecoder.receivedNotificationMessageLatch.await( |
| 182 | MESSAGE_TIMEOUT_MS, |
| 183 | TimeUnit.MILLISECONDS); |
Shashikanth VH | 97e571e | 2016-01-05 12:15:14 +0530 | [diff] [blame] | 184 | assertThat(result, is(true)); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | @Test |
| 188 | public void bgpOpenMessageTest3() throws InterruptedException { |
| 189 | // Open message with invalid hold time value |
| 190 | peer1.peerChannelHandler.asNumber = 200; |
| 191 | peer1.peerChannelHandler.version = 4; |
| 192 | peer1.peerChannelHandler.holdTime = 1; |
| 193 | peer1.connect(connectToSocket); |
| 194 | |
| 195 | boolean result; |
| 196 | result = peer1.peerFrameDecoder.receivedNotificationMessageLatch.await( |
| 197 | MESSAGE_TIMEOUT_MS, |
| 198 | TimeUnit.MILLISECONDS); |
| 199 | assertThat(result, is(true)); |
| 200 | } |
| 201 | |
| 202 | @Test |
| 203 | public void bgpOpenMessageTest4() throws InterruptedException { |
| 204 | // Open message with invalid as number |
| 205 | peer1.peerChannelHandler.asNumber = 200; |
| 206 | peer1.peerChannelHandler.version = 4; |
| 207 | peer1.peerChannelHandler.holdTime = 120; |
| 208 | peer1.peerChannelHandler.isLargeAsCapabilitySet = true; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 209 | BgpValueType tempTlv = new FourOctetAsNumCapabilityTlv(766545); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 210 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv); |
| 211 | peer1.connect(connectToSocket); |
| 212 | |
| 213 | boolean result; |
| 214 | result = peer1.peerFrameDecoder.receivedNotificationMessageLatch.await( |
| 215 | MESSAGE_TIMEOUT_MS, |
| 216 | TimeUnit.MILLISECONDS); |
| 217 | assertThat(result, is(true)); |
| 218 | } |
| 219 | |
| 220 | @Test |
| 221 | public void bgpOpenMessageTest5() throws InterruptedException { |
| 222 | // Open message with LS capability |
| 223 | short afi = 16388; |
| 224 | byte res = 0; |
| 225 | byte safi = 71; |
| 226 | peer1.peerChannelHandler.asNumber = 200; |
| 227 | peer1.peerChannelHandler.version = 4; |
| 228 | peer1.peerChannelHandler.holdTime = 120; |
| 229 | bgpControllerImpl.getConfig().setLsCapability(true); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 230 | BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 231 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 232 | peer1.connect(connectToSocket); |
| 233 | |
| 234 | boolean result; |
| 235 | result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await( |
| 236 | MESSAGE_TIMEOUT_MS, |
| 237 | TimeUnit.MILLISECONDS); |
| 238 | assertThat(result, is(true)); |
| 239 | result = peer1.peerFrameDecoder.receivedKeepaliveMessageLatch.await( |
| 240 | MESSAGE_TIMEOUT_MS, |
| 241 | TimeUnit.MILLISECONDS); |
| 242 | assertThat(result, is(true)); |
| 243 | } |
| 244 | |
| 245 | @Test |
| 246 | public void bgpOpenMessageTest6() throws InterruptedException { |
| 247 | // Open message with as4 capability |
| 248 | peer1.peerChannelHandler.asNumber = 200; |
| 249 | peer1.peerChannelHandler.version = 4; |
| 250 | peer1.peerChannelHandler.holdTime = 120; |
| 251 | peer1.peerChannelHandler.isLargeAsCapabilitySet = true; |
| 252 | bgpControllerImpl.getConfig().setLargeASCapability(true); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 253 | BgpValueType tempTlv = new FourOctetAsNumCapabilityTlv(200); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 254 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv); |
| 255 | peer1.connect(connectToSocket); |
| 256 | |
| 257 | boolean result; |
| 258 | result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await( |
| 259 | MESSAGE_TIMEOUT_MS, |
| 260 | TimeUnit.MILLISECONDS); |
| 261 | assertThat(result, is(true)); |
| 262 | result = peer1.peerFrameDecoder.receivedKeepaliveMessageLatch.await( |
| 263 | MESSAGE_TIMEOUT_MS, |
| 264 | TimeUnit.MILLISECONDS); |
| 265 | assertThat(result, is(true)); |
| 266 | |
| 267 | result = peer1.peerFrameDecoder.receivedKeepaliveMessageLatch.await( |
| 268 | MESSAGE_TIMEOUT_MS, |
| 269 | TimeUnit.MILLISECONDS); |
| 270 | assertThat(result, is(true)); |
| 271 | } |
| 272 | |
| 273 | @Test |
| 274 | public void bgpOpenMessageTest7() throws InterruptedException { |
| 275 | // Open message with both LS capability and as4 capability |
| 276 | short afi = 16388; |
| 277 | byte res = 0; |
| 278 | byte safi = 71; |
| 279 | peer1.peerChannelHandler.asNumber = 200; |
| 280 | peer1.peerChannelHandler.version = 4; |
| 281 | peer1.peerChannelHandler.holdTime = 120; |
| 282 | |
| 283 | peer1.peerChannelHandler.isLargeAsCapabilitySet = true; |
| 284 | bgpControllerImpl.getConfig().setLargeASCapability(true); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 285 | BgpValueType tempTlv = new FourOctetAsNumCapabilityTlv(200); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 286 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv); |
| 287 | |
| 288 | bgpControllerImpl.getConfig().setLsCapability(true); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 289 | BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 290 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 291 | peer1.connect(connectToSocket); |
| 292 | |
| 293 | boolean result; |
| 294 | result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await( |
| 295 | MESSAGE_TIMEOUT_MS, |
| 296 | TimeUnit.MILLISECONDS); |
| 297 | assertThat(result, is(true)); |
| 298 | } |
| 299 | |
| 300 | /** |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 301 | * Peer1 has Node NLRI (MpReach). |
| 302 | */ |
| 303 | @Test |
| 304 | public void testBgpUpdateMessage1() throws InterruptedException { |
| 305 | // Initiate the connections |
| 306 | peer1.peerChannelHandler.asNumber = 200; |
| 307 | peer1.peerChannelHandler.version = 4; |
| 308 | peer1.peerChannelHandler.holdTime = 120; |
| 309 | |
| 310 | short afi = 16388; |
| 311 | byte res = 0; |
| 312 | byte safi = 71; |
| 313 | |
| 314 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 315 | BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 316 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 317 | peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.9", 0)); |
| 318 | TimeUnit.MILLISECONDS.sleep(1000); |
| 319 | |
| 320 | //Get peer1 |
| 321 | BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.9")); |
| 322 | BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 323 | |
| 324 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
| 325 | BgpValueType tlv = AutonomousSystemTlv.of(2478); |
| 326 | subTlvs.add(tlv); |
| 327 | tlv = BgpLSIdentifierTlv.of(33686018); |
| 328 | subTlvs.add(tlv); |
| 329 | NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x10, (short) 256); |
| 330 | BgpNodeLSIdentifier key = new BgpNodeLSIdentifier(nodeDes); |
| 331 | AdjRibIn adj = peer.adjRib(); |
| 332 | |
| 333 | //In Adj-RIB, nodeTree should contains specified key |
| 334 | assertThat(adj.nodeTree().containsKey(key), is(true)); |
| 335 | |
| 336 | BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib(); |
| 337 | //In Local-RIB, nodeTree should contains specified key |
| 338 | assertThat(obj.nodeTree().containsKey(key), is(true)); |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * Peer1 has Node NLRI (MpReach) and Peer2 has Node NLRI with same MpReach and MpUnReach. |
| 343 | */ |
| 344 | @Test |
| 345 | public void testBgpUpdateMessage2() throws InterruptedException, TestUtilsException { |
| 346 | // Initiate the connections |
| 347 | peer1.peerChannelHandler.asNumber = 200; |
| 348 | peer1.peerChannelHandler.version = 4; |
| 349 | peer1.peerChannelHandler.holdTime = 120; |
| 350 | short afi = 16388; |
| 351 | byte res = 0; |
| 352 | byte safi = 71; |
| 353 | |
| 354 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 355 | BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 356 | peer2.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 357 | Channel channel = peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.95", 0)); |
| 358 | TimeUnit.MILLISECONDS.sleep(1000); |
| 359 | |
| 360 | //Get peer1 |
| 361 | BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.95")); |
| 362 | BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 363 | |
| 364 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
| 365 | BgpValueType tlv = AutonomousSystemTlv.of(2478); |
| 366 | subTlvs.add(tlv); |
| 367 | tlv = BgpLSIdentifierTlv.of(33686018); |
| 368 | subTlvs.add(tlv); |
| 369 | NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x10, (short) 256); |
| 370 | BgpNodeLSIdentifier key = new BgpNodeLSIdentifier(nodeDes); |
| 371 | TimeUnit.MILLISECONDS.sleep(500); |
| 372 | AdjRibIn adj = peer.adjRib(); |
| 373 | |
| 374 | //In Adj-RIB, nodeTree should contains specified key |
| 375 | assertThat(adj.nodeTree().containsKey(key), is(true)); |
| 376 | |
| 377 | BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib(); |
| 378 | //In Local-RIB, nodeTree should contains specified key |
| 379 | assertThat(obj.nodeTree().containsKey(key), is(true)); |
| 380 | |
| 381 | peer2.peerChannelHandler.asNumber = 200; |
| 382 | peer2.peerChannelHandler.version = 4; |
| 383 | peer2.peerChannelHandler.holdTime = 120; |
| 384 | |
| 385 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 386 | tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 387 | peer2.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 388 | peer2.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.70", 0)); |
| 389 | TimeUnit.MILLISECONDS.sleep(1000); |
| 390 | |
| 391 | //Get peer2 |
| 392 | bgpId = new BgpId(IpAddress.valueOf("127.0.0.70")); |
| 393 | peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 394 | TimeUnit.MILLISECONDS.sleep(200); |
| 395 | adj = peer.adjRib(); |
| 396 | |
| 397 | //In Adj-RIB, nodetree should be empty |
| 398 | assertThat(adj.nodeTree().isEmpty(), is(true)); |
| 399 | |
| 400 | //Disconnect peer1 |
| 401 | channel.disconnect(); |
| 402 | channel.close(); |
| 403 | |
| 404 | obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib(); |
| 405 | TimeUnit.MILLISECONDS.sleep(200); |
| 406 | //In Local-RIB, nodetree should be empty |
| 407 | assertThat(obj.nodeTree().isEmpty(), is(true)); |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Peer1 has Link NLRI (MpReach). |
| 412 | */ |
| 413 | @Test |
| 414 | public void testBgpUpdateMessage3() throws InterruptedException, TestUtilsException { |
| 415 | // Initiate the connections |
| 416 | peer1.peerChannelHandler.asNumber = 200; |
| 417 | peer1.peerChannelHandler.version = 4; |
| 418 | peer1.peerChannelHandler.holdTime = 120; |
| 419 | |
| 420 | short afi = 16388; |
| 421 | byte res = 0; |
| 422 | byte safi = 71; |
| 423 | |
| 424 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 425 | BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 426 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 427 | peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.10", 0)); |
| 428 | TimeUnit.MILLISECONDS.sleep(1000); |
| 429 | |
| 430 | //Get peer1 |
| 431 | BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.10")); |
| 432 | BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 433 | |
| 434 | LinkedList<BgpValueType> localNodeSubTlvs = new LinkedList<>(); |
| 435 | LinkedList<BgpValueType> remoteNodeSubTlvs = new LinkedList<>(); |
| 436 | BgpValueType tlv = AutonomousSystemTlv.of(2222); |
| 437 | localNodeSubTlvs.add(tlv); |
| 438 | remoteNodeSubTlvs.add(tlv); |
| 439 | tlv = BgpLSIdentifierTlv.of(33686018); |
| 440 | localNodeSubTlvs.add(tlv); |
| 441 | remoteNodeSubTlvs.add(tlv); |
| 442 | byte[] isoNodeID = new byte[] {0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21 }; |
| 443 | tlv = IsIsPseudonode.of(isoNodeID, (byte) 0x03); |
| 444 | localNodeSubTlvs.add(tlv); |
| 445 | isoNodeID = new byte[] {0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21 }; |
| 446 | tlv = IsIsNonPseudonode.of(isoNodeID); |
| 447 | remoteNodeSubTlvs.add(tlv); |
| 448 | NodeDescriptors localNodeDes = new NodeDescriptors(localNodeSubTlvs, (short) 0x1b, (short) 256); |
| 449 | NodeDescriptors remoteNodeDes = new NodeDescriptors(remoteNodeSubTlvs, (short) 0x1a, (short) 0x101); |
| 450 | LinkedList<BgpValueType> linkDescriptor = new LinkedList<>(); |
| 451 | tlv = IPv4AddressTlv.of(Ip4Address.valueOf("2.2.2.2"), (short) 0x103); |
| 452 | linkDescriptor.add(tlv); |
| 453 | |
| 454 | BgpLinkLSIdentifier key = new BgpLinkLSIdentifier(localNodeDes, remoteNodeDes, linkDescriptor); |
| 455 | TimeUnit.MILLISECONDS.sleep(200); |
| 456 | AdjRibIn adj = peer.adjRib(); |
| 457 | |
| 458 | //In Adj-RIB, linkTree should contain specified key |
| 459 | assertThat(adj.linkTree().containsKey(key), is(true)); |
| 460 | |
| 461 | BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib(); |
| 462 | TimeUnit.MILLISECONDS.sleep(200); |
| 463 | |
| 464 | //In Local-RIB, linkTree should contain specified key |
| 465 | assertThat(obj.linkTree().containsKey(key), is(true)); |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * Peer1 has Node NLRI and Peer2 has Node NLRI with different MpReach and MpUnReach with VPN. |
| 470 | */ |
| 471 | @Test |
| 472 | public void testBgpUpdateMessage4() throws InterruptedException { |
| 473 | // Initiate the connections |
| 474 | peer1.peerChannelHandler.asNumber = 200; |
| 475 | peer1.peerChannelHandler.version = 4; |
| 476 | peer1.peerChannelHandler.holdTime = 120; |
| 477 | |
| 478 | short afi = 16388; |
| 479 | byte res = 0; |
| 480 | byte safi = (byte) 0x80; |
| 481 | |
| 482 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 483 | BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 484 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 485 | Channel channel = peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.35", 0)); |
| 486 | TimeUnit.MILLISECONDS.sleep(1000); |
| 487 | |
| 488 | //Get peer1 |
| 489 | IpAddress ipAddress = IpAddress.valueOf("127.0.0.35"); |
| 490 | BgpId bgpId = new BgpId(ipAddress); |
| 491 | BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 492 | LinkedList<BgpValueType> subTlvs1 = new LinkedList<>(); |
| 493 | |
| 494 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
| 495 | BgpValueType tlv = AutonomousSystemTlv.of(2478); |
| 496 | subTlvs.add(tlv); |
| 497 | tlv = BgpLSIdentifierTlv.of(33686018); |
| 498 | subTlvs.add(tlv); |
| 499 | |
| 500 | NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x10, (short) 256); |
| 501 | BgpNodeLSIdentifier key = new BgpNodeLSIdentifier(nodeDes); |
| 502 | RouteDistinguisher rd = new RouteDistinguisher((long) 0x0A); |
| 503 | VpnAdjRibIn vpnAdj = peer.vpnAdjRib(); |
| 504 | |
| 505 | //In Adj-RIB, vpnNodeTree should contain rd |
| 506 | assertThat(vpnAdj.vpnNodeTree().containsKey(rd), is(true)); |
| 507 | |
| 508 | Map<BgpNodeLSIdentifier, PathAttrNlriDetails> treeValue = vpnAdj.vpnNodeTree().get(rd); |
| 509 | //In Adj-RIB, vpnNodeTree should contain rd key which contains specified value |
| 510 | assertThat(treeValue.containsKey(key), is(true)); |
| 511 | |
| 512 | BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRibVpn(); |
| 513 | //In Local-RIB, vpnNodeTree should contain rd |
| 514 | assertThat(obj.vpnNodeTree().containsKey(rd), is(true)); |
| 515 | |
| 516 | Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib> value = obj.vpnNodeTree().get(rd); |
| 517 | //In Local-RIB, vpnNodeTree should contain rd key which contains specified value |
| 518 | assertThat(value.containsKey(key), is(true)); |
| 519 | |
| 520 | peer2.peerChannelHandler.asNumber = 200; |
| 521 | peer2.peerChannelHandler.version = 4; |
| 522 | peer2.peerChannelHandler.holdTime = 120; |
| 523 | |
| 524 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 525 | tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 526 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 527 | peer2.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.40", 0)); |
| 528 | TimeUnit.MILLISECONDS.sleep(1000); |
| 529 | |
| 530 | //Get peer2 |
| 531 | bgpId = new BgpId(IpAddress.valueOf("127.0.0.40")); |
| 532 | peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 533 | |
| 534 | tlv = AutonomousSystemTlv.of(686); |
| 535 | subTlvs1.add(tlv); |
| 536 | tlv = BgpLSIdentifierTlv.of(33686018); |
| 537 | subTlvs1.add(tlv); |
| 538 | nodeDes = new NodeDescriptors(subTlvs1, (short) 0x10, (short) 256); |
| 539 | key = new BgpNodeLSIdentifier(nodeDes); |
| 540 | vpnAdj = peer.vpnAdjRib(); |
| 541 | |
| 542 | //In Adj-RIB, vpnNodeTree should contain rd |
| 543 | assertThat(vpnAdj.vpnNodeTree().containsKey(rd), is(true)); |
| 544 | |
| 545 | treeValue = vpnAdj.vpnNodeTree().get(rd); |
| 546 | //In Adj-RIB, vpnNodeTree should contain rd key which contains specified value |
| 547 | assertThat(treeValue.containsKey(key), is(true)); |
| 548 | |
| 549 | //Disconnect peer1 |
| 550 | channel.disconnect(); |
| 551 | channel.close(); |
| 552 | |
| 553 | obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRibVpn(); |
| 554 | |
| 555 | //In Local-RIB, vpnNodeTree should contain rd |
| 556 | assertThat(obj.vpnNodeTree().containsKey(rd), is(true)); |
| 557 | |
| 558 | value = obj.vpnNodeTree().get(rd); |
| 559 | //In Local-RIB, vpnNodeTree should contain rd key which contains specified value |
| 560 | assertThat(value.containsKey(key), is(true)); |
| 561 | } |
| 562 | |
| 563 | /** |
| 564 | * Peer1 has Node NLRI and Peer2 has Node NLRI with different MpReach and MpUnReach. |
| 565 | */ |
| 566 | @Test |
| 567 | public void testBgpUpdateMessage5() throws InterruptedException, TestUtilsException { |
| 568 | // Initiate the connections |
| 569 | peer1.peerChannelHandler.asNumber = 200; |
| 570 | peer1.peerChannelHandler.version = 4; |
| 571 | peer1.peerChannelHandler.holdTime = 120; |
| 572 | |
| 573 | short afi = 16388; |
| 574 | byte res = 0; |
| 575 | byte safi = 71; |
| 576 | |
| 577 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 578 | BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 579 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 580 | Channel channel = peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.99", 0)); |
| 581 | TimeUnit.MILLISECONDS.sleep(1000); |
| 582 | |
| 583 | //Get peer1 |
| 584 | BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.99")); |
| 585 | BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 586 | |
| 587 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
| 588 | BgpValueType tlv = null; |
| 589 | tlv = AutonomousSystemTlv.of(2478); |
| 590 | subTlvs.add(tlv); |
| 591 | tlv = BgpLSIdentifierTlv.of(33686018); |
| 592 | subTlvs.add(tlv); |
| 593 | NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x10, (short) 256); |
| 594 | BgpNodeLSIdentifier key = new BgpNodeLSIdentifier(nodeDes); |
| 595 | TimeUnit.MILLISECONDS.sleep(500); |
| 596 | AdjRibIn adj = peer.adjRib(); |
| 597 | |
| 598 | //In Adj-RIB, nodeTree should contain specified key |
| 599 | assertThat(adj.nodeTree().containsKey(key), is(true)); |
| 600 | |
| 601 | BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib(); |
| 602 | //In Local-RIB, nodeTree should contain specified key |
| 603 | assertThat(obj.nodeTree().containsKey(key), is(true)); |
| 604 | |
| 605 | peer2.peerChannelHandler.asNumber = 200; |
| 606 | peer2.peerChannelHandler.version = 4; |
| 607 | peer2.peerChannelHandler.holdTime = 120; |
| 608 | |
| 609 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 610 | tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 611 | peer2.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 612 | peer2.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.92", 0)); |
| 613 | TimeUnit.MILLISECONDS.sleep(1000); |
| 614 | |
| 615 | //Get peer2 |
| 616 | bgpId = new BgpId(IpAddress.valueOf("127.0.0.92")); |
| 617 | peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 618 | adj = peer.adjRib(); |
| 619 | |
| 620 | //In Adj-RIB, nodetree should be empty |
| 621 | assertThat(adj.nodeTree().isEmpty(), is(true)); |
| 622 | |
| 623 | //peer1 disconnects |
| 624 | channel.disconnect(); |
| 625 | channel.close(); |
| 626 | |
| 627 | obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib(); |
| 628 | TimeUnit.MILLISECONDS.sleep(200); |
| 629 | |
| 630 | //In Local-RIB, nodeTree should be empty |
| 631 | assertThat(obj.nodeTree().isEmpty(), is(true)); |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * Peer2 has Prefix NLRI (MpReach). |
| 636 | */ |
| 637 | @Test |
| 638 | public void testBgpUpdateMessage6() throws InterruptedException { |
| 639 | // Initiate the connections |
| 640 | peer1.peerChannelHandler.asNumber = 200; |
| 641 | peer1.peerChannelHandler.version = 4; |
| 642 | peer1.peerChannelHandler.holdTime = 120; |
| 643 | |
| 644 | short afi = 16388; |
| 645 | byte res = 0; |
| 646 | byte safi = 71; |
| 647 | |
| 648 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 649 | BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 650 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 651 | Channel channel = peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.94", 0)); |
| 652 | TimeUnit.MILLISECONDS.sleep(1000); |
| 653 | |
| 654 | //Get peer1 |
| 655 | BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.94")); |
| 656 | BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 657 | |
| 658 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
| 659 | BgpValueType tlv = AutonomousSystemTlv.of(2478); |
| 660 | subTlvs.add(tlv); |
| 661 | tlv = BgpLSIdentifierTlv.of(33686018); |
| 662 | subTlvs.add(tlv); |
| 663 | NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x10, (short) 256); |
| 664 | BgpNodeLSIdentifier key = new BgpNodeLSIdentifier(nodeDes); |
| 665 | TimeUnit.MILLISECONDS.sleep(500); |
| 666 | AdjRibIn adj = peer.adjRib(); |
| 667 | |
| 668 | //In Adj-RIB, nodeTree should contain specified key |
| 669 | assertThat(adj.nodeTree().containsKey(key), is(true)); |
| 670 | |
| 671 | BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib(); |
| 672 | //In Local-RIB, nodeTree should contain specified key |
| 673 | assertThat(obj.nodeTree().containsKey(key), is(true)); |
| 674 | |
| 675 | peer2.peerChannelHandler.asNumber = 200; |
| 676 | peer2.peerChannelHandler.version = 4; |
| 677 | peer2.peerChannelHandler.holdTime = 120; |
| 678 | |
| 679 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 680 | tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 681 | peer2.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 682 | peer2.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.80", 0)); |
| 683 | TimeUnit.MILLISECONDS.sleep(1000); |
| 684 | |
| 685 | //Get peer2 |
| 686 | bgpId = new BgpId(IpAddress.valueOf("127.0.0.80")); |
| 687 | peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 688 | TimeUnit.MILLISECONDS.sleep(500); |
| 689 | adj = peer.adjRib(); |
| 690 | |
| 691 | //In Adj-RIB, nodeTree should contain specified key |
| 692 | assertThat(adj.nodeTree().containsKey(key), is(true)); |
| 693 | |
| 694 | //peer1 disconnects |
| 695 | channel.disconnect(); |
| 696 | channel.close(); |
| 697 | |
| 698 | obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib(); |
| 699 | TimeUnit.MILLISECONDS.sleep(200); |
| 700 | |
| 701 | //In Local-RIB, nodeTree should contain specified key |
| 702 | assertThat(obj.nodeTree().containsKey(key), is(true)); |
| 703 | } |
| 704 | |
| 705 | /** |
| 706 | * Peer1 has Node NLRI (MpReach) and peer2 has Node NLRI with same MpReach and MpUnReach with IsIsNonPseudonode. |
| 707 | */ |
| 708 | @Test |
| 709 | public void testBgpUpdateMessage7() throws InterruptedException, TestUtilsException { |
| 710 | // Initiate the connections |
| 711 | peer1.peerChannelHandler.asNumber = 200; |
| 712 | peer1.peerChannelHandler.version = 4; |
| 713 | peer1.peerChannelHandler.holdTime = 120; |
| 714 | |
| 715 | short afi = 16388; |
| 716 | byte res = 0; |
| 717 | byte safi = 71; |
| 718 | |
| 719 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 720 | BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 721 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 722 | Channel channel = peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.91", 0)); |
| 723 | TimeUnit.MILLISECONDS.sleep(1000); |
| 724 | |
| 725 | //Get peer1 |
| 726 | BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.91")); |
| 727 | BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 728 | |
| 729 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
| 730 | LinkedList<BgpValueType> subTlvs1 = new LinkedList<>(); |
| 731 | BgpValueType tlv = null; |
| 732 | tlv = AutonomousSystemTlv.of(2478); |
| 733 | subTlvs.add(tlv); |
| 734 | tlv = BgpLSIdentifierTlv.of(33686018); |
| 735 | subTlvs.add(tlv); |
| 736 | subTlvs1.add(tlv); |
| 737 | NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x10, (short) 256); |
| 738 | BgpNodeLSIdentifier key = new BgpNodeLSIdentifier(nodeDes); |
| 739 | AdjRibIn adj = peer.adjRib(); |
| 740 | |
| 741 | //In Adj-RIB, nodeTree should contains specified key |
| 742 | assertThat(adj.nodeTree().containsKey(key), is(true)); |
| 743 | |
| 744 | BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib(); |
| 745 | //In Local-RIB, nodeTree should contains specified key |
| 746 | assertThat(obj.nodeTree().containsKey(key), is(true)); |
| 747 | |
| 748 | peer2.peerChannelHandler.asNumber = 200; |
| 749 | peer2.peerChannelHandler.version = 4; |
| 750 | peer2.peerChannelHandler.holdTime = 120; |
| 751 | |
| 752 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 753 | tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 754 | peer2.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 755 | peer2.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.90", 0)); |
| 756 | TimeUnit.MILLISECONDS.sleep(1000); |
| 757 | |
| 758 | //Get peer2 |
| 759 | bgpId = new BgpId(IpAddress.valueOf("127.0.0.90")); |
| 760 | peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 761 | |
| 762 | tlv = AutonomousSystemTlv.of(2222); |
| 763 | subTlvs1.add(tlv); |
| 764 | byte[] isoNodeID = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; |
| 765 | tlv = IsIsNonPseudonode.of(isoNodeID); |
| 766 | subTlvs1.add(tlv); |
| 767 | nodeDes = new NodeDescriptors(subTlvs1, (short) 0x1a, (short) 256); |
| 768 | key = new BgpNodeLSIdentifier(nodeDes); |
| 769 | adj = peer.adjRib(); |
| 770 | |
| 771 | //In Adj-RIB, nodeTree should contains specified key |
| 772 | log.info("key " + key.toString()); |
| 773 | log.info("adj.nodeTree() " + adj.nodeTree().toString()); |
| 774 | assertThat(adj.nodeTree().containsKey(key), is(true)); |
| 775 | |
| 776 | //peer1 disconnects |
| 777 | channel.disconnect(); |
| 778 | channel.close(); |
| 779 | |
| 780 | obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib(); |
| 781 | TimeUnit.MILLISECONDS.sleep(200); |
| 782 | |
| 783 | //In Local-RIB, nodeTree should contains specified key |
| 784 | assertThat(obj.nodeTree().containsKey(key), is(true)); |
| 785 | } |
| 786 | |
| 787 | /** |
| 788 | * Peer1 has Prefix NLRI (MpReach). |
| 789 | */ |
| 790 | @Test |
| 791 | public void testBgpUpdateMessage8() throws InterruptedException { |
| 792 | // Initiate the connections |
| 793 | peer1.peerChannelHandler.asNumber = 200; |
| 794 | peer1.peerChannelHandler.version = 4; |
| 795 | peer1.peerChannelHandler.holdTime = 150; |
| 796 | |
| 797 | short afi = 16388; |
| 798 | byte res = 0; |
| 799 | byte safi = 71; |
| 800 | |
| 801 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 802 | BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 803 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 804 | peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.20", 0)); |
| 805 | TimeUnit.MILLISECONDS.sleep(1000); |
| 806 | |
| 807 | //Get peer1 |
| 808 | BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.20")); |
| 809 | BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 810 | |
| 811 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
| 812 | BgpValueType tlv = AutonomousSystemTlv.of(2222); |
| 813 | subTlvs.add(tlv); |
| 814 | tlv = BgpLSIdentifierTlv.of(33686018); |
| 815 | subTlvs.add(tlv); |
| 816 | byte[] isoNodeID = new byte[] {0x19, 0x21, 0x68, 0x07, 0x70, 0x01}; |
| 817 | tlv = IsIsNonPseudonode.of(isoNodeID); |
| 818 | subTlvs.add(tlv); |
| 819 | NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x1a, (short) 256); |
| 820 | LinkedList<BgpValueType> prefixDescriptor = new LinkedList<>(); |
| 821 | byte[] prefix = new byte[] {0x20, (byte) 0xc0, (byte) 0xa8, 0x4d, 0x01}; |
| 822 | ChannelBuffer tempCb = ChannelBuffers.dynamicBuffer(); |
| 823 | tempCb.writeBytes(prefix); |
| 824 | tlv = IPReachabilityInformationTlv.read(tempCb, (short) 5); |
| 825 | prefixDescriptor.add(tlv); |
| 826 | BgpPrefixLSIdentifier key = new BgpPrefixLSIdentifier(nodeDes, prefixDescriptor); |
| 827 | |
| 828 | AdjRibIn adj = peer.adjRib(); |
| 829 | |
| 830 | //In Adj-RIB, prefixTree should contain specified key |
| 831 | assertThat(adj.prefixTree().containsKey(key), is(true)); |
| 832 | |
| 833 | BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib(); |
| 834 | //In Local-RIB, prefixTree should contain specified key |
| 835 | assertThat(obj.prefixTree().containsKey(key), is(true)); |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * Peer1 has Node NLRI (MpReach) and Peer2 has node NLRI with different MpReach |
| 840 | * and MpUnReach with IsIsNonPseudonode. |
| 841 | */ |
| 842 | @Test |
| 843 | public void testBgpUpdateMessage9() throws InterruptedException { |
| 844 | // Initiate the connections |
| 845 | peer1.peerChannelHandler.asNumber = 200; |
| 846 | peer1.peerChannelHandler.version = 4; |
| 847 | peer1.peerChannelHandler.holdTime = 120; |
| 848 | |
| 849 | short afi = 16388; |
| 850 | byte res = 0; |
| 851 | byte safi = (byte) 0x80; |
| 852 | |
| 853 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 854 | BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 855 | peer1.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 856 | Channel channel = peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.30", 0)); |
| 857 | TimeUnit.MILLISECONDS.sleep(1000); |
| 858 | |
| 859 | //Get peer1 |
| 860 | BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.30")); |
| 861 | BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 862 | |
| 863 | LinkedList<BgpValueType> subTlvs = new LinkedList<>(); |
| 864 | BgpValueType tlv = AutonomousSystemTlv.of(2478); |
| 865 | subTlvs.add(tlv); |
| 866 | tlv = BgpLSIdentifierTlv.of(33686018); |
| 867 | subTlvs.add(tlv); |
| 868 | |
| 869 | NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x10, (short) 256); |
| 870 | BgpNodeLSIdentifier key = new BgpNodeLSIdentifier(nodeDes); |
| 871 | RouteDistinguisher rd = new RouteDistinguisher((long) 0x0A); |
| 872 | VpnAdjRibIn vpnAdj = peer.vpnAdjRib(); |
| 873 | |
| 874 | //In Adj-RIB, vpnNodeTree should contain specified rd |
| 875 | assertThat(vpnAdj.vpnNodeTree().containsKey(rd), is(true)); |
| 876 | |
| 877 | Map<BgpNodeLSIdentifier, PathAttrNlriDetails> treeValue = vpnAdj.vpnNodeTree().get(rd); |
| 878 | //In Adj-RIB, vpnNodeTree should contain specified rd with specified value |
| 879 | assertThat(treeValue.containsKey(key), is(true)); |
| 880 | |
| 881 | BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRibVpn(); |
| 882 | //In Local-RIB, vpnNodeTree should contain specified rd |
| 883 | assertThat(obj.vpnNodeTree().containsKey(rd), is(true)); |
| 884 | |
| 885 | Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib> value = obj.vpnNodeTree().get(rd); |
| 886 | //In Local-RIB, vpnNodeTree should contain specified rd with specified value |
| 887 | assertThat(value.containsKey(key), is(true)); |
| 888 | |
| 889 | peer2.peerChannelHandler.asNumber = 200; |
| 890 | peer2.peerChannelHandler.version = 4; |
| 891 | peer2.peerChannelHandler.holdTime = 120; |
| 892 | |
| 893 | bgpControllerImpl.getConfig().setLsCapability(true); |
| 894 | tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi); |
| 895 | peer2.peerChannelHandler.capabilityTlv.add(tempTlv1); |
| 896 | peer2.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.50", 0)); |
| 897 | TimeUnit.MILLISECONDS.sleep(1000); |
| 898 | |
| 899 | //Get peer2 |
| 900 | bgpId = new BgpId(IpAddress.valueOf("127.0.0.50")); |
| 901 | peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId); |
| 902 | key = new BgpNodeLSIdentifier(nodeDes); |
| 903 | vpnAdj = peer.vpnAdjRib(); |
| 904 | |
| 905 | //In Adj-RIB, vpnNodeTree should be empty |
| 906 | assertThat(vpnAdj.vpnNodeTree().isEmpty(), is(true)); |
| 907 | |
| 908 | //peer1 disconnects |
| 909 | channel.disconnect(); |
| 910 | channel.close(); |
| 911 | |
| 912 | obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRibVpn(); |
| 913 | TimeUnit.MILLISECONDS.sleep(200); |
| 914 | |
| 915 | //In Local-RIB, vpnNodeTree should be empty |
| 916 | assertThat(obj.vpnNodeTree().isEmpty(), is(true)); |
| 917 | } |
| 918 | |
| 919 | /** |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 920 | * A class to capture the state for a BGP peer. |
| 921 | */ |
| 922 | private final class BgpPeerTest { |
| 923 | private ClientBootstrap peerBootstrap; |
| 924 | private BgpPeerFrameDecoderTest peerFrameDecoder = |
| 925 | new BgpPeerFrameDecoderTest(); |
| 926 | private BgpPeerChannelHandlerTest peerChannelHandler; |
| 927 | |
| 928 | private BgpPeerTest(byte version, short asNumber, |
| 929 | short holdTime, int bgpId, boolean isLargeAsCapabilitySet, |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 930 | LinkedList<BgpValueType> capabilityTlv) { |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 931 | peerChannelHandler = new BgpPeerChannelHandlerTest(version, |
| 932 | asNumber, holdTime, bgpId, isLargeAsCapabilitySet, capabilityTlv); |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * Starts the BGP peer. |
| 937 | * |
| 938 | * @param connectToSocket the socket to connect to |
| 939 | */ |
| 940 | private void connect(InetSocketAddress connectToSocket) |
| 941 | throws InterruptedException { |
| 942 | |
| 943 | ChannelFactory channelFactory = |
| 944 | new NioClientSocketChannelFactory( |
| 945 | Executors.newCachedThreadPool(), |
| 946 | Executors.newCachedThreadPool()); |
| 947 | ChannelPipelineFactory pipelineFactory = () -> { |
| 948 | ChannelPipeline pipeline = Channels.pipeline(); |
| 949 | pipeline.addLast("BgpPeerFrameDecoderTest", |
| 950 | peerFrameDecoder); |
| 951 | pipeline.addLast("BgpPeerChannelHandlerTest", |
| 952 | peerChannelHandler); |
| 953 | return pipeline; |
| 954 | }; |
| 955 | |
| 956 | peerBootstrap = new ClientBootstrap(channelFactory); |
| 957 | peerBootstrap.setOption("child.keepAlive", true); |
| 958 | peerBootstrap.setOption("child.tcpNoDelay", true); |
| 959 | peerBootstrap.setPipelineFactory(pipelineFactory); |
| 960 | peerBootstrap.connect(connectToSocket); |
| 961 | } |
Priyanka B | 249027e | 2015-12-14 12:42:41 +0530 | [diff] [blame^] | 962 | |
| 963 | private Channel connectFrom(InetSocketAddress connectToSocket, SocketAddress localAddress) |
| 964 | throws InterruptedException { |
| 965 | |
| 966 | ChannelFactory channelFactory = |
| 967 | new NioClientSocketChannelFactory( |
| 968 | Executors.newCachedThreadPool(), |
| 969 | Executors.newCachedThreadPool()); |
| 970 | ChannelPipelineFactory pipelineFactory = () -> { |
| 971 | ChannelPipeline pipeline = Channels.pipeline(); |
| 972 | pipeline.addLast("BgpPeerFrameDecoderTest", |
| 973 | peerFrameDecoder); |
| 974 | pipeline.addLast("BgpPeerChannelHandlerTest", |
| 975 | peerChannelHandler); |
| 976 | return pipeline; |
| 977 | }; |
| 978 | |
| 979 | peerBootstrap = new ClientBootstrap(channelFactory); |
| 980 | peerBootstrap.setOption("child.keepAlive", true); |
| 981 | peerBootstrap.setOption("child.tcpNoDelay", true); |
| 982 | peerBootstrap.setPipelineFactory(pipelineFactory); |
| 983 | Channel channel = peerBootstrap.connect(connectToSocket, localAddress).getChannel(); |
| 984 | return channel; |
| 985 | } |
Vidyashree Rama | 7bd3d78 | 2015-11-23 08:46:33 +0530 | [diff] [blame] | 986 | } |
| 987 | } |