AnnotationsPacket.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 
17 #include "AnnotationsPacket.hh"
18 //#include "AnnotationsPacket.ih"
19 
20 // Custom includes
21 #include <iomanip>
22 #include <boost/io/ios_state.hpp>
23 #include <senf/Utils/Format.hh>
24 #include <senf/Utils/senflikely.hh>
27 #include "Annotations.hh"
28 
29 #define prefix_
30 //-/////////////////////////////////////////////////////////////////////////////////////////////////
31 
33 
36 
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38 // senf::AnnotationsPacketType
39 
41 {
42  boost::io::ios_all_saver ias(os);
43  os << senf::fieldName("interfaceId") << p->type().value() << std::endl;
44  os << senf::fieldName("timestampMAC") << format::dumpint(p->timestampMAC().value()) << std::endl;
45  os << senf::fieldName("timestamp") << format::dumpint(p->timestamp().value()) << std::endl;
46  os << senf::fieldName("modulationId") << format::dumpint(p->modulationId().value()) << std::endl;
47  os << senf::fieldName("snr") << format::dumpint(p->snr().value()) << std::endl;
48  os << senf::fieldName("rssi") << format::dumpint(p->rssi().value()) << std::endl;
49  os << senf::fieldName("airTime") << format::dumpint(p->airTime().value()) << std::endl;
50  os << senf::fieldName("type") << format::dumpint(p->type().value()) << std::endl;
51 
52  os << senf::fieldName("flags.corrupt") << format::dumpint(p->corrupt().value()) << std::endl;
53  os << senf::fieldName("flags.retransmitted") << format::dumpint(p->retransmitted().value()) << std::endl;
54  os << senf::fieldName("flags.duplicated") << format::dumpint(p->duplicated().value()) << std::endl;
55  os << senf::fieldName("flags.reordered") << format::dumpint(p->reordered().value()) << std::endl;
56  os << senf::fieldName("flags.aggregated") << format::dumpint(p->aggregated().value()) << std::endl;
57  os << senf::fieldName("flags.gap") << format::dumpint(p->gap().value()) << std::endl;
58  os << senf::fieldName("flags.length") << format::dumpint(p->length().value()) << std::endl;
59 }
60 
62 {
63  static factory_t typeFactory[] = { WLANPacket_MgtFrame::factory(),
64  WLANPacket_CtrlFrame::factory(),
65  WLANPacket_DataFrame::factory(),
66  EthernetPacket::factory(),
67  DataPacket::factory(),
68  no_factory() };
69 
70  return typeFactory[p->type()];
71 }
72 
74 {
75  Packet n (p.next(nothrow));
76  if (SENF_LIKELY(n)) {
77  if (n.is<WLANPacket_MgtFrame>())
78  p->type() << 0;
79  else if (n.is<WLANPacket_CtrlFrame>())
80  p->type() << 1;
81  else if (n.is<WLANPacket_DataFrame>())
82  p->type() << 2;
83  else if (n.is<EthernetPacket>())
84  p->type() << 3;
85  else if (n.is<DataPacket>())
86  p->type() << 4;
87  else
88  p->type() << 0xff;
89  }
90  // Do NOT reset type_length if the type is not known ... doing this will destroy read packets
91 }
92 
94 {
96  EthOUIExtensionPacket const & oui (EthOUIExtensionPacket::createBefore(ap));
97  EthernetPacket eth (EthernetPacket::createBefore(oui));
98 
101  if (SENF_LIKELY(pkt.is<senf::EthernetPacket>())) {
102  src = pkt.as<senf::EthernetPacket>()->source();
103  dst = pkt.as<senf::EthernetPacket>()->destination();
104  }
105  else if (pkt.is<senf::WLANPacket_MgtFrame>()) {
106  src = pkt.as<senf::WLANPacket_MgtFrame>()->sourceAddress();
107  }
108  else if (pkt.is<senf::WLANPacket_CtrlFrame>() and pkt.as<senf::WLANPacket_CtrlFrame>()->is_rts()) {
109  src = pkt.as<senf::WLANPacket_CtrlFrame>()->sourceAddress();
110  }
111  else if (pkt.is<senf::WLANPacket_DataFrame>()) {
112  src = pkt.as<senf::WLANPacket_DataFrame>()->sourceAddress();
113  dst = pkt.as<senf::WLANPacket_DataFrame>()->destinationAddress();
114  }
115  else if (pkt.is<senf::DataPacket>()) {
116  src = src_;
117  dst = dst_;
118  }
119 
120  eth->source() << src;
121  eth->destination() << (dst.multicast() ? pkt.annotation<emu::annotations::Interface>().value : dst);
122 
123  ap->interfaceId() << pkt.annotation<emu::annotations::Interface>().value;
126  ap->modulationId() << pkt.annotation<emu::annotations::WirelessModulation>().id;
127  ap->snr() << pkt.annotation<emu::annotations::Quality>().snr;
128  ap->rssi() << pkt.annotation<emu::annotations::Quality>().rssi;
129  ap->airTime() << pkt.annotation<emu::annotations::Quality>().airTime;
130  ap->corrupt() << pkt.annotation<emu::annotations::Quality>().flags.frameCorrupt;
131  ap->retransmitted() << pkt.annotation<emu::annotations::Quality>().flags.frameRetransmitted;
132  ap->duplicated() << pkt.annotation<emu::annotations::Quality>().flags.frameDuplicate;
133  ap->reordered() << pkt.annotation<emu::annotations::Quality>().flags.frameReordered;
134  ap->aggregated() << pkt.annotation<emu::annotations::Quality>().flags.frameAggregated;
135  ap->gap() << pkt.annotation<emu::annotations::Quality>().flags.framePredecessorLost;
136  ap->length() << pkt.annotation<emu::annotations::Quality>().flags.frameLength;
137 
138  eth.finalizeTo(ap);
139  return eth;
140 }
141 
142 
143 //-/////////////////////////////////////////////////////////////////////////////////////////////////
144 #undef prefix_
145 
146 
147 // Local Variables:
148 // mode: c++
149 // fill-column: 100
150 // c-file-style: "senf"
151 // indent-tabs-mode: nil
152 // ispell-local-dictionary: "american"
153 // compile-command: "scons -u test"
154 // comment-column: 40
155 // End:
static MACAddress const None
static ConcretePacket createBefore(Packet const &packet)
Incoming or outgoing interface.
Definition: Annotations.hh:37
static const std::uint16_t extType
static const std::uint32_t OUI_Fraunhofer_FIT
#define SENF_LIKELY(x)
Annotations public header.
streamable_type dumpint(T const &v)
WLANPacket_DataFrameType::packet WLANPacket_DataFrame
EthernetPacket prependAnnotationsPacket(Packet const &pkt, MACAddress const &src_=senf::MACAddress::None, MACAddress const &dst_=senf::MACAddress::Broadcast)
WLANPacket_MgtFrameType::packet WLANPacket_MgtFrame
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_nanoseconds(clock_type const &v)
Incoming packet timestamp.
Definition: Annotations.hh:86
OtherPacket const & as() const
senf::ClockService::clock_type as_clock_type() const
Packet next() const
Annotation & annotation()
WLANPacket_CtrlFrameType::packet WLANPacket_CtrlFrame
nothrow
ConcretePacket< EthOUIExtensionPacketType > EthOUIExtensionPacket
s8 rssi
#define prefix_
static void finalize(packet p)
static factory_t no_factory()
SENF_PACKET_REGISTRY_REGISTER(senf::EtherOUIExtTypes, senf::EtherOUIExtTypes::type(senf::EthOUIExtensionPacketType::OUI_Fraunhofer_FIT, senf::AnnotationsPacketType::extType), senf::AnnotationsPacket)
PacketInterpreterBase::factory_t factory_t
bool multicast() const
ConcretePacket< EthernetPacketType > EthernetPacket
SENF_PACKET_INSTANTIATE_TEMPLATE(senf::AnnotationsPacket)
ConcretePacket< DataPacketType > DataPacket
AnnotationsPacket public header.
static MACAddress const Broadcast
static key_t type(boost::uint32_t oui, boost::uint16_t extType)
static factory_t nextPacketType(packet p)
bool is() const
static void dump(packet p, std::ostream &os)
Dump given AnnotationsPacket in readable form to given output stream.