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 loopsnumberset protocols bgp group group-name family address-family loopsnumber
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.
### An obvious one, only the local AS (or local AS domain) is checked for loops:
root@R1# show routing-options autonomous-system | display set
set routing-options autonomous-system 65535
### The loops feature is not configured on the box:
root@R1# show | display set | match loops
### There is an as-path loop, but it is ignored because it is not our own AS:
root@R1# run show route 192.168.50.0/26
inet.0: 25 destinations, 25 routes (25 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
192.168.50.0/26 *[BGP/170] 00:04:42, localpref 100
AS path: 64001 111 222 64001 64003 111 222 I, validation-state: unverified
> to 17.8.0.2 via ge-0/0/1.0
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.
root@R3# set protocols bgp group AS65003 local-as loops 3
[edit]
root@R3# show | compare
[edit protocols bgp group AS65003 local-as]
+ loops 3;
[edit]
root@R3# commit
[edit protocols bgp group AS65003]
'local-as'
Invalid loop count configured
error: configuration check-out failed
root@R3# set routing-options autonomous-system loops 5
[edit]
root@R3# commit
[edit protocols bgp group AS65003]
'local-as'
Invalid loop count configured
error: configuration check-out failed
[edit]
root@R3# set routing-options autonomous-system loops 3
[edit]
root@R3# commit
commit complete
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.
### Remove the loops from the address family and configure loops globally
root@R1# delete protocols bgp group AS650001 family inet
root@R1# set routing-options autonomous-system loops 6
[edit]
root@R1# show | compare
[edit routing-options autonomous-system]
+ loops 6;
[edit protocols bgp group AS650001]
- family inet {
- unicast {
- loops 6;
- }
- }
[edit]
root@R1# commit
commit complete
### Route is no longer there:
root@R1# run show route protocol bgp
inet.0: 25 destinations, 25 routes (24 active, 0 holddown, 1 hidden)
### Route is again hidden:
root@R1# run show route protocol bgp hidden
inet.0: 25 destinations, 25 routes (24 active, 0 holddown, 1 hidden)
+ = Active Route, - = Last Active, * = Both
192.168.50.0/26 [BGP ] 00:00:11
AS path: 64001 65535 65535 65535 64003 65535 65535 65535 I, validation-state: unverified
> to 17.8.0.2 via ge-0/0/1.0
### Increase the loops number:
root@R1# set routing-options autonomous-system loops 7
[edit]
root@R1# show | compare
[edit routing-options autonomous-system]
- loops 6;
+ loops 7;
[edit]
root@R1# commit
commit complete
### Route is no longer hidden:
root@R1# run show route protocol bgp
inet.0: 25 destinations, 25 routes (25 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
192.168.50.0/26 *[BGP/170] 00:00:03, localpref 100
AS path: 64001 65535 65535 65535 64003 65535 65535 65535 I, validation-state: unverified
> to 17.8.0.2 via ge-0/0/1.0
Another important point:
- When
loops 1configured 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 1configured 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: