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

Method CommandAdd

sample_plugin/modules/sequential_update.cc:47–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47CommandResponse SequentialUpdate::CommandAdd(
48 const sample::supdate::pb::SequentialUpdateArg &arg) {
49 size_t curr = num_vars_;
50 if (curr + arg.fields_size() > kMaxVariable) {
51 return CommandFailure(EINVAL, "max %zu variables can be specified",
52 kMaxVariable);
53 }
54
55 for (int i = 0; i < arg.fields_size(); i++) {
56 const auto &var = arg.fields(i);
57
58 size_t size;
59 size_t offset;
60 be32_t mask;
61 uint32_t min;
62 uint32_t max;
63
64 offset = var.offset();
65 size = var.size();
66 min = var.min();
67 max = var.max();
68
69 switch (size) {
70 case 1:
71 mask = be32_t(0x00ffffff);
72 min = std::min(min, static_cast<uint32_t>(0xff));
73 max = std::min(max, static_cast<uint32_t>(0xff));
74 break;
75
76 case 2:
77 mask = be32_t(0x0000ffff);
78 min = std::min(min, static_cast<uint32_t>(0xffff));
79 max = std::min(max, static_cast<uint32_t>(0xffff));
80 break;
81
82 case 4:
83 mask = be32_t(0x00000000);
84 min = std::min(min, static_cast<uint32_t>(0xffffffffu));
85 max = std::min(max, static_cast<uint32_t>(0xffffffffu));
86 break;
87
88 default:
89 return CommandFailure(EINVAL, "'size' must be 1, 2, or 4");
90 }
91
92 if (offset + size > SNBUF_DATA) {
93 return CommandFailure(EINVAL, "too large 'offset'");
94 }
95
96 if (min > max) {
97 return CommandFailure(EINVAL, "'min' should not be greater than 'max'");
98 }
99
100 vars_[curr + i].offset = offset;
101 vars_[curr + i].mask = mask;
102 vars_[curr + i].min = min;
103
104 // avoid modulo 0

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected