Monday, March 18, 2013

BGP - inject-map - Conditional Route Injection

In my recently published posts we discussed how to aggregate addresses in BGP and the various optional parameters associated with the "aggregate-address" command. However, there could be instances where we may want to do just the opposite -- un-aggregate the addresses. In this blogtorial we will see how we can achieve this. Consider a very simple topology below and we'll dive right in.


Objective: 
  • Un-aggregate 11.11.11.0/24 into 11.11.11.0/25 and 11.11.11.128/25 on R2 and advertise the /25s to R3.
First, let's get the interfaces and basic routing including BGP configured on all the routers. 

 !  
 hostname R1  
 !  
 interface FastEthernet1/0  
  description connected to r2  
  ip address 1.1.1.1 255.255.255.0  
  duplex auto  
  speed auto  
 !  
 router bgp 1  
  no synchronization  
  bgp log-neighbor-changes  
  network 11.11.11.0 mask 255.255.255.0  
  neighbor 1.1.1.2 remote-as 2  
  no auto-summary  
 !  
 ip route 11.11.11.0 255.255.255.0 Null0  
 !  

 !  
 hostname R2  
 !  
 interface FastEthernet1/0  
  description connected to r1  
  ip address 1.1.1.2 255.255.255.0  
  duplex auto  
  speed auto  
 !  
 interface FastEthernet1/1  
  description connected to r3  
  ip address 2.2.2.2 255.255.255.0  
  duplex auto  
  speed auto  
 !  
 router bgp 2  
  no synchronization  
  bgp log-neighbor-changes  
  bgp soft-reconfig-backup  
  neighbor 1.1.1.1 remote-as 1  
  neighbor 2.2.2.3 remote-as 3  
  no auto-summary  
 !  

 !  
 hostname R3  
 !  
 interface FastEthernet1/1  
  description connected to r2  
  ip address 2.2.2.3 255.255.255.0  
  duplex auto  
  speed auto  
 !  
 router bgp 3  
  no synchronization  
  bgp log-neighbor-changes  
  bgp soft-reconfig-backup  
  neighbor 2.2.2.2 remote-as 2  
  no auto-summary  
 !  

At this point we have basic connectivity and BGP configured. R3 should be receiving 11.11.11.0/24 as expected. Now let's move onto configuring the magic on R2 -- BGP Conditional Route Injection using inject-map.

First we need to create a prefix-list to match the "IF" condition. In our case it is "If 11.11.11.0/24 is learned from 1.1.1.1 (R1)".

 !  
 hostname R2  
 !  
 ip prefix-list aggregated-routes description the aggregated route which needs to be in the bgp table in order for the bgp to inject the un-aggregated routes  
 ip prefix-list aggregated-routes seq 10 permit 11.11.11.0/24  
 !  
 ip prefix-list learned-from description the /32 of the neighbor who is advertising the original route  
 ip prefix-list learned-from seq 10 permit 1.1.1.1/32  
 !  

Next thing we need to do is create a prefix-list to match what we want injected (In this case, 11.11.11.0/25 and 11.11.11.128/25) into BGP "IF" the condition above is true.

 !  
 hostname R2  
 !  
 ip prefix-list unaggregate-routes description Routes to be injected   
 ip prefix-list unaggregate-routes seq 10 permit 11.11.11.0/25  
 ip prefix-list unaggregate-routes seq 20 permit 11.11.11.128/25  

Now we need to create route-maps to associate these prefix-lists so we can use them with the BGP inject-map command. Side note - route-source has to match a /32.

 route-map originate-unagg-routes permit 10  
  set ip address prefix-list unaggregate-routes  
 !  
 route-map learned-from permit 10  
  match ip address prefix-list aggregated-routes  
  match ip route-source prefix-list learned-from  
 !  

Alright now let's get route-maps associated with the BGP inject-map. "inject-map" basically states "IF" a given condition is true then inject certain routes into the BGP table.

 router bgp 2  
  bgp inject-map originate-unagg-routes exist-map learned-from  
  !! adding the prefix-list to R3 neighbor because I only want to adverise the specific routes.   
  neighbor 2.2.2.3 prefix-list unaggregate-routes out  

Let's do a few show commands to verify. R2 now has the injected routes specified by the route-map into BGP.

 R2#show ip bgp  
 BGP table version is 4, local router ID is 2.2.2.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  
 *> 11.11.11.0/25  1.1.1.1                   0     ?  
 *> 11.11.11.0/24  1.1.1.1         0         0     1 i  
 *> 11.11.11.128/25 1.1.1.1                  0     ?  

R2 is now advertising just the specifics to R3.

 R2#show ip bgp nei 2.2.2.3 advertised-routes  
 BGP table version is 4, local router ID is 2.2.2.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  
 *> 11.11.11.0/25  1.1.1.1                     0  ?  
 *> 11.11.11.128/25 1.1.1.1                    0  ?  
 Total number of prefixes 2  

Just to verify it on the R3 to make sure.
 R3#show ip bgp  
 BGP table version is 7, local router ID is 2.2.2.3  
 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  
 *> 11.11.11.0/25  2.2.2.2                    0     2 ?  
 *> 11.11.11.128/25 2.2.2.2                   0     2 ?  

IF 11.11.11.0/24 is received by R2 from R1 then R2 should inject 11.11.11.0/25 and 11.11.11.128/25 into BGP and advertise these 2 /25s to R3 -- Successfully completed.

Have you used this before? Where would you use this feature?

Many more articles to come so stay tuned.

Please reshare/subscribe/comment/+1 if you like my posts as it keeps me motivated to write more and spread the knowledge.