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 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 43 | class CcnxConsumer: public CcnxApp |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 44 | { |
| 45 | public: |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 46 | static TypeId GetTypeId (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 47 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 48 | CcnxConsumer (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 49 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 50 | // From CcnxApp |
| 51 | // virtual void |
| 52 | // OnInterest (const Ptr<const CcnxInterestHeader> &interest); |
| 53 | |
| 54 | virtual void |
| 55 | OnNack (const Ptr<const CcnxInterestHeader> &interest); |
| 56 | |
| 57 | virtual void |
| 58 | OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject, |
| 59 | const Ptr<const Packet> &payload); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 60 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 61 | protected: |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 62 | // from CcnxApp |
| 63 | virtual void |
| 64 | StartApplication (); |
| 65 | |
| 66 | virtual void |
| 67 | StopApplication (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 68 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 69 | private: |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 70 | //helpers |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 71 | void |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 72 | ScheduleNextPacket (); |
| 73 | |
| 74 | void |
| 75 | UpdateMean (); |
| 76 | |
| 77 | void |
| 78 | SetPayloadSize (uint32_t payload); |
| 79 | |
| 80 | uint32_t |
| 81 | GetPayloadSize () const; |
| 82 | |
| 83 | void |
| 84 | SetDesiredRate (DataRate rate); |
| 85 | |
| 86 | DataRate |
| 87 | GetDesiredRate () const; |
| 88 | |
| 89 | void |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 90 | SendPacket (); |
| 91 | |
| 92 | void |
| 93 | CheckRetxTimeout (); |
| 94 | |
| 95 | void |
| 96 | SetRetxTimer (Time retxTimer); |
| 97 | |
| 98 | Time |
| 99 | GetRetxTimer () const; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 100 | |
| 101 | double |
| 102 | GetMaxSize () const; |
| 103 | |
| 104 | void |
| 105 | SetMaxSize (double size); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 106 | |
| 107 | protected: |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 108 | UniformVariable m_rand; // nonce generator |
| 109 | |
| 110 | ExponentialVariable m_randExp; // packet inter-arrival time generation (Poisson process) |
| 111 | DataRate m_desiredRate; // Desired data packet rate |
| 112 | uint32_t m_payloadSize; // expected payload size |
| 113 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 114 | uint32_t m_seq; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 115 | uint32_t m_seqMax; // maximum number of sequence number |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 116 | EventId m_sendEvent; // Eventid of pending "send packet" event |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 117 | Time m_retxTimer; |
| 118 | EventId m_retxEvent; // Event to check whether or not retransmission should be performed |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 119 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 120 | Time m_rto; // Retransmission timeout |
| 121 | Time m_rttVar; // RTT variance |
| 122 | Time m_sRtt; // smoothed RTT |
| 123 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 124 | Time m_offTime; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 125 | CcnxNameComponents m_interestName; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 126 | Time m_interestLifeTime; |
| 127 | int32_t m_minSuffixComponents; |
| 128 | int32_t m_maxSuffixComponents; |
| 129 | bool m_childSelector; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 130 | CcnxNameComponents m_exclude; |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 131 | |
| 132 | struct RetxSeqsContainer : |
| 133 | public std::set<uint32_t> { }; |
| 134 | |
| 135 | RetxSeqsContainer m_retxSeqs; // ordered set of sequence numbers to be retransmitted |
| 136 | |
| 137 | struct SeqTimeout |
| 138 | { |
| 139 | SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { } |
| 140 | |
| 141 | uint32_t seq; |
| 142 | Time time; |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | class i_seq { }; |
| 146 | class i_timestamp { }; |
| 147 | |
| 148 | struct SeqTimeoutsContainer : |
| 149 | public boost::multi_index::multi_index_container< |
| 150 | SeqTimeout, |
| 151 | boost::multi_index::indexed_by< |
| 152 | boost::multi_index::ordered_unique< |
| 153 | boost::multi_index::tag<i_seq>, |
| 154 | boost::multi_index::member<SeqTimeout, uint32_t, &SeqTimeout::seq> |
| 155 | >, |
| 156 | boost::multi_index::ordered_non_unique< |
| 157 | boost::multi_index::tag<i_timestamp>, |
| 158 | boost::multi_index::member<SeqTimeout, Time, &SeqTimeout::time> |
| 159 | > |
| 160 | > |
| 161 | > { } ; |
| 162 | |
| 163 | SeqTimeoutsContainer m_seqTimeouts; |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 164 | boost::mutex m_seqTimeoutsGuard; |
| 165 | |
| 166 | TracedCallback<Ptr<const CcnxInterestHeader>, |
| 167 | Ptr<CcnxApp>, Ptr<CcnxFace> > m_transmittedInterests; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 168 | }; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 169 | |
| 170 | } // namespace ns3 |
| 171 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 172 | #endif |