28 #include <ndn-cxx/encoding/tlv.hpp> 66 , m_linkService(linkService)
82 std::tuple<bool, std::vector<lp::Packet>>
89 if (MAX_SINGLE_FRAG_OVERHEAD + packet.
wireEncode().size() <= mtu) {
93 return std::make_tuple(
true, std::vector<lp::Packet>{packet});
96 ndn::Buffer::const_iterator netPktBegin, netPktEnd;
98 size_t netPktSize = std::distance(netPktBegin, netPktEnd);
101 size_t firstHeaderSize = 0;
106 firstHeaderSize += element.size();
112 if (MAX_FRAG_OVERHEAD + firstHeaderSize + 1 > mtu) {
113 NFD_LOG_FACE_WARN(
"fragmentation error, MTU too small for first fragment: DROP");
114 return std::make_tuple(
false, std::vector<lp::Packet>{});
116 size_t firstPayloadSize = std::min(netPktSize, mtu - firstHeaderSize - MAX_FRAG_OVERHEAD);
118 size_t fragCount = 1 + ((netPktSize - firstPayloadSize) / payloadSize) +
119 ((netPktSize - firstPayloadSize) % payloadSize != 0);
124 return std::make_pair(
false, std::vector<lp::Packet>{});
128 std::vector<lp::Packet> frags(fragCount);
129 frags.front() = packet;
130 size_t fragIndex = 0;
131 auto fragBegin = netPktBegin,
132 fragEnd = fragBegin + firstPayloadSize;
133 while (fragBegin < netPktEnd) {
138 BOOST_ASSERT(frag.
wireEncode().size() <= mtu);
142 fragEnd = std::min(netPktEnd, fragBegin + payloadSize);
144 BOOST_ASSERT(fragIndex == fragCount);
146 return std::make_pair(
true, frags);
150 operator<<(std::ostream& os, const FaceLogHelper<LpFragmenter>& flh)
152 if (flh.obj.getLinkService() ==
nullptr) {
153 os <<
"[id=0,local=unknown,remote=unknown] ";
156 os << FaceLogHelper<LinkService>(*flh.obj.getLinkService());
size_t wireEncode(EncodingImpl< TAG > &encoder) const
append packet to encoder
Packet & set(const typename FIELD::ValueType &value)
remove all occurrences of FIELD, and add a FIELD with value
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
Class representing a wire element of NDN-TLV packet format.
Options that control the behavior of LpFragmenter.
uint64_t Sequence
represents a sequence number
void setOptions(const Options &options)
set options for fragmenter
FIELD::ValueType get(size_t index=0) const
size_t nMaxFragments
maximum number of fragments in a packet
Copyright (c) 2011-2015 Regents of the University of California.
LpFragmenter(const Options &options=Options(), const LinkService *linkService=nullptr)
const element_container & elements() const
Get all subelements.
std::tuple< bool, std::vector< lp::Packet > > fragmentPacket(const lp::Packet &packet, size_t mtu)
fragments a network-layer packet into link-layer packets
#define NFD_LOG_INIT(name)
static const size_t MAX_SINGLE_FRAG_OVERHEAD
maximum overhead on a single fragment, not counting other NDNLPv2 headers
static const size_t MAX_FRAG_OVERHEAD
maximum overhead of adding fragmentation to payload, not counting other NDNLPv2 headers ...
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
const LinkService * getLinkService() const