1 /**
2  * one_page_report.h:
3  * Show map of network traffic by host
4  *
5  * This source file is public domain, as it is not based on the original tcpflow.
6  *
7  * Author: Michael Shick <mike@shick.in>
8  *
9  */
10 
11 #ifndef ONE_PAGE_REPORT_H
12 #define ONE_PAGE_REPORT_H
13 #include "plot_view.h"
14 #include "time_histogram.h"
15 #include "time_histogram_view.h"
16 #include "address_histogram.h"
17 #include "address_histogram_view.h"
18 #include "port_histogram.h"
19 #include "port_histogram_view.h"
20 #include "packetfall.h"
21 #include "net_map.h"
22 #include "iptree.h"
23 #include "legend_view.h"
24 
25 class one_page_report {
26 public:
27     class transport_type {
28     public:
transport_type(uint16_t ethertype_,std::string name_)29         transport_type(uint16_t ethertype_, std::string name_) :
30             ethertype(ethertype_), name(name_) {}
31         uint16_t ethertype;
32         std::string name;
33     };
34 
35 
36     typedef std::map<in_port_t, in_port_t> port_aliases_t;
37     typedef std::map<in_port_t, plot_view::rgb_t> port_colormap_t;
38     typedef std::vector<transport_type> transport_type_vector;
39 
40     std::string source_identifier;
41     std::string filename;
42     plot_view::bounds_t bounds;
43     double header_font_size;
44     double top_list_font_size;
45     unsigned int histogram_show_top_n_text;
46 
47     // a single render event: content moves down a bounded cairo surface as
48     // indicated by end_of_content between render method invocations
49     class render_pass {
50     public:
render_pass(one_page_report & report_,cairo_t * surface_,const plot_view::bounds_t & bounds_)51         render_pass(one_page_report &report_, cairo_t *surface_,
52                 const plot_view::bounds_t &bounds_) :
53             report(report_), surface(surface_), surface_bounds(bounds_),
54             end_of_content(0.0) {}
55 
56         void render_text_line(std::string text, double font_size,
57                 double line_space);
58         void render_text(std::string text, double font_size, double x_offset,
59                 cairo_text_extents_t &rendered_extents);
60 
61         void render_header();
62         void render(time_histogram_view &view);
63         void render(address_histogram_view &left, address_histogram_view &right);
64         void render(port_histogram_view &left, port_histogram_view &right);
65         void render(const legend_view &view);
66         void render_map();
67         void render_packetfall();
68 
69         one_page_report &report;
70         cairo_t *surface;
71         plot_view::bounds_t surface_bounds;
72         double end_of_content;
73     };
74     friend class render_pass;
75 
76     one_page_report(int max_histogram_size);
77 
78     void ingest_packet(const be13::packet_info &pi);
79     void render(const std::string &outdir);
80     plot_view::rgb_t port_color(uint16_t port) const;
81     void dump(int debug);
82 
83     static transport_type_vector build_display_transports();
84 
85     static const unsigned int max_bars;
86     static const unsigned int port_colors_count;
87     // string constants
88     static const std::string title_version;
89     static const std::string generic_legend_format;
90     static const transport_type_vector display_transports;
91     // ratio constants
92     static const double page_margin_factor;
93     static const double line_space_factor;
94     static const double histogram_pad_factor_y;
95     static const double address_histogram_width_divisor;
96     // size constants
97     static const double packet_histogram_height;
98     static const double address_histogram_height;
99     static const double port_histogram_height;
100     static const double legend_height;
101     // color constants
102     static const plot_view::rgb_t default_color;
103     static const plot_view::rgb_t color_orange;
104     static const plot_view::rgb_t color_red;
105     static const plot_view::rgb_t color_magenta;
106     static const plot_view::rgb_t color_purple;
107     static const plot_view::rgb_t color_deep_purple;
108     static const plot_view::rgb_t color_blue;
109     static const plot_view::rgb_t color_teal;
110     static const plot_view::rgb_t color_green;
111     static const plot_view::rgb_t color_yellow;
112     static const plot_view::rgb_t color_light_orange;
113     static const plot_view::rgb_t cdf_color;
114 
115 private:
116     uint64_t packet_count;
117     uint64_t byte_count;
118     struct timeval earliest;
119     struct timeval latest;
120     std::map<uint32_t, uint64_t> transport_counts;
121     std::map<uint16_t, bool> ports_in_time_histogram;
122     legend_view::entries_t color_labels;
123     time_histogram packet_histogram;
124     port_histogram src_port_histogram;
125     port_histogram dst_port_histogram;
126     packetfall pfall;
127     net_map netmap;
128 public:
129     iptree src_tree;
130     iptree dst_tree;
131     port_aliases_t port_aliases;
132     port_colormap_t port_colormap;
133 
134 };
135 
136 #endif
137