vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / extras / vom / vom / types.hpp
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    */
58   VIRTUAL_INTERFACE,
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    */
68   VIRTUAL_TABLE,
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  */
295 struct mac_address_t
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  */
339 struct l2_address_t
340 {
341   l2_address_t(const uint8_t bytes[8], uint8_t n_bytes);
342   l2_address_t(std::initializer_list<uint8_t> bytes);
343   l2_address_t(const mac_address_t& mac);
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 {
388   counter_t()
389     : packets(0)
390     , bytes(0)
391   {
392   }
393   counter_t(const counter_t& c)
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