A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
backoff.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007, Emmanuelle Laprise
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
7 */
8
9#include "backoff.h"
10
11#include "ns3/log.h"
12
13namespace ns3
14{
15
17
30
32 uint32_t minSlots,
33 uint32_t maxSlots,
34 uint32_t ceiling,
35 uint32_t maxRetries)
36{
37 m_slotTime = slotTime;
38 m_minSlots = minSlots;
39 m_maxSlots = maxSlots;
40 m_ceiling = ceiling;
41 m_maxRetries = maxRetries;
44}
45
46Time
48{
49 uint32_t ceiling;
50
52 {
53 ceiling = m_ceiling;
54 }
55 else
56 {
57 ceiling = m_numBackoffRetries;
58 }
59
60 uint32_t minSlot = m_minSlots;
61 uint32_t maxSlot = (uint32_t)pow(2, ceiling) - 1;
62 if (maxSlot > m_maxSlots)
63 {
64 maxSlot = m_maxSlots;
65 }
66
67 auto backoffSlots = (uint32_t)m_rng->GetValue(minSlot, maxSlot);
68
69 Time backoff = Time(backoffSlots * m_slotTime);
70 return backoff;
71}
72
73void
78
79bool
84
85void
90
91int64_t
93{
94 NS_LOG_FUNCTION(this << stream);
95 m_rng->SetStream(stream);
96 return 1;
97}
98
99} // namespace ns3
void ResetBackoffTime()
Indicates to the backoff object that the last packet was successfully transmitted and that the number...
Definition backoff.cc:74
uint32_t m_maxRetries
Maximum number of transmission retries before the packet is dropped.
Definition backoff.h:50
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition backoff.cc:92
uint32_t m_maxSlots
Maximum number of backoff slots (when multiplied by m_slotTime, determines maximum backoff time)
Definition backoff.h:40
uint32_t m_numBackoffRetries
Number of times that the transmitter has tried to unsuccessfuly transmit the current packet.
Definition backoff.h:110
bool MaxRetriesReached() const
Definition backoff.cc:80
void IncrNumRetries()
Increments the number of retries by 1.
Definition backoff.cc:86
uint32_t m_minSlots
Minimum number of backoff slots (when multiplied by m_slotTime, determines minimum backoff time)
Definition backoff.h:34
Time GetBackoffTime()
Definition backoff.cc:47
Ptr< UniformRandomVariable > m_rng
Random number generator.
Definition backoff.h:115
uint32_t m_ceiling
Caps the exponential function when the number of retries reaches m_ceiling.
Definition backoff.h:45
Time m_slotTime
Length of one slot.
Definition backoff.h:56
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1332
Every class exported by the ns3 library is enclosed in the ns3 namespace.