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

Method AddFieldOne

core/modules/generic_encap.cc:44–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42#endif
43
44CommandResponse GenericEncap::AddFieldOne(
45 const bess::pb::GenericEncapArg_EncapField &field, struct Field *f,
46 int idx) {
47 f->size = field.size();
48 if (f->size < 1 || f->size > MAX_FIELD_SIZE) {
49 return CommandFailure(EINVAL, "idx %d: 'size' must be 1-%d", idx,
50 MAX_FIELD_SIZE);
51 }
52
53 if (field.insertion_case() ==
54 bess::pb::GenericEncapArg_EncapField::kAttribute) {
55 const char *attr = field.attribute().c_str();
56 f->attr_id = AddMetadataAttr(attr, f->size,
57 bess::metadata::Attribute::AccessMode::kRead);
58 if (f->attr_id < 0) {
59 return CommandFailure(-f->attr_id, "idx %d: add_metadata_attr() failed",
60 idx);
61 }
62 } else if (field.insertion_case() ==
63 bess::pb::GenericEncapArg_EncapField::kValue) {
64 f->attr_id = -1;
65 if (field.value().encoding_case() == bess::pb::FieldData::kValueInt) {
66 if (!bess::utils::uint64_to_bin(&f->value, field.value().value_int(),
67 f->size, 1)) {
68 return CommandFailure(EINVAL,
69 "idx %d: "
70 "not a correct %d-byte value",
71 idx, f->size);
72 }
73 } else if (field.value().encoding_case() ==
74 bess::pb::FieldData::kValueBin) {
75 if (field.value().value_bin().size() != (size_t)f->size) {
76 return CommandFailure(EINVAL, "idx %d: not a correct %d-byte mask", idx,
77 f->size);
78 }
79 bess::utils::Copy(reinterpret_cast<uint8_t *>(&(f->value)),
80 field.value().value_bin().c_str(),
81 field.value().value_bin().size());
82 }
83 } else {
84 return CommandFailure(EINVAL, "idx %d: must specify 'value' or 'attribute'",
85 idx);
86 }
87
88 return CommandSuccess();
89}
90
91/* Takes a list of fields. Each field is either:
92 *

Callers

nothing calls this directly

Calls 6

CommandFailureFunction · 0.85
uint64_to_binFunction · 0.85
CopyFunction · 0.85
CommandSuccessFunction · 0.85
sizeMethod · 0.80
valueMethod · 0.80

Tested by

no test coverage detected