High availability with ExaBGP

Vincent Bernat

When it comes to pro­vid­ing re­dun­dant ser­vices, sev­eral op­tions are available:

  • The ser­vice can be hosted be­hind a set of load-bal­ancers. They will de­tect any faulty node. How­ever, you need to en­sure that this new layer is also fault-tolerant.
  • The nodes pro­vid­ing the ser­vice can rely on IP failover to share a set of IP us­ing pro­to­cols like VRRP1 or CARP. The IP ad­dress of a faulty node will be as­signed to an­other node. This re­quires all nodes to be part of the same IP subnet.
  • The clients of the ser­vice can ask a third-party for avail­able nodes. Usu­ally, this is achieved through round-robin DNS where only work­ing nodes are ad­ver­tised in a DNS record. The failover can be quite long be­cause of caches.

A com­mon setup is a com­bi­na­tion of these so­lu­tions: web servers are be­hind a cou­ple of load-bal­ancers achiev­ing both re­dun­dancy and load-bal­anc­ing. The load-bal­ancers use VRRP to en­sure re­dun­dancy. The whole setup is repli­cated to an­other dat­a­cen­ter and round-robin DNS is used to en­sure both re­dun­dancy and load-bal­anc­ing of the dat­a­centers.

There is a fourth op­tion which is sim­i­lar to VRRP but re­lies on dy­namic rout­ing and there­fore is not lim­ited to nodes in the same subnet:

  • The nodes ad­ver­tise their avail­abil­ity with BGP to an­nounce the set of ser­vice IP ad­dresses they are able to serve. Each ad­dress is weighted such that IP ad­dresses are bal­anced among the avail­able nodes.

We will ex­plore how to im­ple­ment this fourth op­tion us­ing ExaBGP, the BGP Swiss army knife of net­work­ing, in a small lab based on KVM. You can grab the com­plete lab from GitHub. ExaBGP 3.2.5 is needed to run this lab.

Up­date (2019-05)

Also have a look at “Multi-tier load-bal­anc­ing with Linux.” It de­scribes the build of a highly avail­able load-bal­anc­ing layer of which ExaBGP is one of the com­ponents.

Environment#

We will be work­ing in the fol­low­ing (IPv6-only) en­vi­ronment:

Lab with three web nodes
Basic routed network with three web nodes

BGP configuration#

BGP is en­abled on ER2 and ER3 to ex­change routes with peers and tran­sits (only R1 for this lab). BIRD is used as a BGP dae­mon. Its con­fig­u­ra­tion is pretty ba­sic. Here is a fragment:

router id 1.1.1.2;

protocol static NETS { # ❶
  import all;
  export none;
  route 2001:db8::/40 reject;
}
protocol bgp R1 { # ❷
  import all;
  export where proto = "NETS";
  local as 64496;
  neighbor 2001:db8:1000::1 as 64511;
}
protocol bgp ER3 { # ❸
  import all;
  export all;
  next hop self;
  local as 64496;
  neighbor 2001:db8:1::3 as 64496;
}

First, in ❶, we de­clare the routes that we want to ex­port to our peers. We don’t try to sum­ma­rize them from the IGP. We just un­con­di­tion­ally ex­port the net­works that we own. Then, in ❷, R1 is de­fined as a neigh­bor and we ex­port the static route we de­clared pre­vi­ously. We im­port any route that R1 is will­ing to send us. In ❸, we share ev­ery­thing we know with our pal, ER3, us­ing in­ternal BGP.

OSPF configuration#

OSPF will dis­trib­ute routes in­side the AS. It is en­abled on ER2, ER3, DR6, DR7 and DR8. For ex­am­ple, here is the rel­e­vant part of the con­fig­u­ra­tion of DR6:

router id 1.1.1.6;
protocol kernel {
   persist;
   import none;
   export all;
}
protocol ospf INTERNAL {
  import all;
  export none;
  area 0.0.0.0 {
    networks {
      2001:db8:1::/64;
      2001:db8:6::/64;
    };
    interface "eth0";
    interface "eth1" { stub yes; };
  };
}

ER2 and ER3 in­ject a de­fault route into OSPF:

protocol static DEFAULT {
  import all;
  export none;
  route ::/0 via 2001:db8:1000::1;
}
filter default_route {
  if proto = "DEFAULT" then accept;
  reject;
}
protocol ospf INTERNAL {
  import all;
  export filter default_route;
  area 0.0.0.0 {
    networks {
      2001:db8:1::/64;
    };
    interface "eth1";
  };
}

Web nodes#

The web nodes are pretty ba­sic. They have a de­fault static route to the near­est router and that’s all. The in­ter­est­ing thing here is that they are each on a sep­a­rate IP sub­net: we can­not share an IP us­ing VRRP.2

Why are these web servers on dif­fer­ent sub­nets? Maybe they are not in the same dat­a­cen­ter or maybe your net­work ar­chi­tec­ture is us­ing a routed ac­cess layer.

Let’s see how to use BGP to en­able re­dun­dancy of these web nodes.

Redundancy with ExaBGP#

ExaBGP is a con­ve­nient tool to plug scripts into BGP. They can then re­ceive and ad­ver­tise routes. ExaBGP does the hard work of speak­ing BGP with your routers. The scripts just have to read routes from stan­dard in­put or ad­ver­tise them on stan­dard output.

The big picture#

Here is the big picture:

Using ExaBGP to advertise web services
High availability using ExaBGP and two route servers

Let’s ex­plain it step by step:

  1. Three IP ad­dresses will be al­lo­cated for our web ser­vice: 2001:​db8:30::1, 2001:​db8:30::2 and 2001:​db8:30::3. They are dis­tinct from the real IP ad­dresses of W1, W2 and W3.

  2. Each web node will ad­ver­tise all of them to the route servers we added in the net­work. I will talk more about these route servers later.

  3. Each route comes with a met­ric to help the route server choose where it should be routed. We choose the met­rics such that each IP ad­dress will be routed to a dis­tinct web node (un­less there is a problem).

  4. The route servers (which are not routers) will then ad­ver­tise the best routes they learned to all the routers in our net­work. This is still done using BGP.

  5. Now, for a given IP ad­dress, each router knows to which web node the traf­fic should be directed.

Here are the re­spec­tive met­rics of an­nounced routes for W1, W2 and W3 when ev­ery­thing works as expected:

Route W1 W2 W3 Best Backup
2001:db8:30::1 102 101 100 W3 W2
2001:db8:30::2 101 100 102 W2 W1
2001:db8:30::3 100 102 101 W1 W3

ExaBGP configuration#

The con­fig­u­ra­tion of ExaBGP is quite simple:

group rs {
  neighbor 2001:db8:1::4 {
    router-id 1.1.1.11;
    local-address 2001:db8:6::11;
    local-as 65001;
    peer-as 65002;
  }
  neighbor 2001:db8:8::5 {
    router-id 1.1.1.11;
    local-address 2001:db8:6::11;
    local-as 65001;
    peer-as 65002;
  }

  process watch-nginx {
      run /usr/bin/python /lab/healthcheck.py -s --config /lab/healthcheck-nginx.conf --start-ip 0;
  }
}

A script checks if the ser­vice (an ng­inx web server) is up and run­ning and ad­ver­tises the ap­pro­pri­ate IP ad­dresses to the two de­clared route servers. If we run the script man­u­ally, we can see the ad­ver­tised routes:

$ python /lab/healthcheck.py --config /lab/healthcheck-nginx.conf --start-ip 0
INFO[healthcheck] send announces for UP state to ExaBGP
announce route 2001:db8:30::3/128 next-hop self med 100
announce route 2001:db8:30::2/128 next-hop self med 101
announce route 2001:db8:30::1/128 next-hop self med 102
[…]
WARNING[healthcheck] Check command was unsuccessful: 7
INFO[healthcheck] Output of check command:  curl: (7) Failed connect to ip6-localhost:80; Connection refused
WARNING[healthcheck] Check command was unsuccessful: 7
INFO[healthcheck] Output of check command:  curl: (7) Failed connect to ip6-localhost:80; Connection refused
WARNING[healthcheck] Check command was unsuccessful: 7
INFO[healthcheck] Output of check command:  curl: (7) Failed connect to ip6-localhost:80; Connection refused
INFO[healthcheck] send announces for DOWN state to ExaBGP
announce route 2001:db8:30::3/128 next-hop self med 1000
announce route 2001:db8:30::2/128 next-hop self med 1001
announce route 2001:db8:30::1/128 next-hop self med 1002

When the ser­vice be­comes un­re­spon­sive, the healthcheck script de­tects the sit­u­a­tion and re­tries sev­eral times be­fore ac­knowl­edg­ing that the ser­vice is dead. Then, the IP ad­dresses are ad­ver­tised with higher met­rics and the ser­vice will be routed to an­other node (the one ad­ver­tis­ing 2001:​db8:30::​3/128 with met­ric 101).

This healthcheck script is now part of ExaBGP and can be in­voked with:

$ python -m exabgp healthcheck --config /lab/healthcheck-nginx.conf --start-ip 0

Route servers#

We could have con­nected our ExaBGP servers di­rectly to each router. How­ever, if you have 20 routers and 10 web servers, you now have to man­age a mesh of 200 ses­sions. The route servers are here for three purposes:

  1. Re­duce the num­ber of BGP ses­sions (from 200 to 60) be­tween de­vices (less con­fig­u­ra­tion, fewer errors).

  2. Avoid mod­i­fy­ing the con­fig­u­ra­tion on routers each time a new ser­vice is added.

  3. Sep­a­rate the rout­ing de­ci­sion (the route servers) from the rout­ing process (the routers).

You may also ask your­self: “why not use OSPF?” Good question!

  • OSPF could be en­abled on each web node and the IP ad­dresses ad­ver­tised us­ing this pro­to­col. How­ever, OSPF has sev­eral draw­backs: it does not scale, there are re­stric­tions on the al­lowed topolo­gies, it is dif­fi­cult to fil­ter routes in­side OSPF and a mis­con­fig­u­ra­tion will likely im­pact the whole net­work. There­fore, it is con­sid­ered a good prac­tice to limit OSPF to net­work devices.

  • The routes learned by the route servers could be in­jected into OSPF. On pa­per, OSPF has a “next-hop” field to pro­vide an ex­plicit next-hop. This would be handy as we wouldn’t have to con­fig­ure ad­ja­cen­cies with each router. How­ever, I have ab­so­lutely no idea how to in­ject BGP next-hop into OSPF next-hop. What hap­pens is that BGP next-hop is re­solved lo­cally us­ing OSPF routes. For ex­am­ple, if we in­ject BGP routes into OSPF from RS4, RS4 will know the ap­pro­pri­ate next-hop but other routers will route the traf­fic to RS4.

Let’s look at how to con­fig­ure our route servers. RS4 will use BIRD while RS5 will use Quagga. Us­ing two dif­fer­ent im­ple­men­ta­tions will help with re­siliency by avoid­ing a bug hit­ting the two route servers at the same time.

BIRD configuration#

There are two sides for BGP con­fig­u­ra­tion: the BGP ses­sions with the ExaBGP nodes and the ones with the routers. Here is the con­fig­u­ra­tion for the latter:

template bgp INFRABGP {
  export all;
  import none;
  local as 65002;
  rs client;
}
protocol bgp ER2 from INFRABGP {
  neighbor 2001:db8:1::2 as 65003;
}
protocol bgp ER3 from INFRABGP {
  neighbor 2001:db8:1::3 as 65003;
}
protocol bgp DR6 from INFRABGP {
  neighbor 2001:db8:1::6 as 65003;
}
protocol bgp DR7 from INFRABGP {
  neighbor 2001:db8:1::7 as 65003;
}
protocol bgp DR8 from INFRABGP {
  neighbor 2001:db8:1::8 as 65003;
}

The AS num­ber used by our route server is 65002 while the AS num­ber used for routers is 65003 (the AS num­bers for web nodes will be 65001). They are re­served for pri­vate use by RFC 6996. All routes known by the route server are ex­ported to the routers but no routes are ac­cepted from them.

Let’s have a look at the other side:

# Only import loopback IPs
filter only_loopbacks { # ❶
  if net ~ [ 2001:db8:30::/64{128,128} ] then accept;
  reject;
}

# General template for an EXABGP node
template bgp EXABGP {
  local as 65002;
  import filter only_loopbacks; # ❷
  export none;
  route limit 10; # ❸
  rs client;
  hold time 6; # ❹
  multihop 10;
  igp table internal;
}

protocol bgp W1 from EXABGP {
  neighbor 2001:db8:6::11 as 65001;
}
protocol bgp W2 from EXABGP {
  neighbor 2001:db8:7::12 as 65001;
}
protocol bgp W3 from EXABGP {
  neighbor 2001:db8:8::13 as 65001;
}

To en­sure sep­a­ra­tion of con­cerns, we are be­ing a bit more picky. With ❶ and ❷, we only ac­cept loop­back ad­dresses and only if they are con­tained in the sub­net that we re­served for this use. No server should be able to in­ject ar­bi­trary ad­dresses into our net­work. With ❸, we also limit the num­ber of routes that a server can ad­vertise.

With ❹, we re­duce the hold time from 240 to 6. It means that af­ter 6 sec­onds, the peer is con­sid­ered dead. This is quite im­por­tant to be able to re­cover quickly from a dead ma­chine. The min­i­mal value is 3. We could have used a sim­i­lar set­ting with the ses­sion with the routers.

Quagga configuration#

Quagga’s con­fig­u­ra­tion is a bit more ver­bose but should be strictly equivalent:

router bgp 65002 view EXABGP
 bgp router-id 1.1.1.5
 bgp log-neighbor-changes
 no bgp default ipv4-unicast

 neighbor R peer-group
 neighbor R remote-as 65003
 neighbor R ebgp-multihop 10

 neighbor EXABGP peer-group
 neighbor EXABGP remote-as 65001
 neighbor EXABGP ebgp-multihop 10
 neighbor EXABGP timers 2 6
!
 address-family ipv6

 neighbor R activate
 neighbor R soft-reconfiguration inbound
 neighbor R route-server-client
 neighbor R route-map R-IMPORT import
 neighbor R route-map R-EXPORT export
 neighbor 2001:db8:1::2 peer-group R
 neighbor 2001:db8:1::3 peer-group R
 neighbor 2001:db8:1::6 peer-group R
 neighbor 2001:db8:1::7 peer-group R
 neighbor 2001:db8:1::8 peer-group R

 neighbor EXABGP activate
 neighbor EXABGP soft-reconfiguration inbound
 neighbor EXABGP maximum-prefix 10
 neighbor EXABGP route-server-client
 neighbor EXABGP route-map RSCLIENT-IMPORT import
 neighbor EXABGP route-map RSCLIENT-EXPORT export
 neighbor 2001:db8:6::11 peer-group EXABGP
 neighbor 2001:db8:7::12 peer-group EXABGP
 neighbor 2001:db8:8::13 peer-group EXABGP

 exit-address-family
!
ipv6 prefix-list LOOPBACKS seq 5 permit 2001:db8:30::/64 ge 128 le 128
ipv6 prefix-list LOOPBACKS seq 10 deny any
!
route-map RSCLIENT-IMPORT deny 10
!
route-map RSCLIENT-EXPORT permit 10
  match ipv6 address prefix-list LOOPBACKS
!
route-map R-IMPORT permit 10
!
route-map R-EXPORT deny 10
!

The view is here to not in­stall routes in the kernel.3

Routers#

Con­fig­ur­ing BIRD to re­ceive routes from route servers is straight­forward:

# BGP with route servers
protocol bgp RS4 {
  import all;
  export none;
  local as 65003;
  neighbor 2001:db8:1::4 as 65002;
  gateway recursive;
}
protocol bgp RS5 {
  import all;
  export none;
  local as 65003;
  neighbor 2001:db8:8::5 as 65002;
  multihop 4;
  gateway recursive;
}

It is im­por­tant to set gateway recursive be­cause most of the time, the next-hop is not reach­able di­rectly. In this case, by de­fault, BIRD will use the IP ad­dress of the ad­ver­tis­ing router (the route servers).

Testing#

Let’s check that ev­ery­thing works as ex­pected. Here is the view from RS5:

# show ipv6  bgp
BGP table version is 0, local router ID is 1.1.1.5
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*  2001:db8:30::1/128
                    2001:db8:6::11         102             0 65001 i
*>                  2001:db8:8::13         100             0 65001 i
*                   2001:db8:7::12         101             0 65001 i
*  2001:db8:30::2/128
                    2001:db8:6::11         101             0 65001 i
*                   2001:db8:8::13         102             0 65001 i
*>                  2001:db8:7::12         100             0 65001 i
*> 2001:db8:30::3/128
                    2001:db8:6::11         100             0 65001 i
*                   2001:db8:8::13         101             0 65001 i
*                   2001:db8:7::12         102             0 65001 i

Total number of prefixes 3

For ex­am­ple, traf­fic to 2001:​db8:30::2 should be routed through 2001:​db8:7::12 (which is W2). Other IPs are as­signed to W1 and W3.

RS4 should see the same thing:4

$ birdc6 show route
BIRD 1.3.11 ready.
2001:db8:30::1/128 [W3 22:07 from 2001:db8:8::13] * (100/20) [AS65001i]
                   [W1 23:34 from 2001:db8:6::11] (100/20) [AS65001i]
                   [W2 22:07 from 2001:db8:7::12] (100/20) [AS65001i]
2001:db8:30::2/128 [W2 22:07 from 2001:db8:7::12] * (100/20) [AS65001i]
                   [W1 23:34 from 2001:db8:6::11] (100/20) [AS65001i]
                   [W3 22:07 from 2001:db8:8::13] (100/20) [AS65001i]
2001:db8:30::3/128 [W1 23:34 from 2001:db8:6::11] * (100/20) [AS65001i]
                   [W3 22:07 from 2001:db8:8::13] (100/20) [AS65001i]
                   [W2 22:07 from 2001:db8:7::12] (100/20) [AS65001i]

Let’s have a look at DR6:

$ birdc6 show route
2001:db8:30::1/128 via fe80::5054:56ff:fe6e:98a6 on eth0 * (100/20) [AS65001i]
                   via fe80::5054:56ff:fe6e:98a6 on eth0 (100/20) [AS65001i]
2001:db8:30::2/128 via fe80::5054:60ff:fe02:3681 on eth0 * (100/20) [AS65001i]
                   via fe80::5054:60ff:fe02:3681 on eth0 (100/20) [AS65001i]
2001:db8:30::3/128 via 2001:db8:6::11 on eth1 * (100/10) [AS65001i]
                   via 2001:db8:6::11 on eth1 (100/10) [AS65001i]

2001:​db8:30::3 is owned by W1 which is be­hind DR6 while the two oth­ers are in an­other part of the net­work and will be reached through the ap­pro­pri­ate link-lo­cal ad­dresses learned by OSPF.

Let’s kill W1 by stop­ping ng­inx. A few sec­onds later, DR6 learns the new routes:

$ birdc6 show route
2001:db8:30::1/128 via fe80::5054:56ff:fe6e:98a6 on eth0 * (100/20) [AS65001i]
                   via fe80::5054:56ff:fe6e:98a6 on eth0 (100/20) [AS65001i]
2001:db8:30::2/128 via fe80::5054:60ff:fe02:3681 on eth0 * (100/20) [AS65001i]
                   via fe80::5054:60ff:fe02:3681 on eth0 (100/20) [AS65001i]
2001:db8:30::3/128 via fe80::5054:56ff:fe6e:98a6 on eth0 * (100/20) [AS65001i]
                   via fe80::5054:56ff:fe6e:98a6 on eth0 (100/20) [AS65001i]

Demo#

For a demo, have a look at the fol­low­ing video: