blob: 2da40e659dd2be2af5f28eeff2cb9b1e94f387e6 [file] [log] [blame]
Weiwei Liue4765012016-06-01 00:10:29 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2016, Regents of the University of California,
4 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
6 *
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
27 */
28
29#include "options.hpp"
30#include "pipeline-interests.hpp"
31
32namespace ndn {
33namespace chunks {
34
35class DataFetcher;
36
37class PipelineInterestsFixedWindowOptions : public Options
38{
39public:
40 explicit
41 PipelineInterestsFixedWindowOptions(const Options& options = Options())
42 : Options(options)
43 , maxPipelineSize(1)
44 {
45 }
46
47public:
48 size_t maxPipelineSize;
49};
50
51/**
52 * @brief Service for retrieving Data via an Interest pipeline
53 *
54 * Retrieves all segments of Data under a given prefix by maintaining a fixed-size window of
55 * N Interests in flight. A user-specified callback function is used to notify the arrival of
56 * each segment of Data.
57 *
58 * No guarantees are made as to the order in which segments are fetched or callbacks are invoked,
59 * i.e. out-of-order delivery is possible.
60 */
61class PipelineInterestsFixedWindow : public PipelineInterests
62{
63public:
64 typedef PipelineInterestsFixedWindowOptions Options;
65
66public:
67 /**
68 * @brief create a PipelineInterestsFixedWindow service
69 *
70 * Configures the pipelining service without specifying the retrieval namespace. After this
71 * configuration the method run must be called to start the Pipeline.
72 */
73 explicit
74 PipelineInterestsFixedWindow(Face& face, const Options& options = Options());
75
76 ~PipelineInterestsFixedWindow() final;
77
78private:
79 /**
80 * @brief fetch all the segments between 0 and m_lastSegmentNo
81 *
82 * Starts a fixed-window pipeline with size equal to m_options.maxPipelineSize. The pipeline
83 * will fetch every segment until the last segment is successfully received or an error occurs.
84 * The segment with segment number equal to m_excludedSegmentNo will not be fetched.
85 */
86 void
87 doRun() final;
88
89 void
90 doCancel() final;
91
92 /**
93 * @brief fetch the next segment that has not been requested yet
94 *
95 * @return false if there is an error or all the segments have been fetched, true otherwise
96 */
97 bool
98 fetchNextSegment(size_t pipeNo);
99
100 void
101 handleData(const Interest& interest, const Data& data, size_t pipeNo);
102
103 void
104 handleFail(const std::string& reason, size_t pipeNo);
105
106private:
107 const Options m_options;
108 std::vector<std::pair<shared_ptr<DataFetcher>, uint64_t>> m_segmentFetchers;
109 uint64_t m_nextSegmentNo;
110 /**
111 * true if one or more segment fetchers encountered an error; if m_hasFinalBlockId
112 * is false, this is usually not a fatal error for the pipeline
113 */
114 bool m_hasFailure;
115};
116
117} // namespace chunks
118} // namespace ndn