Border Gateway Protocol

Border Gateway Protocol (BGP) is a standardized exterior gateway protocol that

  • exchanges routing information between different autonomous systems (AS) on the Internet
  • manages how packets are routed from one network to another, and
  • ensures that data finds the most efficient path.

BGP in SONiC is implemented by the bgp container. The bgp container runs an instance of the open-source FRR routing stack (https://frrouting.org/).

You can access the FRR stack in the bgp container using a vty shell. To drop into the FRR shell from SONiC's base Linux environment, enter:

vtysh

For example:

root@sonic:/home/admin# vtysh

Hello, this is FRRouting (version 8.5.1).
Copyright 1996-2005 Kunihiro Ishiguro, et al.

sonic#

From this shell, a user can configure BGP, set prefix lists, route maps, and perform several other configuration options. The following sections will discuss some of these operations.

Set router-id

Set the router-id globally using router-id <router-id>

For example:

root@sonic:/home/admin# vtysh

Hello, this is FRRouting (version 8.5.1).
Copyright 1996-2005 Kunihiro Ishiguro, et al.

sonic# configure
sonic(config)# router-id 1.1.1.1
sonic(config)#

Configure an AS and an iBGP neighbor

router bgp <as-number> neighbor <neighbor-id> remote-as <remote-as-number>

For example:

root@sonic:/home/admin# vtysh

Hello, this is FRRouting (version 8.5.1).
Copyright 1996-2005 Kunihiro Ishiguro, et al.

sonic# configure
sonic(config)# router bgp 64000
sonic(config-router)# neighbor 10.8.16.2 remote-as 64000

And on the neighbor router:

sonic# configure
sonic(config)# router bgp 64000
sonic(config-router)# neighbor 10.8.16.1 remote-as 64000

Verify the BGP session has come up using show bgp summary:

sonic# show bgp summary

IPv4 Unicast Summary (VRF default):
BGP router identifier 1.1.1.1, local AS number 64000 vrf-id 0
BGP table version 0
RIB entries 0, using 0 bytes of memory
Peers 1, using 20 KiB of memory

Neighbor        V         AS   MsgRcvd   MsgSent   TblVer  InQ OutQ  Up/Down State/PfxRcd   PfxSnt Desc
10.8.16.2       4      64000         4         4        0    0    0 00:01:20            0        0 N/A

Total number of neighbors 1

Similarly, on the neighbor:

sonic# show bgp summary

IPv4 Unicast Summary (VRF default):
BGP router identifier 4.4.4.4, local AS number 64000 vrf-id 0
BGP table version 0
RIB entries 0, using 0 bytes of memory
Peers 1, using 20 KiB of memory

Neighbor        V         AS   MsgRcvd   MsgSent   TblVer  InQ OutQ  Up/Down State/PfxRcd   PfxSnt Desc
10.8.16.1       4      64000         4         4        0    0    0 00:01:47            0        0 N/A

Total number of neighbors 1

Configure an AS and an eBGP neighbor

In a similar fashion, a user can configure eBGP session in SONiC. In FRR, eBGP sessions need to have filters for incoming and outgoing routes in accordance with RFC 8212 or the no bgp ebgp-requires-policy flag needs to be explicitly set. An example of setting up an eBGP session using second method:

root@sonic:/home/admin# vtysh

Hello, this is FRRouting (version 8.5.1).
Copyright 1996-2005 Kunihiro Ishiguro, et al.

sonic# configure
sonic(config)# router bgp 64001
sonic(config-router)# neighbor 10.8.16.2 remote-as 64004
sonic(config-router)# no bgp ebgp-requires-policy

On the neighbor:

root@sonic:/home/admin# vtysh

Hello, this is FRRouting (version 8.5.1).
Copyright 1996-2005 Kunihiro Ishiguro, et al.

sonic# configure
sonic(config)# router bgp 64004
sonic(config-router)# neighbor 10.8.16.1 remote-as 64001
sonic(config-router)# no bgp ebgp-requires-policy

To verify, use show bgp summary

sonic# show bgp summary

IPv4 Unicast Summary (VRF default):
BGP router identifier 1.1.1.1, local AS number 64001 vrf-id 0
BGP table version 0
RIB entries 0, using 0 bytes of memory
Peers 1, using 20 KiB of memory

Neighbor        V         AS   MsgRcvd   MsgSent   TblVer  InQ OutQ  Up/Down State/PfxRcd   PfxSnt Desc
10.8.16.2       4      64004         3         3        0    0    0 00:00:07            0        0 N/A

Total number of neighbors 1

Similarly, verify on the BGP neighbor:

sonic# show bgp summary

IPv4 Unicast Summary (VRF default):
BGP router identifier 4.4.4.4, local AS number 64004 vrf-id 0
BGP table version 0
RIB entries 0, using 0 bytes of memory
Peers 1, using 20 KiB of memory

Neighbor        V         AS   MsgRcvd   MsgSent   TblVer  InQ OutQ  Up/Down State/PfxRcd   PfxSnt Desc
10.8.16.1       4      64001         4         4        0    0    0 00:01:09            0        0 N/A

Total number of neighbors 1

Creating prefix-lists and route-maps

Prefix lists can be created using the ip prefix-list command.

sonic(config)# ip prefix-list pl1 seq 10 permit 1.1.1.1/15 le 32

Additionally, route maps can be created using the route-map command.

sonic(config)# route-map rm1 permit 10
sonic(config-route-map)# match ip address prefix-list pl1

BGP address family settings

sonic(config)# router bgp 65000
sonic(config-router)# address-family ipv4 unicast

Change BGP timers

The Keepalive and Holdtime BGP timers can be modified in FRR's vty shell. Here is some example config for adjusting these timers (The first value is the Keepalive interval and the second is Holdtime):

sonic(config)# router bgp 65000
sonic(config-router)# timers bgp 
  (0-65535)  Keepalive interval
sonic(config-router)# timers bgp 2 
  (0-65535)  Holdtime
sonic(config-router)# timers bgp 2 8

BGP send-community and send-community extended

By default FRR ensures communities are sent to BGP peers. However, users can explicitly configure this behaviour using the following commands.

sonic(config)# router bgp 65000
sonic(config-router)# neighbor 10.10.10.1 remote-as 65001
sonic(config-router)# address-family ipv4
sonic(config-router-af)# neighbor 10.10.10.1 send-community
sonic(config-router-af)# neighbor 10.10.10.1 send-community extended

BGP soft-reconfiguration inbound

sonic(config)# router bgp 65000
sonic(config-router)# neighbor 10.10.10.1 remote-as 65001
sonic(config-router)# address-family ipv4
sonic(config-router-af)# neighbor 10.10.10.1 soft-reconfiguration inbound

BGP ECMP maximum-paths configuration

Users can specify the maximum ECMP paths per address family in FRR. The following config configures this for the IPv4 unicast address family.

sonic(config)# router bgp 65000
sonic(config-router)# address-family ipv4 unicast 
sonic(config-router-af)# maximum-paths      
  (1-256)  Number of paths
  ibgp     iBGP-multipath
sonic(config-router-af)# maximum-paths 

Configuration with Peer Groups

FRR supports peer groups to allow users to create peer groups with similar configuration parameters. To create a peer group in FRR, follow these steps:

  • Create a new peer-group using the neighbor <peer-group-name> peer-group command For example:
sonic(config)# router bgp 65000
sonic(config-router)# neighbor PG1 peer-group
  • Specify configuration parameters for the peer-group. These parameters can be global as well as specific to an address family. For example:
sonic(config)# router bgp 65000
sonic(config-router)# neighbor PG1 remote-as 65002
sonic(config-router)# neighbor PG1 timers 2 8
sonic(config-router)# address-family ipv4
sonic(config-router-af)# neighbor PG1 send-community
sonic(config-router-af)# neighbor PG1 send-community extended
sonic(config-router-af)# neighbor PG1 soft-reconfiguration inbound
sonic(config-router-af)# neighbor PG1 route-map rt_map1
  • Now, apply the peer group configuration to neighbors
sonic(config)# router bgp 65000
sonic(config-router)# neighbor 10.2.2.2 peer-group PG1
sonic(config-router)# neighbor 10.3.3.3 peer-group PG1

Apply route map to neighbor

sonic(config)# router bgp 65000
sonic(config-router)# neighbor 10.10.10.1 remote-as 65001
sonic(config-router)# address-family ipv4
sonic(config-router-af)# neighbor 10.10.10.1 route-map rt_map1

Saving FRR configuration

To save the configuration, use:

write

For example:

sonic# write
Note: this version of vtysh never writes vtysh.conf
Building Configuration...
Configuration saved to /etc/frr/zebra.conf
Configuration saved to /etc/frr/bgpd.conf
Configuration saved to /etc/frr/staticd.conf