FD.io VPP  v19.01.1-17-ge106252
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: ON
420  *
421  * Local Variables:
422  * eval: (c-set-style "mozilla")
423  * End:
424  */
425 
426 #endif
static const ethertype_t FCOE
Ethertype FCoE.
Definition: types.hpp:187
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
Global Configuration has no dependency.
A template base class for all enum types.
Definition: enum_base.hpp:30
virtual interfaces - those that depend on some real interface
uint64_t packets
Definition: types.hpp:398
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
static const ethertype_t IPV6
Ethertype Ipv6.
Definition: types.hpp:197
Feature Ethertype.
Definition: types.hpp:167
static const l2_address_t ZERO
An all 0&#39;s L2 address.
Definition: types.hpp:358
static const direction_t INPUT
Permit Direction.
Definition: types.hpp:151
static const handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:268
virtual tables - tables with a dependency on another table
Type def of a L2 address as read from VPP.
Definition: types.hpp:339
static const l2_address_t ONE
An all 1&#39;s L2 address.
Definition: types.hpp:353
Feature Directions.
Definition: types.hpp:136
uint64_t bytes
Definition: types.hpp:399
static const ethertype_t MAC_SECURITY
Ethertype MAC Security.
Definition: types.hpp:202
void to_bytes(const boost::asio::ip::address_v6 &addr, uint8_t *array)
Definition: prefix.cpp:218
static const ethertype_t IPV4
Ethertype IPv4.
Definition: types.hpp:192
static const mac_address_t ONE
An all 1&#39;s MAC address.
Definition: types.hpp:308
counter_t(const counter_t &c)
Definition: types.hpp:393
std::vector< uint8_t > bytes
Underlying bytes array - filled from least to most significant.
Definition: types.hpp:383
u8 len
Definition: ip_types.api:49
svmdb_client_t * c
static const ethertype_t TRILL
Ethertype TRILL.
Definition: types.hpp:212
static const ethertype_t ARP
Ethertype Arp.
Definition: types.hpp:182
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
struct mac_address_t_ mac_address_t
Tables in which entries are added, e.g bridge/route-domains.
std::array< uint8_t, 6 > bytes
Underlying bytes array.
Definition: types.hpp:333
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
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
static const ethertype_t UNSPECIFIED
Ethertype Unspecified.
Definition: types.hpp:217
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
Then L2/objects that bind to interfaces, BD, ACLS, etc.
static const rc_t INVALID
HW write reported invalid input.
Definition: types.hpp:114
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
static const rc_t UNSET
The value un-set.
Definition: types.hpp:99
static const ethertype_t MPLS_UNICAST
Ethertype MPLS unicast.
Definition: types.hpp:207
static const direction_t OUTPUT
Deny Direction.
Definition: types.hpp:156
Entries in Tables.
Type def of a Ethernet address.
Definition: types.hpp:295
static const mac_address_t ZERO
An all 0&#39;s MAC address.
Definition: types.hpp:313
vl_api_mac_address_t mac
Definition: gbp.api:118
static const rc_t TIMEOUT
HW write timedout - VPP did not respond within a timely manner.
Definition: types.hpp:119
interfaces are the root of the dependency graph