Interfaces.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>
34 #include <senf/Utils/Logger.hh>
35 #include <senf/Utils/Console.hh>
36 
37 //#include "main.mpp"
38 #define prefix_
39 
41 namespace module = senf::ppi::module;
43 namespace ppi = senf::ppi;
44 namespace emu = senf::emu;
45 
46 namespace {
47 
48  struct WMMParameter
49  {
50  std::uint8_t accessCategory;
51  std::uint16_t cwMin;
52  std::uint16_t cwMax;
53  std::uint8_t aifs;
54  std::uint16_t txOp;
55  };
56 
57  // TODO (2014-01-13 mtk): TxOp timings are considered in .11n mode in 3.13 (and hopefully above :)
58  static WMMParameter defaultHtWMM[] = {
59  // NC
60  { NL80211_TXQ_Q_VO, 3, 7, 0, 0 },
61  // VO
62  { NL80211_TXQ_Q_VI, 3, 7, 2, 10 },
63  // VI
64  { NL80211_TXQ_Q_BE, 7, 15, 3, 20 },
65  // BE
66  { NL80211_TXQ_Q_BK, 7, 15, 5, 40 },
67  };
68 
69  class ReceiveGroup : public module::Module
70  {
71  SENF_PPI_MODULE(ReceiveGroup);
72  public:
75  senf::MACAddress id_;
76 
77  ReceiveGroup(senf::emu::Interface const & interface) {
78  route( input, output).autoThrottling( false);
80  input.onRequest( &ReceiveGroup::request);
81  id_ = interface.id();
82  }
83  void request() {
84  output(input());
85  }
86  };
87 
88  class TransmitGroup : public module::Module
89  {
90  SENF_PPI_MODULE(TransmitGroup);
91  public:
94 
95  TransmitGroup(senf::emu::Interface const & interface) {
96  route(input, output).autoThrottling( false);
98  input.onRequest( &TransmitGroup::request);
99  }
100  void request() {
101  output(input());
102  }
103  };
104 
106 
107  class EthernetInterface
109  {
110  public:
111  EthernetInterface(std::string const & iface)
113  {}
114  };
115 
116  class WLANInterface
118  {
119  public:
120  WLANInterface(std::string const & phy)
121  : emu::HardwareWLANInterface(initInterfaces(phy))
122  {}
123 
124  ~WLANInterface()
125  {
126  try {
127  wnlc_.ibss_leave();
128  } catch (...) {}
129  }
130 
131  std::pair<std::string,std::string> initInterfaces(std::string const & dev)
132  {
134  // first, remove all existing interfaces of the phy device
135  for (std::string iface : wnlc.all_interfaces()) {
136  wnlc.del_interface( iface);
137  }
138 
139  // now, add the monitor interface...
140  wnlc.add_monInterface(monInterfaceName(wnlc.phyIndex()),
145 
146  // ... and then the adhoc interface
147  std::string ifname (adhocInterfaceName(wnlc.phyIndex()));
148  wnlc.add_adhocInterface(ifname);
149 
150  return std::make_pair(ifname,monInterfaceName(wnlc.phyIndex()));
151  }
152 
153  std::string adhocInterfaceName(int phyIndex)
154  {
155  return (boost::format("wiback-wlan%d") % phyIndex).str();
156  }
157 
158  std::string monInterfaceName(int phyIndex)
159  {
160  return (boost::format("wiback-mon%d") % phyIndex).str();
161  }
162 
163  void join(unsigned freq, unsigned bwidth, unsigned netId)
164  {
165  std::string ssid;
167  ssid = "WiBACK-" + std::to_string(netId) + "-" + std::to_string(freq);
168  std::uint64_t tmp ((std::uint64_t(netId) << 32) + freq);
169  char buf[64];
170  sprintf( buf, "00:%x:%x:%x:%x:%x", std::uint32_t((tmp >> 32) & 0xff), std::uint32_t((tmp >> 24) & 0xff),
171  std::uint32_t((tmp >> 16) & 0xff), std::uint32_t((tmp >> 8) & 0xff),
172  std::uint32_t((tmp >> 0) & 0xff));
173  bssid = senf::MACAddress::from_string( buf);
174 
175  joinAdhocNetwork( ssid, freq*1000, bwidth*1000)
176  ->bssid( bssid)
177  ->beaconInterval(125)
178  ->ampduFactor(3); // WiBACK default. Should be configurable via policy.
179  // For more recent kernels 3.13++, we should set this to 3 and control the burst length via TxOp
180 
181  modulation(senf::emu::WLANModulationParameter::MCS, 7);
182  txPower(txPowers().back().upper);
183  coverageRange(450);
184  senf::emu::WirelessNLController wnlc(device());
185  // the PID rate controller counts the total number of transmissions not only the retries, hence +1
186  wnlc.set_retryLimit(2,2);
187 
188  // default WiBACK WMM settings
189  for (unsigned i = 0; i < 4; i++){
190  wnlc.set_txQueueParameters( defaultHtWMM[i].accessCategory, defaultHtWMM[i].cwMin, defaultHtWMM[i].cwMax, defaultHtWMM[i].aifs, defaultHtWMM[i].txOp);
191  }
192  }
193  };
194 }
195 
197 #undef prefix_
198 //#include "main.mpp"
199 
200 
201 // Local Variables:
202 // mode: c++
203 // indent-tabs-mode: nil
204 // End:
#define NL80211_TXQ_Q_BE
Definition: nl80211-new.h:3511
Interface API base class
void add_adhocInterface(std::string const &name)
WirelessExtController public header.
void del_interface(std::string const &name)
void id(MACAddress const &eui)
Change interface MAC.
Definition: InterfaceAPI.cc:82
static MACAddress from_string(std::string const &s)
char ssid[36]
void add_monInterface(std::string const &name, int flags=MonitorFlags::None)
Apply additional modules to an interface.
std::uint8_t bssid[6]
#define NL80211_TXQ_Q_VO
Definition: nl80211-new.h:3509
void set_txQueueParameters(boost::uint8_t queue, boost::uint16_t cwMin, boost::uint16_t cwMax, boost::uint8_t aifs, boost::uint16_t txop)
#define SENF_PPI_MODULE(name)
void set_retryLimit(boost::uint8_t shortLimit, boost::uint8_t longLimit)
#define NL80211_TXQ_Q_VI
Definition: nl80211-new.h:3510
HardwareEthernetInterface public header.
HardwareWLANInterface public header.
__be16 freq
#define NL80211_TXQ_Q_BK
Definition: nl80211-new.h:3512
void throttlingDisc(ThrottlingDisc const &disc)