blob: 239d7cb5d91a704dad0d116918d4720cb56c4f88 [file] [log] [blame]
Ilya Moiseenkoc706f262011-08-22 19:50:49 -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#include "ccnx-interest-sender.h"
22
23NS_LOG_COMPONENT_DEFINE ("CcnxInterestSender");
24
25namespace ns3
26{
27
28NS_OBJECT_ENSURE_REGISTERED (CcnxInterestSender);
29
30TypeId
31CcnxInterestSender::GetTypeId (void)
32{
33 static TypeId tid = TypeId ("ns3::CcnxInterestSender")
34 .SetParent<Application> ()
35 .AddConstructor<CcnxInterestSender> ()
36 .AddAttribute ("OffTime", "Time interval between packets",
37 TimeValue (Seconds (0.1)),
38 MakeTimeAccessor (&CcnxInterestSender::m_offTime),
39 MakeTimeChecker ())
Ilya Moiseenko946b87b2011-08-23 17:37:54 -070040 .AddAttribute ("Face","Local face to be used",
41 PointerValue (CreateObject<CcnxLocalFace> ()),
42 MakePointerAccessor (&CcnxInterestSender::m_face),
43 MakePointerChecker<CcnxLocalFace> ())
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070044 /*.AddAttribute ("NameComponents","CcnxName of the Interest (use CcnxNameComponents)",
45 CcnxNameComponentsValue(CcnxNameComponents()),
46 MakeCcnxNameComponentsAccessor(&CcnxInterestSender::m_interestName),
47 MakeCcnxNameComponentsChecker())*/
48 .AddAttribute ("InterestName","CcnxName of the Interest (use CcnxNameComponents)",
49 PointerValue (CreateObject<CcnxNameComponents> ()),
Ilya Moiseenkoc706f262011-08-22 19:50:49 -070050 MakePointerAccessor (&CcnxInterestSender::m_interestName),
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070051 MakePointerChecker<CcnxNameComponents> ())
Ilya Moiseenkoc706f262011-08-22 19:50:49 -070052 .AddAttribute ("LifeTime", "LifeTime fo interest packet",
53 TimeValue (Seconds (4.0)),
54 MakeTimeAccessor (&CcnxInterestSender::m_interestLifeTime),
55 MakeTimeChecker ())
56 .AddAttribute ("MinSuffixComponents", "MinSuffixComponents",
57 IntegerValue(-1),
58 MakeIntegerAccessor(&CcnxInterestSender::m_minSuffixComponents),
59 MakeIntegerChecker<int32_t>())
60 .AddAttribute ("MaxSuffixComponents", "MaxSuffixComponents",
61 IntegerValue(-1),
62 MakeIntegerAccessor(&CcnxInterestSender::m_maxSuffixComponents),
63 MakeIntegerChecker<int32_t>())
64 .AddAttribute ("ChildSelector", "ChildSelector",
65 BooleanValue(false),
66 MakeBooleanAccessor(&CcnxInterestSender::m_childSelector),
67 MakeBooleanChecker())
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070068 /*.AddAttribute ("Exclude","only simple name matching is supported (use CcnxNameComponents)",
69 CcnxNameComponentsValue(CcnxNameComponents()),
70 MakeCcnxNameComponentsAccessor(&CcnxInterestSender::m_exclude),
71 MakeCcnxNameComponentsChecker())*/
72 .AddAttribute ("Exclude", "only simple name matching is supported (use CcnxNameComponents)",
73 PointerValue (CreateObject<CcnxNameComponents> ()),
Ilya Moiseenkoc706f262011-08-22 19:50:49 -070074 MakePointerAccessor (&CcnxInterestSender::m_exclude),
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070075 MakePointerChecker<CcnxNameComponents> ())
Ilya Moiseenkoc706f262011-08-22 19:50:49 -070076 .AddAttribute ("Initial Nonce", "If 0 then nonce is not used",
77 UintegerValue(1),
78 MakeUintegerAccessor(&CcnxInterestSender::m_initialNonce),
79 MakeUintegerChecker<uint32_t>())
80 ;
81 /*
82 .AddAttribute ("NoiseModel",
83 "A pointer to the model of the channel ambient noise.",
84 PointerValue (CreateObject<UanNoiseModelDefault> ()),
85 MakePointerAccessor (&UanChannel::m_noise),
86 MakePointerChecker<UanNoiseModel> ())*/
87 return tid;
88}
89
90CcnxInterestSender::CcnxInterestSender ()
91{
92 NS_LOG_FUNCTION_NOARGS ();
93}
94
95CcnxInterestSender::~CcnxInterestSender()
96{
97 NS_LOG_FUNCTION_NOARGS ();
98}
99
100void
101CcnxInterestSender::DoDispose (void)
102{
103 NS_LOG_FUNCTION_NOARGS ();
104
105 Application::DoDispose ();
106}
107
108// Application Methods
109void
110CcnxInterestSender::StartApplication () // Called at time specified by Start
111{
112 NS_LOG_FUNCTION_NOARGS ();
113 ScheduleNextTx();
114}
115
116void
117CcnxInterestSender::StopApplication () // Called at time specified by Stop
118{
119 NS_LOG_FUNCTION_NOARGS ();
120
121 CancelEvents ();
122}
123
124void
125CcnxInterestSender::CancelEvents ()
126{
127 NS_LOG_FUNCTION_NOARGS ();
128
129 Simulator::Cancel (m_sendEvent);
130}
131
132void
133CcnxInterestSender::ScheduleNextTx ()
134{
135 NS_LOG_FUNCTION_NOARGS ();
136
Ilya Moiseenko946b87b2011-08-23 17:37:54 -0700137 Time nextTime = Seconds(m_offTime);
Ilya Moiseenkoc706f262011-08-22 19:50:49 -0700138 m_sendEvent = Simulator::Schedule (nextTime, &CcnxInterestSender::SendPacket, this);
139}
140
141void
142CcnxInterestSender::SendPacket ()
143{
144 NS_LOG_FUNCTION_NOARGS ();
145 NS_LOG_INFO ("Sending Interest at " << Simulator::Now ());
146
147 uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ());
148 CcnxInterestHeader interestHeader;
149 interestHeader.SetNonce(randomNonce);
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700150 //const Ptr<CcnxNameComponents> name = Create<CcnxNameComponents>(m_interestName);
Ilya Moiseenkoc706f262011-08-22 19:50:49 -0700151 interestHeader.SetName(m_interestName);
152 interestHeader.SetInterestLifetime(m_interestLifeTime);
153 interestHeader.SetChildSelector(m_childSelector);
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700154 //const Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents>(m_exclude);
Ilya Moiseenkoc706f262011-08-22 19:50:49 -0700155 interestHeader.SetExclude(m_exclude);
156 interestHeader.SetMaxSuffixComponents(m_maxSuffixComponents);
157 interestHeader.SetMinSuffixComponents(m_minSuffixComponents);
158
159 Ptr<Packet> packet = Create<Packet> ();
160 packet->AddHeader (interestHeader);
161
162 m_face->Send(packet);
163
164 ScheduleNextTx();
165}
166
167
168}