首页 > 解决方案 > SDN Pox 控制器:ARP_TYPE、IP_TYPE,但没有 ICMP_TYPE

问题描述

我有一个基于 Pox 的 SDN 应用程序,它监听 PacketIns 到控制器。我想检查到控制器的数据包是否是 ICMP。Pox 文档提供了一个示例来检查 PacketIn 是否为 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'

没有packet.ICMP_TYPE,通过查看dir(packet)可以看到。

packet.type 等于一个代表协议的数字,在 pox 代码的某个地方,除了它们代表的协议之外,这些数字可能整齐地排列——我不知道这可能在哪里。比如我可以看到我的PacketIn的packet.type是2048,但是不知道代表的是哪个协议,也不知道怎么查。

标签: pythonopenflowpox

解决方案


没有 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

推荐阅读