⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aggcounter.hh

📁 COPE the first practical network coding scheme which is developped on click
💻 HH
字号:
#ifndef CLICK_AGGCOUNTER_HH#define CLICK_AGGCOUNTER_HH#include <click/element.hh>CLICK_DECLSclass HandlerCall;/*=cAggregateCounter([I<KEYWORDS>])=s analysiscounts packets per aggregate annotation=dAggregateCounter maintains counts of how many packets or bytes it has seen foreach aggregate value. Each aggregate annotation value gets a different count.Call its C<write_file> or C<write_text_file> write handler to get a dump ofthe information.The C<freeze> handler, and the C<AGGREGATE_FREEZE> and C<COUNT_FREEZE>keyword arguments, can put AggregateCounter in a frozen state. FrozenAggregateCounters only update existing counters; they do not create newcounters for previously unseen aggregate values.AggregateCounter may have one or two inputs. The optional second input isalways frozen. (It is only useful when the element is push.) It may also havetwo outputs. If so, and the element is push, then packets that were countedare emitted on the first output, while other packets are emitted on the secondoutput.Keyword arguments are:=over 8=item BYTESBoolean. If true, then count bytes, not packets. Default is false.=item IP_BYTESBoolean. If true, then do not count bytes from the link header. Default isfalse.=item MULTIPACKETBoolean. If true, and BYTES is false, then use packets' packet countannotations to add to the number of packets seen. Elements likeFromIPSummaryDump set this annotation. Default is true.=item EXTRA_LENGTHBoolean. If true, and BYTES is true, then include packets' extra lengthannotations in the byte counts. Elements like FromDump set this annotation.Default is true.=item AGGREGATE_STOPUnsigned. Stop the router once I<N> distinct aggregates have been seen.Default is never to stop.=item AGGREGATE_FREEZEUnsigned. Freeze the AggregateCounter once I<N> distinct aggregates have beenseen. Default is never to freeze.=item AGGREGATE_CALLArgument is 'I<N> I<HANDLER> [I<VALUE>]'. Call the given write handler, withthe supplied value, once I<N> distinct aggregates have been seen.The three AGGREGATE keywords are mutually exclusive. Supply at most one ofthem.=item COUNT_STOPUnsigned. Stop the router once the total count (of bytes or packets) hasreached or exceeded I<N>. Default is never to stop.=item COUNT_FREEZEUnsigned. Freeze the AggregateCounter once the total count has reached orexceeded I<N>. Default is never to freeze.=item COUNT_CALLArgument is 'I<N> I<HANDLER> [I<VALUE>]'. Call the given write handler, withthe supplied value, once the total count has reached or exceeded I<N>.The three COUNT keywords are mutually exclusive. Supply at most one ofthem.=item BANNERString. This banner is written to the head of any output file. It shouldprobably begin with a comment character, like '!' or '#'. Default is empty.=back=h write_file write-onlyArgument is a filename, or 'C<->', meaning standard out. Write a packed binaryfile containing all current data to the specified filename. The format is acouple text lines, followed by a line containing 'C<!packed_le>' or'C<!packed_be>', followed by N 8-byte records. In each record, bytes 1-4 arethe aggregate, and bytes 5-8 are the count. Both values are 32-bit integers.The byte order is indicated by the 'C<!packed>' line: 'C<!packed_le>' meanslittle-endian, 'C<!packed_be>' means big-endian.=h write_text_file write-onlyArgument is a filename, or 'C<->', meaning standard out. Write a text filecontaining all current data to the specified filename. The format is a coupletext lines, followed by N data lines, each containing the aggregate ID indecimal, a space, then the count in decimal.=h write_ip_file write-onlyArgument is a filename, or 'C<->', meaning standard out. Write a text filecontaining all current data to the specified filename. The format is as inC<write_text_file>, except that aggregate IDs are printed as IP addresses.=h freeze read/writeReturns or sets the AggregateCounter's frozen state, which is 'true' or'false'. AggregateCounter starts off unfrozen.=h active read/writeReturns or sets the AggregateCounter's active state. When AggregateCounter isinactive ('false'), it does not record information about any packets thatpass. It starts out active.=h stop write-onlyWhen any value is written to this handler, AggregateCounter sets 'active' tofalse and additionally stops the driver.=h counts_pdf write-onlyWhen any value is written to this handler, AggregateCounter will recalculateits counters. The new aggregate identifiers equal the old counts; the newcounts represent how many times each old count appeared. The old aggregateidentifiers are thrown away. To put it another way, AggregateCounter creates amultiset containing all aggregate counts, then stores each count as anaggregate, with its number of occurrences in the multiset as its count.=h banner read/writeReturns or sets the BANNER setting.=h aggregate_call read/writeReturns or sets the AGGREGATE_CALL setting.=h count_call read/writeReturns or sets the COUNT_CALL setting.=h nagg read-onlyReturns the number of aggregates that have been seen so far.=nThe aggregate identifier is stored in host byte order. Thus, the aggregate IDcorresponding to IP address 128.0.0.0 is 2147483648.Only available in user-level processes.=eThis configuration reads an IP summary dump in from standard input, aggregatesbased on destination IP address, and counts packets. When the dump is done,Click will write the aggregate counter's data to standard output, in textform.  FromIPSummaryDump(-, STOP true)	-> AggregateIP(ip dst)	-> ac :: AggregateCounter	-> Discard;  DriverManager(wait_pause,	write ac.write_text_file -);=aAggregateIP, AggregatePacketCounter, FromIPSummaryDump, FromDump */class AggregateCounter : public Element { public:      AggregateCounter();    ~AggregateCounter();      const char *class_name() const	{ return "AggregateCounter"; }    const char *processing() const	{ return AGNOSTIC; }    void notify_ninputs(int);    void notify_noutputs(int);    int configure(Vector<String> &, ErrorHandler *);    int initialize(ErrorHandler *);    void cleanup(CleanupStage);    void add_handlers();    inline bool update(Packet *, bool frozen = false);    void push(int, Packet *);    Packet *pull(int);    bool empty() const			{ return _num_nonzero == 0; }    int clear(ErrorHandler * = 0);    enum WriteFormat { WR_TEXT = 0, WR_BINARY = 1, WR_TEXT_IP = 2, WR_TEXT_PDF = 3 };    int write_file(String, WriteFormat, ErrorHandler *) const;    void reaggregate_counts();      private:    struct Node {	uint32_t aggregate;	uint32_t count;	Node *child[2];    };    bool _bytes : 1;    bool _ip_bytes : 1;    bool _use_packet_count : 1;    bool _use_extra_length : 1;    bool _frozen : 1;    bool _active : 1;        Node *_root;    Node *_free;    Vector<Node *> _blocks;    uint32_t _num_nonzero;    uint64_t _count;    uint32_t _call_nnz;    HandlerCall *_call_nnz_h;    uint64_t _call_count;    HandlerCall *_call_count_h;    String _output_banner;        Node *new_node();    Node *new_node_block();    void free_node(Node *);    Node *make_peer(uint32_t, Node *, bool frozen);    Node *find_node(uint32_t, bool frozen = false);    void reaggregate_node(Node *);    void clear_node(Node *);    void write_nodes(Node *, FILE *, WriteFormat, uint32_t *, int &, int, ErrorHandler *) const;    static int write_file_handler(const String &, Element *, void *, ErrorHandler *);    static String read_handler(Element *, void *);    static int write_handler(const String &, Element *, void *, ErrorHandler *);    };inline AggregateCounter::Node *AggregateCounter::new_node(){    if (_free) {	Node *n = _free;	_free = n->child[0];	return n;    } else	return new_node_block();}inline voidAggregateCounter::free_node(Node *n){    n->child[0] = _free;    _free = n;}CLICK_ENDDECLS#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -