Showing posts with label BGP protocol. Show all posts
Showing posts with label BGP protocol. Show all posts

Sunday, June 7, 2015

BGP route dampening


BGP route dampening là feature rất hay trong việc tránh quảng bá flapping route. BGP route dampening feature có 2 mục đích chính:
1.    Kỹ thuật giảm CPU router xử lý flapping route
2.    Tăng độ ổn định cho mạng
3.    prevent sustained route oscillations
Cấu hình như sau:

BGP Route Dampening Configuration
router bgp 100
 bgp dampening half-life reuse-limit suppress-limit maximum-suppress-limit
!

·         History state: Sau mỗi lần flap, route sẽ được gán giá trị vi phạm và trạng thái vi phạm vào trong History. Mặc định mỗi lần vi phạm route sẽ được tăng thêm giá trị 1000.
·         Suppress limit: Nếu vi phạm vượt quá suppress limit, route sẽ “Dampend”. Trạng thái route chuyển từ History-> Damp. Giá trị suppress limit mặc định là 20000. Khi route ở trạng thái damp, router sẽ không tính toán best_path và không adver route sang neigbhor
·         Half life: Giá trị vi phạm của route sẽ được giảm dựa trên chu kì Half_life. Giá trị half_life mặc định là 15p. Giá trị vi phạm sẽ được giảm mỗi lần sau 5s
·         Reuse limit: Khi vi phạm dưới giá trị reuse limit, route sẽ unsuppressed. Mặc định reuse limit là 750. Khi vi phạm nằm dưới ½ reuse limit thì history sẽ được xóa 
·         Maximum suppress limit: Khoảng thời gian route bị suppressed khi vi phạm vượt quá suppress limit. Mặc định là 60p ( hoặc bằng 4 lần thời gian half_life)

The BGP dampening chỉ ảnh hưởng đến BGP route.


R2 và R3 cấu hình dampening với các giá trị mặc định. Suppress limit = 2000, half-life period = 15 minutes, reuse-limit = 750 and maximum suppress-limit = 60 minutes.

R3 adver mạng 1.1.1.1/32 sang R2.

Khi 1.1.1.1/32 route flap lần thứ nhất, nó sẽ được chuyển sang trạng thái history. Và giá trị vi phạm sẽ gán thêm vào route là 1000. debug ip bgp dampening để thấy rõ hơn.

First flap
02:01:19.687: EvD: charge penalty 1000, new accum. penalty 1000, flap count 1
02:01:19.687: EvD: unsuppress item left in reuse timer array with penalty 1000
02:01:19.687: BGP(0): charge penalty for 1.1.1.1/32 path 300 with halflife-time 15 reuse/suppress 750/2000
02:01:19.687: BGP(0): flapped 1 times since 00:00:00. New penalty is 1000

R2# show ip bgp dampening flap-statistics
BGP table version is 9, local router ID is 10.2.2.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          From            Flaps Duration Reuse    Path
 h 1.1.1.1/32       10.2.2.2        1     00:34:34          300

The penalty decreases with time if no further flaps are noticed.

Reducing penalty
02:01:49.567: EvD: accum. penalty 980, not suppressed

02:02:15.931: EvD: accum. penalty decayed to 961 after 27 second(s)

Khi route flap lần 2, giá trị vi phạm sẽ được thêm 1000. Tuy nhiên giá trị vi pham chưa vượt quá suppress limit (2000) nên route chưa chuyển sang trạng thái dampended

Second flap
02:02:45.599: EvD: accum. penalty decayed to 942 after 29 second(s)
02:02:45.599: EvD: charge penalty 1000, new accum. penalty 1942, flap count 2
02:02:45.599: EvD: unsuppress item left in reuse timer array with penalty 1942
02:02:45.599: BGP(0): charge penalty for 1.1.1.1/32 path 300 with halflife-time 15 reuse/suppress 750/2000
02:02:45.603: BGP(0): flapped 2 times since 00:01:25. New penalty is 1942

show ip bgp dampening flap-statistics command hiển thị BGP dampening flap-statistics của prefixes.

show ip bgp dampening flap-statistics
R2# show ip bgp dampening flap-statistics
BGP table version is 6, local router ID is 10.2.2.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          From            Flaps Duration Reuse    Path
*> 1.1.1.1/32       10.2.2.2        2     00:02:17          300


Khi route flap lần thứ 3, giá trị vi phạm tiếp tục được tăng lên 1000 nữa. đúng lúc này giá trị vi phạm vượt quá giá trị suppress limit 2000 và route sẽ chuyển sang trạng thái dampned/ suppressed và không được adver 
Third flap
02:04:31.463: BGP(0): suppress 1.1.1.1/32 path 300 for 00:28:10 (penalty 2766)
02:04:31.463: halflife-time 15, reuse/suppress 750/2000
02:04:31.463: EvD: accum. penalty 2766, now suppressed with a reuse intervals of 169

 show ip bgp dampening dampened-paths hiển thị route đang bị dampened.  'd' thể hiện route bị dampned



Thursday, May 28, 2015

BGP filter with Regulare expression



  1. GIỚI THIỆU REGULARE EXPRESSION
  • Regular Expression  là h thng chun các biu din các kí t “string” , là một công cụ rất mạnh trong BGP khi sử dụng filter route theo các AS.
  • Cấu hình topology như hình vẽ
    • R1 thiết lập eBGP với R2, R2 eBGP R3, R3 eBGP R4
    • R1 adver 8.8.8.0/24 vào BGP
  • Kiểm tra bảng BGP trên R4:
R4#show ip bgp
BGP table version is 2, local router ID is 4.4.4.4
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 8.8.8.0/24       10.1.34.3                              0 300 200 100 i

  • Các AS quảng bá mạng 8.8.8.0/24 đến AS 400 được viết theo thứ tự từ phải qua trái
    • AS_PATH:         300 200 100 I
  • Chuyển đổi sang Regular Expression ta thêm vào các ký tự đặc biệt vào AS_PATH
    • AS_PATH:        ^300_200_100$
      • ^ bắt đầu AS_PATH
      • $ kết thúc AS_PATH
      • _ giữa các AS
    • Regular expression :
      • ^300_  peer AS ( thằng AS hàng xóm )
      • _200_  transit AS ( AS mà route đi qua)
      • _100$   origin AS ( route được sinh ra từ AS)
      • ^300_200_100$ transit path
      • ^*     Route Local AS
      • .*       Match tất cả
  1. FILTER BẰNG REGULAR EXPRESSION
    • Filter dựa trên một số reguler expression căn bản trên
    • Command:
ip as-path access-list x deny/permit {regular expression}
!
router bgp {AS}
neighbor a.b.c.d filter-list x in/out

  1. TEST FEATURE:
    • Trên R2 tạo mạng  2.2.2.0/24 và adver vào BGP
R4#show ip bgp
BGP table version is 5, local router ID is 4.4.4.4
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 2.2.2.0/24       10.1.34.3                              0 300 200 i
*> 8.8.8.0/24       10.1.34.3                              0 300 200 100 i

  • Tiến hành filter mạng 8.8.8.0/24 bằng 3 cách sử dụng regular expression như ở trên
  • Cách 1: filter dựa vào peer AS 300:
ip as-path access-list 1 deny ^300_ 
ip as-path access-list 1 permit .*
!
router bgp 400
 neighbor 10.1.34.3 filter-list 1 in

 BGP(0): 10.1.34.3 rcvd UPDATE w/ attr: nexthop 10.1.34.3, origin i, path 300 200 100
 BGP(0): 10.1.34.3 rcvd 8.8.8.0/24 -- DENIED due to: filter-list;
 BGP(0): no valid path for 8.8.8.0/24
 BGP(0): 10.1.34.3 rcvd UPDATE w/ attr: nexthop 10.1.34.3, origin i, path 300 200
 BGP(0): 10.1.34.3 rcvd 2.2.2.0/24 -- DENIED due to: filter-list;

 Nhận xét: R4 cùng học mạng 2.2.2.0/24 và mạng 8.8.8.0/24 qua peer AS 300. nên khi filter dựa vào peer AS thì cả 2 mạng trên đều bị filter

*Cách 2: filter dựa vào transit AS 200 :
ip as-path access-list 1 deny _200_
ip as-path access-list 1 permit .*
!
router bgp 400
 neighbor 10.1.34.3 filter-list 1 in

 BGP(0): 10.1.34.3 rcvd UPDATE w/ attr: nexthop 10.1.34.3, origin i, path 300 200 100
 BGP(0): 10.1.34.3 rcvd 8.8.8.0/24 -- DENIED due to: filter-list;
 BGP(0): no valid path for 8.8.8.0/24
 BGP(0): 10.1.34.3 rcvd UPDATE w/ attr: nexthop 10.1.34.3, origin i, path 300 200
 BGP(0): 10.1.34.3 rcvd 2.2.2.0/24 -- DENIED due to: filter-list;
 BGP(0): no valid path for 2.2.2.0/24
 BGP(0): nettable_walker 2.2.2.0/24 no best path
 BGP(0): nettable_walker 8.8.8.0/24 no best path

Nhận xét: giống trường hợp trên cả 2 mạng đều bị filter. Mạng 2.2.2.0/24 có nguồn gốc là AS 200 nó cũng được xem như là transit AS = 200 nên bị filter

* Cách 3: filter dựa vào origin AS cac route có nguồn gốc AS 100:
ip as-path access-list 1 deny _100$
ip as-path access-list 1 permit .*
!
router bgp 400
 neighbor 10.1.34.3 filter-list 1 in

 10.1.34.3 rcvd UPDATE w/ attr: nexthop 10.1.34.3, origin i, path 300 200 100
 BGP(0): 10.1.34.3 rcvd 8.8.8.0/24 -- DENIED due to: filter-list;
 BGP(0): no valid path for 8.8.8.0/24
 BGP(0): 10.1.34.3 rcvd UPDATE w/ attr: nexthop 10.1.34.3, origin i, path 300 200
 BGP(0): 10.1.34.3 rcvd 2.2.2.0/24...duplicate ignored
 BGP(0): nettable_walker 8.8.8.0/24 no best path.

R4(config)#do show ip bgp
BGP table version is 16, local router ID is 4.4.4.4
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 2.2.2.0/24       10.1.34.3                              0 300 200 i

Nhận xét: route 8.8.8.0/24 có nguồn gốc từ AS 100 đã bị filter . Trên BGP table R4 còn route 2.2.2.0/24


Kết luận: Regular là một công cụ rất mạnh, trên đây chỉ mới là những trường hợp đơn giản. Bằng cách kết hợp filter AS Path bằng regular chúng ta có thể filter tất cả các route từ những AS_PATH  bằng cách cấu hình đơn giản ở trên.

Saturday, April 18, 2015

step 13 - lowest neighbor address ( 13 step selection route BGP)



R1#show run | se router bgp
router bgp 1
 no synchronization
 bgp log-neighbor-changes
 network 8.8.8.0 mask 255.255.255.0
 neighbor 10.1.12.2 remote-as 1
 neighbor 10.1.21.2 remote-as 1
 no auto-summary
R2#show run | se router bgp
router bgp 1
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.1.12.1 remote-as 1
 neighbor 10.1.21.1 remote-as 1
 no auto-summary

R2#show ip bgp
BGP table version is 2, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
* i8.8.8.0/24       10.1.21.1                0    100      0 i
*>i                         10.1.12.1                0    100      0 I
Nhận xét: R2 học mạng 8.8.8.0/24 qua next-hop 10.1.12.1.
Chúng ta đi kiểm tra từng bước sau:
  1. Weight: bằng nhau 0
  1. Local prefer: bằng nhau 100
  1. Perfer the path was locally..: bằng nhau
  1. AS-path: bằng nhau 1
  1. Origin type : bằng nhau
  1. Med: bằng nhau
  1. Prefer eBGP over iBGP: cùng iBGP
  1. Prefer with lowes IGP metric to BGP next-hop : bằng nhau
  1. Không xét ở đây.
  1. The path are external: cùng học iBGP
  1. Router-id: đều học từ R1 -> cùng Router-id
  1. minimum cluster list length: không xét
  1.  lowest neighbor address: BREAK.

Next-hop 10.1.12.1 < 10.1.21.1 => R2 học mạng 8.8.8.0/24 qua 10.1.12.1

step 12 - minimum cluster list length ( 13 step selection route BGP)



R1#show run | se router bgp
router bgp 1
 no synchronization
 bgp log-neighbor-changes
 network 8.8.8.0 mask 255.255.255.0
 neighbor 10.1.12.2 remote-as 1
 neighbor 10.1.13.3 remote-as 1
R2#show run | se router bgp
router bgp 1
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.1.12.1 remote-as 1
 neighbor 10.1.12.1 route-reflector-client
 neighbor 10.1.25.5 remote-as 1
 no auto-summary
R3#show run | se router bgp
router bgp 1
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.1.13.1 remote-as 1
 neighbor 10.1.13.1 route-reflector-client
 neighbor 10.1.34.4 remote-as 1
 no auto-summary
R4#show run | se router bgp
router bgp 1
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.1.34.3 remote-as 1
 neighbor 10.1.45.5 remote-as 1
 no auto-summary
!
 interface f0/1
 ip ospf cost 2
R5#show run | se router bgp
router bgp 1
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.1.25.2 remote-as 1
 neighbor 10.1.25.2 route-reflector-client
 neighbor 10.1.45.4 remote-as 1
 no auto-summary

R4#show ip route
           1.0.0.0/32 is subnetted, 1 subnets
O        1.1.1.1 [110/4] via 10.1.45.5, 00:06:21, FastEthernet0/0
                       [110/4] via 10.1.34.3, 00:06:21, FastEthernet0/1
           8.0.0.0/24 is subnetted, 1 subnets
B        8.8.8.0 [200/0] via 10.1.13.1, 00:09:42
           10.0.0.0/8 is variably subnetted, 7 subnets, 2 masks
O        10.1.12.0/24 [110/3] via 10.1.45.5, 00:06:31, FastEthernet0/0
O        10.1.13.0/24 [110/3] via 10.1.34.3, 00:06:21, FastEthernet0/1
R4#show ip bgp 8.8.8.0
BGP routing table entry for 8.8.8.0/24, version 7
Paths: (2 available, best #2, table default)
  Not advertised to any peer
  Local
    10.1.12.1 (metric 3) from 10.1.45.5 (5.5.5.5)
      Origin IGP, metric 0, localpref 100, valid, internal
      Originator: 8.8.8.8, Cluster list: 5.5.5.5, 2.2.2.2
  Local
    10.1.13.1 (metric 3) from 10.1.34.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      Originator: 8.8.8.8, Cluster list: 3.3.3.3

Nhận xét: R4 học 8.8.8.0 qua R3.
Chúng ta đi kiểm tra từng bước sau:
  1. Weight: bằng nhau 0
  1. Local prefer: bằng nhau 100
  1. Perfer the path was locally..: bằng nhau
  1. AS-path: bằng nhau
  1. Origin type : bằng nhau
  1. Med: bằng nhau
  1. Prefer eBGP over iBGP: cùng iBGP
  1. Prefer with lowes IGP metric to BGP next-hop : bằng nhau = 3 ( điều chỉnh cost IGP bằng nhau như bảng RIB ở trên)
  1. Không xét ở đây.
  1. The path are external: cùng học iBGP
  1. Router-id: đều học từ R1 -> cùng Router-id
  1. minimum cluster list length: BREAK.

=> cluster length qua next-hop 10.1.13.1 (Cluster list: 3.3.3.3) = 1 < next-hop 10.1.12.1 = 2 (Cluster list: 5.5.5.5, 2.2.2.2)

step 11 - lowest router ID (13 step selection route BGP)


R2#show run | se router bgp
router bgp 2
 bgp bestpath compare-routerid
 neighbor 10.1.12.1 remote-as 1
 neighbor 10.1.23.3 remote-as 3
 no auto-summary

R2#show ip bgp
BGP table version is 6, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 8.8.8.0/24       10.1.12.1                0             0 1 i
*                             10.1.23.3                0             0 3 i

=> R2 học mạng 8.8.8.0/24 qua R1 vì có RID nhỏ hơn.
Chúng ta đi kiểm tra từng bước sau:
  1. Weight: bằng nhau 0
  2. Local prefer: bằng nhau 100
  3. Perfer the path was locally..: bằng nhau
  1. AS-path: bằng nhau
  1. Origin type : bằng nhau
  2. Med: bằng nhau
  3. Prefer eBGP over iBGP: cùng eBGP
  1. Prefer with lowes IGP metric to BGP next-hop : bằng nhau
  1. Không xét ở đây.
  2. The path are external: cùng học iBGP
  1. Router-id: BREAK

R2#clear ip bgp 10.1.12.1
*Mar  1 00:11:06.203: %BGP-5-ADJCHANGE: neighbor 10.1.12.1 Down User reset
*Mar  1 00:11:06.239: BGP(0): Revise route installing 1 of 1 routes for 8.8.8.0/24 -> 10.1.23.3(main) to main IP table
*Mar  1 00:11:06.247: BGP(0): 10.1.23.3 NEXT_HOP part 1 net 8.8.8.0/24, next 10.1.23.3
*Mar  1 00:11:06.247: BGP(0): 10.1.23.3 send UPDATE (format) 8.8.8.0/24, next 10.1.23.3, metric 0, path 3
*Mar  1 00:11:06.351: BGP(0): updgrp 1 - 10.1.23.3 updates replicated for neighbors:
*Mar  1 00:11:07.503: %BGP-5-ADJCHANGE: neighbor 10.1.12.1 Up
*Mar  1 00:11:07.567: BGP(0): 10.1.12.1 rcvd UPDATE w/ attr: nexthop 10.1.12.1, origin i, metric 0, path 1
*Mar  1 00:11:07.571: BGP(0): 10.1.12.1 rcvd 8.8.8.0/24
*Mar  1 00:11:07.571: BGP(0): Revise route installing 1 of 1 routes for 8.8.8.0/24 -> 10.1.12.1(main) to main IP table

  • Khi reset BGP giữa R2 và R1. R2 sẽ học route 8.8.8.0/24 qua R3, nhưng khi bgp giữa R1 và R2 được thiết lập lại thì R2 sẽ học 8.8.8.0/24 qua R1 ( quá trình debug ở trên).



Step 10 - path are external ( 13 step selection route BGP)

10- The paths are external ( chỉ xét đối với eBGP)
        => Prefer with a path was received first.
Note:
- DON'T Modify => Paths learn by eBGP, will always break at Step 10 ( cannot go to step 10,11,12)
- Modify => go to step 11 (command : " bgp bestpath compare-router-id" => when using ? )
Note:
- Using command : " clear ip bgp * soft" when you configure " bgp bestpath... "
- If RouterID is same => go to step 12 or 13


R2#show run | se router bgp
router bgp 2
 neighbor 10.1.12.1 remote-as 1
 neighbor 10.1.23.3 remote-as 3
 no auto-summary

R2#show ip bgp
BGP table version is 6, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 8.8.8.0/24       10.1.12.1                0             0 1 i
*                             10.1.23.3                0             0 3 i
Nhận xét: R2 học mạng 8.8.8.0/24 qua R1 vì nhận được update từ R1 sớm hơn R3.
Xét từng bước:
  1. Weight: bằng nhau 0
  1. Local prefer: bằng nhau 100
  1. Perfer the path was locally..: bằng nhau
  2. AS-path: bằng nhau
  3. Origin type : bằng nhau
  4. Med: bằng nhau
  5. Prefer eBGP over iBGP: cùng eBGP
  6. Prefer with lowes IGP metric to BGP next-hop : bằng nhau
  1. Không xét ở đây.

  1. The path are external: BREAK

Step 9 - Multipath ( 13 step selection route BGP)

9- Determine if multiple paths require installation in the Routing table for "BGP Multipath"
Continue, if bestpath is not yes selected.
  • Cấu hình multipath + step 1-8 giống nhau => tất cả các route được đưa lên RIB

R2#show run | se router bgp
router bgp 2
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.1.12.1 remote-as 1
 neighbor 10.1.23.3 remote-as 3
 no auto-summary
R2#show ip bgp 8.8.8.8
BGP routing table entry for 8.8.8.0/24, version 9
Paths: (2 available, best #2, table Default-IP-Routing-Table)
Flag: 0x820
  Advertised to update-groups:
        1
  1
    10.1.12.1 from 10.1.12.1 (1.1.1.1)
      Origin IGP, metric 0, localpref 100, valid, external
  3
    10.1.23.3 from 10.1.23.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, external, best

=> R2 học mạng 8.8.8.0/24 qua R3.  Xét 13 step

Chúng ta đi kiểm tra từng bước sau:
  1. Weight: bằng nhau 0
  2. Local prefer: bằng nhau 100
  3. Perfer the path was locally..: bằng nhau
  4. AS-path: bằng nhau 1
  5. Origin type : bằng nhau
  6. Med: bằng nhau
  7. Prefer eBGP over iBGP: cùng eBGP
  1. Prefer with lowes IGP metric to BGP next-hop : bằng nhau
  1. Không xét ở đây.
  1. The path are external:  break.
-> R2 học mạng 8.8.8.0/24 vì nó nhận được update từ R3 sớm hơn R1

Cấu hình step 9:
R2#show run | se router
router bgp 2
 bgp bestpath as-path multipath-relax  // equal load balancing bwt same length but different AS Path. Cmd hidden on IOS
 neighbor 10.1.12.1 remote-as 1
 neighbor 10.1.23.3 remote-as 3
 maximum-paths 2                                 // install 2 routes into RIB

Kiểm tra RIB R2:
R2#show ip route
     8.0.0.0/24 is subnetted, 1 subnets
B       8.8.8.0 [20/0] via 10.1.23.3, 00:02:23
                       [20/0] via 10.1.12.1, 00:02:23   


=> R2 đưa 2 route lên bảng RIB