A Discrete-Event Network Simulator
API
backoff.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007, Emmanuelle Laprise
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: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
19  */
20 
21 #include "backoff.h"
22 #include "ns3/log.h"
23 
24 namespace ns3 {
25 
26 NS_LOG_COMPONENT_DEFINE ("Backoff");
27 
29 {
31  m_minSlots = 1;
32  m_maxSlots = 1000;
33  m_ceiling = 10;
34  m_maxRetries = 1000;
36  m_rng = CreateObject<UniformRandomVariable> ();
37 
39 }
40 
41 Backoff::Backoff(Time slotTime, uint32_t minSlots, uint32_t maxSlots, uint32_t ceiling, uint32_t maxRetries)
42 {
43  m_slotTime = slotTime;
44  m_minSlots = minSlots;
45  m_maxSlots = maxSlots;
46  m_ceiling = ceiling;
47  m_maxRetries = maxRetries;
49  m_rng = CreateObject<UniformRandomVariable> ();
50 }
51 
52 Time
54 {
55  uint32_t ceiling;
56 
57  if ((m_ceiling > 0) &&(m_numBackoffRetries > m_ceiling))
58  {
59  ceiling = m_ceiling;
60  }
61  else
62  {
63  ceiling = m_numBackoffRetries;
64  }
65 
66  uint32_t minSlot = m_minSlots;
67  uint32_t maxSlot = (uint32_t)pow (2, ceiling) - 1;
68  if (maxSlot > m_maxSlots)
69  {
70  maxSlot = m_maxSlots;
71  }
72 
73  uint32_t backoffSlots = (uint32_t)m_rng->GetValue (minSlot, maxSlot);
74 
75  Time backoff = Time (backoffSlots * m_slotTime);
76  return backoff;
77 }
78 
79 void
81 {
83 }
84 
85 bool
87 {
89 }
90 
91 void
93 {
95 }
96 
97 int64_t
98 Backoff::AssignStreams (int64_t stream)
99 {
100  NS_LOG_FUNCTION (this << stream);
101  m_rng->SetStream (stream);
102  return 1;
103 }
104 
105 } // namespace ns3
Backoff(void)
Definition: backoff.cc:28
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void ResetBackoffTime(void)
Indicates to the backoff object that the last packet was successfully transmitted and that the number...
Definition: backoff.cc:80
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
uint32_t m_maxSlots
Maximum number of backoff slots (when multiplied by m_slotTime, determines maximum backoff time) ...
Definition: backoff.h:47
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
uint32_t m_maxRetries
Maximum number of transmission retries before the packet is dropped.
Definition: backoff.h:57
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:740
bool MaxRetriesReached(void)
Definition: backoff.cc:86
Ptr< UniformRandomVariable > m_rng
Random number generator.
Definition: backoff.h:118
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: backoff.cc:98
Time GetBackoffTime()
Definition: backoff.cc:53
uint32_t m_minSlots
Minimum number of backoff slots (when multiplied by m_slotTime, determines minimum backoff time) ...
Definition: backoff.h:42
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1030
Time m_slotTime
Length of one slot.
Definition: backoff.h:62
void IncrNumRetries(void)
Increments the number of retries by 1.
Definition: backoff.cc:92
uint32_t m_numBackoffRetries
Number of times that the transmitter has tried to unsuccessfully transmit the current packet...
Definition: backoff.h:113
uint32_t m_ceiling
Caps the exponential function when the number of retries reaches m_ceiling.
Definition: backoff.h:52