Wednesday 6 March 2019

BGP Series 16: BGP Attributes: AS_PATH and MED

BGP Attributes: AS_PATH and MED:

.

  • AS_PATH Attribute:

    • It is a BGP attribute

    • Shortest length of AS_PATH is preferred when weight and local preference is same

    • It can be used to influence both inbound and outbound traffic

    • With AS_PATH prepending, we can make the AS_PATH longer for a path that is less preferred. Ideally, the local AS is prepended

    • Example:

      • In below example, we own AS-1 and both our routers ‘a’ and ‘b’ are advertising net-X to downstream neighbor...But, we want the downstream neighbor to choose ‘b’ .

      • Since I can’t change Weight in router ‘c’ which is not owned by me and I cant use local-pref since it is in a different AS

      • So, we can do this….we can insert some fake AS in the beginning (we can’t insert in middle or at end) to make router b’s path look more preferable

      • When we are doing this, it is very recommended to prepend with our own AS

      • img

      • There is no limitation or check that limits us from prepending any random AS instead of our own….but, if we do that, like below:

        • img
        • Then, when the bgp update reaches the actual AS3, it will see its own AS in the AS_PATH, it will think there is a loop and drop the update.
        • So, that’s why we should only put our own AS in for AS_PATH prepending
    • AS_PATH prepening is a ‘set’ option in route-map and configured as ‘set as-path prepend’

    • This route-map can be applied to a neighbor using command ‘neighbor route-map [in/out]’

    • The following commands are useful for verifying changes made to AS_PATH PA (path-attribute):

      • Show ip bgp
      • Show ip bgp prefix/prefix-length
    • EXAMPLE:

      • Now, we have 2 route to 15.15.0.0/24 n/w and they are both identical

      • img

      • The only reason why top one is selected as best_path is because it came from external neighbor (can be seen using show ip bgp prefix/length)...If we use AS_PATH, it will take effect since AS_PATH has higher priority

      • Now, if we go to router 13.13.13.13,

        • Now, we first need to match 15.15.0.0/24 n/w on the R13. We can do it using ACL
        • img
        • Then, we can create a route-map and match it to the ACL
        • After matching, we can set it to prepend 13 13 13 13 to current AS_PATH
        • Then, we can add another sequence to the same route-map to match everything else and do nothing on match.
        • img
        • Then, go to the router bgp and apply this route-map under the neighbor as ‘out’ and reset/resend bgp updates using ‘clear ip bgp * out’
      • Now, if we check on the neighbor for that route, the internal route is preferred due to smaller AS_PATH

        • img
  • MED Attribute:

    • Multi-Exit Discriminator

    • Also called as BGP Metric

    • It is bgp non-transitive optional attribute

    • In the previous example, we saw an example of influencing neighbors not in my AS...AS_PATH prepending is one way that is commonly used. Another way is by using MED

    • It can be used to influence inbound traffic coming from the neighboring AS (.ie. if we want the neighbor to use one path for sending traffic (here: use path via router ‘b’ instead of ‘a’ → same reason as using AS_PATH prepending)

    • img(same as previous example)

    • It is not advertised beyond the neighboring AS ----> This is the reason MED is considered a non-transitive Optional attribute

    • What the above means is MED is only one AS_PATH level deep which means I can send an eBGP update to you by setting a non-zero MED value. You can use that MED and also propagate it to your iBGP neighbors. But, when you send it to your eBGP neighbors, you should set it to zero.

    • So, in above example, if the link between routers ‘b’ and ‘c’ is down and we have to use the path between ‘a’ and ‘c’; then, unlike AS_PATH which will be sent as long prepended AS_PATH, when ‘d’ and ‘e’ send eBGP updates to ‘f’, the MED value will be zero.

    • It is called a ‘Multi-Exit Discriminator’ because just like the name says, a router (here: ‘b’) has multiple exists from its AS and we are trying to discriminate each of them

    • A smaller value is preferred...This is different from Weight or Local-pref, the lower the number, more preferred

    • The default value is ‘0’

    • The range of MED value is 0 to (2^32 - 1)

    • EXAMPLE:

      • img
      • In the above diagram, if we want router ‘c’ to prefer ‘b’ over ‘a’, then, I have to go to my non-preferable router (here: ‘a’) to make him look worse
      • Previously, we went to ‘a’ and did AS_PATH prepending...now we need to increment MED value on ‘a’
      • img
      • We can see that router ‘c’ will send the updates with MED=0 route to its iBGP neighbors. In case the route from ‘b’ had MED=1 and ‘a’ had MED=2, even then, ‘d’ and ‘e’ will send eBGP update to ‘f’ by setting MED=0 by default unless we have configured a route-map to change it.
    • The MED value can be set under route-map using ‘set metric’ command

    • It can then be applied to a neighbor using ‘neighbor route-map out’

    • The direction of route-map will always be only outbound, to influence inbound traffic on routers ‘a’ and ‘b’

    • Another important thing about MED is the MED value that is received is only relevant for that AS. EXAMPLE:

      • img
      • Now, router ‘c’ receives BGP updates from ‘a’, ‘b’ and ‘c’ with MED values of 2, 1 and 0 respectively
      • We might think that we have a clear winner (considering other attributes are same) since MED from router ‘c’ is lowest
      • But, wrong….MED is only locally relevant to the source AS and we cannot compare two MEDs from different AS
      • It is only used to compare same routes from same external AS
      • So, in this case, it knows that via ‘b’ from AS1 is better path than router ‘a’ from AS1...we cannot use MED to compare b/w AS1 and AS4, and we need to keep going below the list to find tie-breaker
      • But, if we WANT to compare MED of different AS, we could do that using ‘bgp always-compare-med’ under router bgp
      • img
      • After this, it will always compare MED irrespective of AS
    • EXAMPLE:

      • Let us take the same example of 15.15.0.0/24 that we used to change AS_PATH and let us remove AS_PATH prepending and try to use MED instead

      • On router 13.13.13.13,

        • Let us use the same ACL for matching and just change the set to MED instead of AS_PATH prepending in route-map
        • img
        • Then, let us apply this to neighbor and clear bgp
        • img
      • Now, if we go to R12,

        • img
        • We are still seeing the route with metric/MED 2 as best This is because the routes are from different AS and MED is not used for comparison
        • Thus, bgp is still going down the list and using eBGP vs iBGP route for comparison
        • Now, if we enable the always-compare-med in BGP,
        • img
        • We need to clear the bgp using ‘clear ip bgp * in’ and we will see that the best route changed
    • Another interesting thing about MED/Metric is unlike other bgp attributes like Weight, local-pref, AS_Path, etc…., we can see the MED value in the routing table

      • The other bgp attributes are only stored in bgp table and not carried to the routing table
      • But, MED is carried to the routing table and will be present alongside the administrative distance…(here: since the MED value is 2, we can see that...by default MED is 0 and in routing table it will be zero as well)
      • img
    • Useful commands to verify changes made to MED value:

      • Show ip bgp
      • Show ip bgp prefix/length

 

No comments:

Post a Comment