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 | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 30 | #include "ns3/rtt-estimator.h" |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 31 | |
| 32 | #include <set> |
| 33 | |
| 34 | #include <boost/multi_index_container.hpp> |
| 35 | #include <boost/multi_index/tag.hpp> |
| 36 | #include <boost/multi_index/ordered_index.hpp> |
| 37 | #include <boost/multi_index/member.hpp> |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 38 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 39 | #include <boost/thread/mutex.hpp> |
| 40 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 41 | namespace ns3 |
| 42 | { |
| 43 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 44 | /** |
| 45 | * @ingroup ccnx |
| 46 | * \brief CCNx application for sending out Interest packets |
| 47 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 48 | class CcnxConsumer: public CcnxApp |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 49 | { |
| 50 | public: |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 51 | static TypeId GetTypeId (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 52 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 53 | /** |
| 54 | * \brief Default constructor |
| 55 | * Sets up randomizer function and packet sequence number |
| 56 | */ |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 57 | CcnxConsumer (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 58 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 59 | // From CcnxApp |
| 60 | // virtual void |
| 61 | // OnInterest (const Ptr<const CcnxInterestHeader> &interest); |
| 62 | |
| 63 | virtual void |
| 64 | OnNack (const Ptr<const CcnxInterestHeader> &interest); |
| 65 | |
| 66 | virtual void |
| 67 | OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject, |
| 68 | const Ptr<const Packet> &payload); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 69 | |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 70 | virtual void |
| 71 | OnTimeout (uint32_t sequenceNumber); |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 72 | |
| 73 | // Simulator::Schedule doesn't work with protected members??? |
| 74 | void |
| 75 | SendPacket (); |
| 76 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 77 | protected: |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 78 | // from CcnxApp |
| 79 | virtual void |
| 80 | StartApplication (); |
| 81 | |
| 82 | virtual void |
| 83 | StopApplication (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 84 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 85 | /** |
| 86 | * \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol |
| 87 | */ |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 88 | virtual void |
| 89 | ScheduleNextPacket () = 0; |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 90 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 91 | /** |
| 92 | * \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration |
| 93 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 94 | void |
| 95 | CheckRetxTimeout (); |
| 96 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 97 | /** |
| 98 | * \brief Modifies the frequency of checking the retransmission timeouts |
| 99 | * \param retxTimer Timeout defining how frequent retransmission timeouts should be checked |
| 100 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 101 | void |
| 102 | SetRetxTimer (Time retxTimer); |
| 103 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 104 | /** |
| 105 | * \brief Returns the frequency of checking the retransmission timeouts |
| 106 | * \return Timeout defining how frequent retransmission timeouts should be checked |
| 107 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 108 | Time |
| 109 | GetRetxTimer () const; |
| 110 | |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 111 | virtual void |
| 112 | SetPayloadSize (uint32_t payload); |
| 113 | |
| 114 | uint32_t |
| 115 | GetPayloadSize () const; |
| 116 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 117 | double |
| 118 | GetMaxSize () const; |
| 119 | |
| 120 | void |
| 121 | SetMaxSize (double size); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 122 | |
| 123 | protected: |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 124 | UniformVariable m_rand; // nonce generator |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 125 | uint32_t m_payloadSize; // expected payload size |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 126 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 127 | uint32_t m_seq; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 128 | uint32_t m_seqMax; // maximum number of sequence number |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 129 | EventId m_sendEvent; // Eventid of pending "send packet" event |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 130 | Time m_retxTimer; |
| 131 | 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] | 132 | |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 133 | Ptr<RttEstimator> m_rtt; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 134 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 135 | Time m_offTime; ///< \brief Time interval between packets |
| 136 | CcnxNameComponents m_interestName; ///< \brief CcnxName of the Interest (use CcnxNameComponents) |
| 137 | Time m_interestLifeTime; ///< \brief LifeTime for interest packet |
| 138 | int32_t m_minSuffixComponents; ///< \brief MinSuffixComponents. See CcnxInterestHeader for more information |
| 139 | int32_t m_maxSuffixComponents; ///< \brief MaxSuffixComponents. See CcnxInterestHeader for more information |
| 140 | bool m_childSelector; ///< \brief ChildSelector. See CcnxInterestHeader for more information |
| 141 | CcnxNameComponents m_exclude; ///< \brief Exclude. See CcnxInterestHeader for more information |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 142 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 143 | /** |
| 144 | * \struct This struct contains sequence numbers of packets to be retransmitted |
| 145 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 146 | struct RetxSeqsContainer : |
| 147 | public std::set<uint32_t> { }; |
| 148 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 149 | RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 150 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 151 | /** |
| 152 | * \struct This struct contains a pair of packet sequence number and its timeout |
| 153 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 154 | struct SeqTimeout |
| 155 | { |
| 156 | SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { } |
| 157 | |
| 158 | uint32_t seq; |
| 159 | Time time; |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | class i_seq { }; |
| 163 | class i_timestamp { }; |
| 164 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 165 | /** |
| 166 | * \struct This struct contains a multi-index for the set of SeqTimeout structs |
| 167 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 168 | struct SeqTimeoutsContainer : |
| 169 | public boost::multi_index::multi_index_container< |
| 170 | SeqTimeout, |
| 171 | boost::multi_index::indexed_by< |
| 172 | boost::multi_index::ordered_unique< |
| 173 | boost::multi_index::tag<i_seq>, |
| 174 | boost::multi_index::member<SeqTimeout, uint32_t, &SeqTimeout::seq> |
| 175 | >, |
| 176 | boost::multi_index::ordered_non_unique< |
| 177 | boost::multi_index::tag<i_timestamp>, |
| 178 | boost::multi_index::member<SeqTimeout, Time, &SeqTimeout::time> |
| 179 | > |
| 180 | > |
| 181 | > { } ; |
| 182 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 183 | SeqTimeoutsContainer m_seqTimeouts; ///< \brief multi-index for the set of SeqTimeout structs |
| 184 | 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] | 185 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 186 | /** |
| 187 | * \brief A trace that is called after each transmitted Interest packet |
| 188 | */ |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 189 | TracedCallback<Ptr<const CcnxInterestHeader>, |
| 190 | Ptr<CcnxApp>, Ptr<CcnxFace> > m_transmittedInterests; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 191 | }; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 192 | |
| 193 | } // namespace ns3 |
| 194 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 195 | #endif |