wireshark抓包并进行Eigrp网络协议分析

路由协议

Eigrp

​ EIGRP:Enhanced Interior Gateway Routing Protocol 即 增强内部网关路由协议。也翻译为 加强型内部网关路由协议。 EIGRP是Cisco公司的私有协议(2013年已经公有化)。 EIGRP结合了链路状态距离矢量型路由选择协议的Cisco专用协议,采用弥散修正算法(DUAL)来实现快速收敛,可以不发送定期的路由更新信息以减少带宽的占用,支持Appletalk、IP、Novell和NetWare等多种网络层协议。该协议是一个内部网关协议。不同协议类型如下:

  • IGP:内部网关协议,在一个自治系统内运行。比如:RIP、OSPF、IS-IS、EIGRP等。
  • EGP:外部网关协议,用于连接不同的自治系统。比如:BGP

EIGRP报文

#字段解释
Cisco EIGRP
    Version: 2    #协议号
    Opcode: Hello (5)   #Opcode字段,报文类型:1 Update、 3 Query、 4 Reply、 5 Hello/ACK
    Checksum: 0xeecb [correct]
    [Checksum Status: Good]
#	标志(0x01表示INIT,0x02表示CR) INIT标志表示发送给新邻居的第一个初始化Update报文,这个报文将携带所有的路由信息,而以后的普通的Update报文将只携带变化了的路由信息
    Flags: 0x00000000
        .... .... .... .... .... .... .... ...0 = Init: Not set
            .... .... .... .... .... .... .... ..0. = Conditional Receive: Not set
"""
CR状态的作用:
某路由器R在一个接口上有A,B,C三个邻居.它向这个接口发送了一个Update报文,然后收到了A,C的确认,但是因为某种原因没有收到B的确认,这样无法知道B是否收到了这份Update报文.此时,路由器R既不想继续等B的确认;也不希望B在没有收到第一份Update报文的情况下接收第二份Update报文,因为这种失序有可能引起混乱.

于是,路由器R发了一个带有Sequense TLV的Hello报文,里面列出了B的IP地址,这样A,C就会将自己置于CR状态,B则会保持正常态.R发出的后续Update报文将在报文头中打上CR标志,这样只有A,C才会接收到这些报文,而B因为不是CR状态,将会忽略带有CR标志的报文,这样就保证了B不会接收到失序的报文.路由器R将在稍后向B依次发送B所错过的报文
"""
                .... .... .... .... .... .... .... .0.. = Restart: Not set
                    .... .... .... .... .... .... .... 0... = End Of Table: Not set   #分享路由信息

    Sequence: 0		#报文的序列号,用于确认机制,不需要确认的报文,如Hello报文,这个域为0.
    Acknowledge: 0	#文携带的确认信息.表示已经收到了此序列号的报文.
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 1	#自治系统号一般来说就是进程号.
    Parameters
        Type: Parameters (0x0001)
        Length: 12
        K1: 1
        K2: 0
        K3: 1
        K4: 0
        K5: 0
        K6: 0
        Hold Time: 15
    Software Version: EIGRP=12.4, TLV=1.2
        Type: Software Version (0x0004)
        Length: 8
        EIGRP Release: 12.04
        EIGRP TLV version: 1.02
    # Sequense TLV可能出现在Hello报文中,它的TLV Type为0x0003,它的作用让某些邻居路由器进入到CR(Conditional Receive)状态.表示了一个邻居路由器的IP地址,Sequense TLV可以携带多个IP地址的列表.凡是接收到这个TLV的邻居路由器将检查自己是否在这个列表中,如果不在这个列表中,则把自己置为CR状态.只有处于CR状态的路由器,才能接收带有CR标志的报文.(EIGRP报文头部分中关于Flags字段的说明).
    Sequence
        Type: Sequence (0x0003)
        Length: 9
        Address length: 4
        IP Address: 10.0.0.1
"""
Next Multicast Seq TLV可以出现在Hello报文中,它的TLV Type为0x0005.它需要和与Sequense TLV配合使用,单独的Next Multicast Seq TLV没有意义.

在有Sequense TLV,但没有Next Multicast Seq TLV时,表示处于CR状态的邻居路由器可以接收以后所有带CR标志的报文.在有Sequense TLV和Next Multicast Seq TLV都有时,则Next Multicast Seq TLV指定了一个序列号,处于CR状态的邻居路由器只可以接收带CR标志,并且序列号为这个指定序列号的报文.

"""
    Next multicast sequence: 25
        Type: Next multicast sequence (0x0005)
        Length: 8
        Multicast Sequence: 25       #Seq Number:下一个可以接收的多播报文的序列号.

# update消息
    Opcode: Update (1)
    Checksum: 0x24b9 [correct]
    [Checksum Status: Good]
    Flags: 0x00000008, End Of Table
        .... .... .... .... .... .... .... ...0 = Init: Not set
        .... .... .... .... .... .... .... ..0. = Conditional Receive: Not set
        .... .... .... .... .... .... .... .0.. = Restart: Not set
        .... .... .... .... .... .... .... 1... = End Of Table: Set  #标志位
    Sequence: 24									
    Acknowledge: 23
    Virtual Router ID: 0 (Address-Family)		#入这条路由的路由器的IP地址
    Autonomous System: 100				#引入这条路由的路由器所在的自治系统.
    Internal Route(IPv4)  =   192.168.1.0/24
        Type: Internal Route(IPv4) (0x0102)  # 0x0103表示扩展路由
        Length: 28	
        NextHop: 0.0.0.0  		#路由的下一跳的IP地址.
        #Delay,Bandwidth,MTU,Hop Count,Reliability,Load:依次是总延时,最小带宽,MTU值,跳数,可信度,负载.
        Legacy Metric
            Scaled Delay: 2560	#延迟
            Scaled BW: 25600	#带宽
            MTU: 1500			#MTU
            Hop Count: 0   		#路由器跳数
            Reliability: 255	
            Load: 1
            Route Tag: 0
            Flags
                .... ...0 = Source Withdraw: False
                .... ..0. = Candidate Default: False
                .... .0.. = Route is Active: False     
                .... 0... = Route is Replicated: False
        Prefix Length: 24
        Destination: 192.168.1.0   

1.Hello:用于邻居发现、建立、保活。目标地址为224.0.0.10,Hello包在邻居收到后不需要确认。

  • 用于邻居的发现和维护 5s一次

  • 默认使用组播(224.0.0.10)发送(目标地址 ERIP的组播地址)

  • 发现、建立、维护邻居关系

  • 发送的时候使用接口主IP地址作为源,不会使用辅IP地址

  • K值全部255时也叫goodbye消息

  • 网络收敛后,只有hello包发送

2.Update:更新包,携带路由条目信息—目标网络号+度量值。通过组播发送Update数据包,邻居收到后必须回复确认消息。

  • 传递路由更新,仅包含需要的路由条目

  • 收到第一个Hello包,以单播传送全部路由;路由信息变化,以组播方式发送变化的路由信息

  • 当为指定(neighbor)的一台路由器发更新时使用Unicast(P-TO-P) ,当为多台路由器发更新时使用Multicast.(MA)----可靠包

3.Query:查询包,当路由信息丢失并没有备用路由时,使用Query数据包向邻居查询,邻居必须回复确认

  • 当找不到Feasible Successor时,发送查询报文(Multicast)----可靠包

  • 若A发现路由变化,先发Update,再发Query

4.Reply:应答包,是对邻居Query数据包的回复,也需要邻居回复确认。

  • 回应查询报文,单播。(Unicast)----可靠包//B收到Query后,会先发ACK,Reply

5.ACK:确认包,是对收到的数据包的确认,告诉邻居自己已经收到数据包了,收到Ack后,不需要再对Ack做回复,因为这是没有意义的,并且可能造成死循环

  • 用来确认Update/Query/Reply (Unicast),单播报文

6.SIA-QUERY:

  • 用于避免SIA超时导致邻居关系重置

7.SIA-REPLY:

  • 用于避免SIA超时导致邻居关系重置

使用单播传送的包:reply,ack,使用组播传送的包:Hello,Update和query (224.0.0.10),可靠包:Update,Query,Reply。

##hello消息的结构

Opcode字段,报文类型:1 Update、 3 Query、 4 Reply、 5 Hello/ACK

Sequence字段: the 32-bit sequence number used by the RTP

ACK字段:如果此字段不为零的话,那么这个包就是ACK包而不是Hello包

TLV:Type / Length / Value

TLV Types分为4个大类,如下:
''' TLV消息结构
Parameters
    Type: Parameters (0x0001)
    Length: 12
    K1: 1
    K2: 0
    K3: 1
    K4: 0
    K5: 0
    K6: 0
    Hold Time: 15   默认3倍
'''
1.General TLV Types

         0x0001 EIGRP Parameters  EIGRP参数
	
         0x0003 Sequence		序列

         0x0004 Software Version		 软件版本

         0x0005 Next Multicast Sequence 	下一个组播序列

2.IP-Specific TLV Types

         0x0102 IP Internal Routes		IP内部路由

         0x0103 IP External Routes		IP外部路由

3.AppleTalk-Specific TLV Types

         0x0202 AppleTalk Internal Routes	AppleTalk内部路由

         0X0203 AppleTalk External Routes		AppleTalk外部路由

         0x0204 AppleTalk Cable Configuration	AppleTalk电缆配置

4.IPX-Specific TLV Types

         0x0302 IPX Internal Routes		IPX内部路由

         0x0303 IPX External Routes 	IPX外部路由
hello消息 抓包报文
#普通hello消息
Cisco EIGRP
    Version: 2
    Opcode: Hello (5)
    Checksum: 0xeecb [correct]
    [Checksum Status: Good]
    Flags: 0x00000000
    Sequence: 0
    Acknowledge: 0			#有值时为 ack消息
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 1
    Parameters
        Type: Parameters (0x0001)
        Length: 12
        K1: 1
        K2: 0
        K3: 1
        K4: 0
        K5: 0
        K6: 0
        Hold Time: 15
    Software Version: EIGRP=12.4, TLV=1.2
        Type: Software Version (0x0004)
        Length: 8
        EIGRP Release: 12.04
        EIGRP TLV version: 1.02
            
#携带下一个组播序号的hello
Cisco EIGRP
    Version: 2
    Opcode: Hello (5)
    Checksum: 0xc352 [correct]
    [Checksum Status: Good]
    Flags: 0x00000000
        .... .... .... .... .... .... .... ...0 = Init: Not set
        .... .... .... .... .... .... .... ..0. = Conditional Receive: Not set
        .... .... .... .... .... .... .... .0.. = Restart: Not set
        .... .... .... .... .... .... .... 0... = End Of Table: Not set
    Sequence: 0
    Acknowledge: 0
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 100
    Parameters
        Type: Parameters (0x0001)
        Length: 12
        K1: 1
        K2: 0
        K3: 1
        K4: 0
        K5: 0
        K6: 0
        Hold Time: 15
    Software Version: EIGRP=12.4, TLV=1.2
        Type: Software Version (0x0004)
        Length: 8
        EIGRP Release: 12.04
        EIGRP TLV version: 1.02
    Sequence
        Type: Sequence (0x0003)
        Length: 9
        Address length: 4
        IP Address: 10.0.0.1
    Next multicast sequence: 25
        Type: Next multicast sequence (0x0005)
        Length: 8
        Multicast Sequence: 25

update消息 抓包报文
#会话建立 1 from 1 to 2
Cisco EIGRP
    Version: 2
    Opcode: Update (1)
    Checksum: 0xfd82 [correct]
    [Checksum Status: Good]
    Flags: 0x00000001, Init
        .... .... .... .... .... .... .... ...1 = Init: Set
        .... .... .... .... .... .... .... ..0. = Conditional Receive: Not set
        .... .... .... .... .... .... .... .0.. = Restart: Not set
        .... .... .... .... .... .... .... 0... = End Of Table: Not set
    Sequence: 23
    Acknowledge: 0
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 100
#会话建立 2 from 2 to 1
Cisco EIGRP
    Version: 2
    Opcode: Update (1)
    Checksum: 0xfd6b [correct]
    [Checksum Status: Good]
    Flags: 0x00000001, Init
        .... .... .... .... .... .... .... ...1 = Init: Set
        .... .... .... .... .... .... .... ..0. = Conditional Receive: Not set
        .... .... .... .... .... .... .... .0.. = Restart: Not set
        .... .... .... .... .... .... .... 0... = End Of Table: Not set
    Sequence: 23
    Acknowledge: 23
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 100

#路由信息传递1  from 1 to 2
Cisco EIGRP
    Version: 2
    Opcode: Update (1)
    Checksum: 0x24b9 [correct]
    [Checksum Status: Good]
    Flags: 0x00000008, End Of Table
        .... .... .... .... .... .... .... ...0 = Init: Not set
        .... .... .... .... .... .... .... ..0. = Conditional Receive: Not set
        .... .... .... .... .... .... .... .0.. = Restart: Not set
        .... .... .... .... .... .... .... 1... = End Of Table: Set
    Sequence: 24
    Acknowledge: 23
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 100
    Internal Route(IPv4)  =   192.168.1.0/24
        Type: Internal Route(IPv4) (0x0102)
        Length: 28
        NextHop: 0.0.0.0
        Legacy Metric
            Scaled Delay: 2560
            Scaled BW: 25600
            MTU: 1500
            Hop Count: 0
            Reliability: 255
            Load: 1
            Route Tag: 0
            Flags
                .... ...0 = Source Withdraw: False
                .... ..0. = Candidate Default: False
                .... .0.. = Route is Active: False
                .... 0... = Route is Replicated: False
        Prefix Length: 24
        Destination: 192.168.1.0
            
            
#路由信息传递2  from 2 to 1
Cisco EIGRP
    Version: 2
    Opcode: Update (1)
    Checksum: 0x7d9b [correct]
    [Checksum Status: Good]
    Flags: 0x00000008, End Of Table
        .... .... .... .... .... .... .... ...0 = Init: Not set
        .... .... .... .... .... .... .... ..0. = Conditional Receive: Not set
        .... .... .... .... .... .... .... .0.. = Restart: Not set
        .... .... .... .... .... .... .... 1... = End Of Table: Set
    Sequence: 24
    Acknowledge: 24
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 100
        
        
#更新后的路由信息传递 to 组播
Cisco EIGRP
    Version: 2
    Opcode: Update (1)
    Checksum: 0xa2d8 [correct]
    [Checksum Status: Good]
    Flags: 0x00000002, Conditional Receive
        .... .... .... .... .... .... .... ...0 = Init: Not set
        .... .... .... .... .... .... .... ..1. = Conditional Receive: Set
        .... .... .... .... .... .... .... .0.. = Restart: Not set
        .... .... .... .... .... .... .... 0... = End Of Table: Not set
    Sequence: 25
    Acknowledge: 0
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 100
    Internal Route(IPv4)  =   192.168.1.0/24
        Type: Internal Route(IPv4) (0x0102)
        Length: 28
        NextHop: 0.0.0.0
        Legacy Metric
            Scaled Delay: 4294967295
            Scaled BW: 256000
            MTU: 1500
            Hop Count: 1
            Reliability: 255
            Load: 1
            Route Tag: 0
            Flags
                .... ...0 = Source Withdraw: False
                .... ..0. = Candidate Default: False
                .... .0.. = Route is Active: False
                .... 0... = Route is Replicated: False
        Prefix Length: 24
        Destination: 192.168.1.0

#更新后的路由信息  from 2 to 1
Cisco EIGRP
    Version: 2
    Opcode: Update (1)
    Checksum: 0xa2c2 [correct]
    [Checksum Status: Good]
    Flags: 0x00000000
        .... .... .... .... .... .... .... ...0 = Init: Not set
        .... .... .... .... .... .... .... ..0. = Conditional Receive: Not set
        .... .... .... .... .... .... .... .0.. = Restart: Not set
        .... .... .... .... .... .... .... 0... = End Of Table: Not set
    Sequence: 25
    Acknowledge: 24
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 100
    Internal Route(IPv4)  =  #上一条一致

Query消息
Cisco EIGRP
    Version: 2
    Opcode: Query (3)
    Checksum: 0xf9cc [correct]
    [Checksum Status: Good]
    Flags: 0x00000000
        .... .... .... .... .... .... .... ...0 = Init: Not set
        .... .... .... .... .... .... .... ..0. = Conditional Receive: Not set
        .... .... .... .... .... .... .... .0.. = Restart: Not set
        .... .... .... .... .... .... .... 0... = End Of Table: Not set
    Sequence: 5
    Acknowledge: 0
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 1
    Internal Route(IPv4)  =   1.1.1.0/24
        Type: Internal Route(IPv4) (0x0102)
        Length: 28
        NextHop: 0.0.0.0
        Legacy Metric
            Scaled Delay: 4294967295
            Scaled BW: 0
            MTU: 1514
            Hop Count: 0
            Reliability: 0
            Load: 0
            Route Tag: 0
            Flags
                .... ...0 = Source Withdraw: False
                .... ..0. = Candidate Default: False
                .... .1.. = Route is Active: True            #查询消息
                .... 0... = Route is Replicated: False
        Prefix Length: 24
        Destination: 1.1.1.0

reply
Cisco EIGRP
    Version: 2
    Opcode: Reply (4)
    Checksum: 0xf9c4 [correct]
    [Checksum Status: Good]
    Flags: 0x00000000
        .... .... .... .... .... .... .... ...0 = Init: Not set
        .... .... .... .... .... .... .... ..0. = Conditional Receive: Not set
        .... .... .... .... .... .... .... .0.. = Restart: Not set
        .... .... .... .... .... .... .... 0... = End Of Table: Not set
    Sequence: 11
    Acknowledge: 5
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 1
    Internal Route(IPv4)  =   1.1.1.0/24

  • 大概流程:发送hello消息后,建好邻居表,使用update LSA/LSP LSDB链路状态数据库(可以形成拓扑表)

  • 网络结构:Layer 2 |IPV4|EIGRP|FCS protocol| 88 该消息是 先有控制层面,再有数据层面数据。

  • EIGRP使用混合度量值进行计算路径的好坏,主要包含5个方面

    • 带宽:bd

    • 延迟:delay

    • 负载:load

    • 可靠性:reliability

    • 最大传输单元:MTU(基本不做计算)

  • eigrp进行路劲好坏计算时用的两个参数:AD、FD(表示不同的代价,代价由上面的五个参数结合k值(下文)权重计算)。A路由器要到达C路由,需要经过B路由或者D路由,AD是B到C的代价,FD则是A通过计算A到B的代价加上AD 得到新的A由B到C的代价FD1 ,或者A由D到C的代价FD2,并使用 min(FD1,FD2)得到最优的路径,次路径为备份路径。

    AD和FD的计算方法

  • 建立邻居的必要条件

    • 收到hello ack

    • 匹配AS:EIGRP两台路由器需要建立令居需要AS号相同。

      • 相同的度量值(K值)

        • 路径度量值权重 (0-255)

          k1 1 带宽 的权重

          k2 0 负载 的权重

          k3 1 延迟 的权重

          k4 0 可靠性 的权重

          k5 0 最大传输单元 的权重

    • 其他条件:认证通过。

报文交换&建立过程

一旦收到任何符合条件(AS相同,度量值权重K相同)邻居的hello报文,则将发送者设置为邻居,并向对方单播发送update报文,该报文不携带路由信息,其中 flag init位置位。

  • step1:10.0.0.2 向224.0.0.10 进行组播

    image-20231109134207439

  • step2: 10.0.0.1收到hello消息后,回复给10.0.0.2 单播 update信息,修改init标志位,产生随机序列号。

    image-20231109134459297

  • setp4: 10.0.0.2 收到来自10.0.0.1的update消息后,向10.0.0.1发送update消息,并确认序列号,实现握手。

    image-20231109134904739

  • step5:10.0.0.1 收到update消息,知道10.0.0.2也是init了,开始向10.0.0.2传播数据。并设置end标志位,表示10.0.0.1的路由信息已传完。

    image-20231109135313636

    路由参数

# 10.0.0.1 的一条路由信息。
Internal Route(IPv4)  =   192.168.1.0/24 
    Type: Internal Route(IPv4) (0x0102) #内部路由
    Length: 28							#
    NextHop: 0.0.0.0					#下一跳,0.0.0.0表示自己
    Legacy Metric						#度量值
        Scaled Delay: 25600				#延迟
        Scaled BW: 256000				#带宽
        MTU: 1500						#MTU
        Hop Count: 0					#跳数
        Reliability: 255				#可靠性
        Load: 1							#负载
        Route Tag: 0					#路由标记
        Flags
            .... ...0 = Source Withdraw: False
            .... ..0. = Candidate Default: False
            .... .0.. = Route is Active: False
            .... 0... = Route is Replicated: False
    Prefix Length: 30
    Destination: 10.0.0.4				#目的地址
  • step6:10.0.0.2 收到update消息,获取到10.0.0.1的路由信息,同时向10.0.0.1传播本机的路由数据。并设置end标志位,表示10.0.0.2的路由信息已传完。下面的路由是10.0.0.2的。

    image-20231109140045257

  • step7: 10.0.0.1收到后,向10.0.0.2 发送确认消息 确认号为ack 24

    image-20231109140255181

    image-20231109143021120

  • 下面为公告自己的最新路由信息

  • step8:在更新完自身的最佳路由后,10.0.0.2 又发hello消息,但是携带的参数更多。包括 序列携带下一个组播序列号,接着马上发送更新后的路由信息。该信息中Sequence中的路由器不会被设置为CR,但是其他都会被设置为CR,方便2发送新的CR消息通知其他被设置为CR的路由

    image-20231109144136472

  • step9: 10.0.0.2 向组播地址以及 sequence中的路由器 发送update消息 传递参数,携带更新的路由信息(即只发送已更改的、新增或删除的路由信息,而不是发送整个路由表)。发送CR消息,该消息10.0.0.1不会被接受,其他都会被接受

    image-20231109145403223

  • step10: 10.0.0.2 向step8中的 sequence中的路由器 发送update消息 告知最近的路由信息。

    image-20231109161407087

  • step11 : 10.0.0.1 收到update消息后对10.0.0.2进行确认回复。

    image-20231109161540454

  • step12 : 10.0.0.1 向组播地址 发送update消息 传递参数,携带更新的路由信息(即只发送已更改的、新增或删除的路由信息,而不是发送整个路由表)。

    image-20231109161857338

  • step13 : 10.0.0.2 向10.0.0.1 回复确认。

    image-20231109162302976

  • 更新的路由分析

    这里发布的信息是更新的信息,表示路由1 更新了3条路由信息,以跳数为例子(当中涉及其他的权重计算)

    image-20231110093632022

  • 最终的路由信息,综合更新的路由一起。

    image-20231110094139676

  • 大致的拓扑结构

    image-20231110100058969

两个节点未知

image-20231110100112443

结构突变

(1)新增网段:直连新增网段的设备,使用更新包 update消息告知所有邻居即可

(2)断开网段:直连断开网段的设备,发出查询包Query消息,通过DUAL,收集应答包来重新收敛;完成全网同步。

(3)设备无法沟通:hello time 5s hold time 15s 。hold time (采取的是倒计时方式)计时器结束断开邻居关系,同时产生删除所有从邻居出学习到的信息

断开网段
Cisco EIGRP
    Opcode: Query (3)
    Internal Route(IPv4)  =   1.1.1.0/24
        Type: Internal Route(IPv4) (0x0102)
        Length: 28
        NextHop: 0.0.0.0
        Legacy Metric
            Scaled Delay: 4294967295
            Scaled BW: 0
            MTU: 1514
            Hop Count: 0
            Reliability: 0
            Load: 0
            Route Tag: 0
            Flags
            # False,即源撤回标志位未设置。该标志位通常与路由划分和路由更新相关,用于指示是否有源节点撤回了路由信息。
                .... ...0 = Source Withdraw: False	
             #即候选默认路由标志位未设置。候选默认路由用于在没有更具体的路由匹配时,作为默认路径来转发数据包。
                .... ..0. = Candidate Default: False
                .... .1.. = Route is Active: True  #该路由是活动的,被选定为转发数据流量的路径。
                .... 0... = Route is Replicated: False#False,即路由未进行复制。这表示该路由未被复制到其他设备上。
        Prefix Length: 24
        Destination: 1.1.1.0

image-20231110122452105

参考文献

参考文献:
https://zhuanlan.zhihu.com/p/393295263
https://blog.csdn.net/Sisyphuss/article/details/132633851
https://www.cisco.com/c/en/us/support/docs/ip/enhanced-interior-gateway-routing-protocol-eigrp/16406-eigrp-toc.html

eigrp关键参数

1 AS号、系数K值是否与自己的一致。如果一致,则建立邻居关系,得到一个自治域的路由器列表。同时监听路由器的hello消息,如果超时,可能该路由已经下线。 编程:将K和AS作为 自治域的 key

Cisco EIGRP
    Version: 2
    Opcode: Hello (5)			#确定消息类型  #Opcode字段,报文类型:1 Update、 3 Query、 4 Reply、 5 Hello/ACK
    Checksum: 0xee68 [correct]
    [Checksum Status: Good]  
    Flags: 0x00000000						#确定update消息类型的关键参数  为1 表示 握手,0x00000008表示交换路由信息
    Sequence: 0 
    Acknowledge: 0  
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 100                   #确定自治域的关键参数  *******************
    Parameters
        Type: Parameters (0x0001)
        Length: 12
        K1: 1								# #关键参数
        K2: 0								# #关键参数
        K3: 1								 #关键参数
        K4: 0								 #关键参数
        K5: 0								 #关键参数
        K6: 0								#关键参数
        Hold Time: 15
    Software Version: EIGRP=12.4, TLV=1.2
        Type: Software Version (0x0004)
        Length: 8
        EIGRP Release: 12.04
        EIGRP TLV version: 1.02

2 使用update消息,获取路由信息,根据路由信息 统计路由表

# 1 路由A和B 相互发送该报文 但是IPV4参数不一样 flag为8    携带源ip和目的ip 根据源ip确定该路由的路由变化
Cisco EIGRP
    Version: 2
    Opcode: Update (1)  
    Checksum: 0x24b9 [correct]
    [Checksum Status: Good]
    Flags: 0x00000008, End Of Table   #关键参数 确保这是个报文交换消息
    Sequence: 24
    Acknowledge: 23
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 100
    Internal Route(IPv4)  =   192.168.1.0/24  #关键参数,
    Internal Route(IPv4)  =   10.0.0.4/30
    Internal Route(IPv4)  =   192.168.3.0/24
    Internal Route(IPv4)  =   10.0.0.12/30
    Internal Route(IPv4)  =   192.168.4.0/24
    Internal Route(IPv4)  =   10.0.0.8/30
    Internal Route(IPv4)  =   192.168.2.0/24
#2 AB收到路由信息后,双发 发出更新的路由信息 此时flag为0  携带源ip和目的ip  根据源ip确定该路由的路由变化
Cisco EIGRP
    Version: 2
    Opcode: Update (1)
    Checksum: 0x9dd9 [correct]
    [Checksum Status: Good]
    Flags: 0x00000000
    Sequence: 25
    Acknowledge: 0
    Virtual Router ID: 0 (Address-Family)
    Autonomous System: 100
    Internal Route(IPv4)  =   192.168.2.0/24
    Internal Route(IPv4)  =   10.0.0.8/30
    Internal Route(IPv4)  =   192.168.4.0/24

eigrp拓扑图

  • 1 获取自治域。

  • 2 获取路由器信息

    根据EIGRP.flag==8判断是否是交换路由消息;根据EIGRP.flag==0判断是否是更新消息。得到两个的报文信息。

  • 3 获取路由器的路由表信息

  • 4 获取具体的网口信息

    image-20231113101558606

处理代码-python

class As_system:
    """自治与"""

    def __init__(self, key, as_num, routers):
        self.key = key
        self.as_num = as_num
        self.routers = routers


class Router:
    def __init__(self, ASNum, router_id, addr_mac, super_mac, ip):
        self.ASNum = ASNum  # 路由域
        self.router_id = router_id  # id
        self.addr_mac = addr_mac  # 路由器mac
        self.super_mac = super_mac  # 上级路由器

        self.ip = ip
        self.port = 0
        self.neigbhor = []  # 邻居表
        self.router_info_raw = []  # 路由信息
        self.router_info_other = []  # 路由信息
        self.router_info_new = []  # 路由信息
        self.key = hash(addr_mac)


class Internal:
    def __init__(self):
        self.rouType = 0
        self.nextHop = 0
        self.metric = 0
        self.dst = 0


class Node:
    def __init__(self, name):
        self.name = name
        self.edges = []

    def add_edge(self, node, weight=1):
        self.edges.append((node, weight))


class Graph:
    def __init__(self):
        self.nodes = {}

    def add_node(self, node):
        self.nodes[node.name] = node

    def add_edge(self, node1, node2, weight=1):
        if node1.name in self.nodes and node2.name in self.nodes:
            self.nodes[node1.name].add_edge(node2, weight)
            self.nodes[node2.name].add_edge(node1, weight)
        else:
            raise ValueError("Both nodes must be added to the graph before adding an edge.")


def creat_router(packet):
    """"前置条件,hello消息,为组播"""
    global router_id
    global router_dict
    global router_ip_dict

    comm = packet["comm"][0]
    eigrp = packet["eigrp"]
    asnum = eigrp["ASNum"]
    # k=eigrp["k"]  #获取到key
    k = "01001"  # 获取到key
    as_key = hash((asnum, k))
    classic = []
    if eigrp["flag"] == 8 and eigrp["opCode"] == 1:
        classic = eigrp["classic"]
        router_ip_dict[comm["srcMac"]] = classic
    if as_key in router_dict:
        as_system = router_dict[as_key]
        routers = as_system["routers"]  #
        routers_mac = as_system["routers_mac"]  #
        if comm["srcMac"] in routers_mac:
            router = routers[comm["srcMac"]]
            if len(classic) > 0:
                router.router_info_raw = classic
        else:
            router_id += 1
            router = Router(asnum, router_id, comm["srcMac"], comm["dstMac"], comm["srcAddr"])
            router.router_info_raw = classic
            routers[comm["srcMac"]] = router
            routers_mac.append(comm["srcMac"])
    else:
        router_id += 1
        router_dict[as_key] = {
            "key": as_key,
            "as_num": asnum,
            "routers": {},
            "routers_mac": [comm["srcMac"]]
        }
        routers = router_dict[as_key]["routers"]
        router = Router(asnum, router_id, comm["srcMac"], comm["dstMac"], comm["srcAddr"])
        router.router_info_raw = classic
        routers[comm["srcMac"]] = router


globals()["router_id"] = 0
globals()["router_dict"] = {}
globals()["router_ip_dict"] = {}

import json

# 指定本地 JSON 文件路径
file_path = "data/0EC0A8582C0C1C4F_192.168.88.44_1.json"
# file_path = "data/data.json"
with open(file_path, "r", encoding="gbk", errors="ignore") as file:
    lines = file.readlines()
data_list = []
for line in lines:
    data = json.loads(line)
    data_list.append(data)
for item in data_list:
    creat_router(item)  # 创建路由集合

print("end")

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

魔芋小灰菜

不要下次一定,要一键三连

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值