blob: fa364f83790cbb28bf57ce35529059c1116d1557 [file] [log] [blame]
Eric Newberry4c3e6b82015-11-10 16:48:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoa3148082018-04-12 18:21:54 -04002/*
Davide Pesaventoe0b67df2024-02-17 19:14:24 -05003 * Copyright (c) 2014-2024, Regents of the University of California,
Eric Newberry4c3e6b82015-11-10 16:48:42 -07004 * 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 Pesaventocb425e82019-07-14 21:48:22 -040029#include "face-common.hpp"
Eric Newberry4c3e6b82015-11-10 16:48:42 -070030
31#include <ndn-cxx/lp/packet.hpp>
32
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040033namespace nfd::face {
Eric Newberry4c3e6b82015-11-10 16:48:42 -070034
Davide Pesaventoe0b67df2024-02-17 19:14:24 -050035/**
36 * \brief Fragments network-layer packets into NDNLPv2 link-layer packets.
37 * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
Eric Newberry4c3e6b82015-11-10 16:48:42 -070038 */
39class LpFragmenter
40{
41public:
Davide Pesaventoe0b67df2024-02-17 19:14:24 -050042 /**
43 * \brief %Options that control the behavior of LpFragmenter.
Eric Newberry4c3e6b82015-11-10 16:48:42 -070044 */
Davide Pesaventoe4b22382018-06-10 14:37:24 -040045 struct Options
Eric Newberry4c3e6b82015-11-10 16:48:42 -070046 {
Davide Pesaventoe0b67df2024-02-17 19:14:24 -050047 /**
48 * \brief Maximum number of fragments in a packet.
Eric Newberry4c3e6b82015-11-10 16:48:42 -070049 */
Davide Pesaventoe4b22382018-06-10 14:37:24 -040050 size_t nMaxFragments = 400;
Eric Newberry4c3e6b82015-11-10 16:48:42 -070051 };
52
53 explicit
Davide Pesaventoe4b22382018-06-10 14:37:24 -040054 LpFragmenter(const Options& options, const LinkService* linkService = nullptr);
Eric Newberry4c3e6b82015-11-10 16:48:42 -070055
Davide Pesaventoe0b67df2024-02-17 19:14:24 -050056 /**
57 * \brief Set options for fragmenter.
Eric Newberry4c3e6b82015-11-10 16:48:42 -070058 */
59 void
Davide Pesaventoe0b67df2024-02-17 19:14:24 -050060 setOptions(const Options& options)
61 {
62 m_options = options;
63 }
Eric Newberry4c3e6b82015-11-10 16:48:42 -070064
Davide Pesaventoe0b67df2024-02-17 19:14:24 -050065 /**
66 * \brief Returns the LinkService that owns this instance.
Eric Newberry4c3e6b82015-11-10 16:48:42 -070067 *
Davide Pesaventoe0b67df2024-02-17 19:14:24 -050068 * This is only used for logging, and may be nullptr.
Eric Newberry4c3e6b82015-11-10 16:48:42 -070069 */
70 const LinkService*
Davide Pesaventoe0b67df2024-02-17 19:14:24 -050071 getLinkService() const noexcept
72 {
73 return m_linkService;
74 }
Eric Newberry4c3e6b82015-11-10 16:48:42 -070075
Davide Pesaventoe0b67df2024-02-17 19:14:24 -050076 /**
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 Newberry4c3e6b82015-11-10 16:48:42 -070082 */
83 std::tuple<bool, std::vector<lp::Packet>>
84 fragmentPacket(const lp::Packet& packet, size_t mtu);
85
86private:
87 Options m_options;
88 const LinkService* m_linkService;
89};
90
91std::ostream&
92operator<<(std::ostream& os, const FaceLogHelper<LpFragmenter>& flh);
93
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040094} // namespace nfd::face
Eric Newberry4c3e6b82015-11-10 16:48:42 -070095
96#endif // NFD_DAEMON_FACE_LP_FRAGMENTER_HPP