Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 23 | NS_LOG_COMPONENT_DEFINE ("CcnxInterestSender"); |
| 24 | |
| 25 | namespace ns3 |
| 26 | { |
| 27 | |
| 28 | NS_OBJECT_ENSURE_REGISTERED (CcnxInterestSender); |
| 29 | |
| 30 | TypeId |
| 31 | CcnxInterestSender::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 Moiseenko | 946b87b | 2011-08-23 17:37:54 -0700 | [diff] [blame] | 40 | .AddAttribute ("Face","Local face to be used", |
| 41 | PointerValue (CreateObject<CcnxLocalFace> ()), |
| 42 | MakePointerAccessor (&CcnxInterestSender::m_face), |
| 43 | MakePointerChecker<CcnxLocalFace> ()) |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 44 | /*.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 Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 50 | MakePointerAccessor (&CcnxInterestSender::m_interestName), |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 51 | MakePointerChecker<CcnxNameComponents> ()) |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 52 | .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 Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 68 | /*.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 Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 74 | MakePointerAccessor (&CcnxInterestSender::m_exclude), |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 75 | MakePointerChecker<CcnxNameComponents> ()) |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 76 | .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 | |
| 90 | CcnxInterestSender::CcnxInterestSender () |
| 91 | { |
| 92 | NS_LOG_FUNCTION_NOARGS (); |
| 93 | } |
| 94 | |
| 95 | CcnxInterestSender::~CcnxInterestSender() |
| 96 | { |
| 97 | NS_LOG_FUNCTION_NOARGS (); |
| 98 | } |
| 99 | |
| 100 | void |
| 101 | CcnxInterestSender::DoDispose (void) |
| 102 | { |
| 103 | NS_LOG_FUNCTION_NOARGS (); |
| 104 | |
| 105 | Application::DoDispose (); |
| 106 | } |
| 107 | |
| 108 | // Application Methods |
| 109 | void |
| 110 | CcnxInterestSender::StartApplication () // Called at time specified by Start |
| 111 | { |
| 112 | NS_LOG_FUNCTION_NOARGS (); |
| 113 | ScheduleNextTx(); |
| 114 | } |
| 115 | |
| 116 | void |
| 117 | CcnxInterestSender::StopApplication () // Called at time specified by Stop |
| 118 | { |
| 119 | NS_LOG_FUNCTION_NOARGS (); |
| 120 | |
| 121 | CancelEvents (); |
| 122 | } |
| 123 | |
| 124 | void |
| 125 | CcnxInterestSender::CancelEvents () |
| 126 | { |
| 127 | NS_LOG_FUNCTION_NOARGS (); |
| 128 | |
| 129 | Simulator::Cancel (m_sendEvent); |
| 130 | } |
| 131 | |
| 132 | void |
| 133 | CcnxInterestSender::ScheduleNextTx () |
| 134 | { |
| 135 | NS_LOG_FUNCTION_NOARGS (); |
| 136 | |
Ilya Moiseenko | 946b87b | 2011-08-23 17:37:54 -0700 | [diff] [blame] | 137 | Time nextTime = Seconds(m_offTime); |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 138 | m_sendEvent = Simulator::Schedule (nextTime, &CcnxInterestSender::SendPacket, this); |
| 139 | } |
| 140 | |
| 141 | void |
| 142 | CcnxInterestSender::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 Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 150 | //const Ptr<CcnxNameComponents> name = Create<CcnxNameComponents>(m_interestName); |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 151 | interestHeader.SetName(m_interestName); |
| 152 | interestHeader.SetInterestLifetime(m_interestLifeTime); |
| 153 | interestHeader.SetChildSelector(m_childSelector); |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 154 | //const Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents>(m_exclude); |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 155 | 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 | } |