bmv2
Designing your own switch target with bmv2
runtime_interface.h
1 /* Copyright 2013-present Barefoot Networks, Inc.
2  *
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
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 /*
17  * Antonin Bas (antonin@barefootnetworks.com)
18  *
19  */
20 
21 #ifndef BM_BM_SIM_RUNTIME_INTERFACE_H_
22 #define BM_BM_SIM_RUNTIME_INTERFACE_H_
23 
24 #include <string>
25 #include <vector>
26 #include <iosfwd>
27 
28 #include "action_profile.h"
29 #include "match_tables.h"
30 #include "device_id.h"
31 
32 namespace bm {
33 
34 class RuntimeInterface {
35  public:
36  using mbr_hdl_t = MatchTableIndirect::mbr_hdl_t;
37  using grp_hdl_t = MatchTableIndirectWS::grp_hdl_t;
38 
39  using MeterErrorCode = Meter::MeterErrorCode;
40  using RegisterErrorCode = Register::RegisterErrorCode;
41 
42  enum ErrorCode {
43  SUCCESS = 0,
44  CONFIG_SWAP_DISABLED,
45  ONGOING_SWAP,
46  NO_ONGOING_SWAP
47  };
48 
49  public:
50  virtual ~RuntimeInterface() { }
51 
52  // common to all tables
53 
54  virtual MatchErrorCode
55  mt_get_num_entries(cxt_id_t cxt_id,
56  const std::string &table_name,
57  size_t *num_entries) const = 0;
58 
59  virtual MatchErrorCode
60  mt_clear_entries(cxt_id_t cxt_id,
61  const std::string &table_name,
62  bool reset_default_entry) = 0;
63 
64  // direct tables
65 
66  virtual MatchErrorCode
67  mt_add_entry(cxt_id_t cxt_id,
68  const std::string &table_name,
69  const std::vector<MatchKeyParam> &match_key,
70  const std::string &action_name,
71  ActionData action_data, // will be moved
72  entry_handle_t *handle,
73  int priority = -1 /*only used for ternary*/) = 0;
74 
75  virtual MatchErrorCode
76  mt_set_default_action(cxt_id_t cxt_id,
77  const std::string &table_name,
78  const std::string &action_name,
79  ActionData action_data) = 0;
80 
81  virtual MatchErrorCode
82  mt_reset_default_entry(cxt_id_t cxt_id,
83  const std::string &table_name) = 0;
84 
85  virtual MatchErrorCode
86  mt_delete_entry(cxt_id_t cxt_id,
87  const std::string &table_name,
88  entry_handle_t handle) = 0;
89 
90  virtual MatchErrorCode
91  mt_modify_entry(cxt_id_t cxt_id,
92  const std::string &table_name,
93  entry_handle_t handle,
94  const std::string &action_name,
95  ActionData action_data) = 0;
96 
97  virtual MatchErrorCode
98  mt_set_entry_ttl(cxt_id_t cxt_id,
99  const std::string &table_name,
100  entry_handle_t handle,
101  unsigned int ttl_ms) = 0;
102 
103  // action profiles
104 
105  virtual MatchErrorCode
106  mt_act_prof_add_member(cxt_id_t cxt_id,
107  const std::string &act_prof_name,
108  const std::string &action_name,
109  ActionData action_data,
110  mbr_hdl_t *mbr) = 0;
111 
112  virtual MatchErrorCode
113  mt_act_prof_delete_member(cxt_id_t cxt_id,
114  const std::string &act_prof_name,
115  mbr_hdl_t mbr) = 0;
116 
117  virtual MatchErrorCode
118  mt_act_prof_modify_member(cxt_id_t cxt_id,
119  const std::string &act_prof_name,
120  mbr_hdl_t mbr,
121  const std::string &action_name,
122  ActionData action_data) = 0;
123 
124  virtual MatchErrorCode
125  mt_act_prof_create_group(cxt_id_t cxt_id,
126  const std::string &act_prof_name,
127  grp_hdl_t *grp) = 0;
128 
129  virtual MatchErrorCode
130  mt_act_prof_delete_group(cxt_id_t cxt_id,
131  const std::string &act_prof_name,
132  grp_hdl_t grp) = 0;
133 
134  virtual MatchErrorCode
135  mt_act_prof_add_member_to_group(cxt_id_t cxt_id,
136  const std::string &act_prof_name,
137  mbr_hdl_t mbr, grp_hdl_t grp) = 0;
138 
139  virtual MatchErrorCode
140  mt_act_prof_remove_member_from_group(cxt_id_t cxt_id,
141  const std::string &act_prof_name,
142  mbr_hdl_t mbr, grp_hdl_t grp) = 0;
143 
144  virtual std::vector<ActionProfile::Member>
145  mt_act_prof_get_members(cxt_id_t cxt_id,
146  const std::string &act_prof_name) const = 0;
147 
148  virtual MatchErrorCode
149  mt_act_prof_get_member(cxt_id_t cxt_id, const std::string &act_prof_name,
150  mbr_hdl_t mbr,
151  ActionProfile::Member *member) const = 0;
152 
153  virtual std::vector<ActionProfile::Group>
154  mt_act_prof_get_groups(cxt_id_t cxt_id,
155  const std::string &act_prof_name) const = 0;
156 
157  virtual MatchErrorCode
158  mt_act_prof_get_group(cxt_id_t cxt_id, const std::string &act_prof_name,
159  grp_hdl_t grp,
160  ActionProfile::Group *group) const = 0;
161 
162  // indirect tables
163 
164  virtual MatchErrorCode
165  mt_indirect_add_entry(cxt_id_t cxt_id,
166  const std::string &table_name,
167  const std::vector<MatchKeyParam> &match_key,
168  mbr_hdl_t mbr,
169  entry_handle_t *handle,
170  int priority = 1) = 0;
171 
172  virtual MatchErrorCode
173  mt_indirect_modify_entry(cxt_id_t cxt_id,
174  const std::string &table_name,
175  entry_handle_t handle,
176  mbr_hdl_t mbr) = 0;
177 
178  virtual MatchErrorCode
179  mt_indirect_delete_entry(cxt_id_t cxt_id,
180  const std::string &table_name,
181  entry_handle_t handle) = 0;
182 
183  virtual MatchErrorCode
184  mt_indirect_set_entry_ttl(cxt_id_t cxt_id,
185  const std::string &table_name,
186  entry_handle_t handle,
187  unsigned int ttl_ms) = 0;
188 
189  virtual MatchErrorCode
190  mt_indirect_set_default_member(cxt_id_t cxt_id,
191  const std::string &table_name,
192  mbr_hdl_t mbr) = 0;
193 
194  virtual MatchErrorCode
195  mt_indirect_reset_default_entry(cxt_id_t cxt_id,
196  const std::string &table_name) = 0;
197 
198  virtual MatchErrorCode
199  mt_indirect_ws_add_entry(cxt_id_t cxt_id,
200  const std::string &table_name,
201  const std::vector<MatchKeyParam> &match_key,
202  grp_hdl_t grp,
203  entry_handle_t *handle,
204  int priority = 1) = 0;
205 
206  virtual MatchErrorCode
207  mt_indirect_ws_modify_entry(cxt_id_t cxt_id,
208  const std::string &table_name,
209  entry_handle_t handle,
210  grp_hdl_t grp) = 0;
211 
212  virtual MatchErrorCode
213  mt_indirect_ws_set_default_group(cxt_id_t cxt_id,
214  const std::string &table_name,
215  grp_hdl_t grp) = 0;
216 
217 
218  virtual MatchErrorCode
219  mt_read_counters(cxt_id_t cxt_id,
220  const std::string &table_name,
221  entry_handle_t handle,
222  MatchTableAbstract::counter_value_t *bytes,
223  MatchTableAbstract::counter_value_t *packets) = 0;
224 
225  virtual MatchErrorCode
226  mt_reset_counters(cxt_id_t cxt_id,
227  const std::string &table_name) = 0;
228 
229  virtual MatchErrorCode
230  mt_write_counters(cxt_id_t cxt_id,
231  const std::string &table_name,
232  entry_handle_t handle,
233  MatchTableAbstract::counter_value_t bytes,
234  MatchTableAbstract::counter_value_t packets) = 0;
235 
236  virtual MatchErrorCode
237  mt_set_meter_rates(cxt_id_t cxt_id,
238  const std::string &table_name,
239  entry_handle_t handle,
240  const std::vector<Meter::rate_config_t> &configs) = 0;
241 
242  virtual MatchErrorCode
243  mt_get_meter_rates(cxt_id_t cxt_id,
244  const std::string &table_name,
245  entry_handle_t handle,
246  std::vector<Meter::rate_config_t> *configs) = 0;
247 
248  virtual MatchErrorCode
249  mt_reset_meter_rates(cxt_id_t cxt_id,
250  const std::string &table_name,
251  entry_handle_t handle) = 0;
252 
253  virtual MatchTableType
254  mt_get_type(cxt_id_t cxt_id, const std::string &table_name) const = 0;
255 
256  virtual std::vector<MatchTable::Entry>
257  mt_get_entries(cxt_id_t cxt_id, const std::string &table_name) const = 0;
258 
259  virtual std::vector<MatchTableIndirect::Entry>
260  mt_indirect_get_entries(cxt_id_t cxt_id,
261  const std::string &table_name) const = 0;
262 
263  virtual std::vector<MatchTableIndirectWS::Entry>
264  mt_indirect_ws_get_entries(cxt_id_t cxt_id,
265  const std::string &table_name) const = 0;
266 
267  virtual MatchErrorCode
268  mt_get_entry(cxt_id_t cxt_id, const std::string &table_name,
269  entry_handle_t handle, MatchTable::Entry *entry) const = 0;
270 
271  virtual MatchErrorCode
272  mt_indirect_get_entry(cxt_id_t cxt_id, const std::string &table_name,
273  entry_handle_t handle,
274  MatchTableIndirect::Entry *entry) const = 0;
275 
276  virtual MatchErrorCode
277  mt_indirect_ws_get_entry(cxt_id_t cxt_id, const std::string &table_name,
278  entry_handle_t handle,
279  MatchTableIndirectWS::Entry *entry) const = 0;
280 
281  virtual MatchErrorCode
282  mt_get_default_entry(cxt_id_t cxt_id, const std::string &table_name,
283  MatchTable::Entry *entry) const = 0;
284 
285  virtual MatchErrorCode
286  mt_indirect_get_default_entry(cxt_id_t cxt_id, const std::string &table_name,
287  MatchTableIndirect::Entry *entry) const = 0;
288 
289  virtual MatchErrorCode
290  mt_indirect_ws_get_default_entry(
291  cxt_id_t cxt_id, const std::string &table_name,
292  MatchTableIndirectWS::Entry *entry) const = 0;
293 
294  virtual MatchErrorCode
295  mt_get_entry_from_key(cxt_id_t cxt_id, const std::string &table_name,
296  const std::vector<MatchKeyParam> &match_key,
297  MatchTable::Entry *entry, int priority = 1) const = 0;
298 
299  virtual MatchErrorCode
300  mt_indirect_get_entry_from_key(cxt_id_t cxt_id, const std::string &table_name,
301  const std::vector<MatchKeyParam> &match_key,
302  MatchTableIndirect::Entry *entry,
303  int priority = 1) const = 0;
304 
305  virtual MatchErrorCode
306  mt_indirect_ws_get_entry_from_key(cxt_id_t cxt_id,
307  const std::string &table_name,
308  const std::vector<MatchKeyParam> &match_key,
309  MatchTableIndirectWS::Entry *entry,
310  int priority = 1) const = 0;
311 
312  virtual Counter::CounterErrorCode
313  read_counters(cxt_id_t cxt_id,
314  const std::string &counter_name,
315  size_t index,
316  MatchTableAbstract::counter_value_t *bytes,
317  MatchTableAbstract::counter_value_t *packets) = 0;
318 
319  virtual Counter::CounterErrorCode
320  reset_counters(cxt_id_t cxt_id,
321  const std::string &counter_name) = 0;
322 
323  virtual Counter::CounterErrorCode
324  write_counters(cxt_id_t cxt_id,
325  const std::string &counter_name,
326  size_t index,
327  MatchTableAbstract::counter_value_t bytes,
328  MatchTableAbstract::counter_value_t packets) = 0;
329 
330 
331  virtual MeterErrorCode
332  meter_array_set_rates(cxt_id_t cxt_id,
333  const std::string &meter_name,
334  const std::vector<Meter::rate_config_t> &configs) = 0;
335 
336  virtual MeterErrorCode
337  meter_set_rates(cxt_id_t cxt_id,
338  const std::string &meter_name, size_t idx,
339  const std::vector<Meter::rate_config_t> &configs) = 0;
340 
341  virtual MeterErrorCode
342  meter_get_rates(cxt_id_t cxt_id,
343  const std::string &meter_name, size_t idx,
344  std::vector<Meter::rate_config_t> *configs) = 0;
345 
346  virtual MeterErrorCode
347  meter_reset_rates(cxt_id_t cxt_id,
348  const std::string &meter_name, size_t idx) = 0;
349 
350  virtual RegisterErrorCode
351  register_read(cxt_id_t cxt_id,
352  const std::string &register_name,
353  const size_t idx, Data *value) = 0;
354 
355  virtual std::vector<Data>
356  register_read_all(cxt_id_t cxt_id, const std::string &register_name) = 0;
357 
358  virtual RegisterErrorCode
359  register_write(cxt_id_t cxt_id,
360  const std::string &register_name,
361  const size_t idx, Data value) = 0; // to be moved
362 
363  virtual RegisterErrorCode
364  register_write_range(cxt_id_t cxt_id,
365  const std::string &register_name,
366  const size_t start, const size_t end,
367  Data value) = 0;
368 
369  virtual RegisterErrorCode
370  register_reset(cxt_id_t cxt_id, const std::string &register_name) = 0;
371 
372  virtual ParseVSet::ErrorCode
373  parse_vset_add(cxt_id_t cxt_id, const std::string &parse_vset_name,
374  const ByteContainer &value) = 0;
375 
376  virtual ParseVSet::ErrorCode
377  parse_vset_remove(cxt_id_t cxt_id, const std::string &parse_vset_name,
378  const ByteContainer &value) = 0;
379 
380  virtual ParseVSet::ErrorCode
381  parse_vset_get(cxt_id_t cxt_id, const std::string &parse_vset_name,
382  std::vector<ByteContainer> *values) = 0;
383 
384  virtual ParseVSet::ErrorCode
385  parse_vset_clear(cxt_id_t cxt_id, const std::string &parse_vset_name) = 0;
386 
387  virtual ErrorCode
388  load_new_config(const std::string &new_config) = 0;
389 
390  virtual ErrorCode
391  swap_configs() = 0;
392 
393  virtual std::string
394  get_config() const = 0;
395 
396  virtual std::string
397  get_config_md5() const = 0;
398 
399  virtual CustomCrcErrorCode
400  set_crc16_custom_parameters(
401  cxt_id_t cxt_id, const std::string &calc_name,
402  const CustomCrcMgr<uint16_t>::crc_config_t &crc16_config) = 0;
403 
404  virtual CustomCrcErrorCode
405  set_crc32_custom_parameters(
406  cxt_id_t cxt_id, const std::string &calc_name,
407  const CustomCrcMgr<uint32_t>::crc_config_t &crc32_config) = 0;
408 
409  virtual ToeplitzErrorCode
410  set_toeplitz_key(
411  cxt_id_t cxt_id, const std::string &calc_name,
412  const ToeplitzMgr::key_t &key) = 0;
413 
414  virtual ErrorCode
415  reset_state() = 0;
416 
417  virtual ErrorCode
418  serialize(std::ostream *out) = 0;
419 };
420 
421 } // namespace bm
422 
423 #endif // BM_BM_SIM_RUNTIME_INTERFACE_H_