bmv2
Designing your own switch target with bmv2
Loading...
Searching...
No Matches
simple_pre.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_H_
25#define BM_BM_SIM_SIMPLE_PRE_H_
26
27#include <string>
28#include <unordered_map>
29#include <vector>
30
31#include <boost/thread/shared_mutex.hpp>
32
33#include "handle_mgr.h"
34#include "pre.h"
35
36// forward declaration of Json::Value
37namespace Json {
38
39class Value;
40
41} // namespace Json
42
43namespace bm {
44
48 public:
50 using mgrp_t = unsigned int;
52 using rid_t = unsigned int;
54 using egress_port_t = unsigned int;
55
56 using mgrp_hdl_t = uintptr_t;
57 using l1_hdl_t = uintptr_t;
58 using l2_hdl_t = uintptr_t;
59
60 public:
61 enum McReturnCode {
62 SUCCESS = 0,
63 TABLE_FULL,
64 INVALID_MGID,
65 INVALID_MGRP_HANDLE,
66 INVALID_L1_HANDLE,
67 ERROR
68 };
69
71 struct McIn {
74 };
75
83
84 public:
85 static constexpr int DEFAULT_MGID_TABLE_SIZE = 4096;
86 static constexpr int DEFAULT_L1_MAX_ENTRIES = 4096;
87 static constexpr int DEFAULT_L2_MAX_ENTRIES = 8192;
88
89 static constexpr size_t PORT_MAP_SIZE = 512;
90 using PortMap = McPre::Set<PORT_MAP_SIZE>;
91
92 static constexpr size_t LAG_MAP_SIZE = 512;
93 using LagMap = McPre::Set<LAG_MAP_SIZE>;
94
95 explicit McSimplePre(
96 int mgid_table_size = DEFAULT_MGID_TABLE_SIZE,
97 int l1_max_entries = DEFAULT_L1_MAX_ENTRIES,
98 int l2_max_entries = DEFAULT_L2_MAX_ENTRIES)
99 : mgid_table_size(mgid_table_size),
100 l1_max_entries(l1_max_entries),
101 l2_max_entries(l2_max_entries) {}
102 McReturnCode mc_mgrp_create(const mgrp_t, mgrp_hdl_t *);
103 McReturnCode mc_mgrp_destroy(const mgrp_hdl_t);
104 McReturnCode mc_node_create(const rid_t,
105 const PortMap &port_map,
106 l1_hdl_t *l1_hdl);
107 McReturnCode mc_node_associate(const mgrp_hdl_t, const l1_hdl_t);
108 McReturnCode mc_node_dissociate(const mgrp_hdl_t, const l1_hdl_t);
109 McReturnCode mc_node_destroy(const l1_hdl_t);
110 McReturnCode mc_node_update(const l1_hdl_t l1_hdl,
111 const PortMap &port_map);
112
113 std::string mc_get_entries() const;
114
115 void reset_state();
116
139 std::vector<McOut> replicate(const McIn) const;
140
142 McSimplePre(const McSimplePre &other) = delete;
144 McSimplePre &operator=(const McSimplePre &other) = delete;
145
147 McSimplePre(McSimplePre &&other) = delete;
150
151 protected:
152 int mgid_table_size;
153 int l1_max_entries;
154 int l2_max_entries;
155
156 struct MgidEntry {
157 mgrp_t mgid{};
158 std::vector<l1_hdl_t> l1_list{};
159
160 MgidEntry() {}
161 explicit MgidEntry(mgrp_t mgid)
162 : mgid(mgid) {}
163 };
164
165 struct L1Entry {
166 mgrp_hdl_t mgrp_hdl{};
167 rid_t rid{};
168 l2_hdl_t l2_hdl{};
169 bool is_associated{false};
170
171 L1Entry() {}
172 explicit L1Entry(rid_t rid)
173 : rid(rid) {}
174 };
175
176 struct L2Entry {
177 l1_hdl_t l1_hdl{};
178 PortMap port_map{};
179 LagMap lag_map{};
180
181 L2Entry() {}
182 L2Entry(l1_hdl_t l1_hdl, const PortMap &port_map)
183 : l1_hdl(l1_hdl), port_map(port_map) {}
184
185 L2Entry(l1_hdl_t l1_hdl, const PortMap &port_map, const LagMap &lag_map)
186 : l1_hdl(l1_hdl), port_map(port_map), lag_map(lag_map) {}
187 };
188
189 // internal version, which does not acquire the lock
190 void reset_state_();
191
192 // does not acquire lock
193 void get_entries_common(Json::Value *root) const;
194
195 // does not acquire lock
196 void node_dissociate(MgidEntry *mgid_entry, l1_hdl_t l1_hdl);
197
198 std::unordered_map<mgrp_hdl_t, MgidEntry> mgid_entries{};
199 std::unordered_map<l1_hdl_t, L1Entry> l1_entries{};
200 std::unordered_map<l2_hdl_t, L2Entry> l2_entries{};
201 HandleMgr l1_handles{};
202 HandleMgr l2_handles{};
203 mutable boost::shared_mutex mutex{};
204};
205
206} // namespace bm
207
208#endif // BM_BM_SIM_SIMPLE_PRE_H_
Definition simple_pre.h:47
unsigned int mgrp_t
NC.
Definition simple_pre.h:50
unsigned int egress_port_t
NC.
Definition simple_pre.h:54
McSimplePre & operator=(const McSimplePre &other)=delete
Deleted move assignment operator.
McSimplePre(McSimplePre &&other)=delete
Deleted move constructor.
McSimplePre(const McSimplePre &other)=delete
Deleted copy constructor.
unsigned int rid_t
NC.
Definition simple_pre.h:52
std::vector< McOut > replicate(const McIn) const
McSimplePre & operator=(McSimplePre &&other)=delete
Deleted move assignment operator.
Input to replicate() method.
Definition simple_pre.h:71
mgrp_t mgid
Multicast group id to use for replication.
Definition simple_pre.h:73
Output of replicate() method.
Definition simple_pre.h:77
rid_t rid
replication id of multicast copy
Definition simple_pre.h:79
egress_port_t egress_port
egress port of multicast copy
Definition simple_pre.h:81