📄 ackunenc.cc
字号:
/* * ackfilter.{cc,hh} -- Picks up ack header for encoded packets * Wenjun Hu * * Copyright (c) 2005 University of Cambridge * Copyright (c) 2005 Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, subject to the conditions * listed in the Click LICENSE file. These conditions include: you must * preserve this copyright notice, and you cannot mention the copyright * holders in advertising related to the Software without their permission. * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This * notice is a summary of the Click LICENSE file; the license in that file is * legally binding. */#include <click/config.h>#include <click/confparse.hh>#include <click/error.hh>#include <click/glue.hh>#include <click/etheraddress.hh>#include <clicknet/ether.h>#include <click/straccum.hh>#include <click/timestamp.hh>#include <click/string.hh>#include <clicknet/ip.h>#include <clicknet/tcp.h>#include "ackheader.hh"#include "ackunenc.hh"CLICK_DECLSAckUnencoded::AckUnencoded() : Element(1, 1), _nreceivedpkts(0), _nduplicatepkts(0), _nnewpkts(0), _nreceivedbytes(0), _nduplicatebytes(0), _nnewbytes(0), _recvmgr(0), _scrambleq(0){}AckUnencoded::~AckUnencoded(){}intAckUnencoded::configure(Vector<String> &conf, ErrorHandler *errh){ int ret = cp_va_parse(conf, this, errh, cpKeywords, "RECVMGR", cpElement, "RecvManager Table", &_recvmgr, "SCRAMBLEQUEUE", cpElement, "ScrambleQueue element", &_scrambleq, cpEnd); if (!_recvmgr) return errh->error("RECVMGR not specified"); if (_recvmgr->cast("RecvManager") == 0) { return errh->error("RECVMGR element is not a RecvManager"); } if (!_scrambleq) { return errh->error("SCRAMBLEQUEUE not specified"); } if (_scrambleq->cast("ScrambleQueue") == 0) { return errh->error("SCRAMBLEQUEUE element is not a ScrambleQueue"); } return ret;}voidAckUnencoded::push(int, Packet *p){ struct click_ether *eth_h = (struct click_ether*)p->data(); StringAccum sa; sa << EtherAddress(eth_h->ether_shost) << ' '; struct click_ether *eh = (struct click_ether *)p->data(); struct srpacket *srh = (struct srpacket *)(eh + 1); unsigned int reclen = srh->hlen_with_data() - srh->hlen_wo_data(); const struct click_ip *iph = p->ip_header(); bool isnewpkt = _recvmgr->register_packet_to_ack(p, Timestamp::now().msec1()); click_chatter("%s: %u ackunenc received a packet from ethsrc = %s ipsrc = %s ipdst = %s ipid = %u coded = 0 iplen = %u srhlen = %u pktlen = %u isnew = %d", id().cc(), Timestamp::now().msec1(), sa.c_str(), IPAddress(iph->ip_src).unparse().c_str(), IPAddress(iph->ip_dst).unparse().c_str(), ntohs(iph->ip_id), ntohs(iph->ip_len), srh->hlen_wo_data(), p->length(), isnewpkt); _nreceivedpkts++; _nreceivedbytes += reclen; // if it is not a new packet, don't send it upstairs uint8_t tflag = 0; if (iph->ip_p == IP_PROTO_TCP) { const struct click_tcp *ctcph = p->tcp_header(); sa.clear(); sa << "tcp au " << iph->ip_src << " " << ntohs(ctcph->th_sport) << " " << iph->ip_dst << " " << ntohs(ctcph->th_dport) << " " << ntohl(ctcph->th_seq) << " " << ntohl(ctcph->th_ack); tflag = ctcph->th_flags; } else { click_chatter("%s: ip proto is %u", id().cc(), iph->ip_p); } if (!isnewpkt) { _nduplicatepkts++; _nduplicatebytes += reclen; p->kill(); click_chatter("%s: %u %s %#0x k", id().cc(), Timestamp::now().msec1(), sa.c_str(), tflag); return; } _nnewpkts++; _nnewbytes += reclen; _scrambleq->wakeup_if_needed(); click_chatter("%s: %s %#0x p", id().cc(), sa.c_str(), tflag); output(0).push(p);}StringAckUnencoded::stats(Element *e, void *){ StringAccum sa; AckUnencoded *ackunenc = static_cast<AckUnencoded *>(e); sa << "NRecdPkts: " << ackunenc->_nreceivedpkts << "; NRecdBytes: " << ackunenc->_nreceivedbytes << "; NDuplicatePkts: " << ackunenc->_nduplicatepkts << "; NDuplicateBytes: " << ackunenc->_nduplicatebytes << "; NNewPkts: " << ackunenc->_nnewpkts << "; NNewBytes: " << ackunenc->_nnewbytes << "\n"; click_chatter("%{element}: statistics ----------", ackunenc); return sa.take_string();}intAckUnencoded::static_clear(const String &arg, Element *e, void *, ErrorHandler *errh){ AckUnencoded *au = static_cast<AckUnencoded *>(e); bool b; if (!cp_bool(arg, &b)) return errh->error("`clear' must be a boolean"); if (b) { au->_nreceivedpkts = au->_nduplicatepkts = au->_nnewpkts = 0; au->_nreceivedbytes = au->_nduplicatebytes = au->_nnewbytes = 0; click_chatter("%{element}: statistics cleared\n", au); } return 0;}void AckUnencoded::add_handlers(){ add_read_handler("stats", stats, 0); add_write_handler("clear", static_clear, 0);}CLICK_ENDDECLSEXPORT_ELEMENT(AckUnencoded)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -