librelist archives

« back to archive

Newbie question - how to create new packet with modified paylod

Newbie question - how to create new packet with modified paylod

From:
Tibor Moore
Date:
2014-10-23 @ 08:05
Dear all,

I'm a student and a newbie in click so please forgive me the following 
trivial questions, but I really need some help to start. I'm trying to 
implement network coding into a custom click element. My plan is to encode
only the data of the incoming packet and then create a new packet with all
the same informations included (headers, refreshed checksums and all the 
other annotations), but with the encoded data in it.

I've tried to check a lot of source code for it (iprewriter.cc, 
tcpipsend.cc, etc.) and the mailing-list archives but it is still not 
clear how to do it. 

Could anyone give me a simple and clear code example how I can modify the 
data and create the new packet? 

There are two ways I've tried it: make() and uniqueify().
I tried to use make like this, but got segmentation fault:

const unsigned char *lowers = (const unsigned char 
*)"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";

WritablePacket *wp = Packet::make(p->headroom(),lowers,54,p->tailroom());
wp->copy_annotations(p); 
if(p->has_mac_header()){
const click_ether *eth = p->ether_header();
wp->set_mac_header(reinterpret_cast<const unsigned char *>(eth), 14);
}
if(p->has_network_header()){
const click_ip *iph = p->ip_header();
wp->set_ip_header(iph, p->ip_header_length());
}

For uniqueify the problem is that I can't set the data() and end_data() pointers:

WritablePacket *wp = p->uniqueify();
wp->data() = lowers;
wp->end_data() = lowers + 54;

And finally I think I should update the checksums somehow.

If the above examples would work can I consider the new packet as 
"identical" to the original, except that contatins the new data? 

Thank you in advance for the help!

Tibor

Re: [click] Newbie question - how to create new packet with modified paylod

From:
Braem Bart
Date:
2014-10-23 @ 08:13
On 23 Oct 2014, at 10:05, Tibor Moore 
<tibormoore@yahoo.de<mailto:tibormoore@yahoo.de>> wrote:

I'm a student and a newbie in click so please forgive me the following 
trivial questions, but I really need some help to start. I'm trying to 
implement network coding into a custom click element. My plan is to encode
only the data of the incoming packet and then create a new packet with all
the same informations included (headers, refreshed checksums and all the 
other annotations), but with the encoded data in it.

I've tried to check a lot of source code for it 
(iprewriter.cc<http://iprewriter.cc/>, tcpipsend.cc<http://tcpipsend.cc/>,
etc.) and the mailing-list archives but it is still not clear how to do 
it.

Could anyone give me a simple and clear code example how I can modify the 
data and create the new packet?


Take a look at our documentation at 
https://github.com/mosaicresearch/click_modular_router_lessons
Especially the coding slides will be of interest.

best regards,
Bart

Re: [click] Newbie question - how to create new packet with modified paylod

From:
Tibor Moore
Date:
2014-10-23 @ 09:04
 
Hi Bart, 


thanks for the quick answer, I've already checked that slide and I had 
been able to create a packet just it's own. The problem as I wrote that I 
need a 
packet that is almost identical to the one that arrived so I should 
either set the header annotations correctly (which results a seg error) 
or set the data pointers correctly which leads an "lvalue required as 
left operand of assignment" error. 


Nevertheless when I try to use the code from the slide for creating a 
packet, one more errors occured: 
mysimpleforwarder.cc:83:70: error: invalid application of ‘sizeof’ to 
incomplete type ‘click_ether’
  int headroom = sizeof(click_ip)+sizeof(click_udp)+sizeof(click_ether);

Thanks for the patience,
TIbor


Braem Bart <bart.braem@uantwerpen.be> schrieb am 10:13 Donnerstag, 
23.Oktober 2014:
 


On 23 Oct 2014, at 10:05, Tibor Moore <tibormoore@yahoo.de> wrote:



I'm a student and a newbie in click so please forgive me the following 
trivial questions, but I really need some help to start. I'm trying to 
implement network coding into a custom click element. My plan is to encode
only the data of the incoming packet and then create a new packet with all
the same informations included (headers, refreshed checksums and all the 
other annotations), but with the encoded data in it.
>
>
>I've tried to check a lot of source code for it (iprewriter.cc, 
tcpipsend.cc, etc.) and the mailing-list archives but it is still not 
clear how to do it.
>
>
>Could anyone give me a simple and clear code example how I can modify the
data and create the new packet?
>
>
>
Take a look at our documentation at 
https://github.com/mosaicresearch/click_modular_router_lessons 
Especially the coding slides will be of interest.

best regards,
Bart

Re: [click] Newbie question - how to create new packet with modified paylod

From:
Braem Bart
Date:
2014-10-23 @ 09:11
On 23 Oct 2014, at 11:04, Tibor Moore 
<tibormoore@yahoo.de<mailto:tibormoore@yahoo.de>> wrote:

thanks for the quick answer, I've already checked that slide and I had 
been able to create a packet just it's own. The problem as I wrote that I 
need a packet that is almost identical to the one that arrived so I should
either set the header annotations correctly (which results a seg error) or
set the data pointers correctly which leads an "lvalue required as left 
operand of assignment" error.

Nevertheless when I try to use the code from the slide for creating a 
packet, one more errors occured:
mysimpleforwarder.cc<http://mysimpleforwarder.cc/>:83:70: error: invalid 
application of ‘sizeof’ to incomplete type ‘click_ether’
  int headroom = sizeof(click_ip)+sizeof(click_udp)+sizeof(click_ether);

That’s your compiler telling you to include the header for click_ether:
#include <clicknet/ether.h>

best regards,
Bart

Re: [click] Newbie question - how to create new packet with modified paylod

From:
Tibor Moore
Date:
2014-10-23 @ 09:46
Sorrry, it was my fault, the header include is truly needed.

In the meanwhile I could modify the data in this way: 

    const unsigned char *lowers = (const unsigned char 
*)"abcdefghijklmnopqurstxyvzabcdefghijklmnopqurstxyvzabcdefghijklmnopqurstxyvzabcdefghijklmnopqurstxyvz";

    wp = p->uniqueify();
    memset(wp->data(), 0, wp->length());
    memcpy(wp->data(), lowers, wp->length());

One last question about this: is there any further calculation that is 
needed (I mean the checksums for example) or now it can be sent forward?

Thanks! 



Braem Bart <bart.braem@uantwerpen.be> schrieb am 11:11 Donnerstag, 
23.Oktober 2014:
 


On 23 Oct 2014, at 11:04, Tibor Moore <tibormoore@yahoo.de> wrote:



thanks for the quick answer, I've already checked that slide and I had 
been able to create a packet just it's own. The problem as I wrote that I 
need a packet that is almost identical to the one that arrived so I should
either set the header annotations correctly (which results a seg error) or
set the data pointers correctly which leads an "lvalue required as left 
operand of assignment" error. 
>
>
>
>Nevertheless when I try to use the code from the slide for creating a 
packet, one more errors occured: 
>mysimpleforwarder.cc:83:70: error: invalid application of ‘sizeof’ to 
incomplete type ‘click_ether’
>  int headroom = sizeof(click_ip)+sizeof(click_udp)+sizeof(click_ether);
>

That’s your compiler telling you to include the header for click_ether:
#include <clicknet/ether.h>

best regards,
Bart