BGP doesn't rely on any type of metric to determine if a path is looped, the metrics it does use are more policy-based—that is, they can be used by network administrators to set policies for routers to use when selecting a path.
BGP only advertises the best route to each of its neighbors unless BGP multipath is configured.
Listed in order of importance, these metrics are as follows:
- Locally originated routes
- Multiple Exit Discriminator (MED)
- Path through nearest neighbor if synchronization is on
- Path through neighbor with the lowest router ID
The sections that follow discuss some of these metrics individually.
Local Preference
A route map generally sets local preference when a destination network (prefix) is advertised or received from a BGP peer. The local preference is advertised with the prefix throughout the AS. The local preference is used to set a preferred exit point for this destination from this AS.
AS Path Length
The path with the shortest AS path length is preferred if all factors with more weight than path length are equal.
MED
The MED, or metric, is generally set using a route map when a prefix is advertised to a neighboring AS. The MED is not carried when a prefix is advertised from one AS to another. It is non-transitive.
The MED is considered to be a hint about which entry point into an AS the administrator would like traffic for that destination to use. It is generally checked only if the AS paths on two routes are equal in length and identical. In other words, the MEDs of two prefixes learned from different neighboring ASs are not considered. On a Cisco router, bgp always-compare-med will compare MEDs from different ASs. This is not the default.
Lowest Router ID
If all metrics previously listed are equal, BGP selects the path through the neighbor with the lowest router ID. This final metric can become an issue in places where an AS has two connections to another AS.
Community Strings
A community string is a string of numbers (its not a characters) that can be used to tag a prefix. This tag can then be used for things like:
- Entry point control— Because the MED, in many cases, isn't used in path determination (because the AS path of two routes must be the same for the MED to be compared), there is a system where a router receiving a prefix with a given community string set will set its local preference.
- Propagating Quality of Service (QoS) information— An arrangement could be made between two BGP peers so that tagging a prefix with a given community string results in the packets destined to that subnet being treated differently.