Got it

As-path length control

Created: Feb 27, 2021 14:58:44Latest reply: Feb 27, 2021 15:01:49 350 1 0 0 0
  Rewarded HiCoins: 0 (problem resolved)

Hi,

When our customer replaces the device, they found the old device of another vendor had a policy 'if as-path length le 3'. It means only permit the routes which as-path length <= 3.

Whether the HW router has similar command can replace this command of another vendor?

Featured Answers

Recommended answer

Popeye_Wang
Admin Created Feb 27, 2021 15:01:49

Hello,

 We don't have a command which has the same function. However, we can use other methods to achieve the same result.

The length of as-path <= 3 , it equals to the length of as-path is 0, 1, 2 or 3. So, we can use the as-path-filter to achieve it.

According to the format of as-path, there is a space character between every AS number.

So, we can use the number of spaces to judge the length of the as-path. Following is the as-path-filter example.


ip as-path-filter test permit ^$                    // ^$ means the length of as-path is 0.

ip as-path-filter test permit ^[^ ]+$               // [^ ] means the string without space character, ^[^ ]+$ means there is one AS number in as-path.

ip as-path-filter test permit ^[^ ]+_[^ ]+$         // "_" can match space character, ^[^ ]+_[^ ]+$ means one space character between 2 AS number.

ip as-path-filter test permit ^[^ ]+_[^ ]+_[^ ]+$   // similar to above sentence, it means 3 AS number.


If you worry about there could be an invalid character among as-path string in exception condition and want to restrict the character strictly, you can add only valid character in the regular expression.

4 bytes as-path could have "." character in AS number. AS_Set uses {}, AS_Confed_Set uses [], AS_Confed_Sequence use (). In a regular expression, it needs to use "\" to express the bracket's character.

Then, update the as-path like the following sentences.


ip as-path-filter test2 permit ^$

ip as-path-filter test2 permit ^[0-9\.\{\}\[\]\(\)]*$

ip as-path-filter test2 permit ^[0-9\.\{\}\[\]\(\)]*_[0-9\.\{\}\[\]\(\)]*$

ip as-path-filter test2 permit ^[0-9\.\{\}\[\]\(\)]*_[0-9\.\{\}\[\]\(\)]*_[0-9\.\{\}\[\]\(\)]*$

                     

Note:

1. For the Metacharacters supported by BGP AS_Path regular expressions, please refer to Product Document. This case will not describe them.

2. There are other methods to calculate the length of the as-path. If calculate the length of AS_Set is 1, calculate the length of AS_Confed_Set and AS_Confed_Sequence as 0, the regular expression will be very complicated, it's difficult to achieve it. So, in this case, I just calculate the quantity of AS number, do not care about another complicated method.


View more
  • x
  • convention:

All Answers

Hello,

 We don't have a command which has the same function. However, we can use other methods to achieve the same result.

The length of as-path <= 3 , it equals to the length of as-path is 0, 1, 2 or 3. So, we can use the as-path-filter to achieve it.

According to the format of as-path, there is a space character between every AS number.

So, we can use the number of spaces to judge the length of the as-path. Following is the as-path-filter example.


ip as-path-filter test permit ^$                    // ^$ means the length of as-path is 0.

ip as-path-filter test permit ^[^ ]+$               // [^ ] means the string without space character, ^[^ ]+$ means there is one AS number in as-path.

ip as-path-filter test permit ^[^ ]+_[^ ]+$         // "_" can match space character, ^[^ ]+_[^ ]+$ means one space character between 2 AS number.

ip as-path-filter test permit ^[^ ]+_[^ ]+_[^ ]+$   // similar to above sentence, it means 3 AS number.


If you worry about there could be an invalid character among as-path string in exception condition and want to restrict the character strictly, you can add only valid character in the regular expression.

4 bytes as-path could have "." character in AS number. AS_Set uses {}, AS_Confed_Set uses [], AS_Confed_Sequence use (). In a regular expression, it needs to use "\" to express the bracket's character.

Then, update the as-path like the following sentences.


ip as-path-filter test2 permit ^$

ip as-path-filter test2 permit ^[0-9\.\{\}\[\]\(\)]*$

ip as-path-filter test2 permit ^[0-9\.\{\}\[\]\(\)]*_[0-9\.\{\}\[\]\(\)]*$

ip as-path-filter test2 permit ^[0-9\.\{\}\[\]\(\)]*_[0-9\.\{\}\[\]\(\)]*_[0-9\.\{\}\[\]\(\)]*$

                     

Note:

1. For the Metacharacters supported by BGP AS_Path regular expressions, please refer to Product Document. This case will not describe them.

2. There are other methods to calculate the length of the as-path. If calculate the length of AS_Set is 1, calculate the length of AS_Confed_Set and AS_Confed_Sequence as 0, the regular expression will be very complicated, it's difficult to achieve it. So, in this case, I just calculate the quantity of AS number, do not care about another complicated method.


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.