blob: 9b28a2c4ff78972cd9a356123d343838ef2119a5 [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
22#ifndef CCNX_CONSUMER_H
23#define CCNX_CONSUMER_H
24
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080025#include "ccnx-app.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080026#include "ns3/random-variable.h"
27#include "ns3/ccnx-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"
Alexander Afanasyev781ea812011-12-15 22:42:09 -080030
31#include <set>
32
33#include <boost/multi_index_container.hpp>
34#include <boost/multi_index/tag.hpp>
35#include <boost/multi_index/ordered_index.hpp>
36#include <boost/multi_index/member.hpp>
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070037
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080038#include <boost/thread/mutex.hpp>
39
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070040namespace ns3
41{
42
Ilya Moiseenko956d0542012-01-02 15:26:40 -080043/**
44 * @ingroup ccnx
45 * \brief CCNx application for sending out Interest packets
46 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080047class CcnxConsumer: public CcnxApp
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070048{
49public:
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070050 static TypeId GetTypeId ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070051
Ilya Moiseenko956d0542012-01-02 15:26:40 -080052 /**
53 * \brief Default constructor
54 * Sets up randomizer function and packet sequence number
55 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070056 CcnxConsumer ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070057
Alexander Afanasyev781ea812011-12-15 22:42:09 -080058 // From CcnxApp
59 // virtual void
60 // OnInterest (const Ptr<const CcnxInterestHeader> &interest);
61
62 virtual void
63 OnNack (const Ptr<const CcnxInterestHeader> &interest);
64
65 virtual void
66 OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
67 const Ptr<const Packet> &payload);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080068
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070069protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080070 // from CcnxApp
71 virtual void
72 StartApplication ();
73
74 virtual void
75 StopApplication ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070076
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070077private:
Ilya Moiseenko956d0542012-01-02 15:26:40 -080078 /**
79 * \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol
80 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -080081 void
Alexander Afanasyev011b8592011-12-21 14:45:27 -080082 ScheduleNextPacket ();
83
84 void
85 UpdateMean ();
86
87 void
88 SetPayloadSize (uint32_t payload);
89
90 uint32_t
91 GetPayloadSize () const;
92
93 void
94 SetDesiredRate (DataRate rate);
95
96 DataRate
97 GetDesiredRate () const;
98
99 void
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800100 SendPacket ();
101
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800102 /**
103 * \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration
104 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800105 void
106 CheckRetxTimeout ();
107
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800108 /**
109 * \brief Modifies the frequency of checking the retransmission timeouts
110 * \param retxTimer Timeout defining how frequent retransmission timeouts should be checked
111 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800112 void
113 SetRetxTimer (Time retxTimer);
114
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800115 /**
116 * \brief Returns the frequency of checking the retransmission timeouts
117 * \return Timeout defining how frequent retransmission timeouts should be checked
118 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800119 Time
120 GetRetxTimer () const;
121
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800122 double
123 GetMaxSize () const;
124
125 void
126 SetMaxSize (double size);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800127
128protected:
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800129 UniformVariable m_rand; // nonce generator
130
131 ExponentialVariable m_randExp; // packet inter-arrival time generation (Poisson process)
132 DataRate m_desiredRate; // Desired data packet rate
133 uint32_t m_payloadSize; // expected payload size
134
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800135 uint32_t m_seq;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800136 uint32_t m_seqMax; // maximum number of sequence number
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800137 EventId m_sendEvent; // Eventid of pending "send packet" event
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800138 Time m_retxTimer;
139 EventId m_retxEvent; // Event to check whether or not retransmission should be performed
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800140
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800141 Time m_rto; ///< \brief Retransmission timeout
142 Time m_rttVar; ///< \brief RTT variance
143 Time m_sRtt; ///< \brief smoothed RTT
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700144
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800145 Time m_offTime; ///< \brief Time interval between packets
146 CcnxNameComponents m_interestName; ///< \brief CcnxName of the Interest (use CcnxNameComponents)
147 Time m_interestLifeTime; ///< \brief LifeTime for interest packet
148 int32_t m_minSuffixComponents; ///< \brief MinSuffixComponents. See CcnxInterestHeader for more information
149 int32_t m_maxSuffixComponents; ///< \brief MaxSuffixComponents. See CcnxInterestHeader for more information
150 bool m_childSelector; ///< \brief ChildSelector. See CcnxInterestHeader for more information
151 CcnxNameComponents m_exclude; ///< \brief Exclude. See CcnxInterestHeader for more information
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800152
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800153 /**
154 * \struct This struct contains sequence numbers of packets to be retransmitted
155 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800156 struct RetxSeqsContainer :
157 public std::set<uint32_t> { };
158
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800159 RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800160
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800161 /**
162 * \struct This struct contains a pair of packet sequence number and its timeout
163 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800164 struct SeqTimeout
165 {
166 SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { }
167
168 uint32_t seq;
169 Time time;
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800170 };
171
172 class i_seq { };
173 class i_timestamp { };
174
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800175 /**
176 * \struct This struct contains a multi-index for the set of SeqTimeout structs
177 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800178 struct SeqTimeoutsContainer :
179 public boost::multi_index::multi_index_container<
180 SeqTimeout,
181 boost::multi_index::indexed_by<
182 boost::multi_index::ordered_unique<
183 boost::multi_index::tag<i_seq>,
184 boost::multi_index::member<SeqTimeout, uint32_t, &SeqTimeout::seq>
185 >,
186 boost::multi_index::ordered_non_unique<
187 boost::multi_index::tag<i_timestamp>,
188 boost::multi_index::member<SeqTimeout, Time, &SeqTimeout::time>
189 >
190 >
191 > { } ;
192
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800193 SeqTimeoutsContainer m_seqTimeouts; ///< \brief multi-index for the set of SeqTimeout structs
194 boost::mutex m_seqTimeoutsGuard; ///< \brief mutex for safe work with the m_seqTimeouts
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800195
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800196 /**
197 * \brief A trace that is called after each transmitted Interest packet
198 */
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800199 TracedCallback<Ptr<const CcnxInterestHeader>,
200 Ptr<CcnxApp>, Ptr<CcnxFace> > m_transmittedInterests;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700201};
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700202
203} // namespace ns3
204
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700205#endif