0
votes

I have a Pox-based SDN application that listens for PacketIns to the controller. I would like to check if a packet to the controller is ICMP. The Pox docs provide an example to check if a PacketIn is ARP as shown by the following code.

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

But I cannot use the same logic to check for ICMP messages:

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

The latter code returns an error:

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

There is no packet.ICMP_TYPE, which can be seen by checking dir(packet).

The packet.type is equal to a number which represents a protocol, and somewhere in the pox code these numbers are probably neatly laid out besides the protocols they represent - I have no idea where this may be. For example, I can see that the packet.type of my PacketIn is 2048, but I don't know which protocol that represents or how to find out.

1
I am not sure about this but i think this link will help groups.google.com/forum/#!topic/nox_dev/dQzwOShh4C0. To get icmp type try doing something like this. tp = packet.icmp() if packet.type == tp.type: # do somethingPoojan
@Poojan Thanks, I tried tp = packet.icmp() and got the error message *** AttributeError: 'ethernet' object has no attribute 'icmp'. I don't see how to check if a PacketIn is ICMP from the link.Astrophe
I think this link covers it: github.com/noxrepo/pox/issues/205. It includes the following quote from MurphyMc "To check if the packet in a POX packet-in handler contains ICMP, the easiest way is to see if .find("icmp") returns something besides None."Astrophe
So did it worked?Poojan
@Poojan some ICMP packets are being detected but I think some are passing through undetected. I'll post an update if it gets any clearer.Astrophe

1 Answers

0
votes

There is no ICMP TYPE constant. ICMP packets are actually IP packets. Hence the below code will help.

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