Post

BGP Fundamentals

BGP Fundamentals

πŸ›°οΈ BGP Fundamentals – Interview & Beginner Friendly Guide

βœ… What is BGP?

BGP stands for Border Gateway Protocol – it’s the standard exterior gateway protocol (EGP) used to exchange routing information between autonomous systems (AS) on the Internet.

🧠 Key BGP Concepts:

  • Layer: Works at Layer 7 (Application Layer) of the OSI model.
  • Transport Protocol: Uses TCP (Transmission Control Protocol).
  • Port Number: TCP port 179.
  • Protocol Type: Path Vector Protocol (unlike Distance Vector or Link State).
  • Slow Protocol: Because of reliability and policy-based nature.

πŸ” Types of BGP

TypeFull FormScopeAdmin Distance
iBGPInternal BGPInside same AS200
eBGPExternal BGPBetween different AS20

πŸ“Œ Note: No auto-discovery or multicast is used in BGP. All neighbors must be configured manually.

🌐 BGP Basics

  • AS (Autonomous System): A group of routers under a single administrative domain.
  • BGP tracks AS-path to determine loop-free routing.
  • BGP can form neighborship with:
    • Directly connected routers
    • Remotely connected routers (static routes used to reach them)

πŸ› οΈ BGP Configuration Syntax

On Cisco routers (example):

1
2
3
router bgp 100
  neighbor <IP> remote-as 500
  network <LAN prefixes>

πŸ”„ BGP Message Types

Message TypePurpose
OPENStart session, exchange BGP version, AS number, BGP ID, Hold Timer
KEEPALIVEHeartbeat, sent every 60s (β…“ of hold timer 180s)
UPDATESend routing info (NLRI – Network Layer Reachability Info)
NOTIFICATIONSend errors, alerts

🧱 TCP/IP Stack Relevance in BGP

LayerNameFunctionBGP RelevancePort Number Role
Layer 7ApplicationHandles application-specific logic (BGP, HTTP, FTP, etc.)BGP runs here as a routing applicationRequests or binds to port 179 (BGP)
Layer 4TransportEnd-to-end communication, reliable delivery using TCPBGP uses TCP for reliable neighbor communicationEncapsulates source & destination ports
Layer 3InternetLogical addressing and routing (IP layer)Uses IP addresses to reach BGP peersNo direct involvement with ports
Layer 2Data LinkPhysical addressing and frame delivery (MAC, Ethernet)Responsible for hop-to-hop delivery on same linkNo direct involvement with ports
Layer 1PhysicalTransmits raw bits over physical medium (cables, fiber, etc.)Underlying physical connectivity between routersNo involvement

πŸ”„ BGP Finite State Machine (FSM)

BGP has several states before a session is fully established:

πŸ”Ή TCP Phase States

  1. Idle
    • Initial state when router bgp <asn> is configured.
    • On neighbor <IP> remote-as <asn>, BGP starts TCP connection (port 179).
    • Initializes BGP resources and listens for incoming connections.
  2. Connect
    • Starts TCP 3-way handshake (SYN, SYN-ACK, ACK).
    • If fails, starts ConnectRetry timer (120s).
    • On failure β†’ goes to Active. On success β†’ OpenSent.
  3. Active
    • Tries new TCP connection.
    • If fails β†’ back to Connect and retries (timer resets).
    • If successful β†’ move to OpenSent.

⚠️ Frequent transition between Connect/Active indicates TCP issues (ACLs, port 179 blocked, IP reachability).

πŸ”Ή BGP Phase States

  1. OpenSent
    • Sends OPEN message (BGP version, ASN, router ID, Hold Timer, optional capabilities).
    • If mismatch/error β†’ sends NOTIFICATION β†’ back to Idle.
    • If matched β†’ move to OpenConfirm.
  2. OpenConfirm
    • Waits for KEEPALIVE message from peer.
    • If received β†’ go to Established.
    • If not received β†’ reset to Idle.
  3. Established
    • BGP session fully up.
    • Exchange UPDATE messages (NLRI, path attributes).
    • Sends KEEPALIVE every 60s (1/3 of Hold Timer 180s).
    • If no UPDATE/KEEPALIVE in hold time β†’ reset to Idle.

🧠 Two-Phase Process

  • Phase 1: TCP Phase – Establish transport connection
    • ➝ Idle β†’ Connect β†’ Active
  • Phase 2: BGP Phase – Exchange BGP messages
    • ➝ OpenSent β†’ OpenConfirm β†’ Established

πŸ” Quick FSM Flow Summary

1
2
3
4
5
6
7
8
9
Idle
 β”œβ”€β–Ά Connect (start TCP handshake)
 β”‚    β”œβ”€β–Ά success β†’ OpenSent
 β”‚    └─▢ fail β†’ Active
 β”‚               β”œβ”€β–Ά success β†’ OpenSent
 β”‚               └─▢ fail β†’ Connect (retry)
OpenSent
 └─▢ OpenConfirm (if OPEN accepted)
       └─▢ Established (if KEEPALIVE received)

βœ… In Established, routes are exchanged via UPDATEs, and session health is maintained via KEEPALIVEs. If any error or timer expires β†’ back to Idle.

πŸ” BGP State Flow Summary

1
Idle β†’ Connect β†’ Active β†’ OpenSent β†’ OpenConfirm β†’ Established

Each transition depends on TCP success/failure and BGP message exchange.

🧩 Inter-AS BGP Example (From Diagrams)

  • R1 (AS 100) ↔ R2 (AS 200): eBGP
  • R2 β†’ R3: Static route (to reach remote peer)
  • R3 ↔ R4 (AS 200): iBGP
  • R4 advertises internal routes to ISP 1/2 using BGP.

πŸ”— Redistribution and Routing

  • Common redistribution from:
    • OSPF β†’ Admin Distance: 110
    • EIGRP β†’ Admin Distance: 90
    • Static β†’ Admin Distance: 1
  • BGP routes can be redistributed to IGPs (OSPF, EIGRP), and vice versa.

🧠 Additional Key Terms

  • NLRI (Network Layer Reachability Info): The actual IP prefixes being advertised.
  • AS Path: Tracks all AS numbers a route has passed through. Used for loop prevention.
  • Hold Timer: Typically set to 180 seconds.
  • Keepalive Timer: Sent every 60 seconds.

πŸ“Œ Interview Tips

  • Know all BGP FSM states and transitions.
  • Be able to explain TCP 3-way handshake in the context of BGP.
  • Understand difference between iBGP vs eBGP.
  • Remember BGP does not use multicast or auto-discovery.
  • Know default Administrative Distances:
    • eBGP = 20
    • iBGP = 200
  • Be able to draw or describe AS-level topologies.

βœ… Conclusion

BGP is the backbone of internet routing. While it’s complex, understanding the message types, state machine, and configuration basics can set a strong foundation for deeper learning and acing interviews.

πŸ™Œ Connect With Me

GitHub LinkedIn YouTube Gmail

This post is licensed under CC BY 4.0 by the author.