8 mins read

BGP – loops

1. Intro

When configured, loops will allow the local device’s AS number to be in the received AS paths, and specify the number of times detection of the local device’s AS number in the AS_PATH attribute causes the route to be discarded.

There are 2 ways of configuring loops:

  • set routing-options autonomous-system as-number loops number
  • set protocols bgp group group-name family address-family loops number

As we can see, we can configure this globally, or we can be more specific configuring per group or per address family.

Note: If you configure the local AS values for any BGP group, the detection of routing loops is performed using both the AS and the local AS values for all BGP groups. All of the local-as statements configured on the device are part of a single AS domain. The AS path loop-detection mechanism is based on looking for a matching AS present in the domain.

Note: Once you set the loops count for an AS number, it must be the same loop count for that AS number, whether it is set for different routing instances or in the global routing options: Article Detail.

2. Configuring loops

We will use the following setup where we have the same AS65535 on R1, R3 and R5. We want to advertise the R5 192.168.50.0/26 prefix to R1. Routers have been already configured, including advertise-peer-as, the only part that is missing is loops on R1.

### By default the route which has an AS path loop is discarded, in our case we have the keep all knob: 

root@R1# show protocols bgp | display set 
set protocols bgp group AS650001 keep all
set protocols bgp group AS650001 export BGP-EXPORT
set protocols bgp group AS650001 peer-as 64001
set protocols bgp group AS650001 neighbor 17.8.0.2

### R1 is receiving the 192.168.50.0/26 prefix but it is hidden (because of the keep all knob): 

root@R1# run show route protocol bgp hidden extensive 

inet.0: 25 destinations, 25 routes (24 active, 0 holddown, 1 hidden)
192.168.50.0/26 (1 entry, 0 announced)
         BGP   
                Next hop type: Router, Next hop index: 598
                Address: 0x7bbe964
                Next-hop reference count: 1, key opaque handle: 0x0, non-key opaque handle: 0x0
                Kernel Table Id: 0
                Source: 17.8.0.2
                Next hop: 17.8.0.2 via ge-0/0/1.0, selected
                Session Id: 356
                State: <Hidden Ext Changed>
                Local AS: 65535 Peer AS: 64001
                Age: 4:45 
                Validation State: unverified 
                Task: BGP_64001.17.8.0.2
                AS path: 64001 65535 65535 65535 64003 65535 65535 65535 I  (Looped: 65535) 
                Router ID: 17.0.0.2
                Hidden reason: AS path loop
                Thread: junos-main 

As we can see, we have 2 loops, but because the as-path was prepended multiple times by R3 and R5, the 65535 AS appears 6 times in the as-path. Let’s configure loops to allow the prefix

root@R1# set protocols bgp group AS650001 family inet unicast loops 2  

[edit]
root@R1# show | compare 
[edit protocols bgp group AS650001]
+     family inet {
+         unicast {
+             loops 2;
+         }
+     }

[edit]
root@R1# commit 
commit complete

### The prefix is still hidden, because loop 2 configuration is not enough: 

[edit]
root@R1# run show route protocol bgp hidden extensive 

inet.0: 25 destinations, 25 routes (24 active, 0 holddown, 1 hidden)
192.168.50.0/26 (1 entry, 0 announced)
         BGP   
                Next hop type: Router, Next hop index: 598
                Address: 0x7bbe964
                Next-hop reference count: 1, key opaque handle: 0x0, non-key opaque handle: 0x0
                Kernel Table Id: 0
                Source: 17.8.0.2
                Next hop: 17.8.0.2 via ge-0/0/1.0, selected
                Session Id: 356
                State: <Hidden Ext Changed>
                Local AS: 65535 Peer AS: 64001
                Age: 22 
                Validation State: unverified 
                Task: BGP_64001.17.8.0.2
                AS path: 64001 65535 65535 65535 64003 65535 65535 65535 I  (Looped: 65535) 
                Router ID: 17.0.0.2
                Hidden reason: AS path loop
                Thread: junos-main 

### Increasing the loop number one by one, we get to 6, where the prefix is accepted: 

root@R1# set protocols bgp group AS650001 family inet unicast loops 6    

[edit]
root@R1# commit 
commit complete

[edit]
root@R1# run show route protocol bgp extensive                          

inet.0: 25 destinations, 25 routes (25 active, 0 holddown, 0 hidden)
192.168.50.0/26 (1 entry, 1 announced)
TSI:
KRT in-kernel 192.168.50.0/26 -> {17.8.0.2}
        *BGP    Preference: 170/-101
                Next hop type: Router, Next hop index: 598
                Address: 0x7bbe964
                Next-hop reference count: 2, key opaque handle: 0x0, non-key opaque handle: 0x0
                Kernel Table Id: 0
                Source: 17.8.0.2
                Next hop: 17.8.0.2 via ge-0/0/1.0, selected
                Session Id: 356
                State: <Active Ext>
                Local AS: 65535 Peer AS: 64001
                Age: 9 
                Validation State: unverified 
                Task: BGP_64001.17.8.0.2
                Announcement bits (1): 0-KRT 
                AS path: 64001 65535 65535 65535 64003 65535 65535 65535 I  (Looped: 65535) 
                Accepted
                Localpref: 100
                Router ID: 17.0.0.2
                Thread: junos-main 

So, the loops feature will not check now many loops are in the as-path (2 in our case), instead it will check how many times the local device’s AS number is detected in the ae-path.

Now, let’s remove the loops from the address family and configure loops globally instead.

Another important point:

  • When loops 1 configured globally: route is discarded if the local device’s AS number is detected in the path one or more times (greater or equal than the configured value)
  • When loops 1 configured per address family: route is discarded if the local device’s AS number is detected in the path more than once (greater than the configured value).

3. Final remarks

  • The loops feature will not count the actual loops, but the number of times local as is in the path (as-path prepends matter).
  • Can be configured globally or per address family
  • Globally: route is discarded if the local device’s AS detection number in the path one is grater or equal than the configured value
  • Per address family: route is discarded if the local device’s AS detection number in the path one is grater than the configured value
  • Configuring local-as has a big influence on the as-path filter.
  • By default the routes whose AS path is looped are discarded (in the lab we have the keep all feature).

Note: enabling the AS as-override feature may result in routing loops. Use this feature only for specific applications that require this type of behavior, and in situations with strict network control.


External Resources: