BGP路由聚合
在大规模的网络中,BGP路由表十分庞大,给设备造成了很大的负担,同时使发生路由振荡的几率也大大增加,影响网络的稳定性。
路由聚合是将多条路由合并的机制,它通过只向对等体发送聚合后的路由而不发送所有的具体路由的方法,减小路由表的规模。并且被聚合的路由如果发生路由振荡,也不再对网络造成影响,从而提高了网络的稳定性。
拓扑:
基本配置:
完成基本接口配置 (略)
完成AS200内IGP配置,使用OSPF协议,宣告各自直连接口和环回口(略)
完成EBGP和IBGP配置
以AR1为例:
bgp 100
router-id 11.1.1.1
timer keepalive 50 hold 150
peer 12.1.1.2 as-number 200
#
ipv4-family unicast
undo synchronization
network 11.1.1.1 255.255.255.255
peer 12.1.1.2 enable
AR2:
bgp 200
router-id 22.1.1.1
peer 12.1.1.1 as-number 100
peer 33.1.1.1 as-number 200
peer 33.1.1.1 connect-interface LoopBack0
peer 44.1.1.1 as-number 200
peer 44.1.1.1 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
peer 12.1.1.1 enable
peer 33.1.1.1 enable
peer 33.1.1.1 next-hop-local
peer 44.1.1.1 enable
peer 44.1.1.1 next-hop-local
(1)自动聚合
对BGP引入的子网路由进行自然掩码聚合。配置自动聚合后,生成聚合后的自然网段路由,而原引入的子网路由被抑制,不会被优选和发布给BGP邻居。
在AR2上把OSPF学习到的路由引入到BGP协议中
AR2:
bgp 200
import-route ospf 1 //引入OSPF路由
[AR2]dis bgp routing-table //查看BGP路由表
BGP Local router ID is 22.1.1.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 7
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 10.1.1.0/24 0.0.0.0 2 0 ? ---问号代表重分布引入路由
*> 11.1.1.1/32 12.1.1.1 0 0 100i
*> 22.1.1.1/32 0.0.0.0 0 0 ?
*> 23.1.1.0/24 0.0.0.0 0 0 ?
*> 33.1.1.1/32 0.0.0.0 1 0 ?
*> 44.1.1.1/32 0.0.0.0 2 0 ?
*>i 55.1.1.1/32 44.1.1.1 0 100 0 300i
此时在AR2上开启自动汇总功能,配置如下
[AR2-bgp]summary automatic //开启自动汇总
Info: Automatic summarization is valid only for the routes imported through the import-route command.
[AR2]dis bgp routing-table
BGP Local router ID is 22.1.1.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 14
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 10.0.0.0 127.0.0.1 0 ?
s> 10.1.1.0/24 0.0.0.0 2 0 ? //生成聚合后的自然网段路由,而原引入的子网路由被抑制,不会被优选和发布给BGP邻居。
*> 11.1.1.1/32 12.1.1.1 0 0 100i
*> 22.0.0.0 127.0.0.1 0 ?
s> 22.1.1.1/32 0.0.0.0 0 0 ?
*> 23.0.0.0 127.0.0.1 0 ?
s> 23.1.1.0/24 0.0.0.0 0 0 ?
*> 33.0.0.0 127.0.0.1 0 ?
s> 33.1.1.1/32 0.0.0.0 1 0 ?
*> 44.0.0.0 127.0.0.1 0 ?
s> 44.1.1.1/32 0.0.0.0 2 0 ?
*> 55.0.0.0 127.0.0.1 0 ?
s> 55.1.1.1/32 0.0.0.0 1 0 ?
* i 44.1.1.1 0 100 0 300i
[AR2]dis bgp routing-table 10.0.0.0
BGP local router ID : 22.1.1.1
Local AS number : 200
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 10.0.0.0/8:
Summary automatic route
Route Duration: 00h00m29s
Direct Out-interface: NULL0
Original nexthop: 127.0.0.1
Qos information : 0x0
AS-path Nil, origin incomplete, pref-val 0, valid, local, best, select, active, pre 255
Aggregator: AS 200, Aggregator ID 22.1.1.1
Advertised to such 3 peers:
44.1.1.1
33.1.1.1
12.1.1.1
[AR2]dis ip routing-table protocol bgp
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : BGP
Destinations : 7 Routes : 7
BGP routing table status :
Destinations : 7 Routes : 7
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.0.0/8 IBGP 255 0 D 127.0.0.1 NULL0 ===路由聚合以后,会产生指向NULL0空接口路由
11.1.1.1/32 EBGP 255 0 D 12.1.1.1 GigabitEthernet0/0/0
22.0.0.0/8 IBGP 255 0 D 127.0.0.1 NULL0
23.0.0.0/8 IBGP 255 0 D 127.0.0.1 NULL0
33.0.0.0/8 IBGP 255 0 D 127.0.0.1 NULL0
44.0.0.0/8 IBGP 255 0 D 127.0.0.1 NULL0
55.1.1.1/32 IBGP 255 0 RD 44.1.1.1 GigabitEthernet0/0/1
(2)手动聚合
手动聚合:
对BGP本地路由进行聚合。通常情况下,手动聚合的优先级高于自动聚合的优先级。缺省情况下手动聚合后会把明细路由和聚合路由一起发布。
在AR1上新添加环回口地址 LO10 192.168.0.1/24、 LO11 192.168.1.1/24、 LO12 192.168.2.1/24 、LO13 192.168.3.1/24,然后将新增加4个环回接口宣告进BGP进程下,
[AR1]bgp 100
[AR1-bgp]net 192.168.0.0 24
[AR1-bgp]net 192.168.1.0 24
[AR1-bgp]net 192.168.2.0 24
[AR1-bgp]net 192.168.3.0 24
BGP Local router ID is 22.1.1.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 11
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 10.1.1.0/24 0.0.0.0 2 0 ?
*> 11.1.1.1/32 12.1.1.1 0 0 100i
*> 22.1.1.1/32 0.0.0.0 0 0 ?
*> 23.1.1.0/24 0.0.0.0 0 0 ?
*> 33.1.1.1/32 0.0.0.0 1 0 ?
*> 44.1.1.1/32 0.0.0.0 2 0 ?
*>i 55.1.1.1/32 44.1.1.1 0 100 0 300i
*> 192.168.0.0 12.1.1.1 0 0 100i
*> 192.168.1.0 12.1.1.1 0 0 100i
*> 192.168.2.0 12.1.1.1 0 0 100i
*> 192.168.3.0 12.1.1.1 0 0 100i
在AR2上查看BGP路由表,学习到AR1宣告的192网段的4条明细路由,由于学习到大量的明细路由会占用内存空间,需手工聚合,路由聚合如下配置:
为了查看路由表,把AR2上OSPF引入BGP路由删掉
[AR2]bgp 200
[AR2-bgp]aggregate ?
IP_ADDR
[AR2-bgp]aggregate 192.168.0.0 255.255.252.0 ? //发布所有聚合路由和被聚合的路由
as-set Generate the route with AS-SET path-attribute //发布检测环路的聚合路由
attribute-policy Set aggregation attributes / //设置聚合路由的属性
detail-suppressed Filter more detail route from updates //只发布聚合路由
origin-policy Filter the originate routes of the aggregate //只将通过路由策略的路由生成聚合路由
suppress-policy Filter more detail route from updates through a Routing policy //只发布聚合路由和通过路由策略的被聚合的路由
(1) 发布所有聚合路由和被聚合的路由
[AR2-bgp]aggregate 192.168.0.0 255.255.252.0
[AR2]dis bgp routing-table 192.168.0.0 255.255.252.0
BGP local router ID : 22.1.1.1
Local AS number : 200
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 192.168.0.0/22:
Aggregated route.
Route Duration: 00h00m30s
Direct Out-interface: NULL0
Original nexthop: 127.0.0.1
Qos information : 0x0
AS-path Nil, origin igp, pref-val 0, valid, local, best, select, active, pre 255
Aggregator: AS 200, Aggregator ID 22.1.1.1
Advertised to such 3 peers:
44.1.1.1
33.1.1.1
12.1.1.1
[AR1]dis bgp routing-table
BGP Local router ID is 11.1.1.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 7
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 11.1.1.1/32 0.0.0.0 0 0 i
*> 55.1.1.1/32 12.1.1.2 0 200 300i
*> 192.168.0.0/22 12.1.1.2 0 200i
*> 192.168.0.0 0.0.0.0 0 0 i
*> 192.168.1.0 0.0.0.0 0 0 i
*> 192.168.2.0 0.0.0.0 0 0 i
*> 192.168.3.0 0.0.0.0 0 0 i
(2)只发布聚合路由
[AR2-bgp]aggregate 192.168.0.0 22 detail-suppressed
[AR2]dis bgp routing-table
BGP Local router ID is 22.1.1.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 7
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 11.1.1.1/32 12.1.1.1 0 0 100i
*>i 55.1.1.1/32 44.1.1.1 0 100 0 300i
*> 192.168.0.0/22 127.0.0.1 0 i
s> 192.168.0.0 12.1.1.1 0 0 100i
s> 192.168.1.0 12.1.1.1 0 0 100i
s> 192.168.2.0 12.1.1.1 0 0 100i
s> 192.168.3.0 12.1.1.1 0 0 100i
[AR2]dis bgp routing-table peer 44.1.1.1 advertised-routes
BGP Local router ID is 22.1.1.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 2
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 11.1.1.1/32 22.1.1.1 0 100 0 100i
*> 192.168.0.0/22 22.1.1.1 100 0 i
(3)只发布聚合路由和通过路由策略的被聚合的路由
ip ip-prefix 192 index 10 permit 192.168.1.0 24
route-policy BGP permit node 10
if-match ip-prefix 192
[AR2-bgp] aggregate 192.168.0.0 255.255.252.0 detail-suppressed suppress-policy BGP
//只发布聚合路由和抑制被匹配的路由,但其他未通过策略的具体路由仍被通告。
[AR2]dis bgp routing-table
BGP Local router ID is 22.1.1.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 7
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 11.1.1.1/32 12.1.1.1 0 0 100i
*>i 55.1.1.1/32 44.1.1.1 0 100 0 300i
*> 192.168.0.0/22 127.0.0.1 0 i
*> 192.168.0.0 12.1.1.1 0 0 100i
s> 192.168.1.0 12.1.1.1 0 0 100i
*> 192.168.2.0 12.1.1.1 0 0 100i
*> 192.168.3.0 12.1.1.1 0 0 100i
[AR2]dis ip ip-prefix 192
Prefix-list 192
Permitted 1
Denied 3
index: 10 permit 192.168.1.0/24
[AR2]
[AR2]dis route-policy BGP
Route-policy : BGP
permit : 10 (matched counts: 1)
Match clauses :
if-match ip-prefix 192
(4)发布检测环路的聚合路由
为了避免路由聚合可能引起的路由环路,BGP设计了AS_Set属性。
AS_Set属性是一种无序的AS_Path属性,标明聚合路由所经过的AS号。当聚合路由重新进入AS_Set属性中列出的任何一个AS时,BGP将会检测到自己的AS号在聚合路由的AS_Set属性中,于是会丢弃该聚合路由,从而避免了路由环路的形成。
[AR2-bgp]aggregate 192.168.0.0 255.255.252.0 detail-suppressed suppress-policy BGP as-set
[AR2]dis bgp routing-table 192.168.0.0 22
BGP local router ID : 22.1.1.1
Local AS number : 200
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 192.168.0.0/22:
Aggregated route.
Route Duration: 00h00m08s
Direct Out-interface: NULL0
Original nexthop: 127.0.0.1
Qos information : 0x0
AS-path 100, origin igp, pref-val 0, valid, local, best, select, active, pre 255
Aggregator: AS 200, Aggregator ID 22.1.1.1
Advertised to such 3 peers:
44.1.1.1
33.1.1.1
12.1.1.1
BGP Local router ID is 44.1.1.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 6
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 11.1.1.1/32 22.1.1.1 0 100 0 100i
*> 55.1.1.1/32 45.1.1.5 0 0 300i
*>i 192.168.0.0/22 22.1.1.1 100 0 100i
*>i 192.168.0.0 22.1.1.1 0 100 0 100i
*>i 192.168.2.0 22.1.1.1 0 100 0 100i
*>i 192.168.3.0 22.1.1.1 0 100 0 100i
此时由于还原起源AS-path的属性,R1就不会学习到汇总以后的路由。
BGP Local router ID is 11.1.1.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 6
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 11.1.1.1/32 0.0.0.0 0 0 i
*> 55.1.1.1/32 12.1.1.2 0 200 300i
*> 192.168.0.0 0.0.0.0 0 0 i
*> 192.168.1.0 0.0.0.0 0 0 i
*> 192.168.2.0 0.0.0.0 0 0 i
*> 192.168.3.0 0.0.0.0 0 0 i
(4)设置聚合路由的属性:给汇总路由设置community
[AR2-bgp] aggregate 192.168.0.0 255.255.252.0 detail-suppressed suppress-policy BGP attribute-policy ORN
route-policy ORN permit node 10
apply origin incomplete //设置origin 属性
[AR2]dis bgp routing-table
BGP Local router ID is 22.1.1.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 7
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 11.1.1.1/32 12.1.1.1 0 0 100i
*>i 55.1.1.1/32 44.1.1.1 0 100 0 300i
*> 192.168.0.0/22 127.0.0.1 0 100?
*> 192.168.0.0 12.1.1.1 0 0 100i
s> 192.168.1.0 12.1.1.1 0 0 100i
*> 192.168.2.0 12.1.1.1 0 0 100i
*> 192.168.3.0 12.1.1.1 0 0 100i
[AR2]dis bgp routing-table 192.168.0.0 22
BGP local router ID : 22.1.1.1
Local AS number : 200
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 192.168.0.0/22:
Aggregated route.
Route Duration: 00h01m32s
Direct Out-interface: NULL0
Original nexthop: 127.0.0.1
Qos information : 0x0
AS-path 100, origin incomplete, pref-val 0, valid, local, best, select, active, pre 255
Aggregator: AS 200, Aggregator ID 22.1.1.1
Advertised to such 3 peers:
44.1.1.1
33.1.1.1
12.1.1.1
(5)只将通过路由策略的路由生成聚合路由
有条件的聚合,仅仅在匹配route-policy时才会产生聚合路由
如果BGP路由表中存在需要汇总的明细路由,才会生成聚合的路由,同时抑制匹配的到明细路由。
ip ip-prefix 194 index 10 permit 192.168.3.0 24
route-policy ORI permit node 10
if-match ip-prefix 194
[AR2-bgp] aggregate 192.168.0.0 255.255.252.0 detail-suppressed origin-policy ORI
Route-policy : ORI
permit : 10 (matched counts: 10)
Match clauses :
if-match ip-prefix 194
BGP Local router ID is 22.1.1.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 8
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 11.1.1.1/32 12.1.1.1 0 0 100i
*>i 55.1.1.1/32 44.1.1.1 0 100 0 300i
*> 192.168.0.0/22 127.0.0.1 0 i
*> 192.168.0.0 12.1.1.1 0 0 100i
*> 192.168.1.0 12.1.1.1 0 0 100i
*> 192.168.2.0 12.1.1.1 0 0 100i
s> 192.168.3.0 12.1.1.1 0 0 100i