Skip to content
Ask AI

BGP Configuration

BGP (Border Gateway Protocol) is a distance-vector routing protocol that facilitates routing reachability and selection of the best routes between Autonomous Systems (ASes).

To manage the ever-expanding networks more effectively, networks are divided into different Autonomous Systems. In 1982, Exterior Gateway Protocol (EGP) was used to dynamically exchange routing information between ASes. However, EGP was designed with simplicity and only announced reachable network routes without route selection or loop avoidance mechanisms. It quickly became insufficient to meet the needs of network management. This led to the development of BGP, which allows for route selection, loop prevention, efficient route propagation, and management of a large number of routes.

An Autonomous System (AS) refers to an IP network under the control of a single administrative entity with a common routing policy. Each AS in a BGP network is assigned a unique AS number, which is used to distinguish different ASes. AS numbers come in 2-byte and 4-byte formats, with the range of 2-byte AS numbers being 1 to 65535, and 4-byte AS numbers ranging from 1 to 4294967295. Devices that support 4-byte AS numbers can be compatible with devices that support 2-byte AS numbers.

BGP is categorized into Exterior BGP (EBGP) and Interior BGP (IBGP) based on its operational context.

  • IBGP (Internal BGP)

IBGP operates within the same AS. To prevent loops within the AS, BGP devices do not advertise routes learned from IBGP peers to other IBGP peers. Full connections are established with all IBGP peers. When deploying IBGP, Route Reflectors (RRs) can be introduced to simplify full connection configurations. All Leaf devices establish BGP peer relationships only with the RR. The RR discovers and accepts BGP connections initiated by VTEPs, forming a client list, and reflects routes received from a VTEP to all other VTEPs. RRs can be deployed on Spine devices, Leaf devices, or as standalone devices.

  • EBGP (Exterior BGP)

EBGP operates between different ASes. To prevent loops between ASes, BGP devices discard routes received from EBGP peers that contain the local AS number. When deploying EBGP, RRs are not needed. BGP automatically sends EVPN messages received from EBGP neighbors to other EBGP and IBGP neighbors, effectively making the Spine device function as a RR.

In most cases, devices within a network have different AS numbers, making EBGP a common choice in SONiC. If redundant Leafs are used with the same ASN, IBGP can be used.

In BGP message exchange, there are two roles: Speaker and Peer.

Speaker: The device that sends BGP messages is referred to as a BGP speaker. It receives or generates new message information and advertises it to other BGP speakers.

Peer: Speakers that exchange messages with each other are referred to as peers. Several related peers can form a peer group.

The Router ID is a 32-bit value used to identify a BGP device. It is typically represented in the form of an IPv4 address and is carried in the Open message sent during BGP session establishment. When establishing a BGP session between peers, each BGP device must have a unique Router ID. Without a unique Router ID, BGP connections between peers cannot be established.

Configure TasksInstructionsIndex
Enable BGPRequired5.1.3.1
Configure Router IDRequired5.1.3.2
Configure BGP NeighborsOptional5.1.3.3
Configure BFD Integration with BGPOptional5.1.3.4
OperationCommandDescription
Enter the system configuration viewconfigure terminal
Enter the BGP viewrouter bgp asn
Enable BGP session for a specific neighborno neighbor {ipaddr | hostname} shutdownBy default, BGP sessions are in the enabled state
Enable all BGP sessionno bgp shutdown

The Router ID uniquely identifies a device within the entire Autonomous System. By default, the IP address of the loopback interface is used as the Router ID.

OperationCommandDescription
Enter the system configuration viewconfigure terminal
Enter the BGP viewrouter bgp asn
Configure router IDbgp router-id ip_addr
OperationCommandDescription
Enter the system configuration viewconfigure terminal
Enter the BGP viewrouter bgp asn
Add BGP neighborneighbor neighbor_ip remote-as asn
OperationCommandDescription
Enter the system configuration viewconfigure terminal
Enter the BGP viewrouter bgp asn
Configure BFD Integration with BGPneighbor {ipaddr | hostname} bfd
OperationCommandDescriptionb
Display detailed information of BGP neighborshow ip bgp neighbors {ipaddr|hostname} [OPTION]ipaddr: Specifies the IP address of the neighbor.
hostname: Specifies the hostname of the neighbor.
Options for displaying specific information include:
routes: Displays routes learned from the neighbor.
advertised-routes: Displays routes advertised to the neighbor.
received-routes: Displays routes received from the neighbor.
prefix-counts: Displays detailed prefix count information.
filtered-routes: Displays filtered routes received from the neighbor.
bestpath-routes: Displays routes selected based on the best path.
received: Displays received information from the neighbor.
flap-statistics: Displays flap statistics of routes learned from the neighbor.
dampened-routes: Displays dampened routes received from the neighbor.
**json**: Displays information in JSON format. |

| Display BGP Neighbor Network Information | **show ip bgp ** [A.B.C.D/M |A.B.C.D] | | | Display BGP Neighbor Summary Information: | **show ip bgp summary ** [established|failed|json] | established: Displays a summary of established BGP neighbors. failed: Displays a summary of failed BGP neighbors. json: Displays the summary information in JSON format. |

Network requirements

Hosts in different network segments are connected through three switches, all of which run the BGP protocol. It is required to configure IBGP and EBGP neighbors so that PC1 under Device A and PC2 under Device C can interoperate.

Procedure

  1. Take Device A as an example to configure the IP address of each interface

    # Create VLANs and add member interfaces

sonic(config)# vlan 100
sonic(config)# interface ethernet 1
sonic(config-if-1)# switchport access vlan 100
sonic(config)# interface ethernet 2
sonic(config-if-2)# switchport access vlan 100

# Configuring IP addresses for interfaces

sonic(config)# interface vlan 100
sonic(config-vlanif-100)# ip address 10.10.0.2/24
sonic(config-vlanif-100)# exit
sonic(config)# interface ethernet 49
sonic(config-if-49)# ip address 10.0.0.1/30
sonic(config-if-49)# exit
config-routerinterface loopback 0
sonic(config-loif-0)# ip address 10.1.15.10/32
  1. Configure IBGP connection # Device A
sonic(config)# router bgp 65001
sonic(config-router)# bgp router-id 10.1.15.10
sonic(config-router)# no bgp ibgp-requires-policy
sonic(config-router)# neighbor 10.0.0.2 remote-as 65001
sonic(config-router)# neighbor 10.0.0.2 bfd
sonic(config-router)# neighbor 10.0.0.2 description DeviceB

# Declare the directly connected route on Device A

sonic(config-router)# address-family ipv4 unicast
sonic(config-router-af)# redistribute connected

# Device B

sonic(config)# router bgp 65001
sonic(config-router)# bgp router-id 10.1.15.20
sonic(config-router)# no bgp ibgp-requires-policy
sonic(config-router)# neighbor 10.0.0.1 remote-as 65001
sonic(config-router)# neighbor 10.0.0.1 bfd
sonic(config-router)# neighbor 10.0.0.1 description DeviceA
  1. Configure EBGP connection # Device B
sonic(config)# router bgp 65001
sonic(config-router)# no bgp ebgp-requires-policy
sonic(config-router)# neighbor 30.0.0.1 remote-as 65003
sonic(config-router)# neighbor 30.0.0.1 bfd
sonic(config-router)# neighbor 30.0.0.1 description DeviceC

# Device C

sonic(config)# router bgp 65003
sonic(config-router)# bgp router-id 10.1.15.30
sonic(config-router)# no bgp ebgp-requires-policy
sonic(config-router)# no bgp ibgp-requires-policy
sonic(config-router)# neighbor 30.0.0.2 remote-as 65001
sonic(config-router)# neighbor 30.0.0.2 bfd
sonic(config-router)# neighbor 30.0.0.2 description DeviceB

# Declare a directly connected route on Device C

sonic(config-router)# address-family ipv4 unicast
sonic(config-router-af)# redistribute connected

Verify configuration

  1. Take Device B as an example to check whether the BGP connection is established successfully.
sonic# show ip bgp summary
IPv4 Unicast Summary:
BGP router identifier 10.1.15.20, local AS number 65001 vrf-id 0
BGP table version 1474
RIB entries 37, using 7104 bytes of memory
Peers 4, using 85 KiB of memory
Peer groups 6, using 384 bytes of memory
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt
10.0.0.1 4 65001 30274 3672 0 0 0 01:16:37 17 22
30.0.0.1 4 65003 29184 3712 0 0 0 01:00:07 16 22
  1. PC1 and PC2 can ping each other

In BGP networks, route policy is a crucial approach that allows flexible control over the propagation and reception of routes by modifying their attributes. It involves the following steps:

  1. Define a set of matching rules to identify the characteristics of the routes for which the route policy will be applied. These characteristics can include destination addresses, originating router addresses, and more.
  2. Create specific policies based on the matching rules, which may involve modifying route attributes or restricting the route propagation.
  3. Apply the defined policies to various stages of route handling, such as route advertisement, reception, and introduction, to effectively control the behavior of routes. By implementing route policies, network administrators can fine-tune the behavior of BGP routes according to their specific requirements, ultimately optimizing network performance and reliability.

Network requirements

Device A and Device B are connected via BGP. Set the routing policy to be applied when introducing directly connected routes, so that directly connected routes in the 192.168.1.1/24 and 192.168.2.1/24 segments are visible and routes in the 192.168.10.1/24 segment are blocked.

Procedure

  1. Configuring Device A # Configure the interface IP address
sonic(config)# interface vlan 100
sonic(config-vlanif-100)# ip address 192.168.1.1/24
sonic(config-vlanif-100)# exit
sonic(config)# interface vlan 200
sonic(config-vlanif-200)# ip address 192.168.2.1/24
sonic(config-vlanif-200)# exit
sonic(config)# interface vlan 300
sonic(config-vlanif-300)# ip address 192.168.10.1/24
sonic(config-vlanif-300)# exit
sonic(config)# interface ethernet50
sonic(config-if-50)# ip address 30.0.0.2/30

# Establishing a BGP connection

sonic(config)# router bgp 65001
sonic(config-router)# bgp router-id 10.1.15.10
sonic(config-router)# no bgp ebgp-requires-policy
sonic(config-router)# neighbor 30.0.0.1 remote-as 65003
sonic(config-router)# neighbor 30.0.0.1 bfd
sonic(config-router)# neighbor 30.0.0.1 description DeviceB

# Configuring Routing Policies

sonic(config)# ip prefix-list test permit 192.168.10.1/24
sonic(config)# route-map connect_filter deny 30000
sonic(config-route-map)# match ip address prefix-list test

# Introduce directly connected routes in BGP neighbors and apply routing policies for filtering

sonic(config)# router bgp 65001
sonic(config-router)# address-family ipv4 unicast
sonic(config-router-af)# redistribute connected
sonic(config-router-af)# redistribute kernel route-map connect_filter
  1. Configuring Device B # Omit IP address configuration # Establishing a BGP connection
sonic(config)# router bgp 65003
sonic(config-router)# bgp router-id 10.1.15.20
sonic(config-router)# no bgp ebgp-requires-policy
sonic(config-router)# neighbor 30.0.0.2 remote-as 65001
sonic(config-router)# neighbor 30.0.0.2 bfd
sonic(config-router)# neighbor 30.0.0.2 description DeviceA

Verify configuration

View the routing table on Device B

sonic# show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP,
O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP,
F - PBR, f - OpenFabric,
> - selected route, * - FIB route, q - queued, r - rejected, b - backup
B>* 192.168.1.1/24 [20/0] via 30.0.0.2, ethernet 50, weight 1, 01:41:43
B>* 192.168.2.1/24 [20/0] via 30.0.0.2, ethernet 50, weight 1, 01:41:43
C>* 30.0.0.1/30 is directly connected, ethernet 50, 1d00h59m