blob: 970da4c20839d99d17ebd968cd608d3aa0c68bc4 [file] [log] [blame]
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -07001/* -*- 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>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080019 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070020 */
21
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070022#ifndef NDN_CONSUMER_H
23#define NDN_CONSUMER_H
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070024
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070025#include "ndn-app.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080026#include "ns3/random-variable.h"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070027#include "ns3/ndn-name-components.h"
Alexander Afanasyev781ea812011-12-15 22:42:09 -080028#include "ns3/nstime.h"
Alexander Afanasyev011b8592011-12-21 14:45:27 -080029#include "ns3/data-rate.h"
Ilya Moiseenko2c069b92012-01-13 18:39:28 -080030//#include "ns3/internet-module.h"
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -080031#include "ns3/rtt-estimator.h"
Alexander Afanasyev781ea812011-12-15 22:42:09 -080032
33#include <set>
Alexander Afanasyev400aae12013-01-19 13:27:52 -080034#include <map>
Alexander Afanasyev781ea812011-12-15 22:42:09 -080035
36#include <boost/multi_index_container.hpp>
37#include <boost/multi_index/tag.hpp>
38#include <boost/multi_index/ordered_index.hpp>
39#include <boost/multi_index/member.hpp>
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070040
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070041namespace ns3 {
42namespace ndn {
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070043
Ilya Moiseenko956d0542012-01-02 15:26:40 -080044/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070045 * @ingroup ndn
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070046 * \brief NDN application for sending out Interest packets
Ilya Moiseenko956d0542012-01-02 15:26:40 -080047 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070048class Consumer: public App
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070049{
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -080050public:
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070051 static TypeId GetTypeId ();
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -080052
Ilya Moiseenko956d0542012-01-02 15:26:40 -080053 /**
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -080054 * \brief Default constructor
Ilya Moiseenko956d0542012-01-02 15:26:40 -080055 * Sets up randomizer function and packet sequence number
56 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070057 Consumer ();
58 virtual ~Consumer () {};
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070059
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070060 // From App
Alexander Afanasyev781ea812011-12-15 22:42:09 -080061 // virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070062 // OnInterest (const Ptr<const InterestHeader> &interest);
Alexander Afanasyev781ea812011-12-15 22:42:09 -080063
64 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070065 OnNack (const Ptr<const InterestHeader> &interest, Ptr<Packet> packet);
Alexander Afanasyev781ea812011-12-15 22:42:09 -080066
67 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070068 OnContentObject (const Ptr<const ContentObjectHeader> &contentObject,
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080069 Ptr<Packet> payload);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080070
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070071 /**
72 * @brief Timeout event
73 * @param sequenceNumber time outed sequence number
74 */
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080075 virtual void
76 OnTimeout (uint32_t sequenceNumber);
Alexander Afanasyev029d38d2012-01-09 13:50:50 -080077
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070078 /**
79 * @brief Actually send packet
80 */
Alexander Afanasyev029d38d2012-01-09 13:50:50 -080081 void
82 SendPacket ();
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -080083
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070084protected:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070085 // from App
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080086 virtual void
87 StartApplication ();
88
89 virtual void
90 StopApplication ();
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -080091
Ilya Moiseenko956d0542012-01-02 15:26:40 -080092 /**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070093 * \brief Constructs the Interest packet and sends it using a callback to the underlying NDN protocol
Ilya Moiseenko956d0542012-01-02 15:26:40 -080094 */
Alexander Afanasyev029d38d2012-01-09 13:50:50 -080095 virtual void
96 ScheduleNextPacket () = 0;
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -080097
Ilya Moiseenko956d0542012-01-02 15:26:40 -080098 /**
99 * \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration
100 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800101 void
102 CheckRetxTimeout ();
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800103
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800104 /**
105 * \brief Modifies the frequency of checking the retransmission timeouts
106 * \param retxTimer Timeout defining how frequent retransmission timeouts should be checked
107 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800108 void
109 SetRetxTimer (Time retxTimer);
110
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800111 /**
112 * \brief Returns the frequency of checking the retransmission timeouts
113 * \return Timeout defining how frequent retransmission timeouts should be checked
114 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800115 Time
116 GetRetxTimer () const;
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800117
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800118protected:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700119 UniformVariable m_rand; ///< @brief nonce generator
Alexander Afanasyev029d38d2012-01-09 13:50:50 -0800120
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700121 uint32_t m_seq; ///< @brief currently requested sequence number
122 uint32_t m_seqMax; ///< @brief maximum number of sequence number
123 EventId m_sendEvent; ///< @brief EventId of pending "send packet" event
124 Time m_retxTimer; ///< @brief Currently estimated retransmission timer
125 EventId m_retxEvent; ///< @brief Event to check whether or not retransmission should be performed
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800126
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700127 Ptr<RttEstimator> m_rtt; ///< @brief RTT estimator
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800128
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800129 Time m_offTime; ///< \brief Time interval between packets
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700130 NameComponents m_interestName; ///< \brief NDN Name of the Interest (use NameComponents)
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800131 Time m_interestLifeTime; ///< \brief LifeTime for interest packet
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800132
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800133/// @cond include_hidden
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800134 /**
135 * \struct This struct contains sequence numbers of packets to be retransmitted
136 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800137 struct RetxSeqsContainer :
138 public std::set<uint32_t> { };
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800139
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800140 RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800141
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800142 /**
143 * \struct This struct contains a pair of packet sequence number and its timeout
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800144 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800145 struct SeqTimeout
146 {
147 SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { }
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800148
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800149 uint32_t seq;
150 Time time;
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800151 };
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700152/// @endcond
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800153
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700154/// @cond include_hidden
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800155 class i_seq { };
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800156 class i_timestamp { };
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700157/// @endcond
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800158
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700159/// @cond include_hidden
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800160 /**
161 * \struct This struct contains a multi-index for the set of SeqTimeout structs
162 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800163 struct SeqTimeoutsContainer :
164 public boost::multi_index::multi_index_container<
165 SeqTimeout,
166 boost::multi_index::indexed_by<
167 boost::multi_index::ordered_unique<
168 boost::multi_index::tag<i_seq>,
169 boost::multi_index::member<SeqTimeout, uint32_t, &SeqTimeout::seq>
170 >,
171 boost::multi_index::ordered_non_unique<
172 boost::multi_index::tag<i_timestamp>,
173 boost::multi_index::member<SeqTimeout, Time, &SeqTimeout::time>
174 >
175 >
176 > { } ;
177
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800178 SeqTimeoutsContainer m_seqTimeouts; ///< \brief multi-index for the set of SeqTimeout structs
Alexander Afanasyev400aae12013-01-19 13:27:52 -0800179
180 SeqTimeoutsContainer m_seqLastDelay;
181 SeqTimeoutsContainer m_seqFullDelay;
182 std::map<uint32_t, uint32_t> m_seqRetxCounts;
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800183
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800184 TracedCallback<Ptr<App> /* app */, uint32_t /* seqno */,
185 Time /* delay */, int32_t /*hop count*/> m_lastRetransmittedInterestDataDelay;
186 TracedCallback<Ptr<App> /* app */, uint32_t /* seqno */,
187 Time /* delay */, uint32_t /*retx count*/,
188 int32_t /*hop count*/> m_firstInterestDataDelay;
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800189
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700190/// @endcond
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700191};
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700192
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700193} // namespace ndn
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700194} // namespace ns3
195
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700196#endif