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