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

Method CommandUpdate

core/modules/flowgen.cc:277–347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275}
276
277CommandResponse FlowGen::CommandUpdate(const bess::pb::FlowGenArg &arg) {
278 if (arg.template_().length() > 0) {
279 LOG(INFO) << "Updating FlowGen template";
280 if (arg.template_().length() > MAX_TEMPLATE_SIZE) {
281 return CommandFailure(EINVAL, "'template' is too big");
282 }
283 template_size_ = arg.template_().length();
284
285 memset(templ_, 0, MAX_TEMPLATE_SIZE);
286 bess::utils::Copy(templ_, arg.template_().c_str(), template_size_);
287 }
288
289 double prev_pps = 0;
290 if (!(std::isnan(arg.pps()) || arg.pps() == 0.0)) {
291 if (arg.pps() < 0) {
292 return CommandFailure(EINVAL, "pps cannot be negative");
293 }
294
295 LOG(INFO) << "Updating FlowGen pps" << arg.pps();
296 prev_pps = total_pps_;
297 total_pps_ = arg.pps();
298 }
299
300 double prev_flowrate = 0;
301 if (!(std::isnan(arg.flow_rate()) || arg.flow_rate() == 0.0)) {
302 if (arg.flow_rate() < 0) {
303 return CommandFailure(EINVAL, "flow rate cannot be negative");
304 }
305
306 LOG(INFO) << "Updating FlowGen flow rate" << arg.flow_rate();
307
308 prev_flowrate = flow_rate_;
309 flow_rate_ = arg.flow_rate();
310 }
311
312 if (flow_rate_ > total_pps_) {
313 flow_rate_ = prev_flowrate;
314 total_pps_ = prev_pps;
315 return CommandFailure(EINVAL, "flow rate cannot be more than pps");
316 }
317
318 if (!(std::isnan(arg.flow_duration()) || arg.flow_duration() == 0.0)) {
319 if (arg.flow_duration() < 0) {
320 return CommandFailure(EINVAL, "flow duration cannot be negative");
321 }
322
323 LOG(INFO) << "Updating FlowGen flow duration" << arg.flow_duration();
324 flow_duration_ = arg.flow_duration();
325 }
326
327 if (arg.arrival() == "uniform") {
328 arrival_ = Arrival::kUniform;
329 } else if (arg.arrival() == "exponential") {
330 arrival_ = Arrival::kExponential;
331 } else if (arg.arrival() != "") {
332 return CommandFailure(EINVAL, "arrival must be 'uniform' or 'exponential'");
333 }
334

Callers

nothing calls this directly

Calls 3

CommandFailureFunction · 0.85
CopyFunction · 0.85
CommandSuccessFunction · 0.85

Tested by

no test coverage detected