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 * Tunnel or virtual interfaces next
61 * Tables in which entries are added, e.g bridge/route-domains
71 * Then L2/objects that bind to interfaces, BD, ACLS, etc
82 * Error codes that VPP will return during a HW write
84 struct rc_t : public enum_base<rc_t>
86 rc_t(const rc_t& rc) = default;
96 const static rc_t UNSET;
99 * The HW write/update action was/has not been attempted
101 const static rc_t NOOP;
104 * The HW write was successfull
106 const static rc_t OK;
109 * HW write reported invalid input
111 const static rc_t INVALID;
114 * HW write timedout - VPP did not respond within a timely manner
116 const static rc_t TIMEOUT;
119 * Get the rc_t from the VPP API value
121 static const rc_t& from_vpp_retval(int32_t rv);
127 rc_t(int v, const std::string s);
133 struct direction_t : public enum_base<direction_t>
138 direction_t(int v, const std::string s);
143 ~direction_t() = default;
148 const static direction_t INPUT;
153 const static direction_t OUTPUT;
157 * Output ostream for direction_t
159 std::ostream& operator<<(std::ostream& os, const direction_t& dir);
164 struct ethertype_t : public enum_base<ethertype_t>
169 ethertype_t(int v, const std::string s);
174 ~ethertype_t() = default;
179 const static ethertype_t ARP;
184 const static ethertype_t FCOE;
189 const static ethertype_t IPV4;
194 const static ethertype_t IPV6;
197 * Ethertype MAC Security
199 const static ethertype_t MAC_SECURITY;
202 * Ethertype MPLS unicast
204 const static ethertype_t MPLS_UNICAST;
209 const static ethertype_t TRILL;
212 * Ethertype Unspecified
214 const static ethertype_t UNSPECIFIED;
217 * Get the ethertype from the numeric value
219 static const ethertype_t& from_numeric_val(uint16_t numeric);
223 * Output ostream for ethertype_t
225 std::ostream& operator<<(std::ostream& os, const ethertype_t& eth);
228 * A type declaration of an interface handle in VPP
243 * convert to string format for debug purposes
245 std::string to_string() const;
248 * Comparison operator
250 bool operator==(const handle_t& other) const;
253 * Comparison operator
255 bool operator!=(const handle_t& other) const;
260 bool operator<(const handle_t& other) const;
263 * A value of an interface handle_t that means the itf does not exist
265 const static handle_t INVALID;
268 * get the value of the handle
270 uint32_t value() const;
273 * reset the value of the handle to ~0
285 * ostream print of a handle_t
287 std::ostream& operator<<(std::ostream& os, const handle_t& h);
290 * Type def of a Ethernet address
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);
298 * Convert to byte array
300 void to_bytes(uint8_t* array, uint8_t len) const;
303 * An all 1's MAC address
305 const static mac_address_t ONE;
308 * An all 0's MAC address
310 const static mac_address_t ZERO;
313 * Comparison operator
315 bool operator==(const mac_address_t& m) const;
320 bool operator<(const mac_address_t& m) const;
325 std::string to_string() const;
328 * Underlying bytes array
330 std::array<uint8_t, 6> bytes;
334 * Type def of a L2 address as read from VPP
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);
343 * Convert to byte array
345 void to_bytes(uint8_t* array, uint8_t len) const;
348 * An all 1's L2 address
350 const static l2_address_t ONE;
353 * An all 0's L2 address
355 const static l2_address_t ZERO;
358 * Comparison operator
360 bool operator==(const l2_address_t& m) const;
363 * Comparison operator
365 bool operator!=(const l2_address_t& m) const;
370 std::string to_string() const;
373 * MAC address conversion
375 mac_address_t to_mac() const;
378 * Underlying bytes array - filled from least to most significant
380 std::vector<uint8_t> bytes;
384 * Ostream operator for a MAC address
386 std::ostream& operator<<(std::ostream& os, const mac_address_t& mac);
389 * Ostream operator for a MAC address
391 std::ostream& operator<<(std::ostream& os, const l2_address_t& l2);
395 * fd.io coding-style-patch-verification: ON
398 * eval: (c-set-style "mozilla")