NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ndn-consumer-batches.cc
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 "ndn-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 
31 #include "../utils/batches.h"
32 
33 NS_LOG_COMPONENT_DEFINE ("ndn.ConsumerBatches");
34 
35 namespace ns3 {
36 namespace ndn {
37 
38 NS_OBJECT_ENSURE_REGISTERED (ConsumerBatches);
39 
40 TypeId
41 ConsumerBatches::GetTypeId (void)
42 {
43  static TypeId tid = TypeId ("ns3::ndn::ConsumerBatches")
44  .SetGroupName ("Ndn")
45  .SetParent<Consumer> ()
46  .AddConstructor<ConsumerBatches> ()
47 
48  .AddAttribute ("Batches", "Batches to schedule. Should be vector, containing pairs of time and amount",
49  // TypeId::ATTR_SET,
50  StringValue (""),
51  MakeBatchesAccessor (&ConsumerBatches::m_batches),
52  MakeBatchesChecker ())
53  ;
54 
55  return tid;
56 }
57 
59  : m_initial (true)
60 {
61 }
62 
63 void
64 ConsumerBatches::StartApplication ()
65 {
67 
68  // std::cout << "Batches: " << batches << "\n";
69  for (Batches::const_iterator i = m_batches.begin (); i != m_batches.end (); i++)
70  {
71  Simulator::ScheduleWithContext (GetNode ()->GetId (), i->get<0> (), &ConsumerBatches::AddBatch, this, i->get<1> ());
72  }
73 }
74 
75 void
76 ConsumerBatches::AddBatch (uint32_t amount)
77 {
78  // std::cout << Simulator::Now () << " adding batch of " << amount << "\n";
79  m_seqMax += amount;
80  m_rtt->ClearSent (); // this is important, otherwise RTT estimation for the new batch will be affected by previous batch history
81  m_initial = true;
83 }
84 
85 void
87 {
88  if (!m_sendEvent.IsRunning ())
89  {
90  Time delay = Seconds (0);
91  if (!m_initial) delay = m_rtt->RetransmitTimeout ();
92 
93  m_initial = false;
94  m_sendEvent = Simulator::Schedule (delay, &Consumer::SendPacket, this);
95  }
96 }
97 
99 // Process incoming packets //
101 
102 } // namespace ndn
103 } // namespace ns3
Consumer()
Default constructor Sets up randomizer function and packet sequence number.
Definition: ndn-consumer.cc:86
uint32_t GetId() const
Get application ID (ID of applications face)
Definition: ndn-app.cc:88
ConsumerBatches()
Default constructor.
EventId m_sendEvent
EventId of pending "send packet" event.
Definition: ndn-consumer.h:131
Ptr< RttEstimator > m_rtt
RTT estimator.
Definition: ndn-consumer.h:135
uint32_t m_seqMax
maximum number of sequence number
Definition: ndn-consumer.h:130
void SendPacket()
Actually send packet.
virtual void StartApplication()
Called at time specified by Start.
virtual void ScheduleNextPacket()
Constructs the Interest packet and sends it using a callback to the underlying NDN protocol...