BGP · Topic 1 of 4

BGP Operation, Messages and Attributes

Learn how BGP sessions form over TCP 179, the Open, Update, Keepalive and Notification messages, session states and the main path attributes for JN0-352.

  • 5 min
In a nutshell
  • BGP runs over TCP port 179 between manually configured peers.
  • States in order: Idle, Connect, Active, OpenSent, OpenConfirm, Established.
  • Messages: Open, Update, Keepalive, Notification (plus Route Refresh).

What it is

Border Gateway Protocol (BGP) is the path vector routing protocol that carries routes between autonomous systems. An autonomous system (AS) is a set of networks under one administration, identified by an AS number. Inside an enterprise, BGP is also used between routers of the same AS.

BGP does not discover neighbors. You configure each peer by hand, and the two routers form a session over TCP port 179. Routes are exchanged as prefixes with attributes, and the attributes decide which path wins.

Idlestart eventConnectTCP upOpenSentopen receivedOpenConfirmkeepalive receivedEstablishedConnectTCP failsActiveretryConnect

How it works

Session states

StateMeaning
IdleNo resources allocated; waiting to start or to retry after an error
ConnectWaiting for the TCP connection to complete
ActiveThe TCP attempt failed or is being retried; the router is trying to connect
OpenSentTCP is up and an Open message was sent
OpenConfirmAn Open was received and checked; waiting for a Keepalive
EstablishedPeers exchange Update messages and routes

Only Established carries routes. A peer stuck in Active or Connect means TCP cannot complete, usually a reachability, address or filter problem. A peer that bounces between Idle and Active often fails the Open checks.

Message types

BGP uses four messages, all with a common header.

MessagePurpose
OpenStarts the session; carries BGP version (4), local AS, hold time, BGP identifier and capabilities
UpdateAdvertises new routes with their attributes, or withdraws routes
KeepaliveHeader only; proves the peer is alive
NotificationReports an error and closes the session

The hold time is negotiated to the lower of the two values in the Open messages. The Junos default hold time is 90 seconds, and keepalives are sent at one third of the hold time, so every 30 seconds. If no message arrives within the hold time, the session drops.

Each side checks the other's Open message. The AS number you configure as peer-as must match the AS in the Open sent by the peer, or the router sends a Notification and the session fails. The two routers must also have different BGP identifiers (router IDs).

Exam tip

A session that never leaves Active even though the TCP path works points to a configuration mismatch. Compare peer-as with the real AS of the neighbor, then look at show bgp neighbor for the last error.

A fifth message, Route Refresh, asks a peer to resend its routes after a policy change. It is negotiated as a capability and avoids resetting the session.

Path attributes

Every route in an Update carries path attributes. They fall into four categories.

CategoryMeaningExamples
Well known mandatoryMust be supported and present in every UpdateORIGIN, AS_PATH, NEXT_HOP
Well known discretionaryMust be supported, may be absentLOCAL_PREF, ATOMIC_AGGREGATE
Optional transitiveMay be unrecognized; passed along if soCOMMUNITY, AGGREGATOR
Optional nontransitiveMay be unrecognized; dropped if soMED (MULTI_EXIT_DISC), ORIGINATOR_ID, CLUSTER_LIST

What the common attributes do:

  • ORIGIN tells how the route entered BGP: IGP (best), EGP, or incomplete (worst, usually redistributed).
  • AS_PATH lists the autonomous systems the route crossed. It is used for loop prevention and path length. A router drops a route whose AS path already contains its own AS.
  • NEXT_HOP is the address to forward to. EBGP sets it to the advertising router's address; IBGP leaves it unchanged by default.
  • LOCAL_PREF is sent only to IBGP peers and ranks exit points inside an AS. Higher is better. Junos assumes 100 when none is set.
  • MED suggests to a neighboring AS which entry point to use. Lower is better, and it is sent to the neighbor AS but not passed beyond it.
  • COMMUNITY is a tag, such as 65001:100, that policies match and act on.
Local ASLOCAL PREF stays insidesent toNeighbor ASMED sent oncenot passed onThird AS

Default advertising behavior

With no export policy, Junos advertises active BGP routes to BGP peers. It does not advertise static, direct or IGP routes. To originate your own networks you need an export policy that matches them, shown on the routing policy page.

BGP routes have a Junos route preference of 170. A prefix also learned from OSPF internal (10) or a static route (5) uses those instead, because the lowest preference wins in the routing table.

user@router> show bgp summary
Groups: 1 Peers: 1 Down peers: 0
Peer           AS     InPkt  OutPkt  OutQ  Flaps  Last Up/Dwn  State|#Active/Received/Accepted/Damped...
192.0.2.2   65002       120     118     0      0     0:49:10   2/3/3/0

In the State column, a set of numbers means the session is Established. A word such as Active means it is not.

Common mistakes

Assuming BGP finds neighbors. Both sides need neighbor and the matching AS configured. If only one side is configured, the session stays in Active or Connect.

Confusing MED and LOCAL_PREF. LOCAL_PREF stays inside your AS and higher wins. MED goes to the neighbor AS and lower wins.

Expecting BGP to advertise connected networks. The default export covers BGP routes only.

Watch out

Do not read Active as "working". In BGP, Active means the router is still trying to open the TCP connection.

What to remember for the exam

  • BGP runs over TCP port 179 between manually configured peers.
  • States in order: Idle, Connect, Active, OpenSent, OpenConfirm, Established.
  • Messages: Open, Update, Keepalive, Notification (plus Route Refresh).
  • Hold time default 90 seconds, keepalive 30 seconds; the lower hold time wins.
  • Mandatory well known attributes: ORIGIN, AS_PATH, NEXT_HOP.
  • LOCAL_PREF is higher-wins and IBGP only; MED is lower-wins and optional nontransitive.
  • Default Junos BGP route preference is 170.
  • With no policy, only active BGP routes are advertised.

Check yourself

  • Which BGP message closes a session after an error?

    The Notification message, which reports the error and ends the session.

  • What does a peer showing the state Active mean?

    TCP has not completed; the router is still trying to connect, so no routes are exchanged.

  • Which attribute picks the exit from your AS, and which suggests the entry to a neighbor?

    LOCAL_PREF picks the exit and higher wins; MED suggests the entry and lower wins.

Topic 1 of 4 in BGP

Test yourself on BGP

The full Juniper JNCIS-ENT JN0-352 question bank has 846 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.