28 #include <ndn-cxx/lp/tags.hpp> 40 : allowLocalFields(false)
41 , allowFragmentation(false)
42 , allowReassembly(false)
43 , allowCongestionMarking(false)
44 , baseCongestionMarkingInterval(
time::milliseconds(100))
45 , defaultCongestionThreshold(65536)
46 , allowSelfLearning(false)
52 , m_fragmenter(m_options.fragmenterOptions, this)
53 , m_reassembler(m_options.reassemblerOptions, this)
54 , m_reliability(m_options.reliabilityOptions, this)
56 , m_nextMarkTime(
time::steady_clock::TimePoint::max())
57 , m_lastMarkTime(
time::steady_clock::TimePoint::min())
58 , m_nMarkedSinceInMarkingState(0)
75 GenericLinkService::requestIdlePacket()
79 this->sendLpPacket({});
83 GenericLinkService::sendLpPacket(
lp::Packet&& pkt)
92 checkCongestionLevel(pkt);
95 Transport::Packet tp(pkt.wireEncode());
96 if (mtu !=
MTU_UNLIMITED && tp.packet.size() >
static_cast<size_t>(mtu)) {
105 GenericLinkService::doSendInterest(
const Interest& interest)
109 encodeLpFields(interest, lpPacket);
111 this->sendNetPacket(std::move(lpPacket),
true);
115 GenericLinkService::doSendData(
const Data& data)
119 encodeLpFields(data, lpPacket);
121 this->sendNetPacket(std::move(lpPacket),
false);
125 GenericLinkService::doSendNack(
const lp::Nack& nack)
130 encodeLpFields(nack, lpPacket);
132 this->sendNetPacket(std::move(lpPacket),
false);
140 if (incomingFaceIdTag !=
nullptr) {
146 if (congestionMarkTag !=
nullptr) {
152 if (nonDiscoveryTag !=
nullptr) {
157 if (prefixAnnouncementTag !=
nullptr) {
163 if (hopCountTag !=
nullptr) {
172 GenericLinkService::sendNetPacket(
lp::Packet&& pkt,
bool isInterest)
174 std::vector<lp::Packet> frags;
183 mtu -= CONGESTION_MARK_SIZE;
199 frags.push_back(pkt);
202 frags.push_back(std::move(pkt));
206 if (frags.size() == 1) {
214 if (frags.size() > 1) {
216 this->assignSequences(frags);
224 this->sendLpPacket(std::move(frag));
229 GenericLinkService::assignSequence(
lp::Packet& pkt)
235 GenericLinkService::assignSequences(std::vector<lp::Packet>& pkts)
237 std::for_each(pkts.begin(), pkts.end(), bind(&GenericLinkService::assignSequence,
this, _1));
241 GenericLinkService::checkCongestionLevel(
lp::Packet& pkt)
245 if (sendQueueLength < 0) {
253 congestionThreshold = std::min(congestionThreshold,
254 static_cast<size_t>(
getTransport()->getSendQueueCapacity()) /
258 if (sendQueueLength > 0) {
259 NFD_LOG_FACE_TRACE(
"txqlen=" << sendQueueLength <<
" threshold=" << congestionThreshold <<
260 " capacity=" <<
getTransport()->getSendQueueCapacity());
263 if (static_cast<size_t>(sendQueueLength) > congestionThreshold) {
267 if (m_nMarkedSinceInMarkingState == 0) {
268 m_nextMarkTime = now;
276 ++m_nMarkedSinceInMarkingState;
279 m_nextMarkTime += time::nanoseconds(static_cast<time::nanoseconds::rep>(
281 std::sqrt(m_nMarkedSinceInMarkingState)));
282 m_lastMarkTime = now;
285 else if (m_nextMarkTime != time::steady_clock::TimePoint::max()) {
288 m_nextMarkTime = time::steady_clock::TimePoint::max();
289 m_nMarkedSinceInMarkingState = 0;
294 GenericLinkService::doReceivePacket(Transport::Packet&& packet)
314 bool isReassembled =
false;
317 std::tie(isReassembled, netPkt, firstPkt) = m_reassembler.
receiveFragment(packet.remoteEndpoint,
320 this->decodeNetPacket(netPkt, firstPkt);
323 catch (
const tlv::Error& e) {
330 GenericLinkService::decodeNetPacket(
const Block& netPkt,
const lp::Packet& firstPkt)
333 switch (netPkt.type()) {
336 this->decodeNack(netPkt, firstPkt);
339 this->decodeInterest(netPkt, firstPkt);
343 this->decodeData(netPkt, firstPkt);
347 NFD_LOG_FACE_WARN(
"unrecognized network-layer packet TLV-TYPE " << netPkt.type() <<
": DROP");
351 catch (
const tlv::Error& e) {
358 GenericLinkService::decodeInterest(
const Block& netPkt,
const lp::Packet& firstPkt)
364 auto interest = make_shared<Interest>(netPkt);
414 GenericLinkService::decodeData(
const Block& netPkt,
const lp::Packet& firstPkt)
416 BOOST_ASSERT(netPkt.type() ==
tlv::Data);
419 auto data = make_shared<Data>(netPkt);
463 NFD_LOG_FACE_WARN(
"received PrefixAnnouncement, but self-learning disabled: IGNORE");
471 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
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
Represents an Interest packet.
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
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
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 in NDN Packet Format v0.2.
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)
virtual ssize_t getSendQueueLength()
GenericLinkService(const Options &options=Options())
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