《CCIE路由和交换认证考试指南(第5版) (第2卷)》——1.3节构建BGP表

本节书摘来自异步社区《CCIE路由和交换认证考试指南(第5版) (第2卷)》一书中的第1章,第1.3节构建BGP表,作者 【美】那比克 科查理安(Narbik Kocharians) , 特里 文森(Terry Vinson) , 瑞克 格拉齐亚尼(Rick Graziani),更多章节内容可以访问云栖社区“异步社区”公众号查看

1.3 构建BGP表
BGP拓扑结构表(topology table)也称为BGP RIB(Routing Information Base,路由信息库),负责维护BGP学到的NLRI(Network Layer Reachability Information,网络层可达性信息)以及相关联的PA信息。其中,NLRI就是普通的IP前缀与前缀长度。本节主要讨论BGP将NLRI注入到路由器BGP表中的处理过程,以及路由器将相关联的PA及NLRI宣告给邻居的方式。

注:

从技术上来说,BGP并不宣告路由,而是宣告PA以及一组共享相同PA值的NLRI。但大多数人都简单地将NLRI称为BGP前缀或BGP路由,本书将同时使用这三种术语。不过,由于BGP表中的BGP路由与IP路由表中的IP路由存在一定的区别,因而为了区分这两种表,本书将严格使用BGP表或IP路由表。

1.3.1 将路由/前缀注入BGP表
毫无疑问,BGP路由器也使用与IGP相同的方法将表项添加到本地BGP表中:利用network命令,通过邻居发送来的更新消息学习拓扑结构信息,或者从其他路由协议进行重分发。接下来将详细解释本地BGP路由器通过各种方法(除了从BGP邻居学习路由之外)向其BGP表添加路由的操作方式。

1.BGP network命令
本节以及下一节假设已经配置了BGP no auto-summary命令,请注意,对于Cisco IOS Software Release 12.3 Mainline来说,no auto-summary命令是默认配置,而早期版本则默认使用auto-summary命令。本章后面的“auto-summary对于redistribute以及network命令的影响”一节将详细讨论auto-summary命令对network命令及redistribute命令的影响。

BGP network路由器子命令与IGP使用的network命令完全不同,BGP network命令的作用是指示路由器的BGP进程完成以下操作:

关键

在路由器的当前IP路由表中查找与network命令中的参数完全匹配的路由,如果存在这样的IP路由,那么就将等价的NLRI注入到本地BGP表中。

按照这种逻辑,可以将IP路由表取出的直连路由、静态路由或IGP路由放到BGP表中,并在今后进行宣告。如果路由器从IP路由表中删除了特定路由,那么BGP也要从BGP表中删除相应的NLRI,并向邻居通告该路由已经被撤销。

请注意,如果配置或默认使用了no auto-summary命令,那么IP路由必须完全匹配。


7bf2e528c22e91530f0523a85ef3897163b9f8bb

例1-4给出了图1-4中R5的network命令示例(由于R5的BGP邻居已经关闭,因而BGP表仅显示了由network命令在R5上创建的BGP表项),可以看出R5利用两条network命令将21.0.0.0/8和22.1.1.0/24添加到了BGP表中。

例1-4 通过network命令将路由安装到BGP表中

! On R5, the network commands specifically match prefixes 21.0.0.0/8 and
! 22.1.1.0/24. The omission of the mask on the first command implies the associated
! classful mask of 255.0.0.0, as the IP address listed (21.0.0.0) is a class A
! address.
router bgp 45
 no synchronization
 bgp log-neighbor-changes
network 21.0.0.0
network 22.1.1.0 mask 255.255.255.0
! The neighbor commands are not shown, as they are not pertinent to the topics
! covered in this example.
! Next, the two routes matched by the network commands are indeed in the IP
! routing table. Note that the route to 21.0.0.0/8 is a connected route, and the
! route to 22.1.1.0/24 is a static route.
R5# show ip route | incl 21 | 22
C   21.0.0.0/8 is directly connected, Loopback20
    22.0.0.0 /24 is subnetted, 1 subnets
S       22.1.1.0 [1/0] via 10.1.5.9
! Below, the prefixes have been added to the BGP table. Note that the NEXT_HOP
! PA has been set to 0.0.0.0 for the route (21.0.0.0/8) that was taken from a
! connected route, with the NEXT_HOP for 22.1.1.0/24 matching the IP route.
R5# show ip bgp
BGP table version is 38, local router ID is 5.5.5.5
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
*> 21.0.0.0        0.0.0.0               0          32768 i
*> 22.1.1.0/24    10.1.5.9               0          32768  i


0a523d23e781cd727826bd5386f39516746fd40e

2.从IGP、静态路由或直连路由重分发路由
BGP子命令redistribute可以重分发静态路由、直连路由以及IGP学到的路由,本节将讨论这些BGP重分发操作的一些细微差别。

由于BGP不使用度量计算的概念,不为去往特定前缀的每条可选路由计算度量,而是使用逐步递进的路径决策进程,通过检查各种PA来确定最佳路由,因而将路由重分发到BGP中时不需要考虑度量的设置问题。不过,路由器可能需要为重分发功能应用路由映射以控制PA,从而影响BGP的路径决策进程。如果为注入BGP的路由分配了度量,那么BGP会将该度量值分配给BGP MED(Multi-Exit Discriminator,多出口鉴别符)PA(通常也将该PA称为度量)。

注:

虽然这并不是BGP的独有特性,但需要记住的是,从IGP重分发路由会从路由表中提取两类路由:通过路由协议学到的路由以及该路由协议与network命令相匹配的直连路由。
例1-5中的R6(如图1-4所示)通过路由重分发操作从EIGRP进程6(由例1-5中的router eigrp 6命令进行配置)安装其BGP表,并且重分发了一条静态路由,R6上的EIGRP仅为网络30~39学习路由。本例的主要目标如下:

为网络31和32重分发EIGRP路由;
将静态路由重分发到网络34并将MED(度量)设置为9;
不能意外地重分发与EIGRP network命令相匹配的直连路由;
使用Cisco IOS Release 12.3默认的no auto-summary设置。
例1-5给出了意外重分发额外路由(由EIGRP network命令所匹配的网络10.0.0.0的直连子网)的错误情况。为了解决这个问题,本例在后面增加了一个路由映射。

例1-5 通过重分发操作安装BGP表

! R6 redistributes EIGRP 6 routes and static routes below, setting the metric on
! redistributed static routes to 9. Note that EIGRP 6 matches subnets 10.1.68.0/24
! and 10.1.69.0/24 with its network command.
router bgp 678
redistribute static metric 9
redistribute eigrp 6
!
router eigrp 6
 network 10.0.0.0
!
ip route 34.0.0.0 255.255.255.0 null0
! Commands unrelated to populating the local BGP table are omitted.
! R6 has met the goal of injecting 31 and 32 from EIGRP, and 34 from static.
! It also accidentally picked up two subnets of 10.0.0.0/8 because EIGRP’s network
! 10.0.0.0 command matched these connected subnets.
R6# show ip bgp
BGP table version is 1, local router ID is 6.6.6.6
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.1.68.0/24       0.0.0.0                     0            32768 ?
*> 10.1.69.0/24       0.0.0.0                     0            32768 ?
*> 31.0.0.0           10.1.69.9              156160            32768 ?
*> 32.1.1.0/24        10.1.69.9              156160            32768 ?
*> 34.0.0.0/24        0.0.0.0                     9            32768 ?
! Below, note the metrics for the two EIGRP routes. The show ip bgp command output
! above shows how BGP assigned the MED (metric) that same value.
R6# show ip route eigrp
    32.0.0.0/24 is subnetted, 1 subnets
D       32.1.1.0 [90/ 156160 ] via 10.1.69.9, 00:12:17, FastEthernet0/0
D   31.0.0.0/8 [90/156160] via 10.1.69.9, 00:12:17, FastEthernet0/0
! Below, the redistribute eigrp command has been changed to the following, using
! a route map to only allow routes in networks in the 30s.
redist eigrp 6 route-map just-30-something
! The route map and ACLs used for the filtering are shown next. As a result, the
! two subnets of 10.0.0.0/8 will not be redistributed into the BGP table.
R6# show route-map
route-map just-30-something , permit, sequence 10
  Match clauses:
   ip address (access-lists): permit-30-39
  Set clauses:
Policy routing matches: 0 packets, 0 bytes
R6# show access-list
Standard IP access list permit-30-39
    10 permit 32.0.0.0, wildcard bits 7.255.255.255 (1538 matches)
    20 permit 30.0.0.0, wildcard bits 1.255.255.255 (1130 matches)

此外请注意,每条路由的NEXT_HOP PA要么与重分发路由的下一跳相匹配,要么就是0.0.0.0(对于直连路由以及指向Null0的路由来说)。

3.auto-summary对于redistribute以及network命令的影响
与IGP相同,BGP auto-summary命令也会创建一条有类汇总路由(只要该汇总路由的任意子网存在)。但是与IGP不同的是,BGP auto-summary路由器子命令仅汇总该路由器通过重分发操作注入的路由,BGP auto-summary命令并不查询拓扑结构中的有类网络边界,也不查询BGP表中的已有路由,而仅在路由器上查询通过redistribute命令和network命令注入的路由。

对于通过redistribute命令或network命令注入的路由来说,两者的处理方式有所不同,这两条命令的处理方式如下。

关键

redistribute命令:如果重分发有类网络的任意子网,那么并不重分发该子网,而是重分发该有类网络的路由。
network命令:如果network命令列出了有类网络号及有类默认掩码或者无掩码,并且该有类网络的子网存在,那么就注入该有类网络的路由。
虽然上述定义很清晰,但是仍然有必要强调以下几点:首先,对于重分发来说,auto-summary命令会导致重分发进程仅将有类网络注入本地BGP表中,而不会注入子网;但是对于network命令来说,即使配置了auto-summary命令,根据本章前面所说的处理方式,仍然会注入子网。除此以外,如果network命令与有类网络号相匹配,那么只要IP路由表中存在该有类网络的至少一个子网,BGP就会注入该有类网络。

例1-6给出了auto-summary命令的影响情况(本例以图1-2中的R5为例),步骤如下。

第1步:通过redistribute命令将10.15.0.0/16注入到BGP中。

第2步:配置自动汇总,清除BGP,此时BGP表中仅剩下10.0.0.0/8。

第3步:禁用自动汇总和重分发。

第4步:配置network 10.0.0.0、network 10.12.0.0 mask 255.254.0.0以及network 10.14.0.0 mask 255.255.0.0命令。由于这3条命令中只有最后一条命令与当前路由精确匹配,因而仅将该路由注入到BGP中。

第5步:启用自动汇总,从而注入10.0.0.0/8以及最初的10.14.0.0/16。

例1-6 自动汇总对路由表的影响

! R5 has shut down all neighbor connections, so the output of show ip bgp only
! shows routes injected on R5.
! Step 1 is below. Only 10.15.0.0/16 is injected by the current configuration. Note
! that the unrelated lines of output have been removed, and route-map only15 only
! matches 10.15.0.0/16.
R5# show run | be router bgp
router bgp 5
 no synchronization
redistribute connected route-map only15
no auto-summary
! Below, note the absence of 10.0.0.0/8 as a route, and the presence of
! 10.15.0.0/16,
! as well as the rest of the routes used in the upcoming steps.
R5# show ip route 10.0.0.0
Routing entry for 10.0.0.0/8, 4 known subnets
  Attached (4 connections)
  Redistributing via eigrp 99, bgp 5
  Advertised by bgp 5 route-map only15
C        10.14.0.0/16 is directly connected, Loopback10
C        10.15.0.0/16 is directly connected, Loopback10
C        10.12.0.0/16 is directly connected, Loopback10
C        10.13.0.0/16 is directly connected, Loopback10
! Only 10.15.0.0/16 is injected into BGP.
R5# show ip bgp
BGP table version is 2, local router ID is 5.5.5.5
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.15.0.0/16  0.0.0.0             0           32768 ?
! Next, step 2, where auto-summary is enabled. Now, 10.15.0.0/16 is no longer
! injected into BGP, but classful 10.0.0.0/8 is.
R5# conf t
Enter configuration commands, one per line. End with CNTL/Z.
R5(config)# router bgp 5
R5(config-router)# auto-summary
R5(config-router)# ^Z
R5# clear ip bgp *
R5# show ip bgp
BGP table version is 2, local router ID is 5.5.5.5
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.0.0.0         0.0.0.0                0            32768 ?
! Now, at step 3, no auto-summary disables automatic summarization, redistribution is
! disabled, and at step 4, the network commands are added. Note that 10.12.0.0/15 is
! not injected, as there is no exact match, nor is 10.0.0.0/8, as there is no exact
! match. However, 10.14.0.0/16 is injected due to the exact match of the prefix and
! prefix length.
R5# conf t
Enter configuration commands, one per line. End with CNTL/Z.
R5(config)# router bgp 5
R5(config-router)# no auto-summary
R5(config-router)# no redist conn route-map only15
R5(config-router)# no redist connected
R5(config-router)# network 10.0.0.0
R5(config-router)# network 10.12.0.0 mask 255.254.0.0
R5(config-router)# network 10.14.0.0 mask 255.255.0.0
R5(config-router)# ^Z
R5# clear ip bgp *
R5# sh ip bgp | begin network
  Network           Next Hop          Metric LocPrf Weight Path
*> 10.14.0.0/16     0.0.0.0                  0            32768 i
! Finally, auto-summary is re-enabled (not shown in the example).
! 10.14.0.0/16 is still an exact match, so it is
! still injected. 10.0.0.0/8 is also injected because of the network 10.0.0.0
! command.
R5# sh ip bgp | begin network
  Network             Next Hop            Metric LocPrf Weight Path
* 10.0.0.0            0.0.0.0                    0           32768 i
* 10.14.0.0/16        0.0.0.0                    0           32768 i

4.手动汇总与AS_PATH路径属性
如前所述,路由器可以通过network命令和路由重分发操作向BGP表添加表项。此外,BGP还支持通过手动路由汇总机制将汇总路由宣告给邻居路由器,使得邻居路由器能够学到其他BGP路由。使用aggregate-address命令的BGP手动汇总与auto-summary完全不同,它可以基于BGP表中的任意路由进行汇总,并创建任意前缀长度的汇总路由,而且并不始终抑制成员子网的宣告(虽然可以这么配置)。

聚合路由必须包含AS_PATH PA(与BGP表中NLRI的要求相似),为了更好地理解该命令的使用方式,需要进一步弄清楚AS_PATH PA。

AS_PATH PA最多包含以下4个组件(称为字段[segment]):

AS_SEQ(AS Sequence,AS序列);
AS_SET;
AS_CONFED_SEQ(AS Confederation Sequence,AS联盟序列);
AS_CONFED_SET。

最常用的字段就是AS_SEQ。AS_SEQ的概念与图1-1中的AS_PATH相似,表示路由在宣告过程中经历的所有有序ASN列表。

不过,aggregate-address命令可以创建AS_SEQ必须为空的汇总路由。如果汇总路由的成员子网拥有不同的AS_SEQ值,那么路由器就无法简单地创建AS_SEQ的精确表示,因而使用空AS_SEQ。但这样做可能会引入路由环路,因为路由器收到更新消息后,会使用AS_PATH(特别是AS_SEQ)的内容,这样就可以忽略包含自身ASN的前缀。

如果汇总路由包含空AS_SEQ,那么可以利用AS_PATH的AS_SET字段来解决上述问题。字段AS_SET保存了所有成员子网的AS_SEQ字段中全部ASN的无序列表。

例1-7首先给出了路由器使用空AS_SEQ的汇总路由的示例,然后给出了利用as-set选项创建AS_SET字段的相同汇总路由。

例1-7 路由聚合和as-set选项

! Note that R3’s routes to network 23 all have the same AS_PATH except one new
! prefix, which has an AS_PATH that includes ASN 678. As a result, R3 will
! create a null AS_SEQ for the summary route.
R3# show ip bgp | include 23
*> 23.3.0.0/20     4.4.4.4        0 45 i
*> 23.3.16.0/20    4.4.4.4        0 45 i
*> 23.3.32.0/19    4.4.4.4        0 45 i
*> 23.3.64.0/18    4.4.4.4        0 45 i
*> 23.3.128.0/17   4.4.4.4        0 45 i
*> 23.4.0.0/16     4.4.4.4        0 45 678 i
! The following command is now added to R3’s BGP configuration:
aggregate-address 23.0.0.0 255.0.0.0 summary-only
! Note: R3 will not have a BGP table entry for 23.0.0.0/8; however, R3 will
! advertise this summary to its peers, because at least one component subnet
! exists.
! R1 has learned the prefix, NEXT_HOP 3.3.3.3 (R3’s update source IP address for
! R1), but the AS_PATH is now null because R1 is in the same AS as R3.
! (Had R3-R1 been an eBGP peering, R3 would have prepended its own ASN.)
! Note that the next command is on R1.

R1# sh ip bgp | begin Network
Network           Next Hop         Metric LocPrf Weight Path
*>i21.0.0.0      3.3.3.3                0     100       0  45 i
*> i23.0.0.0     3.3.3.3                0     100       0  i
! Next, R1 displays the AGGREGATOR PA, which identifies R3 (3.3.3.3) and its AS
! (123) as the aggregation point at which information is lost. Also, the phrase
! "atomic-aggregate" refers to the fact that the ATOMIC_AGGREGATE PA has also
! been set; this PA simply states that this NLRI is a summary.
R1# show ip bgp 23.0.0.0
BGP routing table entry for 23.0.0.0/8, version 45
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Flag: 0x800
Advertised to update-groups:
  2
Local, ( aggregated by 123 3.3.3.3 ), (received & used)
  3.3.3.3 (metric 2302976) from 3.3.3.3 (3.3.3.3)
    Origin IGP, metric 0, localpref 100, valid, internal, atomic-aggregate, best
! R6, in AS 678, receives the summary route from R1, but the lack of information
! in the current AS_PATH allows R6 to learn of the route, possibly causing
! a routing loop. (Remember, one of the component subnets, 23.4.0.0/16, came from
! ASN 678.)

R6# sh ip bgp nei 172.16.16.1 received-routes | begin Network
   Network               Next Hop       Metric LocPrf Weight Path
*> 21.0.0.0          172.16.16.1                          0 123 45 i
*> 23.0.0.0          172.16.16.1                          0 123 i
! The R3 configuration is changed as shown next to use the as-set option.

R3# aggregate-address 23.0.0.0 255.0.0.0 summary-only as-set
! R1 now has the AS_SET component of the AS_PATH PA, which includes an unordered
! list of all autonmous systems from all the component subnets’ AS_PATHs on R3.

R1# sh ip bgp | begin Network
   Network         Next Hop     Metric LocPrf Weight Path
*>i21.0.0.0       3.3.3.3      0        100          0 45 i
*> i23.0.0.0      3.3.3.3      0        100          0 { 45,678} i
! R6 does receive the 23.0.0.0 prefix from R1, then checks the AS_SET PA, notices
! its own ASN (678), and ignores the prefix to avoid a loop.

R6# sh ip bgp nei 172.16.16.1 received-routes | begin Network
   Network        Next Hop             Metric LocPrf Weight Path
*> 21.0.0.0      172.16.16.1                          0 123 45 i
注:

AS_PATH还包含AS_CONFED_SEQ和AS_CONFED_SET字段,相关内容请参见后面的“联盟”一节。
aggregate-address命令在创建汇总路由时采取的操作如下。

关键

如果当前BGP表不包含汇总路由内的任何NLRI路由,那么就不会创建该汇总路由。
如果从聚合路由器的BGP表中撤销了聚合路由的所有成员子网,那么该聚合路由也将被撤销(也就是说,路由器将告诉其邻居,该聚合路由已经无效)。
将汇总路由的NEXT_HOP地址(列在本地BGP表中)设置为0.0.0.0。
分别为每个邻居将汇总路由的NEXT_HOP地址(宣告给邻居)设置为路由器的更新源IP地址。
如果汇总路由中的成员子网拥有相同的AS_SEQ,那么就将汇总路由的AS_SEQ设置为与成员子网的AS_SEQ完全相同。
如果汇总路由中的成员子网的AS_SEQ不同,那么就将新的汇总路由的AS_SEQ设置为空。
配置了as-set选项之后,路由器将为聚合路由创建AS_SET字段,但此时汇总路由的AS_SEQ必须为空。
与常规处理方式一样,如果将汇总路由宣告给eBGP对等体,那么路由器在发送更新消息之前会将自己的ASN附加到AS_SEQ中。
如果使用了summary-only关键字,那么将抑制所有成员子网的宣告操作。如果没有配置summary-only关键字,那么将宣告所有成员子网。如果配置了suppress-map选项,那么将宣告单个子网。
如例1-7所示,图1-4中的R3汇总了路由23.0.0.0/8,然后R3以AS 123作为AS_SEQ中的唯一AS宣告该汇总路由。由于有些成员子网的AS_PATH为45,而有些成员子网的AS_PATH为678 45,因而R3为聚合路由使用的是空AS_SEQ。该例的后面还显示了as-set选项的作用。

注:

还可以通过其他方法添加汇总路由。首先路由器需要创建一条静态路由(通常以接口null0为目的接口),然后通过network命令匹配相应的前缀/长度以注入汇总路由。请注意,该方法不过滤任何成员子网。
表1-6列出了与aggregate-address、auto-summary以及network命令相关的路由汇总特性。

关键


614a7f958680036afcd911e3eda4570229d32656

5.向BGP添加默认路由
本章讨论的最后一种向BGP表添加路由的方法就是将默认路由注入到BGP中。可以采取以下3种方式将默认路由添加到BGP中:

利用network命令注入默认路由;
利用redistribute命令注入默认路由;
利用BGP子命令neighbor neighbor-id default-originate[ route-map route-map-name ]将默认路由注入BGP。
使用network命令将默认路由注入BGP时,本地路由表中必须存在路由0.0.0.0/0,并且需要配置network 0.0.0.0命令。虽然可以通过各种途径学到默认IP路由,但是如果IP路由表删除了默认路由,那么BGP也要从BGP表删除默认路由。

通过重分发方式注入默认路由需要额外配置一条命令:default-information originate。首先,路由表中必须存在默认路由,例如,创建一条指向null0的默认路由。然后,利用redistribute static命令重分发该静态默认路由。需要注意的是,对于默认路由这种特殊情况来说,Cisco IOS要求配置BGP子命令default-information originate。

利用BGP子命令neighbor neighbor-id default-originate[ route-map route-map-name ]将默认路由注入BGP时,不会向本地BGP表添加默认路由,而是向指定邻居宣告默认路由。事实上,该方法默认根本就不检查IP路由表中是否存在默认路由(但是可以检查)。利用route-map选项,被引用的路由映射将检查IP路由表(而不是BGP表)中的表项,如果与路由映射的permit语句相匹配,那么就将该默认路由宣告给邻居。例1-8给出了R1的相关示例,在R1向R3宣告默认路由之前,需要通过route-map check-default来检查默认路由的存在性。

例1-8 利用neighbor default-originate命令向邻居宣告默认路由

! The pertinent parts of the R1 configuration are listed next, with the route map
! matching an IP route to 0.0.0.0/0 with a permit action, enabling the
! advertisement of a default route to neighbor 3.3.3.3 (R3).
router bgp 123
neighbor 3.3.3.3 remote-as 123
neighbor 3.3.3.3 update-source Loopback1
neighbor 3.3.3.3 default-originate route-map check-default
!
ip route 0.0.0.0 0.0.0.0 Null0
!
ip prefix-list def-route seq 5 permit 0.0.0.0/0
!
route-map check-default permit 10
match ip address prefix-list def-route
! R1 indeed has a default route, as seen below.
R1# show ip route | include 0.0.0.0/0
S* 0.0.0.0/0 is directly connected, Null0
! R3 now learns a default route from R1, as seen below.

R3# show ip bgp | begin Network
   Network           Next Hop        Metric LocPrf Weight Path
*> i0.0.0.0          1.1.1.1                    100        0 i

6.ORIGIN路径属性
利用不同的方法将路由注入本地BGP表中时,BGP会分配3种BGP ORIGIN PA代码:IGP、EGP或Incomplete(不完全的)。ORIGIN PA提供了一种一般性的描述信息,说明特定NLRI第一次注入路由器BGP表的方式。show ip bgp命令输出结果的顶部列出了这3种可能取值的说明,而且在每个输出行的最后列出了每条BGP路由的实际ORIGIN代码。表1-7列出了这3种ORIGIN代码的名称、Cisco IOS使用的单字母缩写形式以及为路由分配特定代码的原因。

关键

ORIGIN代码及其含义隐藏了一些与许多人直觉相反的概念。首先,对于从IGP重分发到BGP的路由来说,实际分配的ORIGIN代码是Incomplete。其次,不要将EGP与eBGP相混淆,ORIGIN代码EGP表示外部网关协议,指的是一种非常古老的已被废弃的BGP前身,事实上,如今根本就不应该看到ORIGIN代码EGP。

关键


71ab1d6209b64ef18d759d6c723d948747e5fee6

对于由aggregate-address命令创建的汇总路由来说,其ORIGIN代码也比较复杂,其规则如下:

关键

如果没有使用as-set选项,那么该聚合路由将使用ORIGIN代码i;
如果使用了as-set选项,并且所有被汇总的成员子网的ORIGIN代码均为i,那么该聚合路由的ORIGIN代码为i;
如果使用了as-set选项,并且至少有一个被汇总的成员子网的ORIGIN代码为?,那么该聚合路由的ORIGIN代码为?。
注:

BGP ORIGIN PA为BGP表项的来源提供了相应的描述信息,该信息将用于BGP决策进程。
7.向邻居宣告BGP路由
前面主要讨论了BGP将路由注入本地路由器BGP表中的相关工具。BGP路由器可以从本地BGP表中取出路由并将这些路由的子网宣告给BGP邻居。本节将继续分析BGP表,因为BGP路由宣告进程是从BGP表中提取路由并宣告给邻居路由器的(这些路由会被添加到邻居的BGP表中)。此后将在本章最重要的一节“构建IP路由表”中详细讨论BGP将路由安装到IP路由表中的处理规则。

8.BGP更新消息
BGP表拥有了路由、路径及前缀等信息之后,路由器就要将这些信息宣告给邻居路由器,为此路由器需要向邻居发送BGP更新消息。图1-5给出了BGP更新消息的通用格式。


bbf1085ec473ebec8c52cf9fd76615132f4ffe99

每条更新消息都包含以下3个主要部分。

被撤销路由字段:BGP通过该字段告诉邻居已经失效的路由。
路径属性字段:列出了每条路由的PA信息,如NEXT_HOP和AS_PATH等。
前缀和前缀长度字段:定义每个NLRI。
更新消息的中间部分是一组PA集,更新消息的末尾是共享相同PA集以及PA值的所有前缀(NLRI)。如果路由器需要宣告一组NLRI,而且每个NLRI都至少有一个不同的PA设置,那么就需要为每个NLRI都发送一条独立的更新消息。如果多条路由都共享相同的PA(如特定ISP拥有的前缀),那么就可以在单条更新消息中包含多个NLRI,这样就能大大降低路由器的CPU负荷并减少链路带宽的占用。

9.确定更新消息的内容
路由器根据BGP表的内容构造更新消息的内容,但路由器必须选择将哪些BGP表项的子网宣告给每个邻居,而且每个邻居可能都不一样。表1-8总结了BGP不会将哪些路由包含在发送给每个邻居的路由更新中的相关规则,并在表1-8的后面给出了更为详细的描述信息。


511038a0b97bea71ca248660d9a3431f94295bdf

BGP仅宣告被认为是最佳路由的路由以到达指定子网(NLRI)。如果BGP路由器仅学到一条到达特定前缀的路由,那么路由决策进程将非常简单,但是如果要在去往同一前缀的多条路径中选择最佳路由时,那么BGP将按照冗长的BGP决策进程来确定最佳路由(有关BGP决策进程的详细信息,请参见第2章的“BGP决策进程”一节)。假设所有路由器都没有配置任何影响决策进程的路由策略,那么就可以将BGP决策进程归结为以下4步对比过程。

第1步:选择AS_PATH最短的路由。

第2步:如果AS_PATH长度相同,那么学自eBGP的单条路由将优于一条或多条iBGP路由。

第3步:如果此时仍未选出最佳路由,那么就选择去往NEXT_HOP的IGP度量最小的路由。

第4步:如果IGP度量相同,那么就选择宣告路由器的BGP RID最小的学自iBGP的路由。

除此以外,BGP还会根据NEXT_HOP PA值,将某些路由排除在最佳路由之外。对于最佳路由的候选路由来说,其NEXT_HOP必须以下两者之一:

0.0.0.0,因为该路由注入到了本地路由器之上;
按照该路由器的当前IP路由表可达,也就是说,NEXT_HOP IP地址必须与路由表中的某条路由相匹配。
由于NEXT_HOP PA对于BGP选择到达每个NLRI的最佳路径来说非常重要,因而本节将解释相应的处理规则并给出一些案例。根据将路由宣告给iBGP对等体或eBGP对等体的不同场景,可以将处理规则分为以下两种情况。在默认情况下,如果发送给eBGP对等体,那么就会为每个邻居将NEXT_HOP更改为宣告路由器上的某个IP地址,具体而言,就是更改为与该路由器用作BGP更新消息的源IP地址相同的IP地址。如果发送给iBGP对等体,那么默认操作就是保持NEXT_HOP PA不变。利用表1-9中的命令可以更改这两种默认操作行为。

关键


a11bd3d6da36f120c2fc2860af257be66f3dae8e

请注意,无法通过路由映射来设置NEXT_HOP PA,更改NEXT_HOP PA的唯一方式就是使用表1-9列出的方法。

10.案例:决策进程以及NEXT_HOP对BGP更新消息的影响
本节将通过几个案例说明利用BGP在图1-4所示网络中传播网络31.0.0.0/8的一系列操作过程。R6通过重分发学自R9的EIGRP路由在网络30~39中发起相应的路由(如例1-4所示)。本节将通过这些案例解释不同条件下BGP如何选择更新消息中包含的路由。

第一个案例(如例1-9所示)主要讨论检查R6发送给R1哪些路由、R1收到哪些路由以及R1 BGP表的最终表项的相关命令。第二个案例(如例1-10所示)检查上述相同路由从R1传播给R3的处理情况,包括与R1不更改这些路由的NEXT_HOP PA的默认行为相关的问题。最后一个案例(如例1-11所示)给出了R1使用neighbor3.3.3.3 next-hop-self命令的解决方案,以及对AS 123中的BGP更新消息内容的影响情况。

例1-9 R6利用BGP将网络30-39发送给R1

! R6 has injected the three routes listed below; they were not learned from
! another BGP neighbor. Note all three show up as >, meaning they are the best
! (and only in this case) routes to the destination NLRIs.
R6# show ip bgp
BGP table version is 5, local router ID is 6.6.6.6
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
*> 31.0.0.0         10.1.69.9     156160          32768 ?
*> 32.0.0.0         0.0.0.0                       32768 i
*> 32.1.1.0/24      10.1.69.9     156160          32768 ?
! R6 now lists the routes it advertises to R1—sort of. This command lists R6’s
! BGP table entries that are intended to be sent, but R6 can (and will in this
! case) change the information before advertising to R1. Pay particular attention
! to the Next Hop column, versus upcoming commands on R1. In effect, this command
! shows R6’s current BGP table entries that will be sent to R1, but it shows them
! before R6 makes any changes, including NEXT_HOP.
R6# show ip bgp neighbor 172.16.16.1 advertised-routes
BGP table version is 5, local router ID is 6.6.6.6
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
*> 31.0.0.0      10.1.69.9       156160          32768 ?
*> 32.0.0.0      0.0.0.0                         32768 i
*> 32.1.1.0/24   10.1.69.9       156160          32768 ?
Total number of prefixes 3
! The next command (R1) lists the info in the received BGP update from R6. Note
! that the NEXT_HOP is different; R6 changed the NEXT_HOP before sending the
! update, because it has an eBGP peer connection to R1, and eBGP defaults to set
! NEXT_HOP to itself. As R6 was using 172.16.16.6 as the IP address from which to
! send BGP messages to R1, R6 set NEXT_HOP to that number. Also note that R1 lists
! the neighboring AS (678) in the Path column at the end, signifying the AS_PATH
! for the route.

R1# show ip bgp neighbor 172.16.16.6 received-routes
BGP table version is 7, local router ID is 111.111.111.111
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
*> 31.0.0.0      172.16.16.6         156160              0  678 ?
*> 32.0.0.0      172.16.16.6              0              0 678 i
*> 32.1.1.0/24   172.16.16.6         156160              0 678 ?
Total number of prefixes 3
! The show ip bgp summary command lists the state of the neighbor until the
! neighbor becomes established; at that point, the State/PfxRcd column lists the
! number of NLRIs (prefixes) received (and still valid) from that neighbor.
R1# show ip bgp summary | begin Neighbor
Neighbor      V  AS  MsgRcvd MsgSent   TblVer   InQ OutQ Up/Down State/PfxRcd
2.2.2.2       4  123    55    57      7     0   0 00:52:30     0
3.3.3.3       4  123    57    57      7     0   0 00:52:28     3
172.16.16.6   4  678    53    51      7     0   0 00:48:50     3
! R1 has also learned of these prefixes from R3, as seen below. The routes through
! R6 have one AS in the AS_PATH, and the routes through R3 have two autonmous
! systems, so the routes through R6 are best. Also, the iBGP routes have an "i" for
! "internal" just before the prefix.
R1# show ip bgp
BGP table version is 7, local router ID is 111.111.111.111
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
* i31.0.0.0         3.3.3.3            0       100        0 45 678 ?
*>                  172.16.16.6   156160                  0 678 ?
* i 32.0.0.0        3.3.3.3            0       100        0 45 678 i
*>                  172.16.16.6        0                  0 678 i
* i 32.1.1.0/24     3.3.3.3            0       100        0 45 678 ?
*>                  172.16.16.6   156160                  0 678 ?

例1-9解释了查看发送给邻居的更新消息内容的方式(使用show ip bgp neighbor advertised-routes命令),以及查看从邻居接收到的更新消息内容的方式(使用show ip bgp neighbor received-routes命令)。RFC 1771建议将BGP RIB划分为从每个邻居接收到的更新消息以及发送给每个邻居的更新消息。大多数实现情况(包括Cisco IOS)都采用单个RIB,并通过标记来识别发送给每个邻居的表项以及从每个邻居接收到的表项。

注:

为了保证received-routes选项的正常工作,必须在使用该命令的路由器上为对端邻居配置BGP子命令neighbor neighbor-id soft-reconfiguration inbound。
虽然携带advertised-routes选项的show ip bgp neighbor命令可以列出将要宣告给指定邻居的BGP表项,但是该命令的输出结果无法显示每条BGP表项的PA变化情况。例如,R6的showip bgp neighbor 172.16.16.1 advertised-routes命令列出的网络31/8的NEXT_HOP为10.1.69.9,后来R6在发送实际的更新消息之前更改了该NEXT_HOP PA,此时的NEXT_HOP为172.16.16.6。

从例1-9的最后可以看出,对于网络30-39中的3个前缀来说,虽然R1知道每个前缀的两条路径(AS_PATH 678和45-678),但每种情况下都只选择AS_PATH最短(经R6)的路径作为最佳路径。请注意,show ip bgp命令输出结果中的“>”表示该路由是R1的最佳路由。接下来的例1-10显示了R3的最佳路由选择结果,这些结果可能会让人大感意外。

例1-10 检查R3的BGP表

! R1 now updates R3 with R1’s "best" routes
R1# show ip bgp neighbor 3.3.3.3 advertised-routes| begin Network
   Network        Next Hop          Metric LocPrf   Weight Path
*> 31.0.0.0   172.16.16.6          156160               0 678 ?
*> 32.0.0.0   172.16.16.6               0               0 678 i
*> 32.1.1.0/24  172.16.16.6        156160               0 678 ?
Total number of prefixes 3
! R3 received the routes, but R3’s best routes to each prefix point back to
! R4 in AS 45, with AS_PATH 45-678, which is a longer path. The route through R1
! cannot be "best" because the NEXT_HOP was sent unchanged by iBGP neighbor R1.

R3# show ip bgp
BGP table version is 7, local router ID is 3.3.3.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
*> 31.0.0.0         4.4.4.4                                  0 45 678 ?
* i                 172.16.16.6          156160   100        0 678 ?
*> 32.0.0.0         4.4.4.4                                  0 45 678 i
* i                 172.16.16.6               0   100        0 678 i
*> 32.1.1.0/24      4.4.4.4                                  0 45 678 ?
* i                 172.16.16.6          156160   100        0 678 ?
! Proof that R3 cannot reach the next-hop IP address is shown next.
R3# ping 172.16.16.6

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.16.6, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)

例1-10不但列出了show ip bgp命令输出结果中一些不好理解的术语,而且还显示了BGP的重要设计选项。首先,虽然show ip bgp命令输出结果中显示的“*”表示“有效”,但实际上仅表示该路由是候选可用路由,在该路由确实可用并被添加到IP路由表中之前,其NEXT_HOP必须可达。在某些情况下,show ip bgp命令认为“有效”的路由可能并不是可用路由,例1-10给出的就是这样的例子。

为了保证路由确实有效,每条BGP路由的NEXT_HOP都必须可达。在全部采用默认设置的情况下,从iBGP学到的路由的NEXT_HOP IP地址就是最后宣告该路由的eBGP路由器的IP地址。例如,R3经R1去往31.0.0.0/8的路由的NEXT_HOP字段列出的就是R6的IP地址(172.16.16.6)。但不幸的是,R3并没有去往172.16.16.6的路由,因而BGP不会将该路由视为“最佳路由”。

此时可以采取以下两种简单方法来解决上述问题:

关键

使eBGP邻居的IP地址可达(实现方式是将该子网宣告到IGP中);
在指向iBGP对等体的neighbor命令中使用next-hop-self选项。
第一种解决方案通常很容易实现,这是因为很多eBGP邻居都在它们的neighbor命令中使用接口IP地址,因而NEXT_HOP地址都位于与该AS直连的子网中。例如,R1直连172.16.16.0/24,因而R1可以很简单地将该直连子网宣告到该AS内的IGP中。

请注意,如果为BGP邻居使用环回接口地址,那么该解决方案就可能会出现问题。例如,如果R1被配置为引用R6的环回接口IP地址6.6.6.6,并且该环回接口处于工作状态,那么R1就必须拥有去往6.6.6.6的路由,但R1很可能没有被宣告去往ASN 123中的6.6.6.6的路由。

第二种解决方案是让路由器将NEXT_HOP PA更改为自身的某个IP地址,该地址极有可能已经存在于邻居的IP路由表中,该解决方案对于为eBGP对等体使用环回接口地址来说也同样适用。例1-11给出了本解决方案的配置示例,例中的R1通过neighbor next-hop-self命令将自身(1.1.1.1)宣告为NEXT_HOP。由于R3拥有到达1.1.1.1的路由,克服了“NEXT_HOP不可达问题”,因而R3更改了自己的最佳路由选择。

虽然例1-11主要说明的是iBGP对等体将NEXT_HOP设置为自身的配置方式,但该例也很好地解释了BGP确定何时将路由宣告给iBGP对等体的决策方式。例1-11的处理次序如下(通过相应的命令输出结果可以看出这些事件)。

第1步:本例是例1-10的延续,R1将R6作为下一跳来宣告路由,并且R3无法将这些路由用作最佳路由。

第2步:由于R3的最佳路由是eBGP路由(经R4),因而允许R3将这些路由宣告给R2。

第3步:然后R1更改其配置,使用next-hop-self选项。

第4步:此时R3能够将学自R1的路由用作R3的最佳路由。

第5步:由于此时R3的新最佳路由是iBGP路由,因而R3无法将最佳路由宣告给这些网络。

例1-11 R3将网络30-39宣告给R2,然后R3撤销这些路由

! (Step 1): At this point, R3 still believes its best route to all three prefixes
! in the 30s is through R4; as those are eBGP routes, R3 advertises all three
! routes to iBGP peer R2, as seen next.
R3# show ip bgp neighbor 2.2.2.2 advertised-routes
BGP table version is 7, local router ID is 3.3.3.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
*> 31.0.0.0      4.4.4.4                            0 45 678 ?
*> 32.0.0.0      4.4.4.4                            0 45 678 i
*> 32.1.1.0/24   4.4.4.4                            0 45 678 ?
Total number of prefixes 3
! (Step 2) R2 lists the number of prefixes learned from R3 next (3).

R2# show ip bgp summary | begin Neighbor
Neighbor    V   AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
1.1.1.1     4  123    212       210        7   0     0 03:27:59        3
3.3.3.3     4  123    213       211        7   0     0 03:28:00        3
! (Step 3) R1 now changes to use next-hop-self to peer R3.

R1# conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)# router bgp 123
R1(config-router)# neigh 3.3.3.3 next-hop-self
! (Step 4) R3 now lists the routes through R1 as best, because the new
! NEXT_HOP is R1’s update source IP address, 1.1.1.1, which is reachable by R3.

R3# show ip bgp
BGP table version is 10, local router ID is 3.3.3.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
*  31.0.0.0     4.4.4.4                                    0 45 678 ?
*>i             1.1.1.1            156160      100         0 678 ?
*  32.0.0.0     4.4.4.4                                    0 45 678 i
*>i             1.1.1.1                 0      100         0 678 i
*  32.1.1.0/24  4.4.4.4                                    0 45 678 ?
*>i             1.1.1.1            156160      100         0 678 ?
! (Step 5) First, note above that all three "best" routes are iBGP routes, as noted
! by the "i" immediately before the prefix. R3 only advertises "best" routes, with
! the added requirement that it must not advertise iBGP routes to other iBGP peers.
! As a result, R3 has withdrawn the routes that had formerly been sent to R2.
R3# show ip bgp neighbor 2.2.2.2 advertised-routes

Total number of prefixes 0
! The next command confirms on R2 that it no longer has any prefixes learned from
! R3.
R2# show ip bgp summary | begin Neighbor
Neighbor  V  AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
1.1.1.1   4  123     213   211    7   0   0  03:28:44     3
3.3.3.3   4  123     214   211    7   0   0  03:28:46     0

11.在BGP更新消息中宣告路由的规则小结
BGP路由器在更新消息中发送路由时,需要遵循如下规则。

关键

仅发送BGP表中列出的最佳路由。
向iBGP邻居发送路由时,不能宣告从其他iBGP邻居学到的路径。
不宣告已被抑制或被阻尼的路由。
不宣告已被相应配置过滤掉的路由。
本节重点讨论的是前两条规则,后两条规则的相关内容不在本书写作范围之内。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
通过《CCIE路由交换认证考试指南》,你可以了解关于CCIE路由交换笔试以及通信与服务笔试所涉及的全部知识点:一般路由概念,如OSI模型、网络互连设备以及路由选择协议的特点等。快速以太网、吉比特以太网和无线局域网。透明桥接、VLAN和VLAN中继。帧中继、ATM和SONET/SDH。RIP、IGRP、EIGRP。OSPF和IS-IS。BGP路由反射器和联盟。队列、MPLS、CAR和流量整形。IP多播、IP优先级和多服务网络。防火墙、加密以及其它的安全主题。, CCIE网络界炙手可热的认证。获取CCIE认证非常困难,因而在业界拥有无可比拟的声誉。要准备CCIE考试,你必须花大量的时间学习广泛的技术知识,进而在现实网络中加以实践,然后才可以去参加CCIE路由交换的笔试。《CCIE路由交换认证考试指南》涵盖了CCIE路由交换以及通信与服务笔试要求的所有知识点,包括网络理论、设备操作、桥接和局域网交换、WAN、IP和IP路由选择协议、安全性及多业务网络。, 《CCIE路由交换认证考试指南》由CCIE们编写和审校,有助于你理解和掌握通过考试必需的知识。通过每个章关于每个知识点的小测验,可以优化你的学习时间。每章的最后提供了关键概念的回顾,有助于加强记忆。每章的“问题与答案”,可以检验你对知识的理解程度,并且可以在一系列场景中,检验你对知识的吸收和利润,随书的光盘中有模拟测验,包含200多道测验题,你可以选择感兴趣的专题。加上经验和培训,这《CCIE路由交换认证考试指南》可以让你掌握CCIE笔试所需的知识,从而向CCIE进一步靠近。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值