This file contains 2 classes: bm::LookupStructure and bm::LookupStructureFactory. When implementing your target, you may wish to provide custom implementations of the data structures used to perform matches. This can be done by inheriting from one or more of bm::ExactLookupStructure, bm::LPMMatchStructure, and bm::TernaryMatchStructure. Each of these is a specialization of the bm::LookupStructure template for the corresponding match key type.
Once the implementation of the new lookup structure is complete, you must extend the bm::LookupStructureFactory class to build instances of it. This is relatively simple. An (abridged) example of creating a new bm::Switch using a custom lookup structure is as follows
public:
virtual ~MyExactLookupStructure() = default;
bm::internal_handle_t *handle) const override {
}
bool entry_exists(
const bm::ExactMatchKey &key)
const override {
}
bm::internal_handle_t handle) override {
}
}
}
private:
};
public:
virtual ~MyFactory() = default;
std::unique_ptr<bm::ExactLookupStructure>
return std::unique_ptr<bm::ExactLookupStructure>(
new MyExactLookupStructure());
}
};
};
int main(int argc, const char *argv[]) {
auto switch = new MySwitch();
switch->set_lookup_factory(std::shared_ptr<bm::LookupStructureFactory>(
new MyFactory()));
int status = switch->init_from_command_line(argc, argv);
}
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.
Definition lookup_structures.h:120
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.