Pingping Lin
Committed by Gerrit Code Review

[ONOS-2939] Let sdn-ip also can parse bird's bgp OPEN message

RFC5492 allows multiple Capability triples per Optional Parameter.
But our code only support parsing 1 Capability triple per Optional Parameter.
It works with Quagga, but failed parsing bird OPEN message.
This patch adds support for multiple Capability triples per Optional Parameter.

Change-Id: Iae6295d608e44676a44ef6a0ae1868d8dcd7648d
......@@ -309,16 +309,25 @@ final class BgpOpen {
case BgpConstants.Open.Capabilities.TYPE:
// Optional Parameter Type: Capabilities
if (paramLen < BgpConstants.Open.Capabilities.MIN_LENGTH) {
// ERROR: Malformed Capability
String errorMsg = "Malformed Capability Type " + paramType;
// ERROR: Malformed Param Type
String errorMsg = "Malformed Capabilities Optional "
+ "Parameter Type " + paramType;
throw new BgpMessage.BgpParseException(errorMsg);
}
int paramEnd = message.readerIndex() + paramLen;
// Parse Capabilities
while (message.readerIndex() < paramEnd) {
if (paramEnd - message.readerIndex() <
BgpConstants.Open.Capabilities.MIN_LENGTH) {
String errorMsg = "Malformed Capabilities";
throw new BgpMessage.BgpParseException(errorMsg);
}
int capabEnd = message.readerIndex() + paramLen;
int capabCode = message.readUnsignedByte();
int capabLen = message.readUnsignedByte();
if (message.readerIndex() + capabLen > capabEnd) {
if (message.readerIndex() + capabLen > paramEnd) {
// ERROR: Malformed Capability
String errorMsg = "Malformed Capability Type " + paramType;
String errorMsg = "Malformed Capability instance with "
+ "code " + capabCode;
throw new BgpMessage.BgpParseException(errorMsg);
}
......@@ -395,8 +404,9 @@ final class BgpOpen {
break;
}
break;
}
break;
default:
// Unknown Parameter Type: ignore it
log.debug("BGP RX OPEN Parameter Type = {} Length = {}",
......