A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
packet-loss-counter.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 INRIA, UDCAST
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Amine Ismail <amine.ismail@sophia.inria.fr>
18
* <amine.ismail@udcast.com>
19
*/
20
21
#include "
packet-loss-counter.h
"
22
23
#include "ns3/log.h"
24
#include "ns3/simulator.h"
25
#include "ns3/uinteger.h"
26
27
namespace
ns3
28
{
29
30
NS_LOG_COMPONENT_DEFINE
(
"PacketLossCounter"
);
31
32
PacketLossCounter::PacketLossCounter
(uint8_t bitmapSize)
33
: m_lost(0),
34
m_bitMapSize(0),
35
m_lastMaxSeqNum(0),
36
m_receiveBitMap(nullptr)
37
{
38
NS_LOG_FUNCTION
(
this
<< bitmapSize);
39
SetBitMapSize
(bitmapSize);
40
}
41
42
PacketLossCounter::~PacketLossCounter
()
43
{
44
NS_LOG_FUNCTION
(
this
);
45
delete
[]
m_receiveBitMap
;
46
}
47
48
uint16_t
49
PacketLossCounter::GetBitMapSize
()
const
50
{
51
NS_LOG_FUNCTION
(
this
);
52
return
m_bitMapSize
* 8;
53
}
54
55
void
56
PacketLossCounter::SetBitMapSize
(uint16_t winSize)
57
{
58
NS_LOG_FUNCTION
(
this
<< winSize);
59
60
NS_ASSERT_MSG
(winSize % 8 == 0,
"The packet window size should be a multiple of 8"
);
61
m_bitMapSize
= winSize / 8;
62
if
(
m_receiveBitMap
!=
nullptr
)
63
{
64
delete
[]
m_receiveBitMap
;
65
}
66
m_receiveBitMap
=
new
uint8_t[
m_bitMapSize
]();
67
memset(
m_receiveBitMap
, 0xFF,
m_bitMapSize
);
68
}
69
70
uint32_t
71
PacketLossCounter::GetLost
()
const
72
{
73
NS_LOG_FUNCTION
(
this
);
74
return
m_lost
;
75
}
76
77
bool
78
PacketLossCounter::GetBit
(uint32_t seqNum)
79
{
80
NS_LOG_FUNCTION
(
this
<< seqNum);
81
return
((
m_receiveBitMap
[(seqNum % (
m_bitMapSize
* 8)) / 8] >> (7 - (seqNum % 8))) & 0x01);
82
}
83
84
void
85
PacketLossCounter::SetBit
(uint32_t seqNum,
bool
val)
86
{
87
NS_LOG_FUNCTION
(
this
<< seqNum << val);
88
if
(val)
89
{
90
m_receiveBitMap
[(seqNum % (
m_bitMapSize
* 8)) / 8] |= 0x80 >> (seqNum % 8);
91
}
92
else
93
{
94
m_receiveBitMap
[(seqNum % (
m_bitMapSize
* 8)) / 8] &= ~(0x80 >> (seqNum % 8));
95
}
96
}
97
98
/*
99
* This algo works as follows:
100
* When a packet is received:
101
* 1) From the last received packet to the current one:
102
* 1.1) check the corresponding bit in the bitMAP.
103
* This bit indicates if the packet with (SeqNum-bitMapSizeInBit) is
104
* received (1) or not (0)
105
* 1.2) Mark the packet as lost (0) in the bitMap
106
* 2) Mark the current packet as received (1) in the bitMap
107
* 3) Update the value of the last received packet
108
*/
109
110
void
111
PacketLossCounter::NotifyReceived
(uint32_t seqNum)
112
{
113
NS_LOG_FUNCTION
(
this
<< seqNum);
114
for
(uint32_t i =
m_lastMaxSeqNum
+ 1; i <= seqNum; i++)
115
{
116
if
(!
GetBit
(i))
117
{
118
NS_LOG_INFO
(
"Packet lost: "
<< i - (
m_bitMapSize
* 8));
119
m_lost
++;
120
}
121
SetBit
(i,
false
);
122
}
123
SetBit
(seqNum,
true
);
124
if
(seqNum >
m_lastMaxSeqNum
)
125
{
126
m_lastMaxSeqNum
= seqNum;
127
}
128
}
129
130
}
// 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:85
ns3::PacketLossCounter::NotifyReceived
void NotifyReceived(uint32_t seq)
Record a successfully received packet.
Definition:
packet-loss-counter.cc:111
ns3::PacketLossCounter::m_lastMaxSeqNum
uint32_t m_lastMaxSeqNum
Last sequence number seen.
Definition:
packet-loss-counter.h:92
ns3::PacketLossCounter::GetBit
bool GetBit(uint32_t seqNum)
Check if a sequence number in the window has been received.
Definition:
packet-loss-counter.cc:78
ns3::PacketLossCounter::PacketLossCounter
PacketLossCounter(uint8_t bitmapSize)
Constructor.
Definition:
packet-loss-counter.cc:32
ns3::PacketLossCounter::m_lost
uint32_t m_lost
Lost packets counter.
Definition:
packet-loss-counter.h:90
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:56
ns3::PacketLossCounter::m_receiveBitMap
uint8_t * m_receiveBitMap
Received packets in the window size.
Definition:
packet-loss-counter.h:93
ns3::PacketLossCounter::GetBitMapSize
uint16_t GetBitMapSize() const
Return the size of the window used to compute the packet loss.
Definition:
packet-loss-counter.cc:49
ns3::PacketLossCounter::GetLost
uint32_t GetLost() const
Get the number of lost packets.
Definition:
packet-loss-counter.cc:71
ns3::PacketLossCounter::~PacketLossCounter
~PacketLossCounter()
Definition:
packet-loss-counter.cc:42
ns3::PacketLossCounter::m_bitMapSize
uint16_t m_bitMapSize
Window size.
Definition:
packet-loss-counter.h:91
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:86
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
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:240
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition:
log.h:275
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 Sun Mar 3 2024 17:10:54 for ns-3 by
1.9.1