A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
applications
model
packet-loss-counter.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 INRIA, UDCAST
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: Amine Ismail <amine.ismail@sophia.inria.fr>
19
* <amine.ismail@udcast.com>
20
*/
21
22
#include "ns3/log.h"
23
#include "ns3/simulator.h"
24
#include "ns3/uinteger.h"
25
#include "
packet-loss-counter.h
"
26
27
namespace
ns3
{
28
29
NS_LOG_COMPONENT_DEFINE
(
"PacketLossCounter"
);
30
31
PacketLossCounter::PacketLossCounter
(uint8_t bitmapSize)
32
: m_lost (0),
33
m_bitMapSize (0),
34
m_lastMaxSeqNum (0),
35
m_receiveBitMap (0)
36
{
37
NS_LOG_FUNCTION
(
this
<< bitmapSize);
38
SetBitMapSize
(bitmapSize);
39
}
40
41
PacketLossCounter::~PacketLossCounter
()
42
{
43
NS_LOG_FUNCTION
(
this
);
44
delete
[]
m_receiveBitMap
;
45
}
46
47
uint16_t
48
PacketLossCounter::GetBitMapSize
()
const
49
{
50
NS_LOG_FUNCTION
(
this
);
51
return
m_bitMapSize
* 8;
52
}
53
54
void
55
PacketLossCounter::SetBitMapSize
(uint16_t winSize)
56
{
57
NS_LOG_FUNCTION
(
this
<< winSize);
58
59
NS_ASSERT_MSG
(winSize%8==0,
"The packet window size should be a multiple of 8"
);
60
m_bitMapSize
= winSize/8;
61
if
(
m_receiveBitMap
!=0)
62
{
63
delete
[]
m_receiveBitMap
;
64
}
65
m_receiveBitMap
=
new
uint8_t [
m_bitMapSize
] ();
66
memset (
m_receiveBitMap
,0xFF,
m_bitMapSize
);
67
}
68
69
uint32_t
70
PacketLossCounter::GetLost
()
const
71
{
72
NS_LOG_FUNCTION
(
this
);
73
return
m_lost
;
74
}
75
76
bool
77
PacketLossCounter::GetBit
(uint32_t seqNum)
78
{
79
NS_LOG_FUNCTION
(
this
<< seqNum);
80
return
((
m_receiveBitMap
[(seqNum%(
m_bitMapSize
*8))/8] >> (7-(seqNum%8)))&0x01);
81
}
82
83
void
84
PacketLossCounter::SetBit
(uint32_t seqNum,
bool
val)
85
{
86
NS_LOG_FUNCTION
(
this
<< seqNum << val);
87
if
(val)
88
{
89
m_receiveBitMap
[(seqNum%(
m_bitMapSize
*8))/8] |= 0x80 >> (seqNum%8);
90
}
91
else
92
{
93
m_receiveBitMap
[(seqNum%(
m_bitMapSize
*8))/8] &= ~(0x80 >> (seqNum%8));
94
}
95
}
96
97
/*
98
* This algo works as follows:
99
* When a packet is received:
100
* 1) From the last received packet to the current one:
101
* 1.1) check the corresponding bit in the bitMAP.
102
* This bit indicates if the packet with (SeqNum-bitMapSizeInBit) is
103
* received (1) or not (0)
104
* 1.2) Mark the packet as lost (0) in the bitMap
105
* 2) Mark the current packet as received (1) in the bitMap
106
* 3) Update the value of the last received packet
107
*/
108
109
void
110
PacketLossCounter::NotifyReceived
(uint32_t seqNum)
111
{
112
NS_LOG_FUNCTION
(
this
<< seqNum);
113
for
(uint32_t i=
m_lastMaxSeqNum
+1; i<=seqNum; i++)
114
{
115
if
(
GetBit
(i)!=1)
116
{
117
NS_LOG_INFO
(
"Packet lost: "
<< i-(
m_bitMapSize
*8));
118
m_lost
++;
119
}
120
SetBit
(i, 0);
121
}
122
SetBit
(seqNum, 1);
123
if
(seqNum>
m_lastMaxSeqNum
)
124
{
125
m_lastMaxSeqNum
= seqNum;
126
}
127
}
128
129
}
// namespace ns3
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:213
ns3::PacketLossCounter::NotifyReceived
void NotifyReceived(uint32_t seq)
Record a successfully received packet.
Definition:
packet-loss-counter.cc:110
NS_ASSERT_MSG
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
ns3::PacketLossCounter::m_lastMaxSeqNum
uint32_t m_lastMaxSeqNum
Last sequence number seen.
Definition:
packet-loss-counter.h:91
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition:
log.h:278
ns3::PacketLossCounter::GetBit
bool GetBit(uint32_t seqNum)
Check if a sequence number in the window has been received.
Definition:
packet-loss-counter.cc:77
ns3::PacketLossCounter::GetBitMapSize
uint16_t GetBitMapSize(void) const
Return the size of the window used to compute the packet loss.
Definition:
packet-loss-counter.cc:48
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:55
ns3::PacketLossCounter::m_lost
uint32_t m_lost
Lost packets counter.
Definition:
packet-loss-counter.h:89
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::PacketLossCounter::SetBit
void SetBit(uint32_t seqNum, bool val)
Set a sequence number to a given state.
Definition:
packet-loss-counter.cc:84
ns3::PacketLossCounter::GetLost
uint32_t GetLost(void) const
Get the number of lost packets.
Definition:
packet-loss-counter.cc:70
packet-loss-counter.h
ns3::PacketLossCounter::m_receiveBitMap
uint8_t * m_receiveBitMap
Received packets in the window size.
Definition:
packet-loss-counter.h:92
ns3::PacketLossCounter::m_bitMapSize
uint16_t m_bitMapSize
Window size.
Definition:
packet-loss-counter.h:90
ns3::PacketLossCounter::PacketLossCounter
PacketLossCounter(uint8_t bitmapSize)
Constructor.
Definition:
packet-loss-counter.cc:31
ns3::PacketLossCounter::~PacketLossCounter
~PacketLossCounter()
Definition:
packet-loss-counter.cc:41
Generated on Wed Nov 7 2018 10:01:47 for ns-3 by
1.8.14