blob: fc4e363e2af2207e1c977640ccb5bdf7c59cdc68 [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>
19 */
20
21#ifndef CCNX_CONSUMER_H
22#define CCNX_CONSUMER_H
23
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080024#include "ccnx-app.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080025#include "ns3/random-variable.h"
26#include "ns3/ccnx-name-components.h"
Alexander Afanasyev781ea812011-12-15 22:42:09 -080027#include "ns3/nstime.h"
28
29#include <set>
30
31#include <boost/multi_index_container.hpp>
32#include <boost/multi_index/tag.hpp>
33#include <boost/multi_index/ordered_index.hpp>
34#include <boost/multi_index/member.hpp>
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070035
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080036#include <boost/thread/mutex.hpp>
37
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070038namespace ns3
39{
40
Ilya Moiseenko956d0542012-01-02 15:26:40 -080041/**
42 * @ingroup ccnx
43 * \brief CCNx application for sending out Interest packets
44 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080045class CcnxConsumer: public CcnxApp
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070046{
47public:
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070048 static TypeId GetTypeId ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070049
Ilya Moiseenko956d0542012-01-02 15:26:40 -080050 /**
51 * \brief Default constructor
52 * Sets up randomizer function and packet sequence number
53 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070054 CcnxConsumer ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070055
Alexander Afanasyev781ea812011-12-15 22:42:09 -080056 // From CcnxApp
57 // virtual void
58 // OnInterest (const Ptr<const CcnxInterestHeader> &interest);
59
60 virtual void
61 OnNack (const Ptr<const CcnxInterestHeader> &interest);
62
63 virtual void
64 OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
65 const Ptr<const Packet> &payload);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080066
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070067protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080068 // from CcnxApp
69 virtual void
70 StartApplication ();
71
72 virtual void
73 StopApplication ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070074
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070075private:
Ilya Moiseenko956d0542012-01-02 15:26:40 -080076 /**
77 * \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol
78 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -080079 void
80 SendPacket ();
81
Ilya Moiseenko956d0542012-01-02 15:26:40 -080082 /**
83 * \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration
84 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -080085 void
86 CheckRetxTimeout ();
87
Ilya Moiseenko956d0542012-01-02 15:26:40 -080088 /**
89 * \brief Modifies the frequency of checking the retransmission timeouts
90 * \param retxTimer Timeout defining how frequent retransmission timeouts should be checked
91 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -080092 void
93 SetRetxTimer (Time retxTimer);
94
Ilya Moiseenko956d0542012-01-02 15:26:40 -080095 /**
96 * \brief Returns the frequency of checking the retransmission timeouts
97 * \return Timeout defining how frequent retransmission timeouts should be checked
98 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -080099 Time
100 GetRetxTimer () const;
101
102protected:
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800103 UniformVariable m_rand; ///< \brief this random variable is used for Nonce generation
104 uint32_t m_seq; ///< \brief packet sequence number specific for every application
105 EventId m_sendEvent; ///< \brief Eventid of pending "send packet" event
106 Time m_retxTimer; ///< \brief Timeout defining how frequent retransmission timeouts should be checked
107 EventId m_retxEvent; ///< \brief Event to check whether or not retransmission should be performed
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700108
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800109 Time m_rto; ///< \brief Retransmission timeout
110 Time m_rttVar; ///< \brief RTT variance
111 Time m_sRtt; ///< \brief smoothed RTT
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800112
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800113 Time m_offTime; ///< \brief Time interval between packets
114 CcnxNameComponents m_interestName; ///< \brief CcnxName of the Interest (use CcnxNameComponents)
115 Time m_interestLifeTime; ///< \brief LifeTime for interest packet
116 int32_t m_minSuffixComponents; ///< \brief MinSuffixComponents. See CcnxInterestHeader for more information
117 int32_t m_maxSuffixComponents; ///< \brief MaxSuffixComponents. See CcnxInterestHeader for more information
118 bool m_childSelector; ///< \brief ChildSelector. See CcnxInterestHeader for more information
119 CcnxNameComponents m_exclude; ///< \brief Exclude. See CcnxInterestHeader for more information
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800120
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800121 /**
122 * \struct This struct contains sequence numbers of packets to be retransmitted
123 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800124 struct RetxSeqsContainer :
125 public std::set<uint32_t> { };
126
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800127 RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800128
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800129 /**
130 * \struct This struct contains a pair of packet sequence number and its timeout
131 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800132 struct SeqTimeout
133 {
134 SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { }
135
136 uint32_t seq;
137 Time time;
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800138 };
139
140 class i_seq { };
141 class i_timestamp { };
142
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800143 /**
144 * \struct This struct contains a multi-index for the set of SeqTimeout structs
145 */
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800146 struct SeqTimeoutsContainer :
147 public boost::multi_index::multi_index_container<
148 SeqTimeout,
149 boost::multi_index::indexed_by<
150 boost::multi_index::ordered_unique<
151 boost::multi_index::tag<i_seq>,
152 boost::multi_index::member<SeqTimeout, uint32_t, &SeqTimeout::seq>
153 >,
154 boost::multi_index::ordered_non_unique<
155 boost::multi_index::tag<i_timestamp>,
156 boost::multi_index::member<SeqTimeout, Time, &SeqTimeout::time>
157 >
158 >
159 > { } ;
160
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800161 SeqTimeoutsContainer m_seqTimeouts; ///< \brief multi-index for the set of SeqTimeout structs
162 boost::mutex m_seqTimeoutsGuard; ///< \brief mutex for safe work with the m_seqTimeouts
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800163
Ilya Moiseenko956d0542012-01-02 15:26:40 -0800164 /**
165 * \brief A trace that is called after each transmitted Interest packet
166 */
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800167 TracedCallback<Ptr<const CcnxInterestHeader>,
168 Ptr<CcnxApp>, Ptr<CcnxFace> > m_transmittedInterests;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700169};
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700170
171} // namespace ns3
172
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700173#endif