Cisco OSPF 总结 (1)

  声明:通过本文你将了解到OSPF的一些基本理论知识和基本配置方法,如有错误的地方还请指出。  文章部分资料出自思科官网以及《TCP/IP路由技术(第一卷)》。

OSPF基本简介 

  OSPF 全称:Open Shortest Path First , 即:开放式最短路径优先。该协议是工作在IP网络层的一套内部网关路由协议,最先由IETF(互联网工程任务小组)开发,该协议在 RFC 2328 中有定义。

  OSPF是一套基于链路状态的路由协议,什么是链路状态?我们可以认为,一条链路是从路由器的一个接口出发的,而该链路的状态是接口的描述信息和该链路所连邻居的信息。一个接口的描述信息包括IP地址、掩码、网络类型、邻居状态等。这些描述信息构成了所谓的链路状态,而OSPF会同步这些链路状态,这些同步信息也就是所谓的链路状态数据库。

OSPF路径算法 

  OSPF的选路结果是使用Dijkstra的SPF(路径优先算法)所产生的 ,该算法本身是相当复杂的,我们并不对其进行讨论,我们只关注OSPF的选路过程。OSPF初始化时会收集自己的所有链路状态,并生成生成链路状态通告。所有的路由器使用组播地址洪泛交换链路状态。每个路由器接收链路状态更新后将其存储在其链路状态数据库副本,然后更新到到其他路由器。在每个路由器数据库建成后,路由器计算出到达所有目的地的最短路径树。路由器使用Dijkstra算法,以计算最短路径树。最后通过对比所有计算结果,将最优路径添加到路由表中。 在OSPF网络中如果拓扑没有发生变化,OSPF的应该是很安静。如若发生变化,该路径将通过Dijkstra算法重新计算,以寻找最短路径。该算法的结果将是每个路由器都有自己独立的链路状态树,但是他们都使用同一个链路状态数据库来计算。

OSPF的Cost

  OSPF的开销与数据流向方向所途径的所有接口的带宽有关,其关系是成反比的,带宽越大开销越小,开销越小路由越优先。计算公式是 Cost= 100000000bit/bandwith 。例如在T1链路中,链路带宽是1.544M 则Cost为100000000/1544000 ≈ 64.

OSPF区域类型和路由类型

  OSPF是有区域的,主要有两大区域:骨干区域和非骨干区域。OSPF非骨干区域之间必须铜鼓骨干区域才能实现同步链路状态数据库。骨干区域就是所说的area 0 域。

  OSPF路由类型:

  · 内部路由器(Internal Router)——是指所有接口都属于同一个区域的路由器。

  · 区域边界路由器(Area Border Routers,ABR)——是指连接一个或多个区域到骨干区域的路由器,这些路由器负责不同区域间的通信。因而ABR路由器总是至少有一个接口是属于骨干区域的,而且必须为被一个与之相连的区域维护不同的链路状态数据库。ABR路由器会汇总与它相连的区域的拓扑信心给骨干区域,然后将这些汇总信息传给其他区域。

  ·骨干路由器(Backbone Router)——是指至少有一个接口是和骨干区域连接的路由器。这个定义意味着ABR路由器也可以是骨干路由器,但是并不是所有的骨干路由器都是ABR。

  ·自治系统边界路由器(Autonomous System Boundary Router,ASBR)——可以认为是OSPF域外部的通信信息进入OSPF域的网关路由器,也就是说,ASBR路由器是用来把其他路由协议学习到的路由通过路由重发布的方式注入到OSPF域的路由器。一台ASBR路由器可以是位于OSPF域的自治系统内的任何路由器,它可以是一台内部路由器、骨干路由器或者ABR路由器。

  OSPF的网络类型以及邻居建立

  OSPF的网络类型一共有5类,分别为:Point-to-point(点到点)、Point-to-multipoint(点到多点)、Point-to-multipoint nonbroadcast(点到多点非广播)、Broadcast(广播)、NBMA(非广播多路可达)接下来我们将在帧中继网络中分别配置实现这些类型。拓扑如下:

 

 

 

 

  · 一、 点到点网络类型(P2P)

 

首先我们来实现点到点,用R1和R2来实现,基本配置如下:

R1:

interface Serial1/2
ip address 123.1.1.1 255.255.255.0
encapsulation frame-relay
ip ospf network point-to-point
no arp frame-relay
frame-relay map ip 123.1.1.2 102 
no frame-relay inverse-arp

 

router ospf 1
router-id 11.11.11.11
network 123.1.1.0 0.0.0.255 area 0

 

R2:

interface Serial1/2
ip address 123.1.1.2 255.255.255.0
encapsulation frame-relay
 ip ospf network point-to-point
no arp frame-relay
frame-relay map ip 123.1.1.1 201
no frame-relay inverse-arp

 

 

router ospf 1
router-id 22.22.22.22
network 123.1.1.0 0.0.0.255 area 0

 

  OSPF在帧中继中的默认网络类型是NBMA,所以我们要在接口下使用ip ospf network 来更改网络类型。上面的router-id用来指定OSPF的RID,network 123.1.1.0 0.0.0.255 area 0 用来宣告网段。上面命令配置后我们会发现OSPF的邻居并没有建立起来,但是我们的接口是可以Ping通的,如下:

R2#ping 123.1.1.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 123.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 60/86/124 ms

  我们Debug一下看看,命令:debug ip ospf events 结果如下:

R2#debug ip ospf events
OSPF events debugging is on
R2#
*Mar  1 00:14:29.659: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.2
*Mar  1 00:14:39.663: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.2
*Mar  1 00:14:49.667: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.2
*Mar  1 00:14:59.671: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.2
*Mar  1 00:15:09.675: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.2
*Mar  1 00:15:19.679: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.2
*Mar  1 00:15:29.683: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.2
*Mar  1 00:15:39.687: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.2

 

  我们发现OSPF的Hello包是通过组播地址224.0.0.5来发送的,再看看我们上面的帧中继配置

frame-relay map ip 123.1.1.1 201

  这样的配置广播包和组播包是不能发送出去的,我们更改为 frame-relay map ip 123.1.1.1 201 broadcast 试试:

此时我们再到R1上查看邻居:

R1#sho ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address         Interface
22.22.22.22       0   INIT/  -        00:00:39    123.1.1.2       Serial1/2

邻居处在INIT状态,原因是因为我们只能收到HELLO包,但是我们的包对方不能收到也就不能给予回应。我们在R1上也配置

frame-relay map ip 123.1.1.2 102 broadcas

 

配置完成后邻居马上处于FULL状态,说明邻居建立成功了。我们来看看整个过程:

 

*Mar  1 00:26:10.719: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:26:15.627: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:26:15.631: OSPF: Send immediate hello to nbr 22.22.22.22, src address 123.1.1.2, on Serial1/2
*Mar  1 00:26:15.635: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:26:15.639: OSPF: End of hello processing
*Mar  1 00:26:15.999: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:26:15.999: OSPF: 2 Way Communication to 22.22.22.22 on Serial1/2, state 2WAY
*Mar  1 00:26:15.999: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0xA29 opt 0x52 flag 0x7 len 32
*Mar  1 00:26:15.999: OSPF: End of hello processing
*Mar  1 00:26:15.999: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x15B9 opt 0x52 flag 0x7 len 32  mtu 1500 state EXSTART
*Mar  1 00:26:16.003: OSPF: NBR Negotiation Done. We are the SLAVE
*Mar  1 00:26:16.007: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x15B9 opt 0x52 flag 0x2 len 52
*Mar  1 00:26:16.299: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x15BA opt 0x52 flag 0x3 len 52  mtu 1500 state EXCHANGE
*Mar  1 00:26:16.303: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x15BA opt 0x52 flag 0x0 len 32
*Mar  1 00:26:16.467: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x15BB opt 0x52 flag 0x1 len 32  mtu 1500 state EXCHANGE
*Mar  1 00:26:16.471: OSPF: Exchange Done with 22.22.22.22 on Serial1/2
*Mar  1 00:26:16.475: OSPF: Send LS REQ to 22.22.22.22 length 12 LSA count 1
*Mar  1 00:26:16.479: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x15BB opt 0x52 flag 0x0 len 32
*Mar  1 00:26:16.491: OSPF: Rcv LS REQ from 22.22.22.22 on Serial1/2 length 36 LSA count 1
*Mar  1 00:26:16.495: OSPF: Send UPD to 123.1.1.2 on Serial1/2 length 40 LSA count 1
*Mar  1 00:26:16.563: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 64 LSA count 1
*Mar  1 00:26:16.563: OSPF: Synchronized with 22.22.22.22 on Serial1/2, state FULL
*Mar  1 00:26:16.567: %OSPF-5-ADJCHG: Process 1, Nbr 22.22.22.22 on Serial1/2 from LOADING to FULL, Loading Done
*Mar  1 00:26:17.203: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 76 LSA count 1
*Mar  1 00:26:20.723: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:26:25.679: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:26:25.683: OSPF: End of hello processing
*Mar  1 00:26:30.727: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:26:35.643: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:26:35.647: OSPF: End of hello processing


首先OSPF会从宣告网段的接口发送OSPF Hello包,当直连路由器都收到对方的immediate  hello包后开始进入2way状态

*Mar  1 00:26:10.719: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:26:15.627: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:26:15.631: OSPF: Send immediate hello to nbr 22.22.22.22, src address 123.1.1.2, on Serial1/2
*Mar  1 00:26:15.635: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:26:15.639: OSPF: End of hello processing
*Mar  1 00:26:15.999: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:26:15.999: OSPF: 2 Way Communication to 22.22.22.22 on Serial1/2, state 2WAY

  在点到点网络中,邻居到2WAY状态后直接开始发送DBD报文,这个状态成为EXSTART,DBD信息交互完后后邻居状态被至为EXCHANGE状态,如下:

*Mar  1 00:26:15.999: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0xA29 opt 0x52 flag 0x7 len 32
*Mar  1 00:26:15.999: OSPF: End of hello processing
*Mar  1 00:26:15.999: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x15B9 opt 0x52 flag 0x7 len 32  mtu 1500 state EXSTART
*Mar  1 00:26:16.003: OSPF: NBR Negotiation Done. We are the SLAVE
*Mar  1 00:26:16.007: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x15B9 opt 0x52 flag 0x2 len 52
*Mar  1 00:26:16.299: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x15BA opt 0x52 flag 0x3 len 52  mtu 1500 state EXCHANGE
*Mar  1 00:26:16.303: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x15BA opt 0x52 flag 0x0 len 32
*Mar  1 00:26:16.467: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x15BB opt 0x52 flag 0x1 len 32  mtu 1500 state EXCHANGE


 

EXCHANGE 状态邻居开始交互LSR(连路状态请求)和LSU(连路状态跟新)信息,如下:

*Mar  1 00:26:16.471: OSPF: Exchange Done with 22.22.22.22 on Serial1/2
*Mar  1 00:26:16.475: OSPF: Send LS REQ to 22.22.22.22 length 12 LSA count 1
*Mar  1 00:26:16.479: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x15BB opt 0x52 flag 0x0 len 32
*Mar  1 00:26:16.491: OSPF: Rcv LS REQ from 22.22.22.22 on Serial1/2 length 36 LSA count 1
*Mar  1 00:26:16.495: OSPF: Send UPD to 123.1.1.2 on Serial1/2 length 40 LSA count 1
*Mar  1 00:26:16.563: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 64 LSA count 1

 

  EXCHANGE状态完后后,邻居进入LOADING 状态,然后迅速进入FULL状态。

我们来看看OSPF中点到点网络类型的接口信息,命令是 show ip ospf interface s1/2,输出如下:

R1#show ip ospf interface s1/2
Serial1/2 is up, line protocol is up
  Internet Address 123.1.1.1/24, Area 0
  Process ID 1, Router ID 11.11.11.11, Network Type POINT_TO_POINT, Cost: 64
  Transmit Delay is 1 sec, State POINT_TO_POINT,
  Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    oob-resync timeout 40
    Hello due in 00:00:00
  Supports Link-local Signaling (LLS)
  Index 1/1, flood queue length 0
  Next 0x0(0)/0x0(0)
  Last flood scan length is 1, maximum is 1
  Last flood scan time is 0 msec, maximum is 0 msec
  Neighbor Count is 1, Adjacent neighbor count is 1
    Adjacent with neighbor 22.22.22.22
  Suppress hello for 0 neighbor(s)

从输出我们可以看到接口的IP地址、掩码、OSPF域、网络类型、接口开销、Hello、Dead和Wait时间以及邻居的RouterID。

 

  ·二、点到多点网络类型(P2MP)

 

    我们重新配置接口,配置如下:

 

R1:

 

interface Serial1/2
ip address 123.1.1.1 255.255.255.0
encapsulation frame-relay
ip ospf network point-to-multipoint
ip ospf 1 area 0
serial restart-delay 0
no arp frame-relay
frame-relay map ip 123.1.1.2 102 broadcast
no frame-relay inverse-arp

 

router ospf 1
router-id 11.11.11.11

 

 

R2:

 

interface Serial1/2
ip address 123.1.1.2 255.255.255.0
encapsulation frame-relay
ip ospf network point-to-multipoint
ip ospf 1 area 0
serial restart-delay 0
no arp frame-relay
frame-relay map ip 123.1.1.1 201 broadcast
no frame-relay inverse-arp

 

router ospf 1
router-id 22.22.22.22

 

和上面的点到点类型一样,点到多点网络类型也是要在MAP后面加 broadcast 的,原因和上面的一样。我们来看看整个OSPF邻居建立过程,如下:


*Mar  1 00:10:56.639: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:10:56.735: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:10:56.739: OSPF: 2 Way Communication to 22.22.22.22 on Serial1/2, state 2WAY
*Mar  1 00:10:56.743: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x1FBA opt 0x52 flag 0x7 len 32
*Mar  1 00:10:56.747: OSPF: Send immediate hello to nbr 22.22.22.22, src address 123.1.1.2, on Serial1/2
*Mar  1 00:10:56.751: OSPF: Send hello to 123.1.1.2 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:10:56.755: OSPF: End of hello processing
*Mar  1 00:10:56.843: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x16 opt 0x52 flag 0x7 len 32  mtu 1500 state EXSTART
*Mar  1 00:10:56.843: OSPF: NBR Negotiation Done. We are the SLAVE
*Mar  1 00:10:56.847: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x16 opt 0x52 flag 0x2 len 52
*Mar  1 00:10:57.035: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x17 opt 0x52 flag 0x3 len 52  mtu 1500 state EXCHANGE
*Mar  1 00:10:57.035: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x17 opt 0x52 flag 0x0 len 32
*Mar  1 00:10:57.163: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x18 opt 0x52 flag 0x1 len 32  mtu 1500 state EXCHANGE
*Mar  1 00:10:57.163: OSPF: Exchange Done with 22.22.22.22 on Serial1/2
*Mar  1 00:10:57.167: OSPF: Send LS REQ to 22.22.22.22 length 12 LSA count 1
*Mar  1 00:10:57.171: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x18 opt 0x52 flag 0x0 len 32
*Mar  1 00:10:57.215: OSPF: Rcv LS REQ from 22.22.22.22 on Serial1/2 length 36 LSA count 1
*Mar  1 00:10:57.219: OSPF: Send UPD to 123.1.1.2 on Serial1/2 length 40 LSA count 1
*Mar  1 00:10:57.267: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 64 LSA count 1
*Mar  1 00:10:57.271: OSPF: Synchronized with 22.22.22.22 on Serial1/2, state FULL
*Mar  1 00:10:57.271: %OSPF-5-ADJCHG: Process 1, Nbr 22.22.22.22 on Serial1/2 from LOADING to FULL, Loading Done
*Mar  1 00:10:57.875: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 76 LSA count 1

 

 

这个个邻居建立过程和点到点(P2P)类型基本一样。上面我们用到了一个新命令  ip ospf 1 area 0 ,该命令用来在接口下宣告OSPF网段,而且这个命令只在12.4以上的IOS才被支持。我们再来看看点到多点网络类型的进口信息:

 

R1#show ip ospf interface s1/2
Serial1/2 is up, line protocol is up
  Internet Address 123.1.1.1/24, Area 0
  Process ID 1, Router ID 11.11.11.11, Network Type POINT_TO_MULTIPOINT, Cost: 64
  Enabled by interface config, including secondary ip addresses
  Transmit Delay is 1 sec, State POINT_TO_MULTIPOINT,
  Timer intervals configured, Hello 30, Dead 120, Wait 120, Retransmit 5
    oob-resync timeout 120
    Hello due in 00:00:12
  Supports Link-local Signaling (LLS)
  Index 1/1, flood queue length 0
  Next 0x0(0)/0x0(0)
  Last flood scan length is 1, maximum is 1
  Last flood scan time is 0 msec, maximum is 0 msec
  Neighbor Count is 1, Adjacent neighbor count is 1
    Adjacent with neighbor 22.22.22.22
  Suppress hello for 0 neighbor(s)

唯一和点到点不同的是,点到多点类型的Hello时间是30秒,Dead时间是120秒,Wait时间也是120秒。

 

  · 三、点到多点非广播(P2MP-Nonbroadcost)

 

基本配置如下:

 

 

 

R1 :

interface Serial1/2

ip address 123.1.1.1 255.255.255.0

encapsulation frame-relay

ip ospf network point-to-multipoint non-broadcast

ip ospf 1 area 0

serial restart-delay 0

no arp frame-relay

frame-relay map ip 123.1.1.2 102

no frame-relay inverse-arp

 

router ospf 1

router-id 11.11.11.11

 neighbor 123.1.1.2

 

R2:

interface Serial1/2

ip address 123.1.1.2 255.255.255.0

encapsulation frame-relay

ip ospf network point-to-multipoint non-broadcast

ip ospf 1 area 0

serial restart-delay 0

no arp frame-relay

frame-relay map ip 123.1.1.1 201

no frame-relay inverse-arp

 

router ospf 1

router-id 22.22.22.22

log-adjacency-changes

 

  我们在配置该类型网络的时候会发现,及时MAP加Broadcast邻居也无法建立,因为该类型需要手动是邻居的, neighbor 123.1.1.2 但是邻居只需要单边指就可以了。邻居建立过程如下:

 

*Mar  1 00:37:48.619: OSPF: Send hello to 123.1.1.2 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:37:48.719: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:37:48.723: OSPF: 2 Way Communication to 22.22.22.22 on Serial1/2, state 2WAY
*Mar  1 00:37:48.727: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0xA4F opt 0x52 flag 0x7 len 32
*Mar  1 00:37:48.731: OSPF: End of hello processing
*Mar  1 00:37:48.863: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x1C63 opt 0x52 flag 0x7 len 32  mtu 1500 state EXSTART
*Mar  1 00:37:48.867: OSPF: NBR Negotiation Done. We are the SLAVE
*Mar  1 00:37:48.871: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x1C63 opt 0x52 flag 0x0 len 32
*Mar  1 00:37:49.031: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x1C64 opt 0x52 flag 0x3 len 52  mtu 1500 state EXCHANGE
*Mar  1 00:37:49.035: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x1C64 opt 0x52 flag 0x0 len 32
*Mar  1 00:37:49.147: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x1C65 opt 0x52 flag 0x1 len 32  mtu 1500 state EXCHANGE
*Mar  1 00:37:49.151: OSPF: Exchange Done with 22.22.22.22 on Serial1/2
*Mar  1 00:37:49.155: OSPF: Send LS REQ to 22.22.22.22 length 12 LSA count 1
*Mar  1 00:37:49.159: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x1C65 opt 0x52 flag 0x0 len 32
*Mar  1 00:37:49.299: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 64 LSA count 1
*Mar  1 00:37:49.299: OSPF: Synchronized with 22.22.22.22 on Serial1/2, state FULL
*Mar  1 00:37:49.299: %OSPF-5-ADJCHG: Process 1, Nbr 22.22.22.22 on Serial1/2 from LOADING to FULL, Loading Done
*Mar  1 00:37:49.307: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 64 LSA count 1
*Mar  1 00:37:53.679: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 76 LSA count 1
*Mar  1 00:37:53.851: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 76 LSA count 1
*Mar  1 00:37:54.191: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 76 LSA count 1

 

  从上面我们可以看到,Hello 是以单播形式放送的,因为该类型的OSPF网络不支持广播或者组播数据包,这也是为什么要指邻居的原因了。我们来看看接口信息:

 

R1#show ip ospf interface s1/2
Serial1/2 is up, line protocol is up
  Internet Address 123.1.1.1/24, Area 0
  Process ID 1, Router ID 11.11.11.11, Network Type POINT_TO_MULTIPOINT, Cost: 64
  Enabled by interface config, including secondary ip addresses
  Transmit Delay is 1 sec, State POINT_TO_MULTIPOINT,
  Timer intervals configured, Hello 30, Dead 120, Wait 120, Retransmit 5
    oob-resync timeout 120
    Hello due in 00:00:09
  Supports Link-local Signaling (LLS)
  Index 1/1, flood queue length 0
  Next 0x0(0)/0x0(0)
  Last flood scan length is 1, maximum is 1
  Last flood scan time is 4 msec, maximum is 4 msec
  Neighbor Count is 1, Adjacent neighbor count is 1
    Adjacent with neighbor 22.22.22.22
  Suppress hello for 0 neighbor(s)

 

  注意此类型和点多多点类型的接口信息是一样的,网络类型也一样,但是要注意次类型和点到多点是一不一样的。

 

· 四、广播类型(Boardcast)以及 DR和BDR的选举规则

 

  基本配置如下:

 

R1 :

 

interface Serial1/2
ip address 123.1.1.1 255.255.255.0
encapsulation frame-relay
ip ospf network broadcast
ip ospf 1 area 0
serial restart-delay 0
no arp frame-relay
frame-relay map ip 123.1.1.2 102 broadcast
no frame-relay inverse-arp

 

router ospf 1
router-id 11.11.11.11
log-adjacency-changes

 

R2:

 

interface Serial1/2
ip address 123.1.1.2 255.255.255.0
encapsulation frame-relay
ip ospf network broadcast
ip ospf 1 area 0
serial restart-delay 0
no arp frame-relay
frame-relay map ip 123.1.1.1 201 broadcast
no frame-relay inverse-arp

 

router ospf 1
router-id 22.22.22.22
log-adjacency-changes

 

 

  上面的配置我们就不多说了,主要是要MAP要加Broadcast。我们来直接看邻居状态吧,如下:

 

*Mar  1 00:56:14.175: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:56:14.179: OSPF: End of hello processing
*Mar  1 00:56:21.443: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 64 LSA count 1
*Mar  1 00:56:21.447: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 60 LSA count 1
*Mar  1 00:56:21.599: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:56:21.603: OSPF: Cannot see ourself in hello from 22.22.22.22 on Serial1/2, state INIT
*Mar  1 00:56:21.607: OSPF: Neighbor change Event on interface Serial1/2
*Mar  1 00:56:21.607: OSPF: DR/BDR election on Serial1/2
*Mar  1 00:56:21.611: OSPF: Elect BDR 11.11.11.11
*Mar  1 00:56:21.611: OSPF: Elect DR 11.11.11.11
*Mar  1 00:56:21.615: OSPF: Elect BDR 0.0.0.0
*Mar  1 00:56:21.615: OSPF: Elect DR 11.11.11.11
*Mar  1 00:56:21.619:        DR: 11.11.11.11 (Id)   BDR: none
*Mar  1 00:56:21.619: OSPF: Reset Serial1/2 flush timer
*Mar  1 00:56:21.623: OSPF: Remember old DR 22.22.22.22 (id)
*Mar  1 00:56:21.623: OSPF: Send immediate hello to nbr 22.22.22.22, src address 123.1.1.2, on Serial1/2
*Mar  1 00:56:21.627: OSPF: Send hello to 123.1.1.2 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:56:21.631: OSPF: End of hello processing
*Mar  1 00:56:21.811: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:56:21.815: OSPF: 2 Way Communication to 22.22.22.22 on Serial1/2, state 2WAY
*Mar  1 00:56:21.815: OSPF: Neighbor change Event on interface Serial1/2
*Mar  1 00:56:21.819: OSPF: DR/BDR election on Serial1/2
*Mar  1 00:56:21.819: OSPF: Elect BDR 22.22.22.22
*Mar  1 00:56:21.823: OSPF: Elect DR 11.11.11.11
*Mar  1 00:56:21.823:       DR: 11.11.11.11 (Id)   BDR: 22.22.22.22 (Id)
*Mar  1 00:56:21.827: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x23C opt 0x52 flag 0x7 len 32
*Mar  1 00:56:21.831: OSPF: Neighbor change Event on interface Serial1/2
*Mar  1 00:56:21.831: OSPF: DR/BDR election on Serial1/2
*Mar  1 00:56:21.835: OSPF: Elect BDR 22.22.22.22
*Mar  1 00:56:21.835: OSPF: Elect DR 11.11.11.11
*Mar  1 00:56:21.839:        DR: 11.11.11.11 (Id)   BDR: 22.22.22.22 (Id)
*Mar  1 00:56:21.843: OSPF: Neighbor change Event on interface Serial1/2
*Mar  1 00:56:21.843: OSPF: DR/BDR election on Serial1/2
*Mar  1 00:56:21.847: OSPF: Elect BDR 22.22.22.22
*Mar  1 00:56:21.847: OSPF: Elect DR 11.11.11.11
*Mar  1 00:56:21.851:        DR: 11.11.11.11 (Id)   BDR: 22.22.22.22 (Id)
*Mar  1 00:56:21.851: OSPF: End of hello processing
*Mar  1 00:56:21.855: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x7EE opt 0x52 flag 0x7 len 32  mtu 1500 state EXSTART
*Mar  1 00:56:21.859: OSPF: NBR Negotiation Done. We are the SLAVE
*Mar  1 00:56:21.863: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x7EE opt 0x52 flag 0x2 len 52
*Mar  1 00:56:21.975: OSPF: Rcv DBD from 22.22.22.22 on Serial1/2 seq 0x7EF opt 0x52 flag 0x1 len 32  mtu 1500 state EXCHANGE
*Mar  1 00:56:21.979: OSPF: Exchange Done with 22.22.22.22 on Serial1/2
*Mar  1 00:56:21.983: OSPF: Synchronized with 22.22.22.22 on Serial1/2, state FULL
*Mar  1 00:56:21.987: %OSPF-5-ADJCHG: Process 1, Nbr 22.22.22.22 on Serial1/2 from LOADING to FULL, Loading Done
*Mar  1 00:56:21.987: OSPF: Send DBD to 22.22.22.22 on Serial1/2 seq 0x7EF opt 0x52 flag 0x0 len 32
*Mar  1 00:56:22.095: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 64 LSA count 1
*Mar  1 00:56:22.111: OSPF: Rcv LS REQ from 22.22.22.22 on Serial1/2 length 36 LSA count 1
*Mar  1 00:56:22.115: OSPF: Send UPD to 123.1.1.2 on Serial1/2 length 40 LSA count 1
*Mar  1 00:56:22.519: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:56:26.719: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 64 LSA count 1
*Mar  1 00:56:26.727: OSPF: Send UPD to 123.1.1.2 on Serial1/2 length 40 LSA count 1
*Mar  1 00:56:27.807: OSPF: Rcv LS UPD from 22.22.22.22 on Serial1/2 length 64 LSA count 1
*Mar  1 00:56:31.447: OSPF: service_maxage: Trying to delete MAXAGE LSA
*Mar  1 00:56:31.595: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:56:31.599: OSPF: End of hello processing
*Mar  1 00:56:32.523: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:56:41.627: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:56:41.631: OSPF: End of hello processing
*Mar  1 00:56:42.527: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.1
*Mar  1 00:56:51.595: OSPF: Rcv hello from 22.22.22.22 area 0 from Serial1/2 123.1.1.2
*Mar  1 00:56:51.599: OSPF: End of hello processing
*Mar  1 00:56:52.531: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/2 from 123.1.1.1

 

  从上面我们会发现,广播类型的网络中会有一个DR和BDR的选举过程,路由首先把自己的Router ID置为DR和BDR,然后宣告出去,邻居路由进行协商,对放也会以同样的方式发出协商包。协商过程中路由首先会比较优先级,即 Priority 值,如果对方该值为0,直接Pass掉,对方将直接至为Other Router,自己为DR。如果Priority 不为0,且大于对方,则自己成为DR对方成为BDR。 如果Priority 值一样,其中Router ID最小的将被设置为DR较小的将被设置为BDR。我们来看下两个路由器的邻居信息,如下:

 

R1#sho ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address         Interface
22.22.22.22       1   FULL/BDR        00:00:32    123.1.1.2       Serial1/2

 

R2#sho ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address         Interface
11.11.11.11       1   FULL/DR         00:00:31    123.1.1.1       Serial1/2

 

  真的是Router ID最小的将被设置为DR吗?不要被上面的假象锁蒙蔽,我们再把R3加到OSPF中,并且帮网络配置成全互联型,来看看情况。配置如下:

 

R1 :

 

interface Serial1/2
ip address 123.1.1.1 255.255.255.0
encapsulation frame-relay
ip ospf network broadcast
ip ospf 1 area 0
serial restart-delay 0
no arp frame-relay
frame-relay map ip 123.1.1.2 102 broadcast

frame-relay map ip 123.1.1.3 103 broadcast
 

no frame-relay inverse-arp

 

router ospf 1
router-id 11.11.11.11
log-adjacency-changes

 

R2:

 

interface Serial1/2
ip address 123.1.1.2 255.255.255.0
encapsulation frame-relay
ip ospf network broadcast
ip ospf 1 area 0
serial restart-delay 0
no arp frame-relay
frame-relay map ip 123.1.1.1 201 broadcast

frame-relay map ip 123.1.1.3 203 broadcast
no frame-relay inverse-arp

 

router ospf 1
router-id 22.22.22.22
log-adjacency-changes

 

R3:

 

interface Serial1/2
ip address 123.1.1.3 255.255.255.0
encapsulation frame-relay
ip ospf network broadcast
ip ospf 1 area 0
serial restart-delay 0
no arp frame-relay
frame-relay map ip 123.1.1.1 301 broadcast
frame-relay map ip 123.1.1.2 302 broadcast
no frame-relay inverse-arp

 

router ospf 1
router-id 33.33.33.33
log-adjacency-changes

 

 

我们再来看看此时的邻居状态表:

 

R1#sho ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address         Interface
22.22.22.22       1   FULL/BDR        00:00:37    123.1.1.2       Serial1/2
33.33.33.33       1   FULL/DR         00:00:39    123.1.1.3       Serial1/2

 

  R3成了DR,R2成了BDR,R1成了DRother,很明显上面我们所说的:Router ID最小的将被设置为DR是不对的。在上面的试验中我们忽略了一点,就是邻居宣告的同时性。也就是说,我们是配置完成R1后再去配置R2,结果是R1先宣告了网段,开始主动协商邻居,而R2是后配置的,所以R1的主动性大于R2。我们接着做下面一个实验,我们首先让R2协商,然后再配置R1。方法是down掉R1的S1/2口,在R2上刷新OSPF进程,然后再重启R1的S1/2口,我们再来看看结果。

 

R2#sho ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address         Interface
11.11.11.11       1   FULL/BDR        00:00:37    123.1.1.1       Serial1/2

 

  我们发现R1成为BDR了,也就是说,先加组的路由具有较高的优先级,但是此优先级比 priority 低。我们再来想想,要是两个路由器的接口是同时加组的,又会是什么情况呢?我们首先要模拟一种情况,就是让两个路由同时加组,同时选举,这个貌似苛刻的环境其实是很简单的。在OSPF邻居建立的时候,有很多必须相同的参数,其中有一个Hello时间,我们可以利用这个条件来实现。首先我们修改某一个接口的Hello时间,让邻居DOWN掉,此时的情况就是两个接口都处于加组宣告状态,只要我们改回原来的Hello时间,马上就会同时进行邻居建立的过程,这也就达到了目的。

  接下来我们就来看看同时情况下邻居关系的建立。首先我们来看看broadcast类型的HELLO时间:

R1

 

R1#sho ip ospf interface s1/2
Serial1/2 is up, line protocol is up
  Internet Address 123.1.1.1/24, Area 0
  Process ID 1, Router ID 11.11.11.11, Network Type BROADCAST, Cost: 64
  Enabled by interface config, including secondary ip addresses
  Transmit Delay is 1 sec, State BDR, Priority 1
  Designated Router (ID) 22.22.22.22, Interface address 123.1.1.2
  Backup Designated router (ID) 11.11.11.11, Interface address 123.1.1.1
  Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    oob-resync timeout 40
    Hello due in 00:00:04
  Supports Link-local Signaling (LLS)
  Index 1/1, flood queue length 0
  Next 0x0(0)/0x0(0)
  Last flood scan length is 1, maximum is 2
  Last flood scan time is 0 msec, maximum is 4 msec
  Neighbor Count is 1, Adjacent neighbor count is 1
    Adjacent with neighbor 22.22.22.22  (Designated Router)
  Suppress hello for 0 neighbor(s)

 

hello时间是10秒,我们把他改成11秒,配置如下:

 

R1:

interface Serial1/2
ip address 123.1.1.1 255.255.255.0
encapsulation frame-relay
ip ospf network broadcast
ip ospf hello-interval 11
ip ospf 1 area 0
serial restart-delay 0
no arp frame-relay
frame-relay map ip 123.1.1.3 103 broadcast
frame-relay map ip 123.1.1.2 102 broadcast
no frame-relay inverse-arp

 

和我们想象的一样,邻居关系马上就Down掉了。我们重新配置会原来的Hello时间,再来看看此时的邻居关系。

 

R1#sho ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address         Interface
22.22.22.22       1   FULL/DR         00:00:33    123.1.1.2       Serial1/2

 

  果是Router ID大的成了DR,我们分别在R1和R2上多次模拟上面的环境,结果都是一样的,由此看见环境的真实性。同时我们也可以得出,当两个路由器同时进行加组宣告时,Router ID大的将成为 DR。

  我们来总结一下OSPF,DR和BDR的选举过程,首先路由器会查看priority 值,如果为0,则不参与DR和BDR的选举,如果priority 不为0,则把自己的priority值和对方进行比较,priority 值较大的一方将成为DR较小的一方将成为BDR。如果priority值一样,且不为0,那么此时又有两种情况,如果两个路由器不是同时加组宣告的,那么首先加组的一方将成为DR;如果两个路由器是同时加组宣告的,那么则会选择Router ID大的成为DR。在此后的过程中,如果有新路由器加组,则不会再与其进行选举。

 

 

·五、点到多点非广播(NBMA)

 

配置如下:

R1:

ip address 123.1.1.1 255.255.255.0
encapsulation frame-relay
ip ospf network non-broadcast
ip ospf 1 area 0
serial restart-delay 0
no arp frame-relay
frame-relay map ip 123.1.1.3 103 broadcast
frame-relay map ip 123.1.1.2 102 broadcast
no frame-relay inverse-arp

router ospf 1
router-id 11.11.11.11
log-adjacency-changes

R2:

interface Serial1/2
ip address 123.1.1.2 255.255.255.0
encapsulation frame-relay
ip ospf network non-broadcast
ip ospf 1 area 0
serial restart-delay 0
no arp frame-relay
frame-relay map ip 123.1.1.3 203 broadcast
frame-relay map ip 123.1.1.1 201 broadcast
no frame-relay inverse-arp

 

router ospf 1
router-id 22.22.22.22
log-adjacency-changes

 

上面的配置后我们发现邻居是起不来的,我们还要指邻居:

router ospf 1
router-id 11.11.11.11
log-adjacency-changes
neighbor 123.1.1.2

 

配置完后邻居起来了,我们会发现在NBMA网络类型中,也是会进行DR和BDR选举的,规则和广播类型一样。

R1#sho ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address         Interface

22.22.22.22       1   FULL/DR         00:01:55    123.1.1.2       Serial1/2

 

细心的朋友可能会发现,NBMA网络建立邻居的时候会多出一个邻居状态机,如下:

R1#sho ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address         Interface
N/A               0   ATTEMPT/DROTHER 00:00:59    123.1.1.2       Serial1/2

 

  ATTEMPT状态,此状态仅仅适用于NBMA网络上的邻居,在NBMA网络上邻居路由器是手工配置的.当NBMA网络上具有DR选举资格的路由器和其他邻居路由器相连的接口开始变为有效时,或者当这台路由器成为DR或BDR时,这台具有DR选举资格的路由器将会把邻居路由器的状态转到ATTEMPT状态。

  NBMA网络类型的接口参数如下:

 

R1#sho ip ospf interface s1/2
Serial1/2 is up, line protocol is up
  Internet Address 123.1.1.1/24, Area 0
  Process ID 1, Router ID 11.11.11.11, Network Type NON_BROADCAST, Cost: 64
  Enabled by interface config, including secondary ip addresses
  Transmit Delay is 1 sec, State BDR, Priority 1
  Designated Router (ID) 22.22.22.22, Interface address 123.1.1.2
  Backup Designated router (ID) 11.11.11.11, Interface address 123.1.1.1
  Timer intervals configured, Hello 30, Dead 120, Wait 120, Retransmit 5
    oob-resync timeout 120
    Hello due in 00:00:23
  Supports Link-local Signaling (LLS)
  Index 1/1, flood queue length 0
  Next 0x0(0)/0x0(0)
  Last flood scan length is 1, maximum is 2
  Last flood scan time is 4 msec, maximum is 4 msec
  Neighbor Count is 1, Adjacent neighbor count is 1
    Adjacent with neighbor 22.22.22.22  (Designated Router)
  Suppress hello for 0 neighbor(s)

 

·六、环回口类型

 

  此类型出现在环回口,如下:

 

R1#sho ip ospf interface lo0
Loopback0 is up, line protocol is up
  Internet Address 1.1.1.1/24, Area 0
  Process ID 1, Router ID 11.11.11.11, Network Type LOOPBACK, Cost: 1
  Enabled by interface config, including secondary ip addresses
  Loopback interface is treated as a stub Host

 

该网络类型没有HELLO、DEAD、WAIT等时间。因为此网络类型只有宣告网段的能力,没有加组的能力,因此该种网络类型的接口不会接收和放送OSPF报文。而且我们会发现此种类型宣告出去的路由是32的如下:

 

R1:

 

interface Loopback0
ip address 1.1.1.1 255.255.255.0
ip ospf 1 area 0

 

R2:

 

R2#sho ip route
Codes: 

     Design By  Volcano CCIE Lab Of Times Education

                      Mac.sun               

       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       1.1.1.1 [110/65] via 123.1.1.1, 01:16:40, Serial1/2
     123.0.0.0/24 is subnetted, 1 subnets
C       123.1.1.0 is directly connected, Serial1/2

 

·七、虚链路类型

   此类型将在虚链路配置中介绍

 

 

OSPF常见的六种LSA

 

· 一、1类LSA——路由器LSA  (Router Link States)

 

  每一台路由器都会产生路由器LSA通告。这个最基本的LSA通告列出了路由器所有的连接或接口,并指明了他们的状态和和沿每条链路方向出战的代价,以及该链路上所有一直的OSPF邻居。这些LSA通告指挥在始发它们的区域内部进行洪泛。

  我们来看看上面实验中R1上的OSPF数据库:

 

R1#sho ip ospf database

            OSPF Router with ID (11.11.11.11) (Process ID 1)

                Router Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum Link count
11.11.11.11     11.11.11.11     1366        0x80000010 0x007603 2
22.22.22.22     22.22.22.22     1995        0x8000000F 0x00BC79 1

 

从上面可以看到路由器LSA中包含了两个两个路由器,也就是我们的R1和R2

 

· 一、2类LSA——网络LSA  (Net Link States)

 

  网络LSA会列出DR,此类LSA也只仅仅在产生这条网络LSA的区域内部进行洪泛。

 

R1#sho ip ospf database network

            OSPF Router with ID (11.11.11.11) (Process ID 1)

                Net Link States (Area 0)

  Routing Bit Set on this LSA
  LS age: 1934
  Options: (No TOS-capability, DC)
  LS Type: Network Links
  Link State ID: 123.1.1.2 (address of Designated Router)
  Advertising Router: 22.22.22.22
  LS Seq Number: 8000000F
  Checksum: 0x933C
  Length: 32
  Network Mask: /24
        Attached Router: 22.22.22.22
        Attached Router: 11.11.11.11

 

 · 一、3类LSA——网络汇总LSA  (Net Link States) 和区域内汇总

 

  是由ABR路由器始发的。ABR路由器将发送网络汇总LSA到一个区域,用来宣告区域外部的目的地址。一台ABR路由器可以通过网络汇总LSA向骨干区域通告与它相连的区域内部的目标地址。在一个区域外部,仍然在一个OSPF自主系统内部的缺省路由也可以通过这种LSA类型来通告。

  我们来看看如何产生一条三类LSA,首先拓扑如下,R1和R2之间是Area 0域,R2和R3之间是Area 1 域。

 

 

 

 

配置如下:

 

 

 

 

你可能感兴趣的:(职场,Cisco,休闲,思科,ospf)