blob: 31b4eb99110de694e0982404e631a83af0ae7ddc [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
Alexander Afanasyev029d38d2012-01-09 13:50:50 -080069
70 // Simulator::Schedule doesn't work with protected members???
71 void
72 SendPacket ();
73
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070074protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080075 // from CcnxApp
76 virtual void
77 StartApplication ();
78
79 virtual void
80 StopApplication ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070081
Ilya Moiseenko956d0542012-01-02 15:26:40 -080082 /**
83 * \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol
84 */
Alexander Afanasyev029d38d2012-01-09 13:50:50 -080085 virtual void
86 ScheduleNextPacket () = 0;
Alexander Afanasyev011b8592011-12-21 14:45:27 -080087
Ilya Moiseenko956d0542012-01-02 15:26:40 -080088 /**
89 * \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration
90 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -080091 void
92 CheckRetxTimeout ();
93
Ilya Moiseenko956d0542012-01-02 15:26:40 -080094 /**
95 * \brief Modifies the frequency of checking the retransmission timeouts
96 * \param retxTimer Timeout defining how frequent retransmission timeouts should be checked
97 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -080098 void
99 SetRetxTimer (Time retxTimer);
100
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800101 /**
102 * \brief Returns the frequency of checking the retransmission timeouts
103 * \return Timeout defining how frequent retransmission timeouts should be checked
104 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800105 Time
106 GetRetxTimer () const;
107
Alexander Afanasyev029d38d2012-01-09 13:50:50 -0800108 virtual void
109 SetPayloadSize (uint32_t payload);
110
111 uint32_t
112 GetPayloadSize () const;
113
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800114 double
115 GetMaxSize () const;
116
117 void
118 SetMaxSize (double size);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800119
120protected:
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800121 UniformVariable m_rand; // nonce generator
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800122 uint32_t m_payloadSize; // expected payload size
Alexander Afanasyev029d38d2012-01-09 13:50:50 -0800123
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800124 uint32_t m_seq;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800125 uint32_t m_seqMax; // maximum number of sequence number
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800126 EventId m_sendEvent; // Eventid of pending "send packet" event
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800127 Time m_retxTimer;
128 EventId m_retxEvent; // Event to check whether or not retransmission should be performed
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800129
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800130 Time m_rto; ///< \brief Retransmission timeout
131 Time m_rttVar; ///< \brief RTT variance
132 Time m_sRtt; ///< \brief smoothed RTT
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700133
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800134 Time m_offTime; ///< \brief Time interval between packets
135 CcnxNameComponents m_interestName; ///< \brief CcnxName of the Interest (use CcnxNameComponents)
136 Time m_interestLifeTime; ///< \brief LifeTime for interest packet
137 int32_t m_minSuffixComponents; ///< \brief MinSuffixComponents. See CcnxInterestHeader for more information
138 int32_t m_maxSuffixComponents; ///< \brief MaxSuffixComponents. See CcnxInterestHeader for more information
139 bool m_childSelector; ///< \brief ChildSelector. See CcnxInterestHeader for more information
140 CcnxNameComponents m_exclude; ///< \brief Exclude. See CcnxInterestHeader for more information
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800141
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800142 /**
143 * \struct This struct contains sequence numbers of packets to be retransmitted
144 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800145 struct RetxSeqsContainer :
146 public std::set<uint32_t> { };
147
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800148 RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800149
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800150 /**
151 * \struct This struct contains a pair of packet sequence number and its timeout
152 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800153 struct SeqTimeout
154 {
155 SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { }
156
157 uint32_t seq;
158 Time time;
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800159 };
160
161 class i_seq { };
162 class i_timestamp { };
163
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800164 /**
165 * \struct This struct contains a multi-index for the set of SeqTimeout structs
166 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800167 struct SeqTimeoutsContainer :
168 public boost::multi_index::multi_index_container<
169 SeqTimeout,
170 boost::multi_index::indexed_by<
171 boost::multi_index::ordered_unique<
172 boost::multi_index::tag<i_seq>,
173 boost::multi_index::member<SeqTimeout, uint32_t, &SeqTimeout::seq>
174 >,
175 boost::multi_index::ordered_non_unique<
176 boost::multi_index::tag<i_timestamp>,
177 boost::multi_index::member<SeqTimeout, Time, &SeqTimeout::time>
178 >
179 >
180 > { } ;
181
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800182 SeqTimeoutsContainer m_seqTimeouts; ///< \brief multi-index for the set of SeqTimeout structs
183 boost::mutex m_seqTimeoutsGuard; ///< \brief mutex for safe work with the m_seqTimeouts
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800184
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800185 /**
186 * \brief A trace that is called after each transmitted Interest packet
187 */
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800188 TracedCallback<Ptr<const CcnxInterestHeader>,
189 Ptr<CcnxApp>, Ptr<CcnxFace> > m_transmittedInterests;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700190};
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700191
192} // namespace ns3
193
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700194#endif