Committed by
Gerrit Code Review
Implementation of Adj-In and Local RIB UT
Change-Id: I4cac90005f2d728006483b3c03ff0ff3c422f8ba
Showing
2 changed files
with
1103 additions
and
2 deletions
... | @@ -16,7 +16,10 @@ | ... | @@ -16,7 +16,10 @@ |
16 | package org.onosproject.bgp; | 16 | package org.onosproject.bgp; |
17 | 17 | ||
18 | import com.google.common.net.InetAddresses; | 18 | import com.google.common.net.InetAddresses; |
19 | + | ||
19 | import org.jboss.netty.bootstrap.ClientBootstrap; | 20 | import org.jboss.netty.bootstrap.ClientBootstrap; |
21 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
22 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
20 | import org.jboss.netty.channel.Channel; | 23 | import org.jboss.netty.channel.Channel; |
21 | import org.jboss.netty.channel.ChannelFactory; | 24 | import org.jboss.netty.channel.ChannelFactory; |
22 | import org.jboss.netty.channel.ChannelPipeline; | 25 | import org.jboss.netty.channel.ChannelPipeline; |
... | @@ -31,22 +34,43 @@ import static org.hamcrest.core.Is.is; | ... | @@ -31,22 +34,43 @@ import static org.hamcrest.core.Is.is; |
31 | import static org.junit.Assert.assertThat; | 34 | import static org.junit.Assert.assertThat; |
32 | 35 | ||
33 | import org.onlab.junit.TestUtils; | 36 | import org.onlab.junit.TestUtils; |
37 | +import org.onlab.junit.TestUtils.TestUtilsException; | ||
38 | +import org.onlab.packet.Ip4Address; | ||
39 | +import org.onlab.packet.IpAddress; | ||
34 | 40 | ||
35 | import java.net.InetAddress; | 41 | import java.net.InetAddress; |
36 | import java.net.InetSocketAddress; | 42 | import java.net.InetSocketAddress; |
37 | import java.net.SocketAddress; | 43 | import java.net.SocketAddress; |
38 | import java.util.LinkedList; | 44 | import java.util.LinkedList; |
45 | +import java.util.Map; | ||
39 | import java.util.concurrent.Executors; | 46 | import java.util.concurrent.Executors; |
40 | import java.util.concurrent.TimeUnit; | 47 | import java.util.concurrent.TimeUnit; |
41 | 48 | ||
42 | import org.slf4j.Logger; | 49 | import org.slf4j.Logger; |
43 | import org.slf4j.LoggerFactory; | 50 | import org.slf4j.LoggerFactory; |
44 | - | ||
45 | import org.onosproject.bgp.controller.BgpCfg; | 51 | import org.onosproject.bgp.controller.BgpCfg; |
52 | +import org.onosproject.bgp.controller.BgpId; | ||
53 | +import org.onosproject.bgp.controller.impl.AdjRibIn; | ||
46 | import org.onosproject.bgp.controller.impl.BgpControllerImpl; | 54 | import org.onosproject.bgp.controller.impl.BgpControllerImpl; |
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; | ||
47 | import org.onosproject.bgpio.types.BgpValueType; | 66 | import org.onosproject.bgpio.types.BgpValueType; |
48 | import org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv; | 67 | import org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv; |
68 | +import org.onosproject.bgpio.types.IPReachabilityInformationTlv; | ||
69 | +import org.onosproject.bgpio.types.IPv4AddressTlv; | ||
70 | +import org.onosproject.bgpio.types.IsIsNonPseudonode; | ||
49 | import org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv; | 71 | import org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv; |
72 | +import org.onosproject.bgpio.types.IsIsPseudonode; | ||
73 | +import org.onosproject.bgpio.types.RouteDistinguisher; | ||
50 | 74 | ||
51 | /** | 75 | /** |
52 | * Test case for BGPControllerImpl. | 76 | * Test case for BGPControllerImpl. |
... | @@ -71,6 +95,9 @@ public class BgpControllerImplTest { | ... | @@ -71,6 +95,9 @@ public class BgpControllerImplTest { |
71 | peer1 = new BgpPeerTest(version, asNumber, | 95 | peer1 = new BgpPeerTest(version, asNumber, |
72 | holdTime, bgpId, isLargeAsCapabilitySet, | 96 | holdTime, bgpId, isLargeAsCapabilitySet, |
73 | capabilityTlv); | 97 | capabilityTlv); |
98 | + peer2 = new BgpPeerTest(version, asNumber, | ||
99 | + holdTime, bgpId, isLargeAsCapabilitySet, | ||
100 | + capabilityTlv); | ||
74 | 101 | ||
75 | bgpControllerImpl = new BgpControllerImpl(); | 102 | bgpControllerImpl = new BgpControllerImpl(); |
76 | 103 | ||
... | @@ -93,6 +120,23 @@ public class BgpControllerImplTest { | ... | @@ -93,6 +120,23 @@ public class BgpControllerImplTest { |
93 | bgpControllerImpl.getConfig().setState(BgpCfg.State.IP_AS_CONFIGURED); | 120 | bgpControllerImpl.getConfig().setState(BgpCfg.State.IP_AS_CONFIGURED); |
94 | 121 | ||
95 | bgpControllerImpl.getConfig().addPeer("127.0.0.1", 200); | 122 | bgpControllerImpl.getConfig().addPeer("127.0.0.1", 200); |
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); | ||
96 | } | 140 | } |
97 | 141 | ||
98 | @After | 142 | @After |
... | @@ -104,7 +148,7 @@ public class BgpControllerImplTest { | ... | @@ -104,7 +148,7 @@ public class BgpControllerImplTest { |
104 | private BgpControllerImpl bgpControllerImpl; | 148 | private BgpControllerImpl bgpControllerImpl; |
105 | 149 | ||
106 | BgpPeerTest peer1; | 150 | BgpPeerTest peer1; |
107 | - | 151 | + BgpPeerTest peer2; |
108 | // The socket that the remote peers should connect to | 152 | // The socket that the remote peers should connect to |
109 | private InetSocketAddress connectToSocket; | 153 | private InetSocketAddress connectToSocket; |
110 | 154 | ||
... | @@ -254,6 +298,625 @@ public class BgpControllerImplTest { | ... | @@ -254,6 +298,625 @@ public class BgpControllerImplTest { |
254 | } | 298 | } |
255 | 299 | ||
256 | /** | 300 | /** |
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 | + /** | ||
257 | * A class to capture the state for a BGP peer. | 920 | * A class to capture the state for a BGP peer. |
258 | */ | 921 | */ |
259 | private final class BgpPeerTest { | 922 | private final class BgpPeerTest { |
... | @@ -296,5 +959,29 @@ public class BgpControllerImplTest { | ... | @@ -296,5 +959,29 @@ public class BgpControllerImplTest { |
296 | peerBootstrap.setPipelineFactory(pipelineFactory); | 959 | peerBootstrap.setPipelineFactory(pipelineFactory); |
297 | peerBootstrap.connect(connectToSocket); | 960 | peerBootstrap.connect(connectToSocket); |
298 | } | 961 | } |
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 | + } | ||
299 | } | 986 | } |
300 | } | 987 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.bgp; | 16 | package org.onosproject.bgp; |
17 | 17 | ||
18 | +import java.net.InetSocketAddress; | ||
18 | import java.util.LinkedList; | 19 | import java.util.LinkedList; |
19 | import java.util.concurrent.TimeUnit; | 20 | import java.util.concurrent.TimeUnit; |
20 | 21 | ||
... | @@ -27,8 +28,11 @@ import org.onosproject.bgpio.protocol.ver4.BgpKeepaliveMsgVer4; | ... | @@ -27,8 +28,11 @@ import org.onosproject.bgpio.protocol.ver4.BgpKeepaliveMsgVer4; |
27 | import org.onosproject.bgpio.protocol.ver4.BgpOpenMsgVer4; | 28 | import org.onosproject.bgpio.protocol.ver4.BgpOpenMsgVer4; |
28 | import org.onosproject.bgpio.types.BgpHeader; | 29 | import org.onosproject.bgpio.types.BgpHeader; |
29 | import org.onosproject.bgpio.types.BgpValueType; | 30 | import org.onosproject.bgpio.types.BgpValueType; |
31 | +import org.slf4j.Logger; | ||
32 | +import org.slf4j.LoggerFactory; | ||
30 | 33 | ||
31 | public class BgpPeerChannelHandlerTest extends SimpleChannelHandler { | 34 | public class BgpPeerChannelHandlerTest extends SimpleChannelHandler { |
35 | + protected static final Logger log = LoggerFactory.getLogger(BgpPeerChannelHandlerTest.class); | ||
32 | public static final int OPEN_MSG_MINIMUM_LENGTH = 29; | 36 | public static final int OPEN_MSG_MINIMUM_LENGTH = 29; |
33 | public static final byte[] MARKER = new byte[] {(byte) 0xff, (byte) 0xff, | 37 | public static final byte[] MARKER = new byte[] {(byte) 0xff, (byte) 0xff, |
34 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | 38 | (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, |
... | @@ -76,6 +80,306 @@ public class BgpPeerChannelHandlerTest extends SimpleChannelHandler { | ... | @@ -76,6 +80,306 @@ public class BgpPeerChannelHandlerTest extends SimpleChannelHandler { |
76 | savedCtx.getChannel().close(); | 80 | savedCtx.getChannel().close(); |
77 | } | 81 | } |
78 | 82 | ||
83 | + /** | ||
84 | + * Select update message buffer with VPN. | ||
85 | + * | ||
86 | + * @param select number to select update message buffer | ||
87 | + * @return packet dump in byte array | ||
88 | + */ | ||
89 | + byte[] selectUpdateMessageVpn(int select) { | ||
90 | + switch (select) { | ||
91 | + case 5: | ||
92 | + /** | ||
93 | + * Node NLRI with VPN - MpReach. | ||
94 | + */ | ||
95 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
96 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
97 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x5E, 0x02, 0x00, 0x00, //withdrawn len | ||
98 | + 0x00, 0x47, //path attribute len | ||
99 | + 0x04, 0x01, 0x01, 0x02, //origin | ||
100 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
101 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
102 | + (byte) 0x80, 0x0e, 0x32, 0x40, 0x04, (byte) 0x80, //mpreach with safi = 80 vpn | ||
103 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
104 | + 0x00, //reserved | ||
105 | + 0x00, 0x01, 0x00, 0x25, //type ND LEN | ||
106 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, | ||
107 | + 0x02, | ||
108 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
109 | + 0x01, 0x00, 0x00, 0x10, | ||
110 | + 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, | ||
111 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02}; //node nlri | ||
112 | + return updateMsg; | ||
113 | + case 6: | ||
114 | + /** | ||
115 | + * Node NLRI MpReach and MpUnReach different with same VPN. | ||
116 | + */ | ||
117 | + updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
118 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
119 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x8D, 0x02, 0x00, 0x00, //withdrawn len | ||
120 | + 0x00, 0x76, //path attribute len | ||
121 | + 0x04, 0x01, 0x01, 0x02, //origin | ||
122 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
123 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
124 | + (byte) 0x80, 0x0e, 0x32, 0x40, 0x04, (byte) 0x80, //mpreach with safi = 80 vpn | ||
125 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
126 | + 0x00, //reserved | ||
127 | + 0x00, 0x01, 0x00, 0x25, //type ND LEN | ||
128 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, | ||
129 | + 0x02, | ||
130 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
131 | + 0x01, 0x00, 0x00, 0x10, | ||
132 | + 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x02, (byte) 0xae, | ||
133 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //node nlri | ||
134 | + (byte) 0x80, 0x0f, 0x2C, 0x40, 0x04, (byte) 0x80, //mpUnreach with safi = 80 VPN | ||
135 | + 0x00, 0x01, 0x00, 0x25, //type n len | ||
136 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, | ||
137 | + 0x02, | ||
138 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
139 | + 0x01, 0x00, 0x00, 0x10, | ||
140 | + 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, (byte) 0xae, //AutonomousSystemTlv | ||
141 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02}; //BGPLSIdentifierTlv | ||
142 | + return updateMsg; | ||
143 | + case 7: | ||
144 | + /** | ||
145 | + * Node NLRI with same MpReach and MpUnReach with VPN. | ||
146 | + */ | ||
147 | + updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
148 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
149 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x8D, 0x02, 0x00, 0x00, //withdrawn len | ||
150 | + 0x00, 0x76, //path attribute len | ||
151 | + 0x04, 0x01, 0x01, 0x02, //origin | ||
152 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
153 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
154 | + (byte) 0x80, 0x0e, 0x32, 0x40, 0x04, (byte) 0x80, //mpreach with safi = 80 vpn | ||
155 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
156 | + 0x00, //reserved | ||
157 | + 0x00, 0x01, 0x00, 0x25, //type ND LEN | ||
158 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, | ||
159 | + 0x02, | ||
160 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
161 | + 0x01, 0x00, 0x00, 0x10, | ||
162 | + 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, | ||
163 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //node nlri | ||
164 | + (byte) 0x80, 0x0f, 0x2C, 0x40, 0x04, (byte) 0x80, //mpUnreach with safi = 80 VPN | ||
165 | + 0x00, 0x01, 0x00, 0x25, //type n len | ||
166 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, | ||
167 | + 0x02, | ||
168 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
169 | + 0x01, 0x00, 0x00, 0x10, | ||
170 | + 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, //AutonomousSystemTlv | ||
171 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02}; //BGPLSIdentifierTlv | ||
172 | + return updateMsg; | ||
173 | + case 17: | ||
174 | + /** | ||
175 | + * Node NLRI with VPN - MpReach. | ||
176 | + */ | ||
177 | + updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
178 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
179 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x5E, 0x02, 0x00, 0x00, //withdrawn len | ||
180 | + 0x00, 0x47, //path attribute len | ||
181 | + 0x04, 0x01, 0x01, 0x02, //origin | ||
182 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
183 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
184 | + (byte) 0x80, 0x0e, 0x32, 0x40, 0x04, (byte) 0x80, //mpreach with safi = 80 vpn | ||
185 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
186 | + 0x00, //reserved | ||
187 | + 0x00, 0x01, 0x00, 0x25, //type ND LEN | ||
188 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, | ||
189 | + 0x02, | ||
190 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
191 | + 0x01, 0x00, 0x00, 0x10, | ||
192 | + 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, | ||
193 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02}; //node nlri | ||
194 | + return updateMsg; | ||
195 | + default: return null; | ||
196 | + } | ||
197 | + } | ||
198 | + | ||
199 | + /** | ||
200 | + * Select update message buffer without VPN. | ||
201 | + * | ||
202 | + * @param select number to select update message buffer | ||
203 | + * @return packet dump in byte array | ||
204 | + */ | ||
205 | + byte[] selectUpdateMsg(int select) { | ||
206 | + switch (select) { | ||
207 | + case 1: | ||
208 | + /** | ||
209 | + * Node NLRI - MpReach. | ||
210 | + */ | ||
211 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
212 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
213 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x56, 0x02, 0x00, 0x00, //withdrawn len | ||
214 | + 0x00, 0x3F, 0x04, 0x01, 0x01, 0x02, //origin | ||
215 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
216 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
217 | + (byte) 0x80, 0x0e, 0x2A, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
218 | + 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x1D, 0x02, | ||
219 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, | ||
220 | + 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, | ||
221 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02}; //node nlri | ||
222 | + return updateMsg; | ||
223 | + case 2: | ||
224 | + /** | ||
225 | + * Node NLRI with same MpReach and MpUnReach. | ||
226 | + */ | ||
227 | + updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
228 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
229 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x7D, 0x02, 0x00, 0x00, //withdrawn len | ||
230 | + 0x00, 0x66, 0x04, 0x01, 0x01, 0x02, 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, | ||
231 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
232 | + (byte) 0x80, 0x0e, 0x2A, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
233 | + 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x1D, //type n len | ||
234 | + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
235 | + 0x01, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, | ||
236 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv | ||
237 | + (byte) 0x80, 0x0f, 0x24, 0x40, 0x04, 0x47, //mpUnreach with safi = 71 | ||
238 | + 0x00, 0x01, 0x00, 0x1D, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
239 | + 0x01, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, | ||
240 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv | ||
241 | + }; | ||
242 | + return updateMsg; | ||
243 | + case 3: | ||
244 | + /** | ||
245 | + * Link NLRI - MpReach. | ||
246 | + */ | ||
247 | + updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
248 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
249 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x8B, 0x02, 0x00, 0x04, | ||
250 | + 0x18, 0x0a, 0x01, 0x01, 0x00, 0x70, //path attribute len | ||
251 | + 0x04, 0x01, 0x01, 0x00, 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
252 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10, //med | ||
253 | + (byte) 0x80, 0x0e, 0x5B, 0x40, 0x04, 0x47, //mpreach safi 71 | ||
254 | + 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x4E, 0x02, | ||
255 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, //local node | ||
256 | + 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, | ||
257 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, | ||
258 | + 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x03, | ||
259 | + 0x01, 0x01, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, | ||
260 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, | ||
261 | + 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri | ||
262 | + 0x01, 0x03, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02 | ||
263 | + }; | ||
264 | + return updateMsg; | ||
265 | + case 4: | ||
266 | + /** | ||
267 | + * Prefix NLRI - MpReach. | ||
268 | + */ | ||
269 | + updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
270 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
271 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0xd6, 0x02, 0x00, 0x04, | ||
272 | + 0x18, 0x0a, 0x01, 0x01, 0x00, (byte) 0xbb, //path attribute len | ||
273 | + 0x04, 0x01, 0x01, 0x00, 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
274 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x12, //med | ||
275 | + (byte) 0x90, 0x0e, 0x00, (byte) 0xa5, 0x40, 0x04, 0x47, //mpreach | ||
276 | + 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x30, | ||
277 | + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, //local node | ||
278 | + 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, | ||
279 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x21, 0x68, 0x07, | ||
280 | + 0x70, 0x01, 0x01, 0x09, 0x00, 0x05, 0x20, (byte) 0xc0, (byte) 0xa8, 0x4d, 0x01, //prefix des | ||
281 | + 0x00, 0x03, 0x00, 0x30, 0x02, | ||
282 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, | ||
283 | + 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, | ||
284 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, | ||
285 | + 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, | ||
286 | + 0x01, 0x09, 0x00, 0x05, 0x20, 0x15, 0x15, 0x15, 0x15, 0x00, 0x03, 0x00, 0x30, | ||
287 | + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
288 | + 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, | ||
289 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, | ||
290 | + 0x02, 0x03, 0x00, 0x06, 0x02, 0x20, 0x22, 0x02, 0x20, 0x22, | ||
291 | + 0x01, 0x09, 0x00, 0x05, 0x20, 0x16, 0x16, 0x16, 0x16}; // prefix nlri | ||
292 | + return updateMsg; | ||
293 | + case 8: | ||
294 | + /** | ||
295 | + * Node NLRI with different MpReach and MpUnReach with IsIsPseudonode. | ||
296 | + */ | ||
297 | + updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
298 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
299 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, | ||
300 | + (byte) 0x91, 0x02, 0x00, 0x00, 0x00, 0x7A, //path attribute len | ||
301 | + 0x04, 0x01, 0x01, 0x02, 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, | ||
302 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
303 | + (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
304 | + 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, | ||
305 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
306 | + 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, | ||
307 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
308 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58, | ||
309 | + (byte) 0x80, 0x0f, 0x2E, 0x40, 0x04, 0x47, 0x00, 0x01, 0x00, 0x27, //mpUnreach | ||
310 | + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
311 | + 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, | ||
312 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv | ||
313 | + 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x99, 0x01, (byte) 0x99, 0x58}; | ||
314 | + return updateMsg; | ||
315 | + case 9: | ||
316 | + /** | ||
317 | + * Node NLRI with same MpReach and MpUnReach. | ||
318 | + */ | ||
319 | + updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
320 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
321 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x7D, 0x02, 0x00, 0x00, //withdrawn len | ||
322 | + 0x00, 0x66, 0x04, 0x01, 0x01, 0x02, //origin | ||
323 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
324 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
325 | + (byte) 0x80, 0x0e, 0x2A, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
326 | + 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x1D, //type n len | ||
327 | + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
328 | + 0x01, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, | ||
329 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv | ||
330 | + (byte) 0x80, 0x0f, 0x24, 0x40, 0x04, 0x47, //mpUnreach with safi = 71 | ||
331 | + 0x00, 0x01, 0x00, 0x1D, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
332 | + 0x01, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, | ||
333 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv | ||
334 | + }; | ||
335 | + return updateMsg; | ||
336 | + case 10: | ||
337 | + /** | ||
338 | + * Node NLRI with different MpReach and MpUnReach. | ||
339 | + */ | ||
340 | + updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
341 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
342 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x7D, 0x02, 0x00, 0x00, //withdrawn len | ||
343 | + 0x00, 0x66, 0x04, 0x01, 0x01, 0x02, //origin | ||
344 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
345 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
346 | + (byte) 0x80, 0x0e, 0x2A, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
347 | + 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, //reserved | ||
348 | + 0x00, 0x01, 0x00, 0x1D, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
349 | + 0x01, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, | ||
350 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv | ||
351 | + (byte) 0x80, 0x0f, 0x24, 0x40, 0x04, 0x47, //mpUnreach with safi = 71 | ||
352 | + 0x00, 0x01, 0x00, 0x1D, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
353 | + 0x01, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, | ||
354 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv | ||
355 | + }; | ||
356 | + return updateMsg; | ||
357 | + case 12: | ||
358 | + /** | ||
359 | + * Node NLRI with same MpReach and MpUnReach with IsIsPseudonode. | ||
360 | + */ | ||
361 | + updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
362 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
363 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x91, 0x02, 0x00, 0x00, //withdrawn len | ||
364 | + 0x00, 0x7A, 0x04, 0x01, 0x01, 0x02, //origin | ||
365 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
366 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
367 | + (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
368 | + 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x27, //type n len | ||
369 | + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
370 | + 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, | ||
371 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv | ||
372 | + 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x99, 0x01, (byte) 0x99, 0x58, | ||
373 | + (byte) 0x80, 0x0f, 0x2E, 0x40, 0x04, 0x47, //mpUnreach with safi = 71 | ||
374 | + 0x00, 0x01, 0x00, 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
375 | + 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x09, (byte) 0xae, //AutonomousSystemTlv | ||
376 | + 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, //BGPLSIdentifierTlv | ||
377 | + 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x99, 0x01, (byte) 0x99, 0x58}; | ||
378 | + return updateMsg; | ||
379 | + default: return null; | ||
380 | + } | ||
381 | + } | ||
382 | + | ||
79 | @Override | 383 | @Override |
80 | public void channelConnected(ChannelHandlerContext ctx, | 384 | public void channelConnected(ChannelHandlerContext ctx, |
81 | ChannelStateEvent channelEvent) throws InterruptedException { | 385 | ChannelStateEvent channelEvent) throws InterruptedException { |
... | @@ -97,6 +401,116 @@ public class BgpPeerChannelHandlerTest extends SimpleChannelHandler { | ... | @@ -97,6 +401,116 @@ public class BgpPeerChannelHandlerTest extends SimpleChannelHandler { |
97 | ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer(); | 401 | ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer(); |
98 | keepaliveMsg.writeTo(buffer1); | 402 | keepaliveMsg.writeTo(buffer1); |
99 | ctx.getChannel().write(buffer1); | 403 | ctx.getChannel().write(buffer1); |
404 | + | ||
405 | + if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
406 | + new InetSocketAddress("127.0.0.1", 0).getAddress())) { | ||
407 | + return; | ||
408 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
409 | + new InetSocketAddress("127.0.0.9", 0).getAddress())) { | ||
410 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
411 | + bufferUp.writeBytes(selectUpdateMsg(1)); | ||
412 | + ctx.getChannel().write(bufferUp); | ||
413 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
414 | + new InetSocketAddress("127.0.0.33", 0).getAddress())) { | ||
415 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
416 | + bufferUp.writeBytes(selectUpdateMsg(2)); | ||
417 | + ctx.getChannel().write(bufferUp); | ||
418 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
419 | + new InetSocketAddress("127.0.0.10", 0).getAddress())) { | ||
420 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
421 | + bufferUp.writeBytes(selectUpdateMsg(3)); | ||
422 | + ctx.getChannel().write(bufferUp); | ||
423 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
424 | + new InetSocketAddress("127.0.0.20", 0).getAddress())) { | ||
425 | + | ||
426 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
427 | + bufferUp.writeBytes(selectUpdateMsg(4)); | ||
428 | + ctx.getChannel().write(bufferUp); | ||
429 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
430 | + new InetSocketAddress("127.0.0.30", 0).getAddress())) { | ||
431 | + | ||
432 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
433 | + bufferUp.writeBytes(selectUpdateMessageVpn(5)); | ||
434 | + ctx.getChannel().write(bufferUp); | ||
435 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
436 | + new InetSocketAddress("127.0.0.40", 0).getAddress())) { | ||
437 | + | ||
438 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
439 | + bufferUp.writeBytes(selectUpdateMessageVpn(6)); | ||
440 | + ctx.getChannel().write(bufferUp); | ||
441 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
442 | + new InetSocketAddress("127.0.0.50", 0).getAddress())) { | ||
443 | + | ||
444 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
445 | + bufferUp.writeBytes(selectUpdateMessageVpn(7)); | ||
446 | + ctx.getChannel().write(bufferUp); | ||
447 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
448 | + new InetSocketAddress("127.0.0.60", 0).getAddress())) { | ||
449 | + | ||
450 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
451 | + bufferUp.writeBytes(selectUpdateMsg(8)); | ||
452 | + ctx.getChannel().write(bufferUp); | ||
453 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
454 | + new InetSocketAddress("127.0.0.70", 0).getAddress())) { | ||
455 | + | ||
456 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
457 | + bufferUp.writeBytes(selectUpdateMsg(9)); | ||
458 | + ctx.getChannel().write(bufferUp); | ||
459 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
460 | + new InetSocketAddress("127.0.0.80", 0).getAddress())) { | ||
461 | + | ||
462 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
463 | + bufferUp.writeBytes(selectUpdateMsg(10)); | ||
464 | + ctx.getChannel().write(bufferUp); | ||
465 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
466 | + new InetSocketAddress("127.0.0.90", 0).getAddress())) { | ||
467 | + | ||
468 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
469 | + bufferUp.writeBytes(selectUpdateMsg(8)); | ||
470 | + ctx.getChannel().write(bufferUp); | ||
471 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
472 | + new InetSocketAddress("127.0.0.92", 0).getAddress())) { | ||
473 | + | ||
474 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
475 | + bufferUp.writeBytes(selectUpdateMsg(12)); | ||
476 | + ctx.getChannel().write(bufferUp); | ||
477 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
478 | + new InetSocketAddress("127.0.0.91", 0).getAddress())) { | ||
479 | + | ||
480 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
481 | + bufferUp.writeBytes(selectUpdateMsg(1)); | ||
482 | + ctx.getChannel().write(bufferUp); | ||
483 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
484 | + new InetSocketAddress("127.0.0.9", 0).getAddress())) { | ||
485 | + | ||
486 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
487 | + bufferUp.writeBytes(selectUpdateMsg(1)); | ||
488 | + ctx.getChannel().write(bufferUp); | ||
489 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
490 | + new InetSocketAddress("127.0.0.99", 0).getAddress())) { | ||
491 | + | ||
492 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
493 | + bufferUp.writeBytes(selectUpdateMsg(1)); | ||
494 | + ctx.getChannel().write(bufferUp); | ||
495 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
496 | + new InetSocketAddress("127.0.0.94", 0).getAddress())) { | ||
497 | + | ||
498 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
499 | + bufferUp.writeBytes(selectUpdateMsg(1)); | ||
500 | + ctx.getChannel().write(bufferUp); | ||
501 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
502 | + new InetSocketAddress("127.0.0.35", 0).getAddress())) { | ||
503 | + | ||
504 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
505 | + bufferUp.writeBytes(selectUpdateMessageVpn(17)); | ||
506 | + ctx.getChannel().write(bufferUp); | ||
507 | + } else if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getAddress().equals( | ||
508 | + new InetSocketAddress("127.0.0.95", 0).getAddress())) { | ||
509 | + | ||
510 | + ChannelBuffer bufferUp = ChannelBuffers.dynamicBuffer(); | ||
511 | + bufferUp.writeBytes(selectUpdateMsg(1)); | ||
512 | + ctx.getChannel().write(bufferUp); | ||
513 | + } | ||
100 | } | 514 | } |
101 | 515 | ||
102 | @Override | 516 | @Override | ... | ... |
-
Please register or login to post a comment