Thursday 28 February 2019

BGP Series 15: BGP Attributes: Weight and Local Preference

BGP Attributes: Weight and Local Preference:

.

  • Usually if we want to modify some attributes for best path selection, we will mosify one of these: WEIGHT, LOC_PREF, AS_PATH

  • Influencing BGP Weight:

    • It is not actually an attribute since it is not part of a bgp packet

    • It was previously Cisco proprietary (now used by others like Arista as well) and configured locally on a router

    • It is locally significant to the router and is not advertised to any other BGP neighbor as part of BGP Update

    • It can be used to influence the choice of outbound routes

    • It is set on inbound routes (.ie. for updates coming into the router, a weight is set)

    • Larger weight is preferred

    • Weight value ranged from 0 to 65525 (2^16 - 1)

    • By default, weight is zero (0) for learned routes and 32768 for locally injected routes (if we are the originator of a route, either via network command or redistribution, we will mark that route with a weight of 32768). This is because we have to prefer our direct route which I have via my IGP than someone else’s iBGP Update and then going to that device and then choosing the IGP from them.

    • These default routes cannot be modified

    • Example:

      • Say we have two neighbors 1.1.1.1 and 2.2.2.2. If same route is received from both of them, prefer 1.1.1.1.
      • Also, if I don’t care about the neighbors below me choosing any route...just for me, I need to prefer 1.1.1.1, we can use BGP Weights….anyways if I choose a best path, bgp will only advertise the best-path to the neighbor, but, still the neighbor may get the other route as well from maybe another peer...we are not concerned what route it chooses then
      • Also, I don’t want to do any filtering since I need routes from both of them.
      • To do this, we should first match on network-X (can match based on any way- prefix-list, access-list, as-path access-list, ...any way) (OR) if we need to prefer 1.1.1.1 for all routes (here), match all routes
      • Then, create a route-map and within the route-map, match net-X and then set the weight to something higher than zero
      • Then, finally apply the route-map against neighbor 1.1.1.1
      • img
    • Weight is locally significant and not advertised to bgp neighbors.

      • Example:
      • img
    • If we need to influence even my neighbor, we can’t use bgp weights since it is locally significant, we need to use local preference

    • To change weight values, we can use the following commands:

      • ‘Neighbor route-map’ for matching a prefix and changing weight (used for particular prefixes Weight). Within the route-map, the ‘set-weight’ command is used
      • ‘Neighbor weight’ (used for changing Weight for all routes learnt from this neighbor)
    • The direction of the route-map applied to change the weight will always be inbound (it doesn’t even make sense to set weight of a outbound route since we can’t send it to anybody)

       

  • Setting BGP Local Preference:

    • It is an bgp attribute and can be present inside a bgp update. By default, it is not there, but can be put.

    • Example:

      • In below scenario, if I get same route from 1.1.1.1 and 2.2.2.2, then I need to prefer 1.1.1.1 and also influence my neighbors to choose 1.1.1.1
      • Here, we could not use weights since they are only locally significant….Here, we need to use LOC_PREF
      • LOC_PREF has default value of 100, so we need to set a value greater than 100 for routes from 1.1.1.1 on router-A
      • img
    • Also, LOCAL_PREF are valid only within an AS. So, when routers B and C send an eBGP update to 3.3.3.3, they will strip out the LOCAL_PREF value and then send the update.

    • So, LOCAL_PREF can be used to influence route-selection only within an AS since this attribute is only advertised to iBGP peers but is not advertised to eBGP peers

    • Higher value of LOCAL_PREF is preferred

    • The value ranges from 0 to (2^32 - 1)

    • By default value is 100

    • In LOCAL_PREF, unlike for Weights, we can set the default local preference to some other number other than 100 using 'bgp default local-preference <0-(2^32 - 1)>’

    • LOCAL_PREF is used along with a route-map (can be either in or out depending on whether we want to influence even ourselves or only our neighbors) and the command in route-map is ‘set local-preference’ clause

    • EXAMPLE:

      • We can see that if we receive a route from eBGP neighbor (which won’t be having any local preference), we automatically add the default local-preference value to it...here, 100 and then add it to our bgp table
      • After matching a prefix and setting local-pref to 101 and then adding another route-map permit statement to stop implicit deny, we see that the other path is now preferred.

 

No comments:

Post a Comment