39 , m_linkService(linkService)
43 std::tuple<bool, Block, lp::Packet>
48 static auto FALSE_RETURN = std::make_tuple(
false,
Block(),
lp::Packet());
51 uint64_t fragIndex = 0;
52 uint64_t fragCount = 1;
60 if (fragIndex >= fragCount) {
71 if (fragIndex == 0 && fragCount == 1) {
73 Block netPkt({frag.first, frag.second});
74 return {
true, netPkt, packet};
83 Key key = std::make_tuple(remoteEndpoint, messageIdentifier);
86 PartialPacket& pp = m_partialPackets[key];
87 if (pp.fragCount == 0) {
88 pp.fragCount = fragCount;
89 pp.nReceivedFragments = 0;
90 pp.fragments.resize(fragCount);
93 if (fragCount != pp.fragCount) {
104 pp.fragments[fragIndex] = packet;
105 ++pp.nReceivedFragments;
108 if (pp.nReceivedFragments == pp.fragCount) {
109 Block reassembled = doReassembly(key);
111 m_partialPackets.erase(key);
112 return std::make_tuple(
true, reassembled, firstFrag);
122 LpReassembler::doReassembly(
const Key& key)
124 PartialPacket& pp = m_partialPackets[key];
126 size_t payloadSize = std::accumulate(pp.fragments.begin(), pp.fragments.end(), 0U,
127 [&] (
size_t sum,
const lp::Packet& pkt) ->
size_t {
128 ndn::Buffer::const_iterator fragBegin, fragEnd;
130 return sum + std::distance(fragBegin, fragEnd);
134 auto it = fragBuffer.begin();
137 ndn::Buffer::const_iterator fragBegin, fragEnd;
139 it = std::copy(fragBegin, fragEnd, it);
142 return Block(fragBuffer);
146 LpReassembler::timeoutPartialPacket(
const Key& key)
148 auto it = m_partialPackets.find(key);
149 if (it == m_partialPackets.end()) {
153 this->
beforeTimeout(std::get<0>(key), it->second.nReceivedFragments);
154 m_partialPackets.erase(it);
158 operator<<(std::ostream& os, const FaceLogHelper<LpReassembler>& flh)
160 if (flh.obj.getLinkService() ==
nullptr) {
161 os <<
"[id=0,local=unknown,remote=unknown] ";
164 os << FaceLogHelper<LinkService>(*flh.obj.getLinkService());
NDN_CXX_NODISCARD bool has() const
Options that control the behavior of LpReassembler.
#define NFD_LOG_INIT(name)
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
signal::Signal< LpReassembler, EndpointId, size_t > beforeTimeout
signals before a partial packet is dropped due to timeout
Represents a TLV element of the NDN packet format.
uint64_t EndpointId
Identifies a remote endpoint on the link.
uint64_t Sequence
represents a sequence number
Scheduler & getScheduler()
Returns the global Scheduler instance for the calling thread.
FIELD::ValueType get(size_t index=0) const
std::tuple< bool, Block, lp::Packet > receiveFragment(EndpointId remoteEndpoint, const lp::Packet &packet)
adds received fragment to the buffer
Copyright (c) 2011-2015 Regents of the University of California.
reassembles fragmented network-layer packets
LpReassembler(const Options &options, const LinkService *linkService=nullptr)
time::nanoseconds reassemblyTimeout
timeout before a partially reassembled packet is dropped
General-purpose automatically managed/resized buffer.
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
size_t nMaxFragments
maximum number of fragments in a packet