blob: 1e2985a026e16ac0306f91003b922cd58246bf40 [file] [log] [blame]
Junxiao Shi9b0d3e92014-02-15 12:27:12 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08003 * Copyright (c) 2014-2015, Regents of the University of California,
4 * 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.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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/>.
Junxiao Shia22a2172015-01-05 11:14:02 -070024 */
Junxiao Shi9b0d3e92014-02-15 12:27:12 -070025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_FACE_NDNLP_SLICER_HPP
27#define NFD_DAEMON_FACE_NDNLP_SLICER_HPP
Junxiao Shi9b0d3e92014-02-15 12:27:12 -070028
29#include "ndnlp-tlv.hpp"
30#include "ndnlp-sequence-generator.hpp"
31
32namespace nfd {
33namespace ndnlp {
34
Junxiao Shia22a2172015-01-05 11:14:02 -070035typedef shared_ptr<std::vector<Block>> PacketArray;
Junxiao Shi9b0d3e92014-02-15 12:27:12 -070036
37/** \brief provides fragmentation feature at sender
38 */
39class Slicer : noncopyable
40{
41public:
Junxiao Shia22a2172015-01-05 11:14:02 -070042 /** \param mtu maximum size of NDNLP header and payload
43 * \note If NDNLP packets are to be encapsulated in an additional header
44 * (eg. in UDP packets), the caller must deduct such overhead.
45 */
Junxiao Shi9b0d3e92014-02-15 12:27:12 -070046 explicit
47 Slicer(size_t mtu);
Junxiao Shidf3b4382014-02-23 11:28:21 -070048
Junxiao Shi9b0d3e92014-02-15 12:27:12 -070049 virtual
50 ~Slicer();
Junxiao Shidf3b4382014-02-23 11:28:21 -070051
Junxiao Shi9b0d3e92014-02-15 12:27:12 -070052 PacketArray
53 slice(const Block& block);
54
55private:
Junxiao Shia22a2172015-01-05 11:14:02 -070056 template<bool T>
57 size_t
58 encodeFragment(ndn::EncodingImpl<T>& blk,
59 uint64_t seq, uint16_t fragIndex, uint16_t fragCount,
60 const uint8_t* payload, size_t payloadSize);
61
Junxiao Shi9b0d3e92014-02-15 12:27:12 -070062 /// estimate the size of NDNLP header and maximum payload size per packet
63 void
64 estimateOverhead();
Junxiao Shidf3b4382014-02-23 11:28:21 -070065
Junxiao Shi9b0d3e92014-02-15 12:27:12 -070066private:
67 SequenceGenerator m_seqgen;
Junxiao Shidf3b4382014-02-23 11:28:21 -070068
Junxiao Shi9b0d3e92014-02-15 12:27:12 -070069 /// maximum packet size
70 size_t m_mtu;
Junxiao Shidf3b4382014-02-23 11:28:21 -070071
Junxiao Shi9b0d3e92014-02-15 12:27:12 -070072 /// maximum payload size
73 size_t m_maxPayload;
74};
75
76} // namespace ndnlp
77} // namespace nfd
78
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070079#endif // NFD_DAEMON_FACE_NDNLP_SLICER_HPP