A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
packet-loss-counter.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 INRIA, UDCAST
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Amine Ismail <amine.ismail@sophia.inria.fr>
7
* <amine.ismail@udcast.com>
8
*/
9
10
#include "
packet-loss-counter.h
"
11
12
#include "ns3/log.h"
13
#include "ns3/simulator.h"
14
#include "ns3/uinteger.h"
15
16
namespace
ns3
17
{
18
19
NS_LOG_COMPONENT_DEFINE
(
"PacketLossCounter"
);
20
21
PacketLossCounter::PacketLossCounter
(uint8_t bitmapSize)
22
: m_lost(0),
23
m_bitMapSize(0),
24
m_lastMaxSeqNum(0),
25
m_receiveBitMap(nullptr)
26
{
27
NS_LOG_FUNCTION
(
this
<< bitmapSize);
28
SetBitMapSize
(bitmapSize);
29
}
30
31
PacketLossCounter::~PacketLossCounter
()
32
{
33
NS_LOG_FUNCTION
(
this
);
34
delete
[]
m_receiveBitMap
;
35
}
36
37
uint16_t
38
PacketLossCounter::GetBitMapSize
()
const
39
{
40
NS_LOG_FUNCTION
(
this
);
41
return
m_bitMapSize
* 8;
42
}
43
44
void
45
PacketLossCounter::SetBitMapSize
(uint16_t winSize)
46
{
47
NS_LOG_FUNCTION
(
this
<< winSize);
48
49
NS_ASSERT_MSG
(winSize % 8 == 0,
"The packet window size should be a multiple of 8"
);
50
m_bitMapSize
= winSize / 8;
51
if
(
m_receiveBitMap
!=
nullptr
)
52
{
53
delete
[]
m_receiveBitMap
;
54
}
55
m_receiveBitMap
=
new
uint8_t[
m_bitMapSize
]();
56
memset(
m_receiveBitMap
, 0xFF,
m_bitMapSize
);
57
}
58
59
uint32_t
60
PacketLossCounter::GetLost
()
const
61
{
62
NS_LOG_FUNCTION
(
this
);
63
return
m_lost
;
64
}
65
66
bool
67
PacketLossCounter::GetBit
(
uint32_t
seqNum)
68
{
69
NS_LOG_FUNCTION
(
this
<< seqNum);
70
return
((
m_receiveBitMap
[(seqNum % (
m_bitMapSize
* 8)) / 8] >> (7 - (seqNum % 8))) & 0x01);
71
}
72
73
void
74
PacketLossCounter::SetBit
(
uint32_t
seqNum,
bool
val)
75
{
76
NS_LOG_FUNCTION
(
this
<< seqNum << val);
77
if
(val)
78
{
79
m_receiveBitMap
[(seqNum % (
m_bitMapSize
* 8)) / 8] |= 0x80 >> (seqNum % 8);
80
}
81
else
82
{
83
m_receiveBitMap
[(seqNum % (
m_bitMapSize
* 8)) / 8] &= ~(0x80 >> (seqNum % 8));
84
}
85
}
86
87
/*
88
* This algo works as follows:
89
* When a packet is received:
90
* 1) From the last received packet to the current one:
91
* 1.1) check the corresponding bit in the bitMAP.
92
* This bit indicates if the packet with (SeqNum-bitMapSizeInBit) is
93
* received (1) or not (0)
94
* 1.2) Mark the packet as lost (0) in the bitMap
95
* 2) Mark the current packet as received (1) in the bitMap
96
* 3) Update the value of the last received packet
97
*/
98
99
void
100
PacketLossCounter::NotifyReceived
(
uint32_t
seqNum)
101
{
102
NS_LOG_FUNCTION
(
this
<< seqNum);
103
for
(
uint32_t
i =
m_lastMaxSeqNum
+ 1; i <= seqNum; i++)
104
{
105
if
(!
GetBit
(i))
106
{
107
NS_LOG_INFO
(
"Packet lost: "
<< i - (
m_bitMapSize
* 8));
108
m_lost
++;
109
}
110
SetBit
(i,
false
);
111
}
112
SetBit
(seqNum,
true
);
113
if
(seqNum >
m_lastMaxSeqNum
)
114
{
115
m_lastMaxSeqNum
= seqNum;
116
}
117
}
118
119
}
// namespace ns3
ns3::PacketLossCounter::SetBit
void SetBit(uint32_t seqNum, bool val)
Set a sequence number to a given state.
Definition
packet-loss-counter.cc:74
ns3::PacketLossCounter::NotifyReceived
void NotifyReceived(uint32_t seq)
Record a successfully received packet.
Definition
packet-loss-counter.cc:100
ns3::PacketLossCounter::m_lastMaxSeqNum
uint32_t m_lastMaxSeqNum
Last sequence number seen.
Definition
packet-loss-counter.h:81
ns3::PacketLossCounter::GetBit
bool GetBit(uint32_t seqNum)
Check if a sequence number in the window has been received.
Definition
packet-loss-counter.cc:67
ns3::PacketLossCounter::PacketLossCounter
PacketLossCounter(uint8_t bitmapSize)
Constructor.
Definition
packet-loss-counter.cc:21
ns3::PacketLossCounter::m_lost
uint32_t m_lost
Lost packets counter.
Definition
packet-loss-counter.h:79
ns3::PacketLossCounter::SetBitMapSize
void SetBitMapSize(uint16_t size)
Set the size of the window used to compute the packet loss.
Definition
packet-loss-counter.cc:45
ns3::PacketLossCounter::m_receiveBitMap
uint8_t * m_receiveBitMap
Received packets in the window size.
Definition
packet-loss-counter.h:82
ns3::PacketLossCounter::GetBitMapSize
uint16_t GetBitMapSize() const
Return the size of the window used to compute the packet loss.
Definition
packet-loss-counter.cc:38
ns3::PacketLossCounter::GetLost
uint32_t GetLost() const
Get the number of lost packets.
Definition
packet-loss-counter.cc:60
ns3::PacketLossCounter::~PacketLossCounter
~PacketLossCounter()
Definition
packet-loss-counter.cc:31
ns3::PacketLossCounter::m_bitMapSize
uint16_t m_bitMapSize
Window size.
Definition
packet-loss-counter.h:80
uint32_t
NS_ASSERT_MSG
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition
assert.h:75
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition
log.h:264
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
packet-loss-counter.h
src
applications
model
packet-loss-counter.cc
Generated on Fri Nov 8 2024 13:58:59 for ns-3 by
1.11.0