summaryrefslogtreecommitdiffstats
path: root/libtransport/src/protocols/fec_base.h
diff options
context:
space:
mode:
authorMauro <you@example.com>2021-06-30 07:57:22 +0000
committerMauro Sardara <msardara@cisco.com>2021-07-06 16:16:04 +0000
commit08233d44a6cfde878d7e10bca38ae935ed1c8fd5 (patch)
tree7ecc534d55bdc7e8dd15ecab084720910bcdf4d9 /libtransport/src/protocols/fec_base.h
parent147ba39bed26887f5eba84757e2463ab8e370a9a (diff)
[HICN-713] Transport Library Major Refactoring 2
Co-authored-by: Luca Muscariello <muscariello@ieee.org> Co-authored-by: Michele Papalini <micpapal@cisco.com> Co-authored-by: Olivier Roques <oroques+fdio@cisco.com> Co-authored-by: Giulio Grassi <gigrassi@cisco.com> Signed-off-by: Mauro Sardara <msardara@cisco.com> Change-Id: I5b2c667bad66feb45abdb5effe22ed0f6c85d1c2
Diffstat (limited to 'libtransport/src/protocols/fec_base.h')
-rw-r--r--libtransport/src/protocols/fec_base.h85
1 files changed, 51 insertions, 34 deletions
diff --git a/libtransport/src/protocols/fec_base.h b/libtransport/src/protocols/fec_base.h
index a135c474f..a1929d85e 100644
--- a/libtransport/src/protocols/fec_base.h
+++ b/libtransport/src/protocols/fec_base.h
@@ -16,71 +16,88 @@
#pragma once
#include <hicn/transport/core/content_object.h>
+#include <hicn/transport/errors/not_implemented_exception.h>
#include <functional>
namespace transport {
namespace protocol {
-/**
- * Interface classes to integrate FEC inside any producer transport protocol
- */
-class ProducerFECBase {
+namespace fec {
+
+using buffer = typename utils::MemBuf::Ptr;
+using BufferArray = std::vector<std::pair<uint32_t, buffer>>;
+
+class FECBase {
public:
+ virtual ~FECBase() = default;
/**
- * Callback, to be called by implementations as soon as a repair packet is
- * ready.
+ * Callback to be called after the encode or the decode operations. In the
+ * former case it will contain the symbols, while in the latter the sources.
*/
- using RepairPacketsReady =
- std::function<void(std::vector<core::ContentObject::Ptr> &)>;
+ using PacketsReady = std::function<void(BufferArray &)>;
/**
- * Producers will call this function upon production of a new packet.
+ * Callback to be called when a new buffer (for encoding / decoding) needs to
+ * be allocated.
*/
- virtual void onPacketProduced(const core::ContentObject &content_object) = 0;
+ using BufferRequested = std::function<buffer(std::size_t size)>;
/**
- * Set callback to signal production protocol the repair packet is ready.
+ * @brief Get size of FEC header.
*/
- void setFECCallback(const RepairPacketsReady &on_repair_packet) {
- rep_packet_ready_callback_ = on_repair_packet;
+ virtual std::size_t getFecHeaderSize() = 0;
+
+ /**
+ * Set callback to call after packet encoding / decoding
+ */
+ template <typename Handler>
+ void setFECCallback(Handler &&callback) {
+ fec_callback_ = std::forward<Handler>(callback);
}
+ /**
+ * Set a callback to request a buffer.
+ */
+ template <typename Handler>
+ void setBufferCallback(Handler &&buffer_callback) {
+ buffer_callback_ = buffer_callback;
+ }
+
+ virtual void reset() = 0;
+
protected:
- RepairPacketsReady rep_packet_ready_callback_;
+ PacketsReady fec_callback_{0};
+ BufferRequested buffer_callback_{0};
};
/**
- * Interface classes to integrate FEC inside any consumer transport protocol
+ * Interface classes to integrate FEC inside any producer transport protocol
*/
-class ConsumerFECBase {
+class ProducerFEC : public virtual FECBase {
public:
+ virtual ~ProducerFEC() = default;
/**
- * Callback, to be called by implemrntations as soon as a packet is recovered.
+ * Producers will call this function upon production of a new packet.
*/
- using OnPacketsRecovered =
- std::function<void(std::vector<core::ContentObject::Ptr> &)>;
+ virtual void onPacketProduced(core::ContentObject &content_object,
+ uint32_t offset) = 0;
+};
- /**
- * Consumers will call this function when they receive a FEC packet.
- */
- virtual void onFECPacket(const core::ContentObject &content_object) = 0;
+/**
+ * Interface classes to integrate FEC inside any consumer transport protocol
+ */
+class ConsumerFEC : public virtual FECBase {
+ public:
+ virtual ~ConsumerFEC() = default;
/**
* Consumers will call this function when they receive a data packet
*/
- virtual void onDataPacket(const core::ContentObject &content_object) = 0;
-
- /**
- * Set callback to signal consumer protocol the repair packet is ready.
- */
- void setFECCallback(const OnPacketsRecovered &on_repair_packet) {
- packet_recovered_callback_ = on_repair_packet;
- }
-
- protected:
- OnPacketsRecovered packet_recovered_callback_;
+ virtual void onDataPacket(core::ContentObject &content_object,
+ uint32_t offset) = 0;
};
+} // namespace fec
} // namespace protocol
} // namespace transport \ No newline at end of file