OSPF在选择外部路由的时候,遵循的原则是:
[1]O E1优于O E2
[2]在同样的情况下,Cost越小越优先
[3]在cost相同的情况下,选择到达ASBR最优的路径
下面来通过实验来验证该规则:
[案例1]当外部路由都是O E1的情况
基本配置:(注意ASBR的配置)
R1: [pre]interface Loopback0 ip address 1.1.1.1 255.255.255.0 ip ospf network point-to-point ! interface Serial1/0 ip address 12.1.1.1 255.255.255.0 ! interface Serial2/0 ip address 13.1.1.1 255.255.255.0 ! router ospf 1 redistribute rip subnets metric-type 1 network 12.1.1.0 0.0.0.255 area 0 ! router rip version 2 network 13.0.0.0 distance 109 (因为RIP的AD大于OSPF 所以重发布到OSPF中, 会发生路由抖动,故将其改详解看等级三实验手册1.3) no auto-summary ! [/pre] |
R2: [pre]interface Loopback0
ip address 2.2.2.2 255.255.255.0
ip ospf network point-to-point
!
interface Serial1/0
ip address 24.1.1.2 255.255.255.0
!
interface Serial2/0
ip address 12.1.1.2 255.255.255.0
!
router ospf 1
network 12.1.1.0 0.0.0.255 area 0
network 24.1.1.0 0.0.0.255 area 0
![/pre] |
R3: [pre]interface Loopback0
ip address 3.3.3.3 255.255.255.0
ip ospf network point-to-point
!
interface Serial1/0
ip address 13.1.1.3 255.255.255.0
!
interface Serial2/0
ip address 35.1.1.3 255.255.255.0
!
router rip
version 2
network 3.0.0.0
network 13.0.0.0
network 35.0.0.0
no auto-summary
![/pre] |
R4: [pre]interface Loopback0
ip address 4.4.4.4 255.255.255.0
ip ospf network point-to-point
!
interface Serial1/0
ip address 45.1.1.4 255.255.255.0
!
interface Serial2/0
ip address 24.1.1.4 255.255.255.0
!
router ospf 1
network 24.1.1.0 0.0.0.255 area 0
network 45.1.1.0 0.0.0.255 area 1
![/pre] |
R5: [pre]interface Loopback0
ip address 5.5.5.5 255.255.255.0
ip ospf network point-to-point
!
interface Serial1/0
ip address 35.1.1.5 255.255.255.0
!
interface Serial2/0
ip address 45.1.1.5 255.255.255.0
!
router ospf 1
redistribute rip subnets metric-type 1
network 45.1.1.0 0.0.0.255 area 1
!
router rip
version 2
network 35.0.0.0
distance 109
no auto-summary
![/pre] |
监视和测试配置:
查看R2的路由表:
[pre]R2#sh ip rou
35.0.0.0/24 is subnetted, 1 subnets
O E1 35.1.1.0 [110/84] via 12.1.1.1, 00:00:25, Serial2/0
2.0.0.0/24 is subnetted, 1 subnets
C 2.2.2.0 is directly connected, Loopback0
3.0.0.0/24 is subnetted, 1 subnets
O E2 3.3.3.0 [110/84] via 12.1.1.1, 00:00:25, Serial2/0
24.0.0.0/24 is subnetted, 1 subnets
C 24.1.1.0 is directly connected, Serial1/0
12.0.0.0/24 is subnetted, 1 subnets
C 12.1.1.0 is directly connected, Serial2/0
13.0.0.0/24 is subnetted, 1 subnets
O E2 13.1.1.0 [110/84] via 12.1.1.1, 00:00:25, Serial2/0
45.0.0.0/24 is subnetted, 1 subnets
O IA 45.1.1.0 [110/128] via 24.1.1.4, 00:00:26, Serial1/0[/pre] |
查看R2的ospf数据库 [pre]R1#sh ip os da
Type-5 AS External Link States
Link ID ADV Router Age Seq# Checksum Tag
3.3.3.0 1.1.1.1 237 0x80000001 0x00D93A 0
3.3.3.0 5.5.5.5 239 0x80000001 0x0061A2 0
13.1.1.0 1.1.1.1 509 0x80000001 0x008588 0
13.1.1.0 5.5.5.5 239 0x80000001 0x000DF0 0
35.1.1.0 1.1.1.1 238 0x80000001 0x006691 0
35.1.1.0 5.5.5.5 381 0x80000001 0x00EDF9 0[/pre] |
可以看到R2从两个ASBR都收到了LSA 5的通告,但是R2选择了从R1走。ASBR通告外部路由默认都是以metric值20通告出去的,但是内部接受的路由器看到是 O E1的外部路由,会加上自己到ASBR的cost值来算出新的metric值,这样实际上在我们来看只要选择到ASBR cost值小的路由器就可以了。
[案例2]当外部路由都是O E2的情况 在ASBR R1和R5上更改重发布命令
[pre]R1(config)#router ospf 1
R1(config-router)#redistribute rip metric-type 2 subnets
R5(config)#router ospf 1
R5(config-router)# redistribute rip metric-type 2 subnets[/pre] |
(注意这里直接改为 redistribute rip subnets是没有效果的,因为前面已经将类型改为E1,这里没有指明类型,是不会改为O E2的;这样写只有原来没有作过重发布,类型默认才会为O E2)
监视和测试配置
[pre]R2#sh ip rou
35.0.0.0/24 is subnetted, 1 subnets
O E2 35.1.1.0 [110/20] via 12.1.1.1, 00:00:25, Serial2/0
2.0.0.0/24 is subnetted, 1 subnets
C 2.2.2.0 is directly connected, Loopback0
3.0.0.0/24 is subnetted, 1 subnets
O E2 3.3.3.0 [110/20] via 12.1.1.1, 00:00:25, Serial2/0
24.0.0.0/24 is subnetted, 1 subnets
C 24.1.1.0 is directly connected, Serial1/0
12.0.0.0/24 is subnetted, 1 subnets
C 12.1.1.0 is directly connected, Serial2/0
13.0.0.0/24 is subnetted, 1 subnets
O E2 13.1.1.0 [110/20] via 12.1.1.1, 00:00:25, Serial2/0
45.0.0.0/24 is subnetted, 1 subnets
O IA 45.1.1.0 [110/128] via 24.1.1.4, 00:00:26, Serial1/0[/pre] |
察看R2的OSPF数据库
[pre]R2#sh ip os da
OSPF Router with ID (2.2.2.2) (Process ID 1)
Type-5 AS External Link States
Link ID ADV Router Age Seq# Checksum Tag
3.3.3.0 1.1.1.1 1540 0x80000001 0x005D36 0
3.3.3.0 5.5.5.5 1551 0x80000001 0x00E49E 0
13.1.1.0 1.1.1.1 1540 0x80000001 0x000984 0
13.1.1.0 5.5.5.5 1551 0x80000001 0x0090EC 0
35.1.1.0 1.1.1.1 1540 0x80000001 0x00E98D 0
35.1.1.0 5.5.5.5 1551 0x80000001 0x0071F5 0[/pre] |
可以看到R2对于每一个外部条目都从两个边界路由器分别学到了,让我们看一下它通过两个ASBR学到3.3.3.0这个路由条目的metric值是多少
[pre]R2#sh ip os da ex 3.3.3.0
OSPF Router with ID (2.2.2.2) (Process ID 1)
Type-5 AS External Link States
Routing Bit Set on this LSA
LS age: 1595
Options: (No TOS-capability, DC)
LS Type: AS External Link
Link State ID: 3.3.3.0 (External Network Number )
Advertising Router: 1.1.1.1
LS Seq Number: 80000001
Checksum: 0x5D36
Length: 36
Network Mask: /24
Metric Type: 2 (Larger than any link state path)
TOS: 0
Metric: 20
Forward Address: 0.0.0.0
External Route Tag: 0
LS age: 1606
Options: (No TOS-capability, DC)
LS Type: AS External Link
Link State ID: 3.3.3.0 (External Network Number )
Advertising Router: 5.5.5.5
LS Seq Number: 80000001
Checksum: 0xE49E
Length: 36
Network Mask: /24
Metric Type: 2 (Larger than any link state path)
TOS: 0
Metric: 20
Forward Address: 0.0.0.0
External Route Tag: 0[/pre] |
可以看到都是20,度量值一样,但是R2并没有作负载均衡,而是选择了从R1到达3.3.3.0网段,由于R2到ASBR R1的cost是64,到另一个ASBR R5的cost是128,所以选择R1是没有疑义的,现在我们将R2到R1的metric值改大,看看R2是否还选择R1
[pre]R2(config)#int s2/0
R2(config-if)#ip ospf cost 200
R2(config-if)#end[/pre] |
重启OSPF进程看结果
[pre]R2#clear ip os pro
Reset ALL OSPF processes? [no]: y
R2#sh ip rou
Gateway of last resort is not set
35.0.0.0/24 is subnetted, 1 subnets
O E2 35.1.1.0 [110/20] via 24.1.1.4, 00:00:20, Serial1/0
2.0.0.0/24 is subnetted, 1 subnets
C 2.2.2.0 is directly connected, Loopback0
3.0.0.0/24 is subnetted, 1 subnets
O E2 3.3.3.0 [110/20] via 24.1.1.4, 00:00:20, Serial1/0
24.0.0.0/24 is subnetted, 1 subnets
C 24.1.1.0 is directly connected, Serial1/0
12.0.0.0/24 is subnetted, 1 subnets
C 12.1.1.0 is directly connected, Serial2/0
13.0.0.0/24 is subnetted, 1 subnets
O E2 13.1.1.0 [110/20] via 24.1.1.4, 00:00:20, Serial1/0
45.0.0.0/24 is subnetted, 1 subnets
O IA 45.1.1.0 [110/128] via 24.1.1.4, 00:00:20, Serial1/0[/pre] |
可以看到R2此时选择了R4作为下一条,也就是接收了R5通告的外部路由条目
[案例3]E1和E2路由共存的情况 下面我们将R1通告的外部路由类型改为 O E1,来验证O E1比O E2优先 [pre]R1(config-router)#redistribute rip subnets metric-type 1[/pre] |
在R2上重启OSPF进程看结果
[pre]R2#clear ip os pro
Reset ALL OSPF processes? [no]: y
R2#sh ip rou
Gateway of last resort is not set
R2#sh ip rou
Gateway of last resort is not set
35.0.0.0/24 is subnetted, 1 subnets
O E1 35.1.1.0 [110/220] via 12.1.1.1, 00:00:01, Serial2/0
2.0.0.0/24 is subnetted, 1 subnets
C 2.2.2.0 is directly connected, Loopback0
3.0.0.0/24 is subnetted, 1 subnets
O E1 3.3.3.0 [110/220] via 12.1.1.1, 00:00:01, Serial2/0
24.0.0.0/24 is subnetted, 1 subnets
C 24.1.1.0 is directly connected, Serial1/0
12.0.0.0/24 is subnetted, 1 subnets
C 12.1.1.0 is directly connected, Serial2/0
13.0.0.0/24 is subnetted, 1 subnets
O E1 13.1.1.0 [110/220] via 12.1.1.1, 00:00:01, Serial2/0
45.0.0.0/24 is subnetted, 1 subnets
O IA 45.1.1.0 [110/128] via 24.1.1.4, 00:00:02, Serial1/0[/pre] |
可以看到R2又一次选择了R1通告的外部路由,此时虽然到R5的cost小,但是没有考虑,
可见优先比较O E1和O E2是首要条件
最后总结一下:(说法不同于开始的规则,只是更简单)
(1)OSPF中外部路由类型不同,优先选择O E1路由
(2)OSPF中外部路由类型相同,看到ASBR的cost值,越小越优先
[注:实际实验效果是这样,也就是我们看拓扑图,可以这样分析;但是路由器实际处理过程还是本贴开始的那个规则更符合实际情况]
重要问题补充说明:
在案例一和案例二中,外部路由类型相同,此时路由器看到ASBR的cost值决定路径,实际上这是OSPF内部选路的问题,从哪 里到达ASBR;而在OSPF内部选路时,第一个原则就是“O路由”>“O IA路由”,而案例二的后半步,在更改了到同一区域ASBR的cost值以后,可以发现走了从O IA路由学习到的ASBR,可见在对ASBR的选路,访问外部路由时,这个原则无效。 |