Topic: tech juniper jir prev next

tech juniper jir > 09: Fundamentals of BGP

09: Fundamentals of BGP

Overview of BGP

BGP is a path vector protocol. It is the core routing protocol on the Internet.

Path vector means that BGP routing information contains a series of ASNs to route packets through the network.

BGP is primarily used for routing on the Internet, but it is also used for MPLS VPNs and to separate large OSPF networks. BGP is more scalable and offers a greater degree of control through policy than an interior gateway protocol (IGP).

An autonomous system is a set of routers that operate under the same administration and offer a unified routing policy to the rest of the world. BGP uses the routing information to maintain an information base of Network Layer reachability information (NLRI). It is a classless routing protocol which supports prefix routing, irrespective of the network sizes.

BGP exchanges information between peers. Without configuration changes, the peers must be directly connected for inter-AS routing. Peers exchange information over a TCP connection. BGPv4 is essentially the only exterior gateway protocol (EGP) used on the Internet.

When Should You Use BGP

There is little benefit to using a dynamic routing protocol when a customer has only one connection to the Internet. They would more likely use a static default route. Usually, a customer will have IP addresses assigned from the ISP’s allocation. These are nonportable addresses and cannot be announced by another ISP. They can be aggregated with other customers’ IP addresses to be announced by the ISP.

A customer with portable address space will have their own AS and will use BGP to announce their address space via one or more ISPs.

BGP Loop Avoidance

Exchanges between ASs use the external session type (EBGP). Exchanges within the same AS use the internal session type (IBGP). The EBGP session is established only between directly connected routers, because the TTL of the BGP packets is set to 1. If there are multiple BGP speakers in an AS, then IBGP must be used to establish sessions between them. The routers’ loopback addresses are usually used when establishing IBGP sessions, for stability.

BGP Peering

Unlike other routing protocols, BGP sessions must be manually defined. There is no automatic neighbour discovery mechanism.

BGP transitions through several states when establishing a neighbour relationship. The first three states are part of the underlying TCP transport protocol. The latter three states are part of BGP.

BGP maintains the TCP connection for the life of the BGP relationship. If the peers do not exchange messages before a hold timer, the session is terminated.

BGP Message Types

Examples of notification messages include when an unsupported feature is used, or when the remote peer has allowed the hold timer to expire.

The refresh message allows a peer to send routing information which has already been sent previously. It is used in some MPLS networks.

BGP Update Messages

A BGP update message includes a single path, then lists prefixes which can be reached through the path. An update can also remove multiple prefixes, regardless of their paths.

BGP Attributes

Attribute classes are described in RFC1771. They are well-known mandatory, well-known discretionary, optional transitive, or optional nontransitive.

Well-known mandatory attributes must be understood by every BGP implementation and included in every BGP update. Well-known discretionary attributes must be understood by every BGP implementation but not necessarily included in every BGP update.

Optional transitive attributes not required to be supported, but if they are, they should be passed along unchanged to other peers. Optional nontransitive attributes are not passed on if not understood.

Well known mandatory BGP attributes:

Well known discretionary BGP attributes:

Optional transitive BGP attributes:

Optional nontransitive BGP attributes:

Purpose of BGP Attributes

The purpose of BGP is to find the best path, not necessarily the shortest path. BGP includes attributes to help routers belonging to the source, destination, and transit ASs, to make routing decisions based on their own routing policies.

Next Hop

The IP address of the peer advertising the prefix. The Next Hop address must be reachable for the receiving peer to install the route in the local routing table. The Next Hop value is changed by default across EBGP links only; it is not changed across IBGP links.

In Junos, if the next hop is not reachable, the route is entered into the routing table as a hidden route. Hidden routes can be shown with the show route hidden command.

Local Preference

Determines the preferred path out of the AS. All BGP traffic in an AS flows towards the peer with the highest local preference value. The default local preference is 100.

Local preference values are only used within an AS; nothing is sent over EBGP links.

Junos allows the local preference to be assigned through BGP configuration and routing policy. If both are set, the value set in the routing policy takes priority.

AS Path

The list of ASs the route has been through already. If the receiving ASN is in the path, the router drops the route, as adding it to the routing table would cause a routing loop.

The same AS can be prepended several times, to discourage routers in other ASs from using the path.

Origin

Added by the router that initially injected the route into BGP, to describe where the route came from. The three possible values are 0 (IGP), 1 (EGP), 2 (incomplete).

By default, Junos assigns routes injected into BGP the value 0 (IGP). This behaviour can be changed with routing policy.

Multiple Exit Discriminator

MED is only used when there are multiple paths between the same two ASs. It helps to influence the preferred back into an AS. Lower values are better.

In Junos, the MED value can be configured through BGP configuration (using the metric-out statement at protocol, peer or group level), or routing policy (using the metric action in the then statement).

Community

An identifier that applies to several prefixes that have a common property. In Junos, communities are configured as actions under policy-options.

policy-options {
    policy-statement ibgp-export {
        from neighbor ...;
        then {
            community set customer-route;
        }
    }
    community customer-route members 64700:133;
}

BGP communities usually take the form ‘ASN:commnuity’. Multiple communities can be set for the same prefix. They can be set, added, or deleted in a routing policy, using the add, delete and set keywords, or the shorthand +, -, and =.

Selecting the Active BGP Route

Before installing a route, the router must make sure that the next hop is reachable, and that it will not create a loop. If multiple routes for a BGP prefix are learned, the one with the lowest route preference is selected.

The BGP path is selected as follows;

  1. Prefer the highest local-preference value
  2. Prefer the shortest AS-path length (this is a common tiebreaker)
  3. Prefer the lowest origin value
  4. Prefer the lowest MED value
  5. Prefer routes learned from an EBGP peer over an IBGP peer
  6. Prefer best exit from AS
  7. For EBGP-learned routes, prefer the current active route; otherwise, prefer routes from the peer with the lowest router id
  8. Prefer paths with the shortest cluster length
  9. Prefer routes from the peer with the lowest peer ID

For IBGP peers, install a next physical hop based on the inet.0 and inet.3 routing tables. The best route from either table wins. This usually means that an MPLS label-switched path from the inet.3 table wins. If the two tables tie, select the route from inet.3. When a preference tie exists in the same table, use the next hop with the greatest number of equal-cost paths. This tie occurs when traffic-engineering bgp-igp is configured.