ChannelAnalyzer.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 #include <fstream>
15 
16 // Custom includes
17 #include <senf/PPI.hh>
23 
24 #include "FrameAnalyzer.hh"
25 
26 #define prefix_
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 void handleSignal(siginfo_t const &)
30 {
32 }
33 
34 namespace {
35  int exitCode_ (0);
36 }
37 
38 void exitCode(int code)
39 {
40  exitCode_ = code;
41 }
42 
43 int main(int argc, char const * argv[])
44 {
46 
47  Configuration configuration;
48 
49  if (!configuration.parse( argc, argv)) {
50  exit(1);
51  }
52 
53  senf::TCPv4ClientSocketHandle *handle = NULL;
54  if (configuration.logDestination.port() != 0) {
55  try {
56  handle = new senf::TCPv4ClientSocketHandle( configuration.logDestination);
57  handle->protocol().sndbuf( 128000); // avoid blocking on temporary TCP issues
58  if (dup2( handle->fd(), fileno(stdout)) == -1) {
59  throw senf::SystemException( "dup2 failed");
60  }
61  }
62  catch (senf::SystemException & ex) {
63  SENF_LOG( (senf::log::CRITICAL) ("Failed to connect to log destination: " << ex.message()) );
64  exit(1);
65  }
66  }
67 
68  // determine the MAC address of the monitor Device.
69  // This is required for the MonitorDataFilter to perform proper re-ordering
71  try {
72  std::ifstream fs;
73  std::string buf;
74  fs.open( (std::string("/sys/class/net/") + configuration.device + std::string("/address")).c_str());
75  fs >> buf;
76  fs.close();
78  } catch(...) {
79  SENF_LOG( (senf::log::CRITICAL) ("Failed to determine MAC address of monitor device") );
80  exit(1);
81  }
82  SENF_LOG((senf::log::IMPORTANT)("Determined MAC address for " << configuration.device << " is " << mac));
83 
85  socket.protocol().rcvbuf(4096);
86 
87  senf::emu::MonitorDataFilter filter (mac);
88 
89  /*
90  if (configuration.reorderBufferSize > senf::ClockService::milliseconds(0))
91  filter.reorderTimeout(configuration.reorderTimeout);
92  */
93 
94  if (configuration.tsftHistogram) {
95  filter.tsftHistogram().start();
96  }
97 
98  FrameAnalyzer analyzer (configuration);
99 
100  // monitor mode specific config
101  filter.promisc(configuration.promisc);
102  filter.annotate(true);
103  filter.airTime(true);
105  // now, create the RT source
107  senf::ppi::connect( *source, filter);
108  senf::ppi::connect( filter, analyzer);
109 
111  senf::scheduler::SignalEvent sigterm (SIGTERM, handleSignal);
112 
113  SENF_LOG((senf::log::IMPORTANT)("Waiting for first valid frame to start..."));
114 
115  senf::ppi::run();
116 
117  unsigned dropped (socket.protocol().rxQueueDropped());
118  if (dropped > 0) {
119  SENF_LOG((senf::log::IMPORTANT)("Dropped " << dropped << " frames during the capture! CPU overload ?"));
120  }
121  SENF_LOG((senf::log::IMPORTANT) ("Filterstats " << filter.stats().dump()) );
122 
123  if (configuration.tsftHistogram) {
124  filter.tsftHistogram().dump(std::cout);
125  }
126 
127  return exitCode_;
128 }
129 
130 
131 //-/////////////////////////////////////////////////////////////////////////////////////////////////
132 #undef prefix_
133 
134 
135 // Local Variables:
136 // mode: c++
137 // fill-column: 100
138 // c-file-style: "senf"
139 // indent-tabs-mode: nil
140 // ispell-local-dictionary: "american"
141 // compile-command: "scons -u"
142 // comment-column: 40
143 // End:
void dump(std::ostream &os) const
#define SENF_EMU_MAXMTU
Definition: config.hh:40
MonitorDataFilter header.
std::uint8_t mac[6]
static void logToStderr()
bool start(senf::MACAddress const &src)
senf::INet4SocketAddress logDestination
virtual void terminate() const
static MACAddress from_string(std::string const &s)
int main(int argc, char const *argv[])
void exitCode(int code)
int run(int argc, char const *argv[])
Definition: dfstest.cc:83
bool parse(int argc, char const *argv[])
ProtocolClientSocketHandle< ConnectedMMapPacketSocketProtocol< QueueReadPolicy > > ConnectedMMapReadPacketSocketHandle
ProtocolClientSocketHandle< TCPv4SocketProtocol > TCPv4ClientSocketHandle
std::string message() const
MonitorDataFilterStatistics stats()
static void filterMonitorTxFrames(BSDSocket sock)
unsigned port() const
void handleSignal(siginfo_t const &)
#define SENF_LOG(args)
void dump(std::ostream &os) const
std::string device