Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 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_LP_FRAGMENTER_HPP |
| 27 | #define NFD_DAEMON_FACE_LP_FRAGMENTER_HPP |
| 28 | |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 29 | #include "core/common.hpp" |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 30 | #include "face-log.hpp" |
| 31 | |
| 32 | #include <ndn-cxx/lp/packet.hpp> |
| 33 | |
| 34 | namespace nfd { |
| 35 | namespace face { |
| 36 | |
| 37 | class LinkService; |
| 38 | |
| 39 | /** \brief fragments network-layer packets into NDNLPv2 link-layer packets |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 40 | * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2 |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 41 | */ |
| 42 | class LpFragmenter |
| 43 | { |
| 44 | public: |
| 45 | /** \brief Options that control the behavior of LpFragmenter |
| 46 | */ |
| 47 | class Options |
| 48 | { |
| 49 | public: |
| 50 | Options(); |
| 51 | |
| 52 | public: |
| 53 | /** \brief maximum number of fragments in a packet |
| 54 | */ |
| 55 | size_t nMaxFragments; |
| 56 | }; |
| 57 | |
| 58 | explicit |
| 59 | LpFragmenter(const Options& options = Options(), const LinkService* linkService = nullptr); |
| 60 | |
| 61 | /** \brief set options for fragmenter |
| 62 | */ |
| 63 | void |
| 64 | setOptions(const Options& options); |
| 65 | |
| 66 | /** \return LinkService that owns this instance |
| 67 | * |
| 68 | * This is only used for logging, and may be nullptr. |
| 69 | */ |
| 70 | const LinkService* |
| 71 | getLinkService() const; |
| 72 | |
| 73 | /** \brief fragments a network-layer packet into link-layer packets |
| 74 | * \param packet an LpPacket that contains a network-layer packet; |
| 75 | * must have Fragment field, must not have FragIndex and FragCount fields |
| 76 | * \param mtu maximum allowable LpPacket size after fragmentation and sequence number assignment |
| 77 | * \return whether fragmentation succeeded, fragmented packets without sequence number |
| 78 | */ |
| 79 | std::tuple<bool, std::vector<lp::Packet>> |
| 80 | fragmentPacket(const lp::Packet& packet, size_t mtu); |
| 81 | |
| 82 | private: |
| 83 | Options m_options; |
| 84 | const LinkService* m_linkService; |
| 85 | }; |
| 86 | |
| 87 | std::ostream& |
| 88 | operator<<(std::ostream& os, const FaceLogHelper<LpFragmenter>& flh); |
| 89 | |
| 90 | } // namespace face |
| 91 | } // namespace nfd |
| 92 | |
| 93 | #endif // NFD_DAEMON_FACE_LP_FRAGMENTER_HPP |