Got it

AS path filter and regular expressions [BGP Fundamentals] - 17 Highlighted

Latest reply: May 27, 2021 15:53:57 10534 7 6 0 3

Hi there!


This post will introduce the AS path filter and regular expressions, as part of the BGP Fundamentals on the Forum. Please check below for more details.


1. About Regular Expressions


A regular expression is a pattern used to match against an input string. It is a widely used tool. Regular expressions are often used in Internet access. For example, when registering at a site, you need to enter your mobile phone number (if requested). How does the background program determine whether the entered mobile phone number is a valid number? In this case, regular expressions can be used for matching. Therefore, regular expressions are very powerful.

 

In BGP routing policy deployment, regular expressions can also be flexibly used to obtain routes. A BGP route contains the AS_Path attribute. On a complex large-scale network, the AS_Path attribute is also complex. In specific requirements, regular expressions can be used to obtain routes with a specific AS number or AS_Path attribute.

 

First, let's look at the composition of a regular expression:

 172309cs7oq5xsqiksi5x0.png

Generally, a regular expression can contain two types of characters: regular characters and control characters.
Control characters may be atomic characters, multiplicative characters, or range characters.
For example, the regular expression 100 can match any string that contains the number 100, such as 100 200, 10000, and 21412100. If you want a more precise match result, use control characters to further control the match result.
The following describes the characters that may be used in regular expressions.

 

Atomic characters

.

Match      any character (including a space).

^

Assert      start of string.

$

Assert      end of string.

_

Match      any separator, such as ^, $, space, tab, comma (,), and {,}.

|

Separate      alternative patterns.

\

General      escape character, which converts the following control characters into      regular characters.

 

 Examples of atomic characters

^a.$

Match      the string that starts with a and ends with any single character, such as a0      and a!.

^100_

Match      100, 100 200, 100 300 400, and so on.

^100$

Match      100.

100$|400$

Match      100, 1400, 300 400, and so on.

^\(65000\)$

Match      only 65000.

 

 Multiplicative characters

*

0 or      more quantifiers

+

1 or      more quantifiers

?

0 or 1      quantifier

 

 Examples of multiplicative characters

abc*d

Match      abd, abcd, abccd, abcccd, and so on.

abc+d

Match      abcd, abccd, abcccd, and so on.

abc?d

Match      abd, abcd, abcdefg, and so on.

a(bc)?d

Match      ad, abcd, aaabcd, and so on.

 

A multiplicative character can be applied to a single character or multiple characters. If it is applied to multiple characters, the characters must be enclosed in parentheses ().
 

 Range characters

[]

Specify      a range that contains any of the characters that are enclosed in [ ].

Note      another use for the ^ symbol. As an example, the following regular expression      is a range that matches any character as long as it is not the letters a, b,      c, or d: [^abcd]. With      the underscore character (_), you can specify that a pattern exist anywhere      in the input string.

 

Examples of range characters

[abcd]

Match      a, b, c, or d.

[a-c      1-2]$

Match      a, a1, 62, 1b, xv2, and so on.

[^act]$

Match      any string that does not end with a, c, or t.

[123].[7-9]

Match      15 220 and 91 70.

 

2. About AS Path Filters

 

 

172309frjcezdu9bto6adu.jpg


The AS_Path attribute can be used as a character string and used together with a regular expression to match routes. For example, the AS_Path attribute 123 495 602 is a character string in which three numbers are separated by two spaces. You can run the as-path-filtercommand and specify a regular expression to match the AS_Path attribute of BGP routes and find the matched routes to enforce a routing policy.

 

http://image.hw3static.com/hi/showimage-14958989-432623-974b33c23ccc5f59738892f01762e91c.jpg

 

The preceding figure is an example: The ip as-path-filter 1 permit 443 command defines AS path filter 1, using the regular expression 443, which matches any string containing 443. 


Note that if the AS_Path attribute contains multiple AS numbers, the AS numbers are separated by spaces, and the spaces can be matched by regular expressions. The following shows some examples:

 

^$

Match the routes whose AS_Path attribute      does not contain any AS number, that is, routes within the local AS.

.*

Match any route.

^100$

Match the routes whose AS_Path attribute      is 100.

_100$

Match the routes whose AS_Path attribute      ends with 100, that is, routes originated by AS 100.

^10[012349]$

Match the routes whose AS_Path attribute      is 100, 101, 102, 103, 104, or 109.

^10[^0-6]$

Match the routes whose AS_Path attribute      is not 100, 101, 102, 103, 104, 105, or 106.

^10.

Match the routes whose AS_Path attribute      is 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, or 10 because . also      matches a space.

^(100|200)$

Match the routes whose AS_Path attribute      contains 100 or 200.

12(_34)?_56

Match the routes whose AS_Path attribute      is 12 56 or 12 34 56.

 

Note that the ip as-path-filtercommand rejects all routes by default.

 

3. Examples of AS Path Filters

 

172309bc3457wo8dzoo384.png


In application 1, an AS path filter is defined and associated with a regular expression ^100$. This filter can match the routes whose AS_Path attribute is 100 (excluding any other AS numbers or numbers). Then, the filter is applied to the peer command, which allows only the routes matching the as-path-filter 1 to be transmitted to the BGP peer 10.1.34.4.


In application 2, the if-matchcommand in a route-policy is used to invoke the defined AS path filter, and then the apply command is used to set the attribute value of the LP path. In the BGP configuration mode, the route-policy is applied to the peercommand (in the import direction). In this way, after a router receives the BGP routes from the BGP peer 10.1.34.4, the router sets the LP path attribute to 100 for all the routes that match the AS path filter.

 

·         Example 1 of an AS path filter

 

 172309wk1z3mmd8k0iekd0.png

 

·         Example 2 of an AS path filter


  172310ivv0ditfzcdikdr9.png

The post is synchronized to: BGP - From junior to expert

thank you
View more
  • x
  • convention:

helpful
View more
  • x
  • convention:

Thank you
View more
  • x
  • convention:

GOOD
View more
  • x
  • convention:

andersoncf1
MVE Author Created Apr 30, 2021 17:21:40

Well done! Thanks for sharing
View more
  • x
  • convention:

thanks for information
View more
  • x
  • convention:

Nice info.
View more
  • x
  • convention:

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.