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