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

Method CommandAdd

core/modules/update.cc:68–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68CommandResponse Update::CommandAdd(const bess::pb::UpdateArg &arg) {
69 size_t curr = num_fields_;
70
71 if (curr + arg.fields_size() > kMaxFields) {
72 return CommandFailure(EINVAL, "max %zu variables can be specified",
73 kMaxFields);
74 }
75
76 for (int i = 0; i < arg.fields_size(); i++) {
77 const auto &field = arg.fields(i);
78
79 size_t size = field.size();
80 if (size < 1 || size > 8) {
81 return CommandFailure(EINVAL, "'size' must be 1-8");
82 }
83
84 if (field.offset() + size > SNBUF_DATA) {
85 return CommandFailure(EINVAL, "too large 'offset'");
86 }
87
88 be64_t value(field.value() << ((8 - size) * 8));
89 be64_t mask((1ull << ((8 - size) * 8)) - 1);
90
91 if ((value & mask).value() != 0) {
92 LOG(INFO) << value << ' ' << mask;
93 return CommandFailure(
94 EINVAL, "'value' field has not a correct %zu-byte value", size);
95 }
96
97 fields_[curr + i].offset = field.offset();
98 fields_[curr + i].mask = mask;
99 fields_[curr + i].value = value;
100 }
101
102 num_fields_ = curr + arg.fields_size();
103 return CommandSuccess();
104}
105
106CommandResponse Update::CommandClear(const bess::pb::EmptyArg &) {
107 num_fields_ = 0;

Callers

nothing calls this directly

Calls 5

CommandFailureFunction · 0.85
CommandSuccessFunction · 0.85
sizeMethod · 0.80
offsetMethod · 0.80
valueMethod · 0.80

Tested by

no test coverage detected