blob: c707d926fdcfe35c29cf08fa17b15654c95534da [file] [log] [blame]
Junxiao Shid6dcd2c2014-02-16 14:49:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * 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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070024
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070025#ifndef NFD_DAEMON_FACE_NDNLP_PARTIAL_MESSAGE_STORE_HPP
26#define NFD_DAEMON_FACE_NDNLP_PARTIAL_MESSAGE_STORE_HPP
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070027
28#include "ndnlp-parse.hpp"
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070029#include "core/scheduler.hpp"
30
31namespace nfd {
32namespace ndnlp {
33
34/** \brief represents a partially received message
35 */
36class PartialMessage : noncopyable
37{
38public:
39 PartialMessage();
Junxiao Shidf3b4382014-02-23 11:28:21 -070040
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070041 bool
42 add(uint16_t fragIndex, uint16_t fragCount, const Block& payload);
Junxiao Shidf3b4382014-02-23 11:28:21 -070043
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070044 bool
45 isComplete() const;
Junxiao Shidf3b4382014-02-23 11:28:21 -070046
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070047 /** \brief reassemble network layer packet
Junxiao Shidf3b4382014-02-23 11:28:21 -070048 *
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070049 * isComplete() must be true before calling this method
Junxiao Shidf3b4382014-02-23 11:28:21 -070050 *
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070051 * \exception ndn::Block::Error packet is malformated
52 * \return network layer packet
53 */
54 Block
55 reassemble();
Junxiao Shidf3b4382014-02-23 11:28:21 -070056
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070057public:
58 EventId m_expiry;
Junxiao Shidf3b4382014-02-23 11:28:21 -070059
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070060private:
61 size_t m_fragCount;
62 size_t m_received;
63 std::vector<Block> m_payloads;
64 size_t m_totalLength;
65};
66
67/** \brief provides reassembly feature at receiver
68 */
69class PartialMessageStore : noncopyable
70{
71public:
Junxiao Shi98e29f42014-03-31 10:27:26 -070072 explicit
73 PartialMessageStore(const time::nanoseconds& idleDuration = time::milliseconds(100));
Junxiao Shidf3b4382014-02-23 11:28:21 -070074
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070075 virtual
76 ~PartialMessageStore();
Junxiao Shidf3b4382014-02-23 11:28:21 -070077
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070078 /** \brief receive a NdnlpData packet
Junxiao Shidf3b4382014-02-23 11:28:21 -070079 *
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070080 * \exception ParseError NDNLP packet is malformated
81 * \exception ndn::Block::Error network layer packet is malformated
82 */
83 void
84 receiveNdnlpData(const Block& pkt);
Junxiao Shidf3b4382014-02-23 11:28:21 -070085
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070086 /// fires when network layer packet is received
87 EventEmitter<Block> onReceive;
Junxiao Shidf3b4382014-02-23 11:28:21 -070088
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070089private:
90 void
91 scheduleCleanup(uint64_t messageIdentifier, shared_ptr<PartialMessage> partialMessage);
Junxiao Shidf3b4382014-02-23 11:28:21 -070092
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070093 void
94 cleanup(uint64_t messageIdentifier);
Junxiao Shidf3b4382014-02-23 11:28:21 -070095
Junxiao Shid6dcd2c2014-02-16 14:49:54 -070096private:
97 std::map<uint64_t, shared_ptr<PartialMessage> > m_partialMessages;
98
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070099 time::nanoseconds m_idleDuration;
Junxiao Shid6dcd2c2014-02-16 14:49:54 -0700100};
101
102} // namespace ndnlp
103} // namespace nfd
104
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700105#endif // NFD_DAEMON_FACE_NDNLP_PARTIAL_MESSAGE_STORE_HPP