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 | |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 51 | .AddAttribute ("Frequency", "Frequency of interest packets", |
| 52 | StringValue ("1.0"), |
| 53 | MakeDoubleAccessor (&CcnxConsumerCbr::m_frequency), |
| 54 | MakeDoubleChecker<double> ()) |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 55 | ; |
| 56 | |
| 57 | return tid; |
| 58 | } |
| 59 | |
| 60 | CcnxConsumerCbr::CcnxConsumerCbr () |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 61 | : m_frequency (1.0) |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 62 | { |
| 63 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 66 | void |
| 67 | CcnxConsumerCbr::ScheduleNextPacket () |
| 68 | { |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 69 | // double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate (); |
Alexander Afanasyev | 94cebd0 | 2012-01-16 12:22:34 -0800 | [diff] [blame] | 70 | // std::cout << "next: " << Simulator::Now().ToDouble(Time::S) + mean << "s\n"; |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 71 | |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 72 | if (!m_sendEvent.IsRunning ()) |
| 73 | m_sendEvent = Simulator::Schedule ( |
Alexander Afanasyev | 94cebd0 | 2012-01-16 12:22:34 -0800 | [diff] [blame] | 74 | // Seconds(m_randExp.GetValue ()), |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 75 | Seconds(1.0 / m_frequency), |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 76 | &CcnxConsumer::SendPacket, this); |
| 77 | } |
| 78 | |
| 79 | /////////////////////////////////////////////////// |
| 80 | // Process incoming packets // |
| 81 | /////////////////////////////////////////////////// |
| 82 | |
| 83 | // void |
| 84 | // CcnxConsumer::OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject, |
| 85 | // const Ptr<const Packet> &payload) |
| 86 | // { |
| 87 | // CcnxConsumer::OnContentObject (contentObject, payload); // tracing inside |
| 88 | // } |
| 89 | |
| 90 | // void |
| 91 | // CcnxConsumer::OnNack (const Ptr<const CcnxInterestHeader> &interest) |
| 92 | // { |
| 93 | // CcnxConsumer::OnNack (interest); // tracing inside |
| 94 | // } |
| 95 | |
| 96 | } // namespace ns3 |