BGP For Dummies
BGP For Dummies
tv
BGP for Dummies
www.itbase.tv
Contents
• General definitions
• BGP working principle
• BGP Attributes
www.itbase.tv
1.1 Autonomous System - AS
• A collection of networks that is managed, supervised by an entity or a single organization, or network carrier/ISP
• Each AS is unique and defined by a number (ASN)
• ASN uses 16-bit integer, ranges from 1 – 65535, can be reserved for public or private use
• There is also 32-bit ASN for future.
GENERAL DEFINITION
ABCD
1234 16684
www.itbase.tv
1.2 Border Gateway Protocol - BGP
• BGP is a common routing protocol to connect ASNs together, and can also be used within an ASN
• BGP uses Transmission Control Protocol (TCP) as its transport protocol, commonly TCP port 179
• We call external BGP – eBGP when connecting 2 different ASNs (or 2 different network carriers)
• We call internal BGP – iBGP when connecting small networks within the same ASN (or same carrier network)
• Routers running BGP also can be called BGP speakers, that exchange routing information between
ABCD
Vz
1234
16684
www.itbase.tv
1.3 BGP Neighbor (or Peer)
• The neighbor (peer) means the router/device we are trying to establish BGP connection to.
• Need to manually configure point-to-point connection between two routers, not automatically formed.
ISP configure
BGP here
ABCD
Vz
1234
16684
Neighbor
Vz need to
configure BGP
as well
www.itbase.tv
1.4 eBGP & iBGP Peering
• New routes learned from an eBGP peer are re-advertised to all iBGP and eBGP peers.
AS: ASN1
R1 R2
iBGP
LAN1/subnet1 LAN2/subnet2
R1 Configuration# R2 Configuration#
router bgp [ASN1] router bgp [ASN1]
neighbor [LAN2] remote-as [ASN1] neighbor [LAN1] remote-as [ASN1]
eBGP R1 R2
LAN1/subnet1 LAN2/subnet2
R1 Configuration# R2 Configuration#
router bgp [ASN1] router bgp [ASN2]
neighbor [LAN2] remote-as [ASN2] neighbor [LAN1] remote-as [ASN1]
State Process
2.1 BGP Exchange – 6 States - Quick
www.itbase.tv
2.1 BGP Exchange – 6 States - Quick
• Refuse all incoming BGP connections
Idle • Initialize/attempt a TCP handshake to peer(s)
• If error, restart process
• Awaiting TCP handshake completion:
1.IDLE
Connect + Success: move to OpenSent
+ Failure: move to Active
www.itbase.tv
2.2 Best Path Selection
• To deal with multiple routes leading to a
same destination, BGP needs multiple
considerations (attributes) to determine
the best path among all.
Lowest
www.itbase.tv
3.1 Weight
• Weight is a router brand-specific parameter, its use is confined to the router it is configured on.
• Therefore, weight is not exactly a standard BGP attribute
• Cisco routers have Cisco-specific weights, whose usage for Cisco routers only. The same for Huawei with PreVals, and
for other brands.
• The route/path has the highest weight is preferred.
AS 1
Scenario: After learning route “172.16.0.0“ from R1, 172.16.0.0
both R2 and R3 advertise to R4. R4 has configuration below:
R4#
router bgp 4
BGP ATTRIBUTES
neighbor 10.1.1.1 remote-as 2 R1
neighbor 10.1.1.1 weight 200
Universally supported by all BGP speakers May not be recognized by all BGP speakers
Transitive nature by default
Well-known Optional
Must be included in every May or not be presented in Info can be passed to other peers, Must not be passed
route advertisement route advertisement from one ASN to another beyond next-hop router
i – Internal Atomic
Originator
Aggregate
(ex: from RIP, OSPF, EIGRP?) No-Export
e – External Cluster-ID
(from another eBGP?) No-Advertise
? – Incomplete
(unknown, private source) Internet
Local-AS
www.itbase.tv
3.2.1 BGP Attribute – AS Path
• AS Path is a collection of ASs that a path has goes through, used to detect and avoid loops.
• The shortest AS Path is more preferred.
• Example below has R1 chosen R4 as the next-hop to destination “192.0.2.0/24”, because AS path via R4 is shortest
AS 200 AS 300
3.3.3.0/30
R2 R3
.2
R1 .1 R4 R5
4.4.4.0/30 .2 .5 4.4.4.4/30 .6 192.0.2.0/24
R1 .1 R4 R5
4.4.4.0/30 .2 .5 4.4.4.4/30 .6 192.0.2.0/24
R1 .1 R4 R5
4.4.4.0/30 .2 .5 4.4.4.4/30 .6 192.0.2.0/24
• Local Preference (LP) is exchanged between BGP speakers within same AS only.
• LP helps choose the best among outbound BGP paths (paths to exit from one AS to go to another AS)
• Path with highest LP is chosen.
R2#
router bgp 100
neighbor 2.2.2.2 remote-as 500
.1 neighbor 1.1.1.1 remote-as 100
AS 100 .2 bgp default local-preference 800
R2
AS 500 R3#
.1 .2 router bgp 100
neighbor 3.3.3.2 remote-as 500
R1 .2 R5 neighbor 1.1.1.5 remote-as 100
.5 bgp default local-preference 500
.6 R3 .1
R3#
.1 router bgp 100
AS 100 .2
R2 neighbor 3.3.3.2 remote-as 500
neighbor 3.3.3.2 route-map R5_to_R3 in
AS 500
.2 neighbor 1.1.1.5 remote-as 100
.1
.5 route-map R5_to_R3 permit 10
R1 .2 .2R5 set metric 50
.9
.6 R3 .1 R4#
router bgp 300
neighbor 4.4.4.2 remote-as 500
neighbor 4.4.4.2 route-map R5_to_R4 in
AS 300 neighbor 1.1.1.9 remote-as 100
.1
AS 100 .2 R5 go to R1 AS Path
R2
Via R2 500
AS 500
.1 .2 Via R3 500
.5 Via R4 300 500
R1 .2 .2R5
.9
.6 R3 .1
AS 300
.10 R4 .1
www.itbase.tv
3.2.3 BGP Attribute – Metric
• We can force router to ignore comparing AS_PATH, and to compare Metric using “bgp bestpath as-path ignore”
• Then R5 can compare all MED values equally R5#
router bgp 500
neighbor 2.2.2.1 remote-as 100
neighbor 3.3.3.1 remote-as 100
neighbor 4.4.4.1 remote-as 300
.1 bgp bestpath as-path ignore
AS 100 .2
R2
AS 500
.1 .2
.5
R1 .2 .2R5
.9
.6 R3 .1
AS 300
.10 R4 .1
www.itbase.tv
3.2.4 BGP Attribute –
• We can force router to ignore comparing AS_PATH, and to compare Metric using “bgp bestpath as-path ignore”
• Then R5 can compare all MED values equally R5#
router bgp 500
neighbor 2.2.2.1 remote-as 100
neighbor 3.3.3.1 remote-as 100
neighbor 4.4.4.1 remote-as 300
.1 bgp bestpath as-path ignore
AS 100 .2
R2
AS 500
.1 .2
.5
R1 .2 .2R5
.9
.6 R3 .1
AS 300
.10 R4 .1
www.itbase.tv
interface GigabitEthernet0/0 interface GigabitEthernet0/0
ip address 192.168.1.2 255.255.255.0 ip address 192.168.1.1 255.255.255.0
no shutdown no shutdown
#show ip bgp
Network Next Hop Metric LocPrf Weight Path
* 20.0.0.0/24 192.168.1.2 0 200 0 65002 i
R3 * 30.0.0.0/24 192.168.1.3 0 100 0 65003 i
interface GigabitEthernet0/0
ip address 192.168.1.3 255.255.255.0
no shutdown
R2 R1
#show ip route
Gateway of last resort is not set
#show ip route
Gateway of last resort is not set
APPENDIX www.itbase.tv
www.itbase.tv
Autonomous System (AS) Usage
Full Partial
www.itbase.tv
A TCP Handshake
A TCP Handshake
CLIENT SERVER
CLOSED CLOSED
Passive Open:
Active Open: Wait for Client
Send SYN request LISTENING
SYN
Receive SYN
Send SYN+ACK
SYN-SENT
Wait for ACK
To SYN
SYN+ACK SYN-RECEIVED
www.itbase.tv
2.1 BGP Exchange – 6 States - Slow
IDLE STATE
5.OPENCONFIRM
6.ESTABLISHED
2.1 BGP Exchange – 6 States - Slow
www.itbase.tv
2.1 BGP Exchange – 6 States - Slow
CONNECT STATE
6.ESTABLISHED
2.1 BGP Exchange – 6 States - Slow
www.itbase.tv
2.1 BGP Exchange – 6 States - Slow
ACTIVE STATE
1.IDLE If successful:
+ Send Open message to peer
+ Change state to OpenSent.
2.CONNECT 3.ACTIVE
If listen timeout or any error below encountered, move to Idle state
• TCP port 179 is not open.
• A random TCP port over 1023 is not open.
4.OPENSENT • Peer address configured incorrectly on either router.
• AS number configured incorrectly on either router
Repeated failures may result in a router cycling between the Idle and Active
states
5.OPENCONFIRM
6.ESTABLISHED
2.1 BGP Exchange – 6 States - Slow
www.itbase.tv
2.1 BGP Exchange – 6 States - Slow
OPENSENT STATE
5.OPENCONFIRM
6.ESTABLISHED
2.1 BGP Exchange – 6 States - Slow
www.itbase.tv
2.1 BGP Exchange – 6 States - Slow
OPENCONFIRM STATE
5.OPENCONFIRM
6.ESTABLISHED
2.1 BGP Exchange – 6 States - Slow
www.itbase.tv
2.1 BGP Exchange – 6 States - Slow ESTABLISHED
6.1
+6.2
Notify
Move
Update
If error
to
peer
Idle
within
messages
about
STATE
state
Update
thewith
error
messages
peer, to exchange information about each route being advertised or received BGP working continuously
ESTABLISHED STATE
6.1 Update messages with peer, to exchange information about each route
being advertised or received BGP working continuously
1.IDLE
6.2 If error within Update messages
+ Notify peer about the error
+ Move to Idle state
2.CONNECT 3.ACTIVE
4.OPENSENT
5.OPENCONFIRM
6.ESTABLISHED