Официален блог на WebEKM EKM очаквайте сайта онлайн скоро.

Download Free Templates http://bigtheme.net/ free full Wordpress, Joomla, Mgento - premium themes.

BGP best path selection algorithm based on attributes

bgpaytributessmall-Each protocol has to calculate somehow the metric  in order to choose the best route. So we have the cost in OSPF, K-values in EIGRP, BGP doesn’t differ from them and also calculate the best route, but the metric of BGP is much more complicated.

BGP uses attributes to calculate the metric, attributes are processed in specific order
Also, BGP attributes are divided on : well-known attributes that are recognisable by all BGP routers : Origin, AS-Path, Next-Hop are mandatory ,Local Preference and Atomic Aggregate are discretionary (optional). We have also  optional: MED, Aggregator and Community, that are not recognisable by all vendors and may by ommited.
Let’s have a look on attributes that have influence  on choice of route..

is Cisco proprietary. Weight is significiant only locally is not being passed to the other iBGP routers within the same AS and to the eBGP as well. The higher value of the Weight is preffered. If we get the same prefix from 2 different eBGP routers we may choose the  prefered path that will be using to send packets to destination. Default value for a route is 0 and 32768 for routes injected locally. Weight attribute can’t be applied by default. We may apply Weight directly to the neighbor, then all routes will be prefered or with route maps with marked specified routes, then only this routes updates will be prefered from given eBGP peer.

access-list 10 permit
route-map WEIGHT permit 10
match ip address 10
set weight 200
route-map WEIGHT permit 20
set weight 0

neighbor route-map WEIGHT in


simmilar to Weight attribute, but the value will be relayed to the other iBGP routers in the same AS. Default value is 100. Local Preference can’t leave the AS and be passed to the other AS. The difference to compare to the Weight is that Weight we use within the single router that border with 2 eBGP peers, the Local Preference we use if we want to have influence on behaviour of all BGP routers within our AS. Local Preference may be applied be default:

bgp default local-preference 200

or on the eBGP router against the neighbor or specified route:

route-map LOCAL_PREF permit 10
set local-preference 300

neighbor route-map LOCAL_PREF in


access-list 10 permit
route-map LOCAL_PREF permit 10
match ip address 10
set local-preference 300



not too much to explain, BGP router always preferes routes locally originated. Localy originated means that the router is the one that generates the network (by network statement, redistribution or IGP ). Next hop in bgp table is In the routing table we see ‘i’ for internal iBGP originated routes and no letters for originated by eBGP.



We may choose which way external AS should get into our AS by MED attribute. But this attribute is not too much accurate. More accurate is AIGP that enables us to choose the path more precisely, cause it takes into consideration entire path with IGP metrics from both AS. Take a look at the picture. Take a look on R1. We have 2 paths to prefix that is being advertised by R2 in AS2. Administrator of AS 2 has set up enter to its AS via R20 because the lower IGP cost (10<20) as prefered and from his point of view everything is fine. 






Now let’s go over  AS 1. Form AS 1 administrator point of view it doesn’t look so good, cause IGP to R20 is 50.  Now, what if we would like to take into consideration also metric in AS1? As we see the IGP metric via R20 in AS1 is really poor. The better way would be utilization of the upper path via R10.




AIGP attribute will play its role if the single entity menages of a couple of Autonomous Systems and know very well entire topology. AIGP may be set to the IGP metric or the spicified value, also AIGP may be translated to MED if there are routers not capable to carry AIGP.

Default attribute used by best path algorithm, to determine the best path, the shortest lenght of the path is prefered. Depending on the choosen direction IN/OUT we manipulate the AS PATH value in our AS or the neighbor AS.

If we use OUT then we say to our neighbor what is the PATH to us, despite  the real path is different. In this way we have influence on what AS will be choosen by our neighbor as a next hop. Let’s consider below example. We run the route map on eBGP router in BGP 1 and send its OUT to the neighbor in BGP 2. In our neighbor bgp topology table will appear the AS PATH 1 4 32 23 56 12 to networks advertised by us inspite of the real AS PATH is 1.

on BGP1 eBGP router we configure:

route-map AS_PATH permit 10
set as-path prepend 4 34 23 56 12

neighbor route-map AS_PATH out


If we use IN, we state that, to the neighbor in BGP 2 AS Path is 9 17 29 11 8 2, of course that’s not true, the real AS Path is 2

on BGP1 eBGP router we configure:

route-map AS_PATH permit 10
set as-path prepend 9 17 29 11 8

neighbor route-map AS_PATH in


We may set up ignoring AS-PATH with command ‘bgp bestpath as-path ignore


routes may originate (be injected)  in 2 ways
by “network” command = “i” IGP
by “redistribution” = “?” incomplete
EGP “e” is not being used anymore
IGP > EGP > incomplete – the order of importance, IGP the most important

MED – Multi Exit Discriminator

also called Metric in bgp table, is an optional attribute. The lower value of the metric  (eBGP peer) is preferable. Let’s assume we border with AS 100 via 2 routers . We want to be sure that updates from AS100 will be going always via R2 router. Then we have to manipulate the MED against R100 on the interested routers. In other words by MED we say to the other AS which path should gets into our AS. MED is non-transitive and will never be passed outside our AS. We may change default metric with command ‘default-metric 500

route-map MED 10
set metric 300

neighbor route-map MED out
route-map MED 10
set metric 200

neighbor route-map MED out


There are two BGP configuration commands that can influence the multi-exit discriminator based path selection. The commands are the bgp deterministic-med (by default) command and the bgp always-compare-med . The bgp deterministic-med command ensures the comparison of the MED takes between routers that belong to the same AS. The bgp always-compare-med command ensures the comparison of the MED for eBGP peers in different ASs. The bgp always-compare-med command is useful when multiple service providers or enterprises agree on a uniform policy for how to set MED.  

On  below example peer in AS1 gets information about prefix with different metric (MED) from 2 routers from AS2 and one from AS3.  By default R1 will compare only the metric received from 2 routers from AS2. That’s mean if  AS-PATH attribute (and the others) to the are the same via AS2 and AS3, BGP compares the age of the path (as the next attribute), the oldest wins, So it may happen that even if we have lower MED from AS3 the path via AS2 will be choosen because is older. If we want to change it and take into consideration also the metric from R4, we have tu run command bgp always-compare-med on R1 in AS1. Then packets destined to will be send only via R4 in AS3.




PATHS – BGP always prefer external paths over internal paths eBGP>iBGP

MAXIMUM PATHS CHECK – be default BGP doesn’t provide any load balancing unlike OSPF, so if we have  the same paths but we didn’t set up  Maximum Paths Check for more than 1, then BGP will proceed to examination of  Age of Path and Router ID. If at this moment BGP process states we have 2 exact the same path and Maximum Paths Check has been set up to 2, then will use both routes and provide load balancing

AGE OF PATH – if there are 2 external paths, the path that was received first (older)  is prefered

ROUTER ID – the router with the lower ROUTER ID will be prefered



Onlain bookmaker bet365.com - the best bokie