bmv2
Designing your own switch target with bmv2
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 
113 namespace bm {
114 
119 template <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_
bm::LookupStructure
Definition: lookup_structures.h:120
bm::LookupStructure::delete_entry
virtual void delete_entry(const K &key)=0
bm::LookupStructure::retrieve_handle
virtual bool retrieve_handle(const K &key, internal_handle_t *handle) const =0
bytecontainer.h
bm::ByteContainer
Definition: bytecontainer.h:39
bm::LookupStructureFactory::create_for_ternary
virtual std::unique_ptr< TernaryLookupStructure > create_for_ternary(size_t size, size_t nbytes_key)
Create a lookup structure for ternary matches.
bm::LookupStructureFactory::create_for_range
virtual std::unique_ptr< RangeLookupStructure > create_for_range(size_t size, size_t nbytes_key)
Create a lookup structure for range macthes.
bm::LookupStructure::entry_exists
virtual bool entry_exists(const K &key) const =0
bm::LookupStructureFactory
Definition: lookup_structures.h:167
bm::LookupStructure::add_entry
virtual void add_entry(const K &key, internal_handle_t handle)=0
bm::LookupStructureFactory::create_for_exact
virtual std::unique_ptr< ExactLookupStructure > create_for_exact(size_t size, size_t nbytes_key)
Create a lookup structure for exact matches.
bm::LookupStructure::lookup
virtual bool lookup(const ByteContainer &key_data, internal_handle_t *handle) const =0
bm::LookupStructure::clear
virtual void clear()=0
Completely remove all entries from the data structure.
bm::LookupStructureFactory::create
static std::unique_ptr< LookupStructure< K > > create(LookupStructureFactory *f, size_t size, size_t nbytes_key)
bm::LookupStructureFactory::create_for_LPM
virtual std::unique_ptr< LPMLookupStructure > create_for_LPM(size_t size, size_t nbytes_key)
Create a lookup structure for LPM matches.