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
Showing
2 changed files
with
28 additions
and
13 deletions
| ... | @@ -157,6 +157,12 @@ public final class BgpConstants { | ... | @@ -157,6 +157,12 @@ public final class BgpConstants { |
| 157 | private Update() { | 157 | private Update() { |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | + /** BGP AS length. */ | ||
| 161 | + public static final int AS_LENGTH = 2; | ||
| 162 | + | ||
| 163 | + /** BGP 4 Octet AS length (RFC 6793). */ | ||
| 164 | + public static final int AS_4OCTET_LENGTH = 4; | ||
| 165 | + | ||
| 160 | /** | 166 | /** |
| 161 | * BGP UPDATE: ORIGIN related constants. | 167 | * BGP UPDATE: ORIGIN related constants. |
| 162 | */ | 168 | */ |
| ... | @@ -227,12 +233,6 @@ public final class BgpConstants { | ... | @@ -227,12 +233,6 @@ public final class BgpConstants { |
| 227 | /** BGP UPDATE Attributes Type Code AS_PATH. */ | 233 | /** BGP UPDATE Attributes Type Code AS_PATH. */ |
| 228 | public static final int TYPE = 2; | 234 | public static final int TYPE = 2; |
| 229 | 235 | ||
| 230 | - /** BGP AS length. */ | ||
| 231 | - public static final int AS_LENGTH = 2; | ||
| 232 | - | ||
| 233 | - /** BGP 4 Octet AS length (RFC 6793). */ | ||
| 234 | - public static final int AS_4OCTET_LENGTH = 4; | ||
| 235 | - | ||
| 236 | /** BGP UPDATE AS_PATH Type: AS_SET. */ | 236 | /** BGP UPDATE AS_PATH Type: AS_SET. */ |
| 237 | public static final int AS_SET = 1; | 237 | public static final int AS_SET = 1; |
| 238 | 238 | ||
| ... | @@ -373,8 +373,11 @@ public final class BgpConstants { | ... | @@ -373,8 +373,11 @@ public final class BgpConstants { |
| 373 | /** BGP UPDATE Attributes Type Code AGGREGATOR. */ | 373 | /** BGP UPDATE Attributes Type Code AGGREGATOR. */ |
| 374 | public static final int TYPE = 7; | 374 | public static final int TYPE = 7; |
| 375 | 375 | ||
| 376 | - /** BGP UPDATE Attributes Type Code AGGREGATOR length. */ | 376 | + /** BGP UPDATE Attributes Type Code AGGREGATOR length: 2 octet AS. */ |
| 377 | - public static final int LENGTH = 6; | 377 | + public static final int AS2_LENGTH = 6; |
| 378 | + | ||
| 379 | + /** BGP UPDATE Attributes Type Code AGGREGATOR length: 4 octet AS. */ | ||
| 380 | + public static final int AS4_LENGTH = 8; | ||
| 378 | } | 381 | } |
| 379 | 382 | ||
| 380 | /** | 383 | /** | ... | ... |
| ... | @@ -758,9 +758,9 @@ final class BgpUpdate { | ... | @@ -758,9 +758,9 @@ final class BgpUpdate { |
| 758 | // 4-octet AS number handling. | 758 | // 4-octet AS number handling. |
| 759 | int asPathLen; | 759 | int asPathLen; |
| 760 | if (bgpSession.isAs4OctetCapable()) { | 760 | if (bgpSession.isAs4OctetCapable()) { |
| 761 | - asPathLen = BgpConstants.Update.AsPath.AS_4OCTET_LENGTH; | 761 | + asPathLen = BgpConstants.Update.AS_4OCTET_LENGTH; |
| 762 | } else { | 762 | } else { |
| 763 | - asPathLen = BgpConstants.Update.AsPath.AS_LENGTH; | 763 | + asPathLen = BgpConstants.Update.AS_LENGTH; |
| 764 | } | 764 | } |
| 765 | 765 | ||
| 766 | // Parse the AS numbers | 766 | // Parse the AS numbers |
| ... | @@ -774,7 +774,7 @@ final class BgpUpdate { | ... | @@ -774,7 +774,7 @@ final class BgpUpdate { |
| 774 | ArrayList<Long> segmentAsNumbers = new ArrayList<>(); | 774 | ArrayList<Long> segmentAsNumbers = new ArrayList<>(); |
| 775 | while (pathSegmentLength-- > 0) { | 775 | while (pathSegmentLength-- > 0) { |
| 776 | long asNumber; | 776 | long asNumber; |
| 777 | - if (asPathLen == BgpConstants.Update.AsPath.AS_4OCTET_LENGTH) { | 777 | + if (asPathLen == BgpConstants.Update.AS_4OCTET_LENGTH) { |
| 778 | asNumber = message.readUnsignedInt(); | 778 | asNumber = message.readUnsignedInt(); |
| 779 | } else { | 779 | } else { |
| 780 | asNumber = message.readUnsignedShort(); | 780 | asNumber = message.readUnsignedShort(); |
| ... | @@ -967,9 +967,16 @@ final class BgpUpdate { | ... | @@ -967,9 +967,16 @@ final class BgpUpdate { |
| 967 | int attrFlags, | 967 | int attrFlags, |
| 968 | ChannelBuffer message) | 968 | ChannelBuffer message) |
| 969 | throws BgpMessage.BgpParseException { | 969 | throws BgpMessage.BgpParseException { |
| 970 | + int expectedAttrLen; | ||
| 971 | + | ||
| 972 | + if (bgpSession.isAs4OctetCapable()) { | ||
| 973 | + expectedAttrLen = BgpConstants.Update.Aggregator.AS4_LENGTH; | ||
| 974 | + } else { | ||
| 975 | + expectedAttrLen = BgpConstants.Update.Aggregator.AS2_LENGTH; | ||
| 976 | + } | ||
| 970 | 977 | ||
| 971 | // Check the Attribute Length | 978 | // Check the Attribute Length |
| 972 | - if (attrLen != BgpConstants.Update.Aggregator.LENGTH) { | 979 | + if (attrLen != expectedAttrLen) { |
| 973 | // ERROR: Attribute Length Error | 980 | // ERROR: Attribute Length Error |
| 974 | actionsBgpUpdateAttributeLengthError( | 981 | actionsBgpUpdateAttributeLengthError( |
| 975 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); | 982 | bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); |
| ... | @@ -978,7 +985,12 @@ final class BgpUpdate { | ... | @@ -978,7 +985,12 @@ final class BgpUpdate { |
| 978 | } | 985 | } |
| 979 | 986 | ||
| 980 | // The AGGREGATOR AS number | 987 | // The AGGREGATOR AS number |
| 981 | - long aggregatorAsNumber = message.readUnsignedShort(); | 988 | + long aggregatorAsNumber; |
| 989 | + if (bgpSession.isAs4OctetCapable()) { | ||
| 990 | + aggregatorAsNumber = message.readUnsignedInt(); | ||
| 991 | + } else { | ||
| 992 | + aggregatorAsNumber = message.readUnsignedShort(); | ||
| 993 | + } | ||
| 982 | // The AGGREGATOR IP address | 994 | // The AGGREGATOR IP address |
| 983 | Ip4Address aggregatorIpAddress = | 995 | Ip4Address aggregatorIpAddress = |
| 984 | Ip4Address.valueOf((int) message.readUnsignedInt()); | 996 | Ip4Address.valueOf((int) message.readUnsignedInt()); | ... | ... |
-
Please register or login to post a comment