Netwhere
 All Classes Pages
netwhere.hpp
1 /*
2  * Copyright (c) 2017, Ben Smith
3  * All rights reserved.
4  *
5  */
6 
7 #ifndef __NETWHERE_H__
8 #define __NETWHERE_H__
9 
10 #include <tins/tins.h>
11 #include <boost/format.hpp>
12 
13 #include "flow_collector.hpp"
14 #include "reader_writer_exclusion.hpp"
15 #include "webservice.hpp"
16 #include "logger.hpp"
17 
18 class NetWhere {
19 public:
20  NetWhere(const std::string interface, Tins::IPv4Range hosts_range)
21  : _interface(interface), _collector(hosts_range),
22  _last_stats(0), _last_prune(0) {}
23 
24  void start();
25 
26  bool handle_packet(const Tins::PDU &pdu);
27  std::string handle_request(const std::string& url);
28 
29 private:
30  const int _print_stats_interval = 60;
31  const int _prune_interval = 60*60;
32  const int _prune_older_than = 60*60*2;
33 
34  FlowsCollector _collector;
35  ReaderWriterExclusion _rw_exclusion;
36  const std::string _interface;
37  time_t _last_stats;
38  time_t _last_prune;
39 
40  std::string hosts();
41  std::string host_flows(const std::string& host_key);
42  void print_stats() { LOG(boost::format("%1% hosts, %2% flows") % _collector.hosts().size() % _collector.flows().size()); }
43  std::string get_hostname(const Host& host);
44 };
45 
46 #endif
Definition: flow_collector.hpp:13
a lock shared between multiple reader threads and a single writer thread
Definition: reader_writer_exclusion.hpp:21
IP and hardware address for a network host.
Definition: host.hpp:21
Definition: netwhere.hpp:18