MCPcopy Create free account
hub / github.com/NetSys/bess / CommandAdd

Method CommandAdd

core/modules/rewrite.cc:48–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48CommandResponse 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
84CommandResponse Rewrite::CommandClear(const bess::pb::EmptyArg &) {
85 next_turn_ = 0;

Callers

nothing calls this directly

Calls 3

CommandFailureFunction · 0.85
CopyFunction · 0.85
CommandSuccessFunction · 0.85

Tested by

no test coverage detected