Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120736965
checkorder.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
Sun, Jul 6, 16:42
Size
4 KB
Mime Type
text/x-c
Expires
Tue, Jul 8, 16:42 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27232405
Attached To
R1252 EMPoWER
checkorder.cc
View Options
#include <click/config.h>
#include "checkorder.hh"
CLICK_DECLS
CheckOrder::CheckOrder() : _timer(this)
{
}
CheckOrder::~CheckOrder()
{
}
int
CheckOrder::configure(Vector<String> &conf, ErrorHandler *errh)
{
_active = false;
_debug = false;
if(Args(this, errh).bind(conf)
.read("DEBUG", _debug)
.read("VERB_DEBUG", _verb_debug)
.read("ACTIVE", _active)
.read("ONLY_TCP", _only_tcp)
.complete() < 0)
return -1;
return 0;
}
int
CheckOrder::initialize(ErrorHandler *)
{
_timer.initialize(this);
return 0;
}
void
CheckOrder::push(int port, Packet *p)
{
if(!_active) {
output(port).push(p);
return;
}
_timer.schedule_after_sec(1);
click_ip *ip_hdr = (click_ip *)(p->ip_header());
if(ip_hdr == 0)
ip_hdr = (click_ip *)(p->data()+sizeof(empower_header));
if(ip_hdr) {
IPAddress src = ip_hdr->ip_src;
empower_header *hdr = (empower_header *)(p->data());
_now.assign_now();
if(hdr->_type == REGULAR_TRAFFIC) {
_received[src]++;
if(!_only_tcp) {
if(is_in_hash_table(_last_empower_seq,src)) {
if(hdr->_seq != (_last_empower_seq[src]+1)%MAX_SEQ) {
click_chatter("[CheckOrder %s] Out-of-order empower packet from %s; is %u, last received %u", _now.unparse().c_str(), src.unparse().c_str(),
hdr->_seq, _last_empower_seq[src]);
_ooo[src]++;
}
}
_last_empower_seq.set(src,hdr->_seq);
}
}
if(ip_hdr->ip_p == IP_PROTO_TCP) {
click_tcp *tcp_hdr = (click_tcp *)(p->tcp_header());
if(tcp_hdr == 0)
tcp_hdr = (click_tcp *) (p->data()+sizeof(empower_header) + sizeof(click_ip));
if(tcp_hdr) {
uint16_t len = htons(ip_hdr->ip_len) - 52; // 52 is observed value (IP header + TCP header + 12 B padding)
bool traffic = true, ack=false;
if(tcp_hdr->th_flags & TH_SYN) {
traffic = false;
}
if(tcp_hdr->th_flags & TH_ACK) {
uint16_t a = htons(ip_hdr->ip_len);
uint32_t b = tcp_hdr->th_off;
uint32_t c = a - b*4 - 20;
if(c==0) {
traffic = false;
ack=true;
}
}
if(traffic) {
_received_tcp[src]++;
if(is_in_hash_table(_last_tcp_seq,src)) {
if(htonl(tcp_hdr->th_seq) != (_last_tcp_seq[src]+len)) {
_ooo_tcp[src]++;
click_chatter("[CheckOrder %s] Out-of-order TCP packet from %s; is %u, last received %u", _now.unparse().c_str(), src.unparse().c_str(),
htonl(tcp_hdr->th_seq), _last_tcp_seq[src]);
}
}
_last_tcp_seq.set(src,htonl(tcp_hdr->th_seq));
}
}
}
}
output(port).push(p);
}
void CheckOrder::run_timer(Timer *t) {
_now.assign_now();
for (HashTable<IPAddress, int>::iterator iter = _received.begin(); iter.live(); iter++) {
if(iter.value()>0)
click_chatter("[CheckOrder %s] Received %d empower packets, %d ooo; received %d TCP packets, %d ooo", _now.unparse().c_str(), iter.value(),
_ooo[iter.key()], _received_tcp[iter.key()], _ooo_tcp[iter.key()]);
}
}
int
CheckOrder::active_handler(const String &s, Element *e, void *,
ErrorHandler *errh) {
CheckOrder *elmt = (CheckOrder *)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;
}
int
CheckOrder::debug_handler(const String &s, Element *e, void *a,
ErrorHandler *errh) {
CheckOrder *elmt = (CheckOrder *)e;
int debug;
if(!cp_integer(s, &debug))
return errh->error("Debug must be 0 or 1");
if (!(debug == 0 || debug == 1))
return errh->error("Debug must be 0 or 1");
if(((intptr_t) a) == 0)
elmt->set_debug(debug==1);
else if(((intptr_t) a) == 1)
elmt->set_verb_debug(debug==1);
return 0;
}
void CheckOrder::add_handlers() {
add_write_handler("debug", debug_handler, 0);
add_write_handler("verb_debug", debug_handler, 1);
add_write_handler("active", active_handler, 0);
}
CLICK_ENDDECLS
EXPORT_ELEMENT(CheckOrder)
ELEMENT_MT_SAFE(CheckOrder)
Event Timeline
Log In to Comment