bgp deterministic-med

bgp deterministic-med(commands one)

bgp always-compare-med(commands two)

测试版本IOS Version 12.4(13b)

185639456.png

配置

预配置R1R2之间为12.0.0.0/24,以此类推,R5lo05.5.5.5.

R1的配置

router bgp 1

no  synchronization

bgp router-id 1.1.1.1

bgp log-neighbor-changes

neighbor 12.0.0.2 remote-as 2

neighbor 13.0.0.3 remote-as 2

neighbor 14.0.0.4 remote-as 3

no  auto-summary

R2的配置

router bgp 2

no  synchronization

bgp router-id 2.2.2.2

bgp log-neighbor-changes

neighbor 12.0.0.1 remote-as 1

neighbor 12.0.0.1 route-map xx out

neighbor 25.0.0.5 remote-as 4

no  auto-summary

R3的配置

router bgp 2

no  synchronization

bgp router-id 3.3.3.3

bgp log-neighbor-changes

neighbor 13.0.0.1 remote-as 1

neighbor 13.0.0.1 route-map xx out

neighbor 35.0.0.5 remote-as 4

no  auto-summary

R4的配置

router bgp 3

no  synchronization

bgp router-id 4.4.4.4

bgp log-neighbor-changes

neighbor 14.0.0.1 remote-as 1

neighbor 14.0.0.1 route-map xx out

neighbor 45.0.0.5 remote-as 4

no  auto-summary

R5的配置

router bgp 3

no  synchronization

bgp router-id 4.4.4.4

bgp log-neighbor-changes

neighbor 14.0.0.1 remote-as 1

neighbor 14.0.0.1 route-map xx out

neighbor 45.0.0.5 remote-as 4

no  auto-summary

以上两命令有4(官方)使用方式

1:两个命令都不用

2:只使用命令一

3:只使用命令二

4:使用命令一和命令二

解释:

1.两个命令都不用

R1#sh ip b  5.5.5.5

BGP routing  table entry for 5.5.5.5/32, version 24

Paths: (3  available, best #3, table Default-IP-Routing-Table)

Advertised to update-groups:

1

2 4

12.0.0.2 from 12.0.0.2 (2.2.2.2)

Origin IGP, metric 120, localpref 100,  valid, external

3 4

14.0.0.4 from 14.0.0.4 (4.4.4.4)

Origin IGP, metric 100, localpref 100,  valid, external

2 4

13.0.0.3 from 13.0.0.3 (3.3.3.3)

Origin IGP, metric 110, localpref 100,  valid, external, best

默认情况下,不比较MED,因为默认情况下来自不同AS的目标metric为空,由于使用route-map让其有了metric属性,这时情况分为以下2

1.相同AS之间,比较metric,比如将R1R4 断掉,无论你的刷新R3bgp的进程多少次,来自R3的目标前缀永远为best

R1(config)#int    f2/0

R1(config-if)#sh

R1#sh ip b    5.5.5.5

BGP routing    table entry for 5.5.5.5/32, version 28

Paths: (2    available, best #1, table Default-IP-Routing-Table)

Flag: 0x4840

Advertised to update-groups:

1

2 4

13.0.0.3 from 13.0.0.3 (3.3.3.3)

Origin IGP, metric 110, localpref    100, valid, external, best

2 4

12.0.0.2 from 12.0.0.2 (2.2.2.2)

Origin IGP, metric 120, localpref    100, valid, external

R3#cle ip b *

R1#sh ip b    5.5.5.5

BGP routing    table entry for 5.5.5.5/32, version 29

Paths: (1    available, best #1, table Default-IP-Routing-Table)

Flag: 0x4840

Advertised to update-groups:

1

2 4

12.0.0.2 from 12.0.0.2 (2.2.2.2)

Origin IGP, metric 120, localpref    100, valid, external, best

//这时下一跳为R2的路径为best,当R3的邻居关系正常后,如下:

R1#sh ip b    5.5.5.5

BGP routing    table entry for 5.5.5.5/32, version 30

Paths: (2    available, best #1, table Default-IP-Routing-Table)

Advertised to update-groups:

1

2 4

13.0.0.3 from 13.0.0.3 (3.3.3.3)

Origin IGP, metric 110, localpref    100, valid, external, best

2 4

12.0.0.2 from 12.0.0.2 (2.2.2.2)

Origin IGP, metric 120, localpref    100, valid, external

2.不同AS之间(AS长度相同),使用bgp的路由决策一共11条。

上例有2个不同的ASAS(path)2 4 and AS(path)3 4.

Bgp路由决策http://starshomes.blog.51cto.com/3202512/1123964

2.只使用命令一

router bgp 1

no synchronization

bgp router-id 1.1.1.1

bgp log-neighbor-changes

bgp deterministic-med

neighbor 12.0.0.2 remote-as 2

neighbor 13.0.0.3 remote-as 2

neighbor 14.0.0.4 remote-as 3

no auto-summary

预览bgp

R1#sh ip b    5.5.5.5

BGP routing    table entry for 5.5.5.5/32, version 32

Paths: (3    available, best #1, table Default-IP-Routing-Table)

Advertised to update-groups:

1

2 4entry1

13.0.0.3 from 13.0.0.3 (3.3.3.3)

Origin IGP, metric 110, localpref    100, valid, external, best

2 4entry2

12.0.0.2 from 12.0.0.2 (2.2.2.2)

Origin IGP, metric 120, localpref    100, valid, external

3 4entry3

14.0.0.4 from 14.0.0.4 (4.4.4.4)

Origin IGP, metric 100, localpref    100, valid, external

//不考虑谁是best,先讲命令的用法

1.此命令会将相同的AS路径分为一个组,比如上例AS(path)2 4 and AS(path)3 4在一个组里选择出最小的metric

2.AS(path)2 4 里选择出entry1,因为entry1 metric最小,再在 AS(path)3 4选择出entry3因为只有它一个

3.再比较bgp路由决策的7-11条,只到比较出best路径。

Bgp路由决策http://starshomes.blog.51cto.com/3202512/1123964

R1#cle ipb *

R1#sh ip b    5.5.5.5

BGP routing    table entry for 5.5.5.5/32, version 2

Paths: (3 available,    best #1, table Default-IP-Routing-Table)

Advertised to update-groups:

1

2 4

13.0.0.3 from 13.0.0.3 (3.3.3.3)

Origin IGP, metric 110, localpref    100, valid, external, best

2 4

12.0.0.2 from 12.0.0.2 (2.2.2.2)

Origin IGP, metric 120, localpref 100,    valid, external

3 4

14.0.0.4 from 14.0.0.4 (4.4.4.4)

Origin IGP, metric 100, localpref    100, valid, external

R3#cle ip b *

R1#sh ip b    5.5.5.5

BGP routing    table entry for 5.5.5.5/32, version 3

Paths: (2 available,    best #1, table Default-IP-Routing-Table)

Flag: 0x4840

Advertised to update-groups:

1

2 4

12.0.0.2 from 12.0.0.2 (2.2.2.2)

Origin IGP, metric 120, localpref    100, valid, external, best

3 4

14.0.0.4 from 14.0.0.4 (4.4.4.4)

Origin IGP, metric 100, localpref    100, valid, external

R1R3的邻居关系建立后,来自R3的前缀仍然为best

R1#sh ip b    5.5.5.5

BGP routing    table entry for 5.5.5.5/32, version 4

Paths: (3    available, best #1, table Default-IP-Routing-Table)

Flag: 0x4840

Advertised to update-groups:

1

2 4

13.0.0.3 from 13.0.0.3 (3.3.3.3)

Origin IGP, metric 110, localpref    100, valid, external, best

2 4

12.0.0.2 from 12.0.0.2 (2.2.2.2)

Origin IGP, metric 120, localpref 100,    valid, external

3 4

14.0.0.4 from 14.0.0.4 (4.4.4.4)

Origin IGP, metric 100, localpref    100, valid, external

//在只使用此命令时,bgp的表项会发生一点变化,将不在以新到老的时间来排列,上例2 4排列完后再列出3 4 ,一旦3 4 组里的所有路由刷新后就会排列在2 4之前

R2#cle ip b *

R3#cle ip b *

R1#sh ip b    5.5.5.5

BGP routing    table entry for 5.5.5.5/32, version 5

Paths: (1    available, best #1, table Default-IP-Routing-Table)

Flag: 0x4860

Advertised to update-groups:

1

3 4

14.0.0.4 from 14.0.0.4 (4.4.4.4)

Origin IGP, metric 100, localpref 100,    valid, external, best

R1R2R3的关系建立后

R1#sh ip b    5.5.5.5

BGP routing    table entry for 5.5.5.5/32, version 5

Paths: (3    available, best #3, table Default-IP-Routing-Table)

Advertised to update-groups:

1

2 4

13.0.0.3 from 13.0.0.3 (3.3.3.3)

Origin IGP, metric 110, localpref    100, valid, external

2 4

12.0.0.2 from 12.0.0.2 (2.2.2.2)

Origin IGP, metric 120, localpref    100, valid, external

3 4

14.0.0.4 from 14.0.0.4 (4.4.4.4)

Origin IGP, metric 100, localpref    100, valid, external, best

 

3.只使用命令二

无论如何都会选择出metric最小的

R1#sh ip b    5.5.5.5

BGP routing    table entry for 5.5.5.5/32, version 2

Paths: (3    available, best #2, table Default-IP-Routing-Table)

Flag: 0x820

Advertised to update-groups:

1

2 4

13.0.0.3 from 13.0.0.3 (3.3.3.3)

Origin IGP, metric 110, localpref    100, valid, external

3 4

14.0.0.4 from 14.0.0.4 (4.4.4.4)

Origin IGP, metric 100, localpref    100, valid, external, best

2 4

12.0.0.2 from 12.0.0.2 (2.2.2.2)

Origin IGP, metric 120, localpref 100,    valid, external

刷新两个较小metric的邻居关系

R3#cle ip b *

R4#cle ip b *

R1#sh ip b    5.5.5.5

BGP routing    table entry for 5.5.5.5/32, version 6

Paths: (1    available, best #1, table Default-IP-Routing-Table)

Flag: 0x4860

Advertised to update-groups:

1

2 4

12.0.0.2 from 12.0.0.2 (2.2.2.2)

Origin IGP, metric 120, localpref    100, valid, external, best

R1R2andR3关系建立后

R1#sh ip b    5.5.5.5

BGP routing    table entry for 5.5.5.5/32, version 7

Paths: (3    available, best #2, table Default-IP-Routing-Table)

Flag: 0x4860

Advertised to update-groups:

1

2 4

13.0.0.3 from 13.0.0.3 (3.3.3.3)

Origin IGP, metric 110, localpref    100, valid, external

3 4

14.0.0.4 from 14.0.0.4 (4.4.4.4)

Origin IGP, metric 100, localpref    100, valid, external, best

2 4

12.0.0.2 from 12.0.0.2 (2.2.2.2)

Origin IGP, metric 120, localpref    100, valid, external

 

4.两个都用

AS(path)2 4中选择出entry1再会在AS(path)3 4选择出entry3之后,再一次比较entry1entry2metric(因为bgp always-compare-med开启),小的为best

5.最后备注

在只使用命令二和两个使用都使用时(小3和小4节)的结果都一样,最终都会选择出metric最小的,但是bgp会做出不同的决策过程