Description

Default BGP communities sorting or selection criteria used by Juniper

Solution

By default, BGP communities are sorted in order: Normal-community < Extended-community < Large-community...

 

All community types are internally sorted using a comparison function.

 

The comparison follows a step-by-step approach to ensure consistent ordering. The lowest value is preferred over the highest:

 

            Communities are grouped based on their type (normal, extended, IPv6 extended, or large) to keep similar types together.



            For extended communities, the subtype is used to maintain consistent ordering within those groups.

  • First value is then compared.
    • For IPv6 extended communities, the IPv6 address is compared.
    • For all other community types, the AS number or address value is compared.
  • Second value is compared next.
    • The primary value of the community is used to further differentiate entries.
  • Third value is compared for large communities.

 

Communities that include IP addresses may also appear in a different order:

Big-endian* [which stores the most significant byte (the "big end") first ]

For instance - Big-endian sorting with respect to rt-import extended communities:

user@ASBR2_RE# run show route advertising-protocol bgp 10.2.2.2 extensive 10.1.11.1 | match communit 

   Communities: target:64514:64515 src-as:64514:0 src-as:64515:0 rt-import:172.16.20.0:8 rt-import:172.31.11.11:8 --> Starting from most significant bit, lowest value is 16 over 31 [as 1st octet is the same, i.e. 172, contention moves to 2nd octet], so rt-import:172.16.20.0:8 takes precedence over rt-import:172.31.11.11:8

 

Little-endian* [which stores the least significant byte (the "little end") first]:

For instance - Little-endian sorting with respect to rt-import extended communities:

user@ASBR2_RE# run show route advertising-protocol bgp 10.2.2.2 extensive 10.1.11.1 | match communit 

   Communities: target:64514:64515 src-as:64514:0 src-as:64515:0 rt-import:172.31.20.0:8 rt-import:172.31.11.11:8 --> Starting from least significant bit, lowest value is 0 over 11, so rt-import:172.31.20.0:8 takes precedence over rt-import:172.31.11.11:8

 

*Endianness refers to the order in which bytes are arranged in system memory. Big/little-endian sorting selection varies across platforms/vendors, but is consistent within the same model

 

Modification History

2026-04-09 : Article Created