Retrieves an ExactMatchConfig that would restore this module's runtime configuration.
| 148 | // Retrieves an ExactMatchConfig that would restore this module's |
| 149 | // runtime configuration. |
| 150 | CommandResponse ExactMatch::GetRuntimeConfig(const bess::pb::EmptyArg &) { |
| 151 | bess::pb::ExactMatchConfig r; |
| 152 | using rule_t = bess::pb::ExactMatchCommandAddArg; |
| 153 | |
| 154 | r.set_default_gate(default_gate_); |
| 155 | for (auto const &kv : table_) { |
| 156 | auto const &key = kv.first; |
| 157 | auto const &value = kv.second; |
| 158 | rule_t *rule = r.add_rules(); |
| 159 | |
| 160 | rule->set_gate(value); |
| 161 | for (size_t i = 0; i < table_.num_fields(); i++) { |
| 162 | const ExactMatchField &f = table_.get_field(i); |
| 163 | bess::pb::FieldData *field = rule->add_fields(); |
| 164 | |
| 165 | // See GetInitialArg above for why we only set_value_bin here. |
| 166 | const char *ptr = reinterpret_cast<const char *>(&key.u64_arr[0]); |
| 167 | field->set_value_bin(ptr + f.pos, f.size); |
| 168 | } |
| 169 | } |
| 170 | std::sort(r.mutable_rules()->begin(), r.mutable_rules()->end(), |
| 171 | [this](const rule_t &a, const rule_t &b) { |
| 172 | // Primary sort key is gate number. |
| 173 | if (a.gate() != b.gate()) { |
| 174 | return a.gate() < b.gate(); |
| 175 | } |
| 176 | // After that, sort by value-to-be-matched, in field order. |
| 177 | for (size_t i = 0; i < table_.num_fields(); i++) { |
| 178 | if (a.fields(i).value_bin() != b.fields(i).value_bin()) { |
| 179 | return a.fields(i).value_bin() < b.fields(i).value_bin(); |
| 180 | } |
| 181 | } |
| 182 | // Huh: a, b exactly equal - should not happen unless |
| 183 | // std::sort() is poor. |
| 184 | return false; |
| 185 | }); |
| 186 | return CommandSuccess(r); |
| 187 | } |
| 188 | |
| 189 | Error ExactMatch::AddRule(const bess::pb::ExactMatchCommandAddArg &arg) { |
| 190 | gate_idx_t gate = arg.gate(); |
nothing calls this directly
no test coverage detected