blob: 51d14d937b371c51157d3e425d2eff1911a8b310 [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/*
3 * Copyright (c) 2014-2018, 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 Pesaventoa3148082018-04-12 18:21:54 -040029#include "core/common.hpp"
Eric Newberry4c3e6b82015-11-10 16:48:42 -070030#include "face-log.hpp"
31
32#include <ndn-cxx/lp/packet.hpp>
33
34namespace nfd {
35namespace face {
36
37class LinkService;
38
39/** \brief fragments network-layer packets into NDNLPv2 link-layer packets
Davide Pesaventoa3148082018-04-12 18:21:54 -040040 * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
Eric Newberry4c3e6b82015-11-10 16:48:42 -070041 */
42class LpFragmenter
43{
44public:
45 /** \brief Options that control the behavior of LpFragmenter
46 */
Davide Pesaventoe4b22382018-06-10 14:37:24 -040047 struct Options
Eric Newberry4c3e6b82015-11-10 16:48:42 -070048 {
Eric Newberry4c3e6b82015-11-10 16:48:42 -070049 /** \brief maximum number of fragments in a packet
50 */
Davide Pesaventoe4b22382018-06-10 14:37:24 -040051 size_t nMaxFragments = 400;
Eric Newberry4c3e6b82015-11-10 16:48:42 -070052 };
53
54 explicit
Davide Pesaventoe4b22382018-06-10 14:37:24 -040055 LpFragmenter(const Options& options, const LinkService* linkService = nullptr);
Eric Newberry4c3e6b82015-11-10 16:48:42 -070056
57 /** \brief set options for fragmenter
58 */
59 void
60 setOptions(const Options& options);
61
62 /** \return LinkService that owns this instance
63 *
64 * This is only used for logging, and may be nullptr.
65 */
66 const LinkService*
67 getLinkService() const;
68
69 /** \brief fragments a network-layer packet into link-layer packets
70 * \param packet an LpPacket that contains a network-layer packet;
71 * must have Fragment field, must not have FragIndex and FragCount fields
72 * \param mtu maximum allowable LpPacket size after fragmentation and sequence number assignment
73 * \return whether fragmentation succeeded, fragmented packets without sequence number
74 */
75 std::tuple<bool, std::vector<lp::Packet>>
76 fragmentPacket(const lp::Packet& packet, size_t mtu);
77
78private:
79 Options m_options;
80 const LinkService* m_linkService;
81};
82
83std::ostream&
84operator<<(std::ostream& os, const FaceLogHelper<LpFragmenter>& flh);
85
86} // namespace face
87} // namespace nfd
88
89#endif // NFD_DAEMON_FACE_LP_FRAGMENTER_HPP