blob: 0030a818404726769911c2e255a9f20af644ed12 [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 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
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080063 OnNack (const Ptr<const CcnxInterestHeader> &interest, Ptr<Packet> packet);
Alexander Afanasyev781ea812011-12-15 22:42:09 -080064
65 virtual void
66 OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080067 Ptr<Packet> payload);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080068
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080069 virtual void
70 OnTimeout (uint32_t sequenceNumber);
Alexander Afanasyev029d38d2012-01-09 13:50:50 -080071
72 // Simulator::Schedule doesn't work with protected members???
73 void
74 SendPacket ();
75
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070076protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080077 // from CcnxApp
78 virtual void
79 StartApplication ();
80
81 virtual void
82 StopApplication ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070083
Ilya Moiseenko956d0542012-01-02 15:26:40 -080084 /**
85 * \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol
86 */
Alexander Afanasyev029d38d2012-01-09 13:50:50 -080087 virtual void
88 ScheduleNextPacket () = 0;
Alexander Afanasyev011b8592011-12-21 14:45:27 -080089
Ilya Moiseenko956d0542012-01-02 15:26:40 -080090 /**
91 * \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration
92 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -080093 void
94 CheckRetxTimeout ();
95
Ilya Moiseenko956d0542012-01-02 15:26:40 -080096 /**
97 * \brief Modifies the frequency of checking the retransmission timeouts
98 * \param retxTimer Timeout defining how frequent retransmission timeouts should be checked
99 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800100 void
101 SetRetxTimer (Time retxTimer);
102
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800103 /**
104 * \brief Returns the frequency of checking the retransmission timeouts
105 * \return Timeout defining how frequent retransmission timeouts should be checked
106 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800107 Time
108 GetRetxTimer () const;
109
110protected:
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800111 UniformVariable m_rand; // nonce generator
Alexander Afanasyev029d38d2012-01-09 13:50:50 -0800112
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800113 uint32_t m_seq;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800114 uint32_t m_seqMax; // maximum number of sequence number
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800115 EventId m_sendEvent; // Eventid of pending "send packet" event
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800116 Time m_retxTimer;
117 EventId m_retxEvent; // Event to check whether or not retransmission should be performed
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800118
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800119 Ptr<RttEstimator> m_rtt;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700120
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800121 Time m_offTime; ///< \brief Time interval between packets
122 CcnxNameComponents m_interestName; ///< \brief CcnxName of the Interest (use CcnxNameComponents)
123 Time m_interestLifeTime; ///< \brief LifeTime for interest packet
124 int32_t m_minSuffixComponents; ///< \brief MinSuffixComponents. See CcnxInterestHeader for more information
125 int32_t m_maxSuffixComponents; ///< \brief MaxSuffixComponents. See CcnxInterestHeader for more information
126 bool m_childSelector; ///< \brief ChildSelector. See CcnxInterestHeader for more information
127 CcnxNameComponents m_exclude; ///< \brief Exclude. See CcnxInterestHeader for more information
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800128
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800129 /**
130 * \struct This struct contains sequence numbers of packets to be retransmitted
131 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800132 struct RetxSeqsContainer :
133 public std::set<uint32_t> { };
134
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800135 RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800136
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800137 /**
138 * \struct This struct contains a pair of packet sequence number and its timeout
139 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800140 struct SeqTimeout
141 {
142 SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { }
143
144 uint32_t seq;
145 Time time;
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800146 };
147
148 class i_seq { };
149 class i_timestamp { };
150
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800151 /**
152 * \struct This struct contains a multi-index for the set of SeqTimeout structs
153 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800154 struct SeqTimeoutsContainer :
155 public boost::multi_index::multi_index_container<
156 SeqTimeout,
157 boost::multi_index::indexed_by<
158 boost::multi_index::ordered_unique<
159 boost::multi_index::tag<i_seq>,
160 boost::multi_index::member<SeqTimeout, uint32_t, &SeqTimeout::seq>
161 >,
162 boost::multi_index::ordered_non_unique<
163 boost::multi_index::tag<i_timestamp>,
164 boost::multi_index::member<SeqTimeout, Time, &SeqTimeout::time>
165 >
166 >
167 > { } ;
168
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800169 SeqTimeoutsContainer m_seqTimeouts; ///< \brief multi-index for the set of SeqTimeout structs
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800170
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800171 /**
172 * \brief A trace that is called after each transmitted Interest packet
173 */
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800174 TracedCallback<Ptr<const CcnxInterestHeader>,
175 Ptr<CcnxApp>, Ptr<CcnxFace> > m_transmittedInterests;
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800176
177 TracedCallback<Ptr<Node>, Ptr<Node>, uint32_t, uint32_t > m_pathWeightsTrace;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700178};
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700179
180} // namespace ns3
181
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700182#endif