FD.io VPP  v18.01-8-g0eacf49
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  * Tunnel or virtual interfaces next
57  */
58  TUNNEL,
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  rc_t(const rc_t& rc) = default;
87 
88  /**
89  * Destructor
90  */
91  ~rc_t();
92 
93  /**
94  * The value un-set
95  */
96  const static rc_t UNSET;
97 
98  /**
99  * The HW write/update action was/has not been attempted
100  */
101  const static rc_t NOOP;
102 
103  /**
104  * The HW write was successfull
105  */
106  const static rc_t OK;
107 
108  /**
109  * HW write reported invalid input
110  */
111  const static rc_t INVALID;
112 
113  /**
114  * HW write timedout - VPP did not respond within a timely manner
115  */
116  const static rc_t TIMEOUT;
117 
118  /**
119  * Get the rc_t from the VPP API value
120  */
121  static const rc_t& from_vpp_retval(int32_t rv);
122 
123 private:
124  /**
125  * Constructor
126  */
127  rc_t(int v, const std::string s);
128 };
129 
130 /**
131  * Feature Directions
132  */
133 struct direction_t : public enum_base<direction_t>
134 {
135  /**
136  * Constructor
137  */
138  direction_t(int v, const std::string s);
139 
140  /**
141  * Destructor
142  */
143  ~direction_t() = default;
144 
145  /**
146  * Permit Direction
147  */
148  const static direction_t INPUT;
149 
150  /**
151  * Deny Direction
152  */
153  const static direction_t OUTPUT;
154 };
155 
156 /**
157  * Output ostream for direction_t
158  */
159 std::ostream& operator<<(std::ostream& os, const direction_t& dir);
160 
161 /**
162  * A type declaration of an interface handle in VPP
163  */
164 struct handle_t
165 {
166  /**
167  * Constructor
168  */
169  handle_t(int value);
170 
171  /**
172  * Constructor
173  */
174  handle_t();
175 
176  /**
177  * convert to string format for debug purposes
178  */
179  std::string to_string() const;
180 
181  /**
182  * Comparison operator
183  */
184  bool operator==(const handle_t& other) const;
185 
186  /**
187  * Comparison operator
188  */
189  bool operator!=(const handle_t& other) const;
190 
191  /**
192  * less than operator
193  */
194  bool operator<(const handle_t& other) const;
195 
196  /**
197  * A value of an interface handle_t that means the itf does not exist
198  */
199  const static handle_t INVALID;
200 
201  /**
202  * get the value of the handle
203  */
204  uint32_t value() const;
205 
206 private:
207  /**
208  * VPP's handle value
209  */
210  uint32_t m_value;
211 };
212 
213 /**
214  * ostream print of a handle_t
215  */
216 std::ostream& operator<<(std::ostream& os, const handle_t& h);
217 
218 /**
219  * Type def of a Ethernet address
220  */
222 {
223  mac_address_t(uint8_t bytes[6]);
224  mac_address_t(const std::string& str);
225  mac_address_t(std::initializer_list<uint8_t> bytes);
226  /**
227  * Convert to byte array
228  */
229  void to_bytes(uint8_t* array, uint8_t len) const;
230 
231  /**
232  * An all 1's MAC address
233  */
234  const static mac_address_t ONE;
235 
236  /**
237  * An all 0's MAC address
238  */
239  const static mac_address_t ZERO;
240 
241  /**
242  * Comparison operator
243  */
244  bool operator==(const mac_address_t& m) const;
245 
246  /**
247  * less than operator
248  */
249  bool operator<(const mac_address_t& m) const;
250 
251  /**
252  * String conversion
253  */
254  std::string to_string() const;
255 
256  /**
257  * Underlying bytes array
258  */
259  std::array<uint8_t, 6> bytes;
260 };
261 
262 /**
263  * Type def of a L2 address as read from VPP
264  */
266 {
267  l2_address_t(const uint8_t bytes[8], uint8_t n_bytes);
268  l2_address_t(std::initializer_list<uint8_t> bytes);
269  l2_address_t(const mac_address_t& mac);
270 
271  /**
272  * Convert to byte array
273  */
274  void to_bytes(uint8_t* array, uint8_t len) const;
275 
276  /**
277  * An all 1's L2 address
278  */
279  const static l2_address_t ONE;
280 
281  /**
282  * An all 0's L2 address
283  */
284  const static l2_address_t ZERO;
285 
286  /**
287  * Comparison operator
288  */
289  bool operator==(const l2_address_t& m) const;
290 
291  /**
292  * Comparison operator
293  */
294  bool operator!=(const l2_address_t& m) const;
295 
296  /**
297  * String conversion
298  */
299  std::string to_string() const;
300 
301  /**
302  * MAC address conversion
303  */
304  mac_address_t to_mac() const;
305 
306  /**
307  * Underlying bytes array - filled from least to most significant
308  */
309  std::vector<uint8_t> bytes;
310 };
311 
312 /**
313  * Ostream operator for a MAC address
314  */
315 std::ostream& operator<<(std::ostream& os, const mac_address_t& mac);
316 
317 /**
318  * Ostream operator for a MAC address
319  */
320 std::ostream& operator<<(std::ostream& os, const l2_address_t& l2);
321 };
322 
323 /*
324  * fd.io coding-style-patch-verification: ON
325  *
326  * Local Variables:
327  * eval: (c-set-style "mozilla")
328  * End:
329  */
330 
331 #endif
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:101
Global Configuration has no dependency.
A template base class for all enum types.
Definition: enum_base.hpp:30
Error codes that VPP will return during a HW write.
Definition: types.hpp:84
static const l2_address_t ZERO
An all 0&#39;s L2 address.
Definition: types.hpp:284
static const direction_t INPUT
Permit Direction.
Definition: types.hpp:148
static const handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:199
Tunnel or virtual interfaces next.
Type def of a L2 address as read from VPP.
Definition: types.hpp:265
static const l2_address_t ONE
An all 1&#39;s L2 address.
Definition: types.hpp:279
Feature Directions.
Definition: types.hpp:133
void to_bytes(const boost::asio::ip::address_v6 &addr, uint8_t *array)
Definition: prefix.cpp:205
static const mac_address_t ONE
An all 1&#39;s MAC address.
Definition: types.hpp:234
#define v
Definition: acl.c:341
std::vector< uint8_t > bytes
Underlying bytes array - filled from least to most significant.
Definition: types.hpp:309
vec_header_t h
Definition: buffer.c:282
A type declaration of an interface handle in VPP.
Definition: types.hpp:164
Tables in which entries are added, e.g bridge/route-domains.
std::array< uint8_t, 6 > bytes
Underlying bytes array.
Definition: types.hpp:259
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:106
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:111
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
static const rc_t UNSET
The value un-set.
Definition: types.hpp:96
static const direction_t OUTPUT
Deny Direction.
Definition: types.hpp:153
Entries in Tables.
Type def of a Ethernet address.
Definition: types.hpp:221
static const mac_address_t ZERO
An all 0&#39;s MAC address.
Definition: types.hpp:239
static const rc_t TIMEOUT
HW write timedout - VPP did not respond within a timely manner.
Definition: types.hpp:116
interfaces are the root of the dependency graph