blob: ce0a20c14f966777317a53c0d0f6ef123ab0d674 [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
36namespace ns3
37{
38
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080039class CcnxConsumer: public CcnxApp
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070040{
41public:
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070042 static TypeId GetTypeId ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070043
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070044 CcnxConsumer ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070045
Alexander Afanasyev781ea812011-12-15 22:42:09 -080046 // From CcnxApp
47 // virtual void
48 // OnInterest (const Ptr<const CcnxInterestHeader> &interest);
49
50 virtual void
51 OnNack (const Ptr<const CcnxInterestHeader> &interest);
52
53 virtual void
54 OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
55 const Ptr<const Packet> &payload);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080056
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070057protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080058 // from CcnxApp
59 virtual void
60 StartApplication ();
61
62 virtual void
63 StopApplication ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070064
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070065private:
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070066 //helpers
Alexander Afanasyev781ea812011-12-15 22:42:09 -080067 void
68 SendPacket ();
69
70 void
71 CheckRetxTimeout ();
72
73 void
74 SetRetxTimer (Time retxTimer);
75
76 Time
77 GetRetxTimer () const;
78
79protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080080 UniformVariable m_rand;
81 uint32_t m_seq;
82 EventId m_sendEvent; // Eventid of pending "send packet" event
Alexander Afanasyev781ea812011-12-15 22:42:09 -080083 Time m_retxTimer;
84 EventId m_retxEvent; // Event to check whether or not retransmission should be performed
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070085
Alexander Afanasyev781ea812011-12-15 22:42:09 -080086 Time m_rto; // Retransmission timeout
87 Time m_rttVar; // RTT variance
88 Time m_sRtt; // smoothed RTT
89
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080090 Time m_offTime;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070091 CcnxNameComponents m_interestName;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080092 Time m_interestLifeTime;
93 int32_t m_minSuffixComponents;
94 int32_t m_maxSuffixComponents;
95 bool m_childSelector;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070096 CcnxNameComponents m_exclude;
Alexander Afanasyev781ea812011-12-15 22:42:09 -080097
98 struct RetxSeqsContainer :
99 public std::set<uint32_t> { };
100
101 RetxSeqsContainer m_retxSeqs; // ordered set of sequence numbers to be retransmitted
102
103 struct SeqTimeout
104 {
105 SeqTimeout (uint32_t _seq, Time _time) : seq (_seq), time (_time) { }
106
107 uint32_t seq;
108 Time time;
109
110 bool operator < (const SeqTimeout &st) { return time < st.time || (time == st.time && seq < st.seq); }
111 };
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;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700132};
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700133
134} // namespace ns3
135
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700136#endif