Pavlin Radoslavov
Committed by Gerrit Code Review

Fix the decoding opf BGP AGGREGATOR Attribute when 4 octets AS is enabled

This fixes ONOS-1318

Change-Id: I5681b574c46626e4092439e28d28831499e9562b
......@@ -157,6 +157,12 @@ public final class BgpConstants {
private Update() {
}
/** BGP AS length. */
public static final int AS_LENGTH = 2;
/** BGP 4 Octet AS length (RFC 6793). */
public static final int AS_4OCTET_LENGTH = 4;
/**
* BGP UPDATE: ORIGIN related constants.
*/
......@@ -227,12 +233,6 @@ public final class BgpConstants {
/** BGP UPDATE Attributes Type Code AS_PATH. */
public static final int TYPE = 2;
/** BGP AS length. */
public static final int AS_LENGTH = 2;
/** BGP 4 Octet AS length (RFC 6793). */
public static final int AS_4OCTET_LENGTH = 4;
/** BGP UPDATE AS_PATH Type: AS_SET. */
public static final int AS_SET = 1;
......@@ -373,8 +373,11 @@ public final class BgpConstants {
/** BGP UPDATE Attributes Type Code AGGREGATOR. */
public static final int TYPE = 7;
/** BGP UPDATE Attributes Type Code AGGREGATOR length. */
public static final int LENGTH = 6;
/** BGP UPDATE Attributes Type Code AGGREGATOR length: 2 octet AS. */
public static final int AS2_LENGTH = 6;
/** BGP UPDATE Attributes Type Code AGGREGATOR length: 4 octet AS. */
public static final int AS4_LENGTH = 8;
}
/**
......
......@@ -758,9 +758,9 @@ final class BgpUpdate {
// 4-octet AS number handling.
int asPathLen;
if (bgpSession.isAs4OctetCapable()) {
asPathLen = BgpConstants.Update.AsPath.AS_4OCTET_LENGTH;
asPathLen = BgpConstants.Update.AS_4OCTET_LENGTH;
} else {
asPathLen = BgpConstants.Update.AsPath.AS_LENGTH;
asPathLen = BgpConstants.Update.AS_LENGTH;
}
// Parse the AS numbers
......@@ -774,7 +774,7 @@ final class BgpUpdate {
ArrayList<Long> segmentAsNumbers = new ArrayList<>();
while (pathSegmentLength-- > 0) {
long asNumber;
if (asPathLen == BgpConstants.Update.AsPath.AS_4OCTET_LENGTH) {
if (asPathLen == BgpConstants.Update.AS_4OCTET_LENGTH) {
asNumber = message.readUnsignedInt();
} else {
asNumber = message.readUnsignedShort();
......@@ -967,9 +967,16 @@ final class BgpUpdate {
int attrFlags,
ChannelBuffer message)
throws BgpMessage.BgpParseException {
int expectedAttrLen;
if (bgpSession.isAs4OctetCapable()) {
expectedAttrLen = BgpConstants.Update.Aggregator.AS4_LENGTH;
} else {
expectedAttrLen = BgpConstants.Update.Aggregator.AS2_LENGTH;
}
// Check the Attribute Length
if (attrLen != BgpConstants.Update.Aggregator.LENGTH) {
if (attrLen != expectedAttrLen) {
// ERROR: Attribute Length Error
actionsBgpUpdateAttributeLengthError(
bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
......@@ -978,7 +985,12 @@ final class BgpUpdate {
}
// The AGGREGATOR AS number
long aggregatorAsNumber = message.readUnsignedShort();
long aggregatorAsNumber;
if (bgpSession.isAs4OctetCapable()) {
aggregatorAsNumber = message.readUnsignedInt();
} else {
aggregatorAsNumber = message.readUnsignedShort();
}
// The AGGREGATOR IP address
Ip4Address aggregatorIpAddress =
Ip4Address.valueOf((int) message.readUnsignedInt());
......