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