VLanId.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 
14 #include "VLanId.hh"
15 
16 // Custom includes
18 
19 #define prefix_
20 
23 
25  : id_(id & 0xfff), type_(type)
26 {
27 }
28 
29 prefix_ std::ostream & senf::emu::operator<<(std::ostream & os, VLanId const & vlanId)
30 {
31  if (vlanId) {
32  os << vlanId.id();
33  if (vlanId.stag())
34  os << "s";
35  }
36  else {
37  os << "None";
38  }
39  return os;
40 }
41 
43 {
44  bool valid (false);
46  try {
48  std::string targ (tokens[0].value());
49  if (targ == "None") {
50  vlanId = VLanId::None;
51  valid = true;
52  } else if (!targ.empty() and targ.back() == 's') {
53  targ.pop_back();
54  type = VLanId::STag;
55  } else {
56  type = VLanId::CTag;
57  }
58  if (type != VLanId::NoTag) {
59  std::uint16_t tmp;
60  senf::console::parse(std::vector<senf::console::Token> ({senf::console::WordToken(targ)}), tmp);
61  if (tmp < 4096) {
62  vlanId = VLanId(tmp, type);
63  valid = true;
64  }
65  }
66  }
67  catch (...) {
68  }
69  if (valid)
70  arg++; // successfully parsed a VLanId
71 }
72 
74 #undef prefix_
u8 type
static VLanId const None
Definition: VLanId.hh:35
std::uint16_t id() const
bool stag() const
VLanId(std::uint16_t id=0, Type type=NoTag)
Definition: VLanId.cc:24
void senf_console_parse_argument(senf::console::ParseCommandInfo::TokensRange const &tokens, VLanId &vlanId)
Definition: VLanId.cc:42
std::ostream & operator<<(std::ostream &os, InterfaceDeviceId const &id)
Definition: InterfaceId.cc:105
boost::iterator_range< token_iterator > TokensRange
Type type() const
#define prefix_
Definition: VLanId.cc:19