blob: 6138416c6fae85ce86d6fe8db53538ca81970fea [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>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080019 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070020 */
21
22#ifndef CCNX_CONSUMER_H
23#define CCNX_CONSUMER_H
24
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080025#include "ccnx-app.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080026#include "ns3/random-variable.h"
27#include "ns3/ccnx-name-components.h"
Alexander Afanasyev781ea812011-12-15 22:42:09 -080028#include "ns3/nstime.h"
Alexander Afanasyev011b8592011-12-21 14:45:27 -080029#include "ns3/data-rate.h"
Alexander Afanasyev781ea812011-12-15 22:42:09 -080030
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 Moiseenko8196d2e2011-08-29 13:03:22 -070037
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080038#include <boost/thread/mutex.hpp>
39
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070040namespace ns3
41{
42
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080043class CcnxConsumer: public CcnxApp
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070044{
45public:
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070046 static TypeId GetTypeId ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070047
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070048 CcnxConsumer ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070049
Alexander Afanasyev781ea812011-12-15 22:42:09 -080050 // 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 Afanasyev09c7deb2011-11-23 14:50:10 -080060
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070061protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080062 // from CcnxApp
63 virtual void
64 StartApplication ();
65
66 virtual void
67 StopApplication ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070068
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070069private:
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070070 //helpers
Alexander Afanasyev781ea812011-12-15 22:42:09 -080071 void
Alexander Afanasyev011b8592011-12-21 14:45:27 -080072 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 Afanasyev781ea812011-12-15 22:42:09 -080090 SendPacket ();
91
92 void
93 CheckRetxTimeout ();
94
95 void
96 SetRetxTimer (Time retxTimer);
97
98 Time
99 GetRetxTimer () const;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800100
101 double
102 GetMaxSize () const;
103
104 void
105 SetMaxSize (double size);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800106
107protected:
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800108 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 Afanasyev09c7deb2011-11-23 14:50:10 -0800114 uint32_t m_seq;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800115 uint32_t m_seqMax; // maximum number of sequence number
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800116 EventId m_sendEvent; // Eventid of pending "send packet" event
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800117 Time m_retxTimer;
118 EventId m_retxEvent; // Event to check whether or not retransmission should be performed
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800119
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800120 Time m_rto; // Retransmission timeout
121 Time m_rttVar; // RTT variance
122 Time m_sRtt; // smoothed RTT
123
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800124 Time m_offTime;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700125 CcnxNameComponents m_interestName;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800126 Time m_interestLifeTime;
127 int32_t m_minSuffixComponents;
128 int32_t m_maxSuffixComponents;
129 bool m_childSelector;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700130 CcnxNameComponents m_exclude;
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800131
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 Afanasyev781ea812011-12-15 22:42:09 -0800143 };
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 Afanasyevbdc0d982011-12-16 01:15:26 -0800164 boost::mutex m_seqTimeoutsGuard;
165
166 TracedCallback<Ptr<const CcnxInterestHeader>,
167 Ptr<CcnxApp>, Ptr<CcnxFace> > m_transmittedInterests;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700168};
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700169
170} // namespace ns3
171
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700172#endif