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
{
23
NS_LOG_FUNCTION
(
this
<< bitmapSize);
24
SetBitMapSize
(bitmapSize);
25
}
26
27
PacketLossCounter::~PacketLossCounter
()
28
{
29
NS_LOG_FUNCTION
(
this
);
30
delete
[]
m_receiveBitMap
;
31
}
32
33
uint16_t
34
PacketLossCounter::GetBitMapSize
()
const
35
{
36
NS_LOG_FUNCTION
(
this
);
37
return
m_bitMapSize
* 8;
38
}
39
40
void
41
PacketLossCounter::SetBitMapSize
(uint16_t winSize)
42
{
43
NS_LOG_FUNCTION
(
this
<< winSize);
44
45
NS_ASSERT_MSG
(winSize % 8 == 0,
"The packet window size should be a multiple of 8"
);
46
m_bitMapSize
= winSize / 8;
47
if
(
m_receiveBitMap
!=
nullptr
)
48
{
49
delete
[]
m_receiveBitMap
;
50
}
51
m_receiveBitMap
=
new
uint8_t[
m_bitMapSize
]();
52
memset(
m_receiveBitMap
, 0xFF,
m_bitMapSize
);
53
}
54
55
uint32_t
56
PacketLossCounter::GetLost
()
const
57
{
58
NS_LOG_FUNCTION
(
this
);
59
return
m_lost
;
60
}
61
62
bool
63
PacketLossCounter::GetBit
(
uint32_t
seqNum)
64
{
65
NS_LOG_FUNCTION
(
this
<< seqNum);
66
return
((
m_receiveBitMap
[(seqNum % (
m_bitMapSize
* 8)) / 8] >> (7 - (seqNum % 8))) & 0x01);
67
}
68
69
void
70
PacketLossCounter::SetBit
(
uint32_t
seqNum,
bool
val)
71
{
72
NS_LOG_FUNCTION
(
this
<< seqNum << val);
73
if
(val)
74
{
75
m_receiveBitMap
[(seqNum % (
m_bitMapSize
* 8)) / 8] |= 0x80 >> (seqNum % 8);
76
}
77
else
78
{
79
m_receiveBitMap
[(seqNum % (
m_bitMapSize
* 8)) / 8] &= ~(0x80 >> (seqNum % 8));
80
}
81
}
82
83
/*
84
* This algo works as follows:
85
* When a packet is received:
86
* 1) From the last received packet to the current one:
87
* 1.1) check the corresponding bit in the bitMAP.
88
* This bit indicates if the packet with (SeqNum-bitMapSizeInBit) is
89
* received (1) or not (0)
90
* 1.2) Mark the packet as lost (0) in the bitMap
91
* 2) Mark the current packet as received (1) in the bitMap
92
* 3) Update the value of the last received packet
93
*/
94
95
void
96
PacketLossCounter::NotifyReceived
(
uint32_t
seqNum)
97
{
98
NS_LOG_FUNCTION
(
this
<< seqNum);
99
for
(
uint32_t
i =
m_lastMaxSeqNum
+ 1; i <= seqNum; i++)
100
{
101
if
(!
GetBit
(i))
102
{
103
NS_LOG_INFO
(
"Packet lost: "
<< i - (
m_bitMapSize
* 8));
104
m_lost
++;
105
}
106
SetBit
(i,
false
);
107
}
108
SetBit
(seqNum,
true
);
109
if
(seqNum >
m_lastMaxSeqNum
)
110
{
111
m_lastMaxSeqNum
= seqNum;
112
}
113
}
114
115
}
// 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:70
ns3::PacketLossCounter::NotifyReceived
void NotifyReceived(uint32_t seq)
Record a successfully received packet.
Definition
packet-loss-counter.cc:96
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:63
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:41
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:34
ns3::PacketLossCounter::GetLost
uint32_t GetLost() const
Get the number of lost packets.
Definition
packet-loss-counter.cc:56
ns3::PacketLossCounter::~PacketLossCounter
~PacketLossCounter()
Definition
packet-loss-counter.cc:27
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:231
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
for ns-3 by
1.15.0