python - 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,但是不知道代表的是哪个协议,也不知道怎么查。
解决方案
没有 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
推荐阅读
- php - sql_mode 适用于 php,但不适用于外部数据库管理工具
- python - 如何从我的机器人获取语音频道中的成员列表?
- python - 如何正确重新投影具有多个几何列的地理数据框?
- python - 找到每个子数组的最小值并返回这些最小值的最大值
- r - 如何“命名”每个 JSON 对象
- php - Composer 真的很酷,但是我们如何知道其中一个所需的包中是否存在严重错误?
- python - 接受几种类型之一的(同质)序列的函数的类型提示
- python - 对字符串列表进行数字排序并过滤重复项?
- azure-active-directory - Ocelot 与 Azure Active Directory 身份验证 .Net Core 3.1 集成
- c# - 无法在 Owin 中读取请求正文(卡在 ReadAsStringAsync 中)