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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __VOM_TYPES_H__
17 #define __VOM_TYPES_H__
22 #include <boost/asio/ip/address.hpp>
24 #include "vom/enum_base.hpp"
27 * Convenince wrapper macro for error handling in VAPI sends
29 #define VAPI_CALL(_stmt) \
34 } while (VAPI_OK != _rv); \
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
43 enum class dependency_t
46 * Global Configuration has no dependency
51 * interfaces are the root of the dependency graph
56 * virtual interfaces - those that depend on some real interface
61 * Tables in which entries are added, e.g bridge/route-domains
66 * virtual tables - tables with a dependency on another table
76 * Then L2/objects that bind to interfaces, BD, ACLS, etc
87 * Error codes that VPP will return during a HW write
89 struct rc_t : public enum_base<rc_t>
99 const static rc_t UNSET;
102 * The HW write/update action was/has not been attempted
104 const static rc_t NOOP;
107 * The HW write was successfull
109 const static rc_t OK;
112 * HW write reported invalid input
114 const static rc_t INVALID;
117 * HW write timedout - VPP did not respond within a timely manner
119 const static rc_t TIMEOUT;
122 * Get the rc_t from the VPP API value
124 static const rc_t& from_vpp_retval(int32_t rv);
130 rc_t(int v, const std::string s);
136 struct direction_t : public enum_base<direction_t>
141 direction_t(int v, const std::string s);
146 ~direction_t() = default;
151 const static direction_t INPUT;
156 const static direction_t OUTPUT;
160 * Output ostream for direction_t
162 std::ostream& operator<<(std::ostream& os, const direction_t& dir);
167 struct ethertype_t : public enum_base<ethertype_t>
172 ethertype_t(int v, const std::string s);
177 ~ethertype_t() = default;
182 const static ethertype_t ARP;
187 const static ethertype_t FCOE;
192 const static ethertype_t IPV4;
197 const static ethertype_t IPV6;
200 * Ethertype MAC Security
202 const static ethertype_t MAC_SECURITY;
205 * Ethertype MPLS unicast
207 const static ethertype_t MPLS_UNICAST;
212 const static ethertype_t TRILL;
215 * Ethertype Unspecified
217 const static ethertype_t UNSPECIFIED;
220 * Get the ethertype from the numeric value
222 static const ethertype_t& from_numeric_val(uint16_t numeric);
226 * Output ostream for ethertype_t
228 std::ostream& operator<<(std::ostream& os, const ethertype_t& eth);
231 * A type declaration of an interface handle in VPP
246 * convert to string format for debug purposes
248 std::string to_string() const;
251 * Comparison operator
253 bool operator==(const handle_t& other) const;
256 * Comparison operator
258 bool operator!=(const handle_t& other) const;
263 bool operator<(const handle_t& other) const;
266 * A value of an interface handle_t that means the itf does not exist
268 const static handle_t INVALID;
271 * get the value of the handle
273 uint32_t value() const;
276 * reset the value of the handle to ~0
288 * ostream print of a handle_t
290 std::ostream& operator<<(std::ostream& os, const handle_t& h);
293 * Type def of a Ethernet address
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);
301 * Convert to byte array
303 void to_bytes(uint8_t* array, uint8_t len) const;
306 * An all 1's MAC address
308 const static mac_address_t ONE;
311 * An all 0's MAC address
313 const static mac_address_t ZERO;
316 * Comparison operator
318 bool operator==(const mac_address_t& m) const;
323 bool operator<(const mac_address_t& m) const;
328 std::string to_string() const;
331 * Underlying bytes array
333 std::array<uint8_t, 6> bytes;
337 * Type def of a L2 address as read from VPP
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);
346 * Convert to byte array
348 void to_bytes(uint8_t* array, uint8_t len) const;
351 * An all 1's L2 address
353 const static l2_address_t ONE;
356 * An all 0's L2 address
358 const static l2_address_t ZERO;
361 * Comparison operator
363 bool operator==(const l2_address_t& m) const;
366 * Comparison operator
368 bool operator!=(const l2_address_t& m) const;
373 std::string to_string() const;
376 * MAC address conversion
378 mac_address_t to_mac() const;
381 * Underlying bytes array - filled from least to most significant
383 std::vector<uint8_t> bytes;
393 counter_t(const counter_t& c)
403 * Ostream operator for a MAC address
405 std::ostream& operator<<(std::ostream& os, const mac_address_t& mac);
408 * Ostream operator for a MAC address
410 std::ostream& operator<<(std::ostream& os, const l2_address_t& l2);
413 * Ostream operator for a MAC address
415 std::ostream& operator<<(std::ostream& os, const counter_t& c);
419 * fd.io coding-style-patch-verification: ON
422 * eval: (c-set-style "mozilla")