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