bmv2
Designing your own switch target with bmv2
Loading...
Searching...
No Matches
lookup_structures.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 * Gordon Bailey (gb@gordonbailey.net)
18 *
19 */
20
104
105#ifndef BM_BM_SIM_LOOKUP_STRUCTURES_H_
106#define BM_BM_SIM_LOOKUP_STRUCTURES_H_
107
108#include <memory>
109
110#include "match_key_types.h"
111#include "bytecontainer.h"
112
113namespace bm {
114
119template <typename K>
121 public:
122 virtual ~LookupStructure() = default;
123
127 virtual bool lookup(const ByteContainer &key_data,
128 internal_handle_t *handle) const = 0;
129
134 virtual bool entry_exists(const K &key) const = 0;
135
139 virtual bool retrieve_handle(const K &key,
140 internal_handle_t *handle) const = 0;
141
144 virtual void add_entry(const K &key, internal_handle_t handle) = 0;
145
148 virtual void delete_entry(const K &key) = 0;
149
151 virtual void clear() = 0;
152};
153
154// Convenience alias declarations to simplify the code needed to override
155// LookupStructure and LookupStructureFactory
160
168 public:
169 explicit LookupStructureFactory(bool enable_ternary_cache = true);
170
171 virtual ~LookupStructureFactory() = default;
172
176 template <typename K>
177 static std::unique_ptr<LookupStructure<K> > create(
178 LookupStructureFactory *f, size_t size, size_t nbytes_key);
179
181 virtual std::unique_ptr<ExactLookupStructure>
182 create_for_exact(size_t size, size_t nbytes_key);
183
185 virtual std::unique_ptr<LPMLookupStructure>
186 create_for_LPM(size_t size, size_t nbytes_key);
187
189 virtual std::unique_ptr<TernaryLookupStructure>
190 create_for_ternary(size_t size, size_t nbytes_key);
191
193 virtual std::unique_ptr<RangeLookupStructure>
194 create_for_range(size_t size, size_t nbytes_key);
195
196 private:
197 bool enable_ternary_cache;
198};
199
200
201} // namespace bm
202
203
204#endif // BM_BM_SIM_LOOKUP_STRUCTURES_H_
Definition bytecontainer.h:39
Definition lookup_structures.h:167
virtual std::unique_ptr< ExactLookupStructure > create_for_exact(size_t size, size_t nbytes_key)
Create a lookup structure for exact matches.
static std::unique_ptr< LookupStructure< K > > create(LookupStructureFactory *f, size_t size, size_t nbytes_key)
virtual std::unique_ptr< LPMLookupStructure > create_for_LPM(size_t size, size_t nbytes_key)
Create a lookup structure for LPM matches.
virtual std::unique_ptr< TernaryLookupStructure > create_for_ternary(size_t size, size_t nbytes_key)
Create a lookup structure for ternary matches.
virtual std::unique_ptr< RangeLookupStructure > create_for_range(size_t size, size_t nbytes_key)
Create a lookup structure for range macthes.
Definition lookup_structures.h:120
virtual bool retrieve_handle(const K &key, internal_handle_t *handle) const =0
virtual bool lookup(const ByteContainer &key_data, internal_handle_t *handle) const =0
virtual void delete_entry(const K &key)=0
virtual bool entry_exists(const K &key) const =0
virtual void add_entry(const K &key, internal_handle_t handle)=0
virtual void clear()=0
Completely remove all entries from the data structure.