> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/cgw/1.8/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/cgw/1.8/architecture/bgp-ha-two-sides-full-vpn-bfd.md).

# High available routed attachment over VPN-secured links with liveness probes

This document explains which protocols are running on which links and how they are stacked.
This may be useful if debugging becomes necessary.

The following picture shows the overall architecture, as well as labels the links, components, and interfaces:

![HA BGP VPN full mesh](https://docs.cennso.com/api/assets/components/cgw/1.8/assets/HA-BGP-VPN-full-meshed.svg)

## Routed traffic in CGW

The tour through the protocol stack in CGW side A starts on the left side at `C1`.
In this case, as in MODEL-1, the VXLAN we use to connect to the other network
functions is drawn as a switch, as the VXLAN actually works as a layer 2
network running over layer 3.

![VXLAN layers](https://docs.cennso.com/api/assets/components/cgw/1.8/assets/vxlan-layers.svg)

Incoming packets from VXLAN on interface `INT1` are then decapsulated
and go through the routing engine of the kernel.
If the packets are targeted to networks on the other side (behind C or D), the
path depends on the priority of the router A vs router B.

In the case router B has a higher priority, the packets are sent over `INT5`
to `INT15` on router B and the routing step is repeated there.

In a simpler case for this description, router A has the priority and
the packet is routed to this router.

## GRE

Now it depends, whether GRE must be used as a tunnelling protocol or not.
It is possible to not use GRE when both ends (side A and B, as well as C and
D) support VTI interfaces and assign the correct IP addresses to the
interfaces.
Further tunnelling IPv4 and IPv6 over the same VTI interface is not yet
supported on Linux.

Due to incompatibilities between the different routers and different specifications of
what is supported, GRE must be used in a lot of cases to provide a virtual
point to point link.
GRE is a well-suited protocol for this use case.
The drawback, though, is that additional computation must be performed and MTU
is reduced by 4-16 bytes for the GRE header and an additional IP header.

![GRE layers](https://docs.cennso.com/api/assets/components/cgw/1.8/assets/GRE-layers.svg)

The virtual GRE interface has an inner IP address (on `INT2`), as well
as an outer IP address (on `INT3`).
This is common to all tunnel protocols.
In this setup, `INT3` is the VTI interface of the tunnel (see MODEL-1).

In the case GRE is used, the packet is routed through the IP of `INT23` and
therefore through interface `INT2` of CGW A.
The packets are encapsulated in a GRE header and an additional IP header.

## Encryption

Next, the packet is routed to the other side of the VTI peer-to-peer
link. Because it is a static route in the kernel that must not be
changed by the user, the details are omitted in the graphic.

The packet is then encapsulated and encrypted in the ESP header and sent over
the internet to the other side.

In this example, it is assumed that side C has a higher preference and
therefore the packet layers on L41 between `INT4` and `INT21` are as
follows:

![GRE over ESP](https://docs.cennso.com/api/assets/components/cgw/1.8/assets/GRE-over-ESP.svg)

The bottom IP header contains the IP of `INT4` as the source address and the
IP of `INT21` as the destination address.
The middle IP header contains the IP of `INT3` as the source address and the
IP of `INT22` as the destination address.
The top IP header contains the IP of the source network function on our side
as the source address and the IP of the destination on the other side as the
destination IP address.

On side C, the packets are first decrypted, then decapsulated, and then reach
the routing function of the other side and are routed to the destination.

## High availability

If you have not already, read the documents on
[Routing basics](https://docs.cennso.com/components/cgw/1.8/introduction/routing_basics.md) and
[Bidirectional Forwarding Detection](https://docs.cennso.com/components/cgw/1.8/introduction/bfd.md) first.

In this setup, even if any of the CGWs or connecting functions on the other side,
as well as every connection fails, the setup still
provides connectivity.

To ensure this, the routers on each side are connected to two routers on the
other side.
One of the local routers, as well as one of the other routers have a
preference.
In the case that all routers are active, only one on each side
actually transfers traffic.

There are other configurations using ECMP but this is not considered
here.

In the case the preferred router dies, the traffic is routed over the
spare router.
This failure can either be detected by BGP itself or by BFD, which takes
considerably less time.

In the case of a connection loss of the preferred router to both routers of
the other side, it is still able to forward traffic for the internal network over the secondary router.
This behaviour assumes that the internal network does not run IGP protocols.
