Wednesday, 8 May 2013

BGP LOCAL PREFERENCE



BGP Local Preference has a default of 100 and higher value is preferred. A BGP router would not display its configured local preference in the sh ip bgp command.
We can say that local preference should be applied at the edge routers  i.e. I would apply the local preference as it is coming into my network so I can tell all routers connected to me that I have this local preference.
Default configs are
R1.....................
int s0/1
ip add 20.20.20.1 255.255.255.0
no shut
int  s0/0
ip add 10.10.10.1 255.255.255.0
no shut
int lo 1         
ip add 150.150.150.1 255.255.255.0
no shut
int lo 2
ip add 150.150.151.1 255.255.255.0
no shut
exit
router eigrp 1
network 20.20.20.0 0.0.0.255
network 10.10.10.0 0.0.0.255
no auto-summary
exit
router bgp 100
nei 10.10.10.2 remote-as 222
nei 20.20.20.2 remote-as 100
nei 20.20.20.2 next-hop-selfib
nei 30.30.30.1 remote-as 100
nei 30.30.30.1 next-hop-self
bgp router-id 150.150.150.1
no synchronization
network 150.150.150.0 mask 255.255.255.0
network 150.150.151.0 mask 255.255.255.0


R2..................
int s0/0
ip add 30.30.30.2 255.255.255.0
no shut
int  s0/1
ip add 20.20.20.2 255.255.255.0
no shut
int s0/2
ip add 50.50.50.2 255.255.255.0
no shut
int lo 1
ip add 77.77.77.1 255.255.255.0
no shut
exit
router eigrp 1
network 20.20.20.0 0.0.0.255
network 30.30.30.0 0.0.0.255
network 50.50.50.0 0.0.0.255
no auto-summary
exit
router bgp 100
nei 30.30.30.1 remote-as 100
nei 30.30.30.1 next-hop-self
nei 20.20.20.1 remote-as 100
nei 20.20.20.1 next-hop-self
nei 50.50.50.1 remote-as 111
bgp router-id 77.77.77.1
no synchronization
network 77.77.77.0 mask 255.255.255.0


R3..........................
int s0/0
ip add 40.40.40.1 255.255.255.0
no shut
int s0/1
ip add 30.30.30.1 255.255.255.0
no shut
int lo 1
ip add 99.99.99.1 255.255.255.0
no shut
exit
router eigrp 1
network 30.30.30.0 0.0.0.255
network 40.40.40.0 0.0.0.255
no auto-summary
router bgp 100
nei 40.40.40.2 remote-as 222
nei 30.30.30.2 remote-as 100
nei 30.30.30.2 next-hop-self
nei 20.20.20.1 remote-as 100
nei 20.20.20.1 next-hop-self
bgp router-id 99.99.99.1
no synchronization
network 99.99.99.0 mask 255.255.255.0

ISP1..................................
int s0/0
ip add 50.50.50.1 255.255.255.0
no shut
int lo 1
ip add 200.200.200.1 255.255.255.0
no shut
exit
router bgp 111
nei 50.50.50.2 remote-as 100
bgp router-id 200.200.200.1
no synchronization
network 200.200.200.0 mask 255.255.255.0

ISP2..................
int s0/1
ip add 40.40.40.2 255.255.255.0
no shut
int  s0/0
ip add 10.10.10.2 255.255.255.0
no shut
int lo 1
ip add 100.100.100.1 255.255.255.0
no shut
int lo 2
ip add 100.100.101.1 255.255.255.0
no shut
int lo 3
ip add 100.100.102.1 255.255.255.0
no shut
int lo 4
ip add 100.100.103.1 255.255.255.0
no shut
exit
router bgp 222
nei 10.10.10.1 remote-as 100
nei 40.40.40.1 remote-as 100
bgp router-id 100.100.100.1
no synchronization
network 100.100.100.0 mask 255.255.255.0
network 100.100.101.0 mask 255.255.255.0
network 100.100.102.0 mask 255.255.255.0
network 100.100.103.0 mask 255.255.255.0


1) Ensure r2 uses r1 as to get to 100.100.100.0

Currently checking out the bgp table on R2, we have

  Network                            Next Hop            Metric                   LocPrf                   Weight                                 Path
*>i100.100.100.0/24        30.30.30.1               0                          100                         0                              222 i
* i                                           20.20.20.1               0                          100                         0                              222 i
*>i100.100.101.0/24        30.30.30.1               0                          100                         0                              222 i
* i                                           20.20.20.1               0                          100                         0                              222 i
We can see that R2 prefers to go through R3 (30.30.30.1) bcos of its lower router-id
To use local preference, we apply the config at the edge routers. We can decide to increase the local preference on R1 or decrease the local preference at R3

R1(conf)#            router bgp 100
                                bgp default local-preference 200
                                do clear ip bgp * in
                                do clear ip bgp * out
                                exit

R2#                        sh ip bgp

  Network                            Next Hop            Metric                   LocPrf                   Weight                                 Path
*>i100.100.100.0/24        20.20.20.1               0                          200                         0                              222 i
*>i100.100.101.0/24        20.20.20.1               0                          200                         0                              222 i

We observe that R2 sees only one route to the 100.100.0.0 network. This is so because R3 selected  path R1 to reach 100.100.0.0 ntwk

R3#        sh ip bgp

  Network                            Next Hop            Metric                   LocPrf                   Weight                                 Path
*>i100.100.100.0/24        20.20.20.1               0                          200                         0                              222 i
*                                             40.40.40.2               0                                                          0                              222 i
*>i100.100.101.0/24        20.20.20.1               0                          200                         0                              222 i
*                                             40.40.40.2               0                                                          0                              222 i
R3 also prefers to take R1 to get to 100.100.0.0 network. This might not be ideal for our network design and we might need to tweak this.
Guess what!! Assigning weight would fix this

BGP WEIGHT




Weight is a cisco proprietary bgp metric. Default metric is 0 for external routes and 32768 for locally generated routes. Higher value is preferred. Default configs are
R1.....................
int s0/1
ip add 20.20.20.1 255.255.255.0
no shut
int  s0/0
ip add 10.10.10.1 255.255.255.0
no shut
int lo 1
ip add 150.150.150.1 255.255.255.0
no shut
int lo 2
ip add 150.150.151.1 255.255.255.0
no shut
exit
router eigrp 1
network 20.20.20.0 0.0.0.255
network 10.10.10.0 0.0.0.255
no auto-summary
exit
router bgp 100
nei 10.10.10.2 remote-as 222
nei 20.20.20.2 remote-as 100
nei 20.20.20.2 next-hop-self
nei 30.30.30.1 remote-as 100
nei 30.30.30.1 next-hop-self
bgp router-id 150.150.150.1
no synchronization
network 150.150.150.0 mask 255.255.255.0
network 150.150.151.0 mask 255.255.255.0


R2..................
int s0/0
ip add 30.30.30.2 255.255.255.0
no shut
int  s0/1
ip add 20.20.20.2 255.255.255.0
no shut
int s0/2
ip add 50.50.50.2 255.255.255.0
no shut
int lo 1
ip add 77.77.77.1 255.255.255.0
no shut
exit
router eigrp 1
network 20.20.20.0 0.0.0.255
network 30.30.30.0 0.0.0.255
network 50.50.50.0 0.0.0.255
no auto-summary
exit
router bgp 100
nei 30.30.30.1 remote-as 100
nei 30.30.30.1 next-hop-self
nei 20.20.20.1 remote-as 100
nei 20.20.20.1 next-hop-self
nei 50.50.50.1 remote-as 111
bgp router-id 77.77.77.1
no synchronization
network 77.77.77.0 mask 255.255.255.0

R3..........................
int s0/0
ip add 40.40.40.1 255.255.255.0
no shut
int s0/1
ip add 30.30.30.1 255.255.255.0
no shut
int lo 1
ip add 99.99.99.1 255.255.255.0
no shut
exit
router eigrp 1
network 30.30.30.0 0.0.0.255
network 40.40.40.0 0.0.0.255
no auto-summary
router bgp 100
nei 40.40.40.2 remote-as 222
nei 30.30.30.2 remote-as 100
nei 30.30.30.2 next-hop-self
nei 20.20.20.1 remote-as 100
nei 20.20.20.1 next-hop-self
bgp router-id 99.99.99.1
no synchronization
network 99.99.99.0 mask 255.255.255.0


ISP1..................................
int s0/0
ip add 50.50.50.1 255.255.255.0
no shut
int lo 1
ip add 200.200.200.1 255.255.255.0
no shut
exit
router bgp 111
nei 50.50.50.2 remote-as 100
bgp router-id 200.200.200.1
no synchronization
network 200.200.200.0 mask 255.255.255.0


ISP2..................
int s0/1
ip add 40.40.40.2 255.255.255.0
no shut
int  s0/0
ip add 10.10.10.2 255.255.255.0
no shut
int lo 1
ip add 100.100.100.1 255.255.255.0
no shut
int lo 2
ip add 100.100.101.1 255.255.255.0
no shut
int lo 3
ip add 100.100.102.1 255.255.255.0
no shut
int lo 4
ip add 100.100.103.1 255.255.255.0
no shut
exit
router bgp 222
nei 10.10.10.1 remote-as 100
nei 40.40.40.1 remote-as 100
bgp router-id 100.100.100.1
no synchronization
network 100.100.100.0 mask 255.255.255.0
network 100.100.101.0 mask 255.255.255.0
network 100.100.102.0 mask 255.255.255.0
network 100.100.103.0 mask 255.255.255.0


1) Ensure ISP2 prefers R3 to get out of its AS
Presently, ISP2’s routing table is
   Network                        Next Hop            Metric        LocPrf      Weight         Path
*  77.77.77.0/24             40.40.40.1                                                     0                      100 i
*>                                      10.10.10.1                                                     0                      100 i
*  99.99.99.0/24             10.10.10.1                                                     0                      100 i
*>                                       40.40.40.1           0                                       0                      100 i
*> 100.100.100.0/24      0.0.0.0                  0                                  32768            i
*> 100.100.101.0/24      0.0.0.0                  0                                         32768                      i
*> 100.100.102.0/24      0.0.0.0                  0                                        32768                       i
*> 100.100.103.0/24      0.0.0.0                  0                                         32768                    i
*  150.150.150.0/24        40.40.40.1                                                     0                      100 i
*>                                       10.10.10.1           0                                         0                 100 i
*  200.200.200.0              10.10.10.1                                                      0                     100 111 i
*>                                       40.40.40.1                                                       0                     100 111 i

We see that default weight is 0 for external routes and 32678 for local routes
Recall that there is no bgp default weight command, so we wld need a little tweaking
Isp2(conf)#         ip as-path access-list 1 permit  .*
                                route-map A permit 10
                                match as-path 1
                                set weight 20
                                exit
                                router bgp 222
                                nei 40.40.40.1 route-map A in
                                do clear ip bgp * in
                                do clear ip bgp * out
                                do sh ip bgp
   Network                        Next Hop            Metric        LocPrf      Weight         Path

*> 150.150.150.0/24        40.40.40.1                                                            20           100 i
*                                             10.10.10.1               0                                          0              100 i
*  200.200.200.0                10.10.10.1                                                             0             100 111 i
*>                                           40.40.40.1                                                            20           100 111 i
                               

2)  remov d cfg and ensure isp2 prefers r3 to reach 99.99.99.1 and r1 to reach 150.150.150.1

Assuming the prefix-lists, route-maps have been removed
ISP2(conf)#        ip prefix-list o seq 5 permit 150.150.150.0/24
ip prefix-list p seq 5 permit 99.99.99.0/24
route-map o permit 10
                                match ip address prefix-list o
 set weight 30
route-map o permit 20
exit
route-map p permit 10
 match ip address prefix-list p
 set weight 20
route-map p permit 20
exit
router bgp 222
neighbor 10.10.10.1 route-map o in
neighbor 40.40.40.1 route-map p in
do clear ip bgp * in
do clear ip bgp * out
do sh ip bgp

                                Network                        Next Hop            Metric        LocPrf      Weight         Path

*  150.150.150.0/24         40.40.40.1                                                             0             100 i
*>                                           10.10.10.1               0                                          30           100 i
*  99.99.99.0/24                10.10.10.1                                                             0             100 i
*>                                           40.40.40.1               0                                          20           100 i       

BGP MED



This is used to influence return traffic from our neighbouring AS. Lower value is better. Default is 0

RULES OF MED

1) MED is not propagated outside the receiving AS
2) MED attribute would never be used if the ASes being compared are from different AS except we configure bgp always compare med
3) BGP best-path med missing –med-worst command is used to represent a missing med
4) BGP best path med confederation allows us to use MED within a confederation
5) BGP determistic med command would compare med before it compares origin code in route-selection
Default-configs are

R1.....................
int s0/1
ip add 20.20.20.1 255.255.255.0
no shut
int  s0/0
ip add 10.10.10.1 255.255.255.0
no shut
int lo 1
ip add 150.150.150.1 255.255.255.0
no shut
int lo 2
ip add 150.150.151.1 255.255.255.0
no shut
exit
router eigrp 1
network 20.20.20.0 0.0.0.255
network 10.10.10.0 0.0.0.255
no auto-summary
exit
router bgp 100
nei 10.10.10.2 remote-as 222
nei 20.20.20.2 remote-as 100
nei 20.20.20.2 next-hop-selfib
nei 30.30.30.1 remote-as 100
nei 30.30.30.1 next-hop-self
bgp router-id 150.150.150.1
no synchronization
network 150.150.150.0 mask 255.255.255.0
network 150.150.151.0 mask 255.255.255.0



R2..................
int s0/0
ip add 30.30.30.2 255.255.255.0
no shut
int  s0/1
ip add 20.20.20.2 255.255.255.0
no shut
int s0/2
ip add 50.50.50.2 255.255.255.0
no shut
int lo 1
ip add 77.77.77.1 255.255.255.0
no shut
exit
router eigrp 1
network 20.20.20.0 0.0.0.255
network 30.30.30.0 0.0.0.255
network 50.50.50.0 0.0.0.255
no auto-summary
exit
router bgp 100
nei 30.30.30.1 remote-as 100
nei 30.30.30.1 next-hop-self
nei 20.20.20.1 remote-as 100
nei 20.20.20.1 next-hop-self
nei 50.50.50.1 remote-as 111
bgp router-id 77.77.77.1
no synchronization
network 77.77.77.0 mask 255.255.255.0

R3..........................
int s0/0
ip add 40.40.40.1 255.255.255.0
no shut
int s0/1
ip add 30.30.30.1 255.255.255.0
no shut
int lo 1
ip add 99.99.99.1 255.255.255.0
no shut
exit
router eigrp 1
network 30.30.30.0 0.0.0.255
network 40.40.40.0 0.0.0.255
no auto-summary
router bgp 100
nei 40.40.40.2 remote-as 222
nei 30.30.30.2 remote-as 100
nei 30.30.30.2 next-hop-self
nei 20.20.20.1 remote-as 100
nei 20.20.20.1 next-hop-self
bgp router-id 99.99.99.1
no synchronization
network 99.99.99.0 mask 255.255.255.0


ISP1..................................
int s0/0
ip add 50.50.50.1 255.255.255.0
no shut
int lo 1
ip add 200.200.200.1 255.255.255.0
no shut
exit
router bgp 111
nei 50.50.50.2 remote-as 100
bgp router-id 200.200.200.1
no synchronization
network 200.200.200.0 mask 255.255.255.0


ISP2..................
int s0/1
ip add 40.40.40.2 255.255.255.0
no shut
int  s0/0
ip add 10.10.10.2 255.255.255.0
no shut
int lo 1
ip add 100.100.100.1 255.255.255.0
no shut
int lo 2
ip add 100.100.101.1 255.255.255.0
no shut
int lo 3
ip add 100.100.102.1 255.255.255.0
no shut
int lo 4
ip add 100.100.103.1 255.255.255.0
no shut
exit
router bgp 222
nei 10.10.10.1 remote-as 100
nei 40.40.40.1 remote-as 100
bgp router-id 100.100.100.1
no synchronization
network 100.100.100.0 mask 255.255.255.0
network 100.100.101.0 mask 255.255.255.0
network 100.100.102.0 mask 255.255.255.0
network 100.100.103.0 mask 255.255.255.0


Task 1) Ensure that ISP2 receives the traffic towards 100.100.101.0/24 from R1, and the traffic towards 100.100.100.0/24 from R3. Use MED to accomplish the goal.
On R1, bgp table is

  Network                            Next Hop            Metric                   LocPrf                   Weight                 Path
* i100.100.100.0/24         30.30.30.1               0                          100                         0                              222 i
*>                                           10.10.10.2               0                                                          0                              222 i
* i100.100.101.0/24         30.30.30.1               0                          100                         0                              222 i
*>                                           10.10.10.2               0                                                          0                              222 i
* i100.100.102.0/24         30.30.30.1               0                          100                         0                              222 i
*>                                           10.10.10.2               0                                                          0                              222 i
* i100.100.103.0/24         30.30.30.1               0                          100                         0                              222 i
*>                                           10.10.10.2               0                                                          0                              222 i

On R3, bgp table is
  Network                            Next Hop            Metric                   LocPrf                   Weight                                 Path
* i100.100.100.0/24         20.20.20.1               0                          100                         0                              222 i
*>                                            40.40.40.2               0                                                         0                              222 i
* i100.100.101.0/24         20.20.20.1               0                          100                         0                              222 i
*>                                           40.40.40.2               0                                                          0                              222 i
* i100.100.102.0/24         20.20.20.1               0                          100                         0                              222 i
*>                                           40.40.40.2               0                                                          0                              222 i
* i100.100.103.0/24         20.20.20.1               0                          100                         0                              222 i
*>                                           40.40.40.2               0                                                          0                              222 i

Now, to influence AS 100 to take 10.10.10.2 for 100.100.100.0 and to 40.40.40.2 for  100.100.101.0
ISP2(conf)           ip prefix-list o seq 5 permit 100.100.101.0/24
ip prefix-list p seq 5 permit 100.100.100.0/24
                                route-map o permit 10
                                match ip address prefix-list o
                                set metric 300
                                exit
route-map o permit 20
exit
route-map p permit 10
 match ip address prefix-list p
 set metric 200
exit
route-map p permit 20
exit
router bgp 222
neighbor 10.10.10.1 route-map o out
neighbor 40.40.40.1 route-map p out

Now lets check R1 bgp table
  Network                            Next Hop            Metric                  LocPrf                   Weight                                 Path
*> 100.100.100.0/24        10.10.10.2               0                                                          0                              222 i
*>i100.100.101.0/24        30.30.30.1               0                          100                         0                              222 i
*                                             10.10.10.2             300                                                        0                              222 i

and r3’s bgp table

  Network                            Next Hop            Metric                  LocPrf                   Weight                                 Path
*>i100.100.100.0/24        20.20.20.1               0                          100                         0                              222 i
*                                             40.40.40.2             200                                                        0                              222 i
*> 100.100.101.0/24        40.40.40.2               0                                                          0                              222 i
Hence we see that AS 100 chooses R1 to get to 100.100.100.0 ntwk and R2 to get to 100.100.101.0 ntwk

Task 2) cfg R1 such that routes without MED configured are set to zero

R1(conf)#            router bgp 100
                                bgp  bestpath med missing-as-worst