NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
ndn-consumer-batches.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #include "ndn-consumer-batches.hpp"
21 #include "ns3/ptr.h"
22 #include "ns3/log.h"
23 #include "ns3/simulator.h"
24 #include "ns3/packet.h"
25 #include "ns3/callback.h"
26 #include "ns3/string.h"
27 #include "ns3/uinteger.h"
28 #include "ns3/double.h"
29 
30 #include "utils/batches.hpp"
31 
32 NS_LOG_COMPONENT_DEFINE("ndn.ConsumerBatches");
33 
34 namespace ns3 {
35 namespace ndn {
36 
38 
39 TypeId
41 {
42  static TypeId tid =
43  TypeId("ns3::ndn::ConsumerBatches")
44  .SetGroupName("Ndn")
45  .SetParent<Consumer>()
46  .AddConstructor<ConsumerBatches>()
47 
48  .AddAttribute("Batches",
49  "Batches to schedule. Should be vector, containing pairs of time and amount",
50  // TypeId::ATTR_SET,
51  StringValue(""), MakeBatchesAccessor(&ConsumerBatches::m_batches),
53 
54  return tid;
55 }
56 
58  : m_initial(true)
59 {
60 }
61 
62 void
63 ConsumerBatches::StartApplication()
64 {
66 
67  // std::cout << "Batches: " << batches << "\n";
68  for (Batches::const_iterator i = m_batches.begin(); i != m_batches.end(); i++) {
69  Simulator::ScheduleWithContext(GetNode()->GetId(), std::get<0>(*i), &ConsumerBatches::AddBatch,
70  this, std::get<1>(*i));
71  }
72 }
73 
74 void
75 ConsumerBatches::AddBatch(uint32_t amount)
76 {
77  // std::cout << Simulator::Now () << " adding batch of " << amount << "\n";
78  m_seqMax += amount;
79  m_rtt->ClearSent(); // this is important, otherwise RTT estimation for the new batch will be
80  // affected by previous batch history
81  m_initial = true;
83 }
84 
85 void
87 {
88  if (!m_sendEvent.IsRunning()) {
89  Time delay = Seconds(0);
90  if (!m_initial)
91  delay = m_rtt->RetransmitTimeout();
92 
93  m_initial = false;
94  m_sendEvent = Simulator::Schedule(delay, &Consumer::SendPacket, this);
95  }
96 }
97 
98 } // namespace ndn
99 } // namespace ns3
uint32_t m_seqMax
maximum number of sequence number
Copyright (c) 2011-2015 Regents of the University of California.
Ptr< const AttributeAccessor > MakeBatchesAccessor(T1 a1)
Definition: batches.hpp:55
NS_OBJECT_ENSURE_REGISTERED(ContentStore)
Ptr< RttEstimator > m_rtt
RTT estimator.
NDN application for sending out Interest packets.
void SendPacket()
Actually send packet.
virtual void ScheduleNextPacket()
Constructs the Interest packet and sends it using a callback to the underlying NDN protocol...
Copyright (c) 2011-2015 Regents of the University of California.
ConsumerBatches()
Default constructor.
uint32_t GetId() const
Get application ID (ID of applications face)
Definition: ndn-app.cpp:100
EventId m_sendEvent
EventId of pending "send packet" event.
Ptr< const AttributeChecker > MakeBatchesChecker(void)
virtual void StartApplication()
Called at time specified by Start.
ndn ConsumerBatches
Copyright (c) 2011-2015 Regents of the University of California.