blob: 7cfb739c701cefa7dc965dfb0dc8a98015126aea [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"
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 Moiseenko8196d2e2011-08-29 13:03:22 -070035
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080036#include <boost/thread/mutex.hpp>
37
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070038namespace ns3
39{
40
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080041class CcnxConsumer: public CcnxApp
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070042{
43public:
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070044 static TypeId GetTypeId ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070045
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070046 CcnxConsumer ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070047
Alexander Afanasyev781ea812011-12-15 22:42:09 -080048 // From CcnxApp
49 // virtual void
50 // OnInterest (const Ptr<const CcnxInterestHeader> &interest);
51
52 virtual void
53 OnNack (const Ptr<const CcnxInterestHeader> &interest);
54
55 virtual void
56 OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
57 const Ptr<const Packet> &payload);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080058
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070059protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080060 // from CcnxApp
61 virtual void
62 StartApplication ();
63
64 virtual void
65 StopApplication ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070066
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070067private:
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070068 //helpers
Alexander Afanasyev781ea812011-12-15 22:42:09 -080069 void
70 SendPacket ();
71
72 void
73 CheckRetxTimeout ();
74
75 void
76 SetRetxTimer (Time retxTimer);
77
78 Time
79 GetRetxTimer () const;
80
81protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080082 UniformVariable m_rand;
83 uint32_t m_seq;
84 EventId m_sendEvent; // Eventid of pending "send packet" event
Alexander Afanasyev781ea812011-12-15 22:42:09 -080085 Time m_retxTimer;
86 EventId m_retxEvent; // Event to check whether or not retransmission should be performed
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070087
Alexander Afanasyev781ea812011-12-15 22:42:09 -080088 Time m_rto; // Retransmission timeout
89 Time m_rttVar; // RTT variance
90 Time m_sRtt; // smoothed RTT
91
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080092 Time m_offTime;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070093 CcnxNameComponents m_interestName;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080094 Time m_interestLifeTime;
95 int32_t m_minSuffixComponents;
96 int32_t m_maxSuffixComponents;
97 bool m_childSelector;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070098 CcnxNameComponents m_exclude;
Alexander Afanasyev781ea812011-12-15 22:42:09 -080099
100 struct RetxSeqsContainer :
101 public std::set<uint32_t> { };
102
103 RetxSeqsContainer m_retxSeqs; // ordered set of sequence numbers to be retransmitted
104
105 struct SeqTimeout
106 {
107 SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { }
108
109 uint32_t seq;
110 Time time;
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800111 };
112
113 class i_seq { };
114 class i_timestamp { };
115
116 struct SeqTimeoutsContainer :
117 public boost::multi_index::multi_index_container<
118 SeqTimeout,
119 boost::multi_index::indexed_by<
120 boost::multi_index::ordered_unique<
121 boost::multi_index::tag<i_seq>,
122 boost::multi_index::member<SeqTimeout, uint32_t, &SeqTimeout::seq>
123 >,
124 boost::multi_index::ordered_non_unique<
125 boost::multi_index::tag<i_timestamp>,
126 boost::multi_index::member<SeqTimeout, Time, &SeqTimeout::time>
127 >
128 >
129 > { } ;
130
131 SeqTimeoutsContainer m_seqTimeouts;
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800132 boost::mutex m_seqTimeoutsGuard;
133
134 TracedCallback<Ptr<const CcnxInterestHeader>,
135 Ptr<CcnxApp>, Ptr<CcnxFace> > m_transmittedInterests;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700136};
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700137
138} // namespace ns3
139
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700140#endif