一、网络拓扑
为了深入理解OSPF。如上图,R1、R2、R3处于MA网络中,网段为10.0.0.0/24。每台路由器除了配置接口IP地址外,需要配置L0地址为X.X.X.X/32,同时不将L0通告进任何网络。将EIGRP网络和OSPF网络做双向重分布
二、实验准备
R1#
Int e0/0
Ip address 10.0.0.1 255.255.255.0
No sh
Int e0/1
Ip address 192.168.0.1 255.255.255.0
No sh
Int lo0
Ip address 1.1.1.1 255.255.255.255
Router ospf 1
Router-id 1.1.1.1
int e0/0
ip ospf 1 a 0
int e0/1
ip ospf 1 a 1
int e0/0
ip ospf message 1 md5 epiol
ip ospf auth message
R2#
Int e0/0
Ip address 10.0.0.2 255.255.255.0
No sh
Int e0/1
Ip address 192.168.1.2 255.255.255.0
No sh
Ip address 2.2.2.2 255.255.255.255
int e0/0
ip ospf message 1 md5 epiol
ip ospf auth message
Router ospf 1
Router-id 2.2.2.2
Int e0/0
Ip ospf 1 a 0
Int e0/1
Ip ospf 1 a 2
R3#
Int e0/0
Ip address 10.0.0.3 255.255.255.0
No sh
Int e0/1
Ip address 192.168.2.3 255.255.255.0
No sh
Ip address 3.3.3.3 255.255.255.255
Router ospf 1
Router-id 3.3.3.3
Int e0/0
Ip ospf 1 a 0
Int e0/1
Ip ospf 1 a 3
int e0/0
ip ospf message 1 md5 epiol
ip ospf auth message
R4#
Int e0/0
Ip address 192.168.2.4 255.255.255.0
No sh
Int e0/1
Ip address 192.168.3.4 255.255.255.0
No sh
Ip address 4.4.4.4 255.255.255.255
Router ospf 1
Router-id 4.4.4.4
Red eigrp 1 subnets
Int e0/0
Ip ospf 1 a 3
Router eigrp 1
No auto-summary
Network 192.168.4.0 0.0.0.255
Red ospf 1 metric 10000 100 255 1 1500
R5#
Int e0/0
Ip address 192.168.0.5 255.255.255.0
No sh
Ip address 5.5.5.5 255.255.255.255
Router ospf 1
Router-id 5.5.5.5
Int e0/0
Ip ospf 1 a 1
R6#
Int e0/0
Ip address 192.168.1.6 255.255.255.0
No sh
Ip address 6.6.6.6 255.255.255.255
Router ospf 1
Router-id 6.6.6.6
Int e0/0
Ip ospf 1 a 2
R7#
Int e0/0
Ip address 192.168.3.7 255.255.255.0
No sh
Int e0/1
Ip address 192.168.4.7 255.255.255.0
No sh
Ip address 7.7.7.7 255.255.255.255
Router eigrp 1
No auto-summary
Network 192.168.3.0 0.0.0.255
Network 192.168.4.0 0.0.0.255
三、对标OSPF原理分析
1.查看OSPF信息
查看接口优先级、所属OSPF区域、IP地址/子网掩码、接口cost、state
2.cost计算
2.1 路由cost
以R5 O IA路由为例:
10.0.0.0路由的cost为20,R5 e0/0、R1 e0/0,如下图
192.168.1.0路由的cost为30,结论就是cost值得计算是路由学习途径的入接口总和,上图中的192.168.3.0和192.168.4.0为O E2,重分布进入OSPF后是固定的cost=20
2.2 接口cost
接口cost= (100*1000K)/接口带宽=10
3.组播地址
路由器开启OSPF后,就会自动加入到224.0.0.5和224.0.0.6中
4.DR与BDR选举流程
由于DR和BDR的选举在MA网络(network type BROADCAST)进行,这里的area 0 、area 1、area 2、area 3 都是MA网络,所以选取area 0来解释DR和BDR选举流程。首先R1、R2、R3各自发送hello报文以建立OSPF邻居关系,建立成功后。首先根据HELLO包中的priority来选举BDR,但是一般接口优先级都是不会更改的,默认为1。随后根据OSPF报文中的OSPF header中的router-id来比较大小,router-id大的为DR,router-id次大的为BDR,router-id小的接口为DRother。
tips:检查效果Sh ip ospf events interface generic
四、数据包分析
1.OSPF数据包封装在IP数据报中
2.OSPF header
下图是无认证header
下图是有认证header
3.OSPF data
3.1 hello
Hello目的地址为组播地址(所有开启OSPF的路由器都会监听该地址)224.0.0.5
3.2 DBD
触发DBD:将R1的E0/1口关闭,在重新打开。
正常DBD报文交互5个包:
R1->R5
R5->R1
R1->R5
R5->R1
R1->R5
3.3 LSR
R1->R5:发送LSA首部
3.4 LSU
下图中的具体LSA见LSA格式
3.5 LSACK
4.影响OSPF建立邻居的参数
认证:位于每一个OSPF数据报的header中,为了测试效果,将R1 e0/1接口部署了OSPF认证,而R5 e0/0并没有配置OSPF认证,使得邻居建立时出现问题,以下是R1截图
网络掩码:位于每一个hello包,为了测试效果,将R5 e0/0接口的网络掩码改为/30,并开启debug。在debug ip ospf hello时发现hello包参数不匹配,mask不匹配
Hello time:位于每一个hello包中,为了测试效果,将R5的接口hello time改成20s每次,查看相应的dead time是否更改。可以发现邻居断开,在debug ip ospf hello时发现hello包参数不匹配
特殊区域:R5的OSPF更改为stub区域,而R1的OSPF不更改,导致OSPF邻居dead time超时断开