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);
162 * A type declaration of an interface handle in VPP
177 * convert to string format for debug purposes
179 std::string to_string() const;
182 * Comparison operator
184 bool operator==(const handle_t& other) const;
187 * Comparison operator
189 bool operator!=(const handle_t& other) const;
194 bool operator<(const handle_t& other) const;
197 * A value of an interface handle_t that means the itf does not exist
199 const static handle_t INVALID;
202 * get the value of the handle
204 uint32_t value() const;
207 * reset the value of the handle to ~0
219 * ostream print of a handle_t
221 std::ostream& operator<<(std::ostream& os, const handle_t& h);
224 * Type def of a Ethernet address
228 mac_address_t(uint8_t bytes[6]);
229 mac_address_t(const std::string& str);
230 mac_address_t(std::initializer_list<uint8_t> bytes);
232 * Convert to byte array
234 void to_bytes(uint8_t* array, uint8_t len) const;
237 * An all 1's MAC address
239 const static mac_address_t ONE;
242 * An all 0's MAC address
244 const static mac_address_t ZERO;
247 * Comparison operator
249 bool operator==(const mac_address_t& m) const;
254 bool operator<(const mac_address_t& m) const;
259 std::string to_string() const;
262 * Underlying bytes array
264 std::array<uint8_t, 6> bytes;
268 * Type def of a L2 address as read from VPP
272 l2_address_t(const uint8_t bytes[8], uint8_t n_bytes);
273 l2_address_t(std::initializer_list<uint8_t> bytes);
274 l2_address_t(const mac_address_t& mac);
277 * Convert to byte array
279 void to_bytes(uint8_t* array, uint8_t len) const;
282 * An all 1's L2 address
284 const static l2_address_t ONE;
287 * An all 0's L2 address
289 const static l2_address_t ZERO;
292 * Comparison operator
294 bool operator==(const l2_address_t& m) const;
297 * Comparison operator
299 bool operator!=(const l2_address_t& m) const;
304 std::string to_string() const;
307 * MAC address conversion
309 mac_address_t to_mac() const;
312 * Underlying bytes array - filled from least to most significant
314 std::vector<uint8_t> bytes;
318 * Ostream operator for a MAC address
320 std::ostream& operator<<(std::ostream& os, const mac_address_t& mac);
323 * Ostream operator for a MAC address
325 std::ostream& operator<<(std::ostream& os, const l2_address_t& l2);
329 * fd.io coding-style-patch-verification: ON
332 * eval: (c-set-style "mozilla")