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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | #include "ndn-consumer-batches.h" |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 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 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 32 | NS_LOG_COMPONENT_DEFINE ("ndn.ConsumerBatches"); |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 33 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 34 | namespace ns3 { |
| 35 | namespace ndn { |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 36 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 37 | NS_OBJECT_ENSURE_REGISTERED (ConsumerBatches); |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 38 | |
| 39 | TypeId |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 40 | ConsumerBatches::GetTypeId (void) |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 41 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 42 | static TypeId tid = TypeId ("ns3::ndn::ConsumerBatches") |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 43 | .SetGroupName ("Ndn") |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 44 | .SetParent<Consumer> () |
| 45 | .AddConstructor<ConsumerBatches> () |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 46 | |
| 47 | .AddAttribute ("Batches", "Batches to schedule. Should be vector, containing pairs of time and amount", |
| 48 | // TypeId::ATTR_SET, |
| 49 | StringValue (""), |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 50 | MakeBatchesAccessor (&ConsumerBatches::GetBatch, &ConsumerBatches::SetBatch), |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 51 | MakeBatchesChecker ()) |
| 52 | ; |
| 53 | |
| 54 | return tid; |
| 55 | } |
| 56 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 57 | ConsumerBatches::ConsumerBatches () |
Alexander Afanasyev | 3476edf | 2012-08-14 11:26:00 -0700 | [diff] [blame^] | 58 | : m_initial (true) |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 59 | { |
| 60 | } |
| 61 | |
| 62 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 63 | ConsumerBatches::SetBatch (const Batches &batches) |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 64 | { |
| 65 | // std::cout << "Batches: " << batches << "\n"; |
| 66 | for (Batches::const_iterator i = batches.begin (); i != batches.end (); i++) |
| 67 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 68 | Simulator::Schedule (i->get<0> (), &ConsumerBatches::AddBatch, this, i->get<1> ()); |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 73 | ConsumerBatches::AddBatch (uint32_t amount) |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 74 | { |
| 75 | // std::cout << Simulator::Now () << " adding batch of " << amount << "\n"; |
| 76 | m_seqMax += amount; |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 77 | m_rtt->ClearSent (); // this is important, otherwise RTT estimation for the new batch will be affected by previous batch history |
Alexander Afanasyev | 3476edf | 2012-08-14 11:26:00 -0700 | [diff] [blame^] | 78 | m_initial = true; |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 79 | ScheduleNextPacket (); |
| 80 | } |
| 81 | |
| 82 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 83 | ConsumerBatches::ScheduleNextPacket () |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 84 | { |
| 85 | if (!m_sendEvent.IsRunning ()) |
Alexander Afanasyev | 3476edf | 2012-08-14 11:26:00 -0700 | [diff] [blame^] | 86 | { |
| 87 | Time delay = Seconds (0); |
| 88 | if (!m_initial) delay = m_rtt->RetransmitTimeout (); |
| 89 | |
| 90 | m_initial = false; |
| 91 | m_sendEvent = Simulator::Schedule (delay, &Consumer::SendPacket, this); |
| 92 | } |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /////////////////////////////////////////////////// |
| 96 | // Process incoming packets // |
| 97 | /////////////////////////////////////////////////// |
| 98 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 99 | } // namespace ndn |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 100 | } // namespace ns3 |