There may be multiple routes to the same destination in a BGP routing table. BGP will select one route as the optimal route and advertise it to peers. To select the optimal route among these routes, BGP compares the BGP attributes of the routes in sequence based on route selection rules.
Route attributes describe routes. BGP route attributes are classified into the following types. Table 1 lists common BGP attributes.
Well-known mandatory attribute
All BGP devices can identify this type of attribute, which must be carried in Update messages. Without this type of attribute, errors occur in routing information.
Well-known discretionary attribute
All BGP devices can identify this type of attribute, which is optional in Update messages. Errors do not occur in routing information even if there is a lack of this type of attribute.
Optional transitive attribute
A BGP device may not identify this type of attribute but still accepts and advertises them to peers.
Optional non-transitive attribute
A BGP device may not identify this type of attribute, in which case it ignores them without advertising them to peers.
Attribute | Type |
---|---|
Origin | Well-known mandatory |
AS_Path | Well-known mandatory |
Next_Hop | Well-known mandatory |
Local_Pref | Well-known discretionary |
Community | Optional transitive |
MED | Optional non-transitive |
Originator_ID | Optional non-transitive |
Cluster_List | Optional non-transitive |
The following describes common BGP route attributes:
Origin
The Origin attribute defines the origin of a route and marks the path of a BGP route. The Origin attribute is classified into three types:
IGP
A route with IGP as the Origin attribute has the highest priority. The Origin attribute of the routes imported into a BGP routing table using the network command is IGP.
EGP
A route with EGP as the Origin attribute has the second highest priority. The Origin attribute of the routes obtained through EGP is EGP.
Incomplete
A route with Incomplete as the Origin attribute has the lowest priority. The Origin attribute of the routes learned by other means is Incomplete. For example, the Origin attribute of the routes imported by BGP using the import-route command is Incomplete.
AS_Path
The AS_Path attribute records all of the ASs that a route passes through from the source to the destination in the vector order. To prevent inter-AS routing loops, a BGP device does not receive the routes whose AS_Path list contains the local AS number.
When a BGP speaker advertises an imported route:
If the route is advertised to EBGP peers, the BGP speaker creates an AS_Path list containing the local AS number in an Update message.
If the route is advertised to IBGP peers, the BGP speaker creates an empty AS_Path list in an Update message.
When a BGP speaker advertises a route learned in the Update message sent by another BGP speaker:
If the route is advertised to EBGP peers, the BGP speaker adds the local AS number to the leftmost of the AS_Path list. According to the AS_Path list, the BGP speaker that receives the route can determine the ASs through which the route passes to reach the destination. The number of the AS that is nearest to the local AS is placed on the top of the AS_Path list. The other AS numbers are listed according to the sequence in which the route passes through ASs.
If the route is advertised to IBGP peers, the BGP speaker does not change the AS_Path attribute of the route.
Next_Hop
The Next_Hop attribute records the next hop that a route passes through. The Next_Hop attribute of BGP is different from that of an IGP because it may not be a neighboring IP address. A BGP speaker processes the Next_Hop attribute based on the following rules:
When advertising a route to an EBGP peer, a BGP speaker sets the Next_Hop attribute of the route to the address of the local interface through which the BGP peer relationship is established.
When advertising a locally originated route to an IBGP peer, the BGP speaker sets the Next_Hop attribute of the route to the address of the local interface through which the BGP peer relationship is established.
When advertising a route learned from an EBGP peer to an IBGP peer, the BGP speaker does not change the Next_Hop attribute of the route.
Local_Pref
The Local_Pref attribute indicates the BGP preference of a device and helps determine the optimal route when traffic leaves an AS. When a BGP device obtains multiple routes to the same destination address but with different next hops from different IBGP peers, the BGP device prefers the route with the highest Local_Pref. The Local_Pref attribute is exchanged only between IBGP peers and is not advertised to other ASs. The Local_Pref attribute can be manually configured. If no Local_Pref attribute is configured for a route, the Local_Pref attribute of the route uses the default value 100.
MED
The multi-exit discriminator (MED) attribute helps determine the optimal route when traffic enters an AS. When a BGP device obtains multiple routes to the same destination address but with different next hops from EBGP peers, the BGP device selects the route with the smallest MED value as the optimal route.
The MED attribute is exchanged only between two neighboring ASs. The AS that receives the MED attribute does not advertise it to any other ASs. The MED attribute can be manually configured. If no MED attribute is configured for a route, the MED attribute of the route uses the default value 0.
Community
The Community attribute includes self-defined community attributes and well-known community attributes. Table 2 lists well-known community attributes.
Community Attribute |
Value |
Description |
---|---|---|
Internet |
0 (0x00000000) |
A BGP device can advertise the received route with the Internet attribute to all peers. |
No_Advertise |
4294967042 (0xFFFFFF02) |
A BGP device does not advertise the received route with the No_Advertise attribute to any peer. |
No_Export |
4294967041 (0xFFFFFF01) |
A BGP device does not advertise the received route with the No_Export attribute to devices outside the local AS. |
No_Export_Subconfed |
4294967043 (0xFFFFFF03) |
A BGP device does not advertise the received route with the No_Export_Subconfed attribute to devices outside the local AS or to devices outside the local sub-AS. |
Originator_ID and Cluster_List
The Originator_ID attribute and Cluster_List attribute help eliminate loops in route reflector scenarios. For details, see Route Reflector.