BGP
BGP
Case Study 1, Exercise 1: Single upstream Part 6: BGP Protocol Basics Part 7: BGP Protocol - more detail Case Study 2, Exercise 2: Local peer Part 8: Routing Policy and Filtering Exercise 3: Filtering on AS-path Exercise 4: Filtering on prefix-list Part 9: More detail than you want Exercise 5: Interior BGP Part 10: BGP and Network Design
Static default route to provider Small ISP A Static or IGP routes inside
AS 1 AS 3 AS 5 AS 7
AS 2 AS 4 AS 6 AS 8
C E
G I K
D F
H J L
AS 9
AS 11
AS 10
AS 12
M AS 13
AS 14 N
Refer to BGP cheat sheet Connect cable to upstream provider router bgp for your AS number BGP network statement for your network BGP neighbor for upstream provider (IP address 196.200.220.xx, remote AS 100)
Instructors configure AS 100 to send you all routes to other classroom ASes, and a default route
You can send traffic through AS 100 to more distant destinations In other words, AS 100 provides transit service to you
ip route to see IPv4 routing table ipv6 route to see IPv6 routing table ip bgp to see IPv4 BGP table bgp ipv6 to see IPv6 BGP table
Look at the next hop and AS path Try some pings and traceroutes.
IPv4: ip route x.x.x.x m.m.m.m Null0 250 IPv6: ipv6 route x:x::/60 Null0 250 Smaller is less important Default for a static route is 1
BGP Part 6
BGP Protocol Basics
Terminology General Operation Interior/Exterior BGP
AS 100
B
AS 101
D E
AS 102
sends one copy of the RIB at the beginning, then sends changes as they happen keeps track of the AS path of routing information
Terminology
Neighbour
NLRI/Prefix
Router-ID
Route/Path
Terminology
Transit carrying network traffic across a network, usually for a fee Peering exchanging routing information and traffic
your customers and your peers customers network information only. not your peers peers; not your peers providers. BGP neighbour, whether or not transit is provided
Default where to send traffic when there is no explicit route in the routing table
BGP Basics
Each AS originates a set of NLRI (routing announcements) NLRI is exchanged between BGP peers Can have multiple paths for a given prefix BGP picks the best path and installs in the IP forwarding table Policies applied (through attributes) influences BGP path selection
Between routers in the same AS Often between routers that are far apart Should be a full mesh: every iBGP router talks to all other iBGP routers in the same AS
Between routers in different ASes Almost always between directly-connected routers (ethernet, serial line, etc.)
BGP Peers
A C
AS 100
100.100.8.0/24
AS 101
100.100.16.0/24
B BGP Peers exchange Update messages containing Network Layer Reachability Information (NLRI)
BGP Update Messages
D E
AS 102
100.100.32.0/24
AS 100
100.100.8.0/24
AS 101
100.100.16.0/24
B BGP speakers are called peers Peers in different ASs are called External Peers
eBGP TCP/IP Peer Connection
D E
AS 102
100.100.32.0/24
AS 100
100.100.8.0/24
AS 101
100.100.16.0/24
B BGP speakers are called peers Peers in the same AS are called Internal Peers
iBGP TCP/IP Peer Connection
D E
AS 102
100.100.32.0/24
BGP peering sessions are established using the BGP neighbor command
AS 100
A
.2
AS 101
C
.2
110.110.10.0/30
100.100.8.0/30
.1
.2
.1
100.100.16.0/30
.1
interface Serial 0 ip address 110.110.10.2 255.255.255.252 router bgp 100 network 100.100.8.0 mask 255.255.255.0 neighbor 110.110.10.1 remote-as 101
interface Serial 0 ip address 110.110.10.1 255.255.255.252 router bgp 101 network 100.100.16.0 mask 255.255.255.0 neighbor 110.110.10.2 remote-as 100
BGP peering sessions are established using the BGP neighbor command
AS 100
110.110.10.0/30
AS 101
iBGP TCP Connection .1
.2
100.100.8.0/30
.2
.1
.2
100.100.16.0/30
.1
interface Serial 1 ip address 100.100.16.1 255.255.255.252 router bgp 101 network 100.100.16.0 mask 255.255.255.0 neighbor 100.100.16.2 remote-as 101
router bgp 101 network 100.100.16.0 mask 255.255.255.0 neighbor 100.100.16.1 remote-as 101
Each iBGP speaker must peer with every other iBGP speaker in the AS
AS 100
A B
Loopback interfaces are normally used as the iBGP peer connection end-points
105.10.7.1
AS 100
105.10.7.2
105.10.7.3
AS 100
105.10.7.2
105.10.7.3 interface loopback 0 ip address 105.10.7.1 255.255.255.255 router bgp 100 network 105.10.7.0 mask 255.255.255.0 neighbor 105.10.7.2 remote-as 100 neighbor 105.10.7.2 update-source loopback0 neighbor 105.10.7.3 remote-as 100 neighbor 105.10.7.3 update-source loopback0
AS 100
105.10.7.2
105.10.7.3
interface loopback 0 ip address 105.10.7.2 255.255.255.255 router bgp 100 network 105.10.7.0 mask 255.255.255.0 neighbor 105.10.7.1 remote-as 100 neighbor 105.10.7.1 update-source loopback0 neighbor 105.10.7.3 remote-as 100 neighbor 105.10.7.3 update-source loopback0
AS 100
105.10.7.2
105.10.7.3
interface loopback 0 ip address 105.10.7.3 255.255.255.255 router bgp 100 network 105.10.7.0 mask 255.255.255.0 neighbor 105.10.7.1 remote-as 100 neighbor 105.10.7.1 update-source loopback0 neighbor 105.10.7.2 remote-as 100 neighbor 105.10.7.2 update-source loopback0
BGP Part 7
BGP Protocol A little more detail
AS path Next hop Local preference Multi-Exit Discriminator (MED) Community Origin Aggregator
AS-Path Attribute
Sequence of ASes a route has traversed Loop detection Apply policy
AS 300 AS 400
150.10.0.0/16 Network 180.10.0.0/16 170.10.0.0/16 150.10.0.0/16 Path 300 200 100 300 200 300 400
AS 200
170.10.0.0/16
AS 100
180.10.0.0/16
AS 500
AS 70000
170.10.0.0/16
AS 80000
180.10.0.0/16
AS 90000
140.10.0.0/16
.2
.1
E
BGP Update Messages
Path 100
.1
AS 100
160.10.0.0/16
Next hop to reach a network Usually a local network is the next hop in eBGP session
140.10.0.0/16
.2
.1
E
BGP Update Messages
.1
AS 100
160.10.0.0/16
Next hop to reach a network Usually a local network is the next hop in eBGP session Next Hop updated between eBGP Peers
140.10.0.0/16
.2
.1
E
BGP Update Messages
.1
AS 100
160.10.0.0/16
BGP looks into IGP to find out next hop information BGP is not permitted to use a BGP route as the next hop
Unlinks BGP from actual physical topology Allows IGP to make intelligent forwarding decision
Cisco IOS default is for external next-hop to be propagated unchanged to iBGP peers
This means that IGP has to carry external next-hops Forgetting means external network is invisible With many eBGP peers, it is extra load on IGP
ISP best practice is to change external next-hop to be that of the local router
neighbor x.x.x.x next-hop-self
Community Attribute
32-bit number Conventionally written as two 16-bit numbers separated by colon
First half is usually an AS number ISP determines the meaning (if any) of the second half Used by administratively-defined filters Not directly used by BGP protocol (except for a few well known communities)
AS 321
BGP Update Message
Connectivity lost
192.192.25.0/24
Network Next-Hop Path 150.10.0.0/16 192.168.10.2 321 200 192.192.25.0/24 192.168.10.2 321
D D D R S
router bgp 100 network 160.10.1.0 255.255.255.0 network 160.10.3.0 255.255.255.0 no auto-summary
Route Table
BGP network commands are normally used to populate the BGP RIB with routes from the Route Table
router bgp 100 network 160.10.0.0 255.255.0.0 aggregate-address 160.10.0.0 255.255.0.0 summary-only no auto-summary
D D D R S 10.1.2.0/24 160.10.1.0/24 160.10.3.0/24 153.22.0.0/16 192.1.1.0/24
Route Table
BGP aggregate-address commands may be used to install summary routes in the BGP RIB
router bgp 100 network 160.10.0.0 255.255.0.0 redistribute static route-map foo no auto-summary
D D D R S 10.1.2.0/24 160.10.1.0/24 160.10.3.0/24 153.22.0.0/16 192.1.1.0/24
Route Table
BGP redistribute commands can also be used to populate the BGP RIB with routes from the Route Table
OUT Process
Update
Update
Path 100
BGP in process
receives path information from peers results of BGP path selection placed in the BGP table best path flagged (denoted by >)
OUT Process
Update
Update
D D D R S B
Route Table
An Example
AS200 F
35.0.0.0/8
A
AS3561
B C
AS21
D AS101 E AS675
Your expensive line Their expensive line Same language/culture Traffic between your and their customers
Upstream ISP
Africa
No need to send traffic to other ISP down the street via New York!
Upstream ISP
Small ISP
Small ISP
Africa
AS 2 AS 4 AS 6 AS 8 AS 10 AS 12
I
K
J
L
Transit to provider
M AS 13
AS 14 N
direct route to your peer transit route through provider (AS 100) any more?
IPv4: show ip route IPv6: show ipv6 route IPv4: show ip bgp IPv6: show bgp ipv6
Look at the next hop and AS path Try some pings and traceroutes.
Are your peer ASes sending you transit routes as well as peering routes?
BGP Part 8
Routing Policy Filtering
Terminology: Policy
Accepting routes from some ISPs and not others Sending some routes to some ISPs and not others Preferring routes from some ISPs over others
Routing Policy
Why?
To steer traffic through preferred paths Inbound/Outbound prefix filtering To enforce Customer-ISP agreements
AS based route filtering filter list Prefix based route filtering prefix list BGP attribute modification route maps Complex route filtering route maps
How?
Listen to routes originated by AS 3561. Implicit deny everything else inbound. Dont announce routes originated by AS 35, but announce everything else (outbound).
ip as-path access-list 1 permit _3561$ ip as-path access-list 2 deny _35$ ip as-path access-list 2 permit .*
router bgp 100 neighbor 171.69.233.33 remote-as 33 neighbor 171.69.233.33 filter-list 1 in neighbor 171.69.233.33 filter-list 2 out
incremental configuration
High performance access list Inbound or Outbound Based upon network numbers (using CIDR address/mask format) First relevant allow or deny rule wins Implicit Deny All as last entry in list
This denies all prefix sizes /25, /26, /27, /28, /29, /30, /31 and /32 in the address block 192.0.0.0/8 It has the same effect as the previous example
This denies all prefix sizes /8, /9, /10, /11, /21, /22 and higher in the address block 193.0.0.0/8 ip prefix-list Example 0.0.0.0/0 le 32
Example Configuration
router bgp 200 network 215.7.0.0 neighbor 220.200.1.1 remote-as 210 neighbor 220.200.1.1 prefix-list PEER-IN in neighbor 220.200.1.1 prefix-list PEER-OUT out ! ip prefix-list PEER-IN deny 218.10.0.0/16 ip prefix-list PEER-IN permit 0.0.0.0/0 le 32 ip prefix-list PEER-OUT permit 215.7.0.0/16 ip prefix-list PEER-OUT deny 0.0.0.0/0 le 32
Accept everything except our network from our peer Send only our network to our peer
Prefix-lists in IPv6
Caveat: ipv6 prefix-lists cannot be used for ipv4 neighbours - and vice-versa Syntax is very similar, for example:
ip prefix-list ipv4-ebgp permit 0.0.0.0/0 le 32 ip prefix-list v4out permit 172.16.0.0/16 ! ipv6 prefix-list ipv6-ebgp permit ::/0 le 128 ipv6 prefix-list v6out permit 2001:db8::/32
A route-map is like a program for Cisco IOS Has line numbers, like programs Each line is a separate condition/action Concept is basically:
if match then do expression and exit else if match then do expression and exit else etc
Match Clauses
Set Clauses
BGP Exercise 3
Filtering peer routes using ASpath regular expression
AS 1
AS 2
B D F H
AS 7 AS 9 AS 11
AS 5
AS 3
AS 4 AS 6 AS 8 AS 10 AS 12
I
K
Transit to provider Not filtering here yet
J
L
Transit to provider Not filtering here yet
M AS 13
AS 14 N
ip as-path access-list 2 permit ^$ neighbor <address> filter-list 1 in neighbor <address> filter-list 2 out As-path filters are protocol independent, so the same filter can be applied to both IPv4 and IPv6 peers! neighbor <upstream-addr> filter-list 2 out
show ip route your forwarding table show ip bgp your BGP table show ip bgp neighbor xxx received-routes from your neighbour before filtering show ip bgp neighbor xxx routes from neighbour, after filtering show ip bgp neighbor advertised-routes to neighbour, after filtering
show ipv6 route your forwarding table show bgp ipv6 your BGP table show bgp ipv6 neighbor xxx received-routes from your neighbour before filtering show bgp ipv6 neighbor xxx routes from neighbour, after filtering show bgp ipv6 neighbor advertised-routes to neighbour, after filtering
BGP Exercise 4
Filtering peer routes using prefix-lists
B D F H
I
K
Transit to provider Not filtering here yet
J
L
Transit to provider Not filtering here yet
M AS 13
AS 14 N
We still trust the upstream provider too much. Should filter it too!
See ip prefix-list sanity-filter and ipv6 prefix-list v6sanity-filter in the cheat sheet
show ip route your forwarding table show ip bgp your BGP table show ip bgp neighbor xxx received-routes from your neighbour before filtering show ip bgp neighbor xxx routes from neighbour, after filtering show ip bgp neighbor advertised-routes to neighbour, after filtering
show ipv6 route your routing table show bgp ipv6 your BGP table show bgp ipv6 neighbor xxx received-routes from your neighbour before filtering show bgp ipv6 neighbor xxx routes from neighbour, after filtering show bgp ipv6 neighbor advertised-routes to neighbour, after filtering
BGP Part 9
More detail than you want
BGP Attributes Synchronization Path Selection
BGP Attributes
AS path Next hop Local preference Multi-Exit Discriminator (MED) Community Origin Aggregator
Local Preference
Not used by eBGP, mandatory for iBGP Default value of 100 on Cisco IOS Local to an AS Used to prefer one exit over another Path with highest local preference wins
Local Preference
AS 100
160.10.0.0/16
AS 200
D
500 800
AS 300
E
A
160.10.0.0/16 > 160.10.0.0/16 500 800
AS 400
C
Multi-Exit Discriminator
Non-transitive Represented as a numerical value
Used to convey relative preference of entry points to an AS Comparable if the paths are from the same AS Path with the lowest MED wins IGP metric can be conveyed as MED
C
192.68.1.0/24 2000
preferred
192.68.1.0/24 1000
B
192.68.1.0/24
AS 201
Origin
Historical attribute
IGP from BGP network statement
Three values:
EGP redistributed from EGP (not used today) Incomplete redistributed from another routing protocol
Weight
Not really an attribute Used when there is more than one route to same destination Local to the router on which it is assigned, and not propagated in routing updates Default is 32768 for paths that the router originates and zero for other paths Routes with a higher weight are preferred when there are multiple routes to the same destination
Communities
Transitive, Non-mandatory Represented as a numeric value
Used to group destinations Each destination could be member of multiple communities Flexibility to scope a set of prefixes within or across AS for applying policy
Communities
Community
200:90 200:120
Community:200:90
Community:200:120
B
192.168.1.0/24
Customer AS 201
Well-Known Communities
no-export
no-advertise
no-export-subconfed
no-peer
No-Export Community
105.7.0.0/16 105.7.X.X No-Export
105.7.X.X
A B C E
D AS 200 F G
105.7.0.0/16
AS 100
Subprefixes marked with no-export community Router G in AS200 does not announce prefixes with noexport community set
Administrative Distance
Local routes originated on router: 200 iBGP routes: 200 eBGP routes: 20
Does not influence the BGP path selection algorithm but influences whether BGP learned routes enter the forwarding table
Synchronization
1880
690
A
D
C OSPF
35/8
209
C is not running BGP A wont advertised 35/8 to D until the IGP is in sync Turn synchronization off!
router bgp 1880 no synchronization
Synchronization
In Cisco IOS, BGP does not advertise a route before all routers in the AS have learned it via an IGP
AS doesnt pass traffic from one AS to another, or All transit routers in AS run BGP, or iBGP is used across backbone
so, always use no synchronization
Only if synchronization is enabled Prefix must be in forwarding table Next-hop must be in forwarding table
Locally sourced
Lowest origin
Lowest MED
Closest next-hop
AS 200
D
AS 300
Increase AS path attribute length by at least 1
AS 400
BGP Exercise 5
Internal BGP (iBGP)
Provider AS 200 AS 2 AS 4 AS 6 AS 8 AS 10 AS 12 AS 14
B D F H J L N
One of your routers talks eBGP to AS 100, and one talks to AS 200.
Filter! Send only your routes Accept all except bogus routes (sanity-filter)
BGP Part 10
BGP and Network Design
Stub AS
Enterprise network, or small ISP Typically no need for BGP Point default towards the ISP ISP advertises the stub network to Internet Policy confined within ISP policy
Stub AS
AS 101
Provider
Customer
AS 100
Multihomed AS
Enterprise network or small ISP Only border routers speak BGP iBGP only between border routers Rest of network either has:
exterior routes redistributed in a controlled fashion into IGP or use defaults (much preferred!)
Multi-homed AS
AS 100
provider
AS 300
A
B D
provider
AS 200
customer
IGP used to track topology inside your network Full iBGP mesh required
Every router in ISP backbone should talk iBGP to every other router This has scaling problems, and solutions (e.g. route reflectors)
AS 100
A B C
AS 200
provider
E
AS 300
AS 400
Router A:
interface loopback 0 ip address 20.200.0.1 255.255.255.255 ! router bgp 100 neighbor 10.200.0.2 remote-as 200 neighbor 10.200.0.2 update-source loopback0 neighbor 10.200.0.2 ebgp-multihop 2 ! ip route 10.200.0.2 255.255.255.255 <DMZ-link1> ip route 10.200.0.2 255.255.255.255 <DMZ-link2>
Loopback 0 10.200.0.2
AS100
Loopback 0 20.200.0.1
AS200
Router A:
router bgp 100 neighbor 10.200.0.1 remote-as 200 neighbor 10.300.0.1 remote-as 200 maximum-paths 2
100
200
Redundancy Multi-homing
Reliable connection to Internet 3 common cases of multi-homing
default from all providers customer + default from all providers full routes from all providers comes from upstream providers, or allocated directly from registries
Address Space
Provider AS 200
D
Receive default from upstreams
Provider AS 300
E A B
Receive default from upstreams
AS 400
C
AS 100
Provider AS 200
D E
Provider
AS 300
AS 400
C
More memory/CPU Fine grained routing control Usually transit ASes take full routes
AS 200
D A B E
AS 300
AS 400
C
Clients routes go into iBGP Hosting and service LANs go into iBGP Dial/Broadband/Wireless pools go into iBGP The fewer prefixes in the IGP the better
Runs between loopbacks Next-hop-self Send-community Passwords All non-infrastructure prefixes go here
Static routes
You control directly No route flaps Strongly discouraged You must filter your customers info Route flaps Private AS for those who multihome on to your backbone Public AS for the rest
Cheap Fast
Summary
BGP Protocol Basics Routing Policy and Filtering BGP Best Path Computation Typical BGP topologies Routing Policy BGP Network Design Redundancy/Load sharing Some best practices