Hi Weiyun,
Can you try applying the following patch below and see if it resolves your
issue? Also it looks like your code doesn't copy the ICMP request payload
to the reply. Maybe try adding:
icmp_header.next = packet.find("icmp").next
Aaron
diff --git a/src/nox/lib/packet/ipv4.py b/src/nox/lib/packet/ipv4.py
index 5728e11..4fa5fe3 100644
--- a/src/nox/lib/packet/ipv4.py
+++ b/src/nox/lib/packet/ipv4.py
@@ -73,7 +73,7 @@ class ipv4(packet_base):
self.hl = ipv4.MIN_LEN / 4
self.tos = 0
self.iplen = ipv4.MIN_LEN
- self.id = int(time.time())
+ self.id = int(time.time()) & 0xffff
ipv4.ip_id += 1
self.flags = 0
self.frag = 0
@@ -155,12 +155,20 @@ class ipv4(packet_base):
self.next = self.arr[self.hl*4:length].tostring()
def checksum(self):
- data = struct.pack('!BBHHHBBHII', (self.v << 4) + self.hl,
self.tos, \
+ try:
+ data = struct.pack('!BBHHHBBHII', (self.v << 4) + self.hl,
self.tos, \
self.iplen, self.id, \
(self.flags << 13) | self.frag, self.ttl,
\
self.protocol, 0, self.srcip, \
self.dstip)
- return checksum(data, 0)
+ return checksum(data, 0)
+ except:
+ print "bad packet",[(self.v << 4) + self.hl,
+ self.tos,
+ self.iplen, self.id,
+ (self.flags << 13) | self.frag, self.ttl,
+ self.protocol, 0, self.srcip,
+ self.dstip]
def hdr(self):
On Thu, Jul 12, 2012 at 5:55 PM, Murphy McCauley
<[email protected]>wrote:
> Another note is that you can't set the payload property using the NOX
> version of the packet library. You have to call set_payload():
>
> outer.set_payload(inner)
>
> .. that should definitely give you a better chance of things working.
>
> -- Murphy
>
> On Jul 11, 2012, at 9:53 AM, Weiyun wrote:
>
> Hi,
>
> I followed pong.py from POX to create an ICMP reply using NOX, the packet
> captured by wireshark says “Malformed Packet: IP”. I looked into the
> packet, the ethernet header seems fine.
>
> Here is my codes, could you help me to check where I did wrong?
> Is it because icmp has no payload?
> Or, ethernet_header.tostring() is the wrong argument when calling
> send_openflow_packet?
>
> Thank you very much.
>
> Weiyun
>
> from nox.lib.packet.ethernet import ethernet
> from nox.lib.packet.ipv4 import ipv4
> from nox.lib.packet.icmp import icmp
>
> # ICMP reply
> icmp_header = icmp()
> # icmp.TYPE_ECHO_REPLY = 0
> icmp_header.type = 0
> #icmp_header.payload = packet.find("icmp").payload
> #Controller print: AttributeError: icmp instance has no attribute
> 'payload'
>
> ip_header = ipv4()
> ip_header.protocol = ipv4.ICMP_PROTOCOL
> ip_header.srcip = packet.next.dstip
> ip_header.dstip = packet.next.srcip
>
> ethernet_header = ethernet()
> ethernet_header.src = packet.dst
> ethernet_header.dst = packet.src
> ethernet_header.type = ethernet.IP_TYPE
>
> ip_header.payload = icmp_header
> ethernet_header.payload = ip_header
>
> actions = [[openflow.OFPAT_OUTPUT, [0, inport]]]
> # call send_openflow_packet(self, dp_id, packet, actions,
> inport=openflow.OFPP_CONTROLLER)
> inst.send_openflow_packet(dpid, ethernet_header.tostring(), actions,
> openflow.OFPP_CONTROLLER)
>
>
>
> *From:* Murphy McCauley <[email protected]>
> *Sent:* Tuesday, July 10, 2012 3:39 PM
> *To:* Weiyun <[email protected]>
> *Cc:* [email protected]
> *Subject:* Re: [nox-dev] How to generate ICMP packet?
>
> On Jul 10, 2012, at 12:24 PM, Weiyun wrote:
>
> Could you give me an example how to generate a ICMP reply message?
>
> I suppose that first create packet_base instance, then add ipv4 header,
> and then icmp header?
>
>
> More like an *ethernet* and then ipv4 and then icmp.
>
> Is there a way to copy necessary information from ICMP request to reply
> message, and then modify some attributes?
>
>
> Sure. Just copy it.
>
> The pong.py sample in POX does exactly this. It won't quite work with
> NOX's version of the packet library, but it may be useful as an example.
>
>
> How about ICMP unreachable message?
>
>
> Well, you can read the RFC and set the fields appropriately.
>
> Also, POX's l2_multi.py has an example of generating destination
> unreachable messages. Again, it won't be directly usable in NOX, but it
> might be helpful.
>
>
> Hope that helps.
>
> -- Murphy
>
>
>