Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
fec_base.h
1 /*
2  * Copyright (c) 2021 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <hicn/transport/core/content_object.h>
19 #include <hicn/transport/errors/not_implemented_exception.h>
20 
21 #include <functional>
22 
23 namespace transport {
24 namespace protocol {
25 
26 namespace fec {
27 
28 using buffer = typename utils::MemBuf::Ptr;
29 using BufferArray = std::vector<std::pair<uint32_t, buffer>>;
30 
31 class FECBase {
32  public:
33  virtual ~FECBase() = default;
38  using PacketsReady = std::function<void(BufferArray &)>;
39 
44  using BufferRequested = std::function<buffer(std::size_t size)>;
45 
49  virtual std::size_t getFecHeaderSize() = 0;
50 
54  template <typename Handler>
55  void setFECCallback(Handler &&callback) {
56  fec_callback_ = std::forward<Handler>(callback);
57  }
58 
62  template <typename Handler>
63  void setBufferCallback(Handler &&buffer_callback) {
64  buffer_callback_ = buffer_callback;
65  }
66 
67  virtual void reset() = 0;
68 
69  protected:
70  PacketsReady fec_callback_{0};
71  BufferRequested buffer_callback_{0};
72 };
73 
77 class ProducerFEC : public virtual FECBase {
78  public:
79  virtual ~ProducerFEC() = default;
83  virtual void onPacketProduced(core::ContentObject &content_object,
84  uint32_t offset) = 0;
85 };
86 
90 class ConsumerFEC : public virtual FECBase {
91  public:
92  virtual ~ConsumerFEC() = default;
93 
97  virtual void onDataPacket(core::ContentObject &content_object,
98  uint32_t offset) = 0;
99 };
100 
101 } // namespace fec
102 } // namespace protocol
103 } // namespace transport
transport::protocol::fec::ProducerFEC
Definition: fec_base.h:77
transport::protocol::fec::ProducerFEC::onPacketProduced
virtual void onPacketProduced(core::ContentObject &content_object, uint32_t offset)=0
transport::protocol::fec::FECBase::PacketsReady
std::function< void(BufferArray &)> PacketsReady
Definition: fec_base.h:38
transport::protocol::fec::FECBase::setBufferCallback
void setBufferCallback(Handler &&buffer_callback)
Definition: fec_base.h:63
transport::core::ContentObject
Definition: content_object.h:29
transport::protocol::fec::ConsumerFEC
Definition: fec_base.h:90
transport::protocol::fec::FECBase
Definition: fec_base.h:31
transport::protocol::fec::FECBase::BufferRequested
std::function< buffer(std::size_t size)> BufferRequested
Definition: fec_base.h:44
transport
Definition: forwarder_config.h:32
transport::protocol::fec::FECBase::setFECCallback
void setFECCallback(Handler &&callback)
Definition: fec_base.h:55
transport::protocol::fec::ConsumerFEC::onDataPacket
virtual void onDataPacket(core::ContentObject &content_object, uint32_t offset)=0
transport::protocol::fec::FECBase::getFecHeaderSize
virtual std::size_t getFecHeaderSize()=0
Get size of FEC header.