blob: f7b7ac0e975e731494fd59eb565e58819a8f07ae [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 ())
40 /*.AddAttribute ("NameComponents","CcnxName of the Interest (use Name::Components)",
41 Name::ComponentsValue(Name::Components()),
42 Name::MakeComponentsAccessor(&CcnxInterestSender::m_interestName),
43 Name::MakeComponentsChecker())*/
44 .AddAttribute ("NameComponents","CcnxName of the Interest (use Name::Components)",
45 PointerValue (CreateObject<Name::Components> ()),
46 MakePointerAccessor (&CcnxInterestSender::m_interestName),
47 MakePointerChecker<Name::Components> ())
48 .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())
64 /*.AddAttribute ("Exclude","only simple name matching is supported (use Name::Components)",
65 Name::ComponentsValue(Name::Components()),
66 Name::MakeComponentsAccessor(&CcnxInterestSender::m_exclude),
67 Name::MakeComponentsChecker())*/
68 .AddAttribute ("Exclude", "only simple name matching is supported (use Name::Components)",
69 PointerValue (CreateObject<Name::Components> ()),
70 MakePointerAccessor (&CcnxInterestSender::m_exclude),
71 MakePointerChecker<Name::Components> ())
72 .AddAttribute ("Initial Nonce", "If 0 then nonce is not used",
73 UintegerValue(1),
74 MakeUintegerAccessor(&CcnxInterestSender::m_initialNonce),
75 MakeUintegerChecker<uint32_t>())
76 ;
77 /*
78 .AddAttribute ("NoiseModel",
79 "A pointer to the model of the channel ambient noise.",
80 PointerValue (CreateObject<UanNoiseModelDefault> ()),
81 MakePointerAccessor (&UanChannel::m_noise),
82 MakePointerChecker<UanNoiseModel> ())*/
83 return tid;
84}
85
86CcnxInterestSender::CcnxInterestSender ()
87{
88 NS_LOG_FUNCTION_NOARGS ();
89}
90
91CcnxInterestSender::~CcnxInterestSender()
92{
93 NS_LOG_FUNCTION_NOARGS ();
94}
95
96void
97CcnxInterestSender::DoDispose (void)
98{
99 NS_LOG_FUNCTION_NOARGS ();
100
101 Application::DoDispose ();
102}
103
104// Application Methods
105void
106CcnxInterestSender::StartApplication () // Called at time specified by Start
107{
108 NS_LOG_FUNCTION_NOARGS ();
109 ScheduleNextTx();
110}
111
112void
113CcnxInterestSender::StopApplication () // Called at time specified by Stop
114{
115 NS_LOG_FUNCTION_NOARGS ();
116
117 CancelEvents ();
118}
119
120void
121CcnxInterestSender::CancelEvents ()
122{
123 NS_LOG_FUNCTION_NOARGS ();
124
125 Simulator::Cancel (m_sendEvent);
126}
127
128void
129CcnxInterestSender::ScheduleNextTx ()
130{
131 NS_LOG_FUNCTION_NOARGS ();
132
133 Time nextTime = Seconds(m_offTime); //send now
134 m_sendEvent = Simulator::Schedule (nextTime, &CcnxInterestSender::SendPacket, this);
135}
136
137void
138CcnxInterestSender::SendPacket ()
139{
140 NS_LOG_FUNCTION_NOARGS ();
141 NS_LOG_INFO ("Sending Interest at " << Simulator::Now ());
142
143 uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ());
144 CcnxInterestHeader interestHeader;
145 interestHeader.SetNonce(randomNonce);
146 //const Ptr<Name::Components> name = Create<Name::Components>(m_interestName);
147 interestHeader.SetName(m_interestName);
148 interestHeader.SetInterestLifetime(m_interestLifeTime);
149 interestHeader.SetChildSelector(m_childSelector);
150 //const Ptr<Name::Components> exclude = Create<Name::Components>(m_exclude);
151 interestHeader.SetExclude(m_exclude);
152 interestHeader.SetMaxSuffixComponents(m_maxSuffixComponents);
153 interestHeader.SetMinSuffixComponents(m_minSuffixComponents);
154
155 Ptr<Packet> packet = Create<Packet> ();
156 packet->AddHeader (interestHeader);
157
158 m_face->Send(packet);
159
160 ScheduleNextTx();
161}
162
163
164}