19 #include <arpa/inet.h>
20 #include <hicn/transport/portability/c_portability.h>
21 #include <hicn/transport/utils/membuf.h>
22 #include <protocols/fec/fec_info.h>
23 #include <protocols/fec_base.h>
28 #include <unordered_set>
36 #define foreach_rs_fec_type \
67 static const constexpr uint16_t MAX_SOURCE_BLOCK_SIZE = 128;
76 using Packets = std::array<std::tuple< uint32_t, buffer,
78 MAX_SOURCE_BLOCK_SIZE>;
109 void setSeqNumberBase(uint32_t suffix) {
seq_number = htonl(suffix); }
110 uint32_t getSeqNumberBase() {
return ntohl(
seq_number); }
129 static constexpr std::size_t LEN_SIZE_BYTES = 2;
139 uint32_t offset = 0);
145 uint32_t offset = 0);
150 std::size_t
length() {
return current_block_size_; }
171 bool addSymbol(
const fec::buffer &packet, uint32_t i, uint32_t offset,
190 uint32_t seq_offset_;
192 std::size_t max_buffer_size_;
193 std::size_t current_block_size_;
194 std::vector<uint32_t> sorted_index_;
217 struct MatrixDeleter {
218 void operator()(
struct fec_parms *params);
225 using Matrix = std::unique_ptr<struct fec_parms, MatrixDeleter>;
231 using Code = std::pair<std::uint32_t , std::uint32_t >;
237 std::size_t operator()(
const Code &code)
const {
238 uint64_t ret = uint64_t(code.first) << 32 | uint64_t(code.second);
239 return std::hash<uint64_t>{}(ret);
265 using Codes = std::unordered_map<Code, Matrix, CodeHasher>;
268 rs(uint32_t k, uint32_t n, uint32_t seq_offset = 0);
273 bool isSymbol(uint32_t index) {
return ((index - seq_offset_) % n_) >= k_; }
279 static Codes createCodes();
282 bool processed(
SNBase seq_base) {
287 void setProcessed(
SNBase seq_base) {
293 std::uint32_t seq_offset_;
309 RSEncoder(uint32_t k, uint32_t n, uint32_t seq_offset = 0);
313 void consume(
const fec::buffer &packet, uint32_t index, uint32_t offset = 0);
316 uint32_t offset)
override;
323 void clear()
override {
325 source_block_.
clear();
328 void reset()
override { clear(); }
337 BlockCode source_block_;
346 RSDecoder(uint32_t k, uint32_t n, uint32_t seq_offset = 0);
352 uint32_t offset = 0);
357 void consumeRepair(
const fec::buffer &packet, uint32_t offset = 0);
363 uint32_t offset)
override;
376 parked_packets_.clear();
379 void reset()
override {
clear(); }
382 void recoverPackets(SourceBlocks::iterator &src_block_it);
401 std::unordered_map<uint32_t, std::vector<std::pair<buffer, uint32_t>>>