Showing posts with label BGP. Show all posts
Showing posts with label BGP. Show all posts

July 17, 2011

BGP Conditional Advertisement

If you ever took a programming course or have done any development, you probably have heard of an “If/Then” statement.  An "If/Then" statement is one that says if a condition exists, then take a specific action.  BGP conditional advertising uses a similar logic, but uses something called advertise maps and non-exist or exist maps.  In this example, I will use the advertise map and non-exist map.

Diagram1-1


In this example, we have R4 multi-homed with two different ISPs.  The company has a few public addresses to advertise to the internet to ensure reachability.  The subnets include the following:
  • 77.10.12.0/24
  • 77.14.16.0/24
  • 78.55.97.0/24


The company BGP policy states that subnet 77.10.12.0/24 & 78.55.97.0 should be advertised to both service providers.  The policy also states that traffic entering the AS for subnet 77.14.16.0/24 must use the link between R2 & R4.  If the link between R2 & R4 should fail, traffic for subnet 77.14.16.0/24 should use the link between R3& R4 to ensure reachability.

While we could use AS path prepending to hint to the upstream providers how traffic should enter the AS.  This doesn't mean all traffic will use only one path if AS path prepending is used.  One way to ensure all traffic for subnet 77.14.16.0/24 uses a specific link, is to only advertise the subnet to the ISP where the traffic is expected.  With the requirements that are given, BGP conditional advertising can be used to meet those requirements.

The way in which to approach this is by using a non-exist-map to check for the existence of a default route from R2. (That's the “If”part) If the default route from R2 is removed from the BGP table, the non-exist-map will match and R4 will begin to advertise the 77.14.16.0/24 network to R3 with the advertise-map. (That's the“Then” part)

If the default route from R2 is installed into the BGP table, the non-exist-map will not match and the route being advertised to R3 will be withdrawn.

Here are the intermediate configurations of R2, R3 and R4

R2

interface Loopback77
 ip address 7.7.7.7 255.255.255.255
!
!
router bgp 200
 no synchronization
 bgp router-id 2.2.2.2
 bgp log-neighbor-changes
 network 7.7.7.7 mask 255.255.255.255
 neighbor 10.10.12.1 remote-as 100
 neighbor 10.10.24.4 remote-as 400
 neighbor 10.10.24.4 default-originate
 no auto-summary

R3

router bgp 300
 no synchronization
 bgp router-id 3.3.3.3
 bgp log-neighbor-changes
 neighbor 10.10.13.1 remote-as 100
 neighbor 10.10.34.4 remote-as 400
 neighbor 10.10.34.4 default-originate
 no auto-summary

R4

interface Loopback1
 ip address 77.10.12.1 255.255.255.0
!
interfaceLoopback2
 ip address 77.14.16.1 255.255.255.0
!
interfaceLoopback3
 ip address 78.55.97.1 255.255.255.0
!
!
router bgp 400
 no synchronization
 bgp router-id 4.4.4.4
 bgp log-neighbor-changes
 network 77.10.12.0 mask 255.255.255.0
 network 77.14.16.0 mask 255.255.255.0
 network 78.55.97.0 mask 255.255.255.0
 neighbor 10.10.24.2 remote-as 200
 neighbor 10.10.24.2 distribute-list 5 in
 neighbor 10.10.24.2 distribute-list 10 out
 neighbor 10.10.34.3 remote-as 300
 neighbor 10.10.34.3 distribute-list 5 in
 neighbor 10.10.34.3 distribute-list 10 out
 neighbor 10.10.34.3 advertise-map ADVERTISE non-exist-map NON-EXIST
 no auto-summary
!
!
access-list 5 permit 0.0.0.0
access-list 10 permit 77.10.12.0 0.0.0.255
access-list 10 permit 77.14.16.0 0.0.0.255
access-list 10 permit 78.55.97.0 0.0.0.255
access-list 30 permit 0.0.0.0
access-list 40 permit 77.14.16.0 0.0.0.255
!
!
!
route-map NON-EXIST permit 10
 match ip address 30
!
route-map ADVERTISE permit 40
 match ip address 40

There is a problem with the above configuration.  With this configuration, the NON-EXIST portion of the BGP conditional advertisement will never match.  The reason is that it's only checking for the existence of a default route.  R4 is receiving a default route from both R2 &R3.  The NON-EXIST portion would never match because there will always be a default route in the routing table.  The engineer needs a way to identify which default route to look for.  With BGP conditional advertising, the engineer can create an as-path access-list to identify which AS the default route should be coming from.  The additional configuration would be:

Ip as-path access-list 10 permit ^200$
!
!
route-map NON-EXIST permit 10
 match ip address 30
 match as-path 10

**Note**  The configuration is applied using the neighbor advertise-map non-exist-map configuration command.

Now, if the link between R2 & R4 fails, the non-exist-map will match because both conditions have matched.  The default route has been removed and it was sourced from AS 200.

We can verify that the configuration is working as expected by viewing the routes we are advertising to R3.  R4 should not be advertising the 77.14.16.0/24 network because R4 is receiving a default route from R2.

R4#show ip bgp neighbor 10.10.34.3 advertised-routes  | b O
Origin codes: i - IGP, e - EGP, ? - incomplete

Network            Next Hop      Metric  LocPrf  Weight  Path
*>77.10.12.0/24    0.0.0.0            0           32768  i
*>78.55.97.0/24    0.0.0.0            0           32768  i

To test this, a continuous ping will be started to 77.14.16.1 from R1.  The link between R2 & R4 will be shut down to simulate a link failure.  Because BGP is timer driven, and there has been no changes to the default timers, it will take BGP 3 minutes or longer to converge.  The timers can be adjusted in a lab environment to get the results faster, but in this example the timers will be left at their defaults so the reader can get an understanding of how long it takes BGP to converge after a link failure using BGP conditional advertising.

Once the link between R2 & R4 is shut down a console message on R4 appears.

*Mar  1 01:33:29.675: BGP(0): 10.10.34.3 rcv UPDATE about 77.14.16.0/24 – withdrawn

Note the time that the interface failed in the console message.  This is when BGP sent an UPDATE message to withdraw routes.  Now let's take a look at the debug output when the non-exist-map get a match.

*Mar  1 01:36:25.859: BPG(0): Condition NON-EXIST changes to Advertise
*Mar  1 01:36:25.863: BPG(0): Condition NON-EXIST changes to Advertise
*Mar  1 01:36:25.867: BGP(0): net 77.14.16.0/24 matches ADV MAP ADVERTISE: bump version to 11
*Mar  1 01:36:26.651: BGP(0): 10.10.34.3 77.14.16.0/24 matches advertise map ADVERTISE, state: Advertise
*Mar  1 01:36:55.935: BGP(0): 10.10.34.3 send UPDATE (format) 77.14.16.0/24, next 10.10.34.4, metric 0, path Local

Looking at the time stamps, we can see it took 3 min (180 seconds) for BGP to converge.  The default hold timer for BGP is 180 seconds.

Now let's take a look at R1 where the pings were running.

Type escape sequence to abort.
Sending 10000, 100-byte ICMP Echos to 77.14.16.1, timeout is 2 seconds:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!U....................................
......................................................!!!!!!!!!!!!!!!!

To verify that the conditional advertising is working, we can look at the routes we are sending to R3.  We should now see that R4 is advertising the 77.14.16.0/24 network to R3.

R4#show ip bgp neighbor 10.10.34.3 advertised-routes  | b O
Origin codes: i - IGP, e - EGP, ? - incomplete

Network            Next Hop      Metric  LocPrf  Weight  Path
*> 77.10.12.0/24   0.0.0.0            0           32768 i
*> 77.14.16.0/24   0.0.0.0            0           32768 i
*> 78.55.97.0/24   0.0.0.0            0           32768 i

Now let's bring the link between R2 & R4 back up and examine the debug output on R4.

*Mar  1 01:56:32.463: BPG(0): Condition NON-EXIST changes to Withdraw
*Mar  1 01:56:32.463: BPG(0): Condition NON-EXIST changes to Withdraw
*Mar  1 01:56:32.463: BGP(0): net 77.14.16.0/24 matches ADV MAP ADVERTISE: bump version to 8
*Mar  1 01:56:32.679: BGP(0): 10.10.24.2 skip UPDATE 77.14.16.0/24(chgflags: 0x0), next 0.0.0.0, path *Mar  1 01:56:32.679: BGP(0): 10.10.34.3 77.14.16.0/24 matches advertise map ADVERTISE, state: Withdraw

You can see that once the link is brought back online the NON-EXIST condition does not match and the state changes from advertise to withdraw.

In conclusion, this document outlined the basic function and operation of BGP conditional advertisement.  For more information, please refer to the documentation at Cisco.com.

July 15, 2011

BGP Summarization Part 1

BGP Summarization Part 1
Erick N. Borgard CCNP

This blog post will focus on the first part of BGP summarization.  BGP administrators use summarization reduce the the size of the internet routing table, thereby conserving resources.  I think at this time, the BGP table is at 350,000 routes.  Can you imagine what it would be like if engineers didn't use any form of summarization?  Summarization also indirectly hides potential problems in thenetwork.  If a router were summarizing 100.100.10.0 – 100.100.50.0, any potential problems with the 100.100.20.0 network would stop at the aggregating router since it's only telling it's neighbor about a summary of more specific addresses.

Before moving into the first part of summarization, it's important to get one of the critical foundational topics mastered.  We are going to look at the use of the network command in BGP.  The network command in BGP is not used the same way the network command works with a traditional IGP such as EIGRP & OSPF.  To get a Cisco router to advertise a network into BGP, the statement must match the prefix and prefix length as it is in the IP routing table exactly.  If it doesn't then the router will not tell it's neighbor about the route. Let's take a look at an example.

Diagram 1-1


In this example, I have configured a loopback and a few secondary addresses associated with the loopback.

R1#show ip route | beg Gate
Gateway of last resort is not set

    10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks
C      10.10.10.0/24 is directly connected, Loopback1
C      10.10.20.0/24 is directly connected, Loopback1
C      10.10.30.0/24 is directly connected, Loopback1
C      10.10.40.0/24 is directly connected, Loopback1
C      10.10.50.0/24 is directly connected, Loopback1


For this example, let's advertise 10.10.30.0/24 to R2.  First we will advertise it with the default subnet mask of 255.0.0.0.  Remember that 10.x.x.x is a class A network by default.  If we advertise the network into BGP with no mask configured, it will default to be 255.0.0.0 in this example.  We will see that the route will not be advertised to R2 because the prefix and prefix length must match the routing table exactly.  We will use the following syntax.

Configure terminal
!
!
router bgp 100 
network 10.10.30.0
!
end

R2#show ip bgp

R2#

Nothing. Notice that there is no output on the CLI.  We are not receiving the route because the default prefix length of /8 does not match what's in the routing table, a /24.  Let's change the configuration so we have the mask exactly like it is in the routing table.

Configure terminal
!
!
router bgp 100 
network 10.10.30.0 mask 255.255.255.0
!
end

Notice in the second configuration, we added the mask.  Now let's check to see if R2 is receiving the BGP route.

R2#show ip bgp
BGPtable 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
*>10.10.30.0/24  10.1.1.1                  0               0 100i

Now that we got the prefix length to match the route in the routing table, R1 will advertise the 10.10.30.0/24 network to R2.  This is an important concept to keep in mind while discussing the first part of BGP summarization.

There are two schools of thought when it comes to BGP summarization. One school uses the “static route” method and either use the network command to advertise the route or redistribute it into BGP so the neighboring routers get the summary.  We will look at this method in part 1.

The other school of thought is to use the aggregate-address command.  The aggregate address command has more features tied to it, so this is the method employed by most engineers today.  There are some subtle difference in how things are configured, but in the end, the resultis the same.


Using the“Static Route” Method


This method uses the above concept to advertise a summary route to it's neighbors.  The concept is that the engineer will create a summary route and point it to the null0 interface.(the trash can or bitbucket)

The route to null0 will serve two purposes in this case.  The first purpose of the static route to null0 is to prevent any potential routing loops if all of the more specific routes were to lost in the routing table for any reason.  The second thing the null0 route doesis it serves as a point of reference for the router when we use the network command to advertise the summary.  What is the router going to do when we type a summary address with the network command?  Yep. The router is going to look in the routing table to make sure the prefix & prefix length match the route in the routing table.  In this case, it will use the static route we created.  If we go back and look at the routing table, we can summarize the following on R1 by calculating the summary with binary math.

    10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks
C      10.10.10.0/24 is directly connected, Loopback1
C      10.10.20.0/24 is directly connected, Loopback1
C      10.10.30.0/24 is directly connected, Loopback1
C      10.10.40.0/24 is directly connected, Loopback1
C      10.10.50.0/24 is directly connected, Loopback1


Write the prefixes out in binary and summarize the most significant bits from left to right.

00001010.00001010.00001010.00000000= 10.10.10.0
00001010.00001010.00101000.00000000= 10.10.20.0
00001010.00001010.00011110.00000000= 10.10.30.0
00001010.00001010.00101000.00000000= 10.10.40.0
00001010.00001010.00110010.00000000= 10.10.50.0

We can take those routes and summarize them to 10.10.0.0/18.  All of those addresses have the first 18 bits in common as outlined in bold numbers.  So now we know the summary address we can configure the static route and point it to the null0 interface.  The command to do this will be.
  • Ip route 10.10.0.0 255.255.192.0 null0
 To verify, we can now look at the IP routing table.


R1#show ip route | in Null
S      10.10.0.0/18 is directly connected, Null0

Now that we have met the requirement that the route must be in the routing table, we can match that and advertise it to R2.  We can do this by using the network command or with redistribution.  The engineer can also call a route-map from the network command so there is no need to use redistribution just to call a route-map. I will show both ways just to be sure it's understood how to accomplish this.

The first method is with redistribution.  Simply go to the BGP processand type redistribute static.

The results of the show ip bgp on R2 is as follows after the redistribution and the BGP process cleared.

R2#show ip bgp | beg Or
Origincodes: i - IGP, e - EGP, ? - incomplete

Network         Next Hop         Metric    LocPrf  Weight Path
*>10.10.0.0/18  10.1.1.1              0                 0 100 ?
*>10.10.30.0/24 10.1.1.1              0                 0 100 i

From that output, we can see R2 received the summary route with an origin of “incomplete”.  This means that this route was learned by some other external source other than the network command.  If the network command would have been used, the summary route would have and “i” next to it designating that it is an internal route as the10.10.30.0/24 prefix.

Now let's remove the redistribution statement and use the network command to get that summary to R2.  We will use the network 10.10.0.0 mask 255.255.192.0 command this time and verify with R2.

R2(config)#do sh ip bgp | beg Or
Origincodes: i - IGP, e - EGP, ? - incomplete

Network         Next Hop            Metric  LocPrf  Weight Path
*>10.10.0.0/18  10.1.1.1                 0               0 100 i
*>10.10.30.0/24 10.1.1.1                 0               0 100 i

Notice this time that the summary route now has an “i” for path meaning it is internal.  This is also the expected output for using the network command to send the summary route.

**Hint** While discussing this method, it's probably a good time to briefly mention the ways to advertise a default route with BGP.  After all, what is a default route if it isn't an “all-encompassing” summary route?  The engineer can create a static default route and point itto the null0 interface and then use redistribution or the network command to advertise a default route.

Here is the configuration.

Ip route 0.0.0.0 0.0.0.0 null0
!
router bgp 100
network 0.0.0.0


The other method to use is to advertise the default route on a per-neighbor basis.
  • Neighbor x.x.x.x default-originate
In part two of this series, I will take a look at BGP summarization with the aggregate-address command.

eBGP Peer Groups


eBGP Peer Groups

Erick N. Borgard CCNP


BGP peer groups is a topic that might make you scratch your head wondering how this all works. More importantly, you might be asking yourself; “How is this supposed to help save me some configuration steps?"  Maybe you were researching but still never understood BGP Peer Groups. This document is going to explain the concept behind BGP peer groups and demystify this concept once and for all.

Please take Diagram 1-1 into consideration. (Click to enlarge)


Before we get into the configuration, it's important to discuss the overall purpose of BGP peer groups.  So what are BGP peer groups?  BGP peer groups are groupings of BGP speaking routers that share the same policies and options.  Suppose we needed to peer with our loopback addresses instead of the directly connected interfaces.  The engineer would have to type neighbor x.x.x.x ebgp-mulithop x & neighborx.x.x.x update-source lox for every single peering.  In addition to that, the engineer would have to apply the ingress and egress BGP policy to each and every peering.   BGP peer groups allow the engineer to apply that policy only once.  Let's take Dallas for example.  In this example, you are only asked to create peering with 3 routers. Supposed you have 150 or maybe 300 peering you manage.  If all of those devices will share the same policy and options, you can create BGP peer groups and stick them in a peer group.  Maybe, you get something that states the following on an exam.  Create eBGP peers between R1, R2, R3, &R4. All routers share the same routing policy.  Use the minimum configuration possible.  Well, if you create each and every peering individually, you aren't using the minimal amount of lines of configuration because it was explicitly stated that all peerings share the same ingress and egress policy.

Here is Dallas' BGP and policy configuration.

router bgp 177
 no synchronization
 bgp log-neighbor-changes
 bgp scan-time 5
 network 1.1.1.1 mask 255.255.255.255
 network 11.1.11.1 mask 255.255.255.255
 network 11.11.11.11 mask 255.255.255.255
 network 111.11.11.11 mask 255.255.255.255
 neighbor EBGP_PEERS peer-group
 neighbor EBGP_PEERS ebgp-multihop 255
 neighbor EBGP_PEERS filter-list 200 in
 neighbor EBGP_PEERS filter-list 100 out
 neighbor 10.77.10.2 remote-as 110
 neighbor 10.77.10.2 peer-group EBGP_PEERS
 neighbor 10.77.20.2 remote-as 220
 neighbor 10.77.20.2 peer-group EBGP_PEERS
 neighbor 10.77.30.2 remote-as 330
 neighbor 10.77.30.2 peer-group EBGP_PEERS
 neighbor 155.1.12.2 remote-as 177
 neighbor 155.1.12.2 next-hop-self
 no auto-summary
!
!
ip as-path access-list 100 permit ^$
ip as-path access-list 200 permit ^110$
ip as-path access-list 200 permit ^220$
ip as-path access-list 200 permit ^330$

Now at this point, you might be asking yourself how is all that configuration is supposed to make our life easier? I know I had the very same question until I began to work with BGP peer groups.  All of that code sure doesn't look like it's making my life any easier.  Let's imagine that your initial set up is working great and life is good.  The cramping in your fingers is finally starting to subside from the initial configuration.

The company announces growth and expansion. (See Diagram 1-2) The engineer is tasked with creating two BGP peerings with Calgary and Hawaii.  They should get the same BGP policy that Seattle, Cape Town and London gets.  Here is where the magic happens. In order to form those two(2) peering, the engineer only needs 6 lines of code and only 4 of those 6 lines apply to the peering!  The engineer needs to add the neighbor remote-as command.  The engineer also needs to add the neighbor peer-group EBGP_PEERS command to associate the peering with the peer group.  That's it.  The only other change that needs to be made is to add the peering AS(s) to the as-path access list for each peering.  That's it. It's that simple once the initial configuration is in place.

Diagram 1-2 (Click to enlarge)

The additional configuration for the two peerings  would be:

Dallas

neighbor 10.77.40.2 remote-as 440
neighbor 10.77.40.2 peer-group EBGP_PEERS
neighbor 10.77.50.2 remote-as 550
neighbor 10.77.50.2 peer-group EBGP_PEERS
!
!
ip as-path access list 200 permit ^440$
ip as-path access-list 200 permit ^550$

That's really all there is to eBGP peer groups.  Suppose those 2 additional peerings were 15 additional and you had to apply the same filter-list and options to every peering.  All of those lines of code start to add up, creating an enormous amount of overhead.  Isn't it fantastic that the engineer has a great tool in his back pocket like BGP peer groups to help simplify the configuration and administration of large scale BGP operations?