概念:开放式最短路径优先路由.<链路状态路由协议> 无类路由协议,支持VLSM,CIDR,支持安全认证.
OSPF采用分层区域(area 0 & other area ),area 0为主区域,Other area必须与area 0相连.
路由更新方式:组播<224.0.0.5(OSPF_Routers)/224.0.0.6(DR&BDR)>.触发(增量)更新,更新占用带宽低,消耗本地CPU和内存.
SPF(Shortest Path First):最短路径优先算法,每个路由器都将自己看做一颗树的根,依据到达目的地的积累成本计算最短路径.
Cost=10^8/bandwidth (bps)
LSA(Link-State Advertisement):链路状态通告.
LSA确认方式:
1.Explicit Acknowledgment(显式确认):Router在接收来自Neighbor Router LSA后回送Neighbor Router一个包含该LSA信息的Data Update Packet,
2.ImplicitAcknowledgment(隐式确认):Router在接收来自Neighbor Router LSA后给Neighbor Router发送一个LSAck.
OSPF Tables:
1.Neighbor Table:neighbors
2.Link-state DataBase:all of link on the whole network
3.Routing Table:The best Routing path<that is the short path on the network>
OSPF Packet:
Type 1:Hello package: 与邻居建立和维护邻居关系.
Hello-Time:10s(Broadcast network type)/30s(Non-Broadcast network type)
include:RID(Router ID)
AID(Area ID)
Source Router interface IP/Mask
Source Router Authencation Type&Info
Source Router Hello Interval
Source Router Dead Interval Time
Router Priority
DR&BDR
Identifiler <Five>
Other Router ID
Type 2:DBD(DataBase Description):数据库描述分组,描述一个OSPF路由器状态数据库的内容.
Type 3:LSR(Link-State Request):链路状态请求,请求邻居路由器发送器链路状态数据库中的特定项.
Type 4:LSU(Link-State Update):链路状态更新,向邻居路由器发送链路状态通告.
Type 5:LSACK(Link-State ACK):确认收到邻居路由器的LSA.
OSPF Interface State:
1.Down State:停止状态,OSPF没有进入任何状态,等待进入init状态.<接口down可能是路由器没有启动或者接口没有开启>
2.Attempt:尝试状态,介于停止状态和初始状态之间的一种状态,即是接口开启后第一次发送Hello包给邻居路由器建立邻居关系.<TCP/IP卷一中提到了这个状态,个人觉得这个状态没有什么意义>
3.Init State:初始状态,OSPF每10秒钟发送一个type 1的Hello package,收到Hello package的路由器进入init state.
4.Two-way State:双向状态,Hello package中包括已知的邻居列表,当接收到该Hello的路由器发现自己出现在对方发送过来的Hello package中时,进入Two-way state.
5.Exstart State:准启动状态,成为邻居状态,以Hello分组标识路由器的ID来决定主从状态(DR&BDR).
6.Exchange State:交换状态,交换DBD分组描述链路状态数据库,并用LSAck分组确认.
7.Loading State:加载状态,使用type 3 LSR请求完整的信息,然后使用LSU进行回应,LSU分组中含有确切的LSA.最后用type 5 LSAck确认.
8.Full Adjacency State:全连接状态,每一台路由器都保存着一张邻接路由器的数据库.
OSPF Network Type:
1.Point-to-Point:<T1、DS-3、SONET>
2.Broadcast:<LAN、FDDI、令牌环网>
3.NBMA(Non-Broadcast Multi Acess):<X.25、ATM、Frame-Relay>
4.Point-to-Multipoint:<NBMA中的一个特列>
5.Virtual Links:Virtual-link的出现是为了解决OtherArea与Area 0没有直接连接的一种技术,就是在OtherArea区域打一个通道<严格上来说应该不能算是网路类型吧>
OSPF运行步骤:
1.建立路由器邻接关系:进入Two-way状态.
2.选举DR和BDR:优先级+Router ID.
3.发现路由,进入Exstart状态确定主从关系交换链路状态数据库.
4.选择最优路由,SPF算法,cost成本度量.
5.维护路由选择更新.
Router ID:
1.router-id 指令指定
2.loopback 接口
3.物理接口中最高数值的IP(Active)
OSPF Seven Gengerl LSA Type:
1.Router LSA:由区域内的DRRother Router产生的,Router LSA包含了Router所有的接口和链路的状态和开销,以及链路上所有已知的Neighbor Router.只在区域内泛洪扩散.<Check Command:show ip ospf database router>
2.Network LSA:由区域内的DR产生的,Network LSA通告了整个区域内的网络结构,只在区域内泛洪扩散.<Check Command:show ip ospf database network>
3.Network Summary LSA:ABR(Area Border Router)是连接两个不同区域的路由器,NS-LSA由ABR始发的,它包含了不同区域间的网络汇总,是用来通告到达外部区域的最佳路由的信息.<Check Command:show ip ospf database summary>
4.ASBR Summary LSA:ASBR(Autonomous Systerm Boundary Router)是连接OSPF区域同Non-OSPF网络的.在ASBR上做路由重分发已达到OSPF Router能学习到外部网络的信息.该LSA是由ABR始发的,ASBR Summary LSA通告了目的地是一台ASBR而不是一个网络(是不是就可以将这个LSA看成是一个路由条目呢?),其他和NS-LSA一样.<Check Command:show ip ospf database asbr-summary>
5.ASE LSAl(Autonomous System External LSA):始发于ASBR,用来通告到达OSPF AS外部的网络信息.在OSPF AS中泛洪扩散.<Check Command:show ip ospf database external>
7.NSSAE LSA(NSSA External LSA):NSSA(Not-So-Stubby Area,非完全末节区域)内始发于ASBR的LSA通过.只在NSSA中泛洪扩散.<Check Command:show ip ospf database nssa-external>
OSPF configuration Command:
Basic confiure:
router(config)#router ospf Process_ID(Local)
router(config-router)#network network_address mask area area_id {0|n(n≥1)}
other:router(config-if)#ip ospf Process_ID area area_id
Check OSPF config
Router#show ip protocols 检查配置的路由协议
Router#show ip route 显示路由器中的所有路由
Router#show ip ospf interface 显示area-id邻接的信息
Router#show ip ospf neighbor 显示OSPF的邻居
OSPF debug command
Router#debug ip ospf events
Router#debug ip ospf packet
OSPF Interface Priority
Router(config)#interface inter_number
Router(config-if)#ip ospf priority priority_number
OSPF Summary Routing
Router(config-router)#area area_id network_add subnetmask
OSPF Lab:
R1 config:
Router>enable
Router#configure terminal
Router(config)#line console 0
Router(config-line)#logging synchronous
Router(config-line)#exec-timeout 0 0
Router(config-line)#password cisco
Router(config-line)#login
Router(config-line)#line aux 0
Router(config-line)#password cisco
Router(config-line)#login
Router(config-line)#line vty 0 4
Router(config-line)#password cisco
Router(config-line)#login
Router(config-line)#exit
Router(config)#hostname R1
R1(config)#interface e 0/0 #在R1上配置接口e0/0和loopback0
R1(config-if)#ip address 12.12.12.1 255.255.255.0
R1(config-if)#no shutdown
R1(config)#interface lo0
R1(config-if)#ip address 1.1.1.1 255.255.255.255
R1(config-if)#no shutdown
R1(config-router)#router ospf 1 #在R1上起OSPF路由协议
R1(config-router)#network 12.12.12.1 0.0.0.0 area 0
R1(config-router)#netowrk 1.1.1.1 0.0.0.0 area 0
R2 config:
Router>enable
Router#configure terminal
Router(config)#line console 0
Router(config-line)#logging synchronous
Router(config-line)#exec-timeout 0 0
Router(config-line)#password cisco
Router(config-line)#login
Router(config-line)#line aux 0
Router(config-line)#password cisco
Router(config-line)#login
Router(config-line)#line vty 0 4
Router(config-line)#password cisco
Router(config-line)#login
Router(config-line)#exit
Router(config)#hostname R2
R2(config)#interface e 0/0 #在R2上配置接口e0/0和e0/1
R2(config-if)#ip address 12.12.12.2 255.255.255.0
R2(config-if)#no shutdown
R2(config)#interface e 0/1
R2(config-if)#ip address 23.23.23.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-router)#router ospf 1 #在R1上起OSPF路由协议
R2(config-router)#network 12.12.12.2 0.0.0.0 area 0
R2(config-router)#netowrk 23.23.23.2 0.0.0.0 area 1
R3 config:
Router>enable
Router#configure terminal
Router(config)#line console 0
Router(config-line)#logging synchronous
Router(config-line)#exec-timeout 0 0
Router(config-line)#password cisco
Router(config-line)#login
Router(config-line)#line aux 0
Router(config-line)#password cisco
Router(config-line)#login
Router(config-line)#line vty 0 4
Router(config-line)#password cisco
Router(config-line)#login
Router(config-line)#exit
Router(config)#hostname R3
R3(config)#interface e 0/0 #在R2上配置接口e0/0和回环口
R3(config-if)#ip address 23.23.23.3 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#ip ospf 1 area 1 #在e0/0起OSPF,区域为1
R3(config)#interface lo0
R3(config-if)#ip address 3.3.1.3 255.255.255.0
R3(config-if)#no shutdown
R3(config)#interface lo1
R3(config-if)#ip address 3.3.2.3 255.255.255.0
R3(config-if)#no shutdown
R3(config)#interface lo0
R3(config-if)#ip address 3.3.3.3 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#router eigrp 100 #在R3上起EIGRP
R3(config-router)#network 3.3.1.0 0.0.0.255
R3(config-router)#network 3.3.2.0 0.0.0.255
R3(config-router)#network 3.3.3.0 0.0.0.255
R3#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
1.0.0.0/32 is subnetted, 1 subnets
O IA 1.1.1.1 [110/21] via 23.23.23.2, 00:04:50, Ethernet0/0 O IA表示这条路由是Type 3或者是Type 4的LSA通告的
3.0.0.0/24 is subnetted, 3 subnets
C 3.3.1.0 is directly connected, Loopback0
C 3.3.2.0 is directly connected, Loopback1
C 3.3.3.0 is directly connected, Loopback2
23.0.0.0/24 is subnetted, 1 subnets
C 23.23.23.0 is directly connected, Ethernet0/0
12.0.0.0/24 is subnetted, 1 subnets
O IA 12.12.12.0 [110/20] via 23.23.23.2, 00:04:50, Ethernet0/0
我们知道在整个拓扑中R2是ABR,R3是ASBR.我们来看R1学习到的路由.
R1#show ip rou
*Mar 1 00:21:48.199: %SYS-5-CONFIG_I: Configured from console by console
R1#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
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
23.0.0.0/24 is subnetted, 1 subnets
O IA 23.23.23.0 [110/20] via 12.12.12.2, 00:08:29, Ethernet0/0
12.0.0.0/24 is subnetted, 1 subnets
C 12.12.12.0 is directly connected, Ethernet0/0
很明显R1没有学习到R3 三个回环口的路由,这是为什么呢?我在R3起了EIGRP路由,而不同路由协议之间是不能通信,那么为了使R1和R2能学习到外部路由就必须在R3上做路由重分发.
R3(config)#router ospf 1
R3(config-router)#redistribute eigrp 100 subnets
现在来看看R1是否学习到了.
R1#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
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
3.0.0.0/24 is subnetted, 3 subnets
O E2 3.3.1.0 [110/20] via 12.12.12.2, 00:00:00, Ethernet0/0
O E2 3.3.2.0 [110/20] via 12.12.12.2, 00:00:00, Ethernet0/0
O E2 3.3.3.0 [110/20] via 12.12.12.2, 00:00:00, Ethernet0/0
23.0.0.0/24 is subnetted, 1 subnets
O IA 23.23.23.0 [110/20] via 12.12.12.2, 00:14:14, Ethernet0/0
12.0.0.0/24 is subnetted, 1 subnets
C 12.12.12.0 is directly connected, Ethernet0/0
我们可以看到R1的路由表中多了三个O E2的路由条目,这就是通过路由重分布而学习到了R3的三个回环口.我们知道O E2同样也有O E1,那么两者有什么区别呢,我们看实验.
我们在R3上重新做一下重分布,选择metric-type为1.
R3(config-router)#no redistribute eigrp 100 subnets #在OSPF进程下做的
R3(config-router)#redistribute eigrp 100 subnets metric
R3(config-router)#redistribute eigrp 100 subnets metric-
R3(config-router)#redistribute eigrp 100 subnets metric-type 1 #类型1 既是O E1
我们再来看R1:
R1#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
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
3.0.0.0/24 is subnetted, 3 subnets
O E1 3.3.1.0 [110/40] via 12.12.12.2, 00:00:03, Ethernet0/0
O E1 3.3.2.0 [110/40] via 12.12.12.2, 00:00:03, Ethernet0/0
O E1 3.3.3.0 [110/40] via 12.12.12.2, 00:00:03, Ethernet0/0
23.0.0.0/24 is subnetted, 1 subnets
O IA 23.23.23.0 [110/20] via 12.12.12.2, 00:18:40, Ethernet0/0
12.0.0.0/24 is subnetted, 1 subnets
C 12.12.12.0 is directly connected, Ethernet0/0
很快,O E2变成OE1,我们也可以很明显的看出来,O E2的开销是110/20,而O E1的开销是110/40,这多出来的20是从哪儿来的呢?O E2只计算ASBR外部路由的开销,而O E1是将OSPF内部的开销也计算在内了.如果ASBR到OSPF区域只有一个接口的话,选择O E1或者O E2都没有什么关系,但是如果有两个或者多个的时候就建议使用O E1了.


评论