c语言SPF算法代码,SPF 算法具体过程

路由器 OSPF 的SPF算法具体过程.

这次实验主要体现OSPF 是怎么通过SPF算法根据数据库中的LSA 来计算出一张路由表的.如果理解不到位的地方希望大家指出.拓扑见附件

R1#show ip ospf database

Link ID ADV Router Age Seq# Checksum Link count

1.1.1.1 1.1.1.1 142 0x80000006 0x009598 4

2.2.2.2 2.2.2.2 51 0x80000008 0x00D6FC 5

3.3.3.3 3.3.3.3 130 0x80000007 0x00B7F2 4

在R1的数据库中存在三条router LSA SPF算法正是通过这三条LSA计算出整个路由表的.

1:以自己为根开始计算. 计算原则

碰到stubnetwork就加入路由表(因为stubnetwork有地址和掩码

可以得出路由) 然后

在从上到下查看LSA

R1#show ip ospf database router 1.1.1.1

Link connected to: another Router (point-to-point)

(Link ID) Neighboring Router ID: 3.3.3.3

(Link Data) Router Interface address: 20.20.20.1

Number of TOS metrics: 0

TOS 0 Metrics: 64

Link connected to: a Stub Network

(Link ID) Network/subnet number: 20.20.20.0

(Link Data) Network Mask: 255.255.255.0

Number of TOS metrics: 0

TOS 0 Metrics: 64

Link connected to: another Router (point-to-point)

(Link ID) Neighboring Router ID: 2.2.2.2

(Link Data) Router Interface address: 10.10.10.1

Number of TOS metrics: 0

TOS 0 Metrics: 64

Link connected to: a Stub Network

(Link ID) Network/subnet number: 10.10.10.0

(Link Data) Network Mask: 255.255.255.0

Number of TOS metrics: 0

TOS 0 Metrics: 64

1:首先选出stubnetwork 因为这是自己的LSA 所以R1很轻易的知道自己接口的网络.于是加入路由表

20.0.0.0/24 is subnetted, 1 subnets

C 20.20.20.0 is directly connected, Serial0/1

10.0.0.0/24 is subnetted, 1 subnets

C 10.10.10.0 is directly connected, Serial0/0

2:从上到下查看LSA 发现一个点到点的网络

是关于3.3.3.3路由器的. 于是R1停止对自己LSA的查询,直接到数据库中找3.3.3.3的LSA 以下就是3.3.3.3的LSA

R1#show ip ospf database router 3.3.3.3

Link connected to: another Router (point-to-point)

(Link ID) Neighboring Router ID: 2.2.2.2

(Link Data) Router Interface address: 30.30.30.2

Number of TOS metrics: 0

TOS 0 Metrics: 64

Link connected to: a Stub Network

(Link ID) Network/subnet number: 30.30.30.0

(Link Data) Network Mask: 255.255.255.0

Number of TOS metrics: 0

TOS 0 Metrics: 64

Link connected to: another Router (point-to-point)

(Link ID) Neighboring Router ID: 1.1.1.1

(Link Data) Router Interface address: 20.20.20.2

Number of TOS metrics: 0

TOS 0 Metrics: 64

Link connected to: a Stub Network

(Link ID) Network/subnet number: 20.20.20.0

(Link Data) Network Mask: 255.255.255.0

Number of TOS metrics: 0

TOS 0 Metrics: 64

3:继续重复第一步找stubnetwork

发现了30.30.30.0/24 和20.20.20.0/24 的网络. 两个的cost值都是64 于是查看邻居表找到3.3.3.3的IP 地址把它作为下一跳. 把自己链路的cost值 + 64 就是到达此网段的cost值

于是产生以下信息

30.0.0.0/24 is subnetted, 1 subnets

O 30.30.30.0 [110/128] via 20.20.20.2, 00:14:15, Serial0/1

20.0.0.0/24 is subnetted, 1 subnets

O 20.20.20.0 [110/128] via 20.20.20..2, 00:14:15, Serial0/1 注意此信息是我伪造的,路由表中不可能出现这种路由.

分享至:

90ed4b13fe016cebd9fe3df2ae3a899b.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值