blob: 8d24124960f1600a911af310c4d5071007a052a4 [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 Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, 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
Eric Newberry4c3e6b82015-11-10 16:48:42 -070035/** \brief fragments network-layer packets into NDNLPv2 link-layer packets
Davide Pesaventoa3148082018-04-12 18:21:54 -040036 * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
Eric Newberry4c3e6b82015-11-10 16:48:42 -070037 */
38class LpFragmenter
39{
40public:
41 /** \brief Options that control the behavior of LpFragmenter
42 */
Davide Pesaventoe4b22382018-06-10 14:37:24 -040043 struct Options
Eric Newberry4c3e6b82015-11-10 16:48:42 -070044 {
Eric Newberry4c3e6b82015-11-10 16:48:42 -070045 /** \brief maximum number of fragments in a packet
46 */
Davide Pesaventoe4b22382018-06-10 14:37:24 -040047 size_t nMaxFragments = 400;
Eric Newberry4c3e6b82015-11-10 16:48:42 -070048 };
49
50 explicit
Davide Pesaventoe4b22382018-06-10 14:37:24 -040051 LpFragmenter(const Options& options, const LinkService* linkService = nullptr);
Eric Newberry4c3e6b82015-11-10 16:48:42 -070052
53 /** \brief set options for fragmenter
54 */
55 void
56 setOptions(const Options& options);
57
58 /** \return LinkService that owns this instance
59 *
60 * This is only used for logging, and may be nullptr.
61 */
62 const LinkService*
63 getLinkService() const;
64
65 /** \brief fragments a network-layer packet into link-layer packets
66 * \param packet an LpPacket that contains a network-layer packet;
67 * must have Fragment field, must not have FragIndex and FragCount fields
68 * \param mtu maximum allowable LpPacket size after fragmentation and sequence number assignment
69 * \return whether fragmentation succeeded, fragmented packets without sequence number
70 */
71 std::tuple<bool, std::vector<lp::Packet>>
72 fragmentPacket(const lp::Packet& packet, size_t mtu);
73
74private:
75 Options m_options;
76 const LinkService* m_linkService;
77};
78
79std::ostream&
80operator<<(std::ostream& os, const FaceLogHelper<LpFragmenter>& flh);
81
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040082} // namespace nfd::face
Eric Newberry4c3e6b82015-11-10 16:48:42 -070083
84#endif // NFD_DAEMON_FACE_LP_FRAGMENTER_HPP