TCP for Routing Engineers: The Transport Every BGP Session Rides On
Why BGP Hands Its Transport to TCP
Most routing protocols carry their own reliability. OSPF acknowledges every LSA, EIGRP has its Reliable Transport Protocol, and IS-IS uses sequence number PDUs. BGP does none of that. It opens a TCP connection to port 179 on its neighbour and lets TCP deliver every byte in order, retransmit what is lost and slow down when the receiver cannot keep up. For a routing engineer this is the single most important design fact about BGP, because it means a BGP session can only be as healthy as the TCP connection underneath it.
The choice made sense from the start. BGP was designed to exchange very large tables between networks run by different organisations, over paths that might cross several routers. Today a full IPv4 Internet table is roughly 1.08 million prefixes. Moving that much data reliably is exactly what TCP was built for, so BGP reuses it instead of reinventing it. The price is that every TCP problem, from a blocked port to a wrong MTU, becomes a BGP problem.
The relationship also explains why BGP neighbours are configured, never discovered. OSPF and EIGRP find neighbours with multicast hellos on a link. BGP cannot, because TCP is unicast and the neighbour may be several hops away. Every peer is named explicitly with "#neighbor", and the router needs a working route to that address before anything else can happen.
R1(config)#router bgp 65001
R1(config-router)#neighbor 10.1.12.2 remote-as 65002
Once the neighbour is configured, both routers try to open a TCP connection to the other's port 179. The router that opens the connection is the active side and uses a random high source port. The router that accepts it is the passive side and listens on port 179. A normal three-way handshake follows: SYN, SYN-ACK, ACK. Only after that does BGP send its first message, the OPEN, and the BGP finite state machine moves from Connect or Active through OpenSent and OpenReceive to Established.
R1#show tcp brief
TCB Local Address Foreign Address (state)
7FBA5C4D2A10 10.1.12.1.179 10.1.12.2.52713 ESTAB
This single line already tells you who opened the session. R1 owns port 179, so R1 was passive and R2 actively connected from port 52713. On another day, after a reset, the roles may be reversed, because both sides keep trying.
Reading the TCP Side of a BGP Session
With that background, the long output of "#show ip bgp neighbors" becomes much easier to read, because its lower half is almost pure TCP. Most engineers stop reading after the BGP state line, and that is where many problems hide.
R1#show ip bgp neighbors 10.1.12.2 | begin Connection state
Connection state is ESTAB, I/O status: 1, unread input bytes: 0
Connection is ECN Disabled, Mininum incoming TTL 0, Outgoing TTL 1
Local host: 10.1.12.1, Local port: 179
Foreign host: 10.1.12.2, Foreign port: 52713
Connection tableid (VRF): 0
Maximum output segment queue size: 50
Enqueued packets for retransmit: 0, input: 0 mis-ordered: 0 (0 bytes)
Event Timers (current time is 0x1A2B3C):
Timer Starts Wakeups Next
Retrans 14 0 0x0
TimeWait 0 0 0x0
AckHold 13 11 0x0
SendWnd 0 0 0x0
KeepAlive 0 0 0x0
GiveUp 0 0 0x0
PmtuAger 1 0 0x1A6E80
DeadWait 0 0 0x0
Linger 0 0 0x0
ProcessQ 0 0 0x0
iss: 3485217701 snduna: 3485218102 sndnxt: 3485218102
irs: 1972214509 rcvnxt: 1972214910
sndwnd: 16004 scale: 0 maxrcvwnd: 16384
rcvwnd: 15984 scale: 0 delrcvwnd: 400
SRTT: 287 ms, RTTO: 1103 ms, RTV: 816 ms, KRTT: 0 ms
minRTT: 1 ms, maxRTT: 1000 ms, ACK hold: 200 ms
uptime: 412093 ms, Sent idletime: 21844 ms, Receive idletime: 22044 ms
Status Flags: passive open, gen tcbs
Option Flags: nagle, path mtu capable
IP Precedence value : 6
Datagrams (max data segment is 1460 bytes):
Rcvd: 18 (out of order: 0), with data: 13, total data bytes: 400
Sent: 26 (retransmit: 0, fastretransmit: 0, partialack: 0, Second Congestion: 0), with data: 14, total data bytes: 400
The first lines describe the connection itself: its TCP state, the local and remote addresses and ports, and two TTL values. "Outgoing TTL 1" is the default for a directly connected eBGP neighbour, and "Mininum incoming TTL 0" means no TTL check is applied to received packets. The spelling "Mininum" is Cisco's own typo, so do not let it confuse a search.
The "Event Timers" table shows TCP's own timers. A rising Retrans count means segments are being lost and resent. The KeepAlive row at zero is worth noticing: BGP sessions do not use TCP keepalives. Liveness is BGP's job, through its own KEEPALIVE messages and the hold timer, 180 seconds by default on Cisco.
The sequence numbers (iss, snduna, sndnxt, irs, rcvnxt) show how much data has moved and whether anything is still unacknowledged. When snduna and sndnxt are equal, every byte sent has been acknowledged. The window lines show how much data each side can accept, and the round trip times show the delay TCP measured.
Two lines near the end matter for every later module. "Status Flags: passive open" confirms that the remote side initiated this connection. "max data segment is 1460 bytes" is the TCP maximum segment size, the largest chunk of BGP data per packet. On Ethernet that figure comes from a 1500-byte MTU minus 40 bytes of IP and TCP headers, and it decides how fast a large table can be sent.
When Both Sides Connect at Once, and Other CCIE Details
Because both routers try to connect, sometimes both succeed at the same moment, and that leads to the first of several CCIE-level details. Two TCP connections now exist for one BGP relationship, which is called a connection collision. BGP resolves it with the BGP identifier: the connection opened by the router with the higher Router-ID is kept, and the other is closed. The rule is deterministic, so both routers reach the same decision without negotiating.
You can also decide in advance who opens the session. On IOS XE, "#neighbor 10.1.12.2 transport connection-mode passive" makes R1 only listen, never connect. On IOS XR the same idea is "#session-open-mode", with the values active-only, passive-only or both, where both is the default. This is useful when one side sits behind a firewall that only allows connections in one direction, or when you want predictable port numbers for filtering.
R1(config)#router bgp 65001
R1(config-router)#neighbor 10.1.12.2 transport connection-mode passive
R1#show ip bgp neighbors 10.1.12.2 | include Transport|passive
Transport(tcp) path-mtu-discovery is enabled
Connection mode is passive
Status Flags: passive open, gen tcbs
A second detail is the time a router waits for a TCP handshake to finish. The global "#ip tcp synwait-time" defaults to 30 seconds, with a range of 5 to 300. A half-open connection that never completes is abandoned after that time, and the BGP state machine moves on to its next attempt.
A third detail concerns tuning TCP itself. On IOS XE, BGP sessions use path MTU discovery by default, while the global "#ip tcp path-mtu-discovery" for other TCP sessions is off. Selective acknowledgement, enabled with "#ip tcp selective-ack", is also off by default. These defaults, and what happens when the path MTU is smaller than expected, have their own post in this series.
The habit to take from all of this is to read BGP problems from the bottom up. If a session will not establish, ask first whether TCP can connect: is there a route to the neighbour, is port 179 reachable, and do the TTL and authentication settings match? If a session is up but slow or unstable, look at the TCP half of "#show ip bgp neighbors" for retransmissions, a small segment size or a stalled window. BGP decides what to say. TCP decides whether it gets there.