Tx.hh
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 
17 //#include "main.hh"
18 //#include "main.ih"
19 
20 // Custom includes
21 #include <boost/lexical_cast.hpp>
22 #include <iostream>
23 #include <senf/PPI.hh>
29 #include <senf/Utils/Logger.hh>
30 #include <senf/Utils/Console.hh>
31 
32 #include "MPLSPacket.hh"
33 #include "TIMPacket.hh"
34 
35 //#include "main.mpp"
36 #define prefix_
37 
39 namespace module = senf::ppi::module;
41 namespace ppi = senf::ppi;
42 namespace emu = senf::emu;
43 
44 namespace {
45 
46  class Sender : public module::Module
47  {
48  SENF_PPI_MODULE(Sender);
49  public:
53  senf::MPLSPacket mpls;
57  unsigned seqNo;
58 
59  Sender(senf::MACAddress const & src, senf::MACAddress const & dst, std::uint32_t label)
60  : timer_("TX", senf::membind(&Sender::timerEvent, this), senf::ClockService::clock_type(0), false),
61  eth(senf::EthernetPacket::create()),
64  src_(src), dst_(dst)
65  {
66  noroute(output);
67 
68  eth->source() = src_;
69  eth->destination() = dst_;
70  mpls->label() = label;
71  mpls->tc() = 1;
72  // let's use non-jumbo frames for now
73  senf::DataPacket data (senf::DataPacket::createAfter(tim, 1500u - mpls.size()));
74  eth.finalizeAll();
75  }
76 
77  private:
78  void timerEvent()
79  {
80  tim->timestamp() = senf::ClockService::in_milliseconds(senf::scheduler::now()) % (wiback::TIMPacketParser::timestamp_t::max_value + 1);
81  tim->sequenceNumber() = seqNo;
82  tim->linkLocalSeqNo() = seqNo;
83  seqNo = (seqNo + 1) % (wiback::TIMPacketParser::sequenceNumber_t::max_value + 1);
84 
85  output(eth.clone());
86  nextTimeout += period;
87  timer_.timeout(nextTimeout);
88  }
89 
90  public:
91  void bitrate(unsigned brate_in_kbps)
92  {
93  if (brate_in_kbps == 0) {
94  timer_.disable();
95  return;
96  }
97 
98  seqNo = 0;
99  nextTimeout = senf::scheduler::now();
100  period = senf::ClockService::microseconds((eth.size()*8) * 1000 / brate_in_kbps);
101  timerEvent();
102  }
103 
104  senf::MACAddress src_;
105  senf::MACAddress dst_;
106  };
107 }
108 
110 #undef prefix_
111 //#include "main.mpp"
112 
113 
114 // Local Variables:
115 // mode: c++
116 // indent-tabs-mode: nil
117 // End:
config::time_type clock_type
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_milliseconds(clock_type const &v)
u8 data[SPECTRAL_HT20_NUM_BINS]
StatsDataCollectorKernel bitrate
boost::function< R(Args)> membind(R(T::*fn)(Args), T *ob)
void timeout(ClockService::clock_type const &timeout, bool initiallyEnabled=true)
static SENF_CLOCKSERVICE_CONSTEXPR clock_type microseconds(int64_type const &v)
#define SENF_PPI_MODULE(name)
size_type size() const
ConcretePacket< EthernetPacketType > EthernetPacket
static ConcretePacket createAfter(Packet const &packet)
HardwareEthernetInterface public header.
HardwareWLANInterface public header.