blob: 41431076afc3dae209371a06b1c061f33fd09f13 [file] [log] [blame]
Junxiao Shid6dcd2c2014-02-16 14:49:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi1e46be32015-01-08 20:18:05 -07003 * 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 Shic099ddb2014-12-25 20:53:20 -070024 */
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_FACE_NDNLP_PARTIAL_MESSAGE_STORE_HPP
27#define NFD_DAEMON_FACE_NDNLP_PARTIAL_MESSAGE_STORE_HPP
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070028
29#include "ndnlp-parse.hpp"
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070030#include "core/scheduler.hpp"
31
32namespace nfd {
33namespace ndnlp {
34
35/** \brief represents a partially received message
36 */
37class PartialMessage : noncopyable
38{
39public:
40 PartialMessage();
Junxiao Shidf3b4382014-02-23 11:28:21 -070041
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070042 bool
43 add(uint16_t fragIndex, uint16_t fragCount, const Block& payload);
Junxiao Shidf3b4382014-02-23 11:28:21 -070044
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070045 bool
46 isComplete() const;
Junxiao Shidf3b4382014-02-23 11:28:21 -070047
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070048 /** \brief reassemble network layer packet
Junxiao Shidf3b4382014-02-23 11:28:21 -070049 *
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070050 * isComplete() must be true before calling this method
Junxiao Shidf3b4382014-02-23 11:28:21 -070051 *
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070052 * \exception ndn::Block::Error packet is malformated
53 * \return network layer packet
54 */
55 Block
56 reassemble();
Junxiao Shidf3b4382014-02-23 11:28:21 -070057
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070058public:
Junxiao Shi1e46be32015-01-08 20:18:05 -070059 scheduler::EventId m_expiry;
Junxiao Shidf3b4382014-02-23 11:28:21 -070060
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070061private:
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 */
70class PartialMessageStore : noncopyable
71{
72public:
Junxiao Shi98e29f42014-03-31 10:27:26 -070073 explicit
74 PartialMessageStore(const time::nanoseconds& idleDuration = time::milliseconds(100));
Junxiao Shidf3b4382014-02-23 11:28:21 -070075
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070076 virtual
77 ~PartialMessageStore();
Junxiao Shidf3b4382014-02-23 11:28:21 -070078
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070079 /** \brief receive a NdnlpData packet
Junxiao Shidf3b4382014-02-23 11:28:21 -070080 *
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070081 * \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 Shidf3b4382014-02-23 11:28:21 -070086
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070087 /// fires when network layer packet is received
Junxiao Shic099ddb2014-12-25 20:53:20 -070088 signal::Signal<PartialMessageStore, Block> onReceive;
Junxiao Shidf3b4382014-02-23 11:28:21 -070089
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070090private:
91 void
92 scheduleCleanup(uint64_t messageIdentifier, shared_ptr<PartialMessage> partialMessage);
Junxiao Shidf3b4382014-02-23 11:28:21 -070093
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070094 void
95 cleanup(uint64_t messageIdentifier);
Junxiao Shidf3b4382014-02-23 11:28:21 -070096
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070097private:
98 std::map<uint64_t, shared_ptr<PartialMessage> > m_partialMessages;
99
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700100 time::nanoseconds m_idleDuration;
Junxiao Shid6dcd2c2014-02-16 14:49:54 -0700101};
102
103} // namespace ndnlp
104} // namespace nfd
105
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700106#endif // NFD_DAEMON_FACE_NDNLP_PARTIAL_MESSAGE_STORE_HPP