Warning: Parameter 1 to wp_default_scripts() expected to be a reference, value given in /homepages/36/d681171600/htdocs/stalinbabu/wp-includes/plugin.php on line 601
BGP Route Filtering Using Regular Expressions – StalinBabu.com – My Personal Blog
Warning: Parameter 1 to wp_default_styles() expected to be a reference, value given in /homepages/36/d681171600/htdocs/stalinbabu/wp-includes/plugin.php on line 601
Technology

BGP Route Filtering Using Regular Expressions

Regular expressions can be used to match patterns in a input string, Regular expressions in BGP is used to filter Autonomous System number from the AS_PATH attribute.

Regular Expression

Function

. Any single character
\ Matches special characters
[] Matches characters or a range of characters separated by a hyphen
^ Beginning of a string
? 0 or 1 of preceding character
$ End of String
* 0 or more preceding character
+ 1 or more of preceding character
| Logical OR
_  Underscore РMatches comma, {} beginning of string, end of string or a space

 

Examples of Usage:

Matches Prefix originating AS 100

_100$

Matches prefix originated and sent from AS 100

^100$

Matches prefixes that transited AS 100

_400_

Matches all routes that passes through AS 789

^789_.

^ specifies begin of string

_ next to 789 is a space.

. Match anything after that and also expecting something after that

Match routes with only one AS long or directly connected AS

^[0-9]+$

^ means begin with

[0-9]+ [] means Bracket expression, [0-9] matches any single digit, + means Preceding item must match one or more times meaning it will match 756, 456, 5678 etc

$ The pattern has to appear at the end of a string

Matching prefixes two hops away:

^[0-9]+_[0-9]+$

Match repeat AS numbers in the AS-PATH

^([0-9]+)(_\1)*$

() – specifies a set, the above expression has two sets. set 1 is ([0-9]+) and second set is (_\1)

[0-9]+ – as example above

\1 – is a special match, that will match anything that is matching set 1 ([0-9]+)

Match repeat AS 100

^100(_100)*$

Match prefixes originating AS 200 or 300 and exactly three hops away

^[0-9]+_[0-9]+_(200|300)$

Match routes has no AS in AS-PATH meaning only internal routes (locally originated

^$

Match everything

.*

Using Regular expression in IOS commands Examples:

  ! Matches Prefix originating AS 100
ip as-path access-list 1 deny _100$
! match everything as with ACL a implicit deny apply if the below not used
ip as-path access-list 1 permit .*

router bgp 100
neighbor 150.1.1.1 filter-list 1 in

!Using route-maps

ip as-path access-list 1 deny ^300$
ip as-path access-lis 1 permit .*
route-map FILTER permit 10
match as-path 1
neighbor 1.1.1.1 route-map FILTER OUT