blob: 81b7d72efd10b7d98f99b041ac5db4ac6d7febb3 [file] [log] [blame]
Weiwei Liue4765012016-06-01 00:10:29 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +00002/*
3 * Copyright (c) 2016-2017, Regents of the University of California,
4 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
Weiwei Liue4765012016-06-01 00:10:29 -07006 *
7 * This file is part of ndn-tools (Named Data Networking Essential Tools).
8 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
9 *
10 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
22 *
23 * @author Wentao Shang
24 * @author Steve DiBenedetto
25 * @author Andrea Tosatto
26 * @author Davide Pesavento
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +000027 * @author Chavoosh Ghasemi
Weiwei Liue4765012016-06-01 00:10:29 -070028 */
29
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +000030#ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_PIPELINE_INTERESTS_FIXED_WINDOW_HPP
31#define NDN_TOOLS_CHUNKS_CATCHUNKS_PIPELINE_INTERESTS_FIXED_WINDOW_HPP
32
Weiwei Liue4765012016-06-01 00:10:29 -070033#include "options.hpp"
34#include "pipeline-interests.hpp"
35
36namespace ndn {
37namespace chunks {
38
39class DataFetcher;
40
41class PipelineInterestsFixedWindowOptions : public Options
42{
43public:
44 explicit
45 PipelineInterestsFixedWindowOptions(const Options& options = Options())
46 : Options(options)
47 , maxPipelineSize(1)
48 {
49 }
50
51public:
52 size_t maxPipelineSize;
53};
54
55/**
56 * @brief Service for retrieving Data via an Interest pipeline
57 *
58 * Retrieves all segments of Data under a given prefix by maintaining a fixed-size window of
59 * N Interests in flight. A user-specified callback function is used to notify the arrival of
60 * each segment of Data.
61 *
62 * No guarantees are made as to the order in which segments are fetched or callbacks are invoked,
63 * i.e. out-of-order delivery is possible.
64 */
65class PipelineInterestsFixedWindow : public PipelineInterests
66{
67public:
68 typedef PipelineInterestsFixedWindowOptions Options;
69
70public:
71 /**
72 * @brief create a PipelineInterestsFixedWindow service
73 *
74 * Configures the pipelining service without specifying the retrieval namespace. After this
75 * configuration the method run must be called to start the Pipeline.
76 */
77 explicit
78 PipelineInterestsFixedWindow(Face& face, const Options& options = Options());
79
80 ~PipelineInterestsFixedWindow() final;
81
82private:
83 /**
84 * @brief fetch all the segments between 0 and m_lastSegmentNo
85 *
86 * Starts a fixed-window pipeline with size equal to m_options.maxPipelineSize. The pipeline
87 * will fetch every segment until the last segment is successfully received or an error occurs.
88 * The segment with segment number equal to m_excludedSegmentNo will not be fetched.
89 */
90 void
91 doRun() final;
92
93 void
94 doCancel() final;
95
96 /**
97 * @brief fetch the next segment that has not been requested yet
98 *
99 * @return false if there is an error or all the segments have been fetched, true otherwise
100 */
101 bool
102 fetchNextSegment(size_t pipeNo);
103
104 void
105 handleData(const Interest& interest, const Data& data, size_t pipeNo);
106
107 void
108 handleFail(const std::string& reason, size_t pipeNo);
109
110private:
111 const Options m_options;
112 std::vector<std::pair<shared_ptr<DataFetcher>, uint64_t>> m_segmentFetchers;
113 uint64_t m_nextSegmentNo;
114 /**
115 * true if one or more segment fetchers encountered an error; if m_hasFinalBlockId
116 * is false, this is usually not a fatal error for the pipeline
117 */
118 bool m_hasFailure;
119};
120
121} // namespace chunks
122} // namespace ndn
Chavoosh Ghasemi4d36ed52017-10-31 22:26:25 +0000123
124#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_PIPELINE_INTERESTS_FIXED_WINDOW_HPP