blob: ed1558c97406c5a8cdf666c0976b94d3353da9fe [file] [log] [blame]
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -07001/* -*- 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 Afanasyev09c7deb2011-11-23 14:50:10 -080024#include "ccnx-app.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080025#include "ns3/random-variable.h"
26#include "ns3/ccnx-name-components.h"
Alexander Afanasyev781ea812011-12-15 22:42:09 -080027#include "ns3/nstime.h"
Alexander Afanasyev011b8592011-12-21 14:45:27 -080028#include "ns3/data-rate.h"
Alexander Afanasyev781ea812011-12-15 22:42:09 -080029
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 Moiseenko8196d2e2011-08-29 13:03:22 -070036
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080037#include <boost/thread/mutex.hpp>
38
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070039namespace ns3
40{
41
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080042class CcnxConsumer: public CcnxApp
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070043{
44public:
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070045 static TypeId GetTypeId ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070046
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070047 CcnxConsumer ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070048
Alexander Afanasyev781ea812011-12-15 22:42:09 -080049 // 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 Afanasyev09c7deb2011-11-23 14:50:10 -080059
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070060protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080061 // from CcnxApp
62 virtual void
63 StartApplication ();
64
65 virtual void
66 StopApplication ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070067
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070068private:
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070069 //helpers
Alexander Afanasyev781ea812011-12-15 22:42:09 -080070 void
Alexander Afanasyev011b8592011-12-21 14:45:27 -080071 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 Afanasyev781ea812011-12-15 22:42:09 -080089 SendPacket ();
90
91 void
92 CheckRetxTimeout ();
93
94 void
95 SetRetxTimer (Time retxTimer);
96
97 Time
98 GetRetxTimer () const;
99
100protected:
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800101 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 Afanasyev09c7deb2011-11-23 14:50:10 -0800107 uint32_t m_seq;
108 EventId m_sendEvent; // Eventid of pending "send packet" event
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800109 Time m_retxTimer;
110 EventId m_retxEvent; // Event to check whether or not retransmission should be performed
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700111
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800112 Time m_rto; // Retransmission timeout
113 Time m_rttVar; // RTT variance
114 Time m_sRtt; // smoothed RTT
115
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800116 Time m_offTime;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700117 CcnxNameComponents m_interestName;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800118 Time m_interestLifeTime;
119 int32_t m_minSuffixComponents;
120 int32_t m_maxSuffixComponents;
121 bool m_childSelector;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700122 CcnxNameComponents m_exclude;
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800123
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 Afanasyev781ea812011-12-15 22:42:09 -0800135 };
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 Afanasyevbdc0d982011-12-16 01:15:26 -0800156 boost::mutex m_seqTimeoutsGuard;
157
158 TracedCallback<Ptr<const CcnxInterestHeader>,
159 Ptr<CcnxApp>, Ptr<CcnxFace> > m_transmittedInterests;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700160};
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700161
162} // namespace ns3
163
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700164#endif