blob: d98d7529071d49e5f649deb025c4d933f8a1e5e7 [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 Pesaventocb425e82019-07-14 21:48:22 -04003 * Copyright (c) 2014-2019, 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
33namespace nfd {
34namespace face {
35
Eric Newberry4c3e6b82015-11-10 16:48:42 -070036/** \brief fragments network-layer packets into NDNLPv2 link-layer packets
Davide Pesaventoa3148082018-04-12 18:21:54 -040037 * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
Eric Newberry4c3e6b82015-11-10 16:48:42 -070038 */
39class LpFragmenter
40{
41public:
42 /** \brief Options that control the behavior of LpFragmenter
43 */
Davide Pesaventoe4b22382018-06-10 14:37:24 -040044 struct Options
Eric Newberry4c3e6b82015-11-10 16:48:42 -070045 {
Eric Newberry4c3e6b82015-11-10 16:48:42 -070046 /** \brief maximum number of fragments in a packet
47 */
Davide Pesaventoe4b22382018-06-10 14:37:24 -040048 size_t nMaxFragments = 400;
Eric Newberry4c3e6b82015-11-10 16:48:42 -070049 };
50
51 explicit
Davide Pesaventoe4b22382018-06-10 14:37:24 -040052 LpFragmenter(const Options& options, const LinkService* linkService = nullptr);
Eric Newberry4c3e6b82015-11-10 16:48:42 -070053
54 /** \brief set options for fragmenter
55 */
56 void
57 setOptions(const Options& options);
58
59 /** \return LinkService that owns this instance
60 *
61 * This is only used for logging, and may be nullptr.
62 */
63 const LinkService*
64 getLinkService() const;
65
66 /** \brief fragments a network-layer packet into link-layer packets
67 * \param packet an LpPacket that contains a network-layer packet;
68 * must have Fragment field, must not have FragIndex and FragCount fields
69 * \param mtu maximum allowable LpPacket size after fragmentation and sequence number assignment
70 * \return whether fragmentation succeeded, fragmented packets without sequence number
71 */
72 std::tuple<bool, std::vector<lp::Packet>>
73 fragmentPacket(const lp::Packet& packet, size_t mtu);
74
75private:
76 Options m_options;
77 const LinkService* m_linkService;
78};
79
80std::ostream&
81operator<<(std::ostream& os, const FaceLogHelper<LpFragmenter>& flh);
82
83} // namespace face
84} // namespace nfd
85
86#endif // NFD_DAEMON_FACE_LP_FRAGMENTER_HPP