41 , m_fragmenter(m_options.fragmenterOptions, this)
42 , m_reassembler(m_options.reassemblerOptions, this)
43 , m_reliability(m_options.reliabilityOptions, this)
45 , m_nextMarkTime(
time::steady_clock::TimePoint::max())
46 , m_lastMarkTime(
time::steady_clock::TimePoint::min())
47 , m_nMarkedSinceInMarkingState(0)
64 GenericLinkService::requestIdlePacket()
68 this->sendLpPacket({});
72 GenericLinkService::sendLpPacket(
lp::Packet&& pkt)
81 checkCongestionLevel(pkt);
84 Transport::Packet tp(pkt.wireEncode());
85 if (mtu !=
MTU_UNLIMITED && tp.packet.size() > static_cast<size_t>(mtu)) {
94 GenericLinkService::doSendInterest(
const Interest& interest)
98 encodeLpFields(interest, lpPacket);
100 this->sendNetPacket(std::move(lpPacket),
true);
104 GenericLinkService::doSendData(
const Data& data)
108 encodeLpFields(data, lpPacket);
110 this->sendNetPacket(std::move(lpPacket),
false);
114 GenericLinkService::doSendNack(
const lp::Nack& nack)
119 encodeLpFields(nack, lpPacket);
121 this->sendNetPacket(std::move(lpPacket),
false);
129 if (incomingFaceIdTag !=
nullptr) {
135 if (congestionMarkTag !=
nullptr) {
141 if (nonDiscoveryTag !=
nullptr) {
146 if (prefixAnnouncementTag !=
nullptr) {
152 if (hopCountTag !=
nullptr) {
161 GenericLinkService::sendNetPacket(
lp::Packet&& pkt,
bool isInterest)
163 std::vector<lp::Packet> frags;
172 mtu -= CONGESTION_MARK_SIZE;
188 frags.push_back(pkt);
191 frags.push_back(std::move(pkt));
195 if (frags.size() == 1) {
203 if (frags.size() > 1) {
205 this->assignSequences(frags);
213 this->sendLpPacket(std::move(frag));
218 GenericLinkService::assignSequence(
lp::Packet& pkt)
224 GenericLinkService::assignSequences(std::vector<lp::Packet>& pkts)
226 std::for_each(pkts.begin(), pkts.end(), [
this] (
auto& pkt) { this->assignSequence(pkt); });
230 GenericLinkService::checkCongestionLevel(
lp::Packet& pkt)
234 if (sendQueueLength < 0) {
242 congestionThreshold = std::min(congestionThreshold,
243 static_cast<size_t>(
getTransport()->getSendQueueCapacity()) /
247 if (sendQueueLength > 0) {
248 NFD_LOG_FACE_TRACE(
"txqlen=" << sendQueueLength <<
" threshold=" << congestionThreshold <<
249 " capacity=" <<
getTransport()->getSendQueueCapacity());
252 if (static_cast<size_t>(sendQueueLength) > congestionThreshold) {
256 if (m_nMarkedSinceInMarkingState == 0) {
257 m_nextMarkTime = now;
265 ++m_nMarkedSinceInMarkingState;
268 m_nextMarkTime += time::nanoseconds(static_cast<time::nanoseconds::rep>(
270 std::sqrt(m_nMarkedSinceInMarkingState)));
271 m_lastMarkTime = now;
274 else if (m_nextMarkTime != time::steady_clock::TimePoint::max()) {
277 m_nextMarkTime = time::steady_clock::TimePoint::max();
278 m_nMarkedSinceInMarkingState = 0;
283 GenericLinkService::doReceivePacket(Transport::Packet&& packet)
303 bool isReassembled =
false;
306 std::tie(isReassembled, netPkt, firstPkt) = m_reassembler.
receiveFragment(packet.remoteEndpoint,
309 this->decodeNetPacket(netPkt, firstPkt);
312 catch (
const tlv::Error& e) {
319 GenericLinkService::decodeNetPacket(
const Block& netPkt,
const lp::Packet& firstPkt)
322 switch (netPkt.type()) {
325 this->decodeNack(netPkt, firstPkt);
328 this->decodeInterest(netPkt, firstPkt);
332 this->decodeData(netPkt, firstPkt);
336 NFD_LOG_FACE_WARN(
"unrecognized network-layer packet TLV-TYPE " << netPkt.type() <<
": DROP");
340 catch (
const tlv::Error& e) {
347 GenericLinkService::decodeInterest(
const Block& netPkt,
const lp::Packet& firstPkt)
353 auto interest = make_shared<Interest>(netPkt);
403 GenericLinkService::decodeData(
const Block& netPkt,
const lp::Packet& firstPkt)
405 BOOST_ASSERT(netPkt.type() ==
tlv::Data);
408 auto data = make_shared<Data>(netPkt);
452 NFD_LOG_FACE_WARN(
"received PrefixAnnouncement, but self-learning disabled: IGNORE");
460 GenericLinkService::decodeNack(
const Block& netPkt,
const lp::Packet& firstPkt)
LpFragmenter::Options fragmenterOptions
options for fragmentation
void setTag(shared_ptr< T > tag) const
set a tag item
signal::Signal< LpReassembler, Transport::EndpointId, size_t > beforeTimeout
signals before a partial packet is dropped due to timeout
shared_ptr< T > getTag() const
get a tag item
void setOptions(const Options &options)
set options for reliability
GenericLinkService is a LinkService that implements the NDNLPv2 protocol.
bool allowReassembly
enables reassembly
void processIncomingPacket(const lp::Packet &pkt)
extract and parse all Acks and add Ack for contained Fragment (if any) to AckQueue
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
bool allowLocalFields
enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy
PacketCounter nCongestionMarked
count of outgoing LpPackets that were marked with congestion marks
Packet & set(const typename FIELD::ValueType &value)
remove all occurrences of FIELD, and add a FIELD with value
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
static time_point now() noexcept
size_t defaultCongestionThreshold
default congestion threshold in bytes
void piggyback(lp::Packet &pkt, ssize_t mtu)
called by GenericLinkService to attach Acks onto an outgoing LpPacket
void notifyDroppedInterest(const Interest &packet)
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
Nack & setHeader(const NackHeader &header)
const Transport * getTransport() const
void handleOutgoing(std::vector< lp::Packet > &frags, lp::Packet &&pkt, bool isInterest)
observe outgoing fragment(s) of a network packet and store for potential retransmission
PacketCounter nReassemblyTimeouts
count of dropped partial network-layer packets due to reassembly timeout
LpReliability::Options reliabilityOptions
options for reliability
const NackHeader & getHeader() const
void sendPacket(Transport::Packet &&packet)
sends a lower-layer packet via Transport
bool isEnabled
enables link-layer reliability
static constexpr size_t RESERVED_HEADER_SPACE
TxSequence TLV-TYPE (3 octets) + TxSequence TLV-LENGTH (1 octet) + sizeof(lp::Sequence)
represents a Network Nack
GenericLinkService(const Options &options={})
void setOptions(const Options &options)
set options for fragmenter
provides a tag type for simple types
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
FIELD::ValueType get(size_t index=0) const
PacketCounter nOutOverMtu
count of outgoing LpPackets dropped due to exceeding MTU limit
bool allowSelfLearning
enables self-learning forwarding support
bool allowCongestionMarking
enables send queue congestion detection and marking
Copyright (c) 2011-2015 Regents of the University of California.
time::nanoseconds baseCongestionMarkingInterval
starting value for congestion marking interval
constexpr uint32_t DEFAULT_CONGESTION_THRESHOLD_DIVISOR
void receiveNack(const lp::Nack &nack)
delivers received Nack to forwarding
virtual ssize_t getSendQueueLength()
base class to allow simple management of packet tags
SizeCounter< LpReassembler > nReassembling
count of network-layer packets currently being reassembled
void setOptions(const Options &options)
set options for reassembler
void setOptions(const Options &options)
sets Options used by GenericLinkService
Options that control the behavior of GenericLinkService.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Prepend wire encoding to encoder.
void receiveData(const Data &data)
delivers received Data to forwarding
signal::Signal< LpReliability, Interest > onDroppedInterest
signals on Interest dropped by reliability system for exceeding allowed number of retx
std::tuple< bool, Block, lp::Packet > receiveFragment(Transport::EndpointId remoteEndpoint, const lp::Packet &packet)
adds received fragment to buffer
PacketCounter nInNetInvalid
count of invalid reassembled network-layer packets dropped
std::tuple< bool, std::vector< lp::Packet > > fragmentPacket(const lp::Packet &packet, size_t mtu)
fragments a network-layer packet into link-layer packets
LpReassembler::Options reassemblerOptions
options for reassembly
#define NFD_LOG_INIT(name)
const Interest & getInterest() const
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
PacketCounter nInLpInvalid
count of invalid LpPackets dropped before reassembly
void receiveInterest(const Interest &interest)
delivers received Interest to forwarding
PacketCounter nFragmentationErrors
count of failed fragmentations
bool allowFragmentation
enables fragmentation