Shashikanth VH
Committed by Gerrit Code Review

BGP system test issue fix

Change-Id: I36064e33146444531cdef6deab0d55b89efae8a7
...@@ -376,24 +376,10 @@ class BgpChannelHandler extends IdleStateAwareChannelHandler { ...@@ -376,24 +376,10 @@ class BgpChannelHandler extends IdleStateAwareChannelHandler {
376 throw new IOException("Invalid peer connection."); 376 throw new IOException("Invalid peer connection.");
377 } 377 }
378 378
379 - // Connection should establish only if local ip and Autonomous system number is configured.
380 - if (bgpconfig.getState() != BgpCfg.State.IP_AS_CONFIGURED) {
381 - sendNotification(BgpErrorType.CEASE, BgpErrorType.CONNECTION_REJECTED, null);
382 - channel.close();
383 - log.info("BGP local AS and router ID not configured");
384 - return;
385 - }
386 379
387 inetAddress = (InetSocketAddress) address; 380 inetAddress = (InetSocketAddress) address;
388 peerAddr = IpAddress.valueOf(inetAddress.getAddress()).toString(); 381 peerAddr = IpAddress.valueOf(inetAddress.getAddress()).toString();
389 382
390 - // if peer is not configured disconnect session
391 - if (!bgpconfig.isPeerConfigured(peerAddr)) {
392 - log.debug("Peer is not configured {}", peerAddr);
393 - sendNotification(BgpErrorType.CEASE, BgpErrorType.CONNECTION_REJECTED, null);
394 - channel.close();
395 - return;
396 - }
397 383
398 // if connection is already established close channel 384 // if connection is already established close channel
399 if (peerManager.isPeerConnected(BgpId.bgpId(IpAddress.valueOf(peerAddr)))) { 385 if (peerManager.isPeerConnected(BgpId.bgpId(IpAddress.valueOf(peerAddr)))) {
...@@ -662,8 +648,10 @@ class BgpChannelHandler extends IdleStateAwareChannelHandler { ...@@ -662,8 +648,10 @@ class BgpChannelHandler extends IdleStateAwareChannelHandler {
662 private void sendHandshakeOpenMessage() throws IOException, BgpParseException { 648 private void sendHandshakeOpenMessage() throws IOException, BgpParseException {
663 int bgpId; 649 int bgpId;
664 650
665 - bgpId = Ip4Address.valueOf(bgpconfig.getRouterId()).toInt(); 651 + InetSocketAddress localAddress = (InetSocketAddress) channel.getLocalAddress();
666 - BgpMessage msg = factory4.openMessageBuilder().setAsNumber((short) bgpconfig.getAsNumber()) 652 +
653 + bgpId = Ip4Address.valueOf(IpAddress.valueOf(localAddress.getAddress()).toString()).toInt();
654 + BgpMessage msg = factory4.openMessageBuilder().setAsNumber((short) peerAsNum)
667 .setHoldTime(bgpconfig.getHoldTime()).setBgpId(bgpId).setLsCapabilityTlv(bgpconfig.getLsCapability()) 655 .setHoldTime(bgpconfig.getHoldTime()).setBgpId(bgpId).setLsCapabilityTlv(bgpconfig.getLsCapability())
668 .setLargeAsCapabilityTlv(bgpconfig.getLargeASCapability()).build(); 656 .setLargeAsCapabilityTlv(bgpconfig.getLargeASCapability()).build();
669 log.debug("Sending open message to {}", channel.getRemoteAddress()); 657 log.debug("Sending open message to {}", channel.getRemoteAddress());
...@@ -734,11 +722,6 @@ class BgpChannelHandler extends IdleStateAwareChannelHandler { ...@@ -734,11 +722,6 @@ class BgpChannelHandler extends IdleStateAwareChannelHandler {
734 throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_BGP_IDENTIFIER, null); 722 throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_BGP_IDENTIFIER, null);
735 } 723 }
736 724
737 - // Validate AS number
738 - result = asNumberValidation(h, openMsg);
739 - if (!result) {
740 - throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_PEER_AS, null);
741 - }
742 725
743 // Validate hold timer 726 // Validate hold timer
744 if ((openMsg.getHoldTime() != 0) && (openMsg.getHoldTime() < BGP_MIN_HOLDTIME)) { 727 if ((openMsg.getHoldTime() != 0) && (openMsg.getHoldTime() < BGP_MIN_HOLDTIME)) {
......
...@@ -67,6 +67,7 @@ public class BgpConfig implements BgpCfg { ...@@ -67,6 +67,7 @@ public class BgpConfig implements BgpCfg {
67 this.holdTime = DEFAULT_HOLD_TIMER; 67 this.holdTime = DEFAULT_HOLD_TIMER;
68 this.maxConnRetryTime = DEFAULT_CONN_RETRY_TIME; 68 this.maxConnRetryTime = DEFAULT_CONN_RETRY_TIME;
69 this.maxConnRetryCount = DEFAULT_CONN_RETRY_COUNT; 69 this.maxConnRetryCount = DEFAULT_CONN_RETRY_COUNT;
70 + this.lsCapability = true;
70 } 71 }
71 72
72 @Override 73 @Override
......
...@@ -110,9 +110,15 @@ public class BgpControllerImplTest { ...@@ -110,9 +110,15 @@ public class BgpControllerImplTest {
110 110
111 @Test 111 @Test
112 public void bgpOpenMessageTest1() throws InterruptedException { 112 public void bgpOpenMessageTest1() throws InterruptedException {
113 + short afi = 16388;
114 + byte res = 0;
115 + byte safi = 71;
113 peer1.peerChannelHandler.asNumber = 200; 116 peer1.peerChannelHandler.asNumber = 200;
114 peer1.peerChannelHandler.version = 4; 117 peer1.peerChannelHandler.version = 4;
115 peer1.peerChannelHandler.holdTime = 120; 118 peer1.peerChannelHandler.holdTime = 120;
119 + bgpControllerImpl.getConfig().setLsCapability(true);
120 + BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
121 + peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
116 peer1.connect(connectToSocket); 122 peer1.connect(connectToSocket);
117 boolean result; 123 boolean result;
118 result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await( 124 result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await(
...@@ -128,16 +134,26 @@ public class BgpControllerImplTest { ...@@ -128,16 +134,26 @@ public class BgpControllerImplTest {
128 @Test 134 @Test
129 public void bgpOpenMessageTest2() throws InterruptedException { 135 public void bgpOpenMessageTest2() throws InterruptedException {
130 // Open message with as number which is not configured at peer 136 // Open message with as number which is not configured at peer
137 + short afi = 16388;
138 + byte res = 0;
139 + byte safi = 71;
131 peer1.peerChannelHandler.asNumber = 500; 140 peer1.peerChannelHandler.asNumber = 500;
132 peer1.peerChannelHandler.version = 4; 141 peer1.peerChannelHandler.version = 4;
133 peer1.peerChannelHandler.holdTime = 120; 142 peer1.peerChannelHandler.holdTime = 120;
143 + bgpControllerImpl.getConfig().setLsCapability(true);
144 + BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
145 + peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
134 peer1.connect(connectToSocket); 146 peer1.connect(connectToSocket);
135 147
136 boolean result; 148 boolean result;
149 + result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await(MESSAGE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
150 + assertThat(result, is(true));
151 + result = peer1.peerFrameDecoder.receivedKeepaliveMessageLatch.await(MESSAGE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
152 + assertThat(result, is(true));
137 result = peer1.peerFrameDecoder.receivedNotificationMessageLatch.await( 153 result = peer1.peerFrameDecoder.receivedNotificationMessageLatch.await(
138 MESSAGE_TIMEOUT_MS, 154 MESSAGE_TIMEOUT_MS,
139 TimeUnit.MILLISECONDS); 155 TimeUnit.MILLISECONDS);
140 - assertThat(result, is(true)); 156 + assertThat(result, is(false));
141 } 157 }
142 158
143 @Test 159 @Test
...@@ -201,6 +217,9 @@ public class BgpControllerImplTest { ...@@ -201,6 +217,9 @@ public class BgpControllerImplTest {
201 @Test 217 @Test
202 public void bgpOpenMessageTest6() throws InterruptedException { 218 public void bgpOpenMessageTest6() throws InterruptedException {
203 // Open message with as4 capability 219 // Open message with as4 capability
220 + short afi = 16388;
221 + byte res = 0;
222 + byte safi = 71;
204 peer1.peerChannelHandler.asNumber = 200; 223 peer1.peerChannelHandler.asNumber = 200;
205 peer1.peerChannelHandler.version = 4; 224 peer1.peerChannelHandler.version = 4;
206 peer1.peerChannelHandler.holdTime = 120; 225 peer1.peerChannelHandler.holdTime = 120;
...@@ -208,6 +227,9 @@ public class BgpControllerImplTest { ...@@ -208,6 +227,9 @@ public class BgpControllerImplTest {
208 bgpControllerImpl.getConfig().setLargeASCapability(true); 227 bgpControllerImpl.getConfig().setLargeASCapability(true);
209 BgpValueType tempTlv = new FourOctetAsNumCapabilityTlv(200); 228 BgpValueType tempTlv = new FourOctetAsNumCapabilityTlv(200);
210 peer1.peerChannelHandler.capabilityTlv.add(tempTlv); 229 peer1.peerChannelHandler.capabilityTlv.add(tempTlv);
230 + bgpControllerImpl.getConfig().setLsCapability(true);
231 + BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
232 + peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
211 peer1.connect(connectToSocket); 233 peer1.connect(connectToSocket);
212 234
213 boolean result; 235 boolean result;
......