blob: dacc58685f87b432a74e309e9901efb347762f41 [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"
Ilya Moiseenko2c069b92012-01-13 18:39:28 -080030#include "../../internet/model/rtt-estimator.h"
31//#include "ns3/internet-module.h"
Alexander Afanasyev781ea812011-12-15 22:42:09 -080032
33#include <set>
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>
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070039
40namespace 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 Afanasyev59e67712012-02-07 11:49:34 -080057 virtual ~CcnxConsumer () {};
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070058
Alexander Afanasyev781ea812011-12-15 22:42:09 -080059 // From CcnxApp
60 // virtual void
61 // OnInterest (const Ptr<const CcnxInterestHeader> &interest);
62
63 virtual void
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080064 OnNack (const Ptr<const CcnxInterestHeader> &interest, Ptr<Packet> packet);
Alexander Afanasyev781ea812011-12-15 22:42:09 -080065
66 virtual void
67 OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080068 Ptr<Packet> payload);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080069
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070070 /**
71 * @brief Timeout event
72 * @param sequenceNumber time outed sequence number
73 */
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080074 virtual void
75 OnTimeout (uint32_t sequenceNumber);
Alexander Afanasyev029d38d2012-01-09 13:50:50 -080076
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070077 /**
78 * @brief Actually send packet
79 */
Alexander Afanasyev029d38d2012-01-09 13:50:50 -080080 void
81 SendPacket ();
82
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070083protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080084 // from CcnxApp
85 virtual void
86 StartApplication ();
87
88 virtual void
89 StopApplication ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070090
Ilya Moiseenko956d0542012-01-02 15:26:40 -080091 /**
92 * \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol
93 */
Alexander Afanasyev029d38d2012-01-09 13:50:50 -080094 virtual void
95 ScheduleNextPacket () = 0;
Alexander Afanasyev011b8592011-12-21 14:45:27 -080096
Ilya Moiseenko956d0542012-01-02 15:26:40 -080097 /**
98 * \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration
99 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800100 void
101 CheckRetxTimeout ();
102
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800103 /**
104 * \brief Modifies the frequency of checking the retransmission timeouts
105 * \param retxTimer Timeout defining how frequent retransmission timeouts should be checked
106 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800107 void
108 SetRetxTimer (Time retxTimer);
109
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800110 /**
111 * \brief Returns the frequency of checking the retransmission timeouts
112 * \return Timeout defining how frequent retransmission timeouts should be checked
113 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800114 Time
115 GetRetxTimer () const;
116
117protected:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700118 UniformVariable m_rand; ///< @brief nonce generator
Alexander Afanasyev029d38d2012-01-09 13:50:50 -0800119
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700120 uint32_t m_seq; ///< @brief currently requested sequence number
121 uint32_t m_seqMax; ///< @brief maximum number of sequence number
122 EventId m_sendEvent; ///< @brief EventId of pending "send packet" event
123 Time m_retxTimer; ///< @brief Currently estimated retransmission timer
124 EventId m_retxEvent; ///< @brief Event to check whether or not retransmission should be performed
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800125
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700126 Ptr<RttEstimator> m_rtt; ///< @brief RTT estimator
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700127
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800128 Time m_offTime; ///< \brief Time interval between packets
129 CcnxNameComponents m_interestName; ///< \brief CcnxName of the Interest (use CcnxNameComponents)
130 Time m_interestLifeTime; ///< \brief LifeTime for interest packet
131 int32_t m_minSuffixComponents; ///< \brief MinSuffixComponents. See CcnxInterestHeader for more information
132 int32_t m_maxSuffixComponents; ///< \brief MaxSuffixComponents. See CcnxInterestHeader for more information
133 bool m_childSelector; ///< \brief ChildSelector. See CcnxInterestHeader for more information
134 CcnxNameComponents m_exclude; ///< \brief Exclude. See CcnxInterestHeader for more information
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800135
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700136/// @cond include_hidden
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800137 /**
138 * \struct This struct contains sequence numbers of packets to be retransmitted
139 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800140 struct RetxSeqsContainer :
141 public std::set<uint32_t> { };
142
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800143 RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800144
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800145 /**
146 * \struct This struct contains a pair of packet sequence number and its timeout
147 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800148 struct SeqTimeout
149 {
150 SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { }
151
152 uint32_t seq;
153 Time time;
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800154 };
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700155/// @endcond
156
157/// @cond include_hidden
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800158 class i_seq { };
159 class i_timestamp { };
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700160/// @endcond
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800161
Alexander Afanasyev6315ef72012-06-01 20:56:31 -0700162/// @cond include_hidden
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800163 /**
164 * \struct This struct contains a multi-index for the set of SeqTimeout structs
165 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800166 struct SeqTimeoutsContainer :
167 public boost::multi_index::multi_index_container<
168 SeqTimeout,
169 boost::multi_index::indexed_by<
170 boost::multi_index::ordered_unique<
171 boost::multi_index::tag<i_seq>,
172 boost::multi_index::member<SeqTimeout, uint32_t, &SeqTimeout::seq>
173 >,
174 boost::multi_index::ordered_non_unique<
175 boost::multi_index::tag<i_timestamp>,
176 boost::multi_index::member<SeqTimeout, Time, &SeqTimeout::time>
177 >
178 >
179 > { } ;
180
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800181 SeqTimeoutsContainer m_seqTimeouts; ///< \brief multi-index for the set of SeqTimeout structs
Alexander Afanasyev1ec705f2012-01-23 12:35:10 -0800182 SeqTimeoutsContainer m_seqLifetimes;
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800183
184 TracedCallback<Ptr<Node>, Ptr<Node>, uint32_t, uint32_t > m_pathWeightsTrace;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700185/// @endcond
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700186};
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700187
188} // namespace ns3
189
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700190#endif