FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
types.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __VOM_TYPES_H__
17 #define __VOM_TYPES_H__
18 
19 #include <array>
20 #include <vector>
21 
22 #include <boost/asio/ip/address.hpp>
23 
24 #include "vom/enum_base.hpp"
25 
26 /**
27  * Convenince wrapper macro for error handling in VAPI sends
28  */
29 #define VAPI_CALL(_stmt) \
30  { \
31  vapi_error_e _rv; \
32  do { \
33  _rv = (_stmt); \
34  } while (VAPI_OK != _rv); \
35  }
36 
37 namespace VOM {
38 /**
39  * There needs to be a strict order in which object types are read from VPP
40  * (at boot time) and replayed to VPP (if VPP restarts). That ordering is
41  * defined in this enum types
42  */
43 enum class dependency_t
44 {
45  /**
46  * Global Configuration has no dependency
47  */
48  GLOBAL = 0,
49 
50  /**
51  * interfaces are the root of the dependency graph
52  */
53  INTERFACE,
54 
55  /**
56  * virtual interfaces - those that depend on some real interface
57  */
59 
60  /**
61  * Tables in which entries are added, e.g bridge/route-domains
62  */
63  TABLE,
64 
65  /**
66  * virtual tables - tables with a dependency on another table
67  */
69 
70  /**
71  * ACLs
72  */
73  ACL,
74 
75  /**
76  * Then L2/objects that bind to interfaces, BD, ACLS, etc
77  */
78  BINDING,
79 
80  /**
81  * Entries in Tables
82  */
83  ENTRY,
84 };
85 
86 /**
87  * Error codes that VPP will return during a HW write
88  */
89 struct rc_t : public enum_base<rc_t>
90 {
91  /**
92  * Destructor
93  */
94  ~rc_t() = default;
95 
96  /**
97  * The value un-set
98  */
99  const static rc_t UNSET;
100 
101  /**
102  * The HW write/update action was/has not been attempted
103  */
104  const static rc_t NOOP;
105 
106  /**
107  * The HW write was successfull
108  */
109  const static rc_t OK;
110 
111  /**
112  * HW write reported invalid input
113  */
114  const static rc_t INVALID;
115 
116  /**
117  * HW write timedout - VPP did not respond within a timely manner
118  */
119  const static rc_t TIMEOUT;
120 
121  /**
122  * Get the rc_t from the VPP API value
123  */
124  static const rc_t& from_vpp_retval(int32_t rv);
125 
126 private:
127  /**
128  * Constructor
129  */
130  rc_t(int v, const std::string s);
131 };
132 
133 /**
134  * Feature Directions
135  */
136 struct direction_t : public enum_base<direction_t>
137 {
138  /**
139  * Constructor
140  */
141  direction_t(int v, const std::string s);
142 
143  /**
144  * Destructor
145  */
146  ~direction_t() = default;
147 
148  /**
149  * Permit Direction
150  */
151  const static direction_t INPUT;
152 
153  /**
154  * Deny Direction
155  */
156  const static direction_t OUTPUT;
157 };
158 
159 /**
160  * Output ostream for direction_t
161  */
162 std::ostream& operator<<(std::ostream& os, const direction_t& dir);
163 
164 /**
165  * Feature Ethertype
166  */
167 struct ethertype_t : public enum_base<ethertype_t>
168 {
169  /**
170  * Constructor
171  */
172  ethertype_t(int v, const std::string s);
173 
174  /**
175  * Destructor
176  */
177  ~ethertype_t() = default;
178 
179  /**
180  * Ethertype Arp
181  */
182  const static ethertype_t ARP;
183 
184  /**
185  * Ethertype FCoE
186  */
187  const static ethertype_t FCOE;
188 
189  /**
190  * Ethertype IPv4
191  */
192  const static ethertype_t IPV4;
193 
194  /**
195  * Ethertype Ipv6
196  */
197  const static ethertype_t IPV6;
198 
199  /**
200  * Ethertype MAC Security
201  */
202  const static ethertype_t MAC_SECURITY;
203 
204  /**
205  * Ethertype MPLS unicast
206  */
207  const static ethertype_t MPLS_UNICAST;
208 
209  /**
210  * Ethertype TRILL
211  */
212  const static ethertype_t TRILL;
213 
214  /**
215  * Ethertype Unspecified
216  */
217  const static ethertype_t UNSPECIFIED;
218 
219  /**
220  * Get the ethertype from the numeric value
221  */
222  static const ethertype_t& from_numeric_val(uint16_t numeric);
223 };
224 
225 /**
226  * Output ostream for ethertype_t
227  */
228 std::ostream& operator<<(std::ostream& os, const ethertype_t& eth);
229 
230 /**
231  * A type declaration of an interface handle in VPP
232  */
233 struct handle_t
234 {
235  /**
236  * Constructor
237  */
238  handle_t(int value);
239 
240  /**
241  * Constructor
242  */
243  handle_t();
244 
245  /**
246  * convert to string format for debug purposes
247  */
248  std::string to_string() const;
249 
250  /**
251  * Comparison operator
252  */
253  bool operator==(const handle_t& other) const;
254 
255  /**
256  * Comparison operator
257  */
258  bool operator!=(const handle_t& other) const;
259 
260  /**
261  * less than operator
262  */
263  bool operator<(const handle_t& other) const;
264 
265  /**
266  * A value of an interface handle_t that means the itf does not exist
267  */
268  const static handle_t INVALID;
269 
270  /**
271  * get the value of the handle
272  */
273  uint32_t value() const;
274 
275  /**
276  * reset the value of the handle to ~0
277  */
278  void reset();
279 
280 private:
281  /**
282  * VPP's handle value
283  */
284  uint32_t m_value;
285 };
286 
287 /**
288  * ostream print of a handle_t
289  */
290 std::ostream& operator<<(std::ostream& os, const handle_t& h);
291 
292 /**
293  * Type def of a Ethernet address
294  */
296 {
297  mac_address_t(const uint8_t bytes[6]);
298  mac_address_t(const std::string& str);
299  mac_address_t(std::initializer_list<uint8_t> bytes);
300  /**
301  * Convert to byte array
302  */
303  void to_bytes(uint8_t* array, uint8_t len) const;
304 
305  /**
306  * An all 1's MAC address
307  */
308  const static mac_address_t ONE;
309 
310  /**
311  * An all 0's MAC address
312  */
313  const static mac_address_t ZERO;
314 
315  /**
316  * Comparison operator
317  */
318  bool operator==(const mac_address_t& m) const;
319 
320  /**
321  * less than operator
322  */
323  bool operator<(const mac_address_t& m) const;
324 
325  /**
326  * String conversion
327  */
328  std::string to_string() const;
329 
330  /**
331  * Underlying bytes array
332  */
333  std::array<uint8_t, 6> bytes;
334 };
335 
336 /**
337  * Type def of a L2 address as read from VPP
338  */
340 {
341  l2_address_t(const uint8_t bytes[8], uint8_t n_bytes);
342  l2_address_t(std::initializer_list<uint8_t> bytes);
344 
345  /**
346  * Convert to byte array
347  */
348  void to_bytes(uint8_t* array, uint8_t len) const;
349 
350  /**
351  * An all 1's L2 address
352  */
353  const static l2_address_t ONE;
354 
355  /**
356  * An all 0's L2 address
357  */
358  const static l2_address_t ZERO;
359 
360  /**
361  * Comparison operator
362  */
363  bool operator==(const l2_address_t& m) const;
364 
365  /**
366  * Comparison operator
367  */
368  bool operator!=(const l2_address_t& m) const;
369 
370  /**
371  * String conversion
372  */
373  std::string to_string() const;
374 
375  /**
376  * MAC address conversion
377  */
378  mac_address_t to_mac() const;
379 
380  /**
381  * Underlying bytes array - filled from least to most significant
382  */
383  std::vector<uint8_t> bytes;
384 };
385 
386 struct counter_t
387 {
389  : packets(0)
390  , bytes(0)
391  {
392  }
394  : packets(c.packets)
395  , bytes(c.bytes)
396  {
397  }
398  uint64_t packets;
399  uint64_t bytes;
400 };
401 
402 /**
403  * Ostream operator for a MAC address
404  */
405 std::ostream& operator<<(std::ostream& os, const mac_address_t& mac);
406 
407 /**
408  * Ostream operator for a MAC address
409  */
410 std::ostream& operator<<(std::ostream& os, const l2_address_t& l2);
411 
412 /**
413  * Ostream operator for a MAC address
414  */
415 std::ostream& operator<<(std::ostream& os, const counter_t& c);
416 };
417 
418 /*
419  * fd.io coding-style-patch-verification: OFF
420  *
421  * Local Variables:
422  * eval: (c-set-style "mozilla")
423  * End:
424  */
425 
426 #endif
VOM::ethertype_t::MPLS_UNICAST
const static ethertype_t MPLS_UNICAST
Ethertype MPLS unicast.
Definition: types.hpp:207
VOM::ethertype_t::~ethertype_t
~ethertype_t()=default
Destructor.
mac
vl_api_mac_address_t mac
Definition: l2.api:559
VOM::l2_address_t::ZERO
const static l2_address_t ZERO
An all 0's L2 address.
Definition: types.hpp:358
VOM::dependency_t::VIRTUAL_TABLE
@ VIRTUAL_TABLE
virtual tables - tables with a dependency on another table
VOM::l2_address_t::to_mac
mac_address_t to_mac() const
MAC address conversion.
Definition: types.cpp:216
VOM::ethertype_t
Feature Ethertype.
Definition: types.hpp:167
VOM::direction_t::~direction_t
~direction_t()=default
Destructor.
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::mac_address_t::ZERO
const static mac_address_t ZERO
An all 0's MAC address.
Definition: types.hpp:313
VOM::dependency_t
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
Definition: types.hpp:43
VOM::mac_address_t::operator<
bool operator<(const mac_address_t &m) const
less than operator
Definition: types.cpp:172
VOM::l2_address_t::bytes
std::vector< uint8_t > bytes
Underlying bytes array - filled from least to most significant.
Definition: types.hpp:383
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::rc_t::from_vpp_retval
static const rc_t & from_vpp_retval(int32_t rv)
Get the rc_t from the VPP API value.
Definition: types.cpp:33
VOM::l2_address_t::to_bytes
void to_bytes(uint8_t *array, uint8_t len) const
Convert to byte array.
Definition: types.cpp:208
VOM::handle_t::reset
void reset()
reset the value of the handle to ~0
Definition: types.cpp:99
VOM::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::ethertype_t::ethertype_t
ethertype_t(int v, const std::string s)
Constructor.
Definition: types.cpp:287
VOM::ethertype_t::UNSPECIFIED
const static ethertype_t UNSPECIFIED
Ethertype Unspecified.
Definition: types.hpp:217
VOM::dependency_t::ENTRY
@ ENTRY
Entries in Tables.
VOM::counter_t::counter_t
counter_t()
Definition: types.hpp:388
VOM::handle_t::operator==
bool operator==(const handle_t &other) const
Comparison operator.
Definition: types.cpp:75
h
h
Definition: flowhash_template.h:372
VOM::rc_t::UNSET
const static rc_t UNSET
The value un-set.
Definition: types.hpp:99
len
u8 len
Definition: ip_types.api:103
VOM::mac_address_t::operator==
bool operator==(const mac_address_t &m) const
Comparison operator.
Definition: types.cpp:167
VOM::ethertype_t::from_numeric_val
static const ethertype_t & from_numeric_val(uint16_t numeric)
Get the ethertype from the numeric value.
Definition: types.cpp:300
VOM::handle_t::operator<
bool operator<(const handle_t &other) const
less than operator
Definition: types.cpp:87
VOM::ethertype_t::IPV6
const static ethertype_t IPV6
Ethertype Ipv6.
Definition: types.hpp:197
enum_base.hpp
VOM::mac_address_t::to_bytes
void to_bytes(uint8_t *array, uint8_t len) const
Convert to byte array.
Definition: types.cpp:140
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
VOM::enum_base
A template base class for all enum types.
Definition: enum_base.hpp:30
VOM::direction_t::OUTPUT
const static direction_t OUTPUT
Deny Direction.
Definition: types.hpp:156
VOM::l2_address_t::to_string
std::string to_string() const
String conversion.
Definition: types.cpp:226
VOM::rc_t::NOOP
const static rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
VOM::rc_t::TIMEOUT
const static rc_t TIMEOUT
HW write timedout - VPP did not respond within a timely manner.
Definition: types.hpp:119
VOM::counter_t::bytes
uint64_t bytes
Definition: types.hpp:399
VOM::ethertype_t::IPV4
const static ethertype_t IPV4
Ethertype IPv4.
Definition: types.hpp:192
VOM::direction_t::INPUT
const static direction_t INPUT
Permit Direction.
Definition: types.hpp:151
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::rc_t::INVALID
const static rc_t INVALID
HW write reported invalid input.
Definition: types.hpp:114
VOM::l2_address_t::operator!=
bool operator!=(const l2_address_t &m) const
Comparison operator.
Definition: types.cpp:251
VOM::dependency_t::TABLE
@ TABLE
Tables in which entries are added, e.g bridge/route-domains.
VOM::operator<<
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
Definition: acl_binding.cpp:201
VOM::ethertype_t::FCOE
const static ethertype_t FCOE
Ethertype FCoE.
Definition: types.hpp:187
VOM::mac_address_t::ONE
const static mac_address_t ONE
An all 1's MAC address.
Definition: types.hpp:308
VOM::counter_t
Definition: types.hpp:386
VOM::mac_address_t::mac_address_t
mac_address_t(const uint8_t bytes[6])
Definition: types.cpp:112
VOM::l2_address_t::ONE
const static l2_address_t ONE
An all 1's L2 address.
Definition: types.hpp:353
VOM::l2_address_t::l2_address_t
l2_address_t(const uint8_t bytes[8], uint8_t n_bytes)
Definition: types.cpp:185
VOM::l2_address_t
Type def of a L2 address as read from VPP.
Definition: types.hpp:339
VOM::handle_t::handle_t
handle_t()
Constructor.
Definition: types.cpp:63
VOM::handle_t::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: types.cpp:69
VOM::dependency_t::VIRTUAL_INTERFACE
@ VIRTUAL_INTERFACE
virtual interfaces - those that depend on some real interface
VOM::dependency_t::INTERFACE
@ INTERFACE
interfaces are the root of the dependency graph
n_bytes
u32 n_bytes
Definition: interface_output.c:401
VOM::mac_address_t::to_string
std::string to_string() const
String conversion.
Definition: types.cpp:148
VOM::mac_address_t
Type def of a Ethernet address.
Definition: types.hpp:295
VOM::handle_t::INVALID
const static handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:268
VOM::l2_address_t::operator==
bool operator==(const l2_address_t &m) const
Comparison operator.
Definition: types.cpp:245
VOM::ethertype_t::ARP
const static ethertype_t ARP
Ethertype Arp.
Definition: types.hpp:182
VOM::direction_t
Feature Directions.
Definition: types.hpp:136
VOM::dependency_t::BINDING
@ BINDING
Then L2/objects that bind to interfaces, BD, ACLS, etc.
rv
int __clib_unused rv
Definition: application.c:491
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::handle_t::operator!=
bool operator!=(const handle_t &other) const
Comparison operator.
Definition: types.cpp:81
VOM::counter_t::counter_t
counter_t(const counter_t &c)
Definition: types.hpp:393
VOM::counter_t::packets
uint64_t packets
Definition: types.hpp:398
VOM::ethertype_t::TRILL
const static ethertype_t TRILL
Ethertype TRILL.
Definition: types.hpp:212
VOM::rc_t::~rc_t
~rc_t()=default
Destructor.
VOM::direction_t::direction_t
direction_t(int v, const std::string s)
Constructor.
Definition: types.cpp:267
VOM::dependency_t::GLOBAL
@ GLOBAL
Global Configuration has no dependency.
VOM::mac_address_t::bytes
std::array< uint8_t, 6 > bytes
Underlying bytes array.
Definition: types.hpp:333
VOM::dependency_t::ACL
@ ACL
ACLs.
string
const char *const string
Definition: cJSON.h:172
VOM::ethertype_t::MAC_SECURITY
const static ethertype_t MAC_SECURITY
Ethertype MAC Security.
Definition: types.hpp:202