Basic BGP Configuration
When configuring BGP, it is best to think of the configuration from a modular perspective. BGP router configuration requires the following components:
BGP Session Parameters: BGP session parameters provide settings that involve establishing communication to the remote BGP neighbor. Session settings include the ASN of the BGP peer, authentication, and keepalive timers.
Address-Family Initialization: The address-family is initialized under the BGP router configuration mode. Networks advertisement and summarization occur within the address-family.
Activate the Address-Family on the BGP Peer: Activate the address-family on the BGP peer. For a session to initiate, one address-family for that neighbor must be activated. The router’s IP address is added to the neighbor table, and BGP attempts to establish a BGP session or accepts a BGP session initiated from the peer router.
For the remainder of this chapter, the BGP context is directed toward IPv4 routing. Other address families are throughout the book.
IOS
The steps for configuring BGP on an IOS router are as follows:
Step 1. Create the BGP Routing Process. Initialize the BGP process with the global command router bgp as-number.
Step 2. Identify the BGP Neighbor’s IP address and Autonomous System Number. Identify the BGP neighbor’s IP address and autonomous system number with the BGP router configuration command neighbor ip-address remote-as as-number.
Step 3. Initialize the address-family with the BGP router configuration command address-family afi safi.
Step 4. Activate the address-family for the BGP neighbor with the BGP address-family configuration command neighbor ip-address activate.
Example 1-2 demonstrates how to configure R1 and R2 using the IOS default and optional IPv4 AFI modifier CLI syntax. R1 is configured using the default IPv4 address-family enabled, and R2 disables IOS’s default IPv4 address-family and manually activates it for the specific neighbor 10.1.12.1.
Example 1-2 IOS Basic BGP Configuration
R1 (Default IPv4 Address-Family Enabled) router bgp 65100 neighbor 10.1.12.2 remote-as 65100
R2 (Default IPv4 Address-Family Disabled) router bgp 65100 no bgp default ipv4-unicast neighbor 10.1.12.1 remote-as 65100 ! address-family ipv4 neighbor 10.1.12.1 activate exit-address-family
IOS XR
The steps for configuring BGP on an IOS XR router are as follows:
Step 1. Create the BGP routing process. Initialize the BGP process with the global configuration command router bgp as-number.
Step 2. Initialize the address-family with the BGP router configuration command address-family afi safi so it can be associated to a BGP neighbor.
Step 3. Identify the BGP neighbor’s IP address with the BGP router configuration command neighbor ip-address.
Step 4. Identify the BGP neighbor’s autonomous system number with the BGP neighbor configuration command remote-as as-number.
Step 5. Activate the address-family for the BGP neighbor with the BGP neighbor configuration command address-family afi safi.
Step 6. Associate a route policy for EBGP Peers. IOS XR requires a routing policy to be associated to an EBGP peer as a security measure to ensure that routes are not accidentally accepted or advertised. If a route policy is not configured in the appropriate address-family, then NLRIs are discarded upon receipt and no NLRIs are advertised to EBGP peers.
An inbound and outbound route policy is configured with the command route-policy policy-name {in | out} under the BGP neighbor address-family configuration.
Example 1-3 displays the BGP configuration for R1 if it was running IOS XR. The RID is set on R1 because that router does not have any loopback interfaces.
Example 1-3 IOS XR BGP Configuration
IOS XR router bgp 65100 bgp router-id 192.168.1.1 address-family ipv4 unicast ! neighbor 10.1.12.2 remote-as 65100 address-family ipv4 unicast
NX-OS
The steps for configuring BGP on an NX-OS device are as follows:
Step 1. Create the BGP routing process. Initialize the BGP process with the global configuration command router bgp as-number.
Step 2. Initialize the address-family with the BGP router configuration command address-family afi safi so it can be associated to a BGP neighbor.
Step 3. Identify the BGP neighbor’s IP address and autonomous system number with the BGP router configuration command neighbor ip-address remote-as as-number.
Step 4. Activate the address-family for the BGP neighbor with the BGP neighbor configuration command address-family afi safi.
Example 1-4 displays the BGP configuration for R1 if it was running NX-OS.
Example 1-4 NX-OS BGP Configuration
NX-OS router bgp 65100 address-family ipv4 unicast neighbor 10.1.12.2 remote-as 65100 address-family ipv4 unicast
Verification of BGP Sessions
The BGP session is verified with the command show bgp afi safi summary on IOS, IOS XR, and NX-OS devices. Example 1-5 displays the IPv4 BGP unicast summary. Notice that the BGP RID and table versions are the first components shown. The Up/Down column reflects that the BGP session is up for over 5 minutes.
Example 1-5 BGP IPv4 Session Summary Verification
R1-IOS# show bgp ipv4 unicast summary BGP router identifier 192.168.2.2, local AS number 65100 BGP table version is 1, main routing table version 1 Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 10.1.12.2 4 65100 8 9 1 0 0 00:05:23 0
RP/0/0/CPU0:R1-XR# show bgp ipv4 unicast summary ! Output omitted for brevity BGP router identifier 192.168.1.1, local AS number 65100 BGP main routing table version 4 Process RcvTblVer bRIB/RIB LabelVer ImportVer SendTblVer StandbyVer Speaker 4 4 4 4 4 4 Neighbor Spk AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down St/PfxRcd 10.1.12.2 0 65100 8 7 4 0 000:05:23 0
R1-NXOS# show bgp ipv4 unicast summary ! Output omitted for brevity BGP router identifier 192.168.1.1, local AS number 65100 BGP table version is 5, IPv4 Unicast config peers 2, capable peers 1 Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 10.1.12.2 4 65100 32 37 5 0 0 00:05:24 0
Table 1-3 explains the fields of output when displaying the BGP Table.
Table 1-3 BGP Summary Fields
Field |
Description |
Neighbor |
IP address of the BGP peer |
V |
BGP Version spoken by BGP peer (IOS and NX-OS only) |
AS |
Autonomous system number of BGP peer |
MsgRcvd |
Count of messages received from the BGP peer |
MsgSent |
Count of messages sent to the BGP peer |
TblVer |
Last version of the BGP database sent to the peer |
InQ |
Number of messages queued to be processed from the peer |
OutQ |
Number of messages queued to be sent to the peer |
Up/Down |
Length of time the BGP session is established, or the current status if the session is not in established state |
State/PfxRcd |
Current state of BGP peer or the number of prefixes received from the peer |
BGP neighbor session state, timers, and other essential peering information is shown with the command show bgp afi safi neighbors ip-address, as shown in Example 1-6.
Example 1-6 BGP IPv4 Neighbor Output
R2# show bgp ipv4 unicast neighbors 10.1.12.1 ! Output ommitted for brevity ! The first section provides the neighbor's IP address, remote-as, indicates if ! the neighbor is 'internal' or 'external', the neighbor's BGP version, RID, ! session state, and timers. BGP neighbor is 10.1.12.1, remote AS100, internal link BGP version 4, remote router ID 192.168.1.1 BGP state = Established, up for 00:01:04 Last read 00:00:10, last write 00:00:09, hold is 180, keepalive is 60 seconds Neighbor sessions: 1 active, is not multisession capable (disabled) ! This second section indicates the capabilities of the BGP neighbor and ! address-families configured on the neighbor. Neighbor capabilities: Route refresh: advertised and received(new) Four-octets ASN Capability: advertised and received Address family IPv4 Unicast: advertised and received Enhanced Refresh Capability: advertised Multisession Capability: Stateful switchover support enabled: NO for session 1 Message statistics: InQ depth is 0 OutQ depth is 0 ! This section provides a list of the BGP packet types that have been received ! or sent to the neighbor router. Sent Rcvd Opens: 1 1 Notifications: 0 0 Updates: 0 0 Keepalives: 2 2 Route Refresh: 0 0 Total: 4 3 Default minimum time between advertisement runs is 0 seconds ! This section provides the BGP table version of the IPv4 Unicast address- ! family. The table version is not a 1-to-1 correlation with routes as multiple ! route change can occur during a revision change. Notice the Prefix Activity ! columns in this section. For address family: IPv4 Unicast Session: 10.1.12.1 BGP table version 1, neighbor version 1/0 Output queue size : 0 Index 1, Advertise bit 0 Sent Rcvd Prefix activity: ---- ---- Prefixes Current: 0 0 Prefixes Total: 0 0 Implicit Withdraw: 0 0 Explicit Withdraw: 0 0 Used as bestpath: n/a 0 Used as multipath: n/a 0 Outbound Inbound Local Policy Denied Prefixes: -------- ------- Total: 0 0 Number of NLRIs in the update sent: max 0, min 0 ! This section indicates that a valid route exists in the RIB to the BGP peer IP ! address, provides the number of times that the connection has established and ! time dropped, since the last reset, the reason for the reset, if path-mtu- ! discovery is enabled, and ports used for the BGP session. Address tracking is enabled, the RIB does have a route to 10.1.12.1 Connections established 2; dropped 1 Last reset 00:01:40, due to Peer closed the session Transport(tcp) path-mtu-discovery is enabled Connection state is ESTAB, I/O status: 1, unread input bytes: 0 Mininum incoming TTL 0, Outgoing TTL 255 Local host: 10.1.12.2, Local port: 179 Foreign host: 10.1.12.1, Foreign port: 56824
Prefix Advertisement
BGP uses three tables for maintaining the network prefix and path attributes (PA) for a route. The BGP tables are as follows:
Adj-RIB-in: Contains the NLRIs in original form before inbound route policies are processed. The table is purged after all route policies are processed to save memory.
Loc-RIB: Contains all the NLRIs that originated locally or were received from other BGP peers. After NLRIs pass the validity and next-hop reachability check, the BGP best path algorithm selects the best NLRI for a specific prefix. The Loc-RIB table is the table used for presenting routes to the ip routing table.
Adj-RIB-out: Contains the NLRIs after outbound route policies have processed.
BGP network statements do not enable BGP for a specific interface. Instead they identify a specific network prefix to be installed into the BGP table, known as the Loc-RIB table.
After configuring a BGP network statement, the BGP process searches the global RIB for an exact network prefix match. The network prefix can be a connected network, secondary connected network, or any route from a routing protocol. After verifying that the network statement matches a prefix in the global RIB, the prefix installs into the BGP Loc-RIB table. As the BGP prefix installs into the Loc-RIB, the following BGP PA are set depending on the RIB prefix type:
Connected Network: The next-hop BGP attribute is set to 0.0.0.0, the origin attribute is set to i (IGP), and the BGP weight is set to 32,768.
Static Route or Routing Protocol: The next-hop BGP attribute is set to the next-hop IP address in the RIB, the origin attribute is set to i (IGP), the BGP weight is set to 32,768; and the MED is set to the IGP metric.
The network statement resides under the appropriate address-family within the BGP router configuration. The command network network mask subnet-mask [route-map route-map-name] is used for advertising IPv4 networks on IOS and NX-OS devices. NX-OS devices also support prefix-length notation with the command network network /prefix-length [route-map route-map-name]. IOS XR routers use the command network network/prefix-length [route-policy route-policy-name] for installing routes into the BGP table. The optional route-map or route-policy parameter provides a method to set specific BGP PAs when the prefix installs into the Loc-RIB.
The command show bgp afi safi displays the contents of the BGP database (Loc-RIB) on IOS, IOS XR, and NX-OS devices. Every entry in the BGP Loc-RIB table contains at least one route, but could contain multiple routes for the same network prefix.
Example 1-7 displays the BGP table for IOS, IOS XR, and NX-OS. The BGP table contains received routes and locally generated routes.
Example 1-7 Display of BGP Table
R1-IOS# show bgp ipv4 unicast BGP table version is 5, local router ID is 192.168.1.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.1.1/32 0.0.0.0 0 32768 i * 192.168.2.2/32 10.1.13.3 0 65300 65200 i *> 10.1.12.2 0 0 65200 i *> 192.168.3.3/32 10.1.13.3 0 65300 i * 10.1.12.2 0 65200 65300 i
RP/0/0/CPU0:R2-XR# show bgp ipv4 unicast ! Output omitted for brevity BGP router identifier 192.168.2.2, local AS number 65200 Status codes: s suppressed, d damped, h history, * valid, > best i - internal, r RIB-failure, S stale, N Nexthop-discard Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path *> 192.168.1.1/32 10.1.12.1 0 0 65100 i * 10.1.23.3 0 65300 65100 i *> 192.168.2.2/32 0.0.0.0 0 32768 i * 192.168.3.3/32 10.1.12.1 0 65100 65300 i *> 10.1.23.3 0 65300 i Processed 3 prefixes, 5 paths
R3-NXOS# show bgp ipv4 unicast ! Output omitted for brevity Status: s-suppressed, x-deleted, S-stale, d-dampened, h-history, *-valid, >-best Path type: i-internal, e-external, c-confed, l-local, a-aggregate, r-redist, I-injected Origin codes: i - IGP, e - EGP, ? - incomplete, | - multipath, & - backup Network Next Hop Metric LocPrf Weight Path *>e192.168.1.1/32 10.1.13.1 0 0 65100 i * e 10.1.23.2 0 65200 65100 i *>e192.168.2.2/32 10.1.23.2 0 0 65200 i * e 10.1.13.1 0 65100 65200 i *>l192.168.3.3/32 0.0.0.0 100 32768 i
Table 1-4 explains the fields of output when displaying the BGP table.
Table 1-4 BGP Table Fields
Field |
Description |
Network |
List of the network prefixes installed in BGP. If multiple NLRIs exist for the same prefix, only the first prefix is identified, and others leave a blank space. Valid NLRIs are indicated by the *. The NLRI selected as the best path is indicated by an angle bracket (>). |
Next Hop |
Next Hop: A well-known mandatory BGP path attribute that defines the IP address for the next-hop for that specific NLRI. |
Metric |
Multiple-Exit Discriminator (MED): An optional nontransitive BGP path attribute used in BGP algorithm for that specific NLRI. |
LocPrf |
Local Preference: A well-known discretionary BGP path attribute used in the BGP best path algorithm for that specific NLRI. |
Weight |
Locally significant Cisco defined attribute used in the BGP best path algorithm for that specific NLRI. |
Path and Origin |
AS_PATH: A well-known mandatory BGP path attribute used for loop prevention and in the BGP best path algorithm for that specific NLRI. Origin: A well-known mandatory BGP path attribute used in the BGP best path algorithm. A value of i represents an IGP, e for EGP, and ? for a route that was redistributed into BGP. |
BGP Best-Path Calculation
In BGP, route advertisements consist of the Network Layer Reachability Information (NLRI) and the path attributes (PAs). The NLRI composes the network prefix and prefix-length, and the BGP attributes such as AS-Path, Origin, and the like are stored in the path attributes. A BGP route may contain multiple paths to the same destination network. Every path’s attributes impact the desirability of the route when a router selects the best path. A BGP router advertises only the best path to the neighboring routers.
Inside the BGP Loc-RIB table, all the routes and their path attributes are maintained with the best path calculated. The best path is then installed in the RIB of the router. In the event the best path is no longer available, the router can use the existing paths to quickly identify a new best path. BGP recalculates the best path for a prefix upon four possible events:
BGP next-hop reachability change
Failure of an interface connected to an EBGP peer
Redistribution change
Reception of new paths for a route
The BGP best path selection algorithm influences how traffic enters or leaves an autonomous system (AS). BGP does not use metrics to identify the best path in a network. BGP uses path attributes to identify its best path.
Some router configurations modify the BGP attributes to influence inbound traffic, outbound traffic, or inbound and outbound traffic depending on the network design requirements. BGP path attributes can be modified upon receipt or advertisement to influence routing in the local AS or neighboring AS. A basic rule for traffic engineering with BGP is that modifications in outbound routing policies influence inbound traffic, and modifications to inbound routing policies influence outbound traffic.
BGP installs the first received path as the best path automatically. When additional paths are received, the newer paths are compared against the current best path. If there is a tie, then processing continues onto the next step, until a best path winner is identified.
The following list provides the attributes that the BGP best path algorithm uses for the best route selection process. These attributes are processed in the order listed:
Weight
Local Preference
Local originated (network statement, redistribution, aggregation)
AIGP
Shortest-AS Path
Origin Type
Lowest MED
EBGP over IBGP
Lowest IGP Next-Hop
If both paths are external (EBGP), prefer the first (oldest)
Prefer the route that comes from the BGP peer with the lower RID
Prefer the route with the minimum cluster list length
Prefer the path that comes from the lowest neighbor address
The best path algorithm can be used to manipulate network traffic patterns for a specific route by modifying various path attributes on BGP routers. Changing of BGP PA can influence traffic flow into, out of, and around an AS.
BGP supports three types of equal cost multipath (ECMP): EBGP multipath, IBGP multipath, or eIBGP multipath. EBGP multipath requires that the weight, local preference, AS-Path length, AS-Path content, Origin, and MED match for a second route to install into the RIB. Chapter 8, “Troubleshooting BGP Edge Architectures,” explains BGP ECMP in more detail.