VLanId.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 
14 #ifndef HH_WiBACK_MIHMessaging_Types_VLanId_
15 #define HH_WiBACK_MIHMessaging_Types_VLanId_ 1
16 
17 // Custom includes
18 #include <set>
19 #include <unordered_set>
20 #include <boost/operators.hpp>
23 
25 
26 namespace senf {
27 namespace emu {
28 
29  typedef std::uint16_t VLanTag;
30 
31  struct VLanId
32  : public boost::equality_comparable<VLanId>,
33  public boost::less_than_comparable<VLanId>
34  {
35  static VLanId const None;
36 
37  enum Type {NoTag = 0, CTag, STag};
38 
39  VLanId(std::uint16_t id = 0, Type type = NoTag);
40  VLanId(senf::EthernetPacket const & eth);
41 
42  explicit operator bool() const;
43  bool operator<(VLanId const & other) const;
44  bool operator==(VLanId const & other) const;
45 
46  std::uint16_t id() const;
47  Type type() const;
48 
49  bool ctag() const;
50  bool stag() const;
51  bool sameTagType(VLanId const & other) const;
52 
53  static bool hasSTag(senf::EthernetPacket const & eth);
54  static bool hasCTag(senf::EthernetPacket const & eth);
55  static bool hasTag(senf::EthernetPacket const & eth);
56  static std::uint16_t payloadTypeLength(senf::EthernetPacket const & eth);
57  template <class PKT> static PKT payload(senf::EthernetPacket const & eth);
58  static Packet payloadPkt(senf::EthernetPacket const & eth);
59 
60  private:
61  std::uint16_t id_:12;
62  std::uint16_t type_:2;
63 
64  SENF_CONSOLE_PARSE_FRIEND( VLanId );
65  };
66 
67  std::size_t hash_value(VLanId const& v);
68 
69  typedef std::set<VLanId> VLanIdSet;
70  // careful, this (actually the hash() functions) treats None and id() == 0 as same (untagged)
71  typedef std::unordered_set<VLanId> VLanIdSetFast;
72 
73  std::ostream & operator<<(std::ostream & os, VLanId const & vlanId);
74 
76 }}
77 
78 namespace std {
79  template <>
80  struct hash<senf::emu::VLanId> {
81  size_t operator () (senf::emu::VLanId const & v) const;
82  };
83 }
84 
86 #include "VLanId.cci"
87 //#include "VLanId.ct"
88 //#include "VLanId.cti"
89 #endif
std::size_t hash_value(VLanId const &v)
std::unordered_set< VLanId > VLanIdSetFast
Definition: VLanId.hh:71
std::uint16_t VLanTag
Definition: VLanId.hh:29
static bool hasTag(senf::EthernetPacket const &eth)
STL namespace.
static VLanId const None
Definition: VLanId.hh:35
bool sameTagType(VLanId const &other) const
std::uint16_t id() const
static bool hasSTag(senf::EthernetPacket const &eth)
bool stag() const
static Packet payloadPkt(senf::EthernetPacket const &eth)
static std::uint16_t payloadTypeLength(senf::EthernetPacket const &eth)
VLanId(std::uint16_t id=0, Type type=NoTag)
Definition: VLanId.cc:24
static bool hasCTag(senf::EthernetPacket const &eth)
void senf_console_parse_argument(senf::console::ParseCommandInfo::TokensRange const &tokens, VLanId &vlanId)
Definition: VLanId.cc:42
bool operator==(VLanId const &other) const
std::ostream & operator<<(std::ostream &os, InterfaceDeviceId const &id)
Definition: InterfaceId.cc:105
boost::iterator_range< token_iterator > TokensRange
Type type() const
bool operator<(VLanId const &other) const
ConcretePacket< EthernetPacketType > EthernetPacket
static PKT payload(senf::EthernetPacket const &eth)
std::set< VLanId > VLanIdSet
Definition: VLanId.hh:69
bool ctag() const