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.h
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: Ilya Moiseenko <iliamo@cs.ucla.edu>
19  * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
20  */
21 
22 #ifndef NDN_CONSUMER_H
23 #define NDN_CONSUMER_H
24 
25 #include "ndn-app.h"
26 #include "ns3/random-variable.h"
27 #include "ns3/ndn-name.h"
28 #include "ns3/nstime.h"
29 #include "ns3/data-rate.h"
30 #include "ns3/ndn-rtt-estimator.h"
31 
32 #include <set>
33 #include <map>
34 
35 #include <boost/multi_index_container.hpp>
36 #include <boost/multi_index/tag.hpp>
37 #include <boost/multi_index/ordered_index.hpp>
38 #include <boost/multi_index/member.hpp>
39 
40 namespace ns3 {
41 namespace ndn {
42 
47 class Consumer: public App
48 {
49 public:
50  static TypeId GetTypeId ();
51 
56  Consumer ();
57  virtual ~Consumer () {};
58 
59  // From App
60  // virtual void
61  // OnInterest (const Ptr<const Interest> &interest);
62 
63  virtual void
64  OnNack (Ptr<const Interest> interest);
65 
66  virtual void
67  OnData (Ptr<const Data> contentObject);
68 
73  virtual void
74  OnTimeout (uint32_t sequenceNumber);
75 
79  void
80  SendPacket ();
81 
89  virtual void
90  WillSendOutInterest (uint32_t sequenceNumber);
91 
92 protected:
93  // from App
94  virtual void
96 
97  virtual void
98  StopApplication ();
99 
103  virtual void
104  ScheduleNextPacket () = 0;
105 
109  void
110  CheckRetxTimeout ();
111 
116  void
117  SetRetxTimer (Time retxTimer);
118 
123  Time
124  GetRetxTimer () const;
125 
126 protected:
127  UniformVariable m_rand;
128 
129  uint32_t m_seq;
130  uint32_t m_seqMax;
131  EventId m_sendEvent;
132  Time m_retxTimer;
133  EventId m_retxEvent;
134 
135  Ptr<RttEstimator> m_rtt;
136 
137  Time m_offTime;
140 
142 
145  struct RetxSeqsContainer :
146  public std::set<uint32_t> { };
147 
148  RetxSeqsContainer m_retxSeqs;
149 
153  struct SeqTimeout
154  {
155  SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { }
156 
157  uint32_t seq;
158  Time time;
159  };
161 
163  class i_seq { };
164  class i_timestamp { };
166 
168 
171  struct SeqTimeoutsContainer :
172  public boost::multi_index::multi_index_container<
173  SeqTimeout,
174  boost::multi_index::indexed_by<
175  boost::multi_index::ordered_unique<
176  boost::multi_index::tag<i_seq>,
177  boost::multi_index::member<SeqTimeout, uint32_t, &SeqTimeout::seq>
178  >,
179  boost::multi_index::ordered_non_unique<
180  boost::multi_index::tag<i_timestamp>,
181  boost::multi_index::member<SeqTimeout, Time, &SeqTimeout::time>
182  >
183  >
184  > { } ;
185 
186  SeqTimeoutsContainer m_seqTimeouts;
187 
188  SeqTimeoutsContainer m_seqLastDelay;
189  SeqTimeoutsContainer m_seqFullDelay;
190  std::map<uint32_t, uint32_t> m_seqRetxCounts;
191 
192  TracedCallback<Ptr<App> /* app */, uint32_t /* seqno */,
193  Time /* delay */, int32_t /*hop count*/> m_lastRetransmittedInterestDataDelay;
194  TracedCallback<Ptr<App> /* app */, uint32_t /* seqno */,
195  Time /* delay */, uint32_t /*retx count*/,
196  int32_t /*hop count*/> m_firstInterestDataDelay;
197 
199 };
200 
201 } // namespace ndn
202 } // namespace ns3
203 
204 #endif
NDN application for sending out Interest packets.
Definition: ndn-consumer.h:47
Class for NDN Name.
Definition: name.h:29
virtual void OnTimeout(uint32_t sequenceNumber)
Timeout event.
Consumer()
Default constructor Sets up randomizer function and packet sequence number.
Definition: ndn-consumer.cc:86
Name m_interestName
NDN Name of the Interest (use Name)
Definition: ndn-consumer.h:138
virtual void ScheduleNextPacket()=0
Constructs the Interest packet and sends it using a callback to the underlying NDN protocol...
UniformVariable m_rand
nonce generator
Definition: ndn-consumer.h:127
Time m_retxTimer
Currently estimated retransmission timer.
Definition: ndn-consumer.h:132
EventId m_sendEvent
EventId of pending "send packet" event.
Definition: ndn-consumer.h:131
virtual void OnData(Ptr< const Data > contentObject)
Method that will be called every time new Data arrives.
EventId m_retxEvent
Event to check whether or not retransmission should be performed.
Definition: ndn-consumer.h:133
Base class that all NDN applications should be derived from.
Definition: ndn-app.h:50
Ptr< RttEstimator > m_rtt
RTT estimator.
Definition: ndn-consumer.h:135
Time GetRetxTimer() const
Returns the frequency of checking the retransmission timeouts.
void CheckRetxTimeout()
Checks if the packet need to be retransmitted becuase of retransmission timer expiration.
uint32_t m_seqMax
maximum number of sequence number
Definition: ndn-consumer.h:130
Time m_offTime
Time interval between packets.
Definition: ndn-consumer.h:137
void SendPacket()
Actually send packet.
virtual void WillSendOutInterest(uint32_t sequenceNumber)
An event that is fired just before an Interest packet is actually send out (send is inevitable) ...
virtual void StartApplication()
Called at time specified by Start.
uint32_t m_seq
currently requested sequence number
Definition: ndn-consumer.h:129
virtual void StopApplication()
Called at time specified by Stop.
Time m_interestLifeTime
LifeTime for interest packet.
Definition: ndn-consumer.h:139
void SetRetxTimer(Time retxTimer)
Modifies the frequency of checking the retransmission timeouts.
Definition: ndn-consumer.cc:97
virtual void OnNack(Ptr< const Interest > interest)
Method that will be called every time new NACK arrives.