[Click] click element customization
Ruetee Chitpranee
rueteec at gmail.com
Thu Dec 22 17:51:33 EST 2011
Hi,
First of all, I'm really a beginner for Click. Now, I'm trying to customize
InfiniteSource to correct IP Header checksum as always (..for trying and
make me understand better about click elements :)
My idea is on function run_task (or function setup_packet() -- but seems
cannot manage anything here :-/, before push result packet out, I will
extract "click_ip" from the packet and process checksum update, then set
the header back.
Look simple but I still got Segmentation fault :(
Here is what I did ...
bool
InfiniteSourcex::run_task(Task *)
{
if (!_active || !_nonfull_signal)
return false;
int n = _burstsize;
if (_limit >= 0 && _count + n >= (ucounter_t) _limit)
n = (_count > (ucounter_t) _limit ? 0 : _limit - _count);
for (int i = 0; i < n; i++) {
Packet *p = _packet->clone();
if (_timestamp)
p->timestamp_anno().assign_now();
///////// customize here /////////
click_ip *ip = const_cast<click_ip *>(p->ip_header());
//// solution1: code from SetIPChecksum element////
unsigned plen, hlen;
plen = p->network_length();
hlen = ip->ip_hl << 2;
click_chatter("network len is %u", plen);
click_chatter("ip len is %u", hlen);
ip->ip_sum = 0;
ip->ip_sum = click_in_cksum((unsigned char *)ip, hlen);
p->set_ip_header(ip, sizeof(click_ip));
//// solution2: code from IPEncap element////
if (ip->ip_len) { // use_dst_anno
ip->ip_dst = p->dst_ip_anno();
update_cksum(ip, 16);
update_cksum(ip, 18);
} else
p->set_dst_ip_anno(IPAddress(ip->ip_dst));
ip->ip_len = htons(p->length());
ip->ip_id = htons(0);
update_cksum(ip, 2);
update_cksum(ip, 4);
p->set_ip_header(ip, sizeof(click_ip));
///////// customize end /////////
output(0).push(p);
}
_count += n;
if (n > 0)
_task.fast_reschedule();
else if (_end_h && _limit >= 0 && _count >= (ucounter_t) _limit)
(void) _end_h->call_write();
return n > 0;
}
Please advise what I should do....
Thank you very much in advance.
Regards,
Ruetee C.
More information about the click
mailing list