Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -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 | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame^] | 24 | */ |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_FACE_NDNLP_PARTIAL_MESSAGE_STORE_HPP |
| 27 | #define NFD_DAEMON_FACE_NDNLP_PARTIAL_MESSAGE_STORE_HPP |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 28 | |
| 29 | #include "ndnlp-parse.hpp" |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 30 | #include "core/scheduler.hpp" |
| 31 | |
| 32 | namespace nfd { |
| 33 | namespace ndnlp { |
| 34 | |
| 35 | /** \brief represents a partially received message |
| 36 | */ |
| 37 | class PartialMessage : noncopyable |
| 38 | { |
| 39 | public: |
| 40 | PartialMessage(); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 41 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 42 | bool |
| 43 | add(uint16_t fragIndex, uint16_t fragCount, const Block& payload); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 44 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 45 | bool |
| 46 | isComplete() const; |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 47 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 48 | /** \brief reassemble network layer packet |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 49 | * |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 50 | * isComplete() must be true before calling this method |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 51 | * |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 52 | * \exception ndn::Block::Error packet is malformated |
| 53 | * \return network layer packet |
| 54 | */ |
| 55 | Block |
| 56 | reassemble(); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 57 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 58 | public: |
| 59 | EventId m_expiry; |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 60 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 61 | private: |
| 62 | size_t m_fragCount; |
| 63 | size_t m_received; |
| 64 | std::vector<Block> m_payloads; |
| 65 | size_t m_totalLength; |
| 66 | }; |
| 67 | |
| 68 | /** \brief provides reassembly feature at receiver |
| 69 | */ |
| 70 | class PartialMessageStore : noncopyable |
| 71 | { |
| 72 | public: |
Junxiao Shi | 98e29f4 | 2014-03-31 10:27:26 -0700 | [diff] [blame] | 73 | explicit |
| 74 | PartialMessageStore(const time::nanoseconds& idleDuration = time::milliseconds(100)); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 75 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 76 | virtual |
| 77 | ~PartialMessageStore(); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 78 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 79 | /** \brief receive a NdnlpData packet |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 80 | * |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 81 | * \exception ParseError NDNLP packet is malformated |
| 82 | * \exception ndn::Block::Error network layer packet is malformated |
| 83 | */ |
| 84 | void |
| 85 | receiveNdnlpData(const Block& pkt); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 86 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 87 | /// fires when network layer packet is received |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame^] | 88 | signal::Signal<PartialMessageStore, Block> onReceive; |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 89 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 90 | private: |
| 91 | void |
| 92 | scheduleCleanup(uint64_t messageIdentifier, shared_ptr<PartialMessage> partialMessage); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 93 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 94 | void |
| 95 | cleanup(uint64_t messageIdentifier); |
Junxiao Shi | df3b438 | 2014-02-23 11:28:21 -0700 | [diff] [blame] | 96 | |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 97 | private: |
| 98 | std::map<uint64_t, shared_ptr<PartialMessage> > m_partialMessages; |
| 99 | |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 100 | time::nanoseconds m_idleDuration; |
Junxiao Shi | d6dcd2c | 2014-02-16 14:49:54 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | } // namespace ndnlp |
| 104 | } // namespace nfd |
| 105 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 106 | #endif // NFD_DAEMON_FACE_NDNLP_PARTIAL_MESSAGE_STORE_HPP |