Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | a22a217 | 2015-01-05 11:14:02 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014, 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | a22a217 | 2015-01-05 11:14:02 -0700 | [diff] [blame^] | 24 | */ |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_FACE_NDNLP_SLICER_HPP |
| 27 | #define NFD_DAEMON_FACE_NDNLP_SLICER_HPP |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 28 | |
| 29 | #include "ndnlp-tlv.hpp" |
| 30 | #include "ndnlp-sequence-generator.hpp" |
| 31 | |
| 32 | namespace nfd { |
| 33 | namespace ndnlp { |
| 34 | |
Junxiao Shi | a22a217 | 2015-01-05 11:14:02 -0700 | [diff] [blame^] | 35 | typedef shared_ptr<std::vector<Block>> PacketArray; |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 36 | |
| 37 | /** \brief provides fragmentation feature at sender |
| 38 | */ |
| 39 | class Slicer : noncopyable |
| 40 | { |
| 41 | public: |
Junxiao Shi | a22a217 | 2015-01-05 11:14:02 -0700 | [diff] [blame^] | 42 | /** \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 Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 46 | explicit |
| 47 | Slicer(size_t mtu); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 48 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 49 | virtual |
| 50 | ~Slicer(); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 51 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 52 | PacketArray |
| 53 | slice(const Block& block); |
| 54 | |
| 55 | private: |
Junxiao Shi | a22a217 | 2015-01-05 11:14:02 -0700 | [diff] [blame^] | 56 | 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 Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 62 | /// estimate the size of NDNLP header and maximum payload size per packet |
| 63 | void |
| 64 | estimateOverhead(); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 65 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 66 | private: |
| 67 | SequenceGenerator m_seqgen; |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 68 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 69 | /// maximum packet size |
| 70 | size_t m_mtu; |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 71 | |
Junxiao Shi | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 72 | /// maximum payload size |
| 73 | size_t m_maxPayload; |
| 74 | }; |
| 75 | |
| 76 | } // namespace ndnlp |
| 77 | } // namespace nfd |
| 78 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 79 | #endif // NFD_DAEMON_FACE_NDNLP_SLICER_HPP |