A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
32
33
PacketLossCounter::PacketLossCounter
(uint8_t bitmapSize)
34
: m_lost (0),
35
m_bitMapSize (0),
36
m_lastMaxSeqNum (0),
37
m_receiveBitMap (0)
38
{
39
NS_LOG_FUNCTION
(
this
<< bitmapSize);
40
SetBitMapSize
(bitmapSize);
41
}
42
43
PacketLossCounter::~PacketLossCounter
()
44
{
45
NS_LOG_FUNCTION
(
this
);
46
delete
[]
m_receiveBitMap
;
47
}
48
49
uint16_t
50
PacketLossCounter::GetBitMapSize
()
const
51
{
52
NS_LOG_FUNCTION
(
this
);
53
return
m_bitMapSize
* 8;
54
}
55
56
void
57
PacketLossCounter::SetBitMapSize
(uint16_t winSize)
58
{
59
NS_LOG_FUNCTION
(
this
<< winSize);
60
61
NS_ASSERT_MSG
(winSize%8==0,
"The packet window size should be a multiple of 8"
);
62
m_bitMapSize
= winSize/8;
63
if
(
m_receiveBitMap
!=0)
64
{
65
delete
[]
m_receiveBitMap
;
66
}
67
m_receiveBitMap
=
new
uint8_t [
m_bitMapSize
] ();
68
memset (
m_receiveBitMap
,0xFF,
m_bitMapSize
);
69
}
70
71
uint32_t
72
PacketLossCounter::GetLost
()
const
73
{
74
NS_LOG_FUNCTION
(
this
);
75
return
m_lost
;
76
}
77
78
bool
79
PacketLossCounter::GetBit
(uint32_t seqNum)
80
{
81
NS_LOG_FUNCTION
(
this
<< seqNum);
82
return
((
m_receiveBitMap
[(seqNum%(
m_bitMapSize
*8))/8] >> (7-(seqNum%8)))&0x01);
83
}
84
85
void
86
PacketLossCounter::SetBit
(uint32_t seqNum,
bool
val)
87
{
88
NS_LOG_FUNCTION
(
this
<< seqNum << val);
89
if
(val)
90
{
91
m_receiveBitMap
[(seqNum%(
m_bitMapSize
*8))/8] |= 0x80 >> (seqNum%8);
92
}
93
else
94
{
95
m_receiveBitMap
[(seqNum%(
m_bitMapSize
*8))/8] &= ~(0x80 >> (seqNum%8));
96
}
97
}
98
99
/*
100
* This algo works as follows:
101
* When a packet is received:
102
* 1) From the last received packet to the current one:
103
* 1.1) check the corresponding bit in the bitMAP.
104
* This bit indicates if the packet with (SeqNum-bitMapSizeInBit) is
105
* received (1) or not (0)
106
* 1.2) Mark the packet as lost (0) in the bitMap
107
* 2) Mark the current packet as received (1) in the bitMap
108
* 3) Update the value of the last received packet
109
*/
110
111
void
112
PacketLossCounter::NotifyReceived
(uint32_t seqNum)
113
{
114
NS_LOG_FUNCTION
(
this
<< seqNum);
115
for
(uint32_t i=
m_lastMaxSeqNum
+1; i<=seqNum; i++)
116
{
117
if
(
GetBit
(i)!=1)
118
{
119
NS_LOG_INFO
(
"Packet lost: "
<< i-(
m_bitMapSize
*8));
120
m_lost
++;
121
}
122
SetBit
(i, 0);
123
}
124
SetBit
(seqNum, 1);
125
if
(seqNum>
m_lastMaxSeqNum
)
126
{
127
m_lastMaxSeqNum
= seqNum;
128
}
129
}
130
131
}
// namespace ns3
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
ns3::NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
ns3::PacketLossCounter::NotifyReceived
void NotifyReceived(uint32_t seq)
Record a successfully received packet.
Definition:
packet-loss-counter.cc:112
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)
Definition:
log.h:298
ns3::PacketLossCounter::GetBit
bool GetBit(uint32_t seqNum)
Check if a sequence number in the window has been received.
Definition:
packet-loss-counter.cc:79
ns3::PacketLossCounter::GetLost
uint32_t GetLost(void) const
Get the number of lost packets.
Definition:
packet-loss-counter.cc:72
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:57
ns3::PacketLossCounter::m_lost
uint32_t m_lost
Lost packets counter.
Definition:
packet-loss-counter.h:89
ns3::PacketLossCounter::SetBit
void SetBit(uint32_t seqNum, bool val)
Set a sequence number to a given state.
Definition:
packet-loss-counter.cc:86
packet-loss-counter.h
NS_ASSERT_MSG
#define NS_ASSERT_MSG(condition, message)
Definition:
assert.h:86
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:33
ns3::PacketLossCounter::~PacketLossCounter
~PacketLossCounter()
Definition:
packet-loss-counter.cc:43
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:50
src
applications
model
packet-loss-counter.cc
Generated on Sat Apr 19 2014 14:06:50 for ns-3 by
1.8.6