RFC 1654
A Border Gateway Protocol 4 (BGP-4)
Okay bestie, let's get the basics down first โจ This is RFC 1654, called A Border Gateway Protocol 4 (BGP-4) ๐ It's a Standards Track doc from the Network Working Group, dated July 1994. The editors are Y. Rekhter (T.J. Watson Research Center, IBM Corp.) and T. Li (cisco Systems) ๐ง The header doesn't list any Obsoletes or Updates, but Section 1 says the earlier version came out as RFC 1267 in October 1991 ๐ธ
Status of this Memo ๐
This is an Internet standards track protocol for the Internet community, and the authors want your discussion and suggestions for improvements ๐ซถ For the standardization state and status of this protocol, check the current edition of the "Internet Official Protocol Standards" (STD 1) ๐ Distribution of this memo is unlimited ๐
1. Acknowledgements ๐ซถ
This doc was originally published as RFC 1267 in October 1991, and it was co-written by Kirk Lougheed (cisco Systems) and Yakov Rekhter (IBM) ๐
Big thanks to Guy Almes (Rice University), Len Bosack (cisco Systems), and Jeffrey C. Honig (Cornell University) for their contributions to the earlier version ๐
We'd like to explicitly thank Bob Braden (ISI) for reviewing the earlier version, plus his constructive and valuable comments ๐
We'd also thank Bob Hinden, Director for Routing of the Internet Engineering Steering Group, and the team of reviewers he pulled together to review the previous version (BGP-2) of this document. That team was Deborah Estrin, Milo Medin, John Moy, Radia Perlman, Martha Steenstrup, Mike St. Johns, and Paul Tsuchiya, and they acted with a strong combination of toughness, professionalism, and courtesy ๐
This updated version is the product of the IETF BGP Working Group, with Yakov Rekhter and Tony Li as editors. Certain sections borrowed heavily from IDRP [7], which is the OSI counterpart of BGP. For that, credit goes to the ANSI X3S3.3 group, chaired by Lyman Chapin (BBN), and to Charles Kunzinger (IBM Corp.), who was the IDRP editor within that group โจ We'd also like to thank Mike Craren (Proteon, Inc.), Dimitry Haskin (Wellfleet), John Krawczyk (Wellfleet), and Paul Traina (cisco) for their insightful comments ๐ฅ
We'd specially acknowledge the numerous contributions by Dennis Ferguson (ANS) ๐ฆ
2. Introduction ๐
The Border Gateway Protocol (BGP) is an inter-Autonomous System routing protocol ๐ It's built on experience gained with EGP as defined in RFC 904 [1], and with EGP usage in the NSFNET Backbone as described in RFC 1092 [2] and RFC 1093 [3] ๐
The main job of a BGP speaking system is to exchange network reachability information with other BGP systems. That information includes the list of Autonomous Systems (ASs) the reachability information travels through. That's enough to build a graph of AS connectivity, which lets you prune routing loops and enforce some policy decisions at the AS level ๐ง
BGP-4 brings a new set of mechanisms for classless interdomain routing. It supports advertising an IP prefix and gets rid of the concept of network "class" within BGP ๐ซง BGP-4 also adds mechanisms for aggregating routes, including aggregation of AS paths. These changes support the proposed supernetting scheme [8, 9] ๐
Now, to figure out which policies you can enforce with BGP, you have to focus on one rule: a BGP speaker only advertises to its peers (the other BGP speakers it talks to) in neighboring ASs the routes it actually uses itself ๐ This rule matches the "hop-by-hop" routing paradigm that's used pretty much everywhere on the Internet right now ๐ธ Some policies can't work with hop-by-hop, so they need techniques like source routing. For example, BGP doesn't let one AS send traffic to a neighboring AS while expecting that traffic to take a different route from the traffic that started in the neighboring AS ๐ But BGP can support any policy that fits hop-by-hop. Since the current Internet only uses hop-by-hop, and BGP can support any policy that fits that paradigm, BGP is extremely applicable as an inter-AS routing protocol for the current Internet ๐ญ๐
A deeper look at which policies can and can't be enforced with BGP is outside the scope of this document. For that, check the companion document on BGP usage [5] ๐ง
BGP runs over a reliable transport protocol ๐ซถ That means it doesn't have to implement explicit update fragmentation, retransmission, acknowledgement, or sequencing. You can use any authentication scheme the transport protocol supports on top of BGP's own authentication mechanisms. The error notification mechanism in BGP assumes the transport protocol supports a "graceful" close, meaning all outstanding data gets delivered before the connection closes ๐
BGP uses TCP [4] as its transport protocol. TCP meets BGP's transport requirements and shows up in virtually every commercial router and host ๐ In the following descriptions, "transport protocol connection" can be understood as a TCP connection. BGP uses TCP port 179 to set up its connections ๐
This memo uses the term `Autonomous System' (AS) throughout. The classic definition is a set of routers under a single technical administration, using an interior gateway protocol and common metrics to route packets within the AS, and an exterior gateway protocol to route packets to other ASs ๐ฐ Since that definition came about, it's become common for a single AS to run several interior gateway protocols and sometimes several sets of metrics inside it. The word Autonomous System here stresses that, even with multiple IGPs and metrics, an AS's administration still looks to other ASs like it has a single coherent interior routing plan and gives a consistent picture of which networks are reachable through it โจ
The planned use of BGP in the Internet environment, including topology, the interaction between BGP and IGPs, and enforcing routing policy rules, is covered in a companion document [5] ๐ This document is the first in a series planned to explore different aspects of BGP application. Send your comments to the BGP mailing list at iwg@ans.net ๐
3. Summary of Operation ๐ฆ
Two systems form a transport protocol connection with each other. They exchange messages to open and confirm the connection parameters ๐ค The initial data flow is the entire BGP routing table. Incremental updates are sent as the routing tables change ๐ BGP doesn't require periodic refresh of the whole BGP routing table, so a BGP speaker has to keep the current version of the entire BGP routing tables of all of its peers for the length of the connection ๐ง KeepAlive messages are sent periodically to make sure the connection is still alive ๐ Notification messages go out in response to errors or special conditions. If a connection runs into an error condition, a notification message is sent and the connection gets closed ๐จ
The hosts running the Border Gateway Protocol don't need to be routers ๐ฅ๏ธ A non-routing host could swap routing information with routers via EGP or even an interior routing protocol. That non-routing host could then use BGP to swap routing information with a border router in another Autonomous System. The implications and applications of this setup are left for further study ๐ญ
If a particular AS has multiple BGP speakers and provides transit service for other ASs, you have to be careful to keep the routing view consistent inside the AS ๐งฉ The interior routing protocol gives a consistent view of the AS's interior routes. A consistent view of the routes outside the AS can come from having all BGP speakers inside the AS keep direct BGP connections with each other ๐ซถ Using a common set of policies, the BGP speakers agree on which border routers will serve as exit/entry points for particular networks outside the AS. That info gets passed to the AS's internal routers, possibly through the interior routing protocol ๐ฌ Be sure the interior routers have all been updated with transit information before the BGP speakers announce to other ASs that transit service is being provided โญ
Connections between BGP speakers in different ASs are called "external" links. BGP connections between BGP speakers in the same AS are called "internal" links ๐ In the same way, a peer in a different AS is an external peer, and a peer in the same AS may be described as an internal peer ๐
3.1 Routes: Advertisement and Storage ๐ฃ๏ธ
For this protocol, a route is a unit of information that pairs a destination with the attributes of a path to that destination:
- Routes are advertised between a pair of BGP speakers in
UPDATEmessages. The destination is the systems whose IP addresses are reported in the Network Layer Reachability Information (NLRI) field, and the path is the information reported in the path attributes fields of that sameUPDATEmessage ๐ - Routes are stored in the Routing Information Bases (RIBs): namely, the Adj-RIBs-In, the Loc-RIB, and the Adj-RIBs-Out. Routes that will be advertised to other BGP speakers must be present in the Adj-RIB-Out. Routes that will be used by the local BGP speaker must be present in the Loc-RIB, and the next hop for each of these routes must be present in the local BGP speaker's forwarding information base. Routes received from other BGP speakers are present in the Adj-RIBs-In ๐๏ธ
If a BGP speaker decides to advertise a route, it may add to or modify the path attributes of that route before advertising it to a peer โจ
BGP gives you ways for a BGP speaker to tell its peer that a route it previously advertised isn't available anymore ๐ โโ๏ธ There are three ways a given BGP speaker can say a route has been withdrawn from service:
a) The IP prefix that expresses the destinations for a previously advertised route can be advertised in the WITHDRAWN ROUTES field of the UPDATE message, which marks the route as no longer available for use ๐ซฅ
b) A replacement route with the same Network Layer Reachability Information can be advertised ๐
c) The BGP speaker - BGP speaker connection can be closed, which implicitly takes all routes the pair of speakers had advertised to each other out of service ๐
3.2. Routing Information Bases
okay so every BGP speaker keeps its own RIB (Routing Information Base), and it's split into three distinct parts ๐
- a) Adj-RIBs-In: this is where routing info learned from inbound UPDATE messages lives. These are the routes that are available as an input to the Decision Process ๐ฅ
- b) Loc-RIB: the local routing info the BGP speaker picked after applying its local policies to whatever is sitting in its Adj-RIBs-In ๐
- c) Adj-RIBs-Out: the info the local BGP speaker picked for advertising to its peers. Whatever is stored here gets carried in the local speaker's UPDATE messages and sent out to those peers ๐
so basically, Adj-RIBs-In is the raw, unprocessed tea from your peers ๐ต, the Loc-RIB is the stuff you actually chose after the Decision Process โจ, and the Adj-RIBs-Out is you neatly organising routes for each specific peer through your UPDATE messages ๐
ngl the best part is that the model is just a model ๐ง. It separates the three RIBs conceptually, but it neither implies nor requires that an implementation keeps three separate copies of the routing information. Whether you store 3 copies or 1 copy with pointers is totally up to you, because the protocol doesn't constrain that choice ๐ฆ
4. Message Formats โจ
this section is all about the message formats BGP uses ๐
messages get sent over a reliable transport protocol connection ๐. A message only gets processed after it has been entirely received ๐ฆ. The maximum message size is 4096 octets, and all implementations are required to support this maximum message size ๐. The smallest message that may be sent is a BGP header with no data portion, which is 19 octets ๐ธ
4.1. Message Header Format
every message starts with a fixed-size header ๐. There may or may not be a data portion after it, depending on the message type. Here's how the fields are laid out ๐
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ +
| Marker |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length | Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Marker:
the Marker is a 16-octet field holding a value that the receiver of the message can predict ๐ฎ. If the Type of the message is OPEN, or if the Authentication Code used in the OPEN message of the connection is zero, then the Marker must be all ones ๐. Otherwise, the value of the marker can be predicted by some computation specified as part of the authentication mechanism being used. The Marker can be used to detect loss of synchronization between a pair of BGP peers, and to authenticate incoming BGP messages ๐ก๏ธ
Length:
the Length is a 2-octet unsigned integer for the total length of the message, header included, in octets ๐. So it lets you find the (Marker field of the) next message in the transport-level stream, e.g. ๐งญ. The Length value must always be at least 19 and no greater than 4096, and it may be further constrained depending on the message type ๐ . No "padding" of extra data is allowed after the message, so the Length field must have the smallest value required for the rest of the message ๐ซถ
Type:
this is a 1-octet unsigned integer for the type code of the message ๐๏ธ. These type codes are defined:
1 - OPEN
2 - UPDATE
3 - NOTIFICATION
4 - KEEPALIVE
4.2. OPEN Message Format
after a transport protocol connection is established, the first message each side sends is an OPEN message ๐ค. If the OPEN message is acceptable, a KEEPALIVE message confirming the OPEN gets sent back ๐. Once the OPEN is confirmed, UPDATE, KEEPALIVE, and NOTIFICATION messages may be exchanged ๐ฆ
on top of the fixed-size BGP header, the OPEN message has these fields:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+
| Version |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| My Autonomous System |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Hold Time |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| BGP Identifier |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Auth. Code |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Authentication Data |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Version:
this is a 1-octet unsigned integer for the protocol version number of the message ๐. The current BGP version number is 4 โจ
My Autonomous System:
this 2-octet unsigned integer is the Autonomous System number of the sender ๐
Hold Time:
this 2-octet unsigned integer is the number of seconds the sender proposes for the value of the Hold Timer โณ. When an OPEN message comes in, a BGP speaker MUST calculate the value of the Hold Timer by using the smaller of its configured Hold Time and the Hold Time received in the OPEN message ๐งฎ. The Hold Time MUST be either zero or at least three seconds ๐ซถ. An implementation may reject connections on the basis of the Hold Time ๐ โโ๏ธ. The calculated value is the maximum number of seconds that may elapse between the receipt of successive KEEPALIVE and/or UPDATE messages by the sender ๐
BGP Identifier:
this 4-octet unsigned integer is the BGP Identifier of the sender ๐ชช. A given BGP speaker sets its BGP Identifier to an IP address assigned to that speaker ๐ก. The value is determined on startup and is the same for every local interface and every BGP peer ๐ธ
Authentication Code:
this 1-octet unsigned integer tells you which authentication mechanism is being used ๐. Whenever an authentication mechanism is specified for use within BGP, three things must be included in the specification:
- the value of the Authentication Code which indicates use of the mechanism,
- the form and meaning of the Authentication Data, and
- the algorithm for computing values of Marker fields.
Only one authentication mechanism is specified as part of this memo:
- its Authentication Code is zero,
- its Authentication Data must be empty (of zero length), and
- the Marker fields of all messages must be all ones.
The semantics of non-zero Authentication Codes lies outside the scope of this memo ๐ง
note that a separate authentication mechanism may be used in establishing the transport level connection ๐
Authentication Data:
the form and meaning of this variable-length field depend on the Authentication Code ๐๏ธ. If the Authentication Code field is zero, the Authentication Data field must have zero length. The semantics of a non-zero length Authentication Data field are outside the scope of this memo ๐
note that you can work out the length of the Authentication Data field from the message Length field with this formula:
Message Length = 29 + Authentication Data Length
the minimum length of the OPEN message is 29 octets, header included ๐
4.3. UPDATE Message Format
UPDATE messages are how routing information gets transferred between BGP peers ๐. The information in an UPDATE packet can be used to construct a graph describing the relationships of the various Autonomous Systems ๐ธ๏ธ. By applying rules (we'll get to those) you can detect routing information loops and some other anomalies, and remove them from inter-AS routing ๐งน
an UPDATE message is used to advertise a single feasible route to a peer, or to withdraw multiple unfeasible routes from service (see 3.1) ๐ฆ. An UPDATE message may advertise a feasible route and withdraw multiple unfeasible routes from service at the same time โจ. The UPDATE message always includes the fixed-size BGP header, and can optionally include the other fields shown below ๐
+-----------------------------------------------------+
| Unfeasible Routes Length (2 octets) |
+-----------------------------------------------------+
| Withdrawn Routes (variable) |
+-----------------------------------------------------+
| Total Path Attribute Length (2 octets) |
+-----------------------------------------------------+
| Path Attributes (variable) |
+-----------------------------------------------------+
| Network Layer Reachability Information (variable) |
+-----------------------------------------------------+
Unfeasible Routes Length:
this 2-octets unsigned integer is the total length of the Withdrawn Routes field in octets ๐งพ. Its value must allow the length of the Network Layer Reachability Information field to be determined as specified below ๐
a value of 0 means no routes are being withdrawn from service, and that the WITHDRAWN ROUTES field is not present in this UPDATE message ๐ โโ๏ธ
Withdrawn Routes:
this is a variable length field with a list of IP address prefixes for the routes being withdrawn from service ๐๏ธ. Each IP address prefix is encoded as a 2-tuple of the form <length, prefix>, and its fields look like this ๐
+---------------------------+
| Length (1 octet) |
+---------------------------+
| Prefix (variable) |
+---------------------------+
the use and meaning of these fields go like this ๐ง
- a) Length: the Length field is the length in bits of the IP address prefix. A length of zero means a prefix that matches all IP addresses (with prefix, itself, of zero octets) ๐
- b) Prefix:
The Prefix field is just a bunch of IP address prefixes, padded with extra trailing bits so the end of the field lands on an octet boundary ๐ง And bestie, the value of those trailing bits is irrelevant, so don't stress about them ๐
Total Path Attribute Length:
This is a 2-octet unsigned integer that tells you the total length of the Path Attributes field in octets ๐ Its value must allow the length of the Network Layer Reachability field to be figured out, which we'll get to in a sec ๐ฆ
A value of 0 means there's no Network Layer Reachability Information field in this UPDATE message at all โจ
Path Attributes:
Every UPDATE has a variable-length sequence of path attributes ๐ Each one is a triple <attribute type, attribute length, attribute value>, and the length is variable too, so it's a whole vibe ๐
The Attribute Type is two octets. The first is the Attribute Flags octet and the second is the Attribute Type Code octet ๐
0 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Attr. Flags |Attr. Type Code|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Okay so the flags octet is packed with little switches ๐ฅ The high-order bit (bit 0) is the Optional bit. If it's set to 1 the attribute is optional, and if it's set to 0 the attribute is well-known ๐
The second high-order bit (bit 1) is the Transitive bit. For an optional attribute, 1 means it's transitive and 0 means it's non-transitive ๐ฆ For well-known attributes, the Transitive bit must be set to 1. (See Section 5 for a discussion of transitive attributes. It's giving main character energy ๐ )
The third high-order bit (bit 2) is the Partial bit. It tells you whether the info in an optional transitive attribute is partial (1) or complete (0) ๐ง For well-known attributes and for optional non-transitive attributes, the Partial bit must be set to 0.
The fourth high-order bit (bit 3) is the Extended Length bit. It says whether the Attribute Length is one octet (0) or two octets (1) ๐ Extended Length may be used only if the length of the attribute value is greater than 255 octets. Not before, bestie ๐
The lower-order four bits of the Attribute Flags octet are unused. They must be zero (and must be ignored when received) ๐ซถ
The Attribute Type Code octet holds the Attribute Type Code. The ones that are currently defined get their own discussion in Section 5 ๐
Now for the length bit. If Extended Length is set to 0, the third octet of the Path Attribute holds the length of the attribute data in octets. If Extended Length is set to 1, then the third and fourth octets together hold that length ๐ธ
The remaining octets are the attribute value, and how you read them depends on the Attribute Flags and the Attribute Type Code ๐ Here are the supported Attribute Type Codes, their values and what they're for ๐
a) ORIGIN (Type Code 1):
ORIGIN is a well-known mandatory attribute that tells you where the path information came from ๐ The data octet can be one of these values:
Value Meaning
0 IGP - Network Layer Reachability Information
is interior to the originating AS
1 EGP - Network Layer Reachability Information
learned via EGP
2 INCOMPLETE - Network Layer Reachability
Information learned by some other means
Its usage is defined in 5.1.1 ๐
b) AS_PATH (Type Code 2):
AS_PATH is a well-known mandatory attribute made up of a sequence of AS path segments. Each segment is a triple <path segment type, path segment length, path segment value> ๐ฆ
The path segment type is a 1-octet field with these values defined:
Value Segment Type
1 AS_SET: unordered set of ASs a route in the
UPDATE message has traversed
2 AS_SEQUENCE: ordered set of ASs a route in
the UPDATE message has traversed
The path segment length is a 1-octet field that holds the number of ASs in the path segment value field โจ The path segment value field has one or more AS numbers, and each one is a 2-octet field ๐ง
Usage of this attribute is defined in 5.1.2 ๐
c) NEXT_HOP (Type Code 3):
This is a well-known mandatory attribute that gives the IP address of the border router that should be used as the next hop to the destinations listed in the Network Layer Reachability field of the UPDATE message ๐ฅ
Usage of this attribute is defined in 5.1.3 ๐
d) MULTI_EXIT_DISC (Type Code 4):
This is an optional non-transitive attribute. It's a four-octet non-negative integer, and a BGP speaker's decision process can use its value to tell apart multiple exit points to a neighboring autonomous system ๐
Its usage is defined in 5.1.4 ๐ฆ
e) LOCAL_PREF (Type Code 5):
LOCAL_PREF is a well-known discretionary attribute and a four-octet non-negative integer ๐ A BGP speaker uses it to tell the other BGP speakers in its own autonomous system how much it prefers an advertised route. Usage of this attribute is described in 5.1.5 ๐
f) ATOMIC_AGGREGATE (Type Code 6)
ATOMIC_AGGREGATE is a well-known discretionary attribute with a length of 0 ๐ธ A BGP speaker uses it to tell other BGP speakers that the local system picked a less specific route without picking a more specific route that's included in it ๐ Usage of this attribute is described in 5.1.6 โจ
g) AGGREGATOR (Type Code 7)
AGGREGATOR is an optional transitive attribute with a length of 6 ๐ง It holds the last AS number that formed the aggregate route (encoded as 2 octets), followed by the IP address of the BGP speaker that formed the aggregate route (encoded as 4 octets) ๐ Usage of this attribute is described in 5.1.7 ๐ซถ
Network Layer Reachability Information:
This variable-length field holds a list of IP address prefixes ๐ฆ Its length in octets isn't encoded explicitly, but you can calculate it like this:
UPDATE message Length - 23 - Total Path Attributes Length -
Unfeasible Routes Length
Here's the breakdown. UPDATE message Length is the value encoded in the fixed-size BGP header. Total Path Attribute Length and Unfeasible Routes Length are the values encoded in the variable part of the UPDATE message. And 23 is the combined length of the fixed-size BGP header, the Total Path Attribute Length field and the Unfeasible Routes Length field ๐งฎโจ
Reachability info is encoded as one or more 2-tuples of the form <length, prefix>, and they look like this ๐
+---------------------------+
| Length (1 octet) |
+---------------------------+
| Prefix (variable) |
+---------------------------+
a) Length:
The Length field gives the length in bits of the IP address prefix. A length of zero means a prefix that matches all IP addresses (with a prefix that's zero octets long, itself) ๐ธ
b) Prefix:
The Prefix field holds IP address prefixes, followed by enough trailing bits to make the end of the field fall on an octet boundary. Again, the value of the trailing bits is irrelevant ๐
Okay, so the minimum length of an UPDATE message is 23 octets. That's 19 octets for the fixed header, plus 2 octets for the Unfeasible Routes Length, plus 2 octets for the Total Path Attribute Length. (In that minimum case, Unfeasible Routes Length is 0 and Total Path Attribute Length is 0 too.) ๐ซถ
An UPDATE message can advertise at most one route, and that route can be described by several path attributes ๐ All path attributes in a given UPDATE message apply to the destinations carried in its Network Layer Reachability Information field ๐
An UPDATE message can also list multiple routes to be withdrawn from service ๐ฆ Each route is identified by its destination, expressed as an IP prefix. That uniquely identifies the route within the BGP speaker to BGP speaker connection it was previously advertised on ๐ง
An UPDATE message may advertise only routes to be withdrawn from service. In that case it won't include path attributes or Network Layer Reachability Information ๐ On the flip side, it may advertise only a feasible route, and then the WITHDRAWN ROUTES field doesn't need to be present โจ
4.4 KEEPALIVE Message Format
Here's the tea ๐ต BGP doesn't use any transport protocol-based keep-alive mechanism to check whether peers are reachable ๐ Instead, peers exchange KEEPALIVE messages often enough that the Hold Timer never expires ๐ฆ A reasonable maximum time between KEEPALIVE messages would be one third of the Hold Time interval ๐ง
KEEPALIVE messages MUST NOT be sent more frequently than one per second. An implementation MAY adjust the rate at which it sends KEEPALIVE messages based on the Hold Time interval ๐
If the negotiated Hold Time interval is zero, then periodic KEEPALIVE messages MUST NOT be sent โญ
A KEEPALIVE message is just the message header, and its length is 19 octets ๐ธ
4.5 NOTIFICATION Message Format ๐จ
okay bestie, a NOTIFICATION message gets sent whenever an error condition is detected ๐ญ. It's giving dramatic exit energy: the BGP connection is closed immediately after sending it ๐.
In addition to the fixed-size BGP header, the NOTIFICATION message has these fields:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Error code | Error subcode | Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Error Code ๐
This 1-octet unsigned integer tells you what type of NOTIFICATION it is. These are the Error Codes that have been defined:
Error Code Symbolic Name Reference
1 Message Header Error Section 6.1
2 OPEN Message Error Section 6.2
3 UPDATE Message Error Section 6.3
4 Hold Timer Expired Section 6.5
5 Finite State Machine Error Section 6.6
6 Cease Section 6.7
Error subcode ๐
This 1-octet unsigned integer gives you the more specific details about what went wrong. Each Error Code can have one or more Error Subcodes attached to it. If there's no suitable Error Subcode defined, then a zero (Unspecific) value gets used for the Error Subcode field ๐ซถ.
Here are the Message Header Error subcodes:
1 - Connection Not Synchronized.
2 - Bad Message Length.
3 - Bad Message Type.
Here are the OPEN Message Error subcodes:
1 - Unsupported Version Number.
2 - Bad Peer AS.
3 - Bad BGP Identifier.
4 - Unsupported Authentication Code.
5 - Authentication Failure.
6 - Unacceptable Hold Time.
And the UPDATE Message Error subcodes:
1 - Malformed Attribute List.
2 - Unrecognized Well-known Attribute.
3 - Missing Well-known Attribute.
4 - Attribute Flags Error.
5 - Attribute Length Error.
6 - Invalid ORIGIN Attribute
7 - AS Routing Loop.
8 - Invalid NEXT_HOP Attribute.
9 - Optional Attribute Error.
10 - Invalid Network Field.
11 - Malformed AS_PATH.
Data ๐งฉ
This variable-length field is used to diagnose why the NOTIFICATION happened. What's in the Data field depends on the Error Code and Error Subcode. See Section 6 below for the full tea โ.
Also, the length of the Data field can be figured out from the message Length field with this formula:
Message Length = 21 + Data Length
The minimum length of the NOTIFICATION message is 21 octets (including the message header). Not a single octet less, periodt โจ.
5. Path Attributes ๐
okay, this section is all about the path attributes of the UPDATE message, and there are a lot of rules here, so grab a snack ๐.
Path attributes fall into four separate categories:
- Well-known mandatory.
- Well-known discretionary.
- Optional transitive.
- Optional non-transitive.
Well-known attributes MUST be recognized by all BGP implementations. Some of them are mandatory and MUST be included in every UPDATE message. Others are discretionary and MAY or may not be sent in a particular UPDATE message.
All well-known attributes MUST be passed along to other BGP peers (after proper updating, if it's necessary) ๐ฆ.
On top of the well-known ones, each path can carry one or more optional attributes. It is not REQUIRED or expected that every BGP implementation supports every optional attribute ๐. How an unrecognized optional attribute gets handled is decided by the setting of the Transitive bit in the attribute flags octet. Paths with unrecognized transitive optional attributes SHOULD be accepted. If a path with an unrecognized transitive optional attribute is accepted and passed along to other BGP peers, then that unrecognized transitive optional attribute MUST be passed along with the path to other BGP peers, with the Partial bit in the Attribute Flags octet set to 1. If a path with a recognized transitive optional attribute is accepted and passed along to other BGP peers, and the Partial bit in the Attribute Flags octet was set to 1 by some previous AS, then it is not set back to 0 by the current AS ๐ฅ. Unrecognized non-transitive optional attributes MUST be quietly ignored and MUST NOT be passed along to other BGP peers ๐คซ.
New transitive optional attributes MAY be attached to the path by the originator or by any other AS in the path. If they aren't attached by the originator, the Partial bit in the Attribute Flags octet is set to 1. The rules for attaching new non-transitive optional attributes depend on the nature of that specific attribute. The documentation for each new non-transitive optional attribute is expected to include those rules. (The description of the MULTI_EXIT_DISC attribute gives an example ๐.) All optional attributes, both transitive and non-transitive, MAY be updated (if that's appropriate) by ASs in the path.
The sender of an UPDATE message SHOULD order the path attributes within that UPDATE message in ascending order of attribute type. The receiver of an UPDATE message MUST be prepared to handle path attributes that are out of order ๐ง.
The same attribute cannot appear more than once within the Path Attributes field of a particular UPDATE message ๐ซ.
5.1 Path Attribute Usage ๐
This part covers how each BGP path attribute is used, one clause at a time โจ.
5.1.1 ORIGIN
ORIGIN is a well-known mandatory attribute. The ORIGIN attribute SHALL be generated by the autonomous system that originates the associated routing information. It SHALL be included in the UPDATE messages of all BGP speakers that choose to propagate this information to other BGP speakers ๐.
5.1.2 AS_PATH
AS_PATH is a well-known mandatory attribute ๐ค๏ธ. This attribute identifies the autonomous systems that the routing information carried in this UPDATE message has passed through. The components of this list can be AS_SETs or AS_SEQUENCEs.
When a BGP speaker propagates a route that it learned from another BGP speaker's UPDATE message, it SHALL modify the route's AS_PATH attribute based on where the BGP speaker that the route will be sent to is located:
- a) When a BGP speaker advertises the route to another BGP speaker located in its own autonomous system, the advertising speaker SHALL NOT modify the
AS_PATHattribute associated with the route. ๐ซถ - b) When a BGP speaker advertises the route to a BGP speaker located in a neighboring autonomous system, the advertising speaker SHALL update the
AS_PATHattribute as follows:- 1) if the first path segment of the
AS_PATHis of typeAS_SEQUENCE, the local system SHALL prepend its own AS number as the last element of the sequence (put it in the leftmost position). - 2) if the first path segment of the
AS_PATHis of typeAS_SET, the local system SHALL prepend a new path segment of typeAS_SEQUENCEto theAS_PATH, including its own AS number in that segment.
- 1) if the first path segment of the
When a BGP speaker originates a route, then:
- a) the originating speaker SHALL include its own AS number in the
AS_PATHattribute of all UPDATE messages sent to BGP speakers located in neighboring autonomous systems. (In this case, the AS number of the originating speaker's autonomous system will be the only entry in theAS_PATHattribute.) ๐ - b) the originating speaker SHALL include an empty
AS_PATHattribute in all UPDATE messages sent to BGP speakers located in its own autonomous system. (An emptyAS_PATHattribute is one whose length field contains the value zero.) ๐
5.1.3 NEXT_HOP โจ
okay so NEXT_HOP is basically the "next stop" sign ๐ฃ๏ธ๐ It carries the IP address of the border router that should be used as the next hop to reach the networks listed in the UPDATE message. If a border router is in the same AS as its peer, that peer is an internal border router ๐ Otherwise, it's an external border router ๐ง
A BGP speaker can advertise any internal border router as the next hop, as long as the interface tied to that router's IP address (the one given in the NEXT_HOP path attribute) sits on a common subnet with both the local and the remote BGP speakers ๐ธ External border routers are a bit pickier ๐
The speaker can advertise one as the next hop only if it learned that router's IP address from one of its peers, AND the interface for that address shares a common subnet with the local and remote BGP speakers. Also, a BGP speaker needs to be able to support turning off the advertising of external border routers ๐
Big rule time ๐ซ A BGP speaker must never advertise a peer's own address back to that peer as a NEXT_HOP for a route the speaker is originating. And it must never install a route with itself as the next hop ๐
When a speaker passes a route to another speaker in its own AS, the advertising speaker shall not modify the NEXT_HOP attribute on that route ๐ And if a speaker got the route over an internal link, it may forward packets to the NEXT_HOP address, as long as that address is on a common subnet with the local and remote BGP speakers ๐ฆ
5.1.4 MULTI_EXIT_DISC ๐ช
The MULTI_EXIT_DISC attribute may be used on external (inter-AS) links to tell apart multiple exit or entry points into the same neighboring AS ๐บ๏ธ Its value is a four octet unsigned number called a metric. With everything else equal, the exit or entry point with the lower metric should be preferred ๐ If it was received over external links, the attribute may be propagated over internal links to other BGP speakers within the same AS. But it is never propagated to BGP speakers in neighboring AS's ๐
5.1.5 LOCAL_PREF ๐
LOCAL_PREF is a well-known discretionary attribute, and it shall be included in every UPDATE message a BGP speaker sends to other speakers in its own AS ๐ The speaker shall work out a degree of preference for each external route and include it when advertising that route to its internal peers ๐งฎ The higher degree of preference should be preferred ๐ And the speaker shall use the degree of preference learned via LOCAL_PREF in its decision process (see section 9.1.1) ๐ฏ
Plot twist ๐ซฃ A speaker shall not include this attribute in UPDATE messages going to speakers in a neighboring AS. And if it shows up in an UPDATE from a speaker outside the receiver's AS, the receiving speaker shall ignore it ๐
5.1.6 ATOMIC_AGGREGATE ๐
ATOMIC_AGGREGATE is a well-known discretionary attribute, and it's basically a "heads up, I hid some details" flag ๐ซฃ Say a speaker gets overlapping routes from one of its peers (see 9.1.4) and picks the less specific route without picking the more specific one. Then the local system shall attach ATOMIC_AGGREGATE to that route when passing it on to other BGP speakers, unless the less specific route already had it ๐
If you receive a route with ATOMIC_AGGREGATE, you shall not strip the attribute off when propagating the route to other speakers ๐ซโ๏ธ You also shall not make any NLRI of that route more specific (as defined in 9.1.4) when advertising it to other BGP speakers ๐
Also, if you get a route with ATOMIC_AGGREGATE, you need to be aware that the real path to the destinations in that route's NLRI can go through ASs that aren't listed in the AS_PATH attribute ๐บ๏ธ The path can still be loop-free though ๐โจ
5.1.7 AGGREGATOR ๐งบ
AGGREGATOR is an optional transitive attribute ๐งบ It may be included in updates that were formed by aggregation (see Section 9.2.4.2). A BGP speaker that does route aggregation may add AGGREGATOR, and when it does, the attribute shall contain its own AS number and IP address ๐
6. BGP Error Handling ๐จ
This section is the "uh oh" chapter ๐ It covers what to do when things go sideways while processing BGP messages.
Whenever one of these conditions gets detected, a NOTIFICATION message goes out carrying the indicated Error Code, Error Subcode, and Data fields ๐ฃ Then the BGP connection gets closed ๐ If no Error Subcode is specified, a zero must be used 0๏ธโฃ
So when the text says "the BGP connection is closed" ๐ it means the transport protocol connection has been shut and all resources for that BGP connection have been freed up. Routing table entries tied to the remote peer get marked as invalid โ and that invalidity gets passed on to other BGP peers before those routes are deleted from the system ๐๏ธ
Unless it's specifically said otherwise, the Data field of the NOTIFICATION message sent to flag an error is empty ๐ซ
6.1 Message Header error handling ๐จ
Any error spotted while processing the Message Header gets flagged by sending a NOTIFICATION message with Error Code Message Header Error ๐ฉ The Error Subcode spills the tea on exactly what went wrong ๐ต
For the Marker field: if the message is an OPEN, the expected value is all ones 1๏ธโฃ1๏ธโฃ For every other BGP message type, the expected value is determined based on the Authentication Code in the BGP OPEN message and the actual authentication mechanism (that second part only kicks in when the Authentication Code in the OPEN is non-zero) ๐ If the Marker field isn't the expected one, that's a synchronization error ๐ฌ and the Error Subcode is set to Connection Not Synchronized.
If any of the following happens, the Error Subcode is set to Bad Message Length ๐
- the
Lengthfield of the message header is less than 19 or greater than 4096, - the
Lengthfield of an OPEN message is less than the minimum length of an OPEN message, - the
Lengthfield of an UPDATE message is less than the minimum length of an UPDATE message, - the
Lengthfield of a KEEPALIVE message is not equal to 19, or - the
Lengthfield of a NOTIFICATION message is less than the minimum length of a NOTIFICATION message.
In that case, the Data field contains the erroneous Length field ๐งพ
If the Type field of the message header isn't recognized, the Error Subcode is set to Bad Message Type, and the Data field contains the erroneous Type field ๐ซ
6.2 OPEN message error handling ๐
Any error spotted while processing the OPEN message gets flagged by sending a NOTIFICATION message with Error Code OPEN Message Error ๐ฉ Once again, the Error Subcode tells you the specific nature of the error ๐
If the version number in the Version field of the received OPEN message isn't supported, the Error Subcode gets set to Unsupported Version Number ๐ข The Data field is a 2-octet unsigned integer that tells the peer the largest locally supported version number that's still lower than the version they bid (as shown in the received OPEN message) ๐ฏ
If the Autonomous System field of the OPEN message is unacceptable, the Error Subcode is set to Bad Peer AS ๐ซ Deciding which Autonomous System numbers are acceptable is outside the scope of this protocol ๐คท
If the Hold Time field of the OPEN message is unacceptable, the Error Subcode MUST be set to Unacceptable Hold Time โณ An implementation MUST reject Hold Time values of one or two seconds ๐
An implementation MAY reject any proposed Hold Time ๐ค And an implementation that does accept a Hold Time MUST use the negotiated value for the Hold Time โ
If the BGP Identifier field of the OPEN message is syntactically incorrect, the Error Subcode is set to Bad BGP Identifier ๐ Being syntactically correct here means the BGP Identifier field represents a valid IP host address ๐
If the Authentication Code of the OPEN message isn't recognized, the Error Subcode is set to Unsupported Authentication Code ๐ If the Authentication Code is zero, the Authentication Data must be of zero length. Otherwise, the Error Subcode is set to Authentication Failure ๐จ
If the Authentication Code is non-zero, the matching authentication procedure gets invoked ๐ชช And if that procedure (based on Authentication Code and Authentication Data) fails, the Error Subcode is set to Authentication Failure ๐
6.3 UPDATE message error handling ๐
okay so every error we catch while processing an UPDATE message gets flagged with a NOTIFICATION message ๐จ using the Error Code UPDATE Message Error. The Error Subcode then spills the tea on exactly what went wrong ๐ซถ
Error checking for an UPDATE message starts with the path attributes ๐. If the Unfeasible Routes Length or Total Attribute Length is way too big (aka if Unfeasible Routes Length + Total Attribute Length + 23 goes past the message Length), the Error Subcode is Malformed Attribute List ๐.
If any recognized attribute has Attribute Flags that clash with its Attribute Type Code, the Error Subcode is Attribute Flags Error ๐. The Data field holds the erroneous attribute (type, length and value).
If any recognized attribute has an Attribute Length that doesn't match the expected length for its attribute type code, the Error Subcode is Attribute Length Error ๐. The Data field holds the erroneous attribute (type, length and value) again, because we love receipts ๐งพ
If any of the mandatory well-known attributes are missing, the Error Subcode is Missing Well-known Attribute ๐ญ. The Data field holds the Attribute Type Code of the missing one.
If any of the mandatory well-known attributes aren't recognized, the Error Subcode is Unrecognized Well-known Attribute ๐คจ. The Data field holds the unrecognized attribute (type, length and value).
If the ORIGIN attribute has an undefined value, the Error Subcode is Invalid Origin Attribute ๐ธ. The Data field holds the unrecognized attribute (type, length and value).
If the NEXT_HOP attribute is syntactically incorrect, the Error Subcode is Invalid NEXT_HOP Attribute ๐. The Data field holds the incorrect attribute (type, length and value). Syntactic correctness just means the NEXT_HOP attribute represents a valid IP host address โ
. Semantic correctness only applies to the external BGP links ๐. It means the interface tied to the IP address in the NEXT_HOP attribute shares a common subnet with the receiving BGP speaker, and it is not the IP address of the receiving BGP speaker ๐ง . If the NEXT_HOP attribute is semantically incorrect, the error should be logged and the route should be ignored ๐. In this case, no NOTIFICATION message should be sent ๐คซ
The AS_PATH attribute gets checked for syntactic correctness ๐ฃ๏ธ. If the path is syntactically incorrect, the Error Subcode is Malformed AS_PATH ๐ฅด.
If an optional attribute is recognized, its value gets checked too ๐. If an error shows up, the attribute is discarded and the Error Subcode is Optional Attribute Error ๐๏ธ. The Data field holds the attribute (type, length and value).
If any attribute appears more than once in the UPDATE message, the Error Subcode is Malformed Attribute List again ๐.
Last but not least, the NLRI field in the UPDATE message gets checked for syntactic validity ๐. If it's syntactically incorrect, the Error Subcode is Invalid Network Field ๐
.
6.4 NOTIFICATION message error handling ๐ฉ
If a peer sends a NOTIFICATION message and there's an error in that message, sadly there's no way to report that error with another NOTIFICATION message ๐ญ. Any error like that, such as an unrecognized Error Code or Error Subcode, should be noticed, logged locally, and brought to the attention of the administration of the peer ๐ฉโ๐ป. How to do that, though, is outside the scope of this document ๐
6.5 Hold Timer Expired error handling โฐ
If a system doesn't receive successive KEEPALIVE and/or UPDATE and/or NOTIFICATION messages within the period set in the Hold Time field of the OPEN message, then a NOTIFICATION message with the Hold Timer Expired Error Code must be sent and the BGP connection closed ๐. Time's up, bestie ๐
6.6 Finite State Machine error handling ๐
Any error the BGP Finite State Machine detects (for example, getting an unexpected event) is flagged by sending a NOTIFICATION message with the Error Code Finite State Machine Error ๐ง
6.7 Cease ๐ฆ
If there are no fatal errors (the ones listed in this section, that is), a BGP peer may choose at any time to close its BGP connection by sending a NOTIFICATION message with the Error Code Cease ๐ซง. BUT, the Cease NOTIFICATION message must not be used when a fatal error from this section actually exists ๐ซ no sneaky Cease when something's actually broken, periodt ๐
6.8 Connection collision detection ๐ซ
If a pair of BGP speakers try to establish a TCP connection to each other at the same time, two parallel connections between that pair might totally get formed ๐. We call this situation a connection collision ๐ฅ. Clearly, one of those connections has to be closed ๐ซ
To figure out which BGP connection to keep during a collision, there's a convention based on the BGP Identifier ๐ชช. The convention is to compare the BGP Identifiers of the peers involved and keep only the connection initiated by the BGP speaker with the higher-valued BGP Identifier ๐
Upon receiving an OPEN message, the local system must examine all of its connections that are in the OpenConfirm state ๐. A BGP speaker may also examine connections in an OpenSent state if it knows the peer's BGP Identifier from outside the protocol ๐ต๏ธโโ๏ธ. If any of those connections go to a remote BGP speaker whose BGP Identifier equals the one in the OPEN message, the local system runs the following collision resolution procedure ๐งช:
- The BGP Identifier of the local system is compared to the BGP Identifier of the remote system (as specified in the OPEN message).
- If the value of the local BGP Identifier is less than the remote one, the local system closes the BGP connection that already exists (the one already in the OpenConfirm state), and accepts the BGP connection initiated by the remote system ๐ค.
- Otherwise, the local system closes the newly created BGP connection (the one tied to the newly received OPEN message), and keeps using the existing one (the one already in the OpenConfirm state) ๐.
Comparing BGP Identifiers is done by treating them as (4-octet long) unsigned integers ๐ข
A connection collision with an existing BGP connection in the Established state causes the newly created connection to be closed, no matter what ๐. Also, a connection collision can't be detected with connections in the Idle, Connect, or Active states ๐ โโ๏ธ
Closing the BGP connection (the result of the collision resolution procedure) is done by sending a NOTIFICATION message with the Error Code Cease ๐ฌ
7. BGP Version Negotiation ๐
BGP speakers may negotiate the protocol version by making several attempts to open a BGP connection, starting with the highest version number each one supports ๐ช. If an open attempt fails with the Error Code OPEN Message Error and the Error Subcode Unsupported Version Number ๐ฅฒ, then the BGP speaker has a few things to work with: the version number it tried, the version number its peer tried, the version number its peer passed back in the NOTIFICATION message, and the version numbers it supports ๐งฉ. If the two peers support one or more versions in common, this lets them quickly figure out the highest common version ๐. To keep BGP version negotiation working, future versions of BGP must keep the format of the OPEN and NOTIFICATION messages ๐ this part is literally the reason it all works, so protect it no matter what ๐
8. BGP Finite State machine โจ
Okay so this section is where BGP gets its whole personality ๐ It's written as a Finite State Machine (FSM), and this part gives you a quick vibe check of what BGP does in each state. There's also a condensed version of the FSM in Appendix 1 ๐
Initially BGP is in the Idle state ๐ธ
Idle state ๐ค
Idle is giving "I refuse all incoming BGP connections, bestie" ๐ โโ๏ธ No resources get allocated to the peer. When the Start event shows up (started by either the system or an operator), the local system sets up all its BGP resources, starts the ConnectRetry timer, and reaches out to the other BGP peer with a transport connection. While that's happening it keeps listening for a connection the remote BGP peer might start, and then it moves to Connect โจ The exact value of the ConnectRetry timer is a local matter, but it SHOULD be sufficiently large to allow TCP initialization. Give TCP time to get ready, periodt ๐ซถ
If a BGP speaker detects an error, it shuts the connection down and goes back to Idle. To get out of Idle, the Start event has to be generated. If that event gets generated automatically, persistent BGP errors may lead to persistent flapping of the speaker ๐ญ To avoid that mess, it is RECOMMENDED that Start events SHOULD NOT be generated immediately for a peer that was previously moved to Idle because of an error. For a peer that was previously moved to Idle because of an error, the time between consecutive generation of Start events, if they're generated automatically, SHALL exponentially increase. The value of the initial timer SHALL be 60 seconds. The time SHALL be doubled for each consecutive retry. The backoff is literally a whole glow-up arc ๐
Any other event received in the Idle state is ignored ๐
Connect state ๐
In Connect, BGP is waiting for the transport protocol connection to finish ๐ง
If the transport protocol connection succeeds, the local system clears the ConnectRetry timer, finishes initialization, sends an OPEN message to its peer, and moves to OpenSent ๐
If the transport protocol connect fails (for example, a retransmission timeout), the local system restarts the ConnectRetry timer, keeps listening for a connection that may be started by the remote BGP peer, and moves to the Active state ๐ฅบ
When the ConnectRetry timer expires, the local system restarts the ConnectRetry timer, starts a transport connection to the other BGP peer, keeps listening for a connection that may be started by the remote BGP peer, and stays in Connect ๐
Start event is ignored in the Active state ๐
For any other event (started by either system or operator), the local system releases all BGP resources tied to this connection and goes back to Idle ๐งน
Active state ๐ท
In Active, BGP is trying to find a peer by starting a transport protocol connection ๐
If the transport protocol connection succeeds, the local system clears the ConnectRetry timer, finishes initialization, sends an OPEN message to its peer, sets its Hold Timer to a large value, and moves to OpenSent. A Hold Timer value of 4 minutes is suggested โณ
When the ConnectRetry timer expires, the local system restarts the ConnectRetry timer, starts a transport connection to the other BGP peer, keeps listening for a connection that may be started by the remote BGP peer, and moves to Connect ๐
If the local system notices that a remote peer is trying to set up a BGP connection with it, and the IP address of that remote peer is not an expected one, the local system restarts the ConnectRetry timer, rejects the attempted connection, keeps listening for a connection that may be started by the remote BGP peer, and stays in Active ๐ซ
Start event is ignored in the Active state ๐
For any other event (started by either system or operator), the local system releases all BGP resources tied to this connection and goes back to Idle ๐งน
OpenSent state ๐จ
In OpenSent, BGP waits for an OPEN message from its peer. When one arrives, every field gets checked for correctness ๐ If the BGP message header checking or the OPEN message checking finds an error (see Section 6.2), or there's a connection collision (see Section 6.8), the local system sends a NOTIFICATION message and moves to Idle ๐
If there are no errors in the OPEN message, BGP sends a KEEPALIVE message and sets a KeepAlive timer โ The Hold Timer, which was originally set to a large value (see above), gets replaced with the negotiated Hold Time value (see section 4.2). If the negotiated Hold Time value is zero, then the Hold Time timer and KeepAlive timers are not started. If the Autonomous System field matches the local Autonomous System number, the connection is an "internal" connection. Otherwise, it's "external". (This will effect UPDATE processing as described below.) Finally, the state changes to OpenConfirm ๐
If a disconnect notification comes in from the underlying transport protocol, the local system closes the BGP connection, restarts the ConnectRetry timer, keeps listening for a connection that may be started by the remote BGP peer, and goes into Active ๐ฅ
If the Hold Timer expires, the local system sends a NOTIFICATION message with the error code Hold Timer Expired and moves to Idle โฐ
For the Stop event (started by either system or operator), the local system sends a NOTIFICATION message with Error Code Cease and moves to Idle ๐
Start event is ignored in the OpenSent state ๐
For any other event, the local system sends a NOTIFICATION message with Error Code Finite State Machine Error and moves to Idle ๐
Whenever BGP changes its state from OpenSent to Idle, it closes the BGP (and transport-level) connection and releases all resources tied to that connection ๐งน
OpenConfirm state ๐ค
In OpenConfirm, BGP waits for a KEEPALIVE or NOTIFICATION message ๐
If the local system receives a KEEPALIVE message, it changes its state to Established ๐
If the Hold Timer expires before a KEEPALIVE message is received, the local system sends a NOTIFICATION message with error code Hold Timer Expired and moves to Idle โฐ
If the local system receives a NOTIFICATION message, it moves to Idle ๐
If the KeepAlive timer expires, the local system sends a KEEPALIVE message and restarts its KeepAlive timer ๐
If a disconnect notification comes in from the underlying transport protocol, the local system moves to Idle ๐ฅฒ
For the Stop event (started by either system or operator), the local system sends a NOTIFICATION message with Error Code Cease and moves to Idle ๐
Start event is ignored in the OpenConfirm state ๐
For any other event, the local system sends a NOTIFICATION message with Error Code Finite State Machine Error and moves to Idle ๐
Whenever BGP changes its state from OpenConfirm to Idle, it closes the BGP (and transport-level) connection and releases all resources tied to that connection ๐งน
Established state ๐
In Established, BGP can swap UPDATE, NOTIFICATION, and KEEPALIVE messages with its peer. This is the main character era ๐โจ
If the local system receives an UPDATE or KEEPALIVE message, it restarts its Hold Timer, as long as the negotiated Hold Time value is non-zero โฑ๏ธ
If the local system receives a NOTIFICATION message, it moves to Idle ๐
If the local system receives an UPDATE message and the UPDATE message error handling procedure (see Section 6.3) finds an error, the local system sends a NOTIFICATION message and moves to Idle ๐จ
If a disconnect notification comes in from the underlying transport protocol, the local system moves to Idle ๐ฅฒ
If the Hold Timer expires, the local system sends a NOTIFICATION message with Error Code Hold Timer Expired and moves to Idle โฐ
If the KeepAlive timer expires, the local system sends a KEEPALIVE message and restarts its KeepAlive timer ๐
Each time the local system sends a KEEPALIVE or UPDATE message, it restarts its KeepAlive timer, unless the negotiated Hold Time value is zero ๐ซถ
For the Stop event (started by either system or operator), the local system sends a NOTIFICATION message with Error Code Cease and moves to Idle ๐
Start event is ignored in the Established state ๐
For any other event, the local system sends a NOTIFICATION message with Error Code Finite State Machine Error and moves to Idle ๐
Whenever BGP changes its state from Established to Idle, it closes the BGP (and transport-level) connection, releases all resources tied to that connection, and deletes all routes derived from that connection ๐๏ธ๐
9. UPDATE Message Handling โจ
okay bestie, so an UPDATE message is only allowed to show up when you're in the Established state ๐
Like, not before ๐ And when one does arrive, every single field gets checked for validity, exactly like Section 6.3 says ๐ซถ
Now the unrecognized attribute stuff, which is lowkey important ๐ค If an optional non-transitive attribute is unrecognized, it just gets quietly ignored ๐คซ But if it's an optional transitive attribute you don't recognize, you flip the Partial bit (that's the third high-order bit in the attribute flags octet) to 1 and keep the attribute, so it can keep getting passed along to other BGP speakers ๐ฆ
And if you DO recognize an optional attribute and its value is valid, then it depends on what type it is. You process it locally, keep it, and update it if needed so it can be propagated to other BGP speakers later ๐
If the UPDATE message has a non-empty WITHDRAWN ROUTES field, the previously advertised routes whose destinations (written as IP prefixes) are contained in that field shall be removed from the Adj-RIB-In ๐๏ธ Then this BGP speaker shall run its Decision Process, because that previously advertised route is no longer available for use ๐ญ
If the UPDATE message contains a feasible route, it shall be placed in the appropriate Adj-RIB-In, and the following additional actions shall be taken. Pay attention, this part is giving main character energy ๐
i) If its Network Layer Reachability Information (NLRI) is identical to the one of a route currently stored in the Adj-RIB-In, then the new route shall replace the older route in the Adj-RIB-In, thus implicitly withdrawing the older route from service. The BGP speaker shall run its Decision Process, since the older route is no longer available for use ๐
ii) If the new route is an overlapping route that is included (see 9.1.4) in an earlier route contained in the Adj-RIB-In, the BGP speaker shall run its Decision Process, since the more specific route has implicitly made a portion of the less specific route unavailable for use ๐
iii) If the new route has identical path attributes to an earlier route contained in the Adj-RIB-In, and is more specific (see 9.1.4) than the earlier route, no further actions are necessary โจ it's already handled, babe
iv) If the new route has NLRI that is not present in any of the routes currently stored in the Adj-RIB-In, then the new route shall be placed in the Adj-RIB-In. The BGP speaker shall run its Decision Process ๐ธ
v) If the new route is an overlapping route that is less specific (see 9.1.4) than an earlier route contained in the Adj-RIB-In, the BGP speaker shall run its Decision Process on the set of destinations described only by the less specific route ๐ง
9.1 Decision Process
okay so the Decision Process is where the magic happens โจ It selects routes for later advertisement by applying the policies in the local Policy Information Base (PIB) to the routes stored in its Adj-RIB-In. The output is the set of routes that will be advertised to all peers, and the selected routes get stored in the local speaker's Adj-RIB-Out ๐
The selection process is basically a function. It takes the attributes of a given route as an argument and returns a non-negative integer that tells you the degree of preference for that route ๐ข Here's the tea ๐ต: the function that calculates the degree of preference for a given route shall not use as its inputs any of the following: the existence of other routes, the non-existence of other routes, or the path attributes of other routes. Route selection then means applying that function to each feasible route one by one, and then picking the one with the highest degree of preference ๐
The Decision Process works on the routes in each Adj-RIB-In, and it's responsible for:
- selection of routes to be advertised to BGP speakers located in the local speaker's autonomous system
- selection of routes to be advertised to BGP speakers located in neighboring autonomous systems
- route aggregation and route information reduction
It all happens in three distinct phases, and each one gets triggered by a different event ๐
a) Phase 1 is responsible for calculating the degree of preference for each route received from a BGP speaker located in a neighboring autonomous system. It also advertises to the other BGP speakers in the local autonomous system the routes that have the highest degree of preference for each distinct destination ๐ฃ
b) Phase 2 is invoked when Phase 1 is done. It's responsible for choosing the best route out of all the available ones for each distinct destination, and for installing each chosen route into the appropriate Loc-RIB ๐
c) Phase 3 is invoked after the Loc-RIB has been modified. It's responsible for disseminating routes in the Loc-RIB to each peer located in a neighboring autonomous system, according to the policies in the PIB. Route aggregation and information reduction can optionally be performed within this phase ๐ฆ
9.1.1 Phase 1: Calculation of Degree of Preference
Phase 1 decision function shall be invoked whenever the local BGP speaker gets an UPDATE message from a peer in a neighboring autonomous system that advertises a new route, a replacement route, or a withdrawn route ๐จ
The Phase 1 decision function is its own separate process, and it finishes once it has no further work to do ๐
The Phase 1 decision function shall lock an Adj-RIB-In before it operates on any route inside it, and shall unlock it after operating on all the new or unfeasible routes inside it ๐
For each newly received or replacement feasible route, the local BGP speaker shall determine a degree of preference. If the route was learned from a BGP speaker in the local autonomous system, then either the value of the LOCAL_PREF attribute shall be taken as the degree of preference, or the local system shall compute it based on preconfigured policy information. If the route was learned from a BGP speaker in a neighboring autonomous system, then the degree of preference shall be computed based on preconfigured policy information. The exact nature of this policy information and the computation involved is a local matter ๐คทโโ๏ธ The local speaker shall then run the internal update process of 9.2.1 to select and advertise the most preferable route ๐
9.1.2 Phase 2: Route Selection
The Phase 2 decision function shall be invoked when Phase 1 is complete. It's its own separate process too, and it finishes when it has no further work to do. Phase 2 shall consider all routes present in the Adj-RIBs-In, including the ones received from BGP speakers in its own autonomous system and the ones received from BGP speakers in neighboring autonomous systems ๐งฉ
The Phase 2 decision function shall be blocked from running while the Phase 3 decision function is in process ๐ง The Phase 2 function shall lock all Adj-RIBs-In before it starts, and shall unlock them when it's done ๐
If the NEXT_HOP attribute of a BGP route points to an address that the local BGP speaker doesn't have a route to in its Loc-RIB, the BGP route SHOULD be excluded from the Phase 2 decision function ๐ โโ๏ธ (that's a big ol' SHOULD, bestie ๐)
For each set of destinations where a feasible route exists in the Adj-RIBs-In, the local BGP speaker shall find the route that has either:
a) the highest degree of preference of any route to the same set of destinations, or
b) is the only route to that destination, or
c) is selected as a result of the Phase 2 tie breaking rules specified in 9.1.2.1.
The local speaker SHALL then install that route in the Loc-RIB, replacing any route to the same destination currently held in the Loc-RIB ๐ The local speaker MUST determine the immediate next hop to the address depicted by the NEXT_HOP attribute of the selected route, by doing a lookup in the IGP and picking one of the possible paths in the IGP ๐บ๏ธ This immediate next hop MUST be used when installing the selected route in the Loc-RIB ๐ And if the route to the address in the NEXT_HOP attribute changes so that the immediate next hop changes, route selection should be recalculated as specified above ๐
Unfeasible routes shall be removed from the Loc-RIB, and the corresponding unfeasible routes shall then be removed from the Adj-RIBs-In ๐งน
9.1.2.1 Breaking Ties (Phase 2)
Okay this is the tie-breaker section and it's kind of dramatic ๐ญ In its Adj-RIBs-In a BGP speaker may have several routes to the same destination with the same degree of preference. But the local speaker can only select one of them for the associated Loc-RIB ๐ค It considers all the equally preferable routes, both the ones from neighboring autonomous systems and the ones from other BGP speakers in the local speaker's autonomous system โ๏ธ
The following tie-breaking procedure assumes that, for each candidate route, all the BGP speakers within an autonomous system can figure out the cost of a path (interior distance) to the address in the route's NEXT_HOP attribute ๐ Ties shall be broken using this algorithm:
a) If the local system is configured to take MULTI_EXIT_DISC into account, and the candidate routes differ in their MULTI_EXIT_DISC attribute, then select the route with the lowest value of the MULTI_EXIT_DISC attribute ๐
b) Otherwise, select the route with the lowest cost (interior distance) to the entity depicted by the NEXT_HOP attribute of the route. If there are several routes with the same cost, the tie gets broken like this ๐
- if at least one of the candidate routes was advertised by the BGP speaker in a neighboring autonomous system, select the route that was advertised by the BGP speaker in a neighboring autonomous system whose BGP Identifier has the lowest value among all other BGP speakers in neighboring autonomous systems;
- otherwise, select the route that was advertised by the BGP speaker whose BGP Identifier has the lowest value. ๐
9.1.3 Phase 3: Route Dissemination ๐ฃ
okay so Phase 3 is where the good routes finally get passed around ๐ bestie, the Phase 3 decision function shall be invoked on completion of Phase 2, or when any of these things happen:
- a) when routes in a
Loc-RIBto local destinations have changed - b) when locally generated routes learned by means outside of BGP have changed
- c) when a new BGP speaker - BGP speaker connection has been established
the Phase 3 function is its own little process ๐ง and it finishes once it has no more work to do. the Phase 3 Routing Decision function shall be blocked from running while the Phase 2 decision function is in process, so no hogging the stage ๐
every route in the Loc-RIB shall get turned into a matching entry in the associated Adj-RIBs-Out. route aggregation and information reduction techniques (see 9.2.4.1) may optionally be applied โจ
for the future of inter-AS multicast, things get extra iconic ๐ a BGP speaker that takes part in inter-AS multicast routing shall advertise a route it receives from one of its external peers, and if it installs that route in its Loc-RIB, it shall advertise it back to the peer it came from. for a BGP speaker that does not take part in inter-AS multicast routing, that advertisement is optional. when you do send one, the NEXT_HOP attribute should be set to the address of the peer. an implementation may also optimize that advertisement by trimming the AS_PATH attribute so it only includes its own AS number and the AS number of the peer that advertised the route. (that trimming requires the ORIGIN attribute to be set to INCOMPLETE.) and on top of that, an implementation is not required to pass optional or discretionary path attributes with such an advertisement ๐ซถ
once the Adj-RIBs-Out and the Forwarding Information Base (FIB) are fully updated, the local BGP speaker shall run the external update process of 9.2.2 ๐ฆ
9.1.4 Overlapping Routes ๐
okay this one is lowkey tricky but so fun ๐ a BGP speaker may send routes with overlapping Network Layer Reachability Information (NLRI) to another BGP speaker. NLRI overlap happens when a set of destinations gets identified in more than one route that doesn't match exactly. since BGP encodes NLRI using IP prefixes, the overlap will always have subset relationships. a route describing a smaller set of destinations (a longer prefix) is more specific than a route describing a bigger set (a shorter prefix). and the other way around: a route describing a bigger set of destinations (a shorter prefix) is less specific than a route describing a smaller set (a longer prefix) ๐
the precedence thing basically splits a less specific route into two parts:
- a set of destinations described only by the less specific route, and
- a set of destinations described by the overlap of the less specific and the more specific routes
when overlapping routes show up in the same Adj-RIB-In, the more specific route shall take precedence, going from most specific to least specific โจ
the overlap is a chunk of the less specific route that is feasible but isn't being used right now ๐ธ so if a more specific route gets withdrawn later, those destinations are still reachable through the less specific route.
if a BGP speaker gets overlapping routes, the Decision Process shall take the meaning of those overlapping routes into account. specifically, if a BGP speaker accepts the less specific route but rejects the more specific route from the same peer, then the destinations in the overlap may not forward along the ASs listed in that route's AS_PATH attribute. so a BGP speaker has these choices:
- a) Install both the less and the more specific routes
- b) Install the more specific route only
- c) Install the non-overlapping part of the less specific route only (that implies de-aggregation)
- d) Aggregate the two routes and install the aggregated route
- e) Install the less specific route only
- f) Install neither route
if a BGP speaker goes with e), it should add the ATOMIC_AGGREGATE attribute to the route. a route that carries the ATOMIC_AGGREGATE attribute can not be de-aggregated, which means its NLRI can not be made more specific. forwarding along a route like that doesn't guarantee that IP packets will actually traverse only the ASs listed in that route's AS_PATH attribute ๐
and if a BGP speaker goes with a), it must not advertise the more general route without the more specific route ๐ซ
9.2 Update-Send Process ๐ฎ
the Update-Send process is in charge of advertising UPDATE messages to all peers ๐ for example, it hands the routes picked by the Decision Process out to other BGP speakers, which might be in the same autonomous system or in a neighboring one. the rules for swapping info between BGP speakers in different autonomous systems are in 9.2.2, and the rules for speakers in the same autonomous system are in 9.2.1.
sharing routing info between a group of BGP speakers that are all in the same autonomous system is called internal distribution ๐
9.2.1 Internal Updates ๐ซง
the Internal update process is all about sending routing info to BGP speakers inside the local speaker's own autonomous system.
when a BGP speaker gets an UPDATE message from another BGP speaker in its own autonomous system, the receiving speaker shall not re-distribute the routing info in that UPDATE message to other BGP speakers in its own autonomous system. no echo chamber here ๐
โโ๏ธ
when a BGP speaker gets a new route from a BGP speaker in a neighboring autonomous system, it shall advertise that route to all the other BGP speakers in its autonomous system with an UPDATE message if any of these conditions happen:
- 1) the degree of preference that the local BGP speaker gives the newly received route is higher than the degree of preference the local speaker has given to other routes received from BGP speakers in neighboring autonomous systems, or
- 2) there are no other routes that have been received from BGP speakers in neighboring autonomous systems, or
- 3) the newly received route is selected as a result of breaking a tie between several routes that have the highest degree of preference, and the same destination (the tie-breaking procedure is specified in 9.2.1.1).
when a BGP speaker gets an UPDATE message with a non-empty WITHDRAWN ROUTES field, it shall remove from its Adj-RIB-In all routes whose destinations were carried in that field (as IP prefixes). the speaker shall also take these extra steps:
- 1) if the corresponding feasible route had not been previously advertised, then no further action is necessary
- 2) if the corresponding feasible route had been previously advertised, then:
- i) if a new route is selected for advertisement that has the same Network Layer Reachability Information as the unfeasible routes, then the local BGP speaker shall advertise the replacement route
- ii) if a replacement route is not available for advertisement, then the BGP speaker shall include the destinations of the unfeasible route (in the form of IP prefixes) in the
WITHDRAWN ROUTESfield of anUPDATEmessage, and shall send this message to each peer it had previously advertised the corresponding feasible route to
all feasible routes that get advertised shall be placed in the appropriate Adj-RIBs-Out, and all unfeasible routes that get advertised shall be removed from the Adj-RIBs-Out ๐งน
9.2.1.1 Breaking Ties (Internal Updates) โ๏ธ
okay so if a local BGP speaker is connected to several BGP speakers in neighboring autonomous systems, it ends up with multiple Adj-RIBs-In tied to those peers ๐ฅน those Adj-RIBs-In might hold several equally good routes to the same destination, and every one of them came from a speaker in a neighboring autonomous system. the local BGP speaker shall pick one of them using these rules:
- a) If the candidate routes differ only in their
NEXT_HOPandMULTI_EXIT_DISCattributes, and the local system is configured to take into account theMULTI_EXIT_DISCattribute, select the route that has the lowest value of theMULTI_EXIT_DISCattribute. - b) If the local system can ascertain the cost of a path to the entity depicted by the
NEXT_HOPattribute of the candidate route, select the route with the lowest cost. - c) In all other cases, select the route that was advertised by the BGP speaker whose BGP Identifier has the lowest value.
9.2.2 External Updates ๐
the external update process is about sending routing info to BGP speakers in neighboring autonomous systems โ๏ธ as part of the Phase 3 route selection process, the BGP speaker has updated its Adj-RIBs-Out and its Forwarding Table. all newly installed routes, plus all newly unfeasible routes that have no replacement route, shall be advertised to BGP speakers in neighboring autonomous systems with an UPDATE message.
any routes in the Loc-RIB that are marked as unfeasible shall be removed ๐๏ธ and changes to the reachable destinations inside its own autonomous system shall also be advertised in an UPDATE message.
9.2.3 Controlling Routing Traffic Overhead ๐ฆ
BGP keeps a tight leash on how much routing traffic (that is, UPDATE messages) gets sent ๐ the goal is to limit both the link bandwidth needed to advertise UPDATE messages and the processing power the Decision Process needs to digest the info inside them โจ
9.2.3.1 Frequency of Route Advertisement โฑ๏ธ
Okay so MinRouteAdvertisementInterval is the timer that keeps a BGP speaker from spamming route ads ๐. It determines the minimum amount of time that MUST elapse between advertisements of routes to a particular destination from a single BGP speaker. This rate limiting procedure is per-destination, even though the value itself gets set per BGP peer. ๐
Two UPDATE messages sent from one BGP speaker that advertise feasible routes to some common set of destinations (learned from BGP speakers in neighboring autonomous systems) MUST be separated by at least MinRouteAdvertisementInterval. Clearly, the only way to hit that exactly is a separate timer for every common set of destinations, and that would be unwarranted overhead ๐ฉ. So any technique that keeps the gap at least MinRouteAdvertisementInterval, and also keeps a constant upper bound on that gap, is acceptable โจ.
Since fast convergence is needed inside an autonomous system, this procedure does not apply to routes received from other BGP speakers in the same autonomous system ๐โโ๏ธ. To avoid long-lived black holes ๐ณ๏ธ, it also doesn't apply to the explicit withdrawal of unfeasible routes. Those are the routes whose destinations (expressed as IP prefixes) are listed in the WITHDRAWN ROUTES field of an UPDATE message.
This procedure doesn't limit the rate of route selection, only the rate of route advertisement ๐ง . If new routes get selected multiple times while waiting for MinRouteAdvertisementInterval to expire, the last route selected SHALL be advertised at the end of MinRouteAdvertisementInterval ๐ฏ.
9.2.3.2 Frequency of Route Origination ๐ฑ
The parameter MinASOriginationInterval determines the minimum amount of time that MUST elapse between successive advertisements of UPDATE messages that report changes within the advertising BGP speaker's own autonomous systems ๐ฃ.
9.2.3.3 Jitter ๐ฒ
To minimize the chance that the distribution of BGP messages from a given BGP speaker contains peaks, jitter SHOULD be applied to the timers associated with MinASOriginationInterval, Keepalive, and MinRouteAdvertisementInterval. A given BGP speaker SHALL apply the same jitter to each of these quantities, regardless of the destinations the updates are being sent to. So jitter will not be applied on a "per peer" basis ๐
โโ๏ธ.
The amount of jitter to be introduced SHALL be determined by multiplying the base value of the appropriate timer by a random factor, uniformly distributed in the range from 0.75 to 1.0 ๐ฐ.
9.2.4 Efficient Organization of Routing Information ๐๏ธ
Once a BGP speaker has selected the routing information it's going to advertise, it MAY make use of several methods to organize that information efficiently ๐ซ.
9.2.4.1 Information Reduction ๐ง
Information reduction may imply a reduction in granularity of policy control. After information is collapsed, the same policies will apply to all destinations and paths in the equivalence class.
The Decision Process MAY optionally reduce the amount of information it places in the Adj-RIBs-Out by using any of the following methods:
a) Network Layer Reachability Information (NLRI):
Destination IP addresses can be represented as IP address prefixes. Where the address structure lines up with the systems under control of an autonomous system administrator, it will be possible to shrink the NLRI carried in UPDATE messages ๐.
b) AS_PATHs:
AS path information can be represented as ordered AS_SEQUENCEs or unordered AS_SETs. AS_SETs are used in the route aggregation algorithm described in 9.2.4.2. They reduce the size of the AS_PATH information by listing each AS number only once, no matter how many times it may have appeared in multiple AS_PATHs that were aggregated.
An AS_SET implies that the destinations listed in the NLRI can be reached through paths that traverse at least some of the constituent autonomous systems. AS_SETs provide enough information to avoid routing information looping โ
. However, their use may prune potentially feasible paths, since those paths are no longer listed individually as AS_SEQUENCEs. In practice this is not likely to be a problem. Once an IP packet reaches the edge of a group of autonomous systems, the BGP speaker there is likely to have more detailed path information and can tell individual paths to destinations apart ๐ต๏ธโโ๏ธ.
9.2.4.2 Aggregating Routing Information ๐งฉ
Aggregation is the process of combining the characteristics of several different routes so that a single route can be advertised. It can happen as part of the decision process, to cut down the amount of routing information placed in the Adj-RIBs-Out ๐ฆ.
Aggregation reduces the amount of information that a BGP speaker must store and exchange with other BGP speakers. Routes can be aggregated by applying the following procedure separately to path attributes of like type and to the Network Layer Reachability Information.
Routes that have the following attributes SHALL NOT be aggregated unless the corresponding attributes of each route are identical: MULTI_EXIT_DISC, NEXT_HOP.
Path attributes that have different type codes can not be aggregated together. Path of the same type code MAY be aggregated, according to the following rules:
ORIGIN attribute: If at least one route among the routes that are aggregated has ORIGIN with the value INCOMPLETE, then the aggregated route MUST have the ORIGIN attribute with the value INCOMPLETE. Otherwise, if at least one route among the routes that are aggregated has ORIGIN with the value EGP, then the aggregated route MUST have the origin attribute with the value EGP. In all other cases, the value of the ORIGIN attribute of the aggregated route is INTERNAL.
AS_PATH attribute: If routes to be aggregated have identical AS_PATH attributes, then the aggregated route has the same AS_PATH attribute as each individual route.
For the purpose of aggregating AS_PATH attributes, we model each AS within the AS_PATH attribute as a tuple <type, value>. Here "type" identifies the type of path segment the AS belongs to (e.g., AS_SEQUENCE, AS_SET), and "value" is the AS number. If the routes to be aggregated have different AS_PATH attributes, then the aggregated AS_PATH attribute SHALL satisfy all of the following conditions:
- all tuples of the type
AS_SEQUENCEin the aggregatedAS_PATHSHALL appear in all of theAS_PATHin the initial set of routes to be aggregated. - all tuples of the type
AS_SETin the aggregatedAS_PATHSHALL appear in at least one of theAS_PATHin the initial set (they MAY appear as eitherAS_SETorAS_SEQUENCEtypes). - for any tuple X of the type
AS_SEQUENCEin the aggregatedAS_PATHwhich precedes tuple Y in the aggregatedAS_PATH, X precedes Y in eachAS_PATHin the initial set which contains Y, regardless of the type of Y. - No tuple with the same value SHALL appear more than once in the aggregated
AS_PATH, regardless of the tuple's type.
An implementation MAY choose any algorithm which conforms to these rules. At a minimum, a conformant implementation SHALL be able to perform the following algorithm, which meets all of the above conditions:
- determine the longest leading sequence of tuples (as defined above) common to all the
AS_PATHattributes of the routes to be aggregated. Make this sequence the leading sequence of the aggregatedAS_PATHattribute. - set the type of the rest of the tuples from the
AS_PATHattributes of the routes to be aggregated toAS_SET, and append them to the aggregatedAS_PATHattribute. - if the aggregated
AS_PATHhas more than one tuple with the same value (regardless of tuple's type), eliminate all but one such tuple by deleting tuples of the typeAS_SETfrom the aggregatedAS_PATHattribute.
Appendix 6, section 6.8 presents another algorithm that satisfies the conditions and allows for more complex policy configurations ๐ง .
ATOMIC_AGGREGATE: If at least one of the routes to be aggregated has the ATOMIC_AGGREGATE path attribute, then the aggregated route SHALL have this attribute as well ๐.
AGGREGATOR: All AGGREGATOR attributes of all routes to be aggregated SHOULD be ignored.
9.3 Route Selection Criteria ๐ฏ
Generally speaking, additional rules for comparing routes among several alternatives are outside the scope of this document. There are two exceptions:
- If the local AS appears in the AS path of the new route being considered, then that new route cannot be viewed as better than any other route. If such a route were ever used, a routing loop would result ๐.
- In order to achieve successful distributed operation, only routes with a likelihood of stability can be chosen. Thus, an AS MUST avoid using unstable routes, and it MUST NOT make rapid spontaneous changes to its choice of route. Quantifying the terms "unstable" and "rapid" in the previous sentence will require experience, but the principle is clear ๐งโโ๏ธ.
9.4 Originating BGP routes ๐
A BGP speaker MAY originate BGP routes by injecting routing information acquired by some other means (e.g., via an IGP) into BGP. A BGP speaker that originates BGP routes SHALL assign the degree of preference to these routes by passing them through the Decision Process (see Section 9.1). These routes MAY also be distributed to other BGP speakers within the local AS as part of the Internal update process (see Section 9.2.1).
The decision whether to distribute non-BGP acquired routes within an AS via BGP or not depends on the environment within the AS (e.g., type of IGP), and it SHOULD be controlled via configuration ๐.
Appendix 1. BGP FSM State Transitions and Actions โจ
okay bestie, this one is the BGP FSM ๐ฆ basically a map of what happens when a thing goes down (a state) and something happens to it (an event). this covers the case where the negotiated Hold Time value is non-zero ๐ซถ
Here are the states:
1 - Idle
2 - Connect
3 - Active
4 - OpenSent
5 - OpenConfirm
6 - Established
And here are the events ๐
1 - BGP Start
2 - BGP Stop
3 - BGP Transport connection open
4 - BGP Transport connection closed
5 - BGP Transport connection open failed
6 - BGP Transport fatal error
7 - ConnectRetry timer expired
8 - Hold Timer expired
9 - KeepAlive timer expired
10 - Receive OPEN message
11 - Receive KEEPALIVE message
12 - Receive UPDATE messages
13 - Receive NOTIFICATION message
The big table is the main event ๐ For each state and event, it tells you what actions fire, what message gets sent (if any), and which state you land in next. It's a lot, so take your time ๐
Event Actions Message Sent Next State
--------------------------------------------------------------------
Idle (1)
1 Initialize resources none 2
Start ConnectRetry timer
Initiate a transport connection
others none none 1
Connect(2)
1 none none 2
3 Complete initialization OPEN 4
Clear ConnectRetry timer
5 Restart ConnectRetry timer none 3
7 Restart ConnectRetry timer none 2
Initiate a transport connection
others Release resources none 1
Active (3)
1 none none 3
3 Complete initialization OPEN 4
Clear ConnectRetry timer
5 Close connection 3
Restart ConnectRetry timer
7 Restart ConnectRetry timer none 2
Initiate a transport connection
others Release resources none 1
OpenSent(4)
1 none none 4
4 Close transport connection none 3
Restart ConnectRetry timer
6 Release resources none 1
10 Process OPEN is OK KEEPALIVE 5
Process OPEN failed NOTIFICATION 1
others Close transport connection NOTIFICATION 1
Release resources
OpenConfirm (5)
1 none none 5
4 Release resources none 1
6 Release resources none 1
9 Restart KeepAlive timer KEEPALIVE 5
11 Complete initialization none 6
Restart Hold Timer
13 Close transport connection 1
Release resources
others Close transport connection NOTIFICATION 1
Release resources
Established (6)
1 none none 6
4 Release resources none 1
6 Release resources none 1
9 Restart KeepAlive timer KEEPALIVE 6
11 Restart Hold Timer KEEPALIVE 6
12 Process UPDATE is OK UPDATE 6
Process UPDATE failed NOTIFICATION 1
13 Close transport connection 1
Release resources
others Close transport connection NOTIFICATION 1
Release resources
---------------------------------------------------------------------
Okay, if the big table feels like a lot, here's the condensed one ๐ธ It's the same info squished into a grid, with states across the top and events down the side โจ
Events| Idle | Connect | Active | OpenSent | OpenConfirm | Estab
| (1) | (2) | (3) | (4) | (5) | (6)
|---------------------------------------------------------------
1 | 2 | 2 | 3 | 4 | 5 | 6
| | | | | |
2 | 1 | 1 | 1 | 1 | 1 | 1
| | | | | |
3 | 1 | 4 | 4 | 1 | 1 | 1
| | | | | |
4 | 1 | 1 | 1 | 3 | 1 | 1
| | | | | |
5 | 1 | 3 | 3 | 1 | 1 | 1
| | | | | |
6 | 1 | 1 | 1 | 1 | 1 | 1
| | | | | |
7 | 1 | 2 | 2 | 1 | 1 | 1
| | | | | |
8 | 1 | 1 | 1 | 1 | 1 | 1
| | | | | |
9 | 1 | 1 | 1 | 1 | 5 | 6
| | | | | |
10 | 1 | 1 | 1 | 1 or 5 | 1 | 1
| | | | | |
11 | 1 | 1 | 1 | 1 | 6 | 6
| | | | | |
12 | 1 | 1 | 1 | 1 | 1 | 1 or 6
| | | | | |
13 | 1 | 1 | 1 | 1 | 1 | 1
| | | | | |
---------------------------------------------------------------
Appendix 2. Comparison with RFC 1267
okay so BGP-4 can work in an environment where a whole set of reachable destinations gets expressed with one IP prefix ๐ network classes and subnetting? totally foreign to BGP-4 ๐ so to make that work, BGP-4 changed the semantics and encoding of the AS_PATH attribute, and new text was added to define what IP prefixes mean. those upgrades let BGP-4 support the proposed supernetting scheme [9] ๐
to keep configuration simple, this version adds a brand new attribute called LOCAL_PREF, which helps with route selection procedures โจ
INTER_AS_METRIC got renamed to MULTI_EXIT_DISC ๐ there's also a new attribute, ATOMIC_AGGREGATE, which makes sure certain aggregates don't get de-aggregated ๐ฅ and AGGREGATOR is a new one that can be added to aggregated routes to show which AS, and which BGP speaker inside that AS, did the aggregating ๐
to make sure Hold Timers are symmetric, the Hold Time is now negotiated on a per-connection basis. and Hold Times of zero are supported now too ๐ง
Appendix 3. Comparison with RFC 1163
all of the changes in Appendix 2, plus these ๐ฆ
to detect and recover from a BGP connection collision, there's a new field (BGP Identifier) in the OPEN message ๐ new text (Section 6.8) lays out the procedure for detecting and recovering from collision ๐ซถ
the new document doesn't restrict the border router passed in the NEXT_HOP path attribute to be part of the same Autonomous System as the BGP Speaker anymore ๐ธ
and the new document optimizes and simplifies the exchange of info about previously reachable routes ๐
Appendix 4. Comparison with RFC 1105
all of the changes in Appendices 2 and 3, plus these ๐
minor changes to the RFC1105 Finite State Machine were needed to fit the TCP user interface provided by 4.3 BSD ๐
the whole notion of Up/Down/Horizontal relations from RFC1105 got removed from the protocol ๐
and the message format changes from RFC1105 go like this:
- The Hold Time field has been removed from the BGP header and added to the OPEN message.
- The version field has been removed from the BGP header and added to the OPEN message.
- The Link Type field has been removed from the OPEN message.
- The OPEN CONFIRM message has been eliminated and replaced with implicit confirmation provided by the KEEPALIVE message.
- The format of the UPDATE message has been changed significantly. New fields were added to the UPDATE message to support multiple path attributes.
- The Marker field has been expanded and its role broadened to support authentication.
okay so the naming situation is a whole thing ๐ quite often BGP as specified in RFC 1105 is called BGP-1, BGP as specified in RFC 1163 is called BGP-2, BGP as specified in RFC1267 is called BGP-3, and BGP as specified in this document is called BGP-4 ๐
Appendix 5. TCP options that may be used with BGP
okay so if the local system's TCP user interface supports the TCP PUSH function, then each BGP message should be transmitted with the PUSH flag set ๐ setting the PUSH flag forces BGP messages to be transmitted promptly to the receiver โญ
and if a local system TCP user interface supports setting precedence for a TCP connection, then the BGP transport connection should be opened with precedence set to Internetwork Control (110) value (see also [6]) ๐
Appendix 6. Implementation Recommendations
okay, this section is where the implementation recommendations live ๐ง buckle up ๐ซถ
6.1 Multiple Networks Per Message ๐
okay bestie, so BGP lets you cram multiple networks that share the same AS path and next-hop gateway into ONE message ๐ฆโจ. Making use of this capability is highly recommended ๐ซถ. Here's the tea: with one network per message, the receiver's overhead goes way up ๐ญ. It's not just receiving all those extra messages. It's also scanning the routing table for updates to BGP peers and other routing protocols (and sending the associated messages) over and over again ๐.
One way to build messages with lots of networks per AS path and gateway, from a routing table that isn't organized per AS path, is to build the messages while you scan the table ๐๏ธ. As each network gets processed, you allocate a message for its AS path and gateway if one doesn't exist yet, then add the network to it. If that message already exists, the new network just gets appended ๐. If the message doesn't have room for the new network, you send it, allocate a fresh one, and insert the network there ๐. When the whole table has been scanned, you send every allocated message and release the resources ๐งน. Maximum compression happens when all networks share a gateway and common path attributes, so you can fit a bunch of networks into one 4096-byte message ๐.
When you're peering with a BGP implementation that doesn't compress multiple networks into one message, it may be necessary to take steps to cut down on the overhead from the flood of data you get when a peer is acquired or a significant network topology change happens ๐. One method is to limit the rate of updates ๐ข. This eliminates the redundant scanning of the routing table to provide flash updates for BGP peers and other routing protocols ๐. The catch? It increases the propagation latency of routing information ๐ฌ. Choosing a minimum flash update interval that isn't much greater than the time it takes to process the multiple messages keeps that latency as low as possible โฑ๏ธ. Honestly, a better method is to read all received messages before sending updates ๐.
6.2 Processing Messages on a Stream Protocol ๐
BGP uses TCP as its transport mechanism ๐งต. Because TCP is a stream, all the data for a received message doesn't necessarily arrive at the same time ๐ตโ๐ซ. That makes it hard to process the data as messages, especially on systems like BSD Unix, where you can't tell how much data has been received but not yet processed ๐.
One method for this situation is to first try to read just the message header ๐จ. For the KEEPALIVE message type, that's a complete message ๐ฅฐ. For other message types, the header should first be verified, in particular the total length ๐. If all the checks are successful, the specified length minus the size of the message header is the amount of data left to read โ๏ธ. An implementation that would "hang" the routing information process while trying to read from a peer could set up a message buffer (4096 bytes) per peer and fill it with data as it becomes available, until a complete message has been received ๐ซง.
6.3 Reducing route flapping ๐ฆ
To avoid excessive route flapping, a BGP speaker that needs to withdraw a destination and send an update about a more specific or less specific route shall combine them into the same UPDATE message ๐
.
6.4 BGP Timers โฐ
BGP employs five timers: ConnectRetry, Hold Time, KeepAlive, MinASOriginationInterval, and MinRouteAdvertisementInterval. The suggested value for the ConnectRetry timer is 120 seconds. The suggested value for the Hold Time is 90 seconds. The suggested value for the KeepAlive timer is 30 seconds. The suggested value for the MinASOriginationInterval is 15 seconds. The suggested value for the MinRouteAdvertisementInterval is 30 seconds.
An implementation of BGP MUST allow these timers to be configurable. โ๏ธ๐
6.5 Path attribute ordering ๐งฉ
Implementations that combine update messages as described above in 6.1 may prefer to see all path attributes presented in a known order โจ. That lets them quickly spot sets of attributes from different update messages that are semantically identical ๐. To make this happen, it's a useful optimization to order the path attributes according to type code ๐ข. This optimization is entirely optional ๐.
6.6 AS_SET sorting ๐ค
Another useful optimization that can be done to simplify this situation is to sort the AS numbers found in an AS_SET ๐ง. This optimization is entirely optional ๐ซถ.
6.7 Control over version negotiation ๐๏ธ
Since BGP-4 is capable of carrying aggregated routes that cannot be properly represented in BGP-3, an implementation that supports BGP-4 and another BGP version should provide the capability to only speak BGP-4 on a per-peer basis ๐ธ.
6.8 Complex AS_PATH aggregation ๐งต
An implementation that chooses to provide a path aggregation algorithm that retains significant amounts of path information may wish to use the following procedure ๐ซ.
For the purpose of aggregating AS_PATH attributes of two routes, we model each AS as a tuple <type, value>, where "type" identifies a type of the path segment the AS belongs to (e.g., AS_SEQUENCE, AS_SET), and "value" is the AS number. Two ASs are said to be the same if their corresponding <type, value> tuples are the same.
The algorithm to aggregate two AS_PATH attributes works as follows:
a) Identify the same ASs (as defined above) within each AS_PATH attribute that are in the same relative order within both AS_PATH attributes. Two ASs, X and Y, are said to be in the same order if either:
- X precedes Y in both
AS_PATHattributes, or - Y precedes X in both
AS_PATHattributes.
b) The aggregated AS_PATH attribute consists of ASs identified in (a) in exactly the same order as they appear in the AS_PATH attributes to be aggregated. If two consecutive ASs identified in (a) do not immediately follow each other in both of the AS_PATH attributes to be aggregated, then the intervening ASs (ASs that are between the two consecutive ASs that are the same) in both attributes are combined into an AS_SET path segment that consists of the intervening ASs from both AS_PATH attributes; this segment is then placed in between the two consecutive ASs identified in (a) of the aggregated attribute. If two consecutive ASs identified in (a) immediately follow each other in one attribute, but do not follow in another, then the intervening ASs of the latter are combined into an AS_SET path segment; this segment is then placed in between the two consecutive ASs identified in (a) of the aggregated attribute.
If as a result of the above procedure a given AS number appears more than once within the aggregated AS_PATH attribute, all, but the last instance (rightmost occurrence) of that AS number should be removed from the aggregated AS_PATH attribute. ๐งน
References ๐
[1] Mills, D., "Exterior Gateway Protocol Formal Specification", STD 18, RFC 904, BBN, April 1984.
[2] Rekhter, Y., "EGP and Policy Based Routing in the New NSFNET Backbone", RFC 1092, T.J. Watson Research Center, February 1989.
[3] Braun, H-W., "The NSFNET Routing Architecture", RFC 1093, MERIT/NSFNET Project, February 1989.
[4] Postel, J., "Transmission Control Protocol - DARPA Internet Program Protocol Specification", RFC 793, DARPA, September 1981.
[5] Rekhter, Y., and P. Gross, "Application of the Border Gateway Protocol in the Internet", T.J. Watson Research Center, IBM Corp., ANS, RFC 1655, T.J. Watson Research Center, MCI, July 1994.
[6] Postel, J., "Internet Protocol - DARPA Internet Program Protocol Specification", STD 5, RFC 791, DARPA, September 1981.
[7] "Information Processing Systems - Telecommunications and Information Exchange between Systems - Protocol for Exchange of Inter-domain Routeing Information among Intermediate Systems to Support Forwarding of ISO 8473 PDUs", ISO/IEC IS10747, 1993
[8] Fuller, V., Li, T., Yu, J., and K. Varadhan, "Classless Inter-Domain Routing (CIDR): an Address Assignment and Aggregation Strategy", RFC 1519, BARRNet, cisco, MERIT, OARnet, September 1993.
[9] Rekhter, Y., and T. Li, "An Architecture for IP Address Allocation with CIDR", RFC 1518, T.J. Watson Research Center, cisco, September 1993.
Security Considerations ๐
Plot twist: this memo doesn't cover security at all ๐. Security issues are not discussed in this memo.
Editors' Addresses ๐
Yakov Rekhter
T.J. Watson Research Center IBM Corporation
P.O. Box 218
Yorktown Heights, NY 10598
Phone: (914) 945-3896
EMail: yakov@watson.ibm.com
Tony Li
cisco Systems, Inc.
1525 O'Brien Drive
Menlo Park, CA 94025
EMail: tli@cisco.com ๐ฆ
๐ฆ where this page comes from
- ietf: rfc1654 1994-07
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms