Sunday, 27 March 2011

MPLS-based VPNs

When I was learning about MPLS, I was a little bit confused about the fact, how BGP distributes vpn labels and how there are used. 

On the picture (click to enlarge) we can see, that customer bank has 2 sites connected to an ISP, who is running BGP in AS 60 and provides an MPLS-based VPNs. The ISP has divided its AS into two sub-AS. Although I am using in my example confederations, in fact the same concept is behind an inter-provider MPLS-based VPNs. In addition to this, I am using a simple formula, that router Rn can distribute labels from range n00 to n99 (R3 sends labels with values between 300-399 and so on).

1) In the first scenario, I will merge OSPF1 and OSPF2 (assuming that the ISP is running only single IGP within the whole AS) and establish a single BGP session between R3 and R6. Next I will send ping from R3 to R2 (154.0.0.1).
In this case, R6 is responsible for assigning a vpn label for the 154.0.0.0/24 network and sending this label via MP-BGP to R3:

R6#show mpls forwarding-table
Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop
tag    tag or VC   or Tunnel Id      switched   interface

                                                 
!Some lines omitted
609    706         12.0.0.0/30       0          Se0/0      point2point
610    707         11.0.0.0/30       0          Se0/0      point2point
611    Untagged    154.0.0.0/24[V]   0          Se0/1      point2point



We can see, that R6 has chosen label with value of 611 for this network. Next via MP-BGP this label was advertised to R3:

R3#show ip bgp vpnv4 all 154.0.0.0
BGP routing table entry for 1:1:154.0.0.0/24, version 17

                                            
! Some lines omitted
    6.6.6.6 (metric 321) from 6.6.6.6 (6.6.6.6)
      Origin incomplete, metric 1, localpref 100, valid, external, best
      Extended Community: RT:1:1
      mpls labels in/out nolabel/611


To see the whole stack of labels, which R3 will use to forward packets to 154.0.0.0/24, we can use:

R3#show ip cef vrf bank 154.0.0.0
154.0.0.0/24, version 14, epoch 0, cached adjacency to Serial0/1
0 packets, 0 bytes
  tag information set
    local tag: VPN-route-head
    fast tag rewrite with Se0/1, point2point, tags imposed: {405 611}
  via 6.6.6.6, 0 dependencies, recursive
    next hop 11.0.0.2, Serial0/1 via 6.6.6.6/32
    valid cached adjacency
    tag rewrite with Se0/1, point2point, tags imposed: {405 611}


And finally, the traceroute:

R3#traceroute vrf bank 154.0.0.1

Type escape sequence to abort.
Tracing the route to 154.0.0.1

  1 11.0.0.2 [MPLS: Labels 405/611 Exp 0] 140 msec 80 msec 100 msec
  2 12.0.0.2 [MPLS: Labels 509/611 Exp 0] 116 msec 180 msec 84 msec
  3 13.0.0.2 [MPLS: Labels 801/611 Exp 0] 76 msec 112 msec 228 msec
  4 14.0.0.1 [MPLS: Labels 701/611 Exp 0] 64 msec 148 msec 196 msec
  5 16.0.0.2 [MPLS: Label 611 Exp 0] 64 msec 136 msec 36 msec
  6 16.0.0.1 192 msec 232 msec *


In this scenario, we can see, that the vpn label is assigned by R6 (611) and is unchanged when packet traverses in the LSP. However the top label is swapped on every single router within the LSP. Next R7 pops the top label and sends the packet with only one label (only the vpn label: 611) to R6. Finally R6 exactly knows what to do with packets destined to 154.0.0.1.

2) In this scenario I assume, that each sub-AS is running a separate IGP (OSPF1 & OSPF2). In contrast to the 1st scenario, I establish three BGP sessions: R3-R5, R5-R8 and R8-R6. Moreover R5 and R8 are configured with next-hop-self, when sending updates to R3 and R6, respectively:

 R3#traceroute vrf bank 154.0.0.1

Type escape sequence to abort.
Tracing the route to 154.0.0.1

  1 11.0.0.2 [MPLS: Labels 400/504 Exp 0] 284 msec 144 msec 100 msec
  2 13.0.0.1 [MPLS: Label 504 Exp 0] 216 msec 168 msec 268 msec
  3 14.0.0.2 [MPLS: Label 805 Exp 0] 116 msec 212 msec 112 msec
  4 14.0.0.1 [MPLS: Labels 701/611 Exp 0] 84 msec 244 msec 244 msec
  5 16.0.0.2 [MPLS: Label 611 Exp 0] 208 msec 140 msec 140 msec
  6 16.0.0.1 144 msec 148 msec *

Here we see three different vpn labels: 504, 805 and 611. Both R5 and R8 are swapping vpn labels:

R8#show ip bgp vpnv4 all 154.0.0.1
BGP routing table entry for 1:1:154.0.0.0/24, version 17
Paths: (1 available, best #1, table bank)
  Advertised to update-groups:
        2
  Local
    6.6.6.6 (metric 129) from 6.6.6.6 (6.6.6.6)
      Origin incomplete, metric 1, localpref 100, valid, internal, best
      Extended Community: RT:1:1
      mpls labels in/out 805/611


This behaviour is due to the fact, that routers in AS 65000 have no idea about routes in AS65001. The connectivity between them is provided only by the BGP session between R5 and R8. So when R3 is sending packets to R2:

  • R3 imposes two labels: 504 as a vpn label assigned by R5, and 400 label assigned by R4 as a label to reach R5 
  • R4 only pops the top label (PHP) and send the packet with vpn label only, (504)
  • R5 pops its vpn label (504) and sends packet to R8 with the new vpn label (805)
  • R8 does the same thing as R5, (swaps the vpn label). R8 also pushes a new label (701) as a label to reach R6
  • R7 pops the top label (PHP) and sends the packet with vpn label only, (611)
  • Finally R6 receives packet with its own vpn label, so R6 pops all labels and sends the unlabelled packet to R2
 3)  Basically this scenario is very similar to the 2nd one, however this time routers R5 and R8 are configured without next-hop-self option, and the network between them (13.0.0.0/30) are redistributed into both OSPF1 and OSPF2 processes. This means, that R3 can ping R8, and R6 can ping R5:

R3#traceroute vrf bank 154.0.0.1

Type escape sequence to abort.
Tracing the route to 154.0.0.1

  1 11.0.0.2 [MPLS: Labels 403/805 Exp 0] 188 msec 272 msec 168 msec
  2 12.0.0.2 [MPLS: Labels 503/805 Exp 0] 160 msec 172 msec 80 msec
  3 14.0.0.2 [MPLS: Label 805 Exp 0] 124 msec 288 msec 448 msec
  4 14.0.0.1 [MPLS: Labels 701/611 Exp 0] 196 msec 272 msec 72 msec
  5 16.0.0.2 [MPLS: Label 611 Exp 0] 96 msec 160 msec 132 msec
  6 16.0.0.1 192 msec 172 msec *


 In this example we see only two vpn labels: 805 and 611. Moreover, only R5 and R7 are performing PHP. In this scenario R3 uses R8 as a next hop (R3 has a route to R8, and R5 doesn't change the next-hop attribute in updates sending to R3) so R3 can use a vpn label directly assigned by R8 (this is the main difference between the previous scenario).

I hope that after reading this post, some of you have a basic idea how packets are forwarded when an MPLS-based VPNs are deployed.

Monday, 21 March 2011

Administrative Distance

Few days ago I heard quite interesting question: what will happen, if different routing protocols receive the same administrative distance (hereinafter only the AD). I have tried to find the answer, however there are few different scenarios, so it is a good place to share with you some of my researches.

I took 3 different routing protocols: EIGRP, OSPF, RIP (with AD equal to 90, 110, 120, respectively). When I was searching for some answers, I came across this link, however the explanations from this website are insufficient for me. We can speak about 2 different situations. In first scenario we choose 2 routing protocols and we are making AD for them equal, however we set AD for them to the "neutral value". In the second option, we set AD to the default value of the first (or second) routing protocol. In both cases we have to find out, which routing protocol will be preferred: this, which has lower default AD or this which has AD unchanged (this may work only for the second scenario). Or maybe this one, which had its AD set later?

I will use a simple topology with 2 routers, R1 and R2. R2 advertises few different networks to R1, as depicted in the following picture:

 Basically, with all default settings, nothing suspicious can be observed:

R1#show ip route
Codes: C - connected, R - RIP, D - EIGRP, O - OSPF, 

D    192.168.4.0/24 [90/2681856] via 10.0.0.2, 00:06:37, Serial0/0
D    192.168.5.0/24 [90/2681856] via 10.0.0.2, 00:06:37, Serial0/0
     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, Serial0/0
D    192.168.6.0/24 [90/2681856] via 10.0.0.2, 00:05:43, Serial0/0
R    192.168.0.0/24 [120/1] via 10.0.0.2, 00:00:12, Serial0/0
O    192.168.1.0/24 [110/128] via 10.0.0.2, 00:06:22, Serial0/0
D    192.168.2.0/24 [90/2681856] via 10.0.0.2, 00:06:37, Serial0/0
O    192.168.3.0/24 [110/128] via 10.0.0.2, 00:06:23, Serial0/0


Now let's change AD to some "neutral values". Here I will focus also on the order in which AD of different routing protocols is changed. Let's make the following changes:
  • AD = 97, EIGRP, OSPF, RIP: 
R1(config)#router eigrp 1
R1(config-router)#distance eigrp 97 170

R1(config-router)#exit
R1(config)#router ospf 1
R1(config-router)#distance 97

R1(config-router)#exit
R1(config)#router rip
R1(config-router)#distance 97


R1#show ip route
Codes: C - connected, R - RIP, D - EIGRP, O - OSPF,

D    192.168.4.0/24 [97/2681856] via 10.0.0.2, 00:01:48, Serial0/0
D    192.168.5.0/24 [97/2681856] via 10.0.0.2, 00:01:48, Serial0/0
     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, Serial0/0
D    192.168.6.0/24 [97/2681856] via 10.0.0.2, 00:01:48, Serial0/0
R    192.168.0.0/24 [97/1] via 10.0.0.2, 00:00:24, Serial0/0
O    192.168.1.0/24 [97/128] via 10.0.0.2, 00:01:18, Serial0/0
D    192.168.2.0/24 [97/2681856] via 10.0.0.2, 00:01:48, Serial0/0
O    192.168.3.0/24 [97/128] via 10.0.0.2, 00:01:18, Serial0/0


  • AD = 98, RIP, OSPF, EIGRP:
R1(config)#router rip
R1(config-router)#distance 98

R1(config-router)#exit
R1(config)#router ospf 1
R1(config-router)#distance 98
R1(config-router)#exit

R1(config)#router eigrp 1
R1(config-router)#distance eigrp 98 170
 

R1#show ip routeCodes: C - connected, R - RIP, D - EIGRP, O - OSPF,

D    192.168.4.0/24 [98/2681856] via 10.0.0.2, 00:00:35, Serial0/0
D    192.168.5.0/24 [98/2681856] via 10.0.0.2, 00:00:35, Serial0/0
     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, Serial0/0
D    192.168.6.0/24 [98/2681856] via 10.0.0.2, 00:00:35, Serial0/0
R    192.168.0.0/24 [98/1] via 10.0.0.2, 00:00:24, Serial0/0
O    192.168.1.0/24 [98/128] via 10.0.0.2, 00:01:06, Serial0/0
D    192.168.2.0/24 [98/2681856] via 10.0.0.2, 00:00:35, Serial0/0
O    192.168.3.0/24 [98/128] via 10.0.0.2, 00:01:06, Serial0/0


  • AD = 99, OSPF, EIGRP, RIP:
R1(config)#router ospf 1
R1(config-router)#distance 99
R1(config-router)#exit

R1(config)#router eigrp 1
R1(config-router)#distance eigrp 99 170
R1(config-router)#exit
R1(config)#router rip
R1(config-router)#distance 99



R1#show ip routeCodes: C - connected, R - RIP, D - EIGRP, O - OSPF,

D    192.168.4.0/24 [99/2681856] via 10.0.0.2, 00:01:08, Serial0/0
D    192.168.5.0/24 [99/2681856] via 10.0.0.2, 00:01:08, Serial0/0
     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, Serial0/0
D    192.168.6.0/24 [99/2681856] via 10.0.0.2, 00:01:08, Serial0/0
R    192.168.0.0/24 [99/1] via 10.0.0.2, 00:00:18, Serial0/0
O    192.168.1.0/24 [99/128] via 10.0.0.2, 00:02:00, Serial0/0
D    192.168.2.0/24 [99/2681856] via 10.0.0.2, 00:01:08, Serial0/0
O    192.168.3.0/24 [99/128] via 10.0.0.2, 00:02:00, Serial0/0


In all cases, the outputs taken from R1 are the same. Metrics are totally ignored, and EIGRP wins with RIP and OSPF, whereas OSPF wins with RIP. So it looks like that default AD is taken into account (EIGRP < OSPF < RIP). Later we will check if it is correct for EIGRP external routes, where default AD is 170.

Now let's set the AD to default OSPF AD (AD = 110), next to default RIP AD (AD = 120):

  • AD = 110
R1(config)#router rip
R1(config-router)#distance 110

R1(config)#router eigrp 1
R1(config-router)#distance eigrp 110 170



R1#show ip routeCodes: C - connected, R - RIP, D - EIGRP, O - OSPF,

D    192.168.4.0/24 [110/2681856] via 10.0.0.2, 00:00:07, Serial0/0
D    192.168.5.0/24 [110/2681856] via 10.0.0.2, 00:00:07, Serial0/0
     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, Serial0/0
D    192.168.6.0/24 [110/2681856] via 10.0.0.2, 00:00:07, Serial0/0
R    192.168.0.0/24 [110/1] via 10.0.0.2, 00:00:09, Serial0/0
O    192.168.1.0/24 [110/128] via 10.0.0.2, 00:01:33, Serial0/0
D    192.168.2.0/24 [110/2681856] via 10.0.0.2, 00:00:07, Serial0/0
O    192.168.3.0/24 [110/128] via 10.0.0.2, 00:01:33, Serial0/0


  • AD = 120
R1(config)#router eigrp 1
R1(config-router)#distance eigrp 120 170
R1(config-router)#exit

R1(config)#router ospf 1
R1(config-router)#distance 120



R1#show ip routeCodes: C - connected, R - RIP, D - EIGRP, O - OSPF,

D    192.168.4.0/24 [120/2681856] via 10.0.0.2, 00:00:50, Serial0/0
D    192.168.5.0/24 [120/2681856] via 10.0.0.2, 00:00:18, Serial0/0
     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, Serial0/0
D    192.168.6.0/24 [120/2681856] via 10.0.0.2, 00:00:18, Serial0/0
R    192.168.0.0/24 [120/1] via 10.0.0.2, 00:00:23, Serial0/0
O    192.168.1.0/24 [120/128] via 10.0.0.2, 00:00:18, Serial0/0
D    192.168.2.0/24 [120/2681856] via 10.0.0.2, 00:00:50, Serial0/0
O    192.168.3.0/24 [120/128] via 10.0.0.2, 00:00:18, Serial0/0


In both cases, the outputs from R1 are the same. Still EIGRP is "the best" and OSPF is "better" than RIP.

Now let's modify slightly our example. R2 will redistribute all EIGRP networks and advertised these networks to R1 as external with default AD equal to 170. Here is the output from R1, when AD is not modified:

R1#show ip route
Codes:
Codes: C - connected, R - RIP, D - EIGRP, EX - EIGRP external, O - OSPF,

R    192.168.4.0/24 [120/1] via 10.0.0.2, 00:00:16, Serial0/0
O    192.168.5.0/24 [120/128] via 10.0.0.2, 00:02:47, Serial0/0
     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, Serial0/0
O    192.168.6.0/24 [120/128] via 10.0.0.2, 00:02:47, Serial0/0
R    192.168.0.0/24 [120/1] via 10.0.0.2, 00:00:16, Serial0/0
O    192.168.1.0/24 [120/128] via 10.0.0.2, 00:08:03, Serial0/0
D EX 192.168.2.0/24 [170/2474496] via 10.0.0.2, 00:00:57, Serial0/0
O    192.168.3.0/24 [120/128] via 10.0.0.2, 00:08:03, Serial0/0


Now let's change AD of all protocols to 130 (first), and 102 (next).
  • AD = 130, EIGRP first, next RIP, last OSPF:
R1(config)#router eigrp 1
R1(config-router)#distance eigrp 130 130
R1(config-router)#exit
R1(config)#router rip
R1(config-router)#distance 130
R1(config)#router ospf 1
R1(config-router)#distance 130


R1#show ip routeCodes: Codes: C - connected, R - RIP, D - EIGRP, EX - EIGRP external, O - OSPF,

D EX 192.168.4.0/24 [130/2474496] via 10.0.0.2, 00:00:49, Serial0/0
D EX 192.168.5.0/24 [130/2474496] via 10.0.0.2, 00:00:14, Serial0/0
     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, Serial0/0
D EX 192.168.6.0/24 [130/2474496] via 10.0.0.2, 00:00:14, Serial0/0
R    192.168.0.0/24 [130/1] via 10.0.0.2, 00:00:26, Serial0/0
O    192.168.1.0/24 [130/128] via 10.0.0.2, 00:00:14, Serial0/0
D EX 192.168.2.0/24 [130/2474496] via 10.0.0.2, 00:00:49, Serial0/0
O    192.168.3.0/24 [130/128] via 10.0.0.2, 00:00:14, Serial0/0


  • AD = 102, OSPF first, then RIP, EIGRP last:
R1(config)#router ospf 1
R1(config-router)#distance 102
R1(config-router)#exit

R1(config)#router rip
R1(config-router)#distance 102
R1(config-router)#exit
R1(config)#router eigrp 1
R1(config-router)#distance eigrp 90 102


R1#show ip routeCodes: Codes: C - connected, R - RIP, D - EIGRP, EX - EIGRP external, O - OSPF,

D EX 192.168.4.0/24 [102/2474496] via 10.0.0.2, 00:00:09, Serial0/0
D EX 192.168.5.0/24 [102/2474496] via 10.0.0.2, 00:00:09, Serial0/0
     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, Serial0/0
D EX 192.168.6.0/24 [102/2474496] via 10.0.0.2, 00:00:09, Serial0/0
R    192.168.0.0/24 [102/1] via 10.0.0.2, 00:00:04, Serial0/0
O    192.168.1.0/24 [102/128] via 10.0.0.2, 00:00:10, Serial0/0
D EX 192.168.2.0/24 [102/2474496] via 10.0.0.2, 00:00:09, Serial0/0
O    192.168.3.0/24 [102/128] via 10.0.0.2, 00:00:10, Serial0/0


Here we can see quite interesting thing. Still EIGRP wins with RIP and OSPF, and routes delivered by EIGRP are installed in the routing table, even if these routes are external with default AD of 170. So it looks like EIGRP is always preferred.

I also made some other tests. For example, eBGP is preferred than EIGRP (eBGP has AD = 20):

R1#show ip route
Codes: Codes: C - connected, R - RIP, D - EIGRP, EX - EIGRP external, O - OSPF, B - BGP,

D    192.168.4.0/24 [56/2681856] via 10.0.0.2, 00:00:17, Serial0/0
D    192.168.5.0/24 [56/2681856] via 10.0.0.2, 00:00:17, Serial0/0
B    192.168.2.0/24 [56/0] via 10.0.0.2, 00:00:30
! Some lines omitted

Above we can see that the 192.168.2.0/24 is received via BGP and EIGRP. The AD of them (both BGP and EIGRP) is set to 56. IOS picked up the route received via BGP. Even iBGP (default AD = 200) is preferred than EIGRP:

R1#show ip bgp
BGP table version is 4, local router ID is 10.0.0.1
Status codes: * valid, > best, i - internal,

   Network          Next Hop            Metric LocPrf Weight Path
*>i192.168.2.0      10.0.0.2                 0    100      0 i

R1#show ip route
Codes: Codes: C - connected, R - RIP, D - EIGRP, EX - EIGRP external, O - OSPF, B - BGP,

D    192.168.4.0/24 [56/2681856] via 10.0.0.2, 00:01:05, Serial0/0
D    192.168.5.0/24 [56/2681856] via 10.0.0.2, 00:01:05, Serial0/0
B    192.168.2.0/24 [56/0] via 10.0.0.2, 00:01:05


However each time I have changed the AD for BGP (external or internal) after changing the AD for EIGRP, I had to prompt clear ip bgp * or clear ip route * so BGP could kick off the existing route which have been delivered via EIGRP (in other words, if AD of BGP was changed first, EIGRP didn't have any chance to install its routes to RIB, however if AD of EIGRP was changed before AD of BGP, and it was a lower value than the default AD of BGP, one of these two commands was required).

To sum up, it looks like the default AD is the tie-breaker. However IOS doesn't take into account default AD of external EIGRP nor iBGP, it just takes default AD equal to 90 and 20, respectively.

Monday, 14 March 2011

The power of access-lists

Today let's talk about access-lists. In many books we can easily find the statements, that prefix-lists are much convenient than access-lists. With prefix-lists, using ge and/or le gives more flexibility. For example imagine, that you have 5 networks: 10.0.0.0/24, 10.0.1.0/25, 10.0.1.128/25, 10.0.2.0/26, 10.0.2.128/25. Next, you want to permit only these networks with prefix length of 25. You can use a simple prefix-list command:

ip prefix-list FILTER permit 10.0.0.0/16 ge 25 le 25

whereas you need to use 3 (or 2) different lines with access-list:

access-list 1 permit 10.0.1.0 0.0.0.127
access-list 1 permit 10.0.1.128 0.0.0.127
access-list 1 permit 10.0.2.128 0.0.0.127

or

access-list 1 permit 10.0.1.0 0.0.0.255
access-list 1 permit 10.0.2.128 0.0.0.127


In this example the difference is small, but with more than 50 lines, using standard access-lists can be daunting. However extended access-lists are much more powerful.

For this example, I will use 2 routers directly connected with EIGRP:


R2 has 10 loopbacks with different networks which are being advertised to R1 via EIGRP:

R2#show ip interface | include 192
  Internet address is 192.168.0.1/24
  Internet address is 192.168.1.1/25
  Internet address is 192.168.1.129/25
  Internet address is 192.168.2.1/26
  Internet address is 192.168.2.65/27
  Internet address is 192.168.2.129/27
  Internet address is 192.168.3.1/28
  Internet address is 192.168.3.65/28
  Internet address is 192.168.3.129/29
  Internet address is 192.168.3.161/29


R1#show ip route eigrp
D    192.168.0.0/24 [90/2297856] via 10.0.0.1, 00:01:08, Serial0/0
     192.168.1.0/25 is subnetted, 2 subnets
D       192.168.1.0 [90/2297856] via 10.0.0.1, 00:00:48, Serial0/0
D       192.168.1.128 [90/2297856] via 10.0.0.1, 00:00:48, Serial0/0
     192.168.2.0/24 is variably subnetted, 3 subnets, 2 masks
D       192.168.2.64/27 [90/2297856] via 10.0.0.1, 00:00:48, Serial0/0
D       192.168.2.0/26 [90/2297856] via 10.0.0.1, 00:00:48, Serial0/0
D       192.168.2.128/27 [90/2297856] via 10.0.0.1, 00:00:48, Serial0/0
     192.168.3.0/24 is variably subnetted, 4 subnets, 2 masks
D       192.168.3.64/28 [90/2297856] via 10.0.0.1, 00:00:48, Serial0/0
D       192.168.3.0/28 [90/2297856] via 10.0.0.1, 00:00:48, Serial0/0
D       192.168.3.160/29 [90/2297856] via 10.0.0.1, 00:00:48, Serial0/0
D       192.168.3.128/29 [90/2297856] via 10.0.0.1, 00:00:48, Serial0/0
R1#show ip route summary | include eigrp
eigrp 1         1           9           720         1280



We see, that everything works. Now we would like to send to R1 only these prefixes with network length of 27 or more. We will do this using either the prefix-list or extended ACL, and in each case we will use one single matching-command!

First, let's do this using prefix-list:

R2#conf t
R2(config)#ip prefix-list PREF1 permit 192.168.0.0/16 ge 27
R2(config)#route-map PREFOUT1 permit 10
R2(config-route-map)#match ip address prefix-list PREF1
R2(config-route-map)#exit
R2(config)#router eigrp 1
R2(config-router)#distribute-list route-map PREFOUT1 out


And on R1 we've got:


R1#show ip route eigrp
     192.168.2.0/27 is subnetted, 2 subnets
D       192.168.2.64 [90/2297856] via 10.0.0.1, 00:04:30, Serial0/0
D       192.168.2.128 [90/2297856] via 10.0.0.1, 00:04:30, Serial0/0
     192.168.3.0/24 is variably subnetted, 4 subnets, 2 masks
D       192.168.3.64/28 [90/2297856] via 10.0.0.1, 00:04:30, Serial0/0
D       192.168.3.0/28 [90/2297856] via 10.0.0.1, 00:04:30, Serial0/0
D       192.168.3.160/29 [90/2297856] via 10.0.0.1, 00:04:30, Serial0/0
D       192.168.3.128/29 [90/2297856] via 10.0.0.1, 00:04:30, Serial0/0
R1#show ip route summary | include eigrp
eigrp 1         0           6           432         768


Now, let's do the same using ACL:


R2#conf t
R2(config)#access-list 100
permit ip 192.168.0.0 0.0.255.255 255.255.255.224 0.0.0.31
R2(config)#route-map ACLOUT1 permit 10
R2(config-route-map)#match ip address 100
R2(config-route-map)#exit
R2(config)#router eigrp 1
R2(config-router)#distribute-list route-map ACLOUT1 out


And what we get on R1? The same!

R1#show ip route eigrp
     192.168.2.0/27 is subnetted, 2 subnets
D       192.168.2.64 [90/2297856] via 10.0.0.1, 00:12:49, Serial0/0
D       192.168.2.128 [90/2297856] via 10.0.0.1, 00:12:49, Serial0/0
     192.168.3.0/24 is variably subnetted, 4 subnets, 2 masks
D       192.168.3.64/28 [90/2297856] via 10.0.0.1, 00:12:49, Serial0/0
D       192.168.3.0/28 [90/2297856] via 10.0.0.1, 00:12:49, Serial0/0
D       192.168.3.160/29 [90/2297856] via 10.0.0.1, 00:12:49, Serial0/0
D       192.168.3.128/29 [90/2297856] via 10.0.0.1, 00:12:49, Serial0/0
R1#show ip route summary | include eigrp
eigrp 1         0           6           432         768


Now let's permit only these prefixes, that have the length of 26 to 28. First we can use the prefix-list solution:

R2#configure t
R2(config)#ip prefix-list PREF2 permit 192.168.0.0/16 ge 26 le 28
R2(config)#route-map PREFOUT2 permit 10
R2(config-route-map)#match ip address prefix-list PREF2
R2(config-route-map)#exit
R2(config)#router eigrp 1
R2(config-router)#distribute-list route-map PREFOUT2 out



On R1:

R1#show ip route eigrp
     192.168.2.0/24 is variably subnetted, 3 subnets, 2 masks
D       192.168.2.64/27 [90/2297856] via 10.0.0.1, 00:17:22, Serial0/0
D       192.168.2.0/26 [90/2297856] via 10.0.0.1, 00:02:27, Serial0/0
D       192.168.2.128/27 [90/2297856] via 10.0.0.1, 00:17:22, Serial0/0
     192.168.3.0/28 is subnetted, 2 subnets
D       192.168.3.64 [90/2297856] via 10.0.0.1, 00:17:22, Serial0/0
D       192.168.3.0 [90/2297856] via 10.0.0.1, 00:17:22, Serial0/0
R1#show ip route summary | include eigrp
eigrp 1         0           5           360         640



Now we will use the ACL logic:

R2#configure t
R2(config)#access-list 101 permit ip 192.168.0.0 0.0.255.255 255.255.255.192 0.0.0.48
R2(config)#route-map ACLOUT2 permit 10
R2(config-route-map)#match ip address 101
R2(config-route-map)#exit
R2(config)#router eigrp 1
R2(config-router)#distribute-list route-map ACLOUT2 out


Let's go back to R1:

R1#show ip route eigrp
     192.168.2.0/24 is variably subnetted, 3 subnets, 2 masks
D       192.168.2.64/27 [90/2297856] via 10.0.0.1, 00:24:44, Serial0/0
D       192.168.2.0/26 [90/2297856] via 10.0.0.1, 00:09:49, Serial0/0
D       192.168.2.128/27 [90/2297856] via 10.0.0.1, 00:24:44, Serial0/0
     192.168.3.0/28 is subnetted, 2 subnets
D       192.168.3.64 [90/2297856] via 10.0.0.1, 00:24:44, Serial0/0
D       192.168.3.0 [90/2297856] via 10.0.0.1, 00:24:44, Serial0/0
R1#show ip route summary | include eigrp
eigrp 1         0           5           360         640


Again, we have done the same thing with the ACL that with the prefix-list! And we used the same number of commands!

Here, I tried to prove, that both of them are provide the similar level of flexibility. However prefix-lists have more user-friendly CLI and provide higher performance (use less CPU cycles) and that should be the main motivation to use them.

Sunday, 13 March 2011

BGP part 2

The second post today is also about BGP. I was asked why in  transit AS we have to run both IGP and iBGP. Why we cannot pick up one routing protocol? Let's find the answer!
In the following picture we can see the transit area which is connected to two others AS. Now let's focus on 3 different situation:
  • routers in the transit area are running only IGP
  • routers in the transit area are running only iBGP
  • routers in the transit area are running both IGP and iBGP

So in the first option, routers in the transit area are running only IGP. Routers R1 and R5 have established the BGP-sessions to routers R6 and R7, respectively. And if you are running only IGP between all others router within the transit area, you have to redistribute on R1 and R5 all received BGP prefixes into the IGP. Easy? Maybe it is easy, however today BGP routing table has about 380 000 prefixes. That amount of prefixes will kill the IGP and the routers will suffer a shortage of CPU power. So this solution is impossible! You can of course establish the iBGP session between R1 and R5. Then R1 and R5 will have all BGP prefixes, even without the redistribution BGP into IGP. However when the R1 would like to send a packet to the R7 via R5, R1 will send the packet to either R2, R3 or R4. And because none of these routers have the route to the R7 (again, we don't redistribute BGP into IGP), the packet will be dropped.

In the second option we are using only iBGP. We redistribute connected into BGP, so every router can ping whatever he want. But BGP is designed to carry a huge number of prefixes. In the path selection, the BGP doesn't take into account the link speed or link delay, which is the strength of link-state IGPs. Moreover BGP has a relative long time to reach the convergence in case of any failures in the network. So this solution may work, however it is not optimal.

Finally we can use IGP and iBGP in our core network. And this solution is almost perfect! Almost, because we have to deploy BGP sessions between every single router (we can use MPLS to avoid this, however this technology is out of scope of this post). Before we saw what happens without a full-mesh BGP sessions (R2, R3 or R4 are dropping all unknown packets). In this solution R1 (or R5) is advertising all BGP prefixes that he learned from R6 to the transit network (so to the R2, R3 or R4) using BGP, so all other routers that are running BGP have the knowledge of all these prefixes, and all other routers in the transit area know exactly how to reach the exit point (R1), because of IGP. In case of any failure in the core network, each router within the transit area is able to update its routing table (and finds out the new route to the exit point) using the IGP and it is much faster that the convergence of BGP.

BGP.

With the first post today, I would like to focus on the BGP routing protocol. I know ( for instance from my personal experience! ) that when people are starting to learn about this protocol, they are a little bit confused. One of the reason is related to the thing, that they are thinking in the IGP-way. Let me show you, where is the problem.

Please take a closer view on the picture:


On the picture we see three routers. Each router is in a different AS. There are two BGP sessions: R1-R2 and R2-R3. Moreover, R1 and R3 are injected their LANs (LANs behind SW1 and SW2, respectively) into the BGP routing table. There is only the BGP, no other routing protocols are running between routers.
Now, lets investigate R1's routing table. R1 knows all routes to the LAN2. However, it cannot ping any address in this LAN. R1 can ping R2, and R2 can ping either R3 or LAN2. What is happening?
The thing is, that when a router is sending the ping generated by itself, it puts to the IP header the IP address of interface from which the router sent the packet. In our case, R1 will send the ping out of the fa0/1 and indeed, R1 will put to the IP packet header the IP address of fa1/0. Eventually the ping will reach LAN2, and R3 will receive the ping reply from LAN2. After this, R3 will drop the packet (the ping reply), because R3 doesn't have the route to R1's fa0/1 IP address. That is the reason, why the communication between R1 and LAN2 is unsuccessful.

What we can do about this? Nothing, because we don't have to! In the real network it is pointless to send pings in this way. In real world, devices in LAN1 have to establish the communication with the devices in LAN2. In this situation R3 exactly knows, where to send the reply, because R3 has in routing table route to LAN1.

However, if you are being determinated to send the ping from R1, you can redistribute connected to the BGP table or change the IOS default behavior by:
ping ip_address source [source_ip_address | interface interface mod/num]

At this point I would like to also tell you what is the difference between the network command in IGP and BGP. In the IGP, a router will find all of its interfaces that have the IP address within the network statement and will start to run the IGP process on these interfaces. Beside of this,  the router will start to advertise by IGP process the network to which is directly connected via this interface. Returning to our picture, when you start the IGP between R1 - R2 and R2 - R3, every single network between these routers will be presented in the routing tables of each router.
However, network in BGP works completely different. Whereas the network command in IGP is using to establish the neighborhood between directly connected routers, in BGP this command is only used to insert to the BGP routing table a network and start to advertise it to the other peers. The session between 2 BGP-speaking peers however is configured manually and even it can be configured between non directly connected routers.

So when you establish a BGP-session between 2 routers, the BGP will not start to advertise the network that is between these routers. Whereas when you establish the IGP neighborhood between two directly connected routers, the IGP process will start to advertise the network that is between the routers. That is the reason, why the connection between R1 and LAN2 doesn't work.