blob: c3ecc59668589638e131f7efef82e96a564bab89 [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> ())
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070044 .AddAttribute ("NameComponents","CcnxName of the Interest (use CcnxNameComponents)",
45 CcnxNameComponentsValue (CcnxNameComponents (/* root */)),
46 MakeCcnxNameComponentsAccessor (&CcnxInterestSender::m_interestName),
47 MakeCcnxNameComponentsChecker ())
Ilya Moiseenkoc706f262011-08-22 19:50:49 -070048 .AddAttribute ("LifeTime", "LifeTime fo interest packet",
49 TimeValue (Seconds (4.0)),
50 MakeTimeAccessor (&CcnxInterestSender::m_interestLifeTime),
51 MakeTimeChecker ())
52 .AddAttribute ("MinSuffixComponents", "MinSuffixComponents",
53 IntegerValue(-1),
54 MakeIntegerAccessor(&CcnxInterestSender::m_minSuffixComponents),
55 MakeIntegerChecker<int32_t>())
56 .AddAttribute ("MaxSuffixComponents", "MaxSuffixComponents",
57 IntegerValue(-1),
58 MakeIntegerAccessor(&CcnxInterestSender::m_maxSuffixComponents),
59 MakeIntegerChecker<int32_t>())
60 .AddAttribute ("ChildSelector", "ChildSelector",
61 BooleanValue(false),
62 MakeBooleanAccessor(&CcnxInterestSender::m_childSelector),
63 MakeBooleanChecker())
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070064 .AddAttribute ("Exclude","only simple name matching is supported (use CcnxNameComponents)",
65 CcnxNameComponentsValue (CcnxNameComponents(/* root */)),
66 MakeCcnxNameComponentsAccessor (&CcnxInterestSender::m_exclude),
67 MakeCcnxNameComponentsChecker ())
Ilya Moiseenkoc706f262011-08-22 19:50:49 -070068 .AddAttribute ("Initial Nonce", "If 0 then nonce is not used",
69 UintegerValue(1),
70 MakeUintegerAccessor(&CcnxInterestSender::m_initialNonce),
71 MakeUintegerChecker<uint32_t>())
72 ;
73 /*
74 .AddAttribute ("NoiseModel",
75 "A pointer to the model of the channel ambient noise.",
76 PointerValue (CreateObject<UanNoiseModelDefault> ()),
77 MakePointerAccessor (&UanChannel::m_noise),
78 MakePointerChecker<UanNoiseModel> ())*/
79 return tid;
80}
81
82CcnxInterestSender::CcnxInterestSender ()
83{
84 NS_LOG_FUNCTION_NOARGS ();
85}
86
87CcnxInterestSender::~CcnxInterestSender()
88{
89 NS_LOG_FUNCTION_NOARGS ();
90}
91
92void
93CcnxInterestSender::DoDispose (void)
94{
95 NS_LOG_FUNCTION_NOARGS ();
96
97 Application::DoDispose ();
98}
99
100// Application Methods
101void
102CcnxInterestSender::StartApplication () // Called at time specified by Start
103{
104 NS_LOG_FUNCTION_NOARGS ();
105 ScheduleNextTx();
106}
107
108void
109CcnxInterestSender::StopApplication () // Called at time specified by Stop
110{
111 NS_LOG_FUNCTION_NOARGS ();
112
113 CancelEvents ();
114}
115
116void
117CcnxInterestSender::CancelEvents ()
118{
119 NS_LOG_FUNCTION_NOARGS ();
120
121 Simulator::Cancel (m_sendEvent);
122}
123
124void
125CcnxInterestSender::ScheduleNextTx ()
126{
127 NS_LOG_FUNCTION_NOARGS ();
128
Ilya Moiseenko946b87b2011-08-23 17:37:54 -0700129 Time nextTime = Seconds(m_offTime);
Ilya Moiseenkoc706f262011-08-22 19:50:49 -0700130 m_sendEvent = Simulator::Schedule (nextTime, &CcnxInterestSender::SendPacket, this);
131}
132
133void
134CcnxInterestSender::SendPacket ()
135{
136 NS_LOG_FUNCTION_NOARGS ();
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700137 // NS_LOG_INFO ("Sending Interest at " << Simulator::Now ());
Ilya Moiseenkoc706f262011-08-22 19:50:49 -0700138
139 uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ());
140 CcnxInterestHeader interestHeader;
141 interestHeader.SetNonce(randomNonce);
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700142 //const Ptr<CcnxNameComponents> name = Create<CcnxNameComponents>(m_interestName);
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700143 interestHeader.SetName(Create<CcnxNameComponents> (m_interestName)); //making a copy of name
Ilya Moiseenkoc706f262011-08-22 19:50:49 -0700144 interestHeader.SetInterestLifetime(m_interestLifeTime);
145 interestHeader.SetChildSelector(m_childSelector);
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700146 //const Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents>(m_exclude);
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700147 interestHeader.SetExclude(Create<CcnxNameComponents> (m_exclude));
Ilya Moiseenkoc706f262011-08-22 19:50:49 -0700148 interestHeader.SetMaxSuffixComponents(m_maxSuffixComponents);
149 interestHeader.SetMinSuffixComponents(m_minSuffixComponents);
150
151 Ptr<Packet> packet = Create<Packet> ();
152 packet->AddHeader (interestHeader);
153
154 m_face->Send(packet);
155
156 ScheduleNextTx();
157}
158
159
160}