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

Method Init

core/modules/split.cc:36–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34#include "../utils/endian.h"
35
36CommandResponse Split::Init(const bess::pb::SplitArg &arg) {
37 size_ = arg.size();
38 if (size_ < 1 || size_ > sizeof(uint64_t)) {
39 return CommandFailure(EINVAL, "'size' must be 1-%zu", sizeof(uint64_t));
40 }
41
42 mask_ = bess::utils::SetBitsHigh<uint64_t>(size_ * 8);
43
44 // We read a be64_t value regardless of the actual size,
45 // hence the read value needs bit shift to the right.
46 shift_ = 64 - (size_ * 8);
47
48 if (arg.type_case() == bess::pb::SplitArg::kAttribute) {
49 attr_id_ = AddMetadataAttr(arg.attribute().c_str(), size_,
50 bess::metadata::Attribute::AccessMode::kRead);
51 if (attr_id_ < 0) {
52 return CommandFailure(-attr_id_, "add_metadata_attr() failed");
53 }
54 } else {
55 attr_id_ = -1;
56 offset_ = arg.offset();
57 if (offset_ > 1024) {
58 return CommandFailure(EINVAL, "invalid 'offset'");
59 }
60 }
61 return CommandSuccess();
62}
63
64void Split::ProcessBatch(Context *ctx, bess::PacketBatch *batch) {
65 using bess::utils::be64_t;

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected