blob: a41753f7d0443d93b654b1c8500ecfd61d779c0a [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
37#include <boost/ref.hpp>
38#include <boost/lexical_cast.hpp>
39#include <boost/lambda/lambda.hpp>
40#include <boost/lambda/bind.hpp>
41
42namespace ll = boost::lambda;
43
44NS_LOG_COMPONENT_DEFINE ("CcnxConsumerCbr");
45
46namespace ns3
47{
48
49NS_OBJECT_ENSURE_REGISTERED (CcnxConsumerCbr);
50
51TypeId
52CcnxConsumerCbr::GetTypeId (void)
53{
54 static TypeId tid = TypeId ("ns3::CcnxConsumerCbr")
55 .SetParent<CcnxConsumer> ()
56 .AddConstructor<CcnxConsumerCbr> ()
57
58 .AddAttribute ("MeanRate", "Mean data packet rate (relies on the PayloadSize parameter)",
59 StringValue ("100Kbps"),
60 MakeDataRateAccessor (&CcnxConsumerCbr::GetDesiredRate, &CcnxConsumerCbr::SetDesiredRate),
61 MakeDataRateChecker ())
62 ;
63
64 return tid;
65}
66
67CcnxConsumerCbr::CcnxConsumerCbr ()
68 : m_desiredRate ("100Kbps")
69{
70 NS_LOG_FUNCTION_NOARGS ();
71
72 UpdateMean ();
73}
74
75
76void
77CcnxConsumerCbr::UpdateMean ()
78{
79 double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
80 m_randExp = ExponentialVariable (mean, 10000 * mean); // set upper limit to inter-arrival time
81}
82
83void
84CcnxConsumerCbr::SetPayloadSize (uint32_t payload)
85{
86 CcnxConsumer::SetPayloadSize (payload);
87 UpdateMean ();
88}
89
90void
91CcnxConsumerCbr::SetDesiredRate (DataRate rate)
92{
93 m_desiredRate = rate;
94 UpdateMean ();
95}
96
97DataRate
98CcnxConsumerCbr::GetDesiredRate () const
99{
100 return m_desiredRate;
101}
102
103
104void
105CcnxConsumerCbr::ScheduleNextPacket ()
106{
107 if (!m_sendEvent.IsRunning ())
108 m_sendEvent = Simulator::Schedule (
109 Seconds(m_randExp.GetValue ()),
110 &CcnxConsumer::SendPacket, this);
111}
112
113///////////////////////////////////////////////////
114// Process incoming packets //
115///////////////////////////////////////////////////
116
117// void
118// CcnxConsumer::OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject,
119// const Ptr<const Packet> &payload)
120// {
121// CcnxConsumer::OnContentObject (contentObject, payload); // tracing inside
122// }
123
124// void
125// CcnxConsumer::OnNack (const Ptr<const CcnxInterestHeader> &interest)
126// {
127// CcnxConsumer::OnNack (interest); // tracing inside
128// }
129
130} // namespace ns3