10 #include <tins/tins.h>
11 #include <boost/functional/hash.hpp>
13 #include "object_set.hpp"
23 Flow(
const Tins::EthernetII::address_type& src_hw,
24 const Tins::IPv4Address& src_ip,
25 const Tins::EthernetII::address_type& dst_hw,
26 const Tins::IPv4Address& dst_ip,
29 : src_hw(src_hw), src_ip(src_ip),
30 dst_hw(dst_hw), dst_ip(dst_ip), dst_port(dst_port), ip_protocol(ip_protocol) {}
32 bool operator == (
const Flow& other)
const {
33 return src_hw == other.src_hw
34 && src_ip == other.src_ip
35 && dst_hw == other.dst_hw
36 && dst_ip == other.dst_ip
37 && dst_port == other.dst_port
38 && ip_protocol == other.ip_protocol;
41 const Tins::EthernetII::address_type src_hw;
42 const Tins::IPv4Address src_ip;
43 const Tins::EthernetII::address_type dst_hw;
44 const Tins::IPv4Address dst_ip;
46 const uint8_t ip_protocol;
53 size_t operator()(
const Flow& flow)
const {
55 for(
auto && value : flow.src_hw) {
56 boost::hash_combine<uint8_t>(seed, value);
58 boost::hash_combine<uint32_t>(seed, flow.src_ip);
59 for(
auto && value : flow.dst_hw) {
60 boost::hash_combine<uint8_t>(seed, value);
62 boost::hash_combine<uint32_t>(seed, flow.dst_ip);
63 boost::hash_combine<uint32_t>(seed, flow.dst_port);
64 boost::hash_combine<uint8_t>(seed, flow.ip_protocol);
76 FlowCounter(
const Flow& flow) : _flow(flow), _bytes_to_src(0), _bytes_to_dst(0), _modified_at(0) {}
78 void incr_src(time_t current_time,
size_t bytes) {
79 _bytes_to_src += bytes;
80 _modified_at = current_time;
83 void incr_dst(time_t current_time,
size_t bytes) {
84 _bytes_to_dst += bytes;
85 _modified_at = current_time;
88 const Flow& flow()
const {
return _flow; }
89 size_t bytes_to_src()
const {
return _bytes_to_src; }
90 size_t bytes_to_dst()
const {
return _bytes_to_dst; }
91 time_t modified_at()
const {
return _modified_at; }
representation of a packet flow
Definition: flow.hpp:22
counts bytes associated with a Flow
Definition: flow.hpp:74