blob: 40d32cb67dc7d84a7b7755a7618fd90dd7b98536 [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 */
47 class Options
48 {
49 public:
50 Options();
51
52 public:
53 /** \brief maximum number of fragments in a packet
54 */
55 size_t nMaxFragments;
56 };
57
58 explicit
59 LpFragmenter(const Options& options = Options(), const LinkService* linkService = nullptr);
60
61 /** \brief set options for fragmenter
62 */
63 void
64 setOptions(const Options& options);
65
66 /** \return LinkService that owns this instance
67 *
68 * This is only used for logging, and may be nullptr.
69 */
70 const LinkService*
71 getLinkService() const;
72
73 /** \brief fragments a network-layer packet into link-layer packets
74 * \param packet an LpPacket that contains a network-layer packet;
75 * must have Fragment field, must not have FragIndex and FragCount fields
76 * \param mtu maximum allowable LpPacket size after fragmentation and sequence number assignment
77 * \return whether fragmentation succeeded, fragmented packets without sequence number
78 */
79 std::tuple<bool, std::vector<lp::Packet>>
80 fragmentPacket(const lp::Packet& packet, size_t mtu);
81
82private:
83 Options m_options;
84 const LinkService* m_linkService;
85};
86
87std::ostream&
88operator<<(std::ostream& os, const FaceLogHelper<LpFragmenter>& flh);
89
90} // namespace face
91} // namespace nfd
92
93#endif // NFD_DAEMON_FACE_LP_FRAGMENTER_HPP