FD.io VPP  v18.11-rc0-18-g2a3fb1a
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  * ACLs
67  */
68  ACL,
69 
70  /**
71  * Then L2/objects that bind to interfaces, BD, ACLS, etc
72  */
73  BINDING,
74 
75  /**
76  * Entries in Tables
77  */
78  ENTRY,
79 };
80 
81 /**
82  * Error codes that VPP will return during a HW write
83  */
84 struct rc_t : public enum_base<rc_t>
85 {
86  /**
87  * Destructor
88  */
89  ~rc_t() = default;
90 
91  /**
92  * The value un-set
93  */
94  const static rc_t UNSET;
95 
96  /**
97  * The HW write/update action was/has not been attempted
98  */
99  const static rc_t NOOP;
100 
101  /**
102  * The HW write was successfull
103  */
104  const static rc_t OK;
105 
106  /**
107  * HW write reported invalid input
108  */
109  const static rc_t INVALID;
110 
111  /**
112  * HW write timedout - VPP did not respond within a timely manner
113  */
114  const static rc_t TIMEOUT;
115 
116  /**
117  * Get the rc_t from the VPP API value
118  */
119  static const rc_t& from_vpp_retval(int32_t rv);
120 
121 private:
122  /**
123  * Constructor
124  */
125  rc_t(int v, const std::string s);
126 };
127 
128 /**
129  * Feature Directions
130  */
131 struct direction_t : public enum_base<direction_t>
132 {
133  /**
134  * Constructor
135  */
136  direction_t(int v, const std::string s);
137 
138  /**
139  * Destructor
140  */
141  ~direction_t() = default;
142 
143  /**
144  * Permit Direction
145  */
146  const static direction_t INPUT;
147 
148  /**
149  * Deny Direction
150  */
151  const static direction_t OUTPUT;
152 };
153 
154 /**
155  * Output ostream for direction_t
156  */
157 std::ostream& operator<<(std::ostream& os, const direction_t& dir);
158 
159 /**
160  * Feature Ethertype
161  */
162 struct ethertype_t : public enum_base<ethertype_t>
163 {
164  /**
165  * Constructor
166  */
167  ethertype_t(int v, const std::string s);
168 
169  /**
170  * Destructor
171  */
172  ~ethertype_t() = default;
173 
174  /**
175  * Ethertype Arp
176  */
177  const static ethertype_t ARP;
178 
179  /**
180  * Ethertype FCoE
181  */
182  const static ethertype_t FCOE;
183 
184  /**
185  * Ethertype IPv4
186  */
187  const static ethertype_t IPV4;
188 
189  /**
190  * Ethertype Ipv6
191  */
192  const static ethertype_t IPV6;
193 
194  /**
195  * Ethertype MAC Security
196  */
197  const static ethertype_t MAC_SECURITY;
198 
199  /**
200  * Ethertype MPLS unicast
201  */
202  const static ethertype_t MPLS_UNICAST;
203 
204  /**
205  * Ethertype TRILL
206  */
207  const static ethertype_t TRILL;
208 
209  /**
210  * Ethertype Unspecified
211  */
212  const static ethertype_t UNSPECIFIED;
213 
214  /**
215  * Get the ethertype from the numeric value
216  */
217  static const ethertype_t& from_numeric_val(uint16_t numeric);
218 };
219 
220 /**
221  * Output ostream for ethertype_t
222  */
223 std::ostream& operator<<(std::ostream& os, const ethertype_t& eth);
224 
225 /**
226  * A type declaration of an interface handle in VPP
227  */
228 struct handle_t
229 {
230  /**
231  * Constructor
232  */
233  handle_t(int value);
234 
235  /**
236  * Constructor
237  */
238  handle_t();
239 
240  /**
241  * convert to string format for debug purposes
242  */
243  std::string to_string() const;
244 
245  /**
246  * Comparison operator
247  */
248  bool operator==(const handle_t& other) const;
249 
250  /**
251  * Comparison operator
252  */
253  bool operator!=(const handle_t& other) const;
254 
255  /**
256  * less than operator
257  */
258  bool operator<(const handle_t& other) const;
259 
260  /**
261  * A value of an interface handle_t that means the itf does not exist
262  */
263  const static handle_t INVALID;
264 
265  /**
266  * get the value of the handle
267  */
268  uint32_t value() const;
269 
270  /**
271  * reset the value of the handle to ~0
272  */
273  void reset();
274 
275 private:
276  /**
277  * VPP's handle value
278  */
279  uint32_t m_value;
280 };
281 
282 /**
283  * ostream print of a handle_t
284  */
285 std::ostream& operator<<(std::ostream& os, const handle_t& h);
286 
287 /**
288  * Type def of a Ethernet address
289  */
291 {
292  mac_address_t(uint8_t bytes[6]);
293  mac_address_t(const std::string& str);
294  mac_address_t(std::initializer_list<uint8_t> bytes);
295  /**
296  * Convert to byte array
297  */
298  void to_bytes(uint8_t* array, uint8_t len) const;
299 
300  /**
301  * An all 1's MAC address
302  */
303  const static mac_address_t ONE;
304 
305  /**
306  * An all 0's MAC address
307  */
308  const static mac_address_t ZERO;
309 
310  /**
311  * Comparison operator
312  */
313  bool operator==(const mac_address_t& m) const;
314 
315  /**
316  * less than operator
317  */
318  bool operator<(const mac_address_t& m) const;
319 
320  /**
321  * String conversion
322  */
323  std::string to_string() const;
324 
325  /**
326  * Underlying bytes array
327  */
328  std::array<uint8_t, 6> bytes;
329 };
330 
331 /**
332  * Type def of a L2 address as read from VPP
333  */
335 {
336  l2_address_t(const uint8_t bytes[8], uint8_t n_bytes);
337  l2_address_t(std::initializer_list<uint8_t> bytes);
338  l2_address_t(const mac_address_t& mac);
339 
340  /**
341  * Convert to byte array
342  */
343  void to_bytes(uint8_t* array, uint8_t len) const;
344 
345  /**
346  * An all 1's L2 address
347  */
348  const static l2_address_t ONE;
349 
350  /**
351  * An all 0's L2 address
352  */
353  const static l2_address_t ZERO;
354 
355  /**
356  * Comparison operator
357  */
358  bool operator==(const l2_address_t& m) const;
359 
360  /**
361  * Comparison operator
362  */
363  bool operator!=(const l2_address_t& m) const;
364 
365  /**
366  * String conversion
367  */
368  std::string to_string() const;
369 
370  /**
371  * MAC address conversion
372  */
373  mac_address_t to_mac() const;
374 
375  /**
376  * Underlying bytes array - filled from least to most significant
377  */
378  std::vector<uint8_t> bytes;
379 };
380 
381 /**
382  * Ostream operator for a MAC address
383  */
384 std::ostream& operator<<(std::ostream& os, const mac_address_t& mac);
385 
386 /**
387  * Ostream operator for a MAC address
388  */
389 std::ostream& operator<<(std::ostream& os, const l2_address_t& l2);
390 };
391 
392 /*
393  * fd.io coding-style-patch-verification: ON
394  *
395  * Local Variables:
396  * eval: (c-set-style "mozilla")
397  * End:
398  */
399 
400 #endif
static const ethertype_t FCOE
Ethertype FCoE.
Definition: types.hpp:182
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:99
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
Error codes that VPP will return during a HW write.
Definition: types.hpp:84
static const ethertype_t IPV6
Ethertype Ipv6.
Definition: types.hpp:192
Feature Ethertype.
Definition: types.hpp:162
static const l2_address_t ZERO
An all 0&#39;s L2 address.
Definition: types.hpp:353
static const direction_t INPUT
Permit Direction.
Definition: types.hpp:146
static const handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:263
Type def of a L2 address as read from VPP.
Definition: types.hpp:334
static const l2_address_t ONE
An all 1&#39;s L2 address.
Definition: types.hpp:348
Feature Directions.
Definition: types.hpp:131
static const ethertype_t MAC_SECURITY
Ethertype MAC Security.
Definition: types.hpp:197
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:187
static const mac_address_t ONE
An all 1&#39;s MAC address.
Definition: types.hpp:303
#define v
Definition: acl.c:491
std::vector< uint8_t > bytes
Underlying bytes array - filled from least to most significant.
Definition: types.hpp:378
static const ethertype_t TRILL
Ethertype TRILL.
Definition: types.hpp:207
static const ethertype_t ARP
Ethertype Arp.
Definition: types.hpp:177
A type declaration of an interface handle in VPP.
Definition: types.hpp:228
Tables in which entries are added, e.g bridge/route-domains.
std::array< uint8_t, 6 > bytes
Underlying bytes array.
Definition: types.hpp:328
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:104
static const ethertype_t UNSPECIFIED
Ethertype Unspecified.
Definition: types.hpp:212
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:109
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
static const rc_t UNSET
The value un-set.
Definition: types.hpp:94
static const ethertype_t MPLS_UNICAST
Ethertype MPLS unicast.
Definition: types.hpp:202
static const direction_t OUTPUT
Deny Direction.
Definition: types.hpp:151
Entries in Tables.
Type def of a Ethernet address.
Definition: types.hpp:290
static const mac_address_t ZERO
An all 0&#39;s MAC address.
Definition: types.hpp:308
static const rc_t TIMEOUT
HW write timedout - VPP did not respond within a timely manner.
Definition: types.hpp:114
interfaces are the root of the dependency graph