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
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>
94 const static rc_t UNSET;
97 * The HW write/update action was/has not been attempted
99 const static rc_t NOOP;
102 * The HW write was successfull
104 const static rc_t OK;
107 * HW write reported invalid input
109 const static rc_t INVALID;
112 * HW write timedout - VPP did not respond within a timely manner
114 const static rc_t TIMEOUT;
117 * Get the rc_t from the VPP API value
119 static const rc_t& from_vpp_retval(int32_t rv);
125 rc_t(int v, const std::string s);
131 struct direction_t : public enum_base<direction_t>
136 direction_t(int v, const std::string s);
141 ~direction_t() = default;
146 const static direction_t INPUT;
151 const static direction_t OUTPUT;
155 * Output ostream for direction_t
157 std::ostream& operator<<(std::ostream& os, const direction_t& dir);
162 struct ethertype_t : public enum_base<ethertype_t>
167 ethertype_t(int v, const std::string s);
172 ~ethertype_t() = default;
177 const static ethertype_t ARP;
182 const static ethertype_t FCOE;
187 const static ethertype_t IPV4;
192 const static ethertype_t IPV6;
195 * Ethertype MAC Security
197 const static ethertype_t MAC_SECURITY;
200 * Ethertype MPLS unicast
202 const static ethertype_t MPLS_UNICAST;
207 const static ethertype_t TRILL;
210 * Ethertype Unspecified
212 const static ethertype_t UNSPECIFIED;
215 * Get the ethertype from the numeric value
217 static const ethertype_t& from_numeric_val(uint16_t numeric);
221 * Output ostream for ethertype_t
223 std::ostream& operator<<(std::ostream& os, const ethertype_t& eth);
226 * A type declaration of an interface handle in VPP
241 * convert to string format for debug purposes
243 std::string to_string() const;
246 * Comparison operator
248 bool operator==(const handle_t& other) const;
251 * Comparison operator
253 bool operator!=(const handle_t& other) const;
258 bool operator<(const handle_t& other) const;
261 * A value of an interface handle_t that means the itf does not exist
263 const static handle_t INVALID;
266 * get the value of the handle
268 uint32_t value() const;
271 * reset the value of the handle to ~0
283 * ostream print of a handle_t
285 std::ostream& operator<<(std::ostream& os, const handle_t& h);
288 * Type def of a Ethernet address
292 mac_address_t(const uint8_t bytes[6]);
293 mac_address_t(const std::string& str);
294 mac_address_t(std::initializer_list<uint8_t> bytes);
296 * Convert to byte array
298 void to_bytes(uint8_t* array, uint8_t len) const;
301 * An all 1's MAC address
303 const static mac_address_t ONE;
306 * An all 0's MAC address
308 const static mac_address_t ZERO;
311 * Comparison operator
313 bool operator==(const mac_address_t& m) const;
318 bool operator<(const mac_address_t& m) const;
323 std::string to_string() const;
326 * Underlying bytes array
328 std::array<uint8_t, 6> bytes;
332 * Type def of a L2 address as read from VPP
336 l2_address_t(const uint8_t bytes[8], uint8_t n_bytes);
337 l2_address_t(std::initializer_list<uint8_t> bytes);
338 l2_address_t(const mac_address_t& mac);
341 * Convert to byte array
343 void to_bytes(uint8_t* array, uint8_t len) const;
346 * An all 1's L2 address
348 const static l2_address_t ONE;
351 * An all 0's L2 address
353 const static l2_address_t ZERO;
356 * Comparison operator
358 bool operator==(const l2_address_t& m) const;
361 * Comparison operator
363 bool operator!=(const l2_address_t& m) const;
368 std::string to_string() const;
371 * MAC address conversion
373 mac_address_t to_mac() const;
376 * Underlying bytes array - filled from least to most significant
378 std::vector<uint8_t> bytes;
382 * Ostream operator for a MAC address
384 std::ostream& operator<<(std::ostream& os, const mac_address_t& mac);
387 * Ostream operator for a MAC address
389 std::ostream& operator<<(std::ostream& os, const l2_address_t& l2);
393 * fd.io coding-style-patch-verification: ON
396 * eval: (c-set-style "mozilla")