Skip to main content
Version: 7.26

Understanding BGP

The Border Gateway Protocol (BGP) is an exterior gateway protocol (EGP). It exchanges reachability information between autonomous systems: which prefixes can be reached through which sequence of autonomous systems. BGP is a path-vector protocol. It does not describe the network topology, so it suits routing between autonomous systems, routing policy, and special cases such as route servers and informational feeds. Inside one network, an interior gateway protocol (IGP) such as OSPF finds the paths between the routers, and BGP often runs on top of it.

note

BGP is not available on SMIPS devices (hAP lite, hAP lite TC and hAP mini).

Terminology​

  • AS (autonomous system): a set of routers under one technical administration with a common routing policy.
  • ASN (AS number): the identifier of an AS. Public ASNs are unique worldwide and are assigned by the regional Internet registries, for example RIPE NCC. Private ASNs (RFC 6996) are for internal use.
  • AS path: the sequence of autonomous systems a route has passed through.
  • Path attributes: information carried with a route (AS path, next hop, origin, local preference, MED, communities and others). Routing policy reads and changes them.
  • Routing policy: the rules that decide which routes a router accepts and advertises, and which of several paths it prefers. In RouterOS, routing filters hold the policy.
  • NLRI (Network Layer Reachability Information): the prefixes carried in a BGP update.
  • IGP (interior gateway protocol): a routing protocol inside an AS, such as OSPF or IS-IS.
  • EGP (exterior gateway protocol): a routing protocol between autonomous systems, such as BGP.
  • eBGP: a session between peers in different autonomous systems.
  • iBGP: a session between peers in the same autonomous system.
  • Route reflector (RR): an iBGP router that passes routes between its iBGP clients, so they do not need a full mesh of sessions.
  • Route server: a BGP router, typically at an Internet exchange point, that passes routes between its clients without being in the forwarding path itself.
  • Loopback address: a /32 (IPv4) or /128 (IPv6) address that does not belong to one link, configured on the lo interface or on a bridge without ports.

Protocol basics​

BGP runs over TCP, port 179. After the TCP connection is up, the peers exchange OPEN messages, which carry the AS number, the BGP identifier (router ID), the hold time and the capabilities each side supports (multiprotocol extensions, route refresh, four-octet AS numbers, graceful restart and others). When both peers accept the OPEN message, the session is established.

The peers then send their routes in UPDATE messages. An UPDATE message carries the prefixes (NLRI) and their path attributes, or withdraws prefixes that are no longer reachable. After the first full exchange, BGP sends only changes, so it does not refresh the whole table periodically.

KEEPALIVE messages show that the peer is alive. When no message arrives within the hold time, the router closes the session. The peers use the lower of the two hold times from their OPEN messages, and RouterOS sends a KEEPALIVE every third of the hold time unless keepalive-time is set. With the default hold time of 3 minutes, a KEEPALIVE goes out every minute.

A NOTIFICATION message reports an error (for example a role mismatch in the OPEN message) or an administrative reason to close the session (Cease, for example when the received prefixes exceed a limit). The session closes after a NOTIFICATION.

An AS that has several BGP routers needs a consistent view of the routes inside it. The BGP routers of the AS either all run iBGP with each other (a full mesh), or they peer with route reflectors. Some attributes are handled differently on eBGP and iBGP sessions: for example, LOCAL_PREF is sent only to iBGP peers.

BGP menus in RouterOS​

MenuWhat it holds
/routing/bgp/instanceThe BGP speaker: AS number, router ID, best-path settings.
/routing/bgp/connectionThe peers: address, role, address families, filters, what to advertise.
/routing/bgp/templateParameters that several connections share.
/routing/bgp/sessionRead-only state of each session, and commands to stop, clear and refresh sessions.
/routing/bgp/advertisementsRead-only list of the routes the router sends to each peer.

The Peering sessions page shows how to configure them. BGP-based VPN services have their own menus: L3VPN in /routing/bgp/vpn, EVPN in /routing/bgp/evpn and VPLS in /routing/bgp/vpls.

Route origin​

The router that first advertises a route into BGP sets its ORIGIN attribute. There are three values:

  • igp (0): the route came from inside the AS. RouterOS sets it on networks advertised with the connection's output.network address list.
  • egp (1): the route came from the historic EGP protocol.
  • incomplete (2): the origin is unknown. RouterOS sets it on routes advertised with output.redistribute, for example redistributed connected routes.

A routing filter can change the value with set bgp-origin.

Best-path selection​

A router can receive several paths for the same prefix, for example from two upstream providers. BGP chooses one best path for each prefix and offers it to the routing table, which installs it when no route with a lower distance exists. By default, BGP advertises the active route to its peers.

Only valid routes take part. A route is not used when:

  • Its next hop is not reachable (the route shows the U unreachable flag). See Nexthop selection.
  • Its AS path contains the AS number of the receiving router, unless input.allow-as allows it.
  • An input routing filter rejects it.

BGP compares the valid paths of one BGP instance step by step. The first step where the paths differ decides:

  1. Prefer the path with the highest WEIGHT. WEIGHT is a RouterOS value that is local to the router: an input routing filter sets it (set bgp-weight), and it is never advertised. A path without a weight has weight 0.
  2. Prefer the path with the highest LOCAL_PREF. LOCAL_PREF is used only within an AS. A path without LOCAL_PREF counts as 100.
  3. Prefer the path with the shortest AS_PATH. This step is skipped when ignore-as-path-len is set to yes on the instance. Each AS_SET counts as 1, whatever its size. AS_CONFED_SEQUENCE and AS_CONFED_SET are not counted.
  4. Prefer the path with the lowest ORIGIN: igp before egp, egp before incomplete.
  5. Prefer the path with the lowest multi-exit discriminator (MED). By default the router compares MED only between paths from the same neighboring AS (the leftmost AS in the path). With always-compare-med set to yes, it compares the MED of all paths. Confederations are not considered when determining the neighboring AS. A path without MED counts as MED 0.
  6. Prefer eBGP paths over iBGP paths.
  7. When multipath is set on the instance, stop here: the paths that are still equal are all installed as ECMP routes, up to the configured number.
  8. Prefer the path with the lowest IGP metric to the next hop.
  9. Prefer the path from the BGP router with the lowest router ID. When a route carries the ORIGINATOR_ID attribute, ORIGINATOR_ID is used instead of the router ID.
  10. Prefer the path with the shortest route reflection CLUSTER_LIST. A route without a cluster list counts as length 0.
  11. Prefer the path from the lowest neighbor address.

The installed path has the A (active) flag in the routing table; the other paths are candidates. /routing/route/print detail where dst-address=<prefix> shows the attributes the steps compare (bgp.weight, .local-pref, .as-path, .origin, .med). The Route selection and filtering page shows how to change the attributes with input filters and how to advertise other paths than the best one.

Multiple instances​

A router can run more than one BGP instance in /routing/bgp/instance, for example a separate instance for a VPN service. Two things work per instance:

  • Best-path selection compares only the paths of one instance. Paths for the same prefix from two instances are compared by the general route selection: the lower distance wins, and with equal distances both are installed as ECMP routes.
  • A connection advertises the routes of its own instance. BGP routes received by another instance are not sent, unless the connection has output.redistribute set to bgp.

Supported standards​

  • RFC 4271 Border Gateway Protocol 4
  • RFC 4456 BGP Route Reflection
  • RFC 5065 Autonomous System Confederations for BGP
  • RFC 1997 BGP Communities Attribute
  • RFC 8092 BGP Large Communities
  • RFC 4360, 5668 BGP Extended Communities
  • RFC 2385 TCP MD5 Authentication for BGPv4
  • RFC 5492 Capabilities Advertisement with BGP-4
  • RFC 2918 Route Refresh Capability
  • RFC 4760 Multiprotocol Extensions for BGP-4
  • RFC 2545 Use of BGP-4 Multiprotocol Extensions for IPv6 Inter-Domain Routing
  • RFC 4893 BGP Support for Four-octet AS Number Space
  • RFC 4364 BGP/MPLS IP Virtual Private Networks (VPNs)
  • RFC 4761 Virtual Private LAN Service (VPLS) Using BGP for Auto-Discovery and Signalling
  • draft-ietf-l2vpn-signaling-08 Cisco VPLS BGP-based auto-discovery
  • RFC 6286 AS-wide Unique BGP Identifier for BGP-4
  • RFC 4273 SNMP peer table monitoring (OID 1.3.6.1.2.1.15.3.1) (IPv4 only)
  • RFC 6793 4-byte ASN support and Aggregator attribute
  • RFC 4486 Subcodes for BGP Cease Notification Message
  • RFC 4659 MPLS VPN Extension for IPv6
  • RFC 8950 Advertising IPv4 Network Layer Reachability Information (NLRI) with an IPv6 Next Hop
  • RFC 6811 BGP Prefix Origin Validation
  • RFC 6996 Autonomous System (AS) Reservation for Private Use
  • RFC 9234 Route Leak Prevention and Detection Using Roles in UPDATE and OPEN Messages
  • RFC 5549 Advertising IPv4 Network Layer Reachability Information with an IPv6 Next Hop