Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -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-producer.h" |
| 22 | |
| 23 | |
| 24 | NS_LOG_COMPONENT_DEFINE ("CcnxProducer"); |
| 25 | |
| 26 | namespace ns3 |
| 27 | { |
| 28 | |
| 29 | NS_OBJECT_ENSURE_REGISTERED (CcnxProducer); |
| 30 | |
| 31 | TypeId |
| 32 | CcnxProducer::GetTypeId (void) |
| 33 | { |
| 34 | static TypeId tid = TypeId ("ns3::CcnxProducer") |
| 35 | .SetParent<Application> () |
| 36 | .AddConstructor<CcnxProducer> () |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 37 | // Alex: this is incorrect. SetNode call is not called if face is created using this accessor |
| 38 | // .AddAttribute ("Face","Local face to be used", |
| 39 | // PointerValue (CreateObject<CcnxLocalFace> ()), |
| 40 | // MakePointerAccessor (&CcnxProducer::m_face), |
| 41 | // MakePointerChecker<CcnxLocalFace> ()) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 42 | .AddAttribute ("Ccnx","Ccnx is needed to access ContentStore", |
| 43 | PointerValue (NULL), |
| 44 | MakePointerAccessor (&CcnxProducer::m_ccnx), |
| 45 | MakePointerChecker<Ccnx> ()) |
| 46 | |
| 47 | /*.AddAttribute ("InterestName","CcnxName of the Interest (use CcnxNameComponents)", |
| 48 | PointerValue (CreateObject<CcnxNameComponents> ()), |
| 49 | MakePointerAccessor (&CcnxConsumer::m_interestName), |
| 50 | MakePointerChecker<CcnxNameComponents> ()) |
| 51 | .AddAttribute ("LifeTime", "LifeTime fo interest packet", |
| 52 | TimeValue (Seconds (4.0)), |
| 53 | MakeTimeAccessor (&CcnxConsumer::m_interestLifeTime), |
| 54 | MakeTimeChecker ()) |
| 55 | .AddAttribute ("MinSuffixComponents", "MinSuffixComponents", |
| 56 | IntegerValue(-1), |
| 57 | MakeIntegerAccessor(&CcnxConsumer::m_minSuffixComponents), |
| 58 | MakeIntegerChecker<int32_t>()) |
| 59 | .AddAttribute ("MaxSuffixComponents", "MaxSuffixComponents", |
| 60 | IntegerValue(-1), |
| 61 | MakeIntegerAccessor(&CcnxConsumer::m_maxSuffixComponents), |
| 62 | MakeIntegerChecker<int32_t>()) |
| 63 | .AddAttribute ("ChildSelector", "ChildSelector", |
| 64 | BooleanValue(false), |
| 65 | MakeBooleanAccessor(&CcnxConsumer::m_childSelector), |
| 66 | MakeBooleanChecker()) |
| 67 | .AddAttribute ("Exclude", "only simple name matching is supported (use CcnxNameComponents)", |
| 68 | PointerValue (CreateObject<CcnxNameComponents> ()), |
| 69 | MakePointerAccessor (&CcnxConsumer::m_exclude), |
| 70 | MakePointerChecker<CcnxNameComponents> ())*/ |
| 71 | .AddAttribute ("Capacity", "Capacity of the ContentStore", |
| 72 | UintegerValue(100), |
| 73 | MakeUintegerAccessor(&CcnxProducer::m_storeCapacity), |
| 74 | MakeUintegerChecker<uint32_t>()) |
| 75 | .AddTraceSource ("InterestTrace", "Interests that were received", |
| 76 | MakeTraceSourceAccessor (&CcnxProducer::m_interestsTrace)) |
| 77 | .AddTraceSource ("ContentObjectTrace", "ContentObjects that were sent", |
| 78 | MakeTraceSourceAccessor (&CcnxProducer::m_contentObjectsTrace)) |
| 79 | ; |
| 80 | |
| 81 | return tid; |
| 82 | } |
| 83 | |
| 84 | CcnxProducer::CcnxProducer () |
| 85 | { |
| 86 | NS_LOG_FUNCTION_NOARGS (); |
| 87 | } |
| 88 | |
| 89 | CcnxProducer::~CcnxProducer() |
| 90 | { |
| 91 | NS_LOG_FUNCTION_NOARGS (); |
| 92 | } |
| 93 | |
| 94 | void |
| 95 | CcnxProducer::DoDispose (void) |
| 96 | { |
| 97 | NS_LOG_FUNCTION_NOARGS (); |
| 98 | |
| 99 | Application::DoDispose (); |
| 100 | } |
| 101 | |
| 102 | // Application Methods |
| 103 | void |
| 104 | CcnxProducer::StartApplication () // Called at time specified by Start |
| 105 | { |
| 106 | NS_LOG_FUNCTION_NOARGS (); |
| 107 | // ScheduleNextTx(); |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | CcnxProducer::StopApplication () // Called at time specified by Stop |
| 112 | { |
| 113 | NS_LOG_FUNCTION_NOARGS (); |
| 114 | |
| 115 | CancelEvents (); |
| 116 | } |
| 117 | |
| 118 | void |
| 119 | CcnxProducer::CancelEvents () |
| 120 | { |
| 121 | NS_LOG_FUNCTION_NOARGS (); |
| 122 | |
Alexander Afanasyev | 152cf11 | 2011-08-29 17:58:32 -0700 | [diff] [blame] | 123 | // Simulator::Cancel (m_sendEvent); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /*void |
| 127 | CcnxProducer::ScheduleNextTx () |
| 128 | { |
| 129 | NS_LOG_FUNCTION_NOARGS (); |
| 130 | |
| 131 | Time nextTime = Seconds(m_offTime); |
| 132 | m_sendEvent = Simulator::Schedule (nextTime, &CcnxConsumer::SendPacket, this); |
| 133 | } |
| 134 | */ |
| 135 | |
| 136 | /*void |
| 137 | CcnxConsumer::SendPacket () |
| 138 | { |
| 139 | NS_LOG_FUNCTION_NOARGS (); |
| 140 | NS_LOG_INFO ("Sending Interest at " << Simulator::Now ()); |
| 141 | |
| 142 | uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ()); |
| 143 | CcnxInterestHeader interestHeader; |
| 144 | interestHeader.SetNonce(randomNonce); |
| 145 | interestHeader.SetName(m_interestName); |
| 146 | interestHeader.SetInterestLifetime(m_interestLifeTime); |
| 147 | interestHeader.SetChildSelector(m_childSelector); |
| 148 | interestHeader.SetExclude(m_exclude); |
| 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->Receive(packet); |
| 156 | |
| 157 | ScheduleNextTx(); |
| 158 | }*/ |
| 159 | |
| 160 | uint32_t |
| 161 | CcnxProducer::GetStoreCapacity() |
| 162 | { |
| 163 | return m_storeCapacity; |
| 164 | } |
| 165 | |
| 166 | void |
| 167 | CcnxProducer::HandlePacket(const Ptr<CcnxFace> &face, const Ptr<const Packet> &packet) |
| 168 | { |
| 169 | uint8_t type[2]; |
| 170 | uint32_t read = packet->CopyData (type,2); |
| 171 | if (read!=2) |
| 172 | { |
| 173 | NS_LOG_INFO ("Unknown CcnxPacket"); |
| 174 | return; |
| 175 | } |
| 176 | |
| 177 | if (type[0] == INTEREST_BYTE0 && type[1] == INTEREST_BYTE1) |
| 178 | { |
| 179 | m_interestsTrace(face,packet); |
| 180 | } |
| 181 | else if (type[0] == CONTENT_OBJECT_BYTE0 && type[1] == CONTENT_OBJECT_BYTE1) |
| 182 | { |
| 183 | m_contentObjectsTrace(face,packet); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | void |
| 188 | CcnxProducer::AddContentStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet) |
| 189 | { |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 190 | // m_ccnx->m_contentStore->Add (header, packet); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 191 | } |
| 192 | } |