DEV Community

Cover image for Networking Series Day-02
mahir dasare
mahir dasare

Posted on

Networking Series Day-02

Think of Border Gateway Protocol (BGP) as the internet's global positioning system (GPS) that maps the routes between major networks. These major networks, like those belonging to large ISPs, universities, or corporations, are called Autonomous Systems (AS). Each AS is identified by a unique Autonomous System Number (ASN).

How BGP Works: A Deeper Look
Instead of calculating the shortest distance, BGP operates as a path-vector protocol. This means it doesn't just look at how "far" a destination is; it looks at the entire path (the sequence of ASNs) a data packet will take to get there.

Peer Connection: Two BGP routers (known as "peers") in different ASes form a TCP connection on port 179. They exchange OPEN messages to set up the session, including their ASNs and capabilities.

Route Advertisement: Once the connection is established, BGP peers send route advertisements in UPDATE messages. These advertisements don't just say, "I can reach this network." Instead, they include a rich set of path attributes that describe the path to that network. The most important attribute is the AS Path, which is a list of all the ASNs the route has passed through.

Loop Prevention: BGP’s path-vector nature is a powerful tool for preventing routing loops. When a router receives a route advertisement, it checks the AS Path. If it sees its own ASN already in the list, it knows the route has been advertised back to it and will ignore that path to avoid a loop.

Route Selection: A BGP router might receive multiple advertisements for the same destination network from different peers. To choose the "best" path, it uses a complex, step-by-step algorithm that evaluates the path attributes in a specific, prioritized order.

Weight: (Cisco proprietary) The highest value is preferred.

Local Preference: The highest value is preferred. This attribute is exchanged within an AS to control the preferred exit path to the internet.

AS Path Length: The path with the fewest ASNs is generally preferred. This is a primary factor in traffic engineering and a core part of BGP's design.

Origin Type: BGP prefers routes that were originated within an AS over those learned from other protocols.

MED (Multi-Exit Discriminator): The lowest value is preferred. An AS can use this attribute to influence how traffic from another AS enters its network when there are multiple connection points.

and many more tie-breaking rules, including a preference for eBGP over iBGP, lowest IGP metric to the BGP next-hop, and lowest router ID.

This entire process, from neighbor discovery to path selection, makes BGP incredibly robust and flexible, allowing network administrators to implement detailed routing policies and manage the flow of traffic across the internet.

Top comments (0)