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

    Example: Defining a Routing Policy Based on the Number of BGP Communities

    This example shows how to create a policy that accepts BGP routes based on the number of BGP communities.

    Requirements

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

    Overview

    This example shows two routing devices with an external BGP (EBGP) connection between them. Device R2 uses the BGP session to send two static routes to Device R1. On Device R1, an import policy specifies that the BGP-received routes can contain up to five communities to be considered a match. For example, if a route contains three communities, it is considered a match and is accepted. If a route contains six or more communities, it is considered a nonmatch and is rejected.

    It is important to remember that the default policy for EBGP is to accept all routes. To ensure that the nonmatching routes are rejected, you must include a then reject action at the end of the policy definition.

    Topology

    Figure 1 shows the sample network.

    Figure 1: BGP Policy with a Limit on the Number of Communities Accepted

    BGP Policy with a Limit
on the Number of Communities Accepted

    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/1/0 unit 0 description to-R2set interfaces fe-1/1/0 unit 0 family inet address 10.0.0.1/30set interfaces lo0 unit 0 family inet address 192.168.0.1/32set protocols bgp group external-peers type externalset protocols bgp group external-peers peer-as 2set protocols bgp group external-peers neighbor 10.0.0.2 import import-communitiesset policy-options policy-statement import-communities term 1 from protocol bgpset policy-options policy-statement import-communities term 1 from community-count 5 orlowerset policy-options policy-statement import-communities term 1 then acceptset policy-options policy-statement import-communities term 2 then rejectset routing-options router-id 192.168.0.1set routing-options autonomous-system 1

    Device R2

    set interfaces fe-1/1/0 unit 0 description to-R1set interfaces fe-1/1/0 unit 0 family inet address 10.0.0.2/30set interfaces lo0 unit 0 family inet address 192.168.0.2/32set protocols bgp group external-peers type externalset protocols bgp group external-peers export staticsset protocols bgp group external-peers peer-as 1set protocols bgp group external-peers neighbor 10.0.0.1set policy-options policy-statement statics from protocol staticset policy-options policy-statement statics then community add 1set policy-options policy-statement statics then acceptset policy-options community 1 members 2:1set policy-options community 1 members 2:2set policy-options community 1 members 2:3set policy-options community 1 members 2:4set policy-options community 1 members 2:5set policy-options community 1 members 2:6set policy-options community 1 members 2:7set policy-options community 1 members 2:8set policy-options community 1 members 2:9set policy-options community 1 members 2:10set routing-options static route 10.2.0.0/16 rejectset routing-options static route 10.2.0.0/16 installset routing-options static route 10.3.0.0/16 rejectset routing-options static route 10.3.0.0/16 installset routing-options router-id 192.168.0.3set routing-options autonomous-system 2

    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 R1:

    1. Configure the interfaces.
      [edit interfaces]user@R1# set fe-1/1/0 unit 0 description to-R2user@R1# set fe-1/1/0 unit 0 family inet address 10.0.0.1/30
      user@R1# set lo0 unit 0 family inet address 192.168.0.1/32
    2. Configure BGP.

      Apply the import policy to the BGP peering session with Device R2.

      [edit protocols bgp group external-peers]user@R1# set type externaluser@R1# set peer-as 2user@R1# set neighbor 10.0.0.2 import import-communities
    3. Configure the routing policy that sends direct routes.
      [edit policy-options policy-statement import-communities]user@R1# set term 1 from protocol bgpuser@R1# set term 1 from community-count 5 orloweruser@R1# set term 1 then acceptuser@R1# set term 2 then reject
    4. Configure the autonomous system (AS) number and the router ID.
      [edit routing-options ]user@R1# set router-id 192.168.0.1user@R1# set autonomous-system 1

    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 interfaces.
      [edit interfaces]user@R2# set fe-1/1/0 unit 0 description to-R1user@R2# set fe-1/1/0 unit 0 family inet address 10.0.0.2/30
      user@R2# set lo0 unit 0 family inet address 192.168.0.2/32
    2. Configure the router ID and the autonomous system (AS) number.
      [edit routing-options]user@R2# set router-id 192.168.0.3user@R2# set autonomous-system 2
    3. Configure BGP.
      [edit protocols bgp group external-peers]user@R2# set type externaluser@R2# set peer-as 1user@R2# set neighbor 10.0.0.1
    4. Configure multiple communities, or configure a single community with multiple members.
      [edit policy-options community 1]user@R2# set members 2:1user@R2# set members 2:2user@R2# set members 2:3user@R2# set members 2:4user@R2# set members 2:5user@R2# set members 2:6user@R2# set members 2:7user@R2# set members 2:8user@R2# set members 2:9user@R2# set members 2:10
    5. Configure the static routes.
      [edit routing-options static]user@R2# set route 10.2.0.0/16 rejectuser@R2# set route 10.2.0.0/16 install
      user@R2# set route 10.3.0.0/16 rejectuser@R2# set route 10.3.0.0/16 install
    6. Configure a routing policy that advertises static routes into BGP and adds the BGP community to the routes.
      [edit policy-options policy-statement statics]user@R2# set from protocol staticuser@R2# set then community add 1user@R2# set then accept
    7. Apply the export policy.
      [edit protocols bgp group external-peers]user@R2# set export statics

    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 R1

    user@R1# show interfaces
    fe-1/1/0 {unit 0{description to-R2;family inet {address 10.0.0.1/30;}}}
    lo0 {unit 0 {family inet {address 192.168.0.1/32;}}}
    }
    user@R1# show protocols
    bgp {group external-peers {type external;peer-as 2;neighbor 10.0.0.2 {import import-communities;}}}
    user@R1# show policy-options
    policy-statement import-communities {term 1 {from {protocol bgp;community-count 5 orlower;}then accept;}term 2 {then reject;}}
    user@R1# show routing-optionsrouter-id 192.168.0.1;autonomous-system 1;

    Device R2

    user@R2# show interfaces
    fe-1/1/0 {unit 0 {description to-R1;family inet {address 10.0.0.2/30;}}}
    lo0 {unit 0 {family inet {address 192.168.0.2/32;}}}
    user@R2# show protocols
    bgp {group external-peers {type external;export statics;peer-as 1;neighbor 10.0.0.1;}}
    user@R2# show policy-options
    policy-statement statics {from protocol static;then {community add 1;accept;}}
    community 1 members [ 2:1 2:2 2:3 2:4 2:5 2:6 2:7 2:8 2:9 2:10 ];
    user@R2# show routing-options
    static {route 10.2.0.0/16 {reject;install;}route 10.3.0.0/16 {reject;install;}}
    router-id 192.168.0.3;autonomous-system 2;

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

    Verification

    Confirm that the configuration is working properly.

    Verifying the BGP Routes

    Purpose

    Make sure that the routing table on Device R1 contains the expected BGP routes.

    Action

    1. On Device R1, run the show route protocols bgp command.
      user@R1> show route protocols bgp
      inet.0: 5 destinations, 5 routes (3 active, 0 holddown, 2 hidden)
      
    2. On Device R1, change the community-count configuration in the import policy.
      [edit policy-options policy-statement import-communities term 1]user@R1# set from community-count 5 orhigheruser@R1# commit
    3. On Device R1, run the show route protocols bgp command.
      user@R1> show route protocols bgp
      inet.0: 5 destinations, 5 routes (5 active, 0 holddown, 0 hidden)
      + = Active Route, - = Last Active, * = Both
      
      10.2.0.0/16        *[BGP/170] 18:29:53, localpref 100
                            AS path: 2 I, validation-state: unverified
                          > to 10.0.0.2 via fe-1/1/0.0
      10.3.0.0/16        *[BGP/170] 18:29:53, localpref 100
                            AS path: 2 I, validation-state: unverified
                          > to 10.0.0.2 via fe-1/1/0.0
    4. On Device R1, run the show route protocols bgp extensive command to view the advertised communities.
      user@R1> show route protocols bgp extensive
      inet.0: 5 destinations, 5 routes (5 active, 0 holddown, 0 hidden)
      10.2.0.0/16 (1 entry, 1 announced)
      TSI:
      KRT in-kernel 10.2.0.0/16 -> {10.0.0.2}
              *BGP    Preference: 170/-101
                      Next hop type: Router, Next hop index: 671
                      Address: 0x9458270
                      Next-hop reference count: 4
                      Source: 10.0.0.2
                      Next hop: 10.0.0.2 via fe-1/1/0.0, selected
                      Session Id: 0x100001
                      State: <Active Ext>
                      Local AS:     1 Peer AS:     2
                      Age: 18:56:10 
                      Validation State: unverified 
                      Task: BGP_2.10.0.0.2+179
                      Announcement bits (1): 0-KRT 
                      AS path: 2 I
                      Communities: 2:1 2:2 2:3 2:4 2:5 2:6 2:7 2:8 2:9 2:10
                      Accepted
                      Localpref: 100
                      Router ID: 192.168.0.3
      
      10.3.0.0/16 (1 entry, 1 announced)
      TSI:
      KRT in-kernel 10.3.0.0/16 -> {10.0.0.2}
              *BGP    Preference: 170/-101
                      Next hop type: Router, Next hop index: 671
                      Address: 0x9458270
                      Next-hop reference count: 4
                      Source: 10.0.0.2
                      Next hop: 10.0.0.2 via fe-1/1/0.0, selected
                      Session Id: 0x100001
                      State: <Active Ext>
                      Local AS:     1 Peer AS:     2
                      Age: 18:56:10 
                      Validation State: unverified 
                      Task: BGP_2.10.0.0.2+179
                      Announcement bits (1): 0-KRT 
                      AS path: 2 I
                      Communities: 2:1 2:2 2:3 2:4 2:5 2:6 2:7 2:8 2:9 2:10
                      Accepted
                      Localpref: 100
                      Router ID: 192.168.0.3
      
      

    Meaning

    The output shows that in Device R1’s routing table, the BGP routes sent from Device R2 are hidden. When the community-count setting in Device R1’s import policy is modified, the BGP routes are no longer hidden.

    Published: 2013-07-31