ONOS-734 Add unit tests for 4 Octets AS numbers in SDN-IP
* Fix a bug in the storing, handling and verification of the AS numbers
with 4 octet AS capability is used.
* Add an unit test to test the decoding and parsing of supported
BGP Capabilities: Multiprotocol Extensions AFI/SAFI, and 4 octet AS.
* Minor refactoring of the BGP unit test framework.
Change-Id: I474b356bc00369c307ac0c5c214b065c1cc0c52c
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/bgp/TestBgpPeerChannelHandler.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/bgp/TestBgpPeerChannelHandler.java
index 05fb5b4..979a1ed 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/bgp/TestBgpPeerChannelHandler.java
+++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/bgp/TestBgpPeerChannelHandler.java
@@ -30,8 +30,10 @@
*/
class TestBgpPeerChannelHandler extends SimpleChannelHandler {
static final long PEER_AS = 65001;
+ static final long PEER_AS4 = 0x12345678;
static final int PEER_HOLDTIME = 120; // 120 seconds
- final Ip4Address bgpId; // The BGP ID
+
+ final BgpSessionInfo localInfo = new BgpSessionInfo();
ChannelHandlerContext savedCtx;
/**
@@ -40,7 +42,10 @@
* @param bgpId the BGP ID to use
*/
TestBgpPeerChannelHandler(Ip4Address bgpId) {
- this.bgpId = bgpId;
+ this.localInfo.setBgpVersion(BgpConstants.BGP_VERSION);
+ this.localInfo.setBgpId(bgpId);
+ this.localInfo.setAsNumber(PEER_AS);
+ this.localInfo.setHoldtime(PEER_HOLDTIME);
}
/**
@@ -55,7 +60,7 @@
ChannelStateEvent channelEvent) {
this.savedCtx = ctx;
// Prepare and transmit BGP OPEN message
- ChannelBuffer message = prepareBgpOpen();
+ ChannelBuffer message = BgpOpen.prepareBgpOpen(localInfo);
ctx.getChannel().write(message);
// Prepare and transmit BGP KEEPALIVE message
@@ -70,23 +75,6 @@
}
/**
- * Prepares BGP OPEN message.
- *
- * @return the message to transmit (BGP header included)
- */
- ChannelBuffer prepareBgpOpen() {
- ChannelBuffer message =
- ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH);
- message.writeByte(BgpConstants.BGP_VERSION);
- message.writeShort((int) PEER_AS);
- message.writeShort(PEER_HOLDTIME);
- message.writeInt(bgpId.toInt());
- message.writeByte(0); // No Optional Parameters
- return BgpMessage.prepareBgpMessage(BgpConstants.BGP_TYPE_OPEN,
- message);
- }
-
- /**
* Prepares BGP UPDATE message.
*
* @param nextHopRouter the next-hop router address for the routes to add