Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 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 | */ |
| 20 | |
| 21 | #include "ccnx-consumer-batches.h" |
| 22 | #include "ns3/ptr.h" |
| 23 | #include "ns3/log.h" |
| 24 | #include "ns3/simulator.h" |
| 25 | #include "ns3/packet.h" |
| 26 | #include "ns3/callback.h" |
| 27 | #include "ns3/string.h" |
| 28 | #include "ns3/uinteger.h" |
| 29 | #include "ns3/double.h" |
| 30 | #include "ns3/batches.h" |
| 31 | |
| 32 | NS_LOG_COMPONENT_DEFINE ("CcnxConsumerBatches"); |
| 33 | |
| 34 | namespace ns3 |
| 35 | { |
| 36 | |
| 37 | NS_OBJECT_ENSURE_REGISTERED (CcnxConsumerBatches); |
| 38 | |
| 39 | TypeId |
| 40 | CcnxConsumerBatches::GetTypeId (void) |
| 41 | { |
| 42 | static TypeId tid = TypeId ("ns3::CcnxConsumerBatches") |
| 43 | .SetParent<CcnxConsumer> () |
| 44 | .AddConstructor<CcnxConsumerBatches> () |
| 45 | |
| 46 | .AddAttribute ("Batches", "Batches to schedule. Should be vector, containing pairs of time and amount", |
| 47 | // TypeId::ATTR_SET, |
| 48 | StringValue (""), |
| 49 | MakeBatchesAccessor (&CcnxConsumerBatches::GetBatch, &CcnxConsumerBatches::SetBatch), |
| 50 | MakeBatchesChecker ()) |
| 51 | ; |
| 52 | |
| 53 | return tid; |
| 54 | } |
| 55 | |
| 56 | CcnxConsumerBatches::CcnxConsumerBatches () |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | void |
| 61 | CcnxConsumerBatches::SetBatch (const Batches &batches) |
| 62 | { |
| 63 | // std::cout << "Batches: " << batches << "\n"; |
| 64 | for (Batches::const_iterator i = batches.begin (); i != batches.end (); i++) |
| 65 | { |
| 66 | Simulator::Schedule (i->get<0> (), &CcnxConsumerBatches::AddBatch, this, i->get<1> ()); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | CcnxConsumerBatches::AddBatch (uint32_t amount) |
| 72 | { |
| 73 | // std::cout << Simulator::Now () << " adding batch of " << amount << "\n"; |
| 74 | m_seqMax += amount; |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 75 | m_rtt->ClearSent (); // this is important, otherwise RTT estimation for the new batch will be affected by previous batch history |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 76 | ScheduleNextPacket (); |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | CcnxConsumerBatches::ScheduleNextPacket () |
| 81 | { |
| 82 | if (!m_sendEvent.IsRunning ()) |
Alexander Afanasyev | 1e9348f | 2012-01-22 17:15:54 -0800 | [diff] [blame] | 83 | m_sendEvent = Simulator::Schedule (Seconds (m_rtt->RetransmitTimeout ().ToDouble (Time::S) * 0.1), &CcnxConsumer::SendPacket, this); |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /////////////////////////////////////////////////// |
| 87 | // Process incoming packets // |
| 88 | /////////////////////////////////////////////////// |
| 89 | |
| 90 | } // namespace ns3 |