CAIDA::Traffic2::FileWriter - Writer of Traffic2-style output files.


    use CAIDA::Traffic2::FileWriter;
    while ( ... ) { # Getting intervals
        $writer->initialize($interval, "Tuple Table");


    while ( ... ) { # Getting intervals
        $writer->initialize($interval, "Tuple Table");
        $writer->init_user_tables("My Table");
        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);


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:

new (FILE)
Creates a new FileWriter. FILE can be either an open filehandle or a file name, and all data is read from it. BINARY is a boolean that dictates whether or not the tables are written in binary format. If BINARY is false or omitted, the tables are written in text format.

As a side effect, it also writes a file header to FILE.

initialize (INTERVAL, LIST)
Specifies meta-information about the tables to be written. INTERVAL is the Interval object that contains table meta-information, which generally is returned by FileReader::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.

init_user_tables (LIST)
Specifies the list of tables to be dumped that are NOT automatically generated by FileReader. These tables MUST be dumped for every SubinterfaceInfo object, or the resulting file will be invalid.

dump_interval_full (USE_TIMESTAMPS)
dump_interval_full ()
Writes out all the information for an interval at once. This requires that the Interval object (specified in 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 ()
dump_interval_table (SUBINTERFACEINFO, TYPE, TABLE)
dump_interval_end ()
Writes out the information for an interval in discrete parts. This can be used with either a fully preloaded Interval, or via incremental reads. 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






Ryan Koga <>