21 #ifndef BM_BM_SIM_ENTRIES_H_
22 #define BM_BM_SIM_ENTRIES_H_
29 #include "control_flow.h"
33 class ControlFlowNode;
37 ActionFnEntry action_entry{};
38 const ControlFlowNode *next_table{
nullptr};
42 MatchEntry(ByteContainer key,
43 ActionFnEntry action_entry,
44 const ControlFlowNode *next_table)
45 : key(std::move(key)), action_entry(std::move(action_entry)),
46 next_table(next_table) {}
48 MatchEntry(
const MatchEntry &other) =
delete;
49 MatchEntry &operator=(
const MatchEntry &other) =
delete;
51 MatchEntry(MatchEntry &&other) =
default;
52 MatchEntry &operator=(MatchEntry &&other) =
default;
55 struct ExactMatchEntry: MatchEntry {
59 ExactMatchEntry(ByteContainer key,
60 ActionFnEntry action_entry,
61 const ControlFlowNode *next_table)
62 : MatchEntry(std::move(key), std::move(action_entry), next_table) {}
65 struct LongestPrefixMatchEntry : MatchEntry {
68 LongestPrefixMatchEntry()
71 LongestPrefixMatchEntry(ByteContainer key,
72 ActionFnEntry action_entry,
73 unsigned int prefix_length,
74 const ControlFlowNode *next_table)
75 : MatchEntry(std::move(key), std::move(action_entry), next_table),
76 prefix_length(prefix_length) {
77 unsigned byte_index = prefix_length / 8;
78 unsigned mod = prefix_length % 8;
81 this->key[byte_index] &= ~(0xFF >> mod);
83 for (; byte_index < key.size(); byte_index++) {
84 this->key[byte_index] = 0;
89 struct TernaryMatchEntry : MatchEntry {
96 TernaryMatchEntry(ByteContainer key, ActionFnEntry action_entry,
97 ByteContainer mask,
int priority,
98 const ControlFlowNode *next_table)
99 : MatchEntry(std::move(key), std::move(action_entry), next_table),
100 mask(std::move(mask)), priority(priority) {
101 for (
unsigned byte_index = 0; byte_index < key.size(); byte_index++) {
102 this->key[byte_index] &= mask[byte_index];
109 #endif // BM_BM_SIM_ENTRIES_H_