Understanding BGP 4-byte ASN
BGP Autonomous System Number (ASN) is a 2-byte (16-bits) entity. 2-bytes give 65536 possible numbers, of which, 0, 23456, 65535 and 64512- 65534 (private ASN) are reserved by IANA. Of the remaining, 39000+ ASNs are already used.
RFC 4893 discusses about 4-byte ASN. 4-bytes provide ASNs ranging from 0 to 4294967296. 0-65535 are called mappable-ASN. The 4-byte ASN can be represented in one of three ways-
ASN role in BGP
BGP carries ASN in-
- OPEN messages
- AS_PATH attribute
- AGGREGATOR attribute
- COMMUNITY attribute
Terminology
Old BGP Speaker- BGP Speaker running 2-byte ASN
New BGP Speaker- BGP Speaker running 4-byte ASN
Interaction with Neighbors
New BGP Speaker advertises to its neighbor that it uses a 4-byte ASN using BGP Capability Advertisements. If the neighbor also advertises that it uses a 4-byte ASN i.e. a New BGP Speaker, the two neighbors can inform each other of their 4-byte ASNs using OPEN messages.
If the neighbor is an Old BGP Speaker and responds that it does not support 4-byte ASN, the New BGP Speaker can still bring up the neighbor relationship, but cannot advertise its 4-byte ASN to this Old BGP neighbor. Instead, the New BGP speaker uses a reserved 2-byte ASN, 23456, called AS_TRANS (even if multiple ASNs use this). The New BGP Speaker adds this ASN to the OPEN message.
Path attribute interoperability
A BGP Speaker now knows whether its neighbor is a New BGP Speaker or an Old BGP Speaker.
A New BGP Speaker advertises the routes to its New BGP neighbors with AS_PATH carrying 4-byte ASN, as compared to an AS_PATH carrying 2-byte ASN when advertising to an Old BGP neighbor during which it adds the AS_TRANS ASN instead of adding its own 4-byte ASN. The router also adds a new attribute, AS4_PATH, to the route. The AS4_PATH attribute is an optional transitive attribute which carries the real AS_PATH list, carrying both 4-byte and 2-byte ASN. The New BGP Speaker adds the AS4_PATH attribute only if there are any 4-byte ASN in the AS_PATH list.
Definition: Optional Transitive
"Optional" meaning it is only used when needed, and
"Transitive" meaning it is passed along to other neighbors by BGP speakers who do not understand the attribute.
When an Old BGP Speaker advertises routes with AS4_PATH and AS_PATH attributes to a New BGP Speaker, the New BGP Speaker uses both attributes to reconstruct the path: AS4_PATH for 4-byte ASNs and AS_PATH for 2-byte ASNs.
The New BGP Speaker constructs the AS_PATH attribute by replacing 4-byte ASN with an AS_TRANS. In this way, the AS_PATH shows the correct number of hops.
Definition: AGGREGATOR attribute
When a number of routes are summarised (aggregated), the summarised route loses details. The AGGREGATOR attribute is added to the summarised route which includes the Router-ID and the ASN of the router performing the aggregation.
This attribute is not included in BGP decision process.
A new attribute AS4_AGGREGATOR is introduced for similar reasons. If the New BGP Speaker has to send the AGGREGATOR attribute and if the aggregating ASN is a 4-byte ASN, then the speaker constructs the AS4_AGGREGATOR attributes by copying the attribute length and attribute value from the AGGREGATOR attribute, places the attribute length and attribute value in the AS4_AGGREGATOR attribute, and replaces the 4-byte ASN with AS_TRANS ASN. Again, if the aggregating ASN is 2-byte, then AS4_AGGREGATOR is not sent.
NOTE
Under certain circumstances, it is not possible to reconstruct the entire AS path information from AS_PATH and AS4_PATH attributes. This can occur when two or more routes carrying the AS4_PATH attribute are aggregated by an Old BGP Speaker, and the AS4_PATH attribute carries atleast one 4-byte ASN. In that case, either the AS4_PATH attribute would be lost, or both AS_PATH and AS4_PATH would contain partial valid information, which will result in incomplete AS path information.
BGP Communities are supported in 4-byte ASN environment by using new Extended Community attribute called 4-Octet AS-specific BGP Extended Community. This new community now has 4-byte ASN field and 2-byte arbitrary number, as opposed to 2-byte ASN field in legacy Community attribute.
Sample Scenario
R1 and R3 routers are using 4-byte ASN. While R2 router is only capable of using 2-byte ASN.
The following shows BGP configuration on R1 and R2 routers.
BGP Configuration
R1(config)# router bgp ? <1-4294967295> Autonomous system number <1.0-XX.YY> Autonomous system numberR1(config)# router bgp 1.100R1(config-router)#^zR1# sh run | begin bgprouter bgp 65636 ! 4-byte ASN 1.100 changes to 65636 in running-config
no synchronization bgp log-neighbor-changes network 1.1.1.1 mask 255.255.255.255 neighbor 10.1.1.2 remote-as 200 no auto-summary!R2# show run | begin bgprouter bgp 200 no synchronization bgp log-neighbor-changes neighbor 10.1.1.1 remote-as 23456 ! R2 is configured to form eBGP neighborship with R1 and R3 using AS_TRANS ASN 23456 neighbor 10.2.2.2 remote-as 23456 no auto-summary!When R1 discovers R2, it sends a BGP Open message and all the capabilities including 4-byte ASN support. It pretends to be in AS 23456 while the actual ASN is hide in the Capability Advertisement.
Since R2 is not capable of understanding 4-byte ASN and as it is configured to peer with R1 in AS 23456, it will accept the BGP Open message and form neighbors with R1.
R1 forms neighbor with R2
R1#00:07:46: BGP: 10.1.1.2 passive open to 10.1.1.100:07:46: BGP: 10.1.1.2 went from Active to Idle00:07:46: BGP: 10.1.1.2 went from Idle to Connect00:07:46: BGP: 10.1.1.2 rcv message type 1, length (excl. header) 2600:07:46: BGP: 10.1.1.2 rcv OPEN, version 4, holdtime 180 seconds00:07:46: BGP: 10.1.1.2 went from Connect to OpenSent00:07:46: BGP: 10.1.1.2 sending OPEN, version 4, my as: 23456, holdtime 180 seconds00:07:46: BGP: 10.1.1.2 rcv OPEN w/ OPTION prameter len: 1600:07:46: BGP: 10.1.1.2 rcvd OPEN w/ optional parameter type 2 (Capability) len 600:07:46: BGP: 10.1.1.2 OPEN has CAPABILITY code: 1, length 400:07:46: BGP: 10.1.1.2 OPEN has MP_EXT CAP for afi/safi: 1/100:07:46: BGP: 10.1.1.2 rcvd OPEN w/ optional parameter type 2 (Capability) len 200:07:46: BGP: 10.1.1.2 OPEN has CAPABILITY code: 128, length 000:07:46: BGP: 10.1.1.2 OPEN has ROUTE-REFRESH capability(old) for all address-families00:07:46: BGP: 10.1.1.2 rcvd OPEN w/ optional parameter type 2(Capability) len 200:07:46: BGP: 10.1.1.2 OPEN has CAPABILITY code: 2, length 000:07:46: BGP: 10.1.1.2 OPEN has ROUTE-REFRESH capability for all address-familiesBGP: 10.1.1.2 rcvd OPEN w/ remote AS 20000:07:46: BGP: 10.1.1.2 went from OpenSent to OpenConfirm00:07:46: BGP: 10.1.1.2 send message type 1, length (incl. header) 5300:07:46: BGP: 10.1.1.2 went from OpenConfirm to Established00:07:46: %BGP-5-ADJCHANGE: neighbor 10.1.1.2 UpThe show ip bgp neighbors command shows the capabilities advertised by a BGP Speaker to its neighbor(s).
show ip bgp neighbors
R1# show ip bgp neighborsBGP neighbor is 10.1.1.2, remote AS 200, external link BGP version 4, remote router ID 10.1.1.2 BGP state = Established, up for 00:01:44 Last read 00:00:44, last write 00:00:44, hold time is 180, keepalive interval is 60 seconds Neighbor capabilities: Route refresh: advertised and received(new) Four-octets ASN Capability: advertised ! Only advertised, not received
Address family IPv4 Unicast: advertised and received Message statistics: InQ depth is 0 OutQ depth is 0 Sent Rcvd Opens: 1 1 Notifications: 0 0 Updates: 1 0 Keepalives: 4 3 Route Refresh: 0 0 Total: 6 4 Default minimum time between advertisement runs is 30 seconds For address family: IPv4 Unicast BGP table version 2, neighbor version 2/0 Output queue size : 0 Index 1, Offset 0, Mask 0x2 Member of update-group 1 Sent Rcvd Prefix activity: ---- ---- Prefixes Current: 1 0 Prefixes Total: 1 0 Implicit Withdraw: 0 0 Explicit Withdraw: 0 0 Used as bestpath: n/a 0 Used as multipath: n/a 0 Outbound Inbound Local Policy Denied Prefixes: -------- ------- Total: 0 0 Number of NLRIs in the update sent: max 0, min 0 Address tracking is enabled, the RIB does have a route to 10.1.1.2 Connections established 1; dropped 0 Last reset neverConnection state is ESTAB, I/O status: 1, unread input bytes: 0Mininum incoming TTL 0, Outgoing TTL 1Local host: 10.1.1.1, Local port: 179Foreign host: 10.1.1.2, Foreign port: 42061Enqueued packets for retransmit: 0, input: 0 mis-ordered: 0 (0 bytes)Event Timers (current time is 0x914D0):Timer Starts Wakeups NextRetrans 5 0 0x0TimeWait 0 0 0x0AckHold 5 3 0x0SendWnd 0 0 0x0KeepAlive 0 0 0x0GiveUp 0 0 0x0PmtuAger 0 0 0x0DeadWait 0 0 0x0iss: 3162196817 snduna: 3162197028 sndnxt: 3162197028 sndwnd: 16174irs: 1401371415 rcvnxt: 1401371537 rcvwnd: 16263 delrcvwnd: 121SRTT: 662 ms, RTTO: 4385 ms, RTV: 1530 ms, KRTT: 0 msminRTT: 72 ms, maxRTT: 336 ms, ACK hold: 200 msFlags: passive open, nagle, gen tcbsDatagrams (max data segment is 1460 bytes):Rcvd: 8 (out of order: 0), with data: 5, total data bytes: 121Sent: 9 (retransmit: 0, fastretransmit: 0), with data: 5, total data bytes: 210When R1 advertises a BGP UPDATE message carrying NLRI for prefix 1.1.1.1/32, it also includes a NEW AS_PATH attribute (AS4_PATH designated by RFC) along with the mandatory AS_PATH attribute.
R2 router accepts it as coming from AS 23456. It also forwards the same update message to R3 after appending its own ASN 200 to the AS_PATH attribute. However, since R3 understands the NEW AS_PATH attribute, it will reconstruct the original AS_PATH list from this attribute.
1.1.1.1/32 on R2 and R3
R2# show ip bgp 1.1.1.1BGP routing table entry for 1.1.1.1/32, version 6Paths: (1 available, best #1, table Default-IP-Routing-Table) Advertised to update-groups: 1 23456 10.1.1.1 from 10.1.1.1 (1.1.1.1) Origin IGP, metric 0, localpref 100, valid, external, bestR3# show ip bgp 1.1.1.1BGP routing table entry for 1.1.1.1/32, version 2Paths: (1 available, best #1)Flag: 0x820 Not advertised to any peer 200 65636 10.2.2.1 from 10.2.2.1 (10.1.1.2) Origin IGP, localpref 100, valid, external, bestAggregating 1.1.1.1/32 to 1.0.0.0/24 on R1
R1 aggregates 1.1.1.1/32 to 1.0.0.0/24 and advertises only the summarized route to R2.
router bgp 1.100 aggregate-address 1.0.0.0 255.0.0.0 summary-only!When R1 advertises this summarized route to R2, it copies all the information from regular AGGREGATOR attribute and puts in a NEW AGGREGATOR attribute, except the ASN. The regular AGGREGATOR attribute has ASN 23456 while NEW AGGREGATOR attribute has AS 65636.
Again, since R3 router can understand this NEW AGGREGATOR attribute, it can reconstruct the correct AS_PATH list.
Aggregated route
R2# show ip bgp 1.0.0.0BGP routing table entry for 1.0.0.0/8, version 7Paths: (1 available, best #1, table Default-IP-Routing-Table)Flag: 0x820 Advertised to update-groups: 1 23456, (aggregated by 23456 1.1.1.1) 10.1.1.1 from 10.1.1.1 (1.1.1.1) Origin IGP, metric 0, localpref 100, valid, external, atomic-aggregate, bestR3# show ip bgp 1.0.0.0BGP routing table entry for 1.0.0.0/8, version 5Paths: (1 available, best #1)Flag: 0x820 Not advertised to any peer 200 65636, (aggregated by 65636 1.1.1.1) 10.2.2.1 from 10.2.2.1 (10.1.1.2) Origin IGP, localpref 100, valid, external, atomic-aggregate, bestFurther reading: