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 | /* |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, 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 | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 29 | #include "face-common.hpp" |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 30 | |
| 31 | #include <ndn-cxx/lp/packet.hpp> |
| 32 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 33 | namespace nfd::face { |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 34 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 35 | /** |
| 36 | * \brief Fragments network-layer packets into NDNLPv2 link-layer packets. |
| 37 | * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2 |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 38 | */ |
| 39 | class LpFragmenter |
| 40 | { |
| 41 | public: |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 42 | /** |
| 43 | * \brief %Options that control the behavior of LpFragmenter. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 44 | */ |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 45 | struct Options |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 46 | { |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 47 | /** |
| 48 | * \brief Maximum number of fragments in a packet. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 49 | */ |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 50 | size_t nMaxFragments = 400; |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | explicit |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 54 | LpFragmenter(const Options& options, const LinkService* linkService = nullptr); |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 55 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 56 | /** |
| 57 | * \brief Set options for fragmenter. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 58 | */ |
| 59 | void |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 60 | setOptions(const Options& options) |
| 61 | { |
| 62 | m_options = options; |
| 63 | } |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 64 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 65 | /** |
| 66 | * \brief Returns the LinkService that owns this instance. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 67 | * |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 68 | * This is only used for logging, and may be nullptr. |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 69 | */ |
| 70 | const LinkService* |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 71 | getLinkService() const noexcept |
| 72 | { |
| 73 | return m_linkService; |
| 74 | } |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 75 | |
Davide Pesavento | e0b67df | 2024-02-17 19:14:24 -0500 | [diff] [blame] | 76 | /** |
| 77 | * \brief Fragments a network-layer packet into link-layer packets. |
| 78 | * \param packet an LpPacket that contains a network-layer packet; |
| 79 | * must have Fragment field, must not have FragIndex and FragCount fields |
| 80 | * \param mtu maximum allowable LpPacket size after fragmentation and sequence number assignment |
| 81 | * \return whether fragmentation succeeded, fragmented packets without sequence number |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 82 | */ |
| 83 | std::tuple<bool, std::vector<lp::Packet>> |
| 84 | fragmentPacket(const lp::Packet& packet, size_t mtu); |
| 85 | |
| 86 | private: |
| 87 | Options m_options; |
| 88 | const LinkService* m_linkService; |
| 89 | }; |
| 90 | |
| 91 | std::ostream& |
| 92 | operator<<(std::ostream& os, const FaceLogHelper<LpFragmenter>& flh); |
| 93 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 94 | } // namespace nfd::face |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 95 | |
| 96 | #endif // NFD_DAEMON_FACE_LP_FRAGMENTER_HPP |