BGP Regular Expressions

Les expressions régulières permettent de réaliser des filtres sur l’attribut « AS Path »

  • as-path
  • filter-list
  • show ip bgp regexp

 

Dans cette exemple, le router R1 obtient la topologie suivante :

R1#show ip bgp | be Net
   Network          Next Hop            Metric LocPrf Weight Path
*> 1.0.0.0          0.0.0.0                  0         32768 i
*> 2.0.0.0          10.1.12.2                0             0 200 i
*> 3.0.0.0          10.1.12.2                              0 200 300 i
*> 4.0.0.0          10.1.12.2                              0 200 300 400 i

Configurations :

Filtre les prefix avec l’attribut « AS Path » terminant par 300

R1#
ip as-path access-list 1 deny _300$
ip as-path access-list 1 permit .*
!
router bgp 100
 no synchronization
 bgp log-neighbor-changes
 network 1.0.0.0
 network 11.0.0.0
 neighbor 10.1.12.2 remote-as 200
 neighbor 10.1.12.2 filter-list 1 in
 no auto-summary

Vérifications

R1#show ip bgp | be Net
   Network          Next Hop            Metric LocPrf Weight Path
*> 1.0.0.0          0.0.0.0                  0         32768 i
*> 2.0.0.0          10.1.12.2                0             0 200 i
*> 4.0.0.0          10.1.12.2                              0 200 300 400 i

Filtre les prefix contenant 300 dans l’attribut « AS Path »

ip as-path access-list 1 deny _300_
ip as-path access-list 1 permit .*
!

Vérifications

R1#show ip bgp | be Net
   Network          Next Hop            Metric LocPrf Weight Path
*> 1.0.0.0          0.0.0.0                  0         32768 i
*> 2.0.0.0          10.1.12.2                0             0 200 i

Filtre les prefix locaux dans les annonces

R3#show ip bgp neighbors 10.1.23.2 advertised-routes | be Net
   Network          Next Hop            Metric LocPrf Weight Path
*> 1.0.0.0          10.1.23.2                              0 200 100 i
*> 2.0.0.0          10.1.23.2                0             0 200 i
*> 3.0.0.0          0.0.0.0                  0         32768 i
*> 4.0.0.0          10.1.34.4                0             0 400 i

Configuration

ip as-path access-list 1 deny ^$
ip as-path access-list 1 permit .*
!
router bgp 300
 no synchronization
 bgp log-neighbor-changes
 network 3.0.0.0
 network 33.0.0.0
 neighbor 10.1.23.2 remote-as 200
 neighbor 10.1.23.2 filter-list 1 out
 neighbor 10.1.34.4 remote-as 400
 no auto-summary

Vérifications

R3#show ip bgp neighbors 10.1.23.2 advertised-routes | be Net
   Network          Next Hop            Metric LocPrf Weight Path
*> 4.0.0.0          10.1.34.4                0             0 400 i

Total number of prefixes 1

show ip bgp regexp

La commande « show ip bgp regexp » permet de verifier (de tester) une expression régulière avant sont implémentation

R3#show ip bgp
   Network          Next Hop            Metric LocPrf Weight Path
*> 1.0.0.0          10.1.23.2                              0 200 100 i
*> 2.0.0.0          10.1.23.2                0             0 200 i
*> 3.0.0.0          0.0.0.0                  0         32768 i
*> 4.0.0.0          10.1.34.4                0             0 400 i
R3#sh ip bgp regexp ^$
   Network          Next Hop            Metric LocPrf Weight Path
*> 3.0.0.0          0.0.0.0                  0         32768 i
R3#sh ip bgp regexp ^200$
   Network          Next Hop            Metric LocPrf Weight Path
*> 2.0.0.0          10.1.23.2                0             0 200 i
R3#sh ip bgp regexp ^200_
   Network          Next Hop            Metric LocPrf Weight Path
*> 1.0.0.0          10.1.23.2                              0 200 100 i
*> 2.0.0.0          10.1.23.2                0             0 200 i
R3#sh ip bgp regexp ^[0-9]+$
   Network          Next Hop            Metric LocPrf Weight Path
*> 2.0.0.0          10.1.23.2                0             0 200 i
*> 4.0.0.0          10.1.34.4                0             0 400 i
R3#sh ip bgp regexp ^200_100$
   Network          Next Hop            Metric LocPrf Weight Path
*> 1.0.0.0          10.1.23.2                              0 200 100 i
This entry was posted in BGP. Bookmark the permalink.

Comments are closed.