zoukankan      html  css  js  c++  java
  • 动态路由协议 OSPF

    OSPF:Open Shortest Path First。RFC2328 v2.

    最短路径优先协议。

    • 链路状态协议:不是传递路由条目。使用rip协议的每个路由器不知道网络的完整拓扑结构,使用OSPF协议的每个路由器知道完整的网络拓扑结构。

    • 度量值cost=10^8/接口的带宽:统计的传递方向上,入接口的带宽。累计所有入接口的度量值。

      百兆接口的带宽=100 000kbits=100 000 000bits。所以百兆接口的度量值就是1。

    • 使用hello包建立邻居,10秒利用组播发送一次

    • 组播地址224.0.0.5

    • 管理距离(AD):110

    • 没有自动汇总功能

    • 无类路由

    • 使用Dijkstra(迪杰斯特拉)算法

    • 维护3张表:邻居表,数据库表,路由表

    • 每条路由都由,数据库表和路由表支撑,路由是根据数据库里的表项计算出来的。网络越大,OSPF的设备的开销越大。

    • OSPF协议号:89

    • 有五种数据报文:Hello,DBD,LSR,LSU,ACK

      • Hello:用于确认邻居关系。

        Hello数据包里的信息:

        • Router-id:标识路由器的,就是一个名字。名字一般是以ip地址的形式命名,由于只是一个名字,所以可以是存在的ip地址,也可以是不存在的。如果没有手动指定,则找环回地址里的ip最大的作为Router-id;如果没有环回地址,则使用开启的物理接口ip的最大的。在OSPF里必须唯一。OSPF的路由器的Router-id必须不相同。

        • 作用:发现邻居;对一些数据的协商;保持邻居的Keeplive状态;选举DR(design router),BDR(backup design router)。

        • hello-interval=10s;dead-interval=40s

        • 形成邻居的条件:区域号,认证类型,hello时间,死亡时间(默认是hello时间的4倍)。如果接收到的这四项和自己的这四项不相同,则不能成为邻居;

          区域划分:把相同网段的路由器,划分到同一个区域,把连接不同区域的路由器叫ABR(区域边界路由器)。区域号是0-255。区域号0:主干区域。其他区域:常规区域。

          OSPF要求:常规区域必须和主干区域相连。

          认证类型:密码。可以不加密码。

      • DBD:用于告诉对方我的个人简介。

      • LSR:对方知道了你有什么了,我缺的如果你有,我向你请求要。

      • LSU:根据对方的请求,给予回答。

      • ACK:发完LSU后,对LSU的确认。

    • 默认支持等价负载均衡4,最大支持16。只支持等价的。

    • OSPF的八种(邻居)状态

      根据不同的邻居状态,发送不同的数据包。

      • down:未开启状态。假设R1和R2直连,R1组播返送发送hello包了。

      • init:当R2,接收到R1发送过来的hello包后,并审核R1的包,通过后,把R1的hello包里的Router-id放到自己的邻居表里,并把接收到router-id设置成init状态。

        同样R2也组播发送hello包,而且包里携带R2的邻居表。当R1接到到了R2的hello包后,发现R2的邻居表里有自己的router-id,而且状态是init,就把R2的router-id加入到自己的邻居表里,且状态是init。然后R1单播发送hello包给R2,然后R1把R2的状态变成2-way。R2接到到R1的单播hello包后,把R1的状态更新成2-way状态。

      • Attempt:不太被使用。

      • Exstart:在建立2-way时,要发送单播。如果OSPF里有1万个路由器,则每台都要单播发送,所以总共要发送1万*9999次单播,这是非常巨大的泛红,而且每增加一台,还要发送1万次单播,开销太大,为了避免,在建立2-way状态时,选举出DR(总经理),BDR(副经理),DR和BDR意外的就是others(普工员工)。先建立BDR,等40秒后,决定出DB,如果决定出的DR是原来的BDR,则再选举出一个BDR。为了选举,hello包里有个优先级的信息,优先级高的,排在前面;如果优先级相同,则看router-id,大的排在前面。

        DR和BDR里面有所有员工的信息,others有更新了,会使用组播ip224.0.0.6,告诉DR和BDR(只有DR和BDR才会监听224.0.0.6),然后DR在使用224.0.0.5,泛洪转告给别的others(others只监听224.0.0.5)。

        一旦DR和BDR选举成功后,others和DB/BDR之间就发送DBD包,交互彼此间的数据库信息,完成后所有的others就停留在2-way。所有的others之间不会再发送DBD 。然后DR和BDR进入Exchange

        所以Exstart是DR,BDR和others之间的关系。

      • Exchange:交互LSR和LSU,单播的请求和单播的更新。接下来到loading

      • loading:持续的发送组播更新给其他区域的路由器,并根据数据库计算出路由条目。然后DR和BDR进入full。

    启动OSPF协议:

    1,在全局模式,输入router ospf 100,后面的数字是进程号。在范围内随便选择。也就是说在同一台路由器里可以启用多个ospf协议,用进程号区分。

    R1(config)#router ospf ?
      <1-65535>  Process ID
    R1(config)#router ospf 100
    R1(config-router)#
    

    2,宣告把哪个网段加入到哪个区域。需要指定反掩码=255 - 掩码。

    R1:

    R1(config-router)#do show ip int b
    Interface                  IP-Address      OK? Method Status                Protocol
    FastEthernet0/0            12.1.1.1        YES manual up                    up  
    FastEthernet1/0            unassigned      YES unset  administratively down down
    Loopback0                  1.1.1.1         YES manual up                    up
    R1(config-router)#do show ip route
         1.0.0.0/32 is subnetted, 1 subnets
    C       1.1.1.1 is directly connected, Loopback0
         12.0.0.0/24 is subnetted, 1 subnets
    C       12.1.1.0 is directly connected, FastEthernet0/0
    R1(config-router)#net 1.1.1.1 0.0.0.0 area 0
    R1(config-router)#net 12.1.1.0 0.0.0.255 area 0
    
    

    R2:

    R2(config-if)#do show ip int b
    Interface                  IP-Address      OK? Method Status                Protocol
    FastEthernet0/0            12.1.1.2        YES manual up                    up  
    FastEthernet1/0            23.1.1.2        YES manual up                    up  
    Loopback0                  2.2.2.2         YES manual up                    up
    R2(config-if)#do show ip route
         2.0.0.0/32 is subnetted, 1 subnets
    C       2.2.2.2 is directly connected, Loopback0
         23.0.0.0/24 is subnetted, 1 subnets
    C       23.1.1.0 is directly connected, FastEthernet1/0
         12.0.0.0/24 is subnetted, 1 subnets
    C       12.1.1.0 is directly connected, FastEthernet0/0
    R2(config)#router ospf 100
    R2(config-router)#net 23.1.1.0 0.0.0.255 a 0
    R2(config-router)#net 12.1.1.0 0.0.0.255 a 0
    R2(config-router)#net 2.2.2.2 0.0.0.0 a 0
    

    R3:

    R3(config-if)#do show ip interface brief
    Interface                  IP-Address      OK? Method Status                Protocol
    FastEthernet0/0            23.1.1.3        YES manual up                    up  
    FastEthernet1/0            unassigned      YES unset  administratively down down
    Loopback0                  3.3.3.3         YES manual up                    up  
    R3(config)#do show ip route
         3.0.0.0/32 is subnetted, 1 subnets
    C       3.3.3.3 is directly connected, Loopback0
         23.0.0.0/24 is subnetted, 1 subnets
    C       23.1.1.0 is directly connected, FastEthernet0/0
    R3(config)#router os
    R3(config)#router ospf 100
    R3(config-router)#net 3.3.3.3 0.0.0.0 a 0
    R3(config-router)#net 23.1.1.0 0.0.0.255 a 0
    

    执行完命令,过一段时间后,会在控制台打印出:

    *Mar  1 00:16:53.431: %OSPF-5-ADJCHG: Process 100, Nbr 2.2.2.2 on FastEthernet0/0 from LOADING to FULL, Loading Done
    

    3,查看自己的邻居有哪些:show ip ospf neighbor

    R1:

    R1#show ip ospf neighbor
    Neighbor ID     Pri   State           Dead Time   Address         Interface
    2.2.2.2           1   FULL/BDR        00:00:36    12.1.1.2        FastEthernet0/0
    

    发现Neighbor ID就是环回地址,因为没有手动指定router-id。由于2.2.2.2比自己的1.1.1.1大,所以对于1.1.1.1来说,它就是2.2.2.2的BDR,而2.2.2.2则是1.1.1.1的DR。

    手动指定router-id命令:先要指定是哪个ospf,用进程号区分。

    R1(config)#router ospf 100
    R1(config-router)#router-id 1.1.1.1
    R1(config-router)#
    

    R2:

    R2#show ip ospf neighbor
    Neighbor ID     Pri   State           Dead Time   Address         Interface
    1.1.1.1           1   FULL/DR         00:00:31    12.1.1.1        FastEthernet0/0
    3.3.3.3           1   FULL/BDR        00:00:34    23.1.1.3        FastEthernet1/0
    

    R3:

    R3#show ip ospf neighbor
    Neighbor ID     Pri   State           Dead Time   Address         Interface
    2.2.2.2           1   FULL/DR         00:00:33    23.1.1.2        FastEthernet0/0
    

    查看路由条目:

    R1:

    R1#show ip route
         1.0.0.0/32 is subnetted, 1 subnets
    C       1.1.1.1 is directly connected, Loopback0
         2.0.0.0/32 is subnetted, 1 subnets
    O       2.2.2.2 [110/2] via 12.1.1.2, 00:11:45, FastEthernet0/0
         3.0.0.0/32 is subnetted, 1 subnets
    O       3.3.3.3 [110/3] via 12.1.1.2, 00:11:45, FastEthernet0/0
         23.0.0.0/24 is subnetted, 1 subnets
    O       23.1.1.0 [110/2] via 12.1.1.2, 00:11:45, FastEthernet0/0
         12.0.0.0/24 is subnetted, 1 subnets
    C       12.1.1.0 is directly connected, FastEthernet0/0
    

    R2:

    R2#show ip route
         1.0.0.0/32 is subnetted, 1 subnets
    O       1.1.1.1 [110/2] via 12.1.1.1, 00:13:09, FastEthernet0/0
         2.0.0.0/32 is subnetted, 1 subnets
    C       2.2.2.2 is directly connected, Loopback0
         3.0.0.0/32 is subnetted, 1 subnets
    O       3.3.3.3 [110/2] via 23.1.1.3, 00:13:09, FastEthernet1/0
         23.0.0.0/24 is subnetted, 1 subnets
    C       23.1.1.0 is directly connected, FastEthernet1/0
         12.0.0.0/24 is subnetted, 1 subnets
    C       12.1.1.0 is directly connected, FastEthernet0/0
    

    R3:

    R3#show ip route
         1.0.0.0/32 is subnetted, 1 subnets
    O       1.1.1.1 [110/3] via 23.1.1.2, 00:14:48, FastEthernet0/0
         2.0.0.0/32 is subnetted, 1 subnets
    O       2.2.2.2 [110/2] via 23.1.1.2, 00:14:48, FastEthernet0/0
         3.0.0.0/32 is subnetted, 1 subnets
    C       3.3.3.3 is directly connected, Loopback0
         23.0.0.0/24 is subnetted, 1 subnets
    C       23.1.1.0 is directly connected, FastEthernet0/0
         12.0.0.0/24 is subnetted, 1 subnets
    O       12.1.1.0 [110/2] via 23.1.1.2, 00:14:48, FastEthernet0/0
    

    查看接口带宽或者mac等:show int f0/0

    里面的BW 100000 Kbit就是带宽。

    R1#show int f0/0
    FastEthernet0/0 is up, line protocol is up
      Hardware is AmdFE, address is cc01.4af0.0000 (bia cc01.4af0.0000)
      Internet address is 12.1.1.1/24
      MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
    

    36集13:47开始,讲OSPF协议

    # c/c++ 学习互助QQ群:877684253 ![](https://img2018.cnblogs.com/blog/1414315/201811/1414315-20181106214320230-961379709.jpg) # 本人微信:xiaoshitou5854
  • 相关阅读:
    【ROM修改教程】添加高级电源重启菜单(安卓4.0.4官方ROM)
    MTK 快速开机 技术详解
    MT6592 经验积累
    Android系统之Broadcom GPS 移植
    Android关机流程源码分析
    Android 4.1.2系统添加重启功能
    android4.2添加重启菜单项
    MTK平台 Android4.0.3 定制关机动画
    不进化,则消亡——互联网时代企业管理的十项实践
    前端切图:调用百度地图API
  • 原文地址:https://www.cnblogs.com/xiaoshiwang/p/12195422.html
Copyright © 2011-2022 走看看