MPLSGenerator.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 #include <string>
16 #include <iomanip>
23 #include <senf/PPI/SocketSink.hh>
24 #include <senf/Utils/membind.hh>
25 #include <senf/Utils/hexdump.hh>
26 
31 
32 #include "Configuration.hh"
33 
34 #define prefix_
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36 
37 
39 {
41 
42  void timeout() {
43  output( eth.clone());
44  count_++;
45  if (numPackets_ > 0 && (count_ > numPackets_)) {
46  exit(0);
47  }
48  next_ += interval_;
50  }
51 
52 public:
58  boost::uint64_t count_;
59  boost::uint64_t numPackets_;
60 
61  MPLSGenerator( senf::MACAddress const & mac, Configuration const & config) :
62  timer("mpls gen", boost::bind(&MPLSGenerator::timeout, this)),
63  next_(senf::scheduler::now()),
64  eth(senf::EthernetPacket::create()),
65  count_(0),
66  numPackets_(0)
67  {
68  noroute(output);
69 
70  eth->source() << mac;
71  eth->destination() << config.destination;
72  eth->type_length() << 0x8847;
73  senf::DataPacket data(senf::DataPacket::createAfter(eth, config.pktSize - 14));
74  eth.finalizeAll();
75 
76  interval_ = senf::ClockService::microseconds( 1000000 / config.pktsPerSecond);
77  numPackets_ = config.numPackets;
78 
79  SENF_LOG((senf::log::IMPORTANT) ("Starting generator on iface " << config.interface << " with MAC " << mac
80  << ", destination " << config.destination
81  << ", interval " << senf::ClockService::in_microseconds(interval_) << " us, pktSize " << config.pktSize
82  << ", numPackets " << config.numPackets));
83 
84  // start the transmission
85  timeout();
86  }
87 };
88 
89 
90 int main(int argc, char const * argv[])
91 {
92  Configuration configuration;
93 
94  if (!configuration.parse( argc, argv)) {
95  exit(1);
96  }
97 
98  senf::NetdeviceController netdevCtrl (configuration.interface);
99  netdevCtrl.up();
100  senf::MACAddress macAddr( netdevCtrl.hardwareAddress());
101 
103  socket.bind(senf::LLSocketAddress(configuration.interface));
105  MPLSGenerator generator( macAddr, configuration);
106 
107  senf::ppi::connect( generator, sink);
108  senf::ppi::run();
109 }
110 
111 
112 //-/////////////////////////////////////////////////////////////////////////////////////////////////
113 #undef prefix_
114 //#include "MCSniffer.mpp"
115 
116 
117 // Local Variables:
118 // mode: c++
119 // fill-column: 100
120 // c-file-style: "senf"
121 // indent-tabs-mode: nil
122 // ispell-local-dictionary: "american"
123 // compile-command: "scons -u"
124 // comment-column: 40
125 // End:
config::time_type clock_type
senf::INet4SocketAddress destination
std::uint8_t mac[6]
boost::uint32_t pktSize
u8 data[SPECTRAL_HT20_NUM_BINS]
std::string interface
boost::uint64_t numPackets_
senf::scheduler::TimerEvent timer
void noroute(connector::Connector &connector)
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_microseconds(clock_type const &v)
boost::uint32_t pktsPerSecond
senf::ClockService::clock_type interval_
void timeout(ClockService::clock_type const &timeout, bool initiallyEnabled=true)
int run(int argc, char const *argv[])
Definition: dfstest.cc:83
std::uint64_t numPackets
senf::ppi::connector::ActiveOutput< senf::EthernetPacket > output
senf::ClockService::clock_type next_
static SENF_CLOCKSERVICE_CONSTEXPR clock_type microseconds(int64_type const &v)
#define SENF_PPI_MODULE(name)
bool parse(int argc, char const *argv[])
int main(int argc, char const *argv[])
MACAddress hardwareAddress() const
ProtocolClientSocketHandle< PacketSocketProtocol > PacketSocketHandle
senf::EthernetPacket eth
ClockService::clock_type const & now() const
ConcretePacket< EthernetPacketType > EthernetPacket
MPLSGenerator(senf::MACAddress const &mac, Configuration const &config)
#define SENF_LOG(args)
boost::uint64_t count_