Example for Using XPL to Filter the Routes to Be Received and Advertised (Paragraph-by-Paragraph Editing)

This section provides an example for using XPL to filter the routes to be received and advertised based on sets and route-filters in paragraph editing mode.

Networking Requirements

On the BGP network shown in Figure 1, Device A and Device B belong to AS 100, and Device C, Device D, and Device E belong to AS 200. Device A imports routes 2.2.2.0/24, 3.3.3.0/24, 4.4.4.0/24, and 5.5.5.0/24. The requirements are as follows:
  • Device A advertises routes 2.2.2.0/24, 3.3.3.0/24, and 4.4.4.0/24 to Device B.
  • On receipt of the three routes from Device B, Device C advertises all of them to Device E. On receipt of the three routes from Device B, Device D increases the MED value of the route 2.2.2.0/24 and advertises routes 2.2.2.0/24 and 3.3.3.0/24 to Device E. The MED of the route 2.2.2.0/24 learned from Device C is less than that of the route 2.2.2.0/24 learned from Device D. Therefore, Device E selects Device C as the egress for the traffic destined for 2.2.2.0/24.

To meet the preceding requirements, configure export or import policies. In this example, an export policy is configured on Device A, and two import policies are configured on Device E.

Figure 1 Cyclic figure for filtering the routes to be received and advertised

Device Name

Interface

IP Address

Device A

GE 0/1/16

1.1.5.2/24

Device B

GE 0/1/16

1.1.5.1/24

Device B

GE 0/1/17

1.1.4.2/24

Device B

GE 0/1/18

1.1.3.2/24

Device C

GE 0/1/17

1.1.1.2/24

Device C

GE 0/1/18

1.1.3.1/24

Device D

GE 0/1/17

1.1.2.2/24

Device D

GE 0/1/18

1.1.4.1/24

Device E

GE 0/1/17

1.1.2.1/24

Device E

GE 0/1/18

1.1.1.1/24

Precautions

When using XPL to filter the routes to be received and advertised, note the following points:

  • A prefix range needs to be specified for the IPv4 prefix set as required.

  • IPv4 prefix set names are case-sensitive.

Configuration Roadmap

The configuration roadmap is as follows:

  1. Configure basic BGP functions on Device A, Device B, Device C, Device D, and Device E.

  2. Configure four static routes on Device A and import them into BGP.

  3. Configure an export policy on Device A and check the BGP routing table of Device B.

  4. Configure two import policies on Device E and check the BGP routing table of Device E.

Data Preparation

To complete the configuration, you need the following data:

  • Four static routes to be imported by Device A

  • AS 100 (for Device A and Device B) and AS 200 (Device C, Device D, and Device E)

  • Name of an IPv4 prefix set and the routes to be filtered

Procedure

  1. Assign an IP address to each interface. For configuration details, see Configuration Files in this section.
  2. Configure basic BGP functions.

    # Configure Device A.

    <DeviceA> system-view
    [~DeviceA] bgp 100
    [*DeviceA-bgp] peer 1.1.5.1 as-number 100
    [*DeviceA-bgp] commit
    [~DeviceA-bgp] quit

    # Configure Device B.

    <DeviceB> system-view
    [~DeviceB] bgp 100
    [*DeviceB-bgp] peer 1.1.5.2 as-number 100
    [*DeviceB-bgp] peer 1.1.3.1 as-number 200
    [*DeviceB-bgp] peer 1.1.4.1 as-number 200
    [*DeviceB-bgp] commit
    [~DeviceB-bgp] quit

    # Configure Device C:

    <DeviceC> system-view
    [~DeviceC] bgp 200
    [*DeviceC-bgp] peer 1.1.1.1 as-number 200
    [*DeviceC-bgp] peer 1.1.3.2 as-number 100
    [*DeviceC-bgp] commit
    [~DeviceC-bgp] quit

    # Configure Device D:

    <DeviceD> system-view
    [~DeviceD] bgp 200
    [*DeviceD-bgp] peer 1.1.2.1 as-number 200
    [*DeviceD-bgp] peer 1.1.4.2 as-number 100
    [*DeviceD-bgp] commit
    [~DeviceD-bgp] quit

    # Configure Device E.

    <DeviceE> system-view
    [~DeviceE] bgp 200
    [*DeviceE-bgp] peer 1.1.1.2 as-number 200
    [*DeviceE-bgp] peer 1.1.2.2 as-number 200
    [*DeviceE-bgp] commit
    [~DeviceE-bgp] quit

  3. Configure four static routes on Device A and import them into BGP.

    [~DeviceA] ip route-static 2.2.2.0 255.255.255.0 NULL0
    [*DeviceA] ip route-static 3.3.3.0 255.255.255.0 NULL0
    [*DeviceA] ip route-static 4.4.4.0 255.255.255.0 NULL0
    [*DeviceA] ip route-static 5.5.5.0 255.255.255.0 NULL0
    [*DeviceA] bgp 100
    [*DeviceA-bgp] import-route static
    [*DeviceA-bgp] commit
    [~DeviceA-bgp] quit

    # Check the BGP routing table of Device B. The following command output shows that the four static routes have been added to the BGP routing table of Device B.

    [~DeviceB] display bgp routing-table
     
     BGP Local router ID is 1.1.5.1
     Status codes: * - valid, > - best, d - damped, x - best external, a - add path,
                   h - history,  i - internal, s - suppressed, S - Stale
                   Origin : i - IGP, e - EGP, ? - incomplete
     RPKI validation codes: V - valid, I - invalid, N - not-found
    
    
     Total Number of Routes: 4 
            Network            NextHop        MED        LocPrf    PrefVal Path/Ogn
    
     *>i    2.2.2.0/24         1.1.5.2         0          100        0       ?
     *>i    3.3.3.0/24         1.1.5.2         0          100        0       ?
     *>i    4.4.4.0/24         1.1.5.2         0          100        0       ?
     *>i    5.5.5.0/24         1.1.5.2         0          100        0       ?

    # Check the BGP routing table of Device E. The following command output shows that two copies of the four static routes from Device C and Device D have been added to the BGP routing table of Device E.

    [~DeviceE] display bgp routing-table
     
     BGP Local router ID is 1.1.1.1
     Status codes: * - valid, > - best, d - damped, x - best external, a - add path,
                   h - history,  i - internal, s - suppressed, S - Stale
                   Origin : i - IGP, e - EGP, ? - incomplete
     RPKI validation codes: V - valid, I - invalid, N - not-found
    
    
     Total Number of Routes: 8 
            Network            NextHop        MED        LocPrf    PrefVal Path/Ogn
    
       i    2.2.2.0/24         1.1.3.2                    100        0      100?
       i                       1.1.4.2                    100        0      100?
       i    3.3.3.0/24         1.1.4.2                    100        0      100?
       i                       1.1.3.2                    100        0      100?
       i    4.4.4.0/24         1.1.3.2                    100        0      100?
       i                       1.1.4.2                    100        0      100?
       i    5.5.5.0/24         1.1.4.2                    100        0      100?
       i                       1.1.3.2                    100        0      100?

  4. Configure an export policy on Device A.

    # Configure an IPv4 prefix set named prefix1 on Device A.

    [~DeviceA] quit
    <DeviceA> edit xpl ip-prefix-list prefix1
    xpl ip-prefix-list prefix1
    2.2.2.0 24,
    3.3.3.0 24,
    4.4.4.0 24
    end-list

    # Configure a route-filter named r1 on Device A, apply prefix1 to r1, and permit routes 2.2.2.0/24, 3.3.3.0/24, and 4.4.4.0/24.

    <DeviceA> edit xpl route-filter r1
    xpl route-filter r1
    if ip route-destination in prefix1 then
    approve
    else
    refuse
    endif
    end-filter

    Press i in the paragraph editing interface view to enter the text editing mode.

    After performing configurations in the text editing mode of the paragraph editing interface view, press Esc to exit from the text editing mode, and press :wq and Enter to save the configurations and exit from the paragraph editing interface view.

    # Configure an export policy on Device A and apply r1 to the policy to filter the routes to be advertised to Device B.

    <DeviceA> system-view
    [~DeviceA] bgp 100
    [~DeviceA-bgp]  peer 1.1.5.1 route-filter r1 export
    [*DeviceA-bgp]  commit
    [~DeviceA-bgp]  quit

    # Check the BGP routing table of Device B. The following command output shows that the route 5.5.5.0/24 is not included in the BGP routing table of Device B.

    [~DeviceB] display bgp routing-table
     
     BGP Local router ID is 1.1.5.1
     Status codes: * - valid, > - best, d - damped, x - best external, a - add path,
                   h - history,  i - internal, s - suppressed, S - Stale
                   Origin : i - IGP, e - EGP, ? - incomplete
     RPKI validation codes: V - valid, I - invalid, N - not-found
    
    
     Total Number of Routes: 3 
            Network            NextHop        MED        LocPrf    PrefVal Path/Ogn
    
     *>i    2.2.2.0/24         1.1.5.2         0          100        0       ?
     *>i    3.3.3.0/24         1.1.5.2         0          100        0       ?
     *>i    4.4.4.0/24         1.1.5.2         0          100        0       ?

  5. Configure two import policies on Device E.

    # Configure a route-filter named appmed with a pre-defined variable to set the MED.

    [~DeviceE] quit
    <DeviceE> edit xpl route-filter appmed
    xpl route-filter appmed($med)
    apply med $med
    end-filter
    

    # Configure a route-filter named r2 on Device E to permit routes 2.2.2.0/24 and 3.3.3.0/24 and use appmed to set the MED of the route 2.2.2.0/24 to 200.

    <DeviceE> edit xpl route-filter r2
    xpl route-filter r2
    if ip route-destination in {2.2.2.0 24} then
    call route-filter appmed(200)
    elseif ip route-destination in {2.2.2.0 24, 3.3.3.0 24} then
    approve
    else
    refuse
    endif
    end-filter
    

    # Configure a route-filter named r3 on Device E to set the MED of the route 2.2.2.0/24 to 100.

    <DeviceE> edit xpl route-filter r3
    xpl route-filter r3
    if ip route-destination in {2.2.2.0 24} then
    call route-filter appmed(100)
    else
    approve
    endif
    end-filter
    

    # Configure an import policy on Device E for the routes learned from Device D and apply r2 to the policy. In addition, configure another import policy on Device E for the routes learned from Device C and apply r3 to the policy.

    <DeviceE> system-view
    [~DeviceE] bgp 200
    [~DeviceE-bgp] peer 1.1.2.2 route-filter r2 import
    [*DeviceE-bgp] peer 1.1.1.2 route-filter r3 import
    [*DeviceE-bgp] commit
    [~DeviceE-bgp] quit

    # Check the BGP routing table of Device E. The following command output shows that the route 4.4.4.0/24 learned from Device D is not included in the BGP routing table of Device B and that the MED values of the routes 2.2.2.0/24 learned from Device C and Device D are 100 and 200, respectively.

    [~DeviceE] display bgp routing-table
     BGP Local router ID is 1.1.1.1
     Status codes: * - valid, > - best, d - damped, x - best external, a - add path,
                   h - history,  i - internal, s - suppressed, S - Stale
                   Origin : i - IGP, e - EGP, ? - incomplete
     RPKI validation codes: V - valid, I - invalid, N - not-found
    
    
     Total Number of Routes: 5 
            Network            NextHop        MED        LocPrf    PrefVal Path/Ogn
    
       i    2.2.2.0/24         1.1.4.2         200        100        0      100?
       i                       1.1.3.2         100        100        0      100?
       i    3.3.3.0/24         1.1.4.2                    100        0      100?
       i                       1.1.3.2                    100        0      100?
       i    4.4.4.0/24         1.1.3.2                    100        0      100?

Configuration Files

  • Device A configuration file

    #
    sysname DeviceA
    #
    interface GigabitEthernet0/1/16
     undo shutdown
     ip address 1.1.5.2 255.255.255.0
    #
    bgp 100
     peer 1.1.5.1 as-number 100
     #
     ipv4-family unicast
      undo synchronization
      import-route static
      peer 1.1.5.1 enable
      peer 1.1.5.1 route-filter r1 export
    #
    ip route-static 2.2.2.0 255.255.255.0 NULL0
    ip route-static 3.3.3.0 255.255.255.0 NULL0
    ip route-static 4.4.4.0 255.255.255.0 NULL0
    ip route-static 5.5.5.0 255.255.255.0 NULL0
    #
    xpl route-filter r1
     if ip route-destination in prefix1 then
      approve
     else
      refuse
     endif
     end-filter
    #
    xpl ip-prefix-list prefix1
     2.2.2.0 24,
     3.3.3.0 24,
     4.4.4.0 24
     end-list
    #
    return
  • Device B configuration file

    #
    sysname DeviceB
    #
    interface GigabitEthernet0/1/16
     undo shutdown
     ip address 1.1.5.1 255.255.255.0
    #
    interface GigabitEthernet0/1/17
     undo shutdown
     ip address 1.1.4.2 255.255.255.0
    #
    interface GigabitEthernet0/1/18
     undo shutdown
     ip address 1.1.3.2 255.255.255.0
    #
    bgp 100
     peer 1.1.3.1 as-number 200
     peer 1.1.4.1 as-number 200
     peer 1.1.5.2 as-number 100
     #
     ipv4-family unicast
      undo synchronization
      peer 1.1.3.1 enable
      peer 1.1.4.1 enable
      peer 1.1.5.2 enable
    #
    return
  • Device C configuration file

    #
    sysname DeviceC
    #
    interface GigabitEthernet0/1/17
     undo shutdown
     ip address 1.1.1.2 255.255.255.0
    #
    interface GigabitEthernet0/1/18
     undo shutdown
     ip address 1.1.3.1 255.255.255.0
    #
    bgp 200
     peer 1.1.1.1 as-number 200
     peer 1.1.3.2 as-number 100
     #
     ipv4-family unicast
      undo synchronization
      peer 1.1.1.1 enable
      peer 1.1.3.2 enable
    #
    return
  • Device D configuration file

    #
    sysname DeviceD
    #
    interface GigabitEthernet0/1/17
     undo shutdown
     ip address 1.1.2.2 255.255.255.0
    #
    interface GigabitEthernet0/1/18
     undo shutdown
     ip address 1.1.4.1 255.255.255.0
    #
    bgp 200
     peer 1.1.2.1 as-number 200
     peer 1.1.4.2 as-number 100
     #
     ipv4-family unicast
      undo synchronization
      peer 1.1.2.1 enable
      peer 1.1.4.2 enable
    #
    return
  • Device E configuration file

    #
    sysname DeviceE
    #
    interface GigabitEthernet0/1/17
     undo shutdown
     ip address 1.1.2.1 255.255.255.0
    #
    interface GigabitEthernet0/1/18
     undo shutdown
     ip address 1.1.1.1 255.255.255.0
    #
    bgp 200
     peer 1.1.1.2 as-number 200
     peer 1.1.2.2 as-number 200
     #
     ipv4-family unicast
      undo synchronization
      peer 1.1.1.2 enable
      peer 1.1.1.2 route-filter r3 import
      peer 1.1.2.2 enable
      peer 1.1.2.2 route-filter r2 import
    #
    xpl route-filter appmed($med)
     apply med $med
     end-filter
    #
    xpl route-filter r2
     if ip route-destination in {2.2.2.0 24} then
      call route-filter appmed(200)
     elseif ip route-destination in {2.2.2.0 24, 3.3.3.0 24} then
      approve
     else
      refuse
     endif
     end-filter
    #
    xpl route-filter r3
     if ip route-destination in {2.2.2.0 24} then
      call route-filter appmed(100)
     else
      approve
     endif
     end-filter
    #
    return
Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
Next topic >