📄 fromflandump.hh
字号:
// -*- mode: c++; c-basic-offset: 4 -*-#ifndef CLICK_FROMFLANDUMP_HH#define CLICK_FROMFLANDUMP_HH#include <click/element.hh>#include <click/task.hh>class HandlerCall;/*=cFromFlanDump(FILENAME [, I<KEYWORDS>])=s analysisreads packets from a DAG file=dReads packets from a file in DAG format, produced by the University ofWaikato's DAG tools. Pushes them out the output, and optionally stops thedriver when there are no more packets. If TIMING is true, then FromFlanDumptries to maintain the timing of the original packet stream. TIMING is false bydefault.FromFlanDump also transparently reads gzip- and bzip2-compressed files, if youhave zcat(1) and bzcat(1) installed.Keyword arguments are:=over 8=item SAMPLEUnsigned real number between 0 and 1. FromFlanDump will output each packet withprobability SAMPLE. Default is 1. FromFlanDump uses fixed-point arithmetic, sothe actual sampling probability may differ substantially from the requestedsampling probability. Use the C<sampling_prob> handler to find out the actualprobability.=item STOPBoolean. If true, then FromFlanDump will ask the router to stop when it is donereading its tcpdump file. Default is false.=item STARTAbsolute time in seconds since the epoch. FromFlanDump will output packets withtimestamps after that time.=item START_AFTERArgument is relative time in seconds (or supply a suffix like `min', `h').FromFlanDump will skip the first I<T> seconds in the log.=item ENDAbsolute time in seconds since the epoch. FromFlanDump will stop whenencountering a packet with timestamp at or after that time.=item END_AFTERArgument is relative time in seconds (or supply a suffix like `min', `h').FromFlanDump will stop at the first packet whose timestamp is at least I<T>seconds after the first timestamp in the log.=item INTERVALArgument is relative time in seconds (or supply a suffix like `min', `h').FromFlanDump will stop at the first packet whose timestamp is at least I<T>seconds after the first packet output.=item END_CALLSpecify the handler to call, instead of stopping FromFlanDump, once the endtime is reached.=item TIMINGBoolean. Same as the TIMING argument.=item ACTIVEBoolean. If false, then FromFlanDump will not emit packets (until the`C<active>' handler is written). Default is true.=item MMAPBoolean. If true, then FromFlanDump will use mmap(2) to access the tcpdumpfile. This can result in slightly better performance on some machines.FromFlanDump's regular file discipline is pretty optimized, so the differenceis often small in practice. Default is true on most operating systems, butfalse on Linux.=backYou can supply at most one of START and START_AFTER, and at most one of END,END_AFTER, and INTERVAL.Only available in user-level processes.=nBy default, `tcpdump -w FILENAME' dumps only the first 68 bytes ofeach packet. You probably want to run `tcpdump -w FILENAME -s 2000' or somesuch.FromFlanDump sets packets' extra length annotations to any additional lengthrecorded in the dump.=h sampling_prob read-onlyReturns the sampling probability (see the SAMPLE keyword argument).=h active read/writeValue is a Boolean.=h encap read-onlyReturns the file's encapsulation type.=h filesize read-onlyReturns the length of the FromFlanDump file, in bytes, or "-" if thatlength cannot be determined.=h filepos read-onlyReturns FromFlanDump's position in the file, in bytes.=h extend_interval write-onlyText is a time interval. If END_TIME or one of its cousins was specified, thenwriting to this handler extends END_TIME by that many seconds. Also, ACTIVE isset to true.=aFromDump, ToDump, mmap(2) */class FromFlanDump : public Element { public: FromFlanDump(); ~FromFlanDump(); const char *class_name() const { return "FromFlanDump"; } const char *processing() const { return AGNOSTIC; } int configure(Vector<String> &, ErrorHandler *); int initialize(ErrorHandler *); void cleanup(CleanupStage); void add_handlers(); void run_scheduled(); Packet *pull(int); void set_active(bool); private: static const uint32_t BUFFER_SIZE = 32768; static const int SAMPLING_SHIFT = 28; class FlanFile { public: FlanFile(); ~FlanFile(); int open(const String &basename, const String &filename, int record_size, ErrorHandler *); int read_more(off_t); off_t last_record() const; uint16_t read_uint16(off_t) const; uint32_t read_uint32(off_t) const; private: int _fd; const uint8_t *_buffer; off_t _offset; uint32_t _len; FILE *_pipe; bool _my_buffer; int _record_size; enum { BUFFER_SIZE = 65536 }; }; enum { FF_FLID = 0, FF_TIME, FF_SIZE, FF_FLAGS, FF_SADDR, FF_DADDR, FF_DPORT, FF_CT_PKT, FF_CT_BYTES, FF_BEG, FF_FIRST_PKT = FF_FLID, FF_LAST_PKT = FF_FLAGS + 1, FF_FIRST_FLOW = FF_SADDR, FF_LAST_FLOW = FF_BEG + 1, FF_LAST = FF_LAST_FLOW }; FlanFile *_ff[FF_LAST]; off_t _record; off_t _last_record; bool _flows : 1; bool _stop : 1; bool _active; Task _task; String _dirname; int error_helper(ErrorHandler *, const char *); int read_buffer(ErrorHandler *); int read_into(void *, uint32_t, ErrorHandler *); bool read_packet(ErrorHandler *); static String read_handler(Element *, void *); static int write_handler(const String &, Element *, void *, ErrorHandler *); };inline off_tFromFlanDump::FlanFile::last_record() const{ return (_offset + _len) / _record_size;}inline uint16_tFromFlanDump::FlanFile::read_uint16(off_t o) const{ return *reinterpret_cast<const uint16_t *>(_buffer + o<<1 - _offset);}inline uint32_tFromFlanDump::FlanFile::read_uint32(off_t o) const{ return *reinterpret_cast<const uint16_t *>(_buffer + o<<2 - _offset);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -