用Zebra做OSPF实验

2023-10-25 11:08
文章标签 实验 ospf zebra

本文主要是介绍用Zebra做OSPF实验,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

用Zebra做OSPF实验
关键字: zebra
OSPF(开放最短路径优先)路由协议是一项链路状态型技术,是目前IGP中应用最广、性能最优的一个 协议,解决了RIP不能解决的大型、可扩展的网络需求而写的,适用于大规模的网络。

Zebra支持OSPFv2和OSPFv3(用于IPv6的OSPF,CISCO还未对其封装),由于条件所限,下面的OSPF实 验同样是在两台单网卡的RedHat7.2下做的。

Zebra使用ospfd程序实现OSPF路由功能,但ospfd需要从zebra程序获得接口信息,所以zebra程序必须在 ospfd程序之前运行。ospfd不支持多个OSPF进程,我们不能指定OSPF进程号。

初始化第一台机器:

shell_1> cd /usr/local/etc
shell_1> cp zebra.conf.sample zebra.conf
shell_1> cp ospfd.conf.sample ospfd.conf
shell_1> zebra -d

进入zebra设置IP

shell_1> telnet localhost 2601
Password:
Router> en
Password:
Router# conf t
Router(config)# hostname r1
r1(config)# int eth0
r1(config-if)# ip address 192.168.5.121/24
r1(config-if)# ctrl+z
r1# copy run start

进入第一台机器的ospf设置

shell_1> ospfd -d
shell_1> telnet localhost 2604
Password:
ospfd> en
ospfd# conf t
ospfd(config)# hostname r1_ospfd !改个名字好辨认
r1_ospfd(config)# router ospf !启动ospf
r1_ospfd(config-router)# ospf router-id 192.168.5.121 !设置router-id
r1_ospfd(config-router)# network 192.168.5.0/24 area 0
!最关键的,来标识路由器上哪些IP网络号是OSPF的一部分,对于每个网络,我们必须标识该网络所属 的区域。由于我们只有两台机器,当然只有一个网络,所以只需执行一个network命令就够了。

对于我们的小网络,ospf就算配好了,下面来检验一下:

r1_ospfd(config-router)# ctrl+z
r1_ospfd# sh ip ospf route
============ OSPF network routing table ============
N 192.168.5.0/24 [10] area: 0.0.0.0
directly attached to eth0

============ OSPF router routing table =============

============ OSPF external routing table ===========

r1_ospfd# sh ip ospf database

OSPF Router with ID (192.168.5.121)

Router Link States (Area 0.0.0.0)

Link ID ADV Router Age Seq# CkSum Link count
192.168.5.121 192.168.5.121 126 0x80000002 0x8584 1

r1_ospfd# sh ip ospf int eth0
eth0 is up, line protocol is up

Internet Address 192.168.5.121/24, Area 0.0.0.0
Router ID 192.168.5.121, Network Type BROADCAST, Cost: 10
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 192.168.5.121, Interface Address 192.168.5.121
No backup designated router on this network
Timer intarvals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:07
Neighbor Count is 0, Adjacent neighbor count is 0

由于网络里没有其它的路由器,r1就把自己选为DR(指定路由器)了。Zebra对log处理可能有些问题,使 用log stdout不能显示各种debug信息,所以只能记录到文件,在shell下用tail命令查看。而且debug命令和 实际路由器也有不同。

r1_ospfd# debug ospf event
r1_ospfd(config)# log file /usr/local/etc/ospfd.log

然后我们在shell下查看debug信息

shell_1> tail -f /usr/local/etc/ospfd.log
--------------------------------8<---------------------------------------
2002/04/28 14:24:27 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 14:24:37 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 14:24:47 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 14:24:57 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 14:25:07 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
--------------------------------8<---------------------------------------

我们错过了最开始的信息,看到路由器每隔10秒发送一个hello数据包。hello数据包通过多目组播地址 224.0.0.5被发送出去,如果我们打开debug ospf packet all就能很清楚的看到。

第二台机器的设置

前面的初始化和第一台一样,不过这里名字设成r2便于辨认,IP设成了192.168.5.123/24。

进入第二台机器的ospf设置

shell_2> ospfd -d
shell_2> telnet localhost 2604
Password:
ospfd> en
ospfd# conf t
ospfd(config)# hostname r2_ospfd
r2_ospfd(config)# router ospf
r2_ospfd(config-router)# ospf router-id 192.168.5.123
r2_ospfd(config-router)# network 192.168.5.0/24 area 0

执行完network命令,我们看到第一台机器的tail -f /usr/local/etc/ospfd.log输出下面的信息:

--------------------------------8<---------------------------------------
2002/04/28 14:25:51 OSPF: Packet 192.168.5.123 [Hello:RECV]: Options *|*|-|-|-|-|E|*
2002/04/28 14:25:51 OSPF: NSM[eth0:192.168.5.121:0.0.0.0]: start
2002/04/28 14:25:52 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 14:25:52 OSPF: couldn't find any VL to associate the packet with
2002/04/28 14:25:52 OSPF: DR-Election[1st]: Backup 192.168.5.123
2002/04/28 14:25:52 OSPF: DR-Election[1st]: DR 192.168.5.121
2002/04/28 14:25:52 OSPF: Packet[DD]: Negotiation done (Slave).
--------------------------------8<---------------------------------------

r1收到r2(192.168.5.123)发过来的hello数据包,交换信息后选举DR,由于本身192.168.5.121是DR了,所以 只选举了BDR就好了。这时在r1上就能看到r2了。

r1_ospfd# sh ip ospf neig

Neighbor ID Pri State Dead Time Address Interface RXmtL RqstL DBsmL
192.168.5.123 1 Full/Backup 00:00:37 192.168.5.123 eth0:192.168.5.121 0 0 0

检验其它信息

r1_ospfd# sh ip ospf database

OSPF Router with ID (192.168.5.121)

Router Link States (Area 0.0.0.0)

Link ID ADV Router Age Seq# CkSum Link count
192.168.5.121 192.168.5.121 1259 0x80000008 0x534e 1
192.168.5.123 192.168.5.123 1265 0x80000006 0x534a 1

Net Link States (Area 0.0.0.0)

Link ID ADV Router Age Seq# CkSum
192.168.5.123 192.168.5.123 1265 0x80000001 0x5a5a

r1_ospfd# sh ip ospf int eth0
eth0 is up, line protocol is up

Internet Address 192.168.5.121/24, Area 0.0.0.0
Router ID 192.168.5.121, Network Type BROADCAST, Cost: 10
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 192.168.5.121, Interface Address 192.168.5.121
Backup Designated Router (ID) 192.168.5.123, Interface Address 192.168.5.123
Timer intarvals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:01
Neighbor Count is 1, Adjacent neighbor count is 1

和前面的输出信息相比,发生了很多变化,两台路由器已经相互识别了。OSPF不象RIP一样,每隔30秒 给所有的邻居广播一次完整的路由表,而是通过IP多目组播地址224.0.0.5每隔10秒发送一个很小的hello 数据包来维护邻居关系,当链路发生变化的时候,才重新计算。

拔掉两台机器连接的网线,看ospfd.log的记录:

--------------------------------8<---------------------------------------
2002/04/28 16:25:53 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 16:25:57 OSPF: Packet 192.168.5.123 [Hello:RECV]: Options *|*|-|-|-|-|E|*
2002/04/28 16:26:03 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 16:26:13 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 16:26:23 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 16:26:33 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): Start
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): looked through areas
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): bb_configured: 1
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): bb_act_attached: 1
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): areas_configured: 1
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): areas_act_attached: 1
2002/04/28 16:26:37 OSPF: nsm_change_status(): scheduling new router-LSA origination
2002/04/28 16:26:37 OSPF: DR-Election[1nd]: Backup 0.0.0.0
2002/04/28 16:26:37 OSPF: DR-Election[1nd]: DR 192.168.5.121
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): Start
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): looked through areas
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): bb_configured: 1
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): bb_act_attached: 1
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): areas_configured: 1
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): areas_act_attached: 1
2002/04/28 16:26:37 OSPF: Timer[router-LSA]: (router-LSA Refresh expire)
2002/04/28 16:26:37 OSPF: counting fully adjacent virtual neighbors in area 0.0.0.0
2002/04/28 16:26:37 OSPF: there are 0 of them
2002/04/28 16:26:37 OSPF: SPF: calculation timer scheduled
2002/04/28 16:26:37 OSPF: SPF: calculation timer delay = 5
2002/04/28 16:26:37 OSPF: ospf_flood_through_interface(): considering int eth0:192.168.5.121
2002/04/28 16:26:37 OSPF: ospf_flood_through_interface(): considering nbr 192.168.5.121
2002/04/28 16:26:42 OSPF: SPF: Timer (SPF calculation expire)
2002/04/28 16:26:42 OSPF: ospf_spf_calculate: Start
2002/04/28 16:26:42 OSPF: ospf_spf_calculate: running Dijkstra for area 0.0.0.0
2002/04/28 16:26:42 OSPF: SPF Result: 0 [R] 192.168.5.121
2002/04/28 16:26:42 OSPF: ========== OSPF routing table ==========
2002/04/28 16:26:42 OSPF: ========================================
2002/04/28 16:26:42 OSPF: ospf_process_stub():processing stubs for area 0.0.0.0
2002/04/28 16:26:42 OSPF: ospf_process_stub():processing router LSA, id: 192.168.5.121
2002/04/28 16:26:42 OSPF: ospf_process_stub(): we have 1 links to process
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): Start
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): processing route to 192.168.5.0/24
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): calculated cost is 0 + 10 = 10
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): installing new route
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): this network is on this router
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): the interface is eth0:192.168.5.121
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): Stop
2002/04/28 16:26:42 OSPF: children of V:
2002/04/28 16:26:42 OSPF: ospf_spf_calculate: Stop
2002/04/28 16:26:42 OSPF: ospf_ia_routing():start
2002/04/28 16:26:42 OSPF: ospf_ia_routing():not ABR, considering all areas
2002/04/28 16:26:42 OSPF: Pruning unreachable networks
2002/04/28 16:26:42 OSPF: Pruning unreachable routers
2002/04/28 16:26:42 OSPF: Route: Router Routing Table free
2002/04/28 16:26:42 OSPF: SPF: calculation complete
--------------------------------8<---------------------------------------

我们看到r1生成一个LSA包,通知其它路由器,由于网络里只有自己了,又选自己为DR。r2也是一样。-

文章出处:http://www.diybl.com/course/6_system/linux/Linuxjs/2008929/146644.html

这篇关于用Zebra做OSPF实验的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/282145

相关文章

STM32(十一):ADC数模转换器实验

AD单通道: 1.RCC开启GPIO和ADC时钟。配置ADCCLK分频器。 2.配置GPIO,把GPIO配置成模拟输入的模式。 3.配置多路开关,把左面通道接入到右面规则组列表里。 4.配置ADC转换器, 包括AD转换器和AD数据寄存器。单次转换,连续转换;扫描、非扫描;有几个通道,触发源是什么,数据对齐是左对齐还是右对齐。 5.ADC_CMD 开启ADC。 void RCC_AD

HNU-2023电路与电子学-实验3

写在前面: 一、实验目的 1.了解简易模型机的内部结构和工作原理。 2.分析模型机的功能,设计 8 重 3-1 多路复用器。 3.分析模型机的功能,设计 8 重 2-1 多路复用器。 4.分析模型机的工作原理,设计模型机控制信号产生逻辑。 二、实验内容 1.用 VERILOG 语言设计模型机的 8 重 3-1 多路复用器; 2.用 VERILOG 语言设计模型机的 8 重 2-1 多

61.以太网数据回环实验(4)以太网数据收发器发送模块

(1)状态转移图: (2)IP数据包格式: (3)UDP数据包格式: (4)以太网发送模块代码: module udp_tx(input wire gmii_txc ,input wire reset_n ,input wire tx_start_en , //以太网开始发送信

LTspice模拟CCM和DCM模式的BUCK电路实验及参数计算

关于BUCK电路的原理可以参考硬件工程师炼成之路写的《 手撕Buck!Buck公式推导过程》.实验内容是将12V~5V的Buck电路仿真,要求纹波电压小于15mv. CCM和DCM的区别: CCM:在一个开关周期内,电感电流从不会到0. DCM:在开关周期内,电感电流总会到0. CCM模式Buck电路仿真: 在用LTspice模拟CCM电路时,MOS管驱动信号频率为100Khz,负载为10R(可自

HCIA--实验十:路由的递归特性

递归路由的理解 一、实验内容 1.需求/要求: 使用4台路由器,在AR1和AR4上分别配置一个LOOPBACK接口,根据路由的递归特性,写一系列的静态路由实现让1.1.1.1和4.4.4.4的双向通信。 二、实验过程 1.拓扑图: 2.步骤: (下列命令行可以直接复制在ensp) 1.如拓扑图所示,配置各路由器的基本信息: 各接口的ip地址及子网掩码,给AR1和AR4分别配置

OpenGL/GLUT实践:流体模拟——数值解法求解Navier-Stokes方程模拟二维流体(电子科技大学信软图形与动画Ⅱ实验)

源码见GitHub:A-UESTCer-s-Code 文章目录 1 实现效果2 实现过程2.1 流体模拟实现2.1.1 网格结构2.1.2 数据结构2.1.3 程序结构1) 更新速度场2) 更新密度值 2.1.4 实现效果 2.2 颜色设置2.2.1 颜色绘制2.2.2 颜色交互2.2.3 实现效果 2.3 障碍设置2.3.1 障碍定义2.3.2 障碍边界条件判定2.3.3 障碍实现2.3.

pta-2024年秋面向对象程序设计实验一-java

文章申明:作者也为初学者,解答仅供参考,不一定是最优解; 一:7-1 sdut-sel-2 汽车超速罚款(选择结构) 答案: import java.util.Scanner;         public class Main { public static void main(String[] arg){         Scanner sc=new Scanner(System

H3C SR-MPLS通过OSPF通告SID配置

首先在配置前理解几个基本概念 Prefix SID配置 统一分配和配置(全局规划)loopback和prefix sidPrefix SID=SRGB Base(16000)+index Adj SID自动生成 对应SR节点间的互联链路SR节点本地标识,从设备本地Segment池中动态分配设备会为其IGP中的链路自动分配Adj SID,并通过IGP进行广播 IGP SID的分发与传递

如何校准实验中振镜频率的漂移

在实验过程中,使用共振扫描振镜(如Cambridge Technology的8kHz振镜)时,频率漂移是一个常见问题,尤其是在温度变化或长期运行的情况下。为了确保实验的准确性和稳定性,我们需要采取有效的校准措施。本文将介绍如何监测、调节和校准振镜频率,以减少漂移对实验结果的影响。 1. 温度管理和稳定性控制 振镜的频率变化与温度密切相关,温度的升高会导致机械结构的变化,进而影响振镜的共

实验C语言“union”的最基础语法

目标 最近在看Rust的“菜鸟教程”,看到 Rust 枚举类 时我发现它所定义的“枚举类”虽然也能像C语言枚举类那样使用,但是多了些功能:对于某个枚举的成员,还可以附带独特的数据,这让我想起了C语言中的union。 而我事实上对union没有使用经验,我自己写程序的时候不用它,看其他的项目的程序时印象里也没见过它。所以我对union的设计意图理解不深(可能只是为了节省内存?)。本篇的目标是对其