Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #ifndef NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP |
| 27 | #define NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP |
| 28 | |
| 29 | #include "common.hpp" |
| 30 | #include "core/logger.hpp" |
| 31 | |
| 32 | #include "link-service.hpp" |
| 33 | |
| 34 | #include <ndn-cxx/lp/packet.hpp> |
| 35 | |
| 36 | namespace nfd { |
| 37 | namespace face { |
| 38 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 39 | /** \brief GenericLinkService is a LinkService that implements the NDNLPv2 protocol |
| 40 | * \sa http://redmine.named-data.net/projects/nfd/wiki/NDNLPv2 |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 41 | */ |
| 42 | class GenericLinkService : public LinkService |
| 43 | { |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 44 | public: |
| 45 | /** \brief Options that control the behavior of GenericLinkService |
| 46 | */ |
| 47 | class Options |
| 48 | { |
| 49 | public: |
| 50 | Options(); |
| 51 | |
| 52 | public: |
| 53 | // TODO #3171: fragmentation and reassembly options |
| 54 | |
| 55 | /** \brief enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy |
| 56 | */ |
| 57 | bool allowLocalFields; |
| 58 | }; |
| 59 | |
| 60 | explicit |
| 61 | GenericLinkService(const Options& options = Options()); |
| 62 | |
| 63 | /** \brief get Options used by GenericLinkService |
| 64 | */ |
| 65 | const Options& |
| 66 | getOptions() const; |
| 67 | |
| 68 | /** \brief sets Options used by GenericLinkService |
| 69 | */ |
| 70 | void |
| 71 | setOptions(const Options& options); |
| 72 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 73 | private: // send path entrypoint |
| 74 | /** \brief sends Interest |
| 75 | */ |
| 76 | void |
| 77 | doSendInterest(const Interest& interest) DECL_OVERRIDE; |
| 78 | |
| 79 | /** \brief sends Data |
| 80 | */ |
| 81 | void |
| 82 | doSendData(const Data& data) DECL_OVERRIDE; |
| 83 | |
| 84 | /** \brief sends Nack |
| 85 | * This class does not send out a Nack. |
| 86 | */ |
| 87 | void |
| 88 | doSendNack(const ndn::lp::Nack& nack) DECL_OVERRIDE; |
| 89 | |
| 90 | private: // receive path entrypoint |
| 91 | /** \brief receives Packet |
| 92 | */ |
| 93 | void |
| 94 | doReceivePacket(Transport::Packet&& packet) DECL_OVERRIDE; |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 95 | |
| 96 | private: // encoding and decoding |
| 97 | /** \brief encode IncomingFaceId into LpPacket and verify local fields |
| 98 | */ |
| 99 | static bool |
| 100 | encodeLocalFields(const Interest& interest, lp::Packet& lpPacket); |
| 101 | |
| 102 | /** \brief encode CachingPolicy and IncomingFaceId into LpPacket and verify local fields |
| 103 | */ |
| 104 | static bool |
| 105 | encodeLocalFields(const Data& data, lp::Packet& lpPacket); |
| 106 | |
| 107 | /** \brief decode incoming Interest |
| 108 | * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest |
| 109 | * \param firstPkt LpPacket of first fragment; must not have Nack field |
| 110 | * |
| 111 | * If decoding is successful, receiveInterest signal is emitted; |
| 112 | * otherwise, a warning is logged. |
| 113 | * |
| 114 | * \throw tlv::Error parse error in an LpHeader field |
| 115 | */ |
| 116 | void |
| 117 | decodeInterest(const Block& netPkt, const lp::Packet& firstPkt); |
| 118 | |
| 119 | /** \brief decode incoming Interest |
| 120 | * \param netPkt reassembled network-layer packet; TLV-TYPE must be Data |
| 121 | * \param firstPkt LpPacket of first fragment |
| 122 | * |
| 123 | * If decoding is successful, receiveData signal is emitted; |
| 124 | * otherwise, a warning is logged. |
| 125 | * |
| 126 | * \throw tlv::Error parse error in an LpHeader field |
| 127 | */ |
| 128 | void |
| 129 | decodeData(const Block& netPkt, const lp::Packet& firstPkt); |
| 130 | |
| 131 | /** \brief decode incoming Interest |
| 132 | * \param netPkt reassembled network-layer packet; TLV-TYPE must be Interest |
| 133 | * \param firstPkt LpPacket of first fragment; must have Nack field |
| 134 | * |
| 135 | * If decoding is successful, receiveNack signal is emitted; |
| 136 | * otherwise, a warning is logged. |
| 137 | * |
| 138 | * \throw tlv::Error parse error in an LpHeader field |
| 139 | */ |
| 140 | void |
| 141 | decodeNack(const Block& netPkt, const lp::Packet& firstPkt); |
| 142 | |
| 143 | private: |
| 144 | Options m_options; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 147 | inline const GenericLinkService::Options& |
| 148 | GenericLinkService::getOptions() const |
| 149 | { |
| 150 | return m_options; |
| 151 | } |
| 152 | |
| 153 | inline void |
| 154 | GenericLinkService::setOptions(const GenericLinkService::Options& options) |
| 155 | { |
| 156 | m_options = options; |
| 157 | } |
| 158 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 159 | } // namespace face |
| 160 | } // namespace nfd |
| 161 | |
Eric Newberry | 86d3187 | 2015-09-23 16:24:59 -0700 | [diff] [blame] | 162 | #endif // NFD_DAEMON_FACE_GENERIC_LINK_SERVICE_HPP |