/
ndn-consumer.hpp
218 lines (180 loc) · 6.72 KB
/
ndn-consumer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2011-2015 Regents of the University of California.
*
* This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
* contributors.
*
* ndnSIM is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
#ifndef NDN_CONSUMER_H
#define NDN_CONSUMER_H
#include "ns3/ndnSIM/model/ndn-common.hpp"
#include "ndn-app.hpp"
#include "ns3/random-variable-stream.h"
#include "ns3/nstime.h"
#include "ns3/data-rate.h"
#include "ns3/ndnSIM/model/ndn-common.hpp"
#include "ns3/ndnSIM/utils/ndn-rtt-estimator.hpp"
#include <set>
#include <map>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/tag.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/member.hpp>
namespace ns3 {
namespace ndn {
/**
* @ingroup ndn-apps
* \brief NDN application for sending out Interest packets
*/
class Consumer : public App {
public:
static TypeId
GetTypeId();
/**
* \brief Default constructor
* Sets up randomizer function and packet sequence number
*/
Consumer();
virtual ~Consumer(){};
// From App
virtual void
OnData(shared_ptr<const Data> contentObject);
// From App
virtual void
OnNack(shared_ptr<const lp::Nack> nack);
/**
* @brief Timeout event
* @param sequenceNumber time outed sequence number
*/
virtual void
OnTimeout(uint32_t sequenceNumber);
/**
* @brief Actually send packet
*/
void
SendPacket();
/**
* @brief An event that is fired just before an Interest packet is actually send out (send is
*inevitable)
*
* The reason for "before" even is that in certain cases (when it is possible to satisfy from the
*local cache),
* the send call will immediately return data, and if "after" even was used, this after would be
*called after
* all processing of incoming data, potentially producing unexpected results.
*/
virtual void
WillSendOutInterest(uint32_t sequenceNumber);
public:
typedef void (*LastRetransmittedInterestDataDelayCallback)(Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount);
typedef void (*FirstInterestDataDelayCallback)(Ptr<App> app, uint32_t seqno, Time delay, uint32_t retxCount, int32_t hopCount);
protected:
// from App
virtual void
StartApplication();
virtual void
StopApplication();
/**
* \brief Constructs the Interest packet and sends it using a callback to the underlying NDN
* protocol
*/
virtual void
ScheduleNextPacket() = 0;
/**
* \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration
*/
void
CheckRetxTimeout();
/**
* \brief Modifies the frequency of checking the retransmission timeouts
* \param retxTimer Timeout defining how frequent retransmission timeouts should be checked
*/
void
SetRetxTimer(Time retxTimer);
/**
* \brief Returns the frequency of checking the retransmission timeouts
* \return Timeout defining how frequent retransmission timeouts should be checked
*/
Time
GetRetxTimer() const;
protected:
Ptr<UniformRandomVariable> m_rand; ///< @brief nonce generator
uint32_t m_seq; ///< @brief currently requested sequence number
uint32_t m_seqMax; ///< @brief maximum number of sequence number
EventId m_sendEvent; ///< @brief EventId of pending "send packet" event
Time m_retxTimer; ///< @brief Currently estimated retransmission timer
EventId m_retxEvent; ///< @brief Event to check whether or not retransmission should be performed
Ptr<RttEstimator> m_rtt; ///< @brief RTT estimator
Time m_offTime; ///< \brief Time interval between packets
Name m_interestName; ///< \brief NDN Name of the Interest (use Name)
Time m_interestLifeTime; ///< \brief LifeTime for interest packet
/// @cond include_hidden
/**
* \struct This struct contains sequence numbers of packets to be retransmitted
*/
struct RetxSeqsContainer : public std::set<uint32_t> {
};
RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted
/**
* \struct This struct contains a pair of packet sequence number and its timeout
*/
struct SeqTimeout {
SeqTimeout(uint32_t _seq, Time _time)
: seq(_seq)
, time(_time)
{
}
uint32_t seq;
Time time;
};
/// @endcond
/// @cond include_hidden
class i_seq {
};
class i_timestamp {
};
/// @endcond
/// @cond include_hidden
/**
* \struct This struct contains a multi-index for the set of SeqTimeout structs
*/
struct SeqTimeoutsContainer
: public boost::multi_index::
multi_index_container<SeqTimeout,
boost::multi_index::
indexed_by<boost::multi_index::
ordered_unique<boost::multi_index::tag<i_seq>,
boost::multi_index::
member<SeqTimeout, uint32_t,
&SeqTimeout::seq>>,
boost::multi_index::
ordered_non_unique<boost::multi_index::
tag<i_timestamp>,
boost::multi_index::
member<SeqTimeout, Time,
&SeqTimeout::time>>>> {
};
SeqTimeoutsContainer m_seqTimeouts; ///< \brief multi-index for the set of SeqTimeout structs
SeqTimeoutsContainer m_seqLastDelay;
SeqTimeoutsContainer m_seqFullDelay;
std::map<uint32_t, uint32_t> m_seqRetxCounts;
TracedCallback<Ptr<App> /* app */, uint32_t /* seqno */, Time /* delay */, int32_t /*hop count*/>
m_lastRetransmittedInterestDataDelay;
TracedCallback<Ptr<App> /* app */, uint32_t /* seqno */, Time /* delay */,
uint32_t /*retx count*/, int32_t /*hop count*/> m_firstInterestDataDelay;
/// @endcond
};
} // namespace ndn
} // namespace ns3
#endif