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 ()) |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 40 | // 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 Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 45 | .AddAttribute ("NameComponents","CcnxName of the Interest (use CcnxNameComponents)", |
| 46 | CcnxNameComponentsValue (CcnxNameComponents (/* root */)), |
| 47 | MakeCcnxNameComponentsAccessor (&CcnxInterestSender::m_interestName), |
| 48 | MakeCcnxNameComponentsChecker ()) |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 49 | .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 Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 65 | .AddAttribute ("Exclude","only simple name matching is supported (use CcnxNameComponents)", |
| 66 | CcnxNameComponentsValue (CcnxNameComponents(/* root */)), |
| 67 | MakeCcnxNameComponentsAccessor (&CcnxInterestSender::m_exclude), |
| 68 | MakeCcnxNameComponentsChecker ()) |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 69 | .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 | |
| 83 | CcnxInterestSender::CcnxInterestSender () |
| 84 | { |
| 85 | NS_LOG_FUNCTION_NOARGS (); |
| 86 | } |
| 87 | |
| 88 | CcnxInterestSender::~CcnxInterestSender() |
| 89 | { |
| 90 | NS_LOG_FUNCTION_NOARGS (); |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | CcnxInterestSender::DoDispose (void) |
| 95 | { |
| 96 | NS_LOG_FUNCTION_NOARGS (); |
| 97 | |
| 98 | Application::DoDispose (); |
| 99 | } |
| 100 | |
| 101 | // Application Methods |
| 102 | void |
| 103 | CcnxInterestSender::StartApplication () // Called at time specified by Start |
| 104 | { |
| 105 | NS_LOG_FUNCTION_NOARGS (); |
| 106 | ScheduleNextTx(); |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | CcnxInterestSender::StopApplication () // Called at time specified by Stop |
| 111 | { |
| 112 | NS_LOG_FUNCTION_NOARGS (); |
| 113 | |
| 114 | CancelEvents (); |
| 115 | } |
| 116 | |
| 117 | void |
| 118 | CcnxInterestSender::CancelEvents () |
| 119 | { |
| 120 | NS_LOG_FUNCTION_NOARGS (); |
| 121 | |
| 122 | Simulator::Cancel (m_sendEvent); |
| 123 | } |
| 124 | |
| 125 | void |
| 126 | CcnxInterestSender::ScheduleNextTx () |
| 127 | { |
| 128 | NS_LOG_FUNCTION_NOARGS (); |
| 129 | |
Ilya Moiseenko | 946b87b | 2011-08-23 17:37:54 -0700 | [diff] [blame] | 130 | Time nextTime = Seconds(m_offTime); |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 131 | m_sendEvent = Simulator::Schedule (nextTime, &CcnxInterestSender::SendPacket, this); |
| 132 | } |
| 133 | |
| 134 | void |
| 135 | CcnxInterestSender::SendPacket () |
| 136 | { |
| 137 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 138 | // NS_LOG_INFO ("Sending Interest at " << Simulator::Now ()); |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 139 | |
| 140 | uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ()); |
| 141 | CcnxInterestHeader interestHeader; |
| 142 | interestHeader.SetNonce(randomNonce); |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 143 | //const Ptr<CcnxNameComponents> name = Create<CcnxNameComponents>(m_interestName); |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 144 | interestHeader.SetName(Create<CcnxNameComponents> (m_interestName)); //making a copy of name |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 145 | interestHeader.SetInterestLifetime(m_interestLifeTime); |
| 146 | interestHeader.SetChildSelector(m_childSelector); |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 147 | //const Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents>(m_exclude); |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 148 | interestHeader.SetExclude(Create<CcnxNameComponents> (m_exclude)); |
Ilya Moiseenko | c706f26 | 2011-08-22 19:50:49 -0700 | [diff] [blame] | 149 | 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 | } |