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

📄 aggregateipflows.hh

📁 COPE the first practical network coding scheme which is developped on click
💻 HH
字号:
// -*- c-basic-offset: 4 -*-#ifndef CLICK_AGGREGATEIPFLOWS_HH#define CLICK_AGGREGATEIPFLOWS_HH#include <click/element.hh>#include <click/ipflowid.hh>#include <click/bighashmap.hh>#include "aggregatenotifier.hh"CLICK_DECLSclass HandlerCall;/*=cAggregateIPFlows([I<KEYWORDS>])=s analysis, IPsets aggregate annotation based on flow=dAggregateIPFlows monitors TCP and UDP flows, setting the aggregate annotationon every passing packet to a flow number, and the paint annotation to adirection indication. Non-TCP/UDP packets and short packets are emitted onoutput 1, or dropped if there is no output 1.AggregateIPFlows uses source and destination addresses and source anddestination ports to distinguish flows. Reply packets get the same flownumber, but a different paint annotation. Old flows die after a configurabletimeout, after which new packets with the same addresses and ports get a newflow number. UDP, active TCP, and completed TCP flows have different timeouts.Flow numbers are assigned sequentially, starting from 1. Different flows getdifferent numbers. Paint annotations are set to 0 or 1, depending on whetherpackets are on the forward or reverse subflow. (The first packet seen on eachflow gets paint color 0; reply packets get paint color 1. ICMP errors getpaints 2 and 3.)AggregateIPFlows can optionally apply aggregate annotations to ICMP errors.See the ICMP keyword argument below.If FRAGMENTS is true (the default in push context), AggregateIPFlows assignsaggregate annotations to second and subsequent fragments. It does this byholding onto the fragments until it finds the relevant port numbers, which areattached to the first fragment. Fragments for which no port numbers can befound after FRAGMENT_TIMEOUT seconds of packet time are emitted on port 1 ordropped.Fragment processing may cause AggregateIPFlows to reorder packets. Packetssent between any given pair of addresses are always emitted in the order inwhich they were received, but packets sent between different address pairs maycome out in a different relative order.Fragment processing also causes AggregateIPFlows to store packets. If youaren't careful, those stored packets might remain in the AggregateIPFlowselement when the driver quits, which is probably not what you want. TheExample below shows one way to manage potentially lingering fragments.If FRAGMENTS is false, second and subsequent fragments are emitted on port 1or dropped.Keywords are:=over 8=item TRACEINFOFilename. If provided, output information about each flow to that filename inan XML format.=item SOURCEElement. If provided, the results of that element's 'C<filename>' and'C<packet_filepos>' read handlers will be recorded in the TRACEINFO dump. (Itis not an error if the element doesn't have those handlers.) The'C<packet_filepos>' results may be particularly useful, since a reader can usethose results to skip ahead through a trace file.=item TCP_TIMEOUTThe timeout for active TCP flows, in seconds. Default is 24 hours.=item TCP_DONE_TIMEOUTThe timeout for completed TCP flows, in seconds. A completed TCP flow has seenFIN flags on both subflows. Default is 30 seconds.=item UDP_TIMEOUTThe timeout for UDP connections, in seconds. Default is 1 minute.=item FRAGMENT_TIMEOUTThe timeout for fragments, in seconds, Default is 30 seconds.=item REAPThe garbage collection interval. Default is 20 minutes of packet time.=item ICMPBoolean. If true, then mark ICMP errors relating to a connection with anaggregate annotation corresponding to that connection. ICMP error packets getpaint annotations equal to 2 plus the paint color of the encapsulated packet.Default is false.=item FRAGMENTSBoolean. If true, then try to assign aggregate annotations to all fragments.May only be set to true if AggregateIPFlows is running in a push context.Default is true in a push context and false in a pull context.=backAggregateIPFlows is an AggregateNotifier, so AggregateListeners can requestnotifications when new aggregates are created and old ones are deleted.=h clear write-onlyClears all flow information. Future packets will get new aggregate annotationvalues. This may cause packets to be emitted if FRAGMENTS is true.=eThis configuration counts the number of packets in each flow in a trace, usingAggregateCounter.   FromDump(tracefile.dump, STOP true, FORCE_IP true)       -> af :: AggregateIPFlows       -> AggregateCounter       -> Discard;   DriverManager(wait, write af.clear)The DriverManager line handles fragments that might be left in theAggregateIPFlows element after FromDump completes. Again, AggregateIPFlowscollects fragments as they arrive and emits them later. If the last packets inFromDump are fragments, then AggregateIPFlows will still be hanging onto themwhen FromDump stops the driver. The DriverManager element waits for FromDumpto request a driver stop, then calls the C<af.clear> handler to flush anyremaining fragments.   =aAggregateIP, AggregateCounter, DriverManager */class AggregateIPFlows : public Element, public AggregateNotifier { public:    AggregateIPFlows();    ~AggregateIPFlows();    const char *class_name() const	{ return "AggregateIPFlows"; }    void *cast(const char *);    void notify_noutputs(int);    const char *processing() const	{ return "a/ah"; }    int configure(Vector<String> &, ErrorHandler *);    int initialize(ErrorHandler *);    void add_handlers();    void cleanup(CleanupStage);    bool stats() const			{ return _traceinfo_file; }        void push(int, Packet *);    Packet *pull(int);    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 {	uint32_t _ports;	uint32_t _aggregate;	Timestamp _last_timestamp;	unsigned _flow_over : 2;	bool _reverse : 1;	FlowInfo *_next;	// have 24 bytes; statistics would double	// + 8 + 8 = 16 bytes	FlowInfo(uint32_t ports, FlowInfo *next, uint32_t agg) : _ports(ports), _aggregate(agg), _flow_over(0), _next(next) { }	uint32_t aggregate() const { return _aggregate; }	bool reverse() const	{ return _reverse; }    };    struct StatFlowInfo : public FlowInfo {	Timestamp _first_timestamp;	uint32_t _filepos;	uint32_t _packets[2];	StatFlowInfo(uint32_t ports, FlowInfo *next, uint32_t agg) : FlowInfo(ports, next, agg) { _packets[0] = _packets[1] = 0; }    };    struct HostPairInfo {	FlowInfo *_flows;	Packet *_fragment_head;	Packet *_fragment_tail;	HostPairInfo() : _flows(0), _fragment_head(0), _fragment_tail(0) { }	FlowInfo *find_force(uint32_t ports);    };    typedef HashMap<HostPair, HostPairInfo> Map;    Map _tcp_map;    Map _udp_map;        uint32_t _next;    unsigned _active_sec;    unsigned _gc_sec;    int _tcp_timeout;    int _tcp_done_timeout;    int _udp_timeout;    int _smallest_timeout;        unsigned _gc_interval;    unsigned _fragment_timeout;    bool _handle_icmp_errors : 1;    unsigned _fragments : 2;    bool _timestamp_warning : 1;    FILE *_traceinfo_file;    String _traceinfo_filename;    Element *_packet_source;    HandlerCall *_filepos_h;    static const click_ip *icmp_encapsulated_header(const Packet *);        void clean_map(Map &);    void reap_map(Map &, uint32_t, uint32_t);    void reap();    inline int relevant_timeout(const FlowInfo *, const Map &) const;    void stat_new_flow_hook(const Packet *, FlowInfo *);    inline void packet_emit_hook(const Packet *, const click_ip *, FlowInfo *);    inline void delete_flowinfo(const HostPair &, FlowInfo *, bool really_delete = true);    void assign_aggregate(Map &, HostPairInfo *, int emit_before_sec);    FlowInfo *find_flow_info(Map &, HostPairInfo *, uint32_t ports, bool flipped, const Packet *);    FlowInfo *uncommon_case(FlowInfo *finfo, const click_ip *iph);    enum { ACT_EMIT, ACT_DROP, ACT_NONE };    int handle_fragment(Packet *, int paint, Map &, HostPairInfo *);    int handle_packet(Packet *);    static int write_handler(const String &, Element *, void *, ErrorHandler *);    };CLICK_ENDDECLS#endif

⌨️ 快捷键说明

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