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> |
| 19 | */ |
| 20 | |
| 21 | #ifndef CCNX_CONSUMER_H |
| 22 | #define CCNX_CONSUMER_H |
| 23 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 24 | #include "ccnx-app.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 25 | #include "ns3/random-variable.h" |
| 26 | #include "ns3/ccnx-name-components.h" |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 27 | #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 Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 36 | #include <boost/thread/mutex.hpp> |
| 37 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 38 | namespace ns3 |
| 39 | { |
| 40 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 41 | /** |
| 42 | * @ingroup ccnx |
| 43 | * \brief CCNx application for sending out Interest packets |
| 44 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 45 | class CcnxConsumer: public CcnxApp |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 46 | { |
| 47 | public: |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 48 | static TypeId GetTypeId (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 49 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 50 | /** |
| 51 | * \brief Default constructor |
| 52 | * Sets up randomizer function and packet sequence number |
| 53 | */ |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 54 | CcnxConsumer (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 55 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 56 | // 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 Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 66 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 67 | protected: |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 68 | // from CcnxApp |
| 69 | virtual void |
| 70 | StartApplication (); |
| 71 | |
| 72 | virtual void |
| 73 | StopApplication (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 74 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 75 | private: |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 76 | /** |
| 77 | * \brief Constructs the Interest packet and sends it using a callback to the underlying CCNx protocol |
| 78 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 79 | void |
| 80 | SendPacket (); |
| 81 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 82 | /** |
| 83 | * \brief Checks if the packet need to be retransmitted becuase of retransmission timer expiration |
| 84 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 85 | void |
| 86 | CheckRetxTimeout (); |
| 87 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 88 | /** |
| 89 | * \brief Modifies the frequency of checking the retransmission timeouts |
| 90 | * \param retxTimer Timeout defining how frequent retransmission timeouts should be checked |
| 91 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 92 | void |
| 93 | SetRetxTimer (Time retxTimer); |
| 94 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 95 | /** |
| 96 | * \brief Returns the frequency of checking the retransmission timeouts |
| 97 | * \return Timeout defining how frequent retransmission timeouts should be checked |
| 98 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 99 | Time |
| 100 | GetRetxTimer () const; |
| 101 | |
| 102 | protected: |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 103 | 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 Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 108 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 109 | Time m_rto; ///< \brief Retransmission timeout |
| 110 | Time m_rttVar; ///< \brief RTT variance |
| 111 | Time m_sRtt; ///< \brief smoothed RTT |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 112 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 113 | 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 Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 120 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 121 | /** |
| 122 | * \struct This struct contains sequence numbers of packets to be retransmitted |
| 123 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 124 | struct RetxSeqsContainer : |
| 125 | public std::set<uint32_t> { }; |
| 126 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 127 | RetxSeqsContainer m_retxSeqs; ///< \brief ordered set of sequence numbers to be retransmitted |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 128 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 129 | /** |
| 130 | * \struct This struct contains a pair of packet sequence number and its timeout |
| 131 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 132 | struct SeqTimeout |
| 133 | { |
| 134 | SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { } |
| 135 | |
| 136 | uint32_t seq; |
| 137 | Time time; |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | class i_seq { }; |
| 141 | class i_timestamp { }; |
| 142 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 143 | /** |
| 144 | * \struct This struct contains a multi-index for the set of SeqTimeout structs |
| 145 | */ |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 146 | 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 Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 161 | 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 Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 163 | |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 164 | /** |
| 165 | * \brief A trace that is called after each transmitted Interest packet |
| 166 | */ |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 167 | TracedCallback<Ptr<const CcnxInterestHeader>, |
| 168 | Ptr<CcnxApp>, Ptr<CcnxFace> > m_transmittedInterests; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 169 | }; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 170 | |
| 171 | } // namespace ns3 |
| 172 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 173 | #endif |