The Local Preference attribute explained, and the ‘All or nothing’ way of configuring it and behaviors explained!

BGP_LocPrf_Top

So as can be seen, once again we’ve ditched the NBMA as this Topology of a shared Ethernet segment will better illustrate Local Preference explanation, behaviors, etc.

***For labbing example purposes I want to point out there is another link in the above Topology, R3-R4 is connected by the Fa0/1 link on the network 172.12.34.0 /24 to advertise the network, however I left it out of the Topology for clarity sake.***

However before we get labbing, we have some theory / fundamentals to go over:

  • Local Preference aka LOCAL_PREF aka LocPrf are different names it goes by
  • Local Preference is a well-known ‘discretionary’ attribute
  • Local Preference is NEVER advertised outside of its AS (to eBGP Speakers)
  • Local Preference is #2 on the Best Path 10 attribute list, outranked by Weight (Cisco Proprietary) at #1, both Local Pref and Weight are preferred by highest value
  • Local Preference passed only between local (iBGP) neighbors

Local Preference is like the exact opposite of MED, in the way that MED tells BGP Speakers outside the AS the Preferred Path into the AS, Local Preference tells the BGP Speakers inside the local as which exit Path to use.

So because of that, it runs between iBGP neighbors only, or is “locally significant only”  among Peers inside the AS – So its a new spin on the term “locally significant only” with BGP it can mean both the local router or the routers local to the local routers AS.

So to show what the configuration looks like for R3 and R4 with this hidden network:

R3(config-router)#neighbor 10.1.1.1 remote-as 12
R3(config-router)#neighbor 10.1.1.4 remote-as 34
R3(config-router)#network 172.12.34.0 mask 255.255.255.0

R4(config-router)#neighbor 10.1.1.3 remote-as 34
R4(config-router)#neighbor 10.1.1.2 remote-as 12
R4(config-router)#network 172.12.34.0 mask 255.255.255.0

So that being said, lets see how R1 and R2 are currently viewing the Path Selection in their AS 12:

R1#sh ip bgp
BGP table version is 2, local router ID is 10.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
              r RIB-failure, S Stale
Origin codes: i – IGP, e – EGP, ? – incomplete

   Network          Next Hop            Metric LocPrf Weight Path
* i172.12.34.0/24   10.1.1.4                 0          100                  0 34 i
*>                             10.1.1.3                 0                                   0 34 i
R1#
ASR#2
[Resuming connection 2 to r2 … ]

R2#sh ip bgp
BGP table version is 4, local router ID is 10.1.1.2
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
              r RIB-failure, S Stale
Origin codes: i – IGP, e – EGP, ? – incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 172.12.34.0/24   10.1.1.4                 0                                 0 34 i
* i                              10.1.1.3                 0          100                0 34 i
R2#

As can be seen, both router have a Preferred Path of the Next Hop to the network, which is the R1 – R3 and R2 – R4, as all other things should be equal. However it is also noted that we only see LocPrf values in one Path in each ip bgp table, does that mean the other is set to 0?

R2#sh ip bgp 172.12.34.0
BGP routing table entry for 172.12.34.0/24, version 4
Paths: (2 available, best #1, table Default-IP-Routing-Table)
  Advertised to update-groups:
     1
  34
    10.1.1.4 from 10.1.1.4 (10.1.1.4)
      Origin IGP, metric 0, localpref 100, valid, external, best
  34
    10.1.1.3 from 10.1.1.1 (10.1.1.1)
      Origin IGP, metric 0, localpref 100, valid, internal
R2#

Offfff course not, because its default is 100 for Local Preference, but it sometimes does not show up in the “sh ip bgp” table so don’t let that trip you up.

So there are a couple of ways to manipulate the Local Preference, one method changes the Local Preference for all routes being advertised by an iBGP Speaker (All or Nothing approach) which I will configure here first, within BGP router configuration mode:

R1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#router bgp 12
R1(config-router)#?
Router configuration commands:
  address-family       Enter Address Family command mode
  aggregate-address    Configure BGP aggregate entries
  auto-summary         Enable automatic network number summarization
  bgp                  BGP specific commands
  default              Set a command to its defaults
  default-information  Control distribution of default information
  default-metric       Set metric of redistributed routes
  distance             Define an administrative distance
  distribute-list      Filter networks in routing updates
  exit                 Exit from routing protocol configuration mode
  help                 Description of the interactive help system
  maximum-paths        Forward packets over multiple paths
  neighbor             Specify a neighbor router
  network              Specify a network to announce via BGP
  no                   Negate a command or set its defaults
  redistribute         Redistribute information from another routing protocol
  synchronization      Perform IGP synchronization
  table-map            Map external entry attributes into routing table
  template             Enter template command mode
  timers               Adjust routing timers

R1(config-router)#bgp ?
  always-compare-med      Allow comparing MED from different neighbors
  bestpath                Change the default bestpath selection
  client-to-client        Configure client to client route reflection
  cluster-id              Configure Route-Reflector Cluster-id (peers may
                          reset)
  confederation           AS confederation parameters
  dampening               Enable route-flap dampening
  default                 Configure BGP defaults
  deterministic-med       Pick the best-MED path among paths advertised from
                          the neighboring AS
  dmzlink-bw              Use DMZ Link Bandwidth as weight for BGP multipaths
  enforce-first-as        Enforce the first AS for EBGP routes(default)
  fast-external-fallover  Immediately reset session if a link to a directly
                          connected external peer goes down
  graceful-restart        Graceful restart capability parameters
  inject-map              Routemap which specifies prefixes to inject
  log-neighbor-changes    Log neighbor up/down and reset reason
  maxas-limit             Allow AS-PATH attribute from any neighbor imposing a
                          limit on number of ASes
  nexthop                 Nexthop tracking commands
  redistribute-internal   Allow redistribution of iBGP into IGPs (dangerous)
  regexp                  Select regular expression engine
  router-id               Override configured router identifier (peers will
                          reset)
  scan-time               Configure background scanner interval
  soft-reconfig-backup    Use soft-reconfiguration inbound only when
                          route-refresh is not negotiated
  suppress-inactive       Suppress routes that are not in the routing table
  update-delay            Set the max initial delay for sending update
  upgrade-cli             upgrade cli

R1(config-router)#bgp default ?
  ipv4-unicast      Activate ipv4-unicast for a peer by default
  local-preference  local preference (higher=more preferred)
  route-target      Control behavior based on Route-Target attributes

R1(config-router)#bgp default local-preference ?
  <0-4294967295>  Configure default local preference value

R1(config-router)#bgp default local-preference 200
R1(config-router)#^Z
R1#
*Mar 31 09:37:31.523: %SYS-5-CONFIG_I: Configured from console by console
R1#clear ip bgp * soft out
R1#

So keep in mind the higher the Local Preference (Like Weight) the more Preferred the Path, lets see how R2 now views its Paths to 172.12.34.0/24 :

R2#sh ip bgp 172.12.34.0
BGP routing table entry for 172.12.34.0/24, version 5
Paths: (2 available, best #2, table Default-IP-Routing-Table)
  Advertised to update-groups:
     2
  34
    10.1.1.4 from 10.1.1.4 (10.1.1.4)
      Origin IGP, metric 0, localpref 100, valid, external
  34
    10.1.1.3 from 10.1.1.1 (10.1.1.1)
      Origin IGP, metric 0, localpref 200, valid, internal, best
R2#

So it has changed it’s tune about where the Path is, lets look at R1 to see if it will send traffic over to R2 as well destined for the 172.12.34.0 network:

R1#sh ip bgp 172.12.34.0
BGP routing table entry for 172.12.34.0/24, version 3
Paths: (1 available, best #1, table Default-IP-Routing-Table)
  Advertised to update-groups:
     2
  34
    10.1.1.3 from 10.1.1.3 (10.1.1.3)
      Origin IGP, metric 0, localpref 200, valid, external, best

Now R1 does not even consider the Path back to 10.1.1.2, because that router is just going to send it right back, creating a routing loop of course. However, I did confirm they are still Peers despite not being in the ip bgp table for that route anymore:

R1#sh ip bgp summ
(Output redacted)

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.1.1.2        4    12     111     111        3    0    0 01:45:52        0
10.1.1.3        4    34      89      88        3    0    0 01:24:19        1

Now if this were a bigger network, or perhaps a ton of routes being advertised by R1, we probably wouldn’t want all of those routes / iBGP Speakers changing the Local Preference to 200

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s