27 #include <ndn-cxx/lp/tags.hpp> 35 : allowLocalFields(false)
36 , allowFragmentation(false)
37 , allowReassembly(false)
62 GenericLinkService::requestIdlePacket()
66 this->sendLpPacket({});
70 GenericLinkService::sendLpPacket(lp::Packet&& pkt)
78 if (mtu !=
MTU_UNLIMITED && tp.packet.size() >
static_cast<size_t>(mtu)) {
87 GenericLinkService::doSendInterest(
const Interest& interest)
89 lp::Packet lpPacket(interest.wireEncode());
91 encodeLpFields(interest, lpPacket);
93 this->sendNetPacket(std::move(lpPacket));
97 GenericLinkService::doSendData(
const Data& data)
99 lp::Packet lpPacket(data.wireEncode());
101 encodeLpFields(data, lpPacket);
103 this->sendNetPacket(std::move(lpPacket));
107 GenericLinkService::doSendNack(
const lp::Nack& nack)
109 lp::Packet lpPacket(nack.getInterest().wireEncode());
110 lpPacket.add<lp::NackField>(nack.getHeader());
112 encodeLpFields(nack, lpPacket);
114 this->sendNetPacket(std::move(lpPacket));
118 GenericLinkService::encodeLpFields(
const ndn::TagHost& netPkt, lp::Packet& lpPacket)
121 shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = netPkt.getTag<lp::IncomingFaceIdTag>();
122 if (incomingFaceIdTag !=
nullptr) {
123 lpPacket.add<lp::IncomingFaceIdField>(*incomingFaceIdTag);
127 shared_ptr<lp::CongestionMarkTag> congestionMarkTag = netPkt.getTag<lp::CongestionMarkTag>();
128 if (congestionMarkTag !=
nullptr) {
129 lpPacket.add<lp::CongestionMarkField>(*congestionMarkTag);
134 GenericLinkService::sendNetPacket(lp::Packet&& pkt)
136 std::vector<lp::Packet> frags;
142 BOOST_ASSERT(mtu > 0);
155 frags.push_back(std::move(pkt));
158 if (frags.size() == 1) {
161 BOOST_ASSERT(!frags.front().has<lp::FragIndexField>());
162 BOOST_ASSERT(!frags.front().has<lp::FragCountField>());
166 if (frags.size() > 1) {
168 this->assignSequences(frags);
175 for (lp::Packet& frag : frags) {
176 this->sendLpPacket(std::move(frag));
181 GenericLinkService::assignSequence(lp::Packet& pkt)
183 pkt.set<lp::SequenceField>(++m_lastSeqNo);
187 GenericLinkService::assignSequences(std::vector<lp::Packet>& pkts)
189 std::for_each(pkts.begin(), pkts.end(), bind(&GenericLinkService::assignSequence,
this, _1));
196 lp::Packet pkt(packet.packet);
202 if (!pkt.has<lp::FragmentField>()) {
207 if ((pkt.has<lp::FragIndexField>() || pkt.has<lp::FragCountField>()) &&
213 bool isReassembled =
false;
216 std::tie(isReassembled, netPkt, firstPkt) = m_reassembler.
receiveFragment(packet.remoteEndpoint,
219 this->decodeNetPacket(netPkt, firstPkt);
222 catch (
const tlv::Error& e) {
229 GenericLinkService::decodeNetPacket(
const Block& netPkt,
const lp::Packet& firstPkt)
232 switch (netPkt.type()) {
234 if (firstPkt.has<lp::NackField>()) {
235 this->decodeNack(netPkt, firstPkt);
238 this->decodeInterest(netPkt, firstPkt);
242 this->decodeData(netPkt, firstPkt);
246 NFD_LOG_FACE_WARN(
"unrecognized network-layer packet TLV-TYPE " << netPkt.type() <<
": DROP");
250 catch (
const tlv::Error& e) {
257 GenericLinkService::decodeInterest(
const Block& netPkt,
const lp::Packet& firstPkt)
259 BOOST_ASSERT(netPkt.type() == tlv::Interest);
260 BOOST_ASSERT(!firstPkt.has<lp::NackField>());
263 auto interest = make_shared<Interest>(netPkt);
265 if (firstPkt.has<lp::NextHopFaceIdField>()) {
267 interest->setTag(make_shared<lp::NextHopFaceIdTag>(firstPkt.get<lp::NextHopFaceIdField>()));
275 if (firstPkt.has<lp::CachePolicyField>()) {
281 if (firstPkt.has<lp::IncomingFaceIdField>()) {
285 if (firstPkt.has<lp::CongestionMarkField>()) {
286 interest->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
293 GenericLinkService::decodeData(
const Block& netPkt,
const lp::Packet& firstPkt)
295 BOOST_ASSERT(netPkt.type() == tlv::Data);
298 auto data = make_shared<Data>(netPkt);
300 if (firstPkt.has<lp::NackField>()) {
306 if (firstPkt.has<lp::NextHopFaceIdField>()) {
312 if (firstPkt.has<lp::CachePolicyField>()) {
316 data->setTag(make_shared<lp::CachePolicyTag>(firstPkt.get<lp::CachePolicyField>()));
319 if (firstPkt.has<lp::IncomingFaceIdField>()) {
323 if (firstPkt.has<lp::CongestionMarkField>()) {
324 data->setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
331 GenericLinkService::decodeNack(
const Block& netPkt,
const lp::Packet& firstPkt)
333 BOOST_ASSERT(netPkt.type() == tlv::Interest);
334 BOOST_ASSERT(firstPkt.has<lp::NackField>());
336 lp::Nack nack((Interest(netPkt)));
337 nack.setHeader(firstPkt.get<lp::NackField>());
339 if (firstPkt.has<lp::NextHopFaceIdField>()) {
345 if (firstPkt.has<lp::CachePolicyField>()) {
351 if (firstPkt.has<lp::IncomingFaceIdField>()) {
355 if (firstPkt.has<lp::CongestionMarkField>()) {
356 nack.setTag(make_shared<lp::CongestionMarkTag>(firstPkt.get<lp::CongestionMarkField>()));
void setOptions(const Options &options)
sets Options used by GenericLinkService
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.
void receiveData(const Data &data)
delivers received Data to forwarding
SizeCounter< LpReassembler > nReassembling
count of network-layer packets currently being reassembled
PacketCounter nInLpInvalid
count of invalid LpPackets dropped before reassembly
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
PacketCounter nFragmentationErrors
count of failed fragmentations
bool allowFragmentation
enables fragmentation
void piggyback(lp::Packet &pkt, ssize_t mtu)
called by GenericLinkService to attach Acks onto an outgoing LpPacket
bool isEnabled
enables link-layer reliability
void setOptions(const Options &options)
set options for fragmenter
PacketCounter nInNetInvalid
count of invalid reassembled network-layer packets dropped
stores a packet along with the remote endpoint
LpReassembler::Options reassemblerOptions
options for reassembly
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
static constexpr size_t RESERVED_HEADER_SPACE
TxSequence TLV-TYPE (3 octets) + TxSequence TLV-LENGTH (1 octet) + sizeof(lp::Sequence) ...
void handleOutgoing(std::vector< lp::Packet > &frags)
observe outgoing fragment(s) of a network packet and store for potential retransmission ...
const Transport * getTransport() const
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
signal::Signal< LpReassembler, Transport::EndpointId, size_t > beforeTimeout
signals before a partial packet is dropped due to timeout
void sendPacket(Transport::Packet &&packet)
sends a lower-layer packet via Transport
std::tuple< bool, std::vector< lp::Packet > > fragmentPacket(const lp::Packet &packet, size_t mtu)
fragments a network-layer packet into link-layer packets
void receiveNack(const lp::Nack &nack)
delivers received Nack to forwarding
PacketCounter nOutOverMtu
count of outgoing LpPackets dropped due to exceeding MTU limit
LpReliability::Options reliabilityOptions
options for reliability
Options that control the behavior of GenericLinkService.
void setOptions(const Options &options)
set options for reliability
GenericLinkService(const Options &options=Options())
#define NFD_LOG_INIT(name)
std::tuple< bool, Block, lp::Packet > receiveFragment(Transport::EndpointId remoteEndpoint, const lp::Packet &packet)
adds received fragment to buffer
bool allowLocalFields
enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy ...
void receiveInterest(const Interest &interest)
delivers received Interest to forwarding
bool allowReassembly
enables reassembly
PacketCounter nReassemblyTimeouts
count of dropped partial network-layer packets due to reassembly timeout
void setOptions(const Options &options)
set options for reassembler
LpFragmenter::Options fragmenterOptions
options for fragmentation