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