blob: 5a2a759dcd8f44334fccd953c6c5404fe818dfeb [file] [log] [blame]
Alexander Afanasyev029d38d2012-01-09 13:50:50 -08001/* -*- 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 Afanasyev029d38d2012-01-09 13:50:50 -080037NS_LOG_COMPONENT_DEFINE ("CcnxConsumerCbr");
38
39namespace ns3
40{
41
42NS_OBJECT_ENSURE_REGISTERED (CcnxConsumerCbr);
43
44TypeId
45CcnxConsumerCbr::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
60CcnxConsumerCbr::CcnxConsumerCbr ()
61 : m_desiredRate ("100Kbps")
62{
63 NS_LOG_FUNCTION_NOARGS ();
64
65 UpdateMean ();
66}
67
68
69void
70CcnxConsumerCbr::UpdateMean ()
71{
72 double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080073 m_randExp = ExponentialVariable (mean, 100 * mean); // set upper limit to inter-arrival time
Alexander Afanasyev029d38d2012-01-09 13:50:50 -080074}
75
76void
77CcnxConsumerCbr::SetPayloadSize (uint32_t payload)
78{
79 CcnxConsumer::SetPayloadSize (payload);
80 UpdateMean ();
81}
82
83void
84CcnxConsumerCbr::SetDesiredRate (DataRate rate)
85{
86 m_desiredRate = rate;
87 UpdateMean ();
88}
89
90DataRate
91CcnxConsumerCbr::GetDesiredRate () const
92{
93 return m_desiredRate;
94}
95
96
97void
98CcnxConsumerCbr::ScheduleNextPacket ()
99{
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800100 // double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
101
Alexander Afanasyev029d38d2012-01-09 13:50:50 -0800102 if (!m_sendEvent.IsRunning ())
103 m_sendEvent = Simulator::Schedule (
104 Seconds(m_randExp.GetValue ()),
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800105 // Seconds(mean),
Alexander Afanasyev029d38d2012-01-09 13:50:50 -0800106 &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