0

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.

Astrophe
  • 568
  • 1
  • 7
  • 25
  • I am not sure about this but i think this link will help https://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 something` – Poojan Jan 28 '19 at 18:27
  • @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 Jan 28 '19 at 18:55
  • I think this link covers it: https://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 Jan 28 '19 at 19:30
  • So did it worked? – Poojan Jan 28 '19 at 19:31
  • @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 Jan 28 '19 at 20:14
  • Thanks I have worked little bit with SDN with mininet and RYU controller but pox is new for me so it will be great to know the answer. – Poojan Jan 28 '19 at 20:16
  • @Poojan yes it is working : ). I've read various bits and pieces about Ryu so I may try it in the future. – Astrophe Jan 28 '19 at 20:30

1 Answers1

0

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