38 , m_linkService(linkService)
42 std::tuple<bool, Block, lp::Packet>
47 static auto FALSE_RETURN = std::make_tuple(
false,
Block(),
lp::Packet());
50 uint64_t fragIndex = 0;
51 uint64_t fragCount = 1;
59 if (fragIndex >= fragCount) {
70 if (fragIndex == 0 && fragCount == 1) {
71 ndn::Buffer::const_iterator fragBegin, fragEnd;
73 Block netPkt(&*fragBegin, std::distance(fragBegin, fragEnd));
74 return std::make_tuple(
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);
110 lp::Packet firstFrag(std::move(pp.fragments[0]));
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.cbegin()), std::distance(fragBuffer.cbegin(), fragBuffer.cend()));
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);
161 os <<
"[id=0,local=unknown,remote=unknown] ";
signal::Signal< LpReassembler, Transport::EndpointId, size_t > beforeTimeout
signals before a partial packet is dropped due to timeout
Options that control the behavior of LpReassembler.
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
std::ostream & operator<<(std::ostream &os, const Face &face)
Represents a TLV element of NDN packet format.
uint64_t Sequence
represents a sequence number
FIELD::ValueType get(size_t index=0) const
Copyright (c) 2011-2015 Regents of the University of California.
reassembles fragmented network-layer packets
LpReassembler(const Options &options, const LinkService *linkService=nullptr)
EventId schedule(time::nanoseconds after, const EventCallback &event)
Schedule an event.
std::tuple< bool, Block, lp::Packet > receiveFragment(Transport::EndpointId remoteEndpoint, const lp::Packet &packet)
adds received fragment to buffer
for internal use by FaceLogging macros
const LinkService * getLinkService() const
#define NFD_LOG_INIT(name)
time::nanoseconds reassemblyTimeout
timeout before a partially reassembled packet is dropped
uint64_t EndpointId
identifies an endpoint on the link
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