-------------------------------------------------------------------------------------
配置:

 
R1的配置:

 
R1#show run
Building configuration...
Current configuration : 657 bytes
!
version 12.3
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R1
!
interface Ethernet0
 ip address 172.1.1.2 255.255.255.0
!        
interface Serial0
 ip address 192.1.1.1 255.255.255.0

 
!
router ospf 10
 log-adjacency-changes
 network 0.0.0.0 255.255.255.255 area 0
!
end

 
------------------------------------------------------------------------------------

 
R2的配置:

 
R2#show run
Building configuration...

 
Current configuration : 749 bytes
!
version 12.3
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R2
!
interface Loopback0
 ip address 2.2.2.2 255.255.255.0
!
interface Serial0
 ip address 192.1.1.2 255.255.255.0
 clock rate 64000
!
interface Serial1
 ip address 202.1.1.2 255.255.255.0
 clock rate 64000
!
router ospf 10
 log-adjacency-changes
 network 0.0.0.0 255.255.255.255 area 0
!
end

 
----------------------------------------------------------------------------------------

 
R3的配置:

 
R3#show run
Building configuration...
Current configuration : 715 bytes
!
version 12.3
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R3
!        
interface Serial0
 ip address 10.1.1.2 255.255.255.0
!
interface Serial1
 ip address 202.1.1.1 255.255.255.0
!
router ospf 10
 log-adjacency-changes
 network 0.0.0.0 255.255.255.255 area 0
!
end

 
R4的配置:

 
R4#show run
Building configuration...
Current configuration : 758 bytes
!
version 12.3
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R4
!
interface Loopback0
 ip address 3.3.3.3 255.255.255.0

!
interface Ethernet0
 ip address 172.1.1.1 255.255.255.0
!
interface Serial0
 ip address 10.1.1.1 255.255.255.0
!
interface Serial1
 ip address 148.1.1.1 255.255.255.0
 shutdown
 clock rate 64000
!
router ospf 10
 log-adjacency-changes
 redistribute connected subnets
 network 10.1.1.1 0.0.0.0 area 0
 network 172.1.1.1 0.0.0.0 area 0
!
end

 
-------------------------------------------------------------------------------------

 
R4重发布自己的直连路由3.3.3.0进到OSPF中,使自己成为一台ASBR,在cisco设备中外部路由存在两种路径OE1和OE2,我们知道OE1是指发布进OSPF中的路由当泛洪到某台路由器时度量值会跟随路径而累加,而OE2则是一个固定的值,cisco默认OE2的度量值是20。

 
现象:

 
下面我们来看一看R2的路由表。

 
---------------------------------------------------------------------------------

 
R2#show ip route ospf
         3.0.0.0/24 is subnetted, 1 subnets
O E2    3.3.3.0 [110/20] via 192.1.1.1, 00:12:39, Serial0

     20.0.0.0/32 is subnetted, 1 subnets
O       20.20.30.1 [110/65] via 202.1.1.1, 00:12:39, Serial1
     172.1.0.0/24 is subnetted, 1 subnets
O       172.1.1.0 [110/74] via 192.1.1.1, 00:12:39, Serial0

 
----------------------------------------------------------------------------------------

 
我们发现R2上存在一条OE2的外部路由,大家注意逃出接口和下一跳。现在细心的人也许会发现一个问题,那就是为什么只有一条去往3.3.3.0的外部路由呢?按照OE2的度量值计算方法,发布进来的外部路由缺省度量值是20。而R1和R3会分别将这样的一条类型5的LSA泛洪给R2,当R2同时收到两条度量值的路由信息应该都会安装进路由表,从而实现负载均衡。而这个例子中OSPF却精妙的选择了去往外部路由的最佳路径。

 
关于这个问题,我们看看拓扑图,注意R4与R3之间的链路是1.544M,而R4与R1之间的链路是10M。现在当我把R1的E0口和R3的S0口的带宽参数都改成1000K,看看在R2的路由表上面会出现什么样的情况。

 
-----------------------------------------------------------------------------
R2#
*Mar  1 02:26:39.267: %SYS-5-CONFIG_I: Configured from console by console
R2#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route

 
Gateway of last resort is not set

 
     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 192.1.1.1, 00:00:04, Serial0
                        [110/20] via 202.1.1.1, 00:00:04, Serial1

     172.1.0.0/24 is subnetted, 1 subnets
O       172.1.1.0 [110/74] via 192.1.1.1, 00:00:04, Serial0
C    202.1.1.0/24 is directly connected, Serial1
     10.0.0.0/24 is subnetted, 1 subnets
O       10.1.1.0 [110/74] via 202.1.1.1, 00:00:04, Serial1
C    192.1.1.0/24 is directly connected, Serial0

 
我们发现,这时候负载均衡实现了。

 
 

 
-------------------------------------------------------------------------------

 
总结:

 
OSPF对外部路由的选路,其实他关键还是在于对ASBR路径的选择,在OSPF的数据库,我们会发现存有ASBR的信息,我们可以使用show ip ospf border-routers来查看。

 
R2#show ip ospf border-routers

 
OSPF Process 10 internal Routing Table

 
Codes: i - Intra-area route, I - Inter-area route

 
i 3.3.3.3 [74] via 192.1.1.1, Serial0, ASBR, Area 0, SPF 34

 
--------------------------------------------------------------------------------------

 
所以我们可以肯定,OSPF在选择如何到达外部路由时,是加入了如何到达ASBR的计算来选路,因此我们推出外部路由的度量值在这个案例中是不起任何作用的(其他情况可能有用,我没验证),所以再次说明了cisco将默认外部路由路径定为OE2的高明之处,想想如果使用的是OE1不但没什么实际作用,反而增加了路由器的运算工作(注:OE1在双点重发布时可能有用