| 34 | #include "../utils/endian.h" |
| 35 | |
| 36 | CommandResponse 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 | |
| 64 | void Split::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { |
| 65 | using bess::utils::be64_t; |
nothing calls this directly
no test coverage detected