Navigation
Guide That Contains This Content
[+] Expand All
[-] Collapse All

    Example: Using AS Path Regular Expressions

    An autonomous system (AS) path is a route attribute used by BGP. The AS path is used both for route selection and to prevent potential routing loops. This example shows how to use regular expressions with AS path numbers to locate a set of routes.

    Requirements

    No special configuration beyond device initialization is required before configuring this example.

    Overview

    Figure 1 shows several ASs connected through external BGP (EBGP) peering sessions. Each device is generating customer routes within its assigned address space.

    Topology

    Figure 1 shows the sample network.

    Figure 1: BGP Topology AS Regular Expressions

    BGP Topology AS Regular Expressions

    The administrators of AS 64516 want to reject all routes originating in AS 64513 and AS 64514. Two AS path regular expressions called orig-in-64513 and orig-in-64514 are created and referenced in a policy called reject-some-routes. The routing policy is then applied as an import policy on Device R6.

    CLI Quick Configuration shows the configuration for all of the devices in Figure 1.

    The section Step-by-Step Procedure describes the steps on Device R2 and Device R6. Verification shows how to use the aspath-regex option with the show route command on Device R2 to locate routes using regular expressions.

    Configuration

    CLI Quick Configuration

    To quickly configure this example, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, and then copy and paste the commands into the CLI at the [edit] hierarchy level.

    Device R1

    set interfaces fe-1/2/2 unit 0 description to-R2set interfaces fe-1/2/2 unit 0 family inet address 10.2.0.2/30set interfaces fe-1/2/3 unit 0 description to-R3set interfaces fe-1/2/3 unit 0 family inet address 10.2.0.6/30set interfaces fe-1/2/0 unit 0 description to-R5set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.2/30set interfaces lo0 unit 0 family inet address 192.168.0.1/32set protocols bgp export send-staticset protocols bgp group 64512 type externalset protocols bgp group 64512 peer-as 64512set protocols bgp group 64512 neighbor 10.2.0.1set protocols bgp group 64513 type externalset protocols bgp group 64513 peer-as 64513set protocols bgp group 64513 neighbor 10.2.0.5set protocols bgp group 64515 type externalset protocols bgp group 64515 peer-as 64515set protocols bgp group 64515 neighbor 10.0.0.1set policy-options policy-statement send-static term 1 from protocol staticset policy-options policy-statement send-static term 1 then acceptset routing-options static route 10.10.1.0/24 rejectset routing-options static route 10.10.2.0/24 rejectset routing-options static route 10.10.3.0/24 rejectset routing-options autonomous-system 64511

    Device R2

    set interfaces fe-1/2/2 unit 0 description to-R1set interfaces fe-1/2/2 unit 0 family inet address 10.2.0.1/30set interfaces lo0 unit 0 family inet address 192.168.0.2/32set protocols bgp export send-staticset protocols bgp group 64511 type externalset protocols bgp group 64511 peer-as 64511set protocols bgp group 64511 neighbor 10.2.0.2set policy-options policy-statement send-static term 1 from protocol staticset policy-options policy-statement send-static term 1 then acceptset routing-options static route 10.20.1.0/24 rejectset routing-options static route 10.20.2.0/24 rejectset routing-options static route 10.20.3.0/24 rejectset routing-options autonomous-system 64512

    Device R3

    set interfaces fe-1/2/3 unit 0 description to-R1set interfaces fe-1/2/3 unit 0 family inet address 10.2.0.5/30set interfaces fe-1/2/2 unit 0 description to-R4set interfaces fe-1/2/2 unit 0 family inet address 10.3.0.42/30set interfaces lo0 unit 0 family inet address 192.168.0.3/32set protocols bgp export send-staticset protocols bgp group 64511 type externalset protocols bgp group 64511 peer-as 64511set protocols bgp group 64511 neighbor 10.2.0.6set protocols bgp group 64514 type externalset protocols bgp group 64514 peer-as 64514set protocols bgp group 64514 neighbor 10.3.0.41set policy-options policy-statement send-static term 1 from protocol staticset policy-options policy-statement send-static term 1 then acceptset routing-options static route 10.30.1.0/24 rejectset routing-options static route 10.30.2.0/24 rejectset routing-options static route 10.30.3.0/24 rejectset routing-options autonomous-system 64513

    Device R4

    set interfaces fe-1/2/2 unit 0 description to-R3set interfaces fe-1/2/2 unit 0 family inet address 10.3.0.41/30set interfaces lo0 unit 0 family inet address 192.168.0.4/32set protocols bgp export send-staticset protocols bgp group 64513 type externalset protocols bgp group 64513 peer-as 64513set protocols bgp group 64513 neighbor 10.3.0.42set policy-options policy-statement send-static term 1 from protocol staticset policy-options policy-statement send-static term 1 then acceptset routing-options static route 10.40.1.0/24 rejectset routing-options static route 10.40.2.0/24 rejectset routing-options static route 10.40.3.0/24 rejectset routing-options autonomous-system 64514

    Device R5

    set interfaces fe-1/2/0 unit 0 description to-R1set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.1/30set interfaces fe-1/2/1 unit 0 description to-R6set interfaces fe-1/2/1 unit 0 family inet address 10.0.0.9/30set interfaces lo0 unit 0 family inet address 192.168.0.5/32set protocols bgp export send-staticset protocols bgp group 64511 type externalset protocols bgp group 64511 peer-as 64511set protocols bgp group 64511 neighbor 10.0.0.2set protocols bgp group 64516 type externalset protocols bgp group 64516 peer-as 64516set protocols bgp group 64516 neighbor 10.0.0.10set policy-options policy-statement send-static term 1 from protocol staticset policy-options policy-statement send-static term 1 then acceptset routing-options static route 10.50.1.0/24 rejectset routing-options static route 10.50.2.0/24 rejectset routing-options static route 10.50.3.0/24 rejectset routing-options autonomous-system 64515

    Device R6

    set interfaces fe-1/2/1 unit 0 description to-R5set interfaces fe-1/2/1 unit 0 family inet address 10.0.0.10/30set interfaces lo0 unit 0 family inet address 192.168.0.6/32set protocols bgp export send-staticset protocols bgp group 64515 type externalset protocols bgp group 64515 import reject-some-routesset protocols bgp group 64515 peer-as 64515set protocols bgp group 64515 neighbor 10.0.0.9set policy-options policy-statement send-static term 1 from protocol staticset policy-options policy-statement send-static term 1 then acceptset policy-options policy-statement reject-some-routes term find-routes from as-path orig-in-64513set policy-options policy-statement reject-some-routes term find-routes from as-path orig-in-64514set policy-options policy-statement reject-some-routes term find-routes then rejectset policy-options as-path orig-in-64513 ".* 64513"set policy-options as-path orig-in-64514 ".* 64514"set routing-options static route 10.60.1.0/24 rejectset routing-options static route 10.60.2.0/24 rejectset routing-options static route 10.60.3.0/24 rejectset routing-options autonomous-system 64516

    Step-by-Step Procedure

    The following example requires that you navigate various levels in the configuration hierarchy. For information about navigating the CLI, see Using the CLI Editor in Configuration Mode in the CLI User Guide.

    To configure Device R2:

    1. Configure the device interfaces.
      [edit interfaces]user@R2# set fe-1/2/2 unit 0 description to-R1user@R2# set fe-1/2/2 unit 0 family inet address 10.2.0.1/30
      user@R2# set lo0 unit 0 family inet address 192.168.0.2/32
    2. Configure the EBGP connection to Device R1.
      [edit protocols bgp]user@R2# set export send-staticuser@R2# set group 64511 type externaluser@R2# set group 64511 peer-as 64511user@R2# set group 64511 neighbor 10.2.0.2
    3. Configure the routing policy.
      [edit policy-options policy-statement send-static term 1]user@R2# set from protocol staticuser@R2# set then accept
    4. Configure the static routes.
      [edit routing-options static]user@R2# set route 10.20.1.0/24 rejectuser@R2# set route 10.20.2.0/24 rejectuser@R2# set route 10.20.3.0/24 reject
    5. Configure the AS number.
      [edit routing-options]user@R2# set autonomous-system 64512

    Step-by-Step Procedure

    The following example requires that you navigate various levels in the configuration hierarchy. For information about navigating the CLI, see Using the CLI Editor in Configuration Mode in the CLI User Guide.

    To configure Device R6:

    1. Configure the device interfaces.
      [edit interfaces]user@R6# set fe-1/2/1 unit 0 description to-R5user@R6# set fe-1/2/1 unit 0 family inet address 10.0.0.10/30
      user@R6# set lo0 unit 0 family inet address 192.168.0.6/32
    2. Configure the EBGP connection to Device R5.
      [edit protocols bgp]user@R6# set export send-staticuser@R6# set group 64515 type externaluser@R6# set group 64515 import reject-some-routesuser@R6# set group 64515 peer-as 64515user@R6# set group 64515 neighbor 10.0.0.9
    3. Configure the routing policy that sends static routes.
      [edit policy-options policy-statement send-static term 1]user@R6# set from protocol staticuser@R6# set then accept
    4. Configure the routing policy that rejects certain routes.
      [edit policy-options policy-statement reject-some-routes term find-routes]user@R6# set from as-path orig-in-64513user@R6# set from as-path orig-in-64514user@R6# set then reject
      [edit policy-options]user@R6# set as-path orig-in-64513 ".* 64513"user@R6# set as-path orig-in-64514 ".* 64514"
    5. Configure the static routes.
      [edit routing-options static]user@R6# set route 10.60.1.0/24 rejectuser@R6# set route 10.60.2.0/24 rejectuser@R6# set route 10.60.3.0/24 reject
    6. Configure the AS number.
      [edit routing-options]user@R6# set autonomous-system 64516

    Results

    From configuration mode, confirm your configuration by entering the show interfaces, show protocols, show policy-options, and show routing-options commands. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.

    Device R2

    user@R2# show interfaces
    fe-1/2/0 {unit 0 {description to-R1;family inet {address 10.2.0.1/30;}}}
    lo0 {unit 0 {family inet {address 192.168.0.2/32;}}}
    user@R2# show protocols
    bgp {export send-static;group 64511 {type external;peer-as 64511;neighbor 10.2.0.2;}}
    user@R2# show policy-options
    policy-statement send-static {term 1 {from protocol static;then accept;}}
    user@R2# show routing-options
    static {route 10.20.1.0/24 reject;route 10.20.2.0/24 reject;route 10.20.3.0/24 reject;}
    autonomous-system 64512;

    Device R6

    user@R6# show interfaces
    fe-1/2/0 {unit 0 {description to-R5;family inet {address 10.0.0.10/30;}}}
    lo0 {unit 0 {family inet {address 192.168.0.6/32;}}}
    user@R6# show protocols
    bgp {export send-static;group 64515 {type external;import reject-some-routes;peer-as 64515;neighbor 10.0.0.9;}}
    user@R6# show policy-options
    policy-statement reject-some-routes {term find-routes {from as-path [ orig-in-64513 orig-in-64514 ];then reject;}}
    policy-statement send-static {term 1 {from protocol static;then accept;}}
    as-path orig-in-64513 ".* 64513";as-path orig-in-64514 ".* 64514";
    user@R6# show routing-options
    static {route 10.60.1.0/24 reject;route 10.60.2.0/24 reject;route 10.60.3.0/24 reject;}
    autonomous-system 64516;

    If you are done configuring the devices, enter commit from configuration mode.

    Verification

    Confirm that the configuration is working properly.

    Finding Routes on Device R2

    Purpose

    On Device R2, use the show route aspath-regex command to locate routes using regular expressions.

    Action

    Look for routes that are originated by Device R6 in AS 64516.

    user@R2> show route terse aspath-regex ".* 64516"
    inet.0: 21 destinations, 21 routes (21 active, 0 holddown, 0 hidden)
    + = Active Route, - = Last Active, * = Both
    
    A V Destination        P Prf   Metric 1   Metric 2  Next hop        AS path
    * ? 10.60.1.0/24       B 170        100                             64511 64515 64516 I
      unverified                                       >10.2.0.2
    * ? 10.60.2.0/24       B 170        100                             64511 64515 64516 I
      unverified                                       >10.2.0.2
    * ? 10.60.3.0/24       B 170        100                             64511 64515 64516 I
      unverified                                       >10.2.0.2
    

    Look for routes that are originated in either AS 64514 or AS 64516.

    user@R2> show route terse aspath-regex ".* (64514|64516)"
    inet.0: 21 destinations, 21 routes (21 active, 0 holddown, 0 hidden)
    + = Active Route, - = Last Active, * = Both
    
    A V Destination        P Prf   Metric 1   Metric 2  Next hop        AS path
    * ? 10.40.1.0/24       B 170        100                             64511 64513 64514 I
      unverified                                       >10.2.0.2
    * ? 10.40.2.0/24       B 170        100                             64511 64513 64514 I
      unverified                                       >10.2.0.2
    * ? 10.40.3.0/24       B 170        100                             64511 64513 64514 I
      unverified                                       >10.2.0.2
    * ? 10.60.1.0/24       B 170        100                             64511 64515 64516 I
      unverified                                       >10.2.0.2
    * ? 10.60.2.0/24       B 170        100                             64511 64515 64516 I
      unverified                                       >10.2.0.2
    * ? 10.60.3.0/24       B 170        100                             64511 64515 64516 I
      unverified                                       >10.2.0.2
    

    Look for routes that use AS 64513 as a transit network.

    user@R2> show route terse aspath-regex ".* 64513 .+"
    inet.0: 21 destinations, 21 routes (21 active, 0 holddown, 0 hidden)
    + = Active Route, - = Last Active, * = Both
    
    A V Destination        P Prf   Metric 1   Metric 2  Next hop        AS path
    * ? 10.40.1.0/24       B 170        100                             64511 64513 64514 I
      unverified                                       >10.2.0.2
    * ? 10.40.2.0/24       B 170        100                             64511 64513 64514 I
      unverified                                       >10.2.0.2
    * ? 10.40.3.0/24       B 170        100                             64511 64513 64514 I
      unverified                          

    Meaning

    The output shows the routing table entries that match the specified AS path regular expressions.

    Making Sure That Routes Are Excluded on Device R6

    Purpose

    On Device R6, use the show route and show route hidden commands to make sure that routes originating from AS 64513 and AS 64514 are excluded from Device R6’s routing table.

    Action

    user@R6> show route 10.30.0/22
    inet.0: 21 destinations, 21 routes (15 active, 0 holddown, 6 hidden)

    user@R6> show route 10.40.0/22
    inet.0: 21 destinations, 21 routes (15 active, 0 holddown, 6 hidden)

    user@R6> show route hidden
    inet.0: 21 destinations, 21 routes (15 active, 0 holddown, 6 hidden)
    + = Active Route, - = Last Active, * = Both
    
    10.30.1.0/24        [BGP ] 02:24:47, localpref 100
                          AS path: 64515 64511 64513 I, validation-state: unverified
                        > to 10.0.0.9 via fe-1/2/1.0
    10.30.2.0/24        [BGP ] 02:24:47, localpref 100
                          AS path: 64515 64511 64513 I, validation-state: unverified
                        > to 10.0.0.9 via fe-1/2/1.0
    10.30.3.0/24        [BGP ] 02:24:47, localpref 100
                          AS path: 64515 64511 64513 I, validation-state: unverified
                        > to 10.0.0.9 via fe-1/2/1.0
    10.40.1.0/24        [BGP ] 02:24:47, localpref 100
                          AS path: 64515 64511 64513 64514 I, validation-state: unverified
                        > to 10.0.0.9 via fe-1/2/1.0
    10.40.2.0/24        [BGP ] 02:24:47, localpref 100
                          AS path: 64515 64511 64513 64514 I, validation-state: unverified
                        > to 10.0.0.9 via fe-1/2/1.0
    10.40.3.0/24        [BGP ] 02:24:47, localpref 100
                          AS path: 64515 64511 64513 64514 I, validation-state: unverified
                        > to 10.0.0.9 via fe-1/2/1.0

    Meaning

    The output shows that the 10.30.0/22 and 10.40.0/22 routes are rejected on Device R6.

    Published: 2013-07-31