Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 23 | #include "fetch-manager.h" |
| 24 | |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 25 | #include <boost/make_shared.hpp> |
| 26 | #include <boost/ref.hpp> |
| 27 | #include <boost/throw_exception.hpp> |
| 28 | |
| 29 | using namespace boost; |
| 30 | using namespace std; |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 31 | using namespace Ccnx; |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 76d4fa4 | 2013-01-19 14:51:21 -0800 | [diff] [blame] | 33 | Fetcher::Fetcher (FetchManager &fetchManger, |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 34 | const Ccnx::Name &name, int32_t minSeqNo, int32_t maxSeqNo, |
| 35 | const Ccnx::Name &forwardingHint/* = Ccnx::Name ()*/) |
Alexander Afanasyev | 76d4fa4 | 2013-01-19 14:51:21 -0800 | [diff] [blame] | 36 | : m_fetchManager (fetchManger) |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 37 | , m_active (false) |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 38 | , m_name (name) |
| 39 | , m_forwardingHint (forwardingHint) |
| 40 | , m_minSendSeqNo (-1) |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 41 | , m_maxInOrderRecvSeqNo (-1) |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 42 | , m_minSeqNo (minSeqNo) |
| 43 | , m_maxSeqNo (maxSeqNo) |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 44 | |
Alexander Afanasyev | 49a1852 | 2013-01-18 17:49:04 -0800 | [diff] [blame] | 45 | , m_pipeline (6) // initial "congestion window" |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 46 | , m_activePipeline (0) |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 47 | { |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | Fetcher::~Fetcher () |
| 51 | { |
Alexander Afanasyev | dfe5819 | 2013-01-17 17:34:04 -0800 | [diff] [blame] | 52 | } |
Alexander Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 53 | |
| 54 | void |
| 55 | Fetcher::RestartPipeline () |
| 56 | { |
| 57 | m_active = true; |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 58 | m_minSendSeqNo = m_maxInOrderRecvSeqNo; |
| 59 | |
| 60 | FillPipeline (); |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | Fetcher::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 Afanasyev | 83531a4 | 2013-01-19 16:21:54 -0800 | [diff] [blame] | 75 | } |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 76 | |
| 77 | void |
| 78 | Fetcher::OnData (uint32_t seqno, const Ccnx::Name &name, const Ccnx::Bytes &) |
| 79 | { |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 80 | 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 Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 99 | // bla bla |
| 100 | if (0) |
| 101 | { |
| 102 | m_active = false; |
| 103 | m_fetchManager.DidFetchComplete (*this); |
| 104 | } |
| 105 | } |
| 106 | |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 107 | Closure::TimeoutCallbackReturnValue |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 108 | Fetcher::OnTimeout (uint32_t seqno, const Ccnx::Name &name) |
| 109 | { |
Alexander Afanasyev | 5054789 | 2013-01-19 22:03:45 -0800 | [diff] [blame] | 110 | // Closure::RESULT_REEXPRESS |
| 111 | return Closure::RESULT_OK; |
Alexander Afanasyev | d6c2a90 | 2013-01-19 21:24:30 -0800 | [diff] [blame] | 112 | } |