Page MenuHomec4science

acneaggregate.cc
No OneTemporary

File Metadata

Created
Tue, Jul 8, 04:05

acneaggregate.cc

#include <click/config.h>
#include "acneaggregate.hh"
#define DEBUG_CHATTER(arg, ...) do { if (_debug) { click_chatter(arg, ## __VA_ARGS__);} } while (0)
#define VERB_DEBUG_CHATTER(arg, ...) do { if (_verb_debug) { click_chatter(arg, ## __VA_ARGS__);} } while (0)
CLICK_DECLS
AcneAggregate::AcneAggregate() : timer(this)
{
}
AcneAggregate::~AcneAggregate()
{
}
int
AcneAggregate::configure(Vector<String> &conf, ErrorHandler *errh) {
_period = 500;
_max_length = 1450;
_packet = 0;
_seq_num = 0;
_debug = false;
_active = true;
if(Args(this, errh).bind(conf)
.read("MAX_LENGTH", _max_length)
.read("PERIOD", _period)
.read("DEBUG", _debug)
.read("ACTIVE", _active)
.complete() < 0)
return -1;
timer.initialize(this);
timer.schedule_after_msec(_period);
return 0;
}
void
AcneAggregate::push(int, Packet *p) {
Timestamp now;
click_ether *eth_hdr = (click_ether *) p->data();
acne_header *acne_hdr = (acne_header *) (p->data() + sizeof(click_ether));
output(0).push(p);
return;
/*
if (!_active || !EtherAddress(eth_hdr->ether_dhost).is_broadcast() || p->length() <= 14 || acne_hdr->_type == REGULAR_TRAFFIC
|| acne_hdr->_type == ACK_RTE_PRICES || acne_hdr->_type == INT2_LOAD_NBOR || acne_hdr->_type == INT1_LOAD_NBOR) {
acne_hdr->_seq_aggreg = 0;
output(0).push(p);
return;
}
// only control broadcast is aggregated
uint32_t length_packet = p->length();
if (_packet != 0) {
if ((_pointer - length_packet) < _packet->data()) { // not enough room for both: push longer packet; if push old one, create new one
if(_debug)
now.assign_now();
DEBUG_CHATTER("[AcneAggregate %s] Not enough room, push one packet...", now.unparse().c_str());
uint32_t length_old_packet = (uint32_t) (_packet->end_data() - _pointer);
if(length_packet > length_old_packet) {
DEBUG_CHATTER("Push received packet");
acne_hdr->_seq_aggreg = 0;
output(0).push(p);
return;
}
else {
uint32_t to_pull = (uint32_t) (_pointer-_packet->data());
if (_packet->length() < to_pull) {
now.assign_now();
click_chatter("[AcneAggregate %s] Error: not enough to pull (have %d, want to pull %d).",
now.unparse().c_str(), _packet->length(), to_pull);
}
else
_packet->pull(to_pull);
if(_debug)
now.assign_now();
DEBUG_CHATTER("Push old packet");
output(0).push(_packet->clone()->uniqueify());
reinitialize_packet();
}
}
}
if (_packet == 0) {
_packet = Packet::make(_max_length);
_pointer = _packet->end_data();
if(_debug)
now.assign_now();
DEBUG_CHATTER("[AcneAggregate %s] Making a new packet...", now.unparse().c_str());
}
// add p to _packet
acne_hdr->_seq_aggreg = _seq_num;
acne_hdr->_length = length_packet;
_seq_num++;
_pointer = _pointer - length_packet;
memcpy(_pointer, p->data(), length_packet);
p->kill();
*/
}
void
AcneAggregate::run_timer(Timer *t) {
Timestamp now;
assert(t == &timer);
if(_packet!=0) {
if(_debug)
now.assign_now();
DEBUG_CHATTER("[AcneAggregate %s] Timer expired: sending packet.", now.unparse().c_str());
uint32_t to_pull = (uint32_t) (_pointer-_packet->data());
if (_packet->length() < to_pull) {
now.assign_now();
click_chatter("[AcneAggregate %s] Error: not enough to pull (have %d, want to pull %d). Pointer is %d, data is %d",
now.unparse().c_str(), _packet->length(), to_pull, _pointer, _packet->data());
}
else
_packet->pull(to_pull);
output(0).push(_packet->clone()->uniqueify());
reinitialize_packet();
}
timer.reschedule_after_msec(_period);
}
void
AcneAggregate::reinitialize_packet() {
_packet->kill();
_packet = 0;
_seq_num = 0;
}
int
AcneAggregate::active_handler(const String &s, Element *e, void *, ErrorHandler *errh) {
AcneAggregate *elmt = (AcneAggregate *)e;
int arg;
if(!cp_integer(s, &arg))
return errh->error("Active must be 0 or 1");
if (!(arg == 0 || arg == 1))
return errh->error("Active must be 0 or 1");
elmt->set_active(arg==1);
return 0;
}
void AcneAggregate::add_handlers() {
add_write_handler("active", active_handler, 0);
}
EXPORT_ELEMENT(AcneAggregate)
CLICK_ENDDECLS

Event Timeline