21 #include <boost/lexical_cast.hpp> 23 #include <senf/PPI.hh> 50 std::uint8_t accessCategory;
58 static WMMParameter defaultHtWMM[] = {
78 route( input, output);
105 route( input, output);
107 input.
onRequest( &TransmitGroup::request);
128 : first_ (
true), src_ (src), dst_ (dst), packetCount_(0), packetIgnored_(0), ttlMin_(255), ttlMax_(0)
130 route(input, output);
134 unsigned packetCount()
136 unsigned res (packetCount_);
141 unsigned packetIgnored()
143 unsigned res (packetIgnored_);
152 std::cerr <<
"first packet: " << ((
void*)
this) << std::endl;
157 std::uint8_t ttl (0);
162 ttl = std::uint8_t(ipv4->ttl());
168 ttl = std::uint8_t(ipv6->hopLimit());
174 if ((eth->type_length() > 1536) && ((ttl == 0) || (ttl > 2))) {
175 eth->destination() << dst_;
176 eth->source() << src_;
187 unsigned packetCount_;
188 unsigned packetIgnored_;
189 std::uint8_t ttlMin_, ttlMax_;
192 class EthernetInterface
196 EthernetInterface(std::string
const & iface)
205 WLANInterface(std::string
const & phy)
208 monitorDevice( monInterfaceName(wnlc_.phyIndex()));
224 std::string initInterfaces(std::string
const & dev)
240 std::string ifname (adhocInterfaceName(wnlc.
phyIndex()));
246 std::string adhocInterfaceName(
int phyIndex)
248 return (boost::format(
"wiback-wlan%d") % phyIndex).str();
251 std::string monInterfaceName(
int phyIndex)
253 return (boost::format(
"wiback-mon%d") % phyIndex).str();
256 void join(
unsigned freq,
unsigned bwidth,
unsigned netId)
260 ssid =
"WiBACK-" + std::to_string(netId) +
"-" + std::to_string(freq);
261 std::uint64_t tmp ((std::uint64_t(netId) << 32) + freq);
263 sprintf( buf,
"00:%x:%x:%x:%x:%x", std::uint32_t((tmp >> 32) & 0xff), std::uint32_t((tmp >> 24) & 0xff),
264 std::uint32_t((tmp >> 16) & 0xff), std::uint32_t((tmp >> 8) & 0xff),
265 std::uint32_t((tmp >> 0) & 0xff));
268 joinAdhocNetwork( ssid, freq*1000, bwidth*1000)
270 ->beaconInterval(125)
274 modulation(senf::emu::WLANModulationParameter::MCS, 7);
275 txPower(txPowers().back().upper);
282 for (
unsigned i = 0; i < 4; i++){
283 wnlc.
set_txQueueParameters( defaultHtWMM[i].accessCategory, defaultHtWMM[i].cwMin, defaultHtWMM[i].cwMax, defaultHtWMM[i].aifs, defaultHtWMM[i].txOp);
288 template <
class Interface>
294 DecoInterface iface0;
295 DecoInterface iface1;
296 Forwarder forwarder0;
297 Forwarder forwarder1;
300 struct ::timeval startTime;
301 unsigned long lastStats;
306 App(std::string
const & iface0_,
309 std::string
const & iface1_,
318 forwarder0 (iface1.id(), peer1),
319 forwarder1 (iface0.id(), peer0),
325 iface0.interface().rcvBuf(rxbuf_);
326 iface0.interface().sndBuf(txbuf_);
327 iface0.interface().qlen(ring_);
328 iface0.interface().maxBurst(burst_);
330 iface1.interface().rcvBuf(rxbuf_);
331 iface1.interface().sndBuf(txbuf_);
332 iface1.interface().qlen(ring_);
333 iface1.interface().maxBurst(burst_);
335 iface0.interface().
enable();
336 iface1.interface().enable();
339 if ((wif = dynamic_cast<WLANInterface*>(&iface0.interface())) != NULL) {
340 wif->join(freq0, 40, 4711u);
342 if ((wif = dynamic_cast<WLANInterface*>(&iface1.interface())) != NULL) {
343 wif->join(freq1, 40, 4711u);
346 ppi::connect(iface0, forwarder0);
347 ppi::connect(forwarder0, iface1);
349 ppi::connect(iface1, forwarder1);
350 ppi::connect(forwarder1, iface0);
352 registerEvent(statsTimer, &App::stats);
353 ::gettimeofday(&startTime, 0);
359 ::gettimeofday(&tv, 0);
361 (tv.tv_sec - startTime.tv_sec) * 1000000 + tv.tv_usec - startTime.tv_usec);
362 std::cout << tv.tv_sec <<
'.' << std::setw(6) << std::setfill(
'0') << tv.tv_usec
363 <<
" usecs " << time - lastStats
364 <<
" packets forwarded " << forwarder0.packetCount() + forwarder1.packetCount()
365 <<
" packets ignored " << forwarder0.packetIgnored() + forwarder1.packetIgnored()
366 <<
" queue0-drops " << iface0.interface().rxQueueDropped()
367 <<
" queue1-drops " << iface1.interface().rxQueueDropped()
374 std::cerr <<
"bye." << std::endl;
379 template <
class Application>
382 unsigned burst,
unsigned nrring,
unsigned rxbuf,
unsigned txbuf)
384 Application app (iface0, freq0, peer0, iface1, freq1, peer1, burst, nrring, rxbuf, txbuf);
390 int main(
int argc,
char ** argv)
395 std::cerr <<
"Usage:\n " << argv[0] <<
"\n" 396 <<
" <iface1> <freq0> <peermac1>\n" 397 <<
" <iface2> <freq1> <peermac2>\n" 398 <<
" <burst> <rxbuf> <txbuf> <nrring> [[NO]RT] [[NO]WLAN]\n" 403 std::string iface0 (argv[1]);
404 unsigned freq0 (boost::lexical_cast<unsigned>(argv[2]));
406 std::string iface1 (argv[4]);
407 unsigned freq1 (boost::lexical_cast<unsigned>(argv[5]));
410 unsigned burst (boost::lexical_cast<unsigned>(argv[7]));
411 unsigned rxbuf (boost::lexical_cast<unsigned>(argv[8]));
412 unsigned txbuf (boost::lexical_cast<unsigned>(argv[9]));
413 unsigned nrring (boost::lexical_cast<unsigned>(argv[10]));
415 bool enableRT (
true);
416 bool useWlan (
false);
418 for (
int i (11); i < argc; ++ i) {
420 char * arg (argv[i]);
423 if (*(++ arg) ==
'O')
427 case 'R': enableRT = state;
break;
428 case 'W': useWlan = state;
break;
429 default: std::cerr <<
"invalid flag " << argv[i] << std::endl; ::exit(1);
434 ::sched_param schedpm = {};
435 schedpm.sched_priority = 1;
436 if (::sched_setscheduler(::getpid(), SCHED_FIFO, &schedpm) >= 0)
437 std::cerr <<
"SCHED_FIFO realtime scheduling enabled" << std::endl;
440 senf::scheduler::watchdogTimeout(0);
445 run< App<WLANInterface> >(iface0, freq0 , peer0,
446 iface1,
freq1, peer1,
447 burst, nrring, rxbuf, txbuf);
448 run< App<EthernetInterface> >(iface0, freq0, peer0,
449 iface1,
freq1, peer1,
450 burst, nrring, rxbuf, txbuf);
static Server & start(senf::INet4SocketAddress const &address)
void add_adhocInterface(std::string const &name)
IfaceNameSet all_interfaces() const
WirelessExtController public header.
virtual void terminate() const
void del_interface(std::string const &name)
void id(MACAddress const &eui)
Change interface MAC.
static SENF_CLOCKSERVICE_CONSTEXPR clock_type seconds(int64_type const &v)
static MACAddress from_string(std::string const &s)
void add_monInterface(std::string const &name, int flags=MonitorFlags::None)
static INet4Address const None
Apply additional modules to an interface.
ConcretePacket< IPv6PacketType > IPv6Packet
int run(int argc, char const *argv[])
void set_txQueueParameters(boost::uint8_t queue, boost::uint16_t cwMin, boost::uint16_t cwMax, boost::uint8_t aifs, boost::uint16_t txop)
Hardware Ethernet Interface.
#define SENF_PPI_MODULE(name)
int main(int argc, char **argv)
void onRequest(Handler handler)
void set_retryLimit(boost::uint8_t shortLimit, boost::uint8_t longLimit)
ConcretePacket< EthernetPacketType > EthernetPacket
HardwareEthernetInterface public header.
HardwareWLANInterface public header.
ConcretePacket< IPv4PacketType > IPv4Packet