| 126 | } |
| 127 | |
| 128 | void GenericEncap::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { |
| 129 | int cnt = batch->cnt(); |
| 130 | |
| 131 | int encap_size = encap_size_; |
| 132 | |
| 133 | char headers[bess::PacketBatch::kMaxBurst][MAX_HEADER_SIZE] __ymm_aligned; |
| 134 | |
| 135 | for (int i = 0; i < num_fields_; i++) { |
| 136 | uint64_t value = fields_[i].value; |
| 137 | |
| 138 | int attr_id = fields_[i].attr_id; |
| 139 | int offset = (attr_id >= 0) ? attr_offset(attr_id) : 0; |
| 140 | |
| 141 | char *header = headers[0] + fields_[i].pos; |
| 142 | |
| 143 | for (int j = 0; j < cnt; j++, header += MAX_HEADER_SIZE) { |
| 144 | bess::Packet *pkt = batch->pkts()[j]; |
| 145 | *(reinterpret_cast<uint64_t *>(header)) = |
| 146 | (attr_id < 0) ? value : get_attr_with_offset<uint64_t>(offset, pkt); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | for (int i = 0; i < cnt; i++) { |
| 151 | bess::Packet *pkt = batch->pkts()[i]; |
| 152 | |
| 153 | char *p = static_cast<char *>(pkt->prepend(encap_size)); |
| 154 | |
| 155 | if (unlikely(!p)) { |
| 156 | continue; |
| 157 | } |
| 158 | |
| 159 | bess::utils::CopyInlined(p, headers[i], encap_size); |
| 160 | } |
| 161 | |
| 162 | RunNextModule(ctx, batch); |
| 163 | } |
| 164 | |
| 165 | ADD_MODULE(GenericEncap, "generic_encap", |
| 166 | "encapsulates packets with constant values and metadata attributes") |
nothing calls this directly
no test coverage detected