Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef CCNX_CONSUMER_H |
| 23 | #define CCNX_CONSUMER_H |
| 24 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 25 | #include "ccnx-app.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 26 | #include "ns3/random-variable.h" |
| 27 | #include "ns3/ccnx-name-components.h" |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 28 | #include "ns3/nstime.h" |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 29 | #include "ns3/data-rate.h" |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 30 | |
| 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 Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 38 | #include <boost/thread/mutex.hpp> |
| 39 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 40 | namespace ns3 |
| 41 | { |
| 42 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 43 | /** |
| 44 | * @ingroup ccnx |
| 45 | * \brief CCNx application for sending out Interest packets |
| 46 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 47 | class CcnxConsumer: public CcnxApp |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 48 | { |
| 49 | public: |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 50 | static TypeId GetTypeId (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 51 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 52 | /** |
| 53 | * \brief Default constructor |
| 54 | * Sets up randomizer function and packet sequence number |
| 55 | */ |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 56 | CcnxConsumer (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 57 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 58 | // 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 Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 68 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 69 | protected: |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 70 | // from CcnxApp |
| 71 | virtual void |
| 72 | StartApplication (); |
| 73 | |
| 74 | virtual void |
| 75 | StopApplication (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 76 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 77 | private: |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 78 | /** |
| 79 | * \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol |
| 80 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 81 | void |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 82 | 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 Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 100 | SendPacket (); |
| 101 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 102 | /** |
| 103 | * \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration |
| 104 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 105 | void |
| 106 | CheckRetxTimeout (); |
| 107 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 108 | /** |
| 109 | * \brief Modifies the frequency of checking the retransmission timeouts |
| 110 | * \param retxTimer Timeout defining how frequent retransmission timeouts should be checked |
| 111 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 112 | void |
| 113 | SetRetxTimer (Time retxTimer); |
| 114 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 115 | /** |
| 116 | * \brief Returns the frequency of checking the retransmission timeouts |
| 117 | * \return Timeout defining how frequent retransmission timeouts should be checked |
| 118 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 119 | Time |
| 120 | GetRetxTimer () const; |
| 121 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 122 | double |
| 123 | GetMaxSize () const; |
| 124 | |
| 125 | void |
| 126 | SetMaxSize (double size); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 127 | |
| 128 | protected: |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 129 | 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 Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 135 | uint32_t m_seq; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 136 | uint32_t m_seqMax; // maximum number of sequence number |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 137 | EventId m_sendEvent; // Eventid of pending "send packet" event |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 138 | Time m_retxTimer; |
| 139 | EventId m_retxEvent; // Event to check whether or not retransmission should be performed |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 140 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 141 | Time m_rto; ///< \brief Retransmission timeout |
| 142 | Time m_rttVar; ///< \brief RTT variance |
| 143 | Time m_sRtt; ///< \brief smoothed RTT |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 144 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 145 | 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 Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 152 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 153 | /** |
| 154 | * \struct This struct contains sequence numbers of packets to be retransmitted |
| 155 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 156 | struct RetxSeqsContainer : |
| 157 | public std::set<uint32_t> { }; |
| 158 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 159 | RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 160 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 161 | /** |
| 162 | * \struct This struct contains a pair of packet sequence number and its timeout |
| 163 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 164 | struct SeqTimeout |
| 165 | { |
| 166 | SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { } |
| 167 | |
| 168 | uint32_t seq; |
| 169 | Time time; |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | class i_seq { }; |
| 173 | class i_timestamp { }; |
| 174 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 175 | /** |
| 176 | * \struct This struct contains a multi-index for the set of SeqTimeout structs |
| 177 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 178 | 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 Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 193 | 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 Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 195 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 196 | /** |
| 197 | * \brief A trace that is called after each transmitted Interest packet |
| 198 | */ |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 199 | TracedCallback<Ptr<const CcnxInterestHeader>, |
| 200 | Ptr<CcnxApp>, Ptr<CcnxFace> > m_transmittedInterests; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 201 | }; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 202 | |
| 203 | } // namespace ns3 |
| 204 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 205 | #endif |