| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /** |
| * Copyright (c) 2014-2017, Regents of the University of California, |
| * Arizona Board of Regents, |
| * Colorado State University, |
| * University Pierre & Marie Curie, Sorbonne University, |
| * Washington University in St. Louis, |
| * Beijing Institute of Technology, |
| * The University of Memphis. |
| * |
| * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| * See AUTHORS.md for complete list of NFD authors and contributors. |
| * |
| * NFD is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, |
| * either version 3 of the License, or (at your option) any later version. |
| * |
| * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| * PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License along with |
| * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| |
| #ifndef NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP |
| #define NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP |
| |
| #include "core/common.hpp" |
| #include "core/logger.hpp" |
| |
| #include "link-service.hpp" |
| #include "lp-fragmenter.hpp" |
| #include "lp-reassembler.hpp" |
| |
| namespace nfd { |
| namespace face { |
| |
| /** \brief counters provided by GenericLinkService |
| * \note The type name 'GenericLinkServiceCounters' is implementation detail. |
| * Use 'GenericLinkService::Counters' in public API. |
| */ |
| class GenericLinkServiceCounters : public virtual LinkService::Counters |
| { |
| public: |
| explicit |
| GenericLinkServiceCounters(const LpReassembler& reassembler); |
| |
| /** \brief count of failed fragmentations |
| */ |
| PacketCounter nFragmentationErrors; |
| |
| /** \brief count of outgoing LpPackets dropped due to exceeding MTU limit |
| * |
| * If this counter is non-zero, the operator should enable fragmentation. |
| */ |
| PacketCounter nOutOverMtu; |
| |
| /** \brief count of invalid LpPackets dropped before reassembly |
| */ |
| PacketCounter nInLpInvalid; |
| |
| /** \brief count of network-layer packets currently being reassembled |
| */ |
| SizeCounter<LpReassembler> nReassembling; |
| |
| /** \brief count of dropped partial network-layer packets due to reassembly timeout |
| */ |
| PacketCounter nReassemblyTimeouts; |
| |
| /** \brief count of invalid reassembled network-layer packets dropped |
| */ |
| PacketCounter nInNetInvalid; |
| }; |
| |
| /** \brief GenericLinkService is a LinkService that implements the NDNLPv2 protocol |
| * \sa http://redmine.named-data.net/projects/nfd/wiki/NDNLPv2 |
| * \todo #3941 declare GenericLinkServiceCounters as virtual inheritance |
| */ |
| class GenericLinkService : public LinkService |
| , protected GenericLinkServiceCounters |
| { |
| public: |
| /** \brief Options that control the behavior of GenericLinkService |
| */ |
| class Options |
| { |
| public: |
| Options(); |
| |
| public: |
| /** \brief enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy |
| */ |
| bool allowLocalFields; |
| |
| /** \brief enables fragmentation |
| */ |
| bool allowFragmentation; |
| |
| /** \brief options for fragmentation |
| */ |
| LpFragmenter::Options fragmenterOptions; |
| |
| /** \brief enables reassembly |
| */ |
| bool allowReassembly; |
| |
| /** \brief options for reassembly |
| */ |
| LpReassembler::Options reassemblerOptions; |
| }; |
| |
| /** \brief counters provided by GenericLinkService |
| */ |
| using Counters = GenericLinkServiceCounters; |
| |
| explicit |
| GenericLinkService(const Options& options = Options()); |
| |
| /** \brief get Options used by GenericLinkService |
| */ |
| const Options& |
| getOptions() const; |
| |
| /** \brief sets Options used by GenericLinkService |
| */ |
| void |
| setOptions(const Options& options); |
| |
| const Counters& |
| getCounters() const override; |
| |
| PROTECTED_WITH_TESTS_ELSE_PRIVATE: // send path |
| /** \brief send Interest |
| */ |
| void |
| doSendInterest(const Interest& interest) override; |
| |
| /** \brief send Data |
| */ |
| void |
| doSendData(const Data& data) override; |
| |
| /** \brief send Nack |
| */ |
| void |
| doSendNack(const ndn::lp::Nack& nack) override; |
| |
| private: |
| /** \brief encode link protocol fields from tags onto an outgoing LpPacket |
| * \param netPkt network-layer packet to extract tags from |
| * \param lpPacket LpPacket to add link protocol fields to |
| */ |
| void |
| encodeLpFields(const ndn::TagHost& netPkt, lp::Packet& lpPacket); |
| |
| /** \brief send a complete network layer packet |
| * \param pkt LpPacket containing a complete network layer packet |
| */ |
| void |
| sendNetPacket(lp::Packet&& pkt); |
| |
| /** \brief assign a sequence number to an LpPacket |
| */ |
| void |
| assignSequence(lp::Packet& pkt); |
| |
| /** \brief assign consecutive sequence numbers to LpPackets |
| */ |
| void |
| assignSequences(std::vector<lp::Packet>& pkts); |
| |
| private: // receive path |
| /** \brief receive Packet from Transport |
| */ |
| void |
| doReceivePacket(Transport::Packet&& packet) override; |
| |
| /** \brief decode incoming network-layer packet |
| * \param netPkt reassembled network-layer packet |
| * \param firstPkt LpPacket of first fragment |
| * |
| * If decoding is successful, a receive signal is emitted; |
| * otherwise, a warning is logged. |
| */ |
| void |
| decodeNetPacket(const Block& netPkt, const lp::Packet& firstPkt); |
| |
| /** \brief decode incoming Interest |
| * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest |
| * \param firstPkt LpPacket of first fragment; must not have Nack field |
| * |
| * If decoding is successful, receiveInterest signal is emitted; |
| * otherwise, a warning is logged. |
| * |
| * \throw tlv::Error parse error in an LpHeader field |
| */ |
| void |
| decodeInterest(const Block& netPkt, const lp::Packet& firstPkt); |
| |
| /** \brief decode incoming Interest |
| * \param netPkt reassembled network-layer packet; TLV-TYPE must be Data |
| * \param firstPkt LpPacket of first fragment |
| * |
| * If decoding is successful, receiveData signal is emitted; |
| * otherwise, a warning is logged. |
| * |
| * \throw tlv::Error parse error in an LpHeader field |
| */ |
| void |
| decodeData(const Block& netPkt, const lp::Packet& firstPkt); |
| |
| /** \brief decode incoming Interest |
| * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest |
| * \param firstPkt LpPacket of first fragment; must have Nack field |
| * |
| * If decoding is successful, receiveNack signal is emitted; |
| * otherwise, a warning is logged. |
| * |
| * \throw tlv::Error parse error in an LpHeader field |
| */ |
| void |
| decodeNack(const Block& netPkt, const lp::Packet& firstPkt); |
| |
| private: |
| Options m_options; |
| LpFragmenter m_fragmenter; |
| LpReassembler m_reassembler; |
| lp::Sequence m_lastSeqNo; |
| }; |
| |
| inline const GenericLinkService::Options& |
| GenericLinkService::getOptions() const |
| { |
| return m_options; |
| } |
| |
| inline void |
| GenericLinkService::setOptions(const GenericLinkService::Options& options) |
| { |
| m_options = options; |
| } |
| |
| inline const GenericLinkService::Counters& |
| GenericLinkService::getCounters() const |
| { |
| return *this; |
| } |
| |
| } // namespace face |
| } // namespace nfd |
| |
| #endif // NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP |