bmv2
Designing your own switch target with bmv2
simple_pre_lag.h
Go to the documentation of this file.
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  * Srikrishna Gopu (krishna@barefootnetworks.com)
18  * Antonin Bas (antonin@barefootnetworks.com)
19  *
20  */
21 
23 
24 #ifndef BM_BM_SIM_SIMPLE_PRE_LAG_H_
25 #define BM_BM_SIM_SIMPLE_PRE_LAG_H_
26 
27 #include <string>
28 #include <unordered_map>
29 #include <vector>
30 
31 #include "pre.h"
32 #include "simple_pre.h"
33 
34 namespace bm {
35 
37 class McSimplePreLAG : public McSimplePre {
38  public:
39  static constexpr int LAG_MAX_ENTRIES = 256;
40  using lag_id_t = uint16_t;
41 
42  explicit McSimplePreLAG(
43  int mgid_table_size = McSimplePre::DEFAULT_MGID_TABLE_SIZE,
44  int l1_max_entries = McSimplePre::DEFAULT_L1_MAX_ENTRIES,
45  int l2_max_entries = McSimplePre::DEFAULT_L2_MAX_ENTRIES)
46  : McSimplePre(mgid_table_size, l1_max_entries, l2_max_entries) {}
47 
48  McReturnCode mc_node_create(const rid_t rid,
49  const PortMap &port_map,
50  const LagMap &lag_map,
51  l1_hdl_t *l1_hdl);
52  McReturnCode mc_node_update(const l1_hdl_t l1_hdl,
53  const PortMap &port_map,
54  const LagMap &lag_map);
55 
56  McReturnCode mc_set_lag_membership(const lag_id_t lag_index,
57  const PortMap &port_map);
58 
59  std::string mc_get_entries() const;
60 
61  void reset_state();
62 
63  std::vector<McOut> replicate(const McIn) const;
64 
65  private:
66  struct LagEntry {
67  uint16_t member_count;
68  PortMap port_map{};
69 
70  LagEntry() {}
71  LagEntry(uint16_t member_count, const PortMap &port_map)
72  : member_count(member_count), port_map(port_map) {}
73  };
74 
75  std::unordered_map<lag_id_t, LagEntry> lag_entries{};
76 };
77 
78 } // namespace bm
79 
80 #endif // BM_BM_SIM_SIMPLE_PRE_LAG_H_
bm::McSimplePre::rid_t
unsigned int rid_t
NC.
Definition: simple_pre.h:52
bm::McSimplePre
Definition: simple_pre.h:47
bm::McSimplePre::McIn
Input to replicate() method.
Definition: simple_pre.h:71
bm::McSimplePreLAG
Enhances McSimplePre with LAG (link aggregation) support.
Definition: simple_pre_lag.h:37
simple_pre.h