blob: c7de1497c3915006de2b5d72e928359fc03682de [file] [log] [blame]
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -08001/* -*- 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 Afanasyev4aac5572012-08-09 10:49:55 -070021#include "ndn-consumer-batches.h"
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080022#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 Afanasyev4aac5572012-08-09 10:49:55 -070032NS_LOG_COMPONENT_DEFINE ("NdnConsumerBatches");
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080033
34namespace ns3
35{
36
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070037NS_OBJECT_ENSURE_REGISTERED (NdnConsumerBatches);
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080038
39TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070040NdnConsumerBatches::GetTypeId (void)
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080041{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070042 static TypeId tid = TypeId ("ns3::NdnConsumerBatches")
43 .SetGroupName ("Ndn")
44 .SetParent<NdnConsumer> ()
45 .AddConstructor<NdnConsumerBatches> ()
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080046
47 .AddAttribute ("Batches", "Batches to schedule. Should be vector, containing pairs of time and amount",
48 // TypeId::ATTR_SET,
49 StringValue (""),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070050 MakeBatchesAccessor (&NdnConsumerBatches::GetBatch, &NdnConsumerBatches::SetBatch),
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080051 MakeBatchesChecker ())
52 ;
53
54 return tid;
55}
56
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070057NdnConsumerBatches::NdnConsumerBatches ()
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080058{
59}
60
61void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070062NdnConsumerBatches::SetBatch (const Batches &batches)
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080063{
64 // std::cout << "Batches: " << batches << "\n";
65 for (Batches::const_iterator i = batches.begin (); i != batches.end (); i++)
66 {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070067 Simulator::Schedule (i->get<0> (), &NdnConsumerBatches::AddBatch, this, i->get<1> ());
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080068 }
69}
70
71void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070072NdnConsumerBatches::AddBatch (uint32_t amount)
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080073{
74 // std::cout << Simulator::Now () << " adding batch of " << amount << "\n";
75 m_seqMax += amount;
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080076 m_rtt->ClearSent (); // this is important, otherwise RTT estimation for the new batch will be affected by previous batch history
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080077 ScheduleNextPacket ();
78}
79
80void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070081NdnConsumerBatches::ScheduleNextPacket ()
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080082{
83 if (!m_sendEvent.IsRunning ())
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070084 m_sendEvent = Simulator::Schedule (Seconds (m_rtt->RetransmitTimeout ().ToDouble (Time::S) * 0.1), &NdnConsumer::SendPacket, this);
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080085}
86
87///////////////////////////////////////////////////
88// Process incoming packets //
89///////////////////////////////////////////////////
90
91} // namespace ns3