CAIDA::Traffic2::FileWriter - Writer of Traffic2-style output files.
use CAIDA::Traffic2::FileWriter;
while ( ... ) { # Getting intervals $writer->initialize($interval, "Tuple Table"); $writer->dump_interval_full(); }
or
while ( ... ) { # Getting intervals $writer->initialize($interval, "Tuple Table"); $writer->init_user_tables("My Table"); $writer->dump_interval_start(); foreach ... { # Getting each ID and Table from the interval $writer->dump_interval_table($id_info, "Tuple Table", $table); my $user_table = new My_Table; $writer->dump_interval_table($id_info, "My Table", $user_table); } $writer->dump_interval_end(); }
FileWriter is a class that simplifies the writing of Traffic2-style output files. Traffic2-style is that which is output by crl_traffic2 (now named crl_flow). Its interface is simple; simply specify an output destination and iterate over all the intervals, dumping out only those tables which are desired. It is intended to be used with FileReader objects, and thus supports incremental writing. (See the FileReader manpage for more information.)
FileWriter has the following member functions:
As a side effect, it also writes a file header to FILE.
get_next_interval()
.
LIST is a list of table types to be written. This is because the
table information is listed in the beginning of the output file,
and must match the types of the tables actually written. Like
FileReader::set_desired_table_types()
, these types can be
classified as expired, active, or both. Types that won't be created
in INTERVAL will not be written.
initialize()
) have all of
the table data stored at once, usually by calling
FileReader::get_next_interval()
with a true argument for preloading.
USE_TIMESTAMPS is a Boolean that indicates whether the 'first' and 'latest'
timestamps should also be dumped, but which defaults to 'true' if omitted.
dump_interval_start()
writes out the header information for the interval.
dump_interval_table()
writes out the data in TABLE, which is of type
TYPE, which is associated with SUBINTERFACEINFO. The SubinterfaceInfo
object (also referred to simple as an ID), contains more meta-information
about the table. Please please please don't set the type to be different
than what the table actually is, this will cause anything that reads it
in the future to be very confused and probably crash and burn.
USE_TIMESTAMPS is a Boolean that indicates whether the 'first' and 'latest'
timestamps should also be dumped, but which defaults to 'true' if omitted.
dump_interval_end()
writes out the footer information for the interval.
The CAIDA::Tables, CAIDA::Traffic2::Interval, CAIDA::Traffic2::SubinterfaceInfo and CAIDA::Traffic2::FileReader manpages.
crl_flow can output in several different formats than the 'Traffic2' format, which are readable by Interval objects, but cause possibly unexpected behavior. crl_flow allows multiple different expiration algorithms, which can cause the output of multiple entries with the same key. These separate entries will be added together when read by these classes. In addition, 'active' flows are currently ignored entirely.
For best results, use crl_flow -I.
If you have any ideas about how better to deal with this (creating different tables for active and expired flows, creating tables that accept multiple separate entries with the same key), please write us at coral-bugs@caida.org
Ryan Koga <rkoga@caida.org>