SDN Pox控制器:ARP_TYPE,IP_TYPE,但没有ICMP_TYPE

问题描述 投票:0回答:1

我有一个基于Pox的SDN应用程序,该应用程序侦听Controller的PacketIns。我想检查发送给控制器的数据包是否为ICMP。 Pox文档为check if a PacketIn is ARP提供了一个示例,如以下代码所示。

def _handle_PacketIn (self, event):
packet = event.parsed
if packet.type == packet.ARP_TYPE: # packet.ARP_TYPE is const equal to 2054
    # do something neat with the packet
    pass

但是我不能使用相同的逻辑来检查ICMP消息:

def _handle_PacketIn (self, event):
packet = event.parsed
if packet.type == packet.ICMP_TYPE:
    # do something neat with the packet
    pass

后面的代码返回错误:

*** AttributeError: 'ethernet' object has no attribute 'ICMP_TYPE'

没有数据包。ICMP_TYPE,可以通过检查dir(数据包)看到。

packet.type等于代表协议的数字,在pox代码中的某个地方,这些数字除了它们所代表的协议外还整齐地排列着-我不知道它在哪里。例如,我可以看到我的PacketIn的packet.type是2048,但是我不知道代表哪个协议或如何找出。

python openflow pox
1个回答
0
投票

没有ICMP TYPE常量。 ICMP数据包实际上是IP数据包。因此,以下代码会有所帮助。

def parse_icmp (eth_packet):
    if eth_packet.type == pkt.IP_TYPE:
        ip_packet = eth_packet.payload
        if ip_packet.protocol == pkt.ICMP_PROTOCOL:
            icmp_packet = ip_packet.payload
© www.soinside.com 2019 - 2024. All rights reserved.