aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp-api/vom/types.hpp
blob: 61a25e71cb8ae1cf46a24cb474a228df06240b24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __VOM_TYPES_H__
#define __VOM_TYPES_H__

#include <array>
#include <vector>

#include <boost/asio/ip/address.hpp>

#include "vom/enum_base.hpp"

/**
 * Convenince wrapper macro for error handling in VAPI sends
 */
#define VAPI_CALL(_stmt)                                                       \
  {                                                                            \
    vapi_error_e _rv;                                                          \
    do {                                                                       \
      _rv = (_stmt);                                                           \
    } while (VAPI_OK != _rv);                                                  \
  }

namespace VOM {
/**
 * There needs to be a strict order in which object types are read from VPP
 *  (at boot time) and replayed to VPP (if VPP restarts). That ordering is
 * defined in this enum types
 */
enum class dependency_t
{
  /**
   * Global Configuration has no dependency
   */
  GLOBAL = 0,

  /**
   * interfaces are the root of the dependency graph
   */
  INTERFACE,

  /**
   * Tunnel or virtual interfaces next
   */
  TUNNEL,

  /**
   * Tables in which entries are added, e.g bridge/route-domains
   */
  TABLE,

  /**
   * ACLs
   */
  ACL,

  /**
   * Then L2/objects that bind to interfaces, BD, ACLS, etc
   */
  BINDING,

  /**
   * Entries in Tables
   */
  ENTRY,
};

/**
 * Error codes that VPP will return during a HW write
 */
struct rc_t : public enum_base<rc_t>
{
  rc_t(const rc_t& rc) = default;

  /**
   * Destructor
   */
  ~rc_t();

  /**
   * The value un-set
   */
  const static rc_t UNSET;

  /**
   * The HW write/update action was/has not been attempted
   */
  const static rc_t NOOP;

  /**
   * The HW write was successfull
   */
  const static rc_t OK;

  /**
   * HW write reported invalid input
   */
  const static rc_t INVALID;

  /**
   * HW write timedout - VPP did not respond within a timely manner
   */
  const static rc_t TIMEOUT;

  /**
   * Get the rc_t from the VPP API value
   */
  static const rc_t& from_vpp_retval(int32_t rv);

private:
  /**
   * Constructor
   */
  rc_t(int v, const std::string s);
};

/**
 * Feature Directions
 */
struct direction_t : public enum_base<direction_t>
{
  /**
   * Constructor
   */
  direction_t(int v, const std::string s);

  /**
   * Destructor
   */
  ~direction_t() = default;

  /**
   * Permit Direction
   */
  const static direction_t INPUT;

  /**
   * Deny Direction
   */
  const static direction_t OUTPUT;
};

/**
 * Output ostream for direction_t
 */
std::ostream& operator<<(std::ostream& os, const direction_t& dir);

/**
 * A type declaration of an interface handle in VPP
 */
struct handle_t
{
  /**
   * Constructor
   */
  handle_t(int value);

  /**
   * Constructor
   */
  handle_t();

  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;

  /**
   * Comparison operator
   */
  bool operator==(const handle_t& other) const;

  /**
   * Comparison operator
   */
  bool operator!=(const handle_t& other) const;

  /**
   * less than operator
   */
  bool operator<(const handle_t& other) const;

  /**
   * A value of an interface handle_t that means the itf does not exist
   */
  const static handle_t INVALID;

  /**
   * get the value of the handle
   */
  uint32_t value() const;

private:
  /**
   * VPP's handle value
   */
  uint32_t m_value;
};

/**
 * ostream print of a handle_t
 */
std::ostream& operator<<(std::ostream& os, const handle_t& h);

/**
 * Type def of a Ethernet address
 */
struct mac_address_t
{
  mac_address_t(uint8_t bytes[6]);
  mac_address_t(const std::string& str);
  mac_address_t(std::initializer_list<uint8_t> bytes);
  /**
   * Convert to byte array
   */
  void to_bytes(uint8_t* array, uint8_t len) const;

  /**
   * An all 1's MAC address
   */
  const static mac_address_t ONE;

  /**
   * An all 0's MAC address
   */
  const static mac_address_t ZERO;

  /**
   * Comparison operator
   */
  bool operator==(const mac_address_t& m) const;

  /**
   * less than operator
   */
  bool operator<(const mac_address_t& m) const;

  /**
   * String conversion
   */
  std::string to_string() const;

  /**
   * Underlying bytes array
   */
  std::array<uint8_t, 6> bytes;
};

/**
 * Type def of a L2 address as read from VPP
 */
struct l2_address_t
{
  l2_address_t(const uint8_t bytes[8], uint8_t n_bytes);
  l2_address_t(std::initializer_list<uint8_t> bytes);
  l2_address_t(const mac_address_t& mac);

  /**
   * Convert to byte array
   */
  void to_bytes(uint8_t* array, uint8_t len) const;

  /**
   * An all 1's L2 address
   */
  const static l2_address_t ONE;

  /**
   * An all 0's L2 address
   */
  const static l2_address_t ZERO;

  /**
   * Comparison operator
   */
  bool operator==(const l2_address_t& m) const;

  /**
   * Comparison operator
   */
  bool operator!=(const l2_address_t& m) const;

  /**
   * String conversion
   */
  std::string to_string() const;

  /**
   * MAC address conversion
   */
  mac_address_t to_mac() const;

  /**
   * Underlying bytes array - filled from least to most significant
   */
  std::vector<uint8_t> bytes;
};

/**
 * Ostream operator for a MAC address
 */
std::ostream& operator<<(std::ostream& os, const mac_address_t& mac);

/**
 * Ostream operator for a MAC address
 */
std::ostream& operator<<(std::ostream& os, const l2_address_t& l2);
};

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "mozilla")
 * End:
 */

#endif