blob: 6afad5b39947f044fa2ff45cbcfa0a4dbc1b221d [file] [log] [blame]
Alexander Afanasyevdfe58192013-01-17 17:34:04 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
20 */
21
22#include "fetcher.h"
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080023#include "fetch-manager.h"
24
Alexander Afanasyevdfe58192013-01-17 17:34:04 -080025#include <boost/make_shared.hpp>
26#include <boost/ref.hpp>
27#include <boost/throw_exception.hpp>
28
29using namespace boost;
30using namespace std;
Alexander Afanasyev50547892013-01-19 22:03:45 -080031using namespace Ccnx;
Alexander Afanasyevdfe58192013-01-17 17:34:04 -080032
Alexander Afanasyev76d4fa42013-01-19 14:51:21 -080033Fetcher::Fetcher (FetchManager &fetchManger,
Alexander Afanasyev49a18522013-01-18 17:49:04 -080034 const Ccnx::Name &name, int32_t minSeqNo, int32_t maxSeqNo,
35 const Ccnx::Name &forwardingHint/* = Ccnx::Name ()*/)
Alexander Afanasyev76d4fa42013-01-19 14:51:21 -080036 : m_fetchManager (fetchManger)
Alexander Afanasyev83531a42013-01-19 16:21:54 -080037 , m_active (false)
Alexander Afanasyev49a18522013-01-18 17:49:04 -080038 , m_name (name)
39 , m_forwardingHint (forwardingHint)
40 , m_minSendSeqNo (-1)
Alexander Afanasyev50547892013-01-19 22:03:45 -080041 , m_maxInOrderRecvSeqNo (-1)
Alexander Afanasyev49a18522013-01-18 17:49:04 -080042 , m_minSeqNo (minSeqNo)
43 , m_maxSeqNo (maxSeqNo)
Alexander Afanasyevdfe58192013-01-17 17:34:04 -080044
Alexander Afanasyev49a18522013-01-18 17:49:04 -080045 , m_pipeline (6) // initial "congestion window"
Alexander Afanasyev50547892013-01-19 22:03:45 -080046 , m_activePipeline (0)
Alexander Afanasyevdfe58192013-01-17 17:34:04 -080047{
Alexander Afanasyevdfe58192013-01-17 17:34:04 -080048}
49
50Fetcher::~Fetcher ()
51{
Alexander Afanasyevdfe58192013-01-17 17:34:04 -080052}
Alexander Afanasyev83531a42013-01-19 16:21:54 -080053
54void
55Fetcher::RestartPipeline ()
56{
57 m_active = true;
Alexander Afanasyev50547892013-01-19 22:03:45 -080058 m_minSendSeqNo = m_maxInOrderRecvSeqNo;
59
60 FillPipeline ();
61}
62
63void
64Fetcher::FillPipeline ()
65{
66 for (; m_minSendSeqNo < m_maxSeqNo && m_activePipeline < m_pipeline; m_minSendSeqNo++)
67 {
68 m_fetchManager.GetCcnx ()
69 ->sendInterest (Name (m_name)("file")(m_minSendSeqNo+1),
70 Closure (bind(&Fetcher::OnData, this, m_minSendSeqNo+1, _1, _2),
71 bind(&Fetcher::OnTimeout, this, m_minSendSeqNo+1, _1)));
72
73 m_activePipeline ++;
74 }
Alexander Afanasyev83531a42013-01-19 16:21:54 -080075}
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080076
77void
78Fetcher::OnData (uint32_t seqno, const Ccnx::Name &name, const Ccnx::Bytes &)
79{
Alexander Afanasyev50547892013-01-19 22:03:45 -080080 m_activePipeline --;
81
82 ////////////////////////////////////////////////////////////////////////////
83 m_outOfOrderRecvSeqNo.insert (seqno);
84 set<int32_t>::iterator inOrderSeqNo = m_outOfOrderRecvSeqNo.begin ();
85 for (; inOrderSeqNo != m_outOfOrderRecvSeqNo.end ();
86 inOrderSeqNo++)
87 {
88 if (*inOrderSeqNo == m_maxInOrderRecvSeqNo+1)
89 {
90 m_maxInOrderRecvSeqNo = *inOrderSeqNo;
91 }
92 else
93 break;
94 }
95 m_outOfOrderRecvSeqNo.erase (m_outOfOrderRecvSeqNo.begin (), inOrderSeqNo);
96 ////////////////////////////////////////////////////////////////////////////
97
98 FillPipeline ();
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080099 // bla bla
100 if (0)
101 {
102 m_active = false;
103 m_fetchManager.DidFetchComplete (*this);
104 }
105}
106
Alexander Afanasyev50547892013-01-19 22:03:45 -0800107Closure::TimeoutCallbackReturnValue
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -0800108Fetcher::OnTimeout (uint32_t seqno, const Ccnx::Name &name)
109{
Alexander Afanasyev50547892013-01-19 22:03:45 -0800110 // Closure::RESULT_REEXPRESS
111 return Closure::RESULT_OK;
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -0800112}