📄 aggregateipaddrpair.hh
字号:
// -*- c-basic-offset: 4 -*-#ifndef CLICK_AGGREGATEIPADDRPAIR_HH#define CLICK_AGGREGATEIPADDRPAIR_HH#include <click/element.hh>CLICK_DECLS/*=cAggregateIPAddrPair(I<KEYWORDS>)=s analysis, IPsets aggregate annotation based on IP packet field=dAggregateIP sets the aggregate annotation on every passing packet to a portionof that packet's IP header, transport header, or payload, depending on thevalue of the FIELD argument.FIELD can be the name of a header field, like C<"ip tos">, or a generaloffset-length specification, like C<"ip[8, 2]">. Either form can be modifiedwith a mask, such as C<"ip src/8"> or C<"ip[8, 2] & 0x3F0">. (Note that theoffset-length form contains a comma, which you must protect with single ordouble quotes.)The aggregate annotation value uses host byte order.General offset-length specifications begin with C<"ip">, C<"transp">, orC<"data">, depending on whether the offset should be measured relative to theIP header, transport header, or payload. (The names C<"tcp">, C<"udp">, andC<"icmp"> act like C<"transp">, but enforce the specified IP protocol.) Nextcomes the offset and length, which can take several forms:=over 8=item C<[OFFSET, LENGTH]>The LENGTH bytes starting at byte OFFSET.=item C<[OFFSET1-OFFSET2]>From byte OFFSET1 to byte OFFSET2, inclusive.=item C<[OFFSET]>The single byte at OFFSET.=item C<{OFFSET, LENGTH}>, C<{OFFSET1-OFFSET2}>, C<{OFFSET}>Similar, but OFFSETs and LENGTHs are measured in bits.=backFinally, the mask can equal either `C</NUM>', which means take the top NUMbits of the field, or `C<& MASK>', which means bitwise-and the field withMASK. (MASK must contain exactly one set of contiguous 1 bits.)Keyword arguments are:=over 8=item INCREMENTALBoolean. If true, then incrementally update the aggregate annotation: given afield N bits wide with value V, and an old aggregate annotation of O, the newaggregate annotation will equal (O * 2^N) + V. Default is false.=item UNSHIFT_IP_ADDRBoolean. If true, and the aggregated field lies within either the IP source ordestination address, then set the aggregate annotation to the masked portionof that address without shifting. For example, consider a packet with sourceaddress 1.0.0.0, and aggregate field C<"ip src/8">. Without UNSHIFT_IP_ADDR,the packet will get aggregate annotation 1; with UNSHIFT_IP_ADDR, it will getaggregate annotation 16777216. Default is false.=back=nPackets lacking the specified field are pushed onto output 1, or dropped ifthere is no output 1. A packet may lack a field because it is too short, it isa fragment, or it has the wrong protocol. (C<"tcp sport">, for example, isrelevant only for first-fragment TCP packets; C<"data"> specifications workonly for first-fragment TCP and UDP.)The simple specifications C<"sport"> and C<"dport"> (no C<"ip">, C<"tcp">, orC<"udp">) apply to either TCP or UDP packets.=eHere are a bunch of equivalent ways to ask for the top 8 bits of the IP sourceaddress: AggregateIP(ip src/8) AggregateIP(ip src & 0xFF000000) AggregateIP(ip[12]) AggregateIP("ip[12, 1]") // protect comma AggregateIP("ip{96, 8}") AggregateIP(ip{96-103})=h header read-onlyReturns the header type AggregateIP is using: either "ip", "transp", or"payload".=h bit_offset read-onlyReturns the offset into the header of the start of the aggregated field, inbits.=h bit_length read-onlyReturns the length of the aggregated field, in bits.=aAggregateLength, AggregateFlows, AggregateCounter*/class AggregateIPAddrPair : public Element { public: AggregateIPAddrPair(); ~AggregateIPAddrPair(); const char *class_name() const { return "AggregateIPAddrPair"; } void notify_noutputs(int); const char *processing() const { return "a/ah"; } int configure(Vector<String> &, ErrorHandler *); void add_handlers(); Packet *simple_action(Packet *); struct HostPair { uint32_t a; uint32_t b; HostPair() : a(0), b(0) { } HostPair(uint32_t aa, uint32_t bb) : a(aa), b(bb) { if (a > b) a ^= b ^= a ^= b; } }; private: struct FlowInfo { Timestamp last_timestamp; uint32_t aggregate; FlowInfo() : aggregate(0) { } }; typedef HashMap<HostPair, FlowInfo> Map; Map _map; unsigned _active_sec; unsigned _gc_sec; int _timeout; unsigned _gc_interval; bool _timestamp_warning; uint32_t _next; Packet *handle_packet(Packet *); Packet *bad_packet(Packet *); static String read_handler(Element *, void *); };CLICK_ENDDECLS#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -