Constructing the BGP Table
Joe Astorino [Link] @jastorino
BGP Table Summary
The BGP table contains all the prefixes learned by BGP and the path attributes (PA) associated with those prefixes
In BGP, prefixes are technically called NLRI
The BGP table is actually comprised of three databases
Adj-RIBs-In Raw NLRI / PA information received from peers Loc-RIB The best NLRIs after route policies have been applied Adj-RIBs-Out Routes BGP will advertise to other BGP peers
BGP Table Sources
The local BGP table is built from three different sources
Network command Local Routes
BGP Updates iBGP or eBGP
Redistribution Redistributed
BGP Network Command
The network command adds routes to the local BGP table that the router wishes to advertise into BGP and ultimately send to BGP peers The network command specifies a prefix and a mask. For the prefix to be added to the BGP table, the prefix must match exactly a route already existing in the routing table! The prefix can match existing routes from connected, static or IGPs
R1#show ip interface brief | i Loopback Loopback0 [Link]
YES NVRAM
up
up
R1#show ip route [Link] Routing entry for [Link]/32 Known via "connected", distance 0, metric 0 (connected, via interface) R1#sh run | section bgp router bgp 65123 network [Link] mask [Link]
Redistribution into BGP
Connected, static and IGP routes may be redistributed into BGP Many times the redistribution is tied to a route-map in order to manipulate the attributes of the redistributed prefixes By default, when redistributing OSPF into BGP, only intra and interarea routes are allowed. This can be changed during the redistribution
ip prefix-list AS65123 seq 5 permit [Link]/24 ge 26 le 26 ip prefix-list AS65123 seq 10 permit [Link]/29 ! route-map CONNECTED-BGP permit 10 match ip address prefix-list AS65123 set metric 100 set community 65123:110 ! router bgp 65123 network [Link] mask [Link] redistribute connected route-map CONNECTED-BGP redistribute ospf 1 match internal external 1 external 2 nssa-external
Auto Summarization
auto-summary summarizes prefixes added to BGP at classful boundaries The behavior is different depending on if the prefixes were added with the network command or through redistribution The default is no auto-summary since IOS 12.3
Redistribution Redistribute only the classful network Network Command Inject more specific and summary
BGP Path Attributes
A BGP path attribute (PA) is a characteristic of a BGP prefix Ultimately, BGP uses path attributes and the BGP best path selection algorithm to select a valid and best path for each NLRI Path attributes are categorized into one of four groups
Well-known
mandatory discretionary
Optional
transitive nontransitive
Path Attributes
Attribute ORIGIN AS_PATH NEXT_HOP LOCAL_PREF ATOMIC_AGGREGATE AGGREGATOR COMMUNITY MULTI_EXIT_DISC ORIGINATOR_ID CLUSTER_LIST Class well-known mandatory well-known mandatory well-known mandatory well-known discretionary well-known discretionary optional transitive optional transitive optional nontransitive optional nontransitive optional nontransitive
ORIGIN Path Attribute
How was this prefix entered into BGP? Where did it come from?
IGP (i)
Prefix was learned internal to the AS Prefixes added to BGP with the network command
EGP (e)
Prefix was learned via EGP
Incomplete (?)
Prefix was learned through some other method Redistributed routes have an origin of incomplete
ORIGIN Path Attribute
R1#show ip bgp | i [Link] BGP table version is 188, local router ID is [Link] *> [Link]/32 [Link] 0
32768 i
R1#show ip bgp [Link] | b Origin Origin IGP, metric 0, localpref 100, weight 32768, valid, sourced, local, best R1#show ip bgp | i [Link] *>i10.0.45.0/30 [Link] 0 100 0 65004 ?
R1#show ip bgp [Link] | b Origin Origin incomplete, metric 0, localpref 100, valid, internal, best
AS_PATH Path Attribute
Generally, AS_PATH lists all the AS a prefix has gone through A router drops any BGP prefix that contains its own AS in the AS_PATH AS_PATH influences inbound routing (shortest AS_PATH wins) Technically, AS_PATH can contain four different sub-components
AS_SEQ
Ordered list of AS numbers
AS_SET
Unordered set of AS numbers enclosed in { } Used when prefixes have been aggregated
AS_CONFED_SEQUENCE
Similar to AS_SEQ but used in confederations
AS_CONFED_SET
Similar to AS_SET but used in confederations
AS_PATH Path Attribute
Router#sh ip bgp | b 10.64 *> [Link]/16 [Link] *> [Link]/16 [Link] *> [Link]/16 [Link] *> [Link]/16 [Link]
500 500 500 500
0 0 0 0
13979 13979 13979 13979
21326 21326 21326 21326
4809 65103 i 4809 65106 i 4809 65107 i 65109 i
Router#sh ip bgp [Link] BGP routing table entry for [Link]/16, version 2698 Paths: (1 available, best #1, table default) Advertised to update-groups: 1 2 Refresh Epoch 1 13979 21326 4809 65103, (aggregated by 65103 [Link]) [Link] from [Link] ([Link]) Origin IGP, localpref 500, valid, external, atomic-aggregate, best Community: 13979:5000
LOCAL_PREF Path Attribute
Local Preference Influences outbound path. Default is 100 and highest wins Well-known discretionary attribute only sent between iBGP peers
Diagram courtesy [Link]
Configuring LOCAL_PREF
ip prefix-list PREFER_ME_PLEASE permit [Link]/32 ! route-map SET_LOCAL_PREF permit 10 match ip address prefix-list PREFER_ME_PLEASE set local-preference 500 ! router bgp 65123 neighbor [Link] route-map SET_LOCAL_PREF in ! R5#sh ip bgp [Link] BGP routing table entry for [Link]/32, version 183 Paths: (2 available, best #2, table Default-IP-Routing-Table) Advertised to update-groups: 2 65004 65123 [Link] (metric 156160) from [Link] ([Link]) Origin IGP, metric 0, localpref 100, valid, internal 65004 65123 [Link] from [Link] ([Link]) Origin IGP, localpref 500, valid, external, best
MULTI_EXIT_DISC Path Attribute
Multi-Exit-Discriminator (MED), sometimes known as metric Optional nontransitive attribute that influences inbound routing Default value is 0 and lowest wins MED is only compared when prefixes are coming from the same AS!!!
Diagram courtesy [Link]
Configuring MED
ip prefix-list PREFER_ME_PLEASE permit [Link]/32 ! route-map SET_MED permit 10 match ip address prefix-list PREFER_ME_PLEASE set metric 50 ! route-map SET_MED permit 20 set metric 100 ! router bgp 65123 neighbor [Link] route-map SET_MED out ! R5#sh ip bgp [Link] BGP routing table entry for [Link]/32, version 183 Paths: (2 available, best #2, table Default-IP-Routing-Table) Advertised to update-groups: 2 65004 65123 [Link] (metric 156160) from [Link] ([Link]) Origin IGP, metric 50, localpref 100, valid, internal 65004 65123 [Link] from [Link] ([Link]) Origin IGP, localpref 500, valid, external, best
ATOMIC_AGGREGATE Path Attribute
When aggregating prefixes that came from different AS_PATHs, AS_PATH information is lost When aggregating, BGP sets the ATOMIC_AGGREGATE path attribute
Signals to receiving routers that AS_PATH information has been lost A router that receives a prefix with ATOMIC_AGGREGATE set cannot advertise a more specific prefix of the aggregate, and must keep ATOMIC_AGGREGATE set on updates
Additionally, the AGGREGATOR path attribute is set
AGGREGATOR specifies the RID and AS that aggregated the prefix
Configuring BGP Aggregation
At least one subnet of the aggregate must be present By default, BGP will advertise the aggregate and more specific prefix
R5#sh ip bgp | i 172.16.56 *> [Link]/26 [Link] *> [Link]/26 [Link] *>i172.16.56.128/26 [Link] *>i172.16.56.192/26 [Link] router bgp 65056 aggregate-address [Link] [Link] R5#sh ip bgp | i 172.16.56 *> [Link]/26 [Link] *> [Link]/24 [Link] *> [Link]/26 [Link] *>i172.16.56.128/26 [Link] *>i172.16.56.192/26 [Link] 0 0 0 0 100 100 32768 32768 32768 0 0 ? i ? ? ? 0 0 0 0 32768 32768 0 0 ? ? ? ?
100 100
router bgp 65056 aggregate-address [Link] [Link] summary-only R5#sh ip bgp | i 172.16.56 s> [Link]/26 [Link] *> [Link]/24 [Link] s> [Link]/26 [Link] s>i172.16.56.128/26 [Link] s>i172.16.56.192/26 [Link] 0 0 0 0 100 100 32768 32768 32768 0 0 ? i ? ? ?
AS_SET
Due to AS_PATH information being lost during aggregation, routing loops are a possibility The AS_SET path attribute helps address this by placing an unordered list of all the AS from the more specific prefixes into AS_SET Additionally, AS_SEQ is still set to the aggregating routers AS No more need to set ATOMIC_AGGREGATE AS_SET is dynamic If more specific routes downstream fail, AS_SET can be updated on the fly, and those changes are advertised
Configuring AS_SET
Diagram courtesy [Link]
RouterC(config)#router bgp 300 aggregate-adddress [Link] [Link] summary-only as-set
RouterD# show ip bgp | b Network Network *> [Link]/8 Next Hop [Link] Metric LocPrf Weight Path 0 300 {200,100} i
Adding a Default Route to the BGP Table
There are multiple ways to get a default route into the BGP table
network [Link]
[Link]/0 must already exist in the routing table
default-information originate
[Link]/0 must already exist in the routing table Requires redistribution of [Link]/0 to work
neighbor default-originate
Unconditionally advertises [Link]/0 to a specific neighbor
Conditional Default Routing
Option 1: route-map
ip prefix-list MUST_EXIST permit [Link]/32 ! route-map CONDITION permit 10 match ip address prefix-list MUST_EXIST ! Router bgp 65123 neighbor [Link] default-originate route-map CONDITION
Option 2: advertise-map
ip prefix-list MUST_EXIST permit [Link]/32 ip prefix-list DEFAULT_ROUTE permit [Link]/0 ! route-map MUST_EXIST permit 10 match ip address prefix-list MUST_EXIST ! route-map DEFAULT_ROUTE match ip address prefix-list DEFAULT_ROUTE ! router bgp 65123 neighbor [Link] advertise-map DEFAULT_ROUTE exist-map MUST_EXIST
BGP Lab Diagrams
Lab L2/L3 Diagram