Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120516904
efficientipprint.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jul 4, 22:59
Size
2 KB
Mime Type
text/x-c
Expires
Sun, Jul 6, 22:59 (2 d)
Engine
blob
Format
Raw Data
Handle
27196184
Attached To
R6591 HyMAB
efficientipprint.cc
View Options
#include <click/config.h>
#include "efficientipprint.hh"
#include <click/args.hh>
#include <click/straccum.hh>
#include <click/error.hh>
CLICK_DECLS
EfficientIPPrint::EfficientIPPrint() : _timer(this)
{
}
int
EfficientIPPrint::configure(Vector<String> &conf, ErrorHandler *errh)
{
_id_modulo = 0;
_dstport = false;
_ts = true;
_active = true;
_freq = 100;
_label = "";
if (Args(conf, this, errh)
.read("ACTIVE", _active)
.read("ID", _id_modulo)
.read("DSTPORT", _dstport)
.read("TIMESTAMP", _ts)
.read("FREQ_PRINT", _freq)
.read("LABEL", _label)
.complete() < 0)
return -1;
return 0;
}
int
EfficientIPPrint::initialize(ErrorHandler *)
{
_timer.initialize(this);
_timer.schedule_after_msec(100);
return 0;
}
void
EfficientIPPrint::push(int, Packet *p)
{
if (_active) {
handle_packet(p);
}
output(0).push(p);
}
Packet *
EfficientIPPrint::pull(int)
{
Packet *p = input(0).pull();
if(p) {
if(_active)
handle_packet(p);
}
return p;
}
void
EfficientIPPrint::run_timer(Timer *timer) {
if (_count > 0 && _count_timer == 0) {
// no packet during timer, print
click_chatter("%s",_current_string.take_string().c_str());
_count = 0;
}
_count_timer = 0;
_timer.schedule_after_msec(100);
}
void
EfficientIPPrint::handle_packet(Packet *p) {
_count++;
_count_timer++;
const click_ip *iph = p->ip_header();
if(_id_modulo <= 1 || (ntohs(iph->ip_id)%_id_modulo) == 0) {
if(_label)
_current_string << _label << ": ";
if(_ts)
_current_string << p->timestamp_anno() << ": ";
if(_id_modulo)
_current_string << "id " << ntohs(iph->ip_id) << " ";
if(_dstport) {
if(p->has_transport_header()) {
const click_udp *udph = p->udp_header();
_current_string << "dp " << ntohs(udph->uh_dport) << " ";
}
}
_current_string << "\n";
}
// TODO: add timer to avoid not to print last packets
if(_count >= _freq) {
click_chatter("%s",_current_string.take_string().c_str());
_count = 0;
}
}
int
EfficientIPPrint::set_bool_handler(const String &s, Element *e, void *a,
ErrorHandler *errh) {
EfficientIPPrint *elmt = (EfficientIPPrint *)e;
int b;
if(!cp_integer(s, &b))
return errh->error("Arg must be 0 or 1");
if (!(b == 0 || b == 1))
return errh->error("Arg must be 0 or 1");
if(((intptr_t) a) == 0)
elmt->set_active(b==1);
return 0;
}
void
EfficientIPPrint::add_handlers()
{
add_write_handler("active", set_bool_handler, 0);
}
CLICK_ENDDECLS
EXPORT_ELEMENT(EfficientIPPrint)
ELEMENT_MT_SAFE(EfficientIPPrint)
Event Timeline
Log In to Comment