| 46 | } |
| 47 | |
| 48 | CommandResponse Rewrite::CommandAdd(const bess::pb::RewriteArg &arg) { |
| 49 | size_t curr = num_templates_; |
| 50 | |
| 51 | if (curr + arg.templates_size() > bess::PacketBatch::kMaxBurst) { |
| 52 | return CommandFailure(EINVAL, "max %zu packet templates can be used %zu %d", |
| 53 | bess::PacketBatch::kMaxBurst, curr, |
| 54 | arg.templates_size()); |
| 55 | } |
| 56 | |
| 57 | for (int i = 0; i < arg.templates_size(); i++) { |
| 58 | const auto &templ = arg.templates(i); |
| 59 | |
| 60 | if (templ.length() > kMaxTemplateSize) { |
| 61 | return CommandFailure(EINVAL, "template is too big"); |
| 62 | } |
| 63 | |
| 64 | memset(templates_[curr + i], 0, kMaxTemplateSize); |
| 65 | bess::utils::Copy(templates_[curr + i], templ.c_str(), templ.length()); |
| 66 | template_size_[curr + i] = templ.length(); |
| 67 | } |
| 68 | |
| 69 | num_templates_ = curr + arg.templates_size(); |
| 70 | if (num_templates_ == 0) { |
| 71 | return CommandSuccess(); |
| 72 | } |
| 73 | |
| 74 | for (size_t i = num_templates_; i < kNumSlots; i++) { |
| 75 | size_t j = i % num_templates_; |
| 76 | bess::utils::Copy(templates_[i], templates_[j], template_size_[j]); |
| 77 | template_size_[i] = template_size_[j]; |
| 78 | jump_[i] = j; |
| 79 | } |
| 80 | |
| 81 | return CommandSuccess(); |
| 82 | } |
| 83 | |
| 84 | CommandResponse Rewrite::CommandClear(const bess::pb::EmptyArg &) { |
| 85 | next_turn_ = 0; |
nothing calls this directly
no test coverage detected