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

Method CommandAdd

core/modules/random_update.cc:46–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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