Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [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-consumer-cbr.h" |
| 22 | #include "ns3/ptr.h" |
| 23 | #include "ns3/log.h" |
| 24 | #include "ns3/simulator.h" |
| 25 | #include "ns3/packet.h" |
| 26 | #include "ns3/callback.h" |
| 27 | #include "ns3/string.h" |
| 28 | #include "ns3/boolean.h" |
| 29 | #include "ns3/uinteger.h" |
| 30 | #include "ns3/double.h" |
| 31 | |
| 32 | #include "ns3/ccnx.h" |
| 33 | #include "../model/ccnx-local-face.h" |
| 34 | #include "ns3/ccnx-interest-header.h" |
| 35 | #include "ns3/ccnx-content-object-header.h" |
| 36 | |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 37 | NS_LOG_COMPONENT_DEFINE ("CcnxConsumerCbr"); |
| 38 | |
| 39 | namespace ns3 |
| 40 | { |
| 41 | |
| 42 | NS_OBJECT_ENSURE_REGISTERED (CcnxConsumerCbr); |
| 43 | |
| 44 | TypeId |
| 45 | CcnxConsumerCbr::GetTypeId (void) |
| 46 | { |
| 47 | static TypeId tid = TypeId ("ns3::CcnxConsumerCbr") |
| 48 | .SetParent<CcnxConsumer> () |
| 49 | .AddConstructor<CcnxConsumerCbr> () |
| 50 | |
| 51 | .AddAttribute ("MeanRate", "Mean data packet rate (relies on the PayloadSize parameter)", |
| 52 | StringValue ("100Kbps"), |
| 53 | MakeDataRateAccessor (&CcnxConsumerCbr::GetDesiredRate, &CcnxConsumerCbr::SetDesiredRate), |
| 54 | MakeDataRateChecker ()) |
| 55 | ; |
| 56 | |
| 57 | return tid; |
| 58 | } |
| 59 | |
| 60 | CcnxConsumerCbr::CcnxConsumerCbr () |
| 61 | : m_desiredRate ("100Kbps") |
| 62 | { |
| 63 | NS_LOG_FUNCTION_NOARGS (); |
| 64 | |
| 65 | UpdateMean (); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | void |
| 70 | CcnxConsumerCbr::UpdateMean () |
| 71 | { |
| 72 | double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate (); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame^] | 73 | m_randExp = ExponentialVariable (mean, 100 * mean); // set upper limit to inter-arrival time |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void |
| 77 | CcnxConsumerCbr::SetPayloadSize (uint32_t payload) |
| 78 | { |
| 79 | CcnxConsumer::SetPayloadSize (payload); |
| 80 | UpdateMean (); |
| 81 | } |
| 82 | |
| 83 | void |
| 84 | CcnxConsumerCbr::SetDesiredRate (DataRate rate) |
| 85 | { |
| 86 | m_desiredRate = rate; |
| 87 | UpdateMean (); |
| 88 | } |
| 89 | |
| 90 | DataRate |
| 91 | CcnxConsumerCbr::GetDesiredRate () const |
| 92 | { |
| 93 | return m_desiredRate; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | void |
| 98 | CcnxConsumerCbr::ScheduleNextPacket () |
| 99 | { |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame^] | 100 | // double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate (); |
| 101 | |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 102 | if (!m_sendEvent.IsRunning ()) |
| 103 | m_sendEvent = Simulator::Schedule ( |
| 104 | Seconds(m_randExp.GetValue ()), |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame^] | 105 | // Seconds(mean), |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 106 | &CcnxConsumer::SendPacket, this); |
| 107 | } |
| 108 | |
| 109 | /////////////////////////////////////////////////// |
| 110 | // Process incoming packets // |
| 111 | /////////////////////////////////////////////////// |
| 112 | |
| 113 | // void |
| 114 | // CcnxConsumer::OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject, |
| 115 | // const Ptr<const Packet> &payload) |
| 116 | // { |
| 117 | // CcnxConsumer::OnContentObject (contentObject, payload); // tracing inside |
| 118 | // } |
| 119 | |
| 120 | // void |
| 121 | // CcnxConsumer::OnNack (const Ptr<const CcnxInterestHeader> &interest) |
| 122 | // { |
| 123 | // CcnxConsumer::OnNack (interest); // tracing inside |
| 124 | // } |
| 125 | |
| 126 | } // namespace ns3 |