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