VOM: ACL: Add Object Model for acl ethertype
[vpp.git] / src / vpp-api / 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    * 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  * Feature Ethertype
163  */
164 struct ethertype_t : public enum_base<ethertype_t>
165 {
166   /**
167    * Constructor
168    */
169   ethertype_t(int v, const std::string s);
170
171   /**
172    * Destructor
173    */
174   ~ethertype_t() = default;
175
176   /**
177    * Ethertype Arp
178    */
179   const static ethertype_t ARP;
180
181   /**
182    * Ethertype FCoE
183    */
184   const static ethertype_t FCOE;
185
186   /**
187    * Ethertype IPv4
188    */
189   const static ethertype_t IPV4;
190
191   /**
192    * Ethertype Ipv6
193    */
194   const static ethertype_t IPV6;
195
196   /**
197    * Ethertype MAC Security
198    */
199   const static ethertype_t MAC_SECURITY;
200
201   /**
202    * Ethertype MPLS unicast
203    */
204   const static ethertype_t MPLS_UNICAST;
205
206   /**
207    * Ethertype TRILL
208    */
209   const static ethertype_t TRILL;
210
211   /**
212    * Ethertype Unspecified
213    */
214   const static ethertype_t UNSPECIFIED;
215
216   /**
217    * Get the ethertype from the numeric value
218    */
219   static const ethertype_t& from_numeric_val(uint16_t numeric);
220 };
221
222 /**
223  * Output ostream for ethertype_t
224  */
225 std::ostream& operator<<(std::ostream& os, const ethertype_t& eth);
226
227 /**
228  * A type declaration of an interface handle in VPP
229  */
230 struct handle_t
231 {
232   /**
233    * Constructor
234    */
235   handle_t(int value);
236
237   /**
238    * Constructor
239    */
240   handle_t();
241
242   /**
243    * convert to string format for debug purposes
244    */
245   std::string to_string() const;
246
247   /**
248    * Comparison operator
249    */
250   bool operator==(const handle_t& other) const;
251
252   /**
253    * Comparison operator
254    */
255   bool operator!=(const handle_t& other) const;
256
257   /**
258    * less than operator
259    */
260   bool operator<(const handle_t& other) const;
261
262   /**
263    * A value of an interface handle_t that means the itf does not exist
264    */
265   const static handle_t INVALID;
266
267   /**
268    * get the value of the handle
269    */
270   uint32_t value() const;
271
272   /**
273    * reset the value of the handle to ~0
274    */
275   void reset();
276
277 private:
278   /**
279    * VPP's handle value
280    */
281   uint32_t m_value;
282 };
283
284 /**
285  * ostream print of a handle_t
286  */
287 std::ostream& operator<<(std::ostream& os, const handle_t& h);
288
289 /**
290  * Type def of a Ethernet address
291  */
292 struct mac_address_t
293 {
294   mac_address_t(uint8_t bytes[6]);
295   mac_address_t(const std::string& str);
296   mac_address_t(std::initializer_list<uint8_t> bytes);
297   /**
298    * Convert to byte array
299    */
300   void to_bytes(uint8_t* array, uint8_t len) const;
301
302   /**
303    * An all 1's MAC address
304    */
305   const static mac_address_t ONE;
306
307   /**
308    * An all 0's MAC address
309    */
310   const static mac_address_t ZERO;
311
312   /**
313    * Comparison operator
314    */
315   bool operator==(const mac_address_t& m) const;
316
317   /**
318    * less than operator
319    */
320   bool operator<(const mac_address_t& m) const;
321
322   /**
323    * String conversion
324    */
325   std::string to_string() const;
326
327   /**
328    * Underlying bytes array
329    */
330   std::array<uint8_t, 6> bytes;
331 };
332
333 /**
334  * Type def of a L2 address as read from VPP
335  */
336 struct l2_address_t
337 {
338   l2_address_t(const uint8_t bytes[8], uint8_t n_bytes);
339   l2_address_t(std::initializer_list<uint8_t> bytes);
340   l2_address_t(const mac_address_t& mac);
341
342   /**
343    * Convert to byte array
344    */
345   void to_bytes(uint8_t* array, uint8_t len) const;
346
347   /**
348    * An all 1's L2 address
349    */
350   const static l2_address_t ONE;
351
352   /**
353    * An all 0's L2 address
354    */
355   const static l2_address_t ZERO;
356
357   /**
358    * Comparison operator
359    */
360   bool operator==(const l2_address_t& m) const;
361
362   /**
363    * Comparison operator
364    */
365   bool operator!=(const l2_address_t& m) const;
366
367   /**
368    * String conversion
369    */
370   std::string to_string() const;
371
372   /**
373    * MAC address conversion
374    */
375   mac_address_t to_mac() const;
376
377   /**
378    * Underlying bytes array - filled from least to most significant
379    */
380   std::vector<uint8_t> bytes;
381 };
382
383 /**
384  * Ostream operator for a MAC address
385  */
386 std::ostream& operator<<(std::ostream& os, const mac_address_t& mac);
387
388 /**
389  * Ostream operator for a MAC address
390  */
391 std::ostream& operator<<(std::ostream& os, const l2_address_t& l2);
392 };
393
394 /*
395  * fd.io coding-style-patch-verification: ON
396  *
397  * Local Variables:
398  * eval: (c-set-style "mozilla")
399  * End:
400  */
401
402 #endif