BGP - Communities
November 21st, 2008 in
BGP | tags:
BGP Communities,
route-map
In a previous post I talked about BGP weight and how this can be used on a router to determine which preferred path to take to a certain network. In this post we will also talk about the weight attribute but this time we are going to configure it in conjunction with bgp communities.
As you can see in the network-diagram below router R5 will advertise 9 loopback networks into the BGP network. What we want to establish on router R1 is that traffic destined for lo 221, 222 and 223 will go via router R2, traffic for lo 331, 332 and 333 go via router R3 and traffic for lo 441, 442 and 443 will go via router R4. The way we want to configure this is by using communities which will be set on router R2, router R3 and router R4.

First off let’s set up the BGP peerings :
R1 :
|
|
|
router bgp 65001
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
network 1.1.1.1 mask 255.255.255.255
neighbor 10.10.12.2 remote-as 65002
neighbor 10.10.12.2 send-community
neighbor 10.10.13.3 remote-as 65003
neighbor 10.10.13.3 send-community
neighbor 10.10.14.4 remote-as 65004
neighbor 10.10.14.4 send-community
no auto-summary
|
R2 :
|
|
|
router bgp 65002
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.2 mask 255.255.255.255
neighbor 10.10.12.1 remote-as 65001
neighbor 10.10.12.1 send-community
neighbor 10.10.25.5 remote-as 65005
neighbor 10.10.25.5 send-community
no auto-summary
|
R3 :
|
|
|
router bgp 65003
no synchronization
bgp router-id 3.3.3.3
bgp log-neighbor-changes
network 3.3.3.3 mask 255.255.255.255
neighbor 10.10.13.1 remote-as 65001
neighbor 10.10.13.1 send-community
neighbor 10.10.35.5 remote-as 65005
neighbor 10.10.35.5 send-community
no auto-summary
|
R4 :
|
|
|
router bgp 65004
no synchronization
bgp router-id 4.4.4.4
bgp log-neighbor-changes
network 4.4.4.4 mask 255.255.255.255
neighbor 10.10.14.1 remote-as 65001
neighbor 10.10.14.1 send-community
neighbor 10.10.45.5 remote-as 65005
neighbor 10.10.45.5 send-community
no auto-summary
|
R5 :
|
|
|
router bgp 65005
no synchronization
bgp router-id 5.5.5.5
bgp log-neighbor-changes
network 5.5.5.5 mask 255.255.255.255
network 22.22.22.1 mask 255.255.255.255
network 22.22.22.2 mask 255.255.255.255
network 22.22.22.3 mask 255.255.255.255
network 33.33.33.1 mask 255.255.255.255
network 33.33.33.2 mask 255.255.255.255
network 33.33.33.3 mask 255.255.255.255
network 44.44.44.1 mask 255.255.255.255
network 44.44.44.2 mask 255.255.255.255
network 44.44.44.3 mask 255.255.255.255
neighbor 10.10.25.2 remote-as 65002
neighbor 10.10.25.2 send-community
neighbor 10.10.35.3 remote-as 65003
neighbor 10.10.35.3 send-community
neighbor 10.10.45.4 remote-as 65004
neighbor 10.10.45.4 send-community
no auto-summary
|
Next let’s have a look at router’s R1 bgp table before configuring communities anywhere :
R1 :
|
|
|
R1#sh ip bgp
BGP table version is 15, local router ID is 1.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
*> 1.1.1.1/32 0.0.0.0 0 32768 i
*> 2.2.2.2/32 10.10.12.2 0 0 65002 i
* 3.3.3.3/32 10.10.12.2 0 65002 65005 65003 i
*> 10.10.13.3 0 0 65003 i
* 4.4.4.4/32 10.10.13.3 0 65003 65005 65004 i
*> 10.10.14.4 0 0 65004 i
* 5.5.5.5/32 10.10.14.4 0 65004 65005 i
* 10.10.12.2 0 65002 65005 i
*> 10.10.13.3 0 65003 65005 i
* 22.22.22.1/32 10.10.14.4 0 65004 65005 i
* 10.10.12.2 0 65002 65005 i
*> 10.10.13.3 0 65003 65005 i
* 22.22.22.2/32 10.10.14.4 0 65004 65005 i
* 10.10.12.2 0 65002 65005 i
*> 10.10.13.3 0 65003 65005 i
* 22.22.22.3/32 10.10.14.4 0 65004 65005 i
* 10.10.12.2 0 65002 65005 i
Network Next Hop Metric LocPrf Weight Path
*> 10.10.13.3 0 65003 65005 i
* 33.33.33.1/32 10.10.14.4 0 65004 65005 i
* 10.10.12.2 0 65002 65005 i
*> 10.10.13.3 0 65003 65005 i
* 33.33.33.2/32 10.10.14.4 0 65004 65005 i
* 10.10.12.2 0 65002 65005 i
*> 10.10.13.3 0 65003 65005 i
* 33.33.33.3/32 10.10.14.4 0 65004 65005 i
* 10.10.12.2 0 65002 65005 i
*> 10.10.13.3 0 65003 65005 i
* 44.44.44.1/32 10.10.14.4 0 65004 65005 i
* 10.10.12.2 0 65002 65005 i
*> 10.10.13.3 0 65003 65005 i
* 44.44.44.2/32 10.10.14.4 0 65004 65005 i
* 10.10.12.2 0 65002 65005 i
*> 10.10.13.3 0 65003 65005 i
* 44.44.44.3/32 10.10.14.4 0 65004 65005 i
* 10.10.12.2 0 65002 65005 i
*> 10.10.13.3 0 65003 65005 i
|
As you can see above router R1 learns all routes advertised by router R5 via routers R2, R3 and R4. All routes are preferred via router R3 as you can see (”>”).
The next we are going to do is set communities on router R2 for lo 221, 222 and 223 of router R5 :
R2 :
|
|
|
router bgp 65002
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.2 mask 255.255.255.255
neighbor 10.10.12.1 remote-as 65001
neighbor 10.10.12.1 send-community
neighbor 10.10.12.1 route-map SETCOM out
neighbor 10.10.25.5 remote-as 65005
neighbor 10.10.25.5 send-community
no auto-summary
!
ip access-list standard router2
permit 22.22.22.2
permit 22.22.22.3
permit 22.22.22.1
!
route-map SETCOM permit 10
match ip address router2
set community 2:5
!
route-map SETCOM permit 20
|
For router R3 and router R4 I also configured it the same way as above for router R2, on router R3 I put a community-value of 3:5 and on router R4 I used the community value 4:5.
Now let’s have a look at router’s R1 “sh ip bgp 22.22.22.1″ output for instance :
R1 :
|
|
|
R1#sh ip bgp 22.22.22.1
BGP routing table entry for 22.22.22.1/32, version 7
Paths: (3 available, best #3, table Default-IP-Routing-Table)
Advertised to update-groups:
1
65002 65005
10.10.12.2 from 10.10.12.2 (2.2.2.2)
Origin IGP, localpref 100, valid, external
Community: 2:5
65004 65005
10.10.14.4 from 10.10.14.4 (4.4.4.4)
Origin IGP, localpref 100, valid, external
65003 65005
10.10.13.3 from 10.10.13.3 (3.3.3.3)
Origin IGP, localpref 100, valid, external, best
|
As you can see there is a community value specified for this route learned by AS 65002. So now what we need to do is make a route-map which matches this community and set the weight for it, this can be done like so :
R1 :
|
|
|
router bgp 65001
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
network 1.1.1.1 mask 255.255.255.255
neighbor 10.10.12.2 remote-as 65002
neighbor 10.10.12.2 send-community
neighbor 10.10.12.2 route-map check-community in
neighbor 10.10.13.3 remote-as 65003
neighbor 10.10.13.3 send-community
neighbor 10.10.13.3 route-map check-community in
neighbor 10.10.14.4 remote-as 65004
neighbor 10.10.14.4 send-community
neighbor 10.10.14.4 route-map check-community in
no auto-summary
!
ip http server
ip classless
!
!
ip bgp-community new-format
ip community-list 2 permit 2:5
ip community-list 3 permit 3:5
ip community-list 4 permit 4:5
ip community-list 5 permit internet
!
!
route-map check-community permit 10
match community 4
set weight 30
!
route-map check-community permit 15
match community 2
set weight 30
!
route-map check-community permit 17
match community 3
set weight 30
!
route-map check-community permit 20
match community 5
|
Now let’s see what router R1’s bgp table tells us :
R1 :
|
|
|
R1#sh ip bgp
BGP table version is 36, local router ID is 1.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
*> 1.1.1.1/32 0.0.0.0 0 32768 i
*> 2.2.2.2/32 10.10.12.2 0 0 65002 i
*> 3.3.3.3/32 10.10.13.3 0 30 65003 i
* 10.10.12.2 0 65002 65005 65003 i
* 10.10.14.4 0 65004 65005 65003 i
*> 4.4.4.4/32 10.10.14.4 0 0 65004 i
*> 5.5.5.5/32 10.10.13.3 30 65003 65005 i
* 10.10.12.2 0 65002 65005 i
* 10.10.14.4 0 65004 65005 i
* 22.22.22.1/32 10.10.13.3 30 65003 65005 i
*> 10.10.12.2 30 65002 65005 i
* 10.10.14.4 0 65004 65005 i
* 22.22.22.2/32 10.10.13.3 30 65003 65005 i
*> 10.10.12.2 30 65002 65005 i
* 10.10.14.4 0 65004 65005 i
* 22.22.22.3/32 10.10.13.3 30 65003 65005 i
*> 10.10.12.2 30 65002 65005 i
Network Next Hop Metric LocPrf Weight Path
* 10.10.14.4 0 65004 65005 i
*> 33.33.33.1/32 10.10.13.3 30 65003 65005 i
* 10.10.12.2 0 65002 65005 i
* 10.10.14.4 0 65004 65005 i
*> 33.33.33.2/32 10.10.13.3 30 65003 65005 i
* 10.10.12.2 0 65002 65005 i
* 10.10.14.4 0 65004 65005 i
*> 33.33.33.3/32 10.10.13.3 30 65003 65005 i
* 10.10.12.2 0 65002 65005 i
* 10.10.14.4 0 65004 65005 i
* 44.44.44.1/32 10.10.13.3 30 65003 65005 i
* 10.10.12.2 0 65002 65005 i
*> 10.10.14.4 30 65004 65005 i
* 44.44.44.2/32 10.10.13.3 30 65003 65005 i
* 10.10.12.2 0 65002 65005 i
*> 10.10.14.4 30 65004 65005 i
* 44.44.44.3/32 10.10.13.3 30 65003 65005 i
* 10.10.12.2 0 65002 65005 i
*> 10.10.14.4 30 65004 65005 i
|
As you can see we reached our goal :

See the traceroutes from router R1 :
A traceroute to 44.44.44.1 should go via router R4 :
R1 :
|
|
|
R1#traceroute
Protocol [ip]:
Target IP address: 44.44.44.1
Source address: 1.1.1.1
Numeric display [n]:
Timeout in seconds [3]:
Probe count [3]:
Minimum Time to Live [1]:
Maximum Time to Live [30]:
Port Number [33434]:
Loose, Strict, Record, Timestamp, Verbose[none]:
Type escape sequence to abort.
Tracing the route to 44.44.44.1
1 10.10.14.4 128 msec 220 msec 536 msec
2 10.10.45.5 452 msec 300 msec *
|
A traceroute to 33.33.33.2 should go via router R3 :
R1 :
|
|
|
R1#traceroute
Protocol [ip]:
Target IP address: 33.33.33.2
Source address: 1.1.1.1
Numeric display [n]:
Timeout in seconds [3]:
Probe count [3]:
Minimum Time to Live [1]:
Maximum Time to Live [30]:
Port Number [33434]:
Loose, Strict, Record, Timestamp, Verbose[none]:
Type escape sequence to abort.
Tracing the route to 33.33.33.2
1 10.10.13.3 156 msec 52 msec 32 msec
2 10.10.35.5 220 msec 184 msec *
|
A traceroute to 22.22.22.3 should go via router R2 :
R1 :
|
|
|
R1#traceroute
Protocol [ip]:
Target IP address: 22.22.22.3
Source address: 1.1.1.1
Numeric display [n]:
Timeout in seconds [3]:
Probe count [3]:
Minimum Time to Live [1]:
Maximum Time to Live [30]:
Port Number [33434]:
Loose, Strict, Record, Timestamp, Verbose[none]:
Type escape sequence to abort.
Tracing the route to 22.22.22.3
1 10.10.12.2 180 msec 68 msec 156 msec
2 10.10.25.5 268 msec 144 msec *
|