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 * bond group binding is after interfaces but before
62 * Tunnel or virtual interfaces next
67 * Tables in which entries are added, e.g bridge/route-domains
77 * Then L2/objects that bind to interfaces, BD, ACLS, etc
88 * Error codes that VPP will return during a HW write
90 struct rc_t : public enum_base<rc_t>
92 rc_t(const rc_t& rc) = default;
102 const static rc_t UNSET;
105 * The HW write/update action was/has not been attempted
107 const static rc_t NOOP;
110 * The HW write was successfull
112 const static rc_t OK;
115 * HW write reported invalid input
117 const static rc_t INVALID;
120 * HW write timedout - VPP did not respond within a timely manner
122 const static rc_t TIMEOUT;
125 * Get the rc_t from the VPP API value
127 static const rc_t& from_vpp_retval(int32_t rv);
133 rc_t(int v, const std::string s);
139 struct direction_t : public enum_base<direction_t>
144 direction_t(int v, const std::string s);
149 ~direction_t() = default;
154 const static direction_t INPUT;
159 const static direction_t OUTPUT;
163 * Output ostream for direction_t
165 std::ostream& operator<<(std::ostream& os, const direction_t& dir);
170 struct ethertype_t : public enum_base<ethertype_t>
175 ethertype_t(int v, const std::string s);
180 ~ethertype_t() = default;
185 const static ethertype_t ARP;
190 const static ethertype_t FCOE;
195 const static ethertype_t IPV4;
200 const static ethertype_t IPV6;
203 * Ethertype MAC Security
205 const static ethertype_t MAC_SECURITY;
208 * Ethertype MPLS unicast
210 const static ethertype_t MPLS_UNICAST;
215 const static ethertype_t TRILL;
218 * Ethertype Unspecified
220 const static ethertype_t UNSPECIFIED;
223 * Get the ethertype from the numeric value
225 static const ethertype_t& from_numeric_val(uint16_t numeric);
229 * Output ostream for ethertype_t
231 std::ostream& operator<<(std::ostream& os, const ethertype_t& eth);
234 * A type declaration of an interface handle in VPP
249 * convert to string format for debug purposes
251 std::string to_string() const;
254 * Comparison operator
256 bool operator==(const handle_t& other) const;
259 * Comparison operator
261 bool operator!=(const handle_t& other) const;
266 bool operator<(const handle_t& other) const;
269 * A value of an interface handle_t that means the itf does not exist
271 const static handle_t INVALID;
274 * get the value of the handle
276 uint32_t value() const;
279 * reset the value of the handle to ~0
291 * ostream print of a handle_t
293 std::ostream& operator<<(std::ostream& os, const handle_t& h);
296 * Type def of a Ethernet address
300 mac_address_t(uint8_t bytes[6]);
301 mac_address_t(const std::string& str);
302 mac_address_t(std::initializer_list<uint8_t> bytes);
304 * Convert to byte array
306 void to_bytes(uint8_t* array, uint8_t len) const;
309 * An all 1's MAC address
311 const static mac_address_t ONE;
314 * An all 0's MAC address
316 const static mac_address_t ZERO;
319 * Comparison operator
321 bool operator==(const mac_address_t& m) const;
326 bool operator<(const mac_address_t& m) const;
331 std::string to_string() const;
334 * Underlying bytes array
336 std::array<uint8_t, 6> bytes;
340 * Type def of a L2 address as read from VPP
344 l2_address_t(const uint8_t bytes[8], uint8_t n_bytes);
345 l2_address_t(std::initializer_list<uint8_t> bytes);
346 l2_address_t(const mac_address_t& mac);
349 * Convert to byte array
351 void to_bytes(uint8_t* array, uint8_t len) const;
354 * An all 1's L2 address
356 const static l2_address_t ONE;
359 * An all 0's L2 address
361 const static l2_address_t ZERO;
364 * Comparison operator
366 bool operator==(const l2_address_t& m) const;
369 * Comparison operator
371 bool operator!=(const l2_address_t& m) const;
376 std::string to_string() const;
379 * MAC address conversion
381 mac_address_t to_mac() const;
384 * Underlying bytes array - filled from least to most significant
386 std::vector<uint8_t> bytes;
390 * Ostream operator for a MAC address
392 std::ostream& operator<<(std::ostream& os, const mac_address_t& mac);
395 * Ostream operator for a MAC address
397 std::ostream& operator<<(std::ostream& os, const l2_address_t& l2);
401 * fd.io coding-style-patch-verification: ON
404 * eval: (c-set-style "mozilla")