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 ()) |
| 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 | |
| 86 | CcnxInterestSender::CcnxInterestSender () |
| 87 | { |
| 88 | NS_LOG_FUNCTION_NOARGS (); |
| 89 | } |
| 90 | |
| 91 | CcnxInterestSender::~CcnxInterestSender() |
| 92 | { |
| 93 | NS_LOG_FUNCTION_NOARGS (); |
| 94 | } |
| 95 | |
| 96 | void |
| 97 | CcnxInterestSender::DoDispose (void) |
| 98 | { |
| 99 | NS_LOG_FUNCTION_NOARGS (); |
| 100 | |
| 101 | Application::DoDispose (); |
| 102 | } |
| 103 | |
| 104 | // Application Methods |
| 105 | void |
| 106 | CcnxInterestSender::StartApplication () // Called at time specified by Start |
| 107 | { |
| 108 | NS_LOG_FUNCTION_NOARGS (); |
| 109 | ScheduleNextTx(); |
| 110 | } |
| 111 | |
| 112 | void |
| 113 | CcnxInterestSender::StopApplication () // Called at time specified by Stop |
| 114 | { |
| 115 | NS_LOG_FUNCTION_NOARGS (); |
| 116 | |
| 117 | CancelEvents (); |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | CcnxInterestSender::CancelEvents () |
| 122 | { |
| 123 | NS_LOG_FUNCTION_NOARGS (); |
| 124 | |
| 125 | Simulator::Cancel (m_sendEvent); |
| 126 | } |
| 127 | |
| 128 | void |
| 129 | CcnxInterestSender::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 | |
| 137 | void |
| 138 | CcnxInterestSender::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 | } |