A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
wimax-fragmentation-test.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009-2010 TELEMATICS LAB - Poliotecnico di Bari
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
* Giuseppe Piro <g.piro@poliba.it>
19
* <peppe.piro@gmail.com>
20
*/
21
#include "ns3/log.h"
22
#include "ns3/test.h"
23
#include "ns3/ptr.h"
24
#include "ns3/packet.h"
25
#include "ns3/simulator.h"
26
#include "ns3/wimax-mac-header.h"
27
#include "ns3/mac-messages.h"
28
#include "ns3/cid.h"
29
#include "ns3/wimax-connection.h"
30
31
using namespace
ns3
;
32
39
class
Ns3WimaxFragmentationTestCase
:
public
TestCase
40
{
41
public
:
42
Ns3WimaxFragmentationTestCase
();
43
virtual
~
Ns3WimaxFragmentationTestCase
();
44
45
private
:
46
virtual
void
DoRun (
void
);
47
48
};
49
50
Ns3WimaxFragmentationTestCase::Ns3WimaxFragmentationTestCase
()
51
:
TestCase
(
"Test the packet fragmentation and defragmentation."
)
52
{
53
}
54
55
Ns3WimaxFragmentationTestCase::~Ns3WimaxFragmentationTestCase
()
56
{
57
}
58
59
void
60
Ns3WimaxFragmentationTestCase::DoRun
(
void
)
61
{
62
GenericMacHeader
gnrcMacHdr;
63
ManagementMessageType
msgType;
64
FragmentationSubheader
fragSubhdr;
65
GenericMacHeader
hdr;
66
67
Cid
cid;
68
WimaxConnection
*connectionTx =
new
WimaxConnection
(cid, Cid::TRANSPORT);
69
WimaxConnection
*connectionRx =
new
WimaxConnection
(cid, Cid::TRANSPORT);
70
71
// A Packet of 1000 bytes has been created.
72
// It will be fragmentated into 4 fragments and then defragmentated into fullPacket.
73
Ptr<Packet>
packet = Create<Packet> (1000);
74
Ptr<Packet>
fragment;
75
Ptr<Packet>
fullPacket = Create<Packet> ();
76
77
// Enqueued packet
78
hdr.
SetLen
(packet->
GetSize
() + hdr.
GetSerializedSize
());
79
hdr.
SetCid
(connectionTx->
GetCid
());
80
MacHeaderType::HeaderType
packetType = MacHeaderType::HEADER_TYPE_GENERIC;
81
82
connectionTx->
Enqueue
(packet, packetType, hdr);
83
84
uint32_t availableByteForFragment = 280;
85
for
(
int
i = 0; i < 4; i++)
86
{
87
// dequeue a fragment
88
if
(connectionTx->
GetQueue
()->GetFirstPacketRequiredByte (packetType) > availableByteForFragment)
89
{
90
fragment = connectionTx->
Dequeue
(packetType, availableByteForFragment);
91
}
92
else
93
{
94
fragment = connectionTx->
Dequeue
(packetType);
95
}
96
// *** send packet -----> receive packet ----**
97
98
// check if receive packet is a fragment
99
fragment->
RemoveHeader
(gnrcMacHdr);
100
uint8_t type = gnrcMacHdr.
GetType
();
101
if
(type)
102
{
103
// Check if there is a fragmentation Subheader
104
NS_TEST_EXPECT_MSG_EQ
(((type >> 2) & 1), 1,
"The packet is not a fragment"
);
105
}
106
107
// remove header from the received fragment
108
fragment->
RemoveHeader
(fragSubhdr);
109
uint32_t fc = fragSubhdr.
GetFc
();
110
111
NS_TEST_EXPECT_MSG_EQ
((fc == 1 && i != 0),
false
,
"The fragment in not the first one"
);
112
NS_TEST_EXPECT_MSG_EQ
((fc == 2 && i != 3),
false
,
"The fragment in not the latest one"
);
113
NS_TEST_EXPECT_MSG_EQ
(((fc == 3 && i != 1) && (fc == 3 && i != 2)),
false
,
"The fragment in not the middle one"
);
114
115
if
(fc != 2)
116
{
117
// This is the first or middle fragment.
118
// Take the fragment queue, store the fragment into the queue
119
connectionRx->
FragmentEnqueue
(fragment);
120
}
121
else
122
{
123
// This is the latest fragment.
124
// Take the fragment queue, defragment a packet and send it to the upper layer
125
connectionRx->
FragmentEnqueue
(fragment);
126
WimaxConnection::FragmentsQueue
fragmentsQueue = connectionRx->
GetFragmentsQueue
();
127
128
// DEFRAGMENTATION
129
for
(
std::list
<
Ptr<const Packet>
>::const_iterator iter = fragmentsQueue.begin ();
130
iter != fragmentsQueue.end (); ++iter)
131
{
132
// Create the whole Packet
133
fullPacket->
AddAtEnd
(*iter);
134
}
135
connectionRx->
ClearFragmentsQueue
();
136
137
NS_TEST_EXPECT_MSG_EQ
(fullPacket->
GetSize
(), 1000,
"The defragmentation is incorrect"
);
138
}
139
}
140
delete
connectionTx;
141
delete
connectionRx;
142
Simulator::Destroy ();
143
}
144
151
class
Ns3WimaxFragmentationTestSuite
:
public
TestSuite
152
{
153
public
:
154
Ns3WimaxFragmentationTestSuite
();
155
};
156
157
Ns3WimaxFragmentationTestSuite::Ns3WimaxFragmentationTestSuite
()
158
:
TestSuite
(
"wimax-fragmentation"
, UNIT)
159
{
160
AddTestCase
(
new
Ns3WimaxFragmentationTestCase
, TestCase::QUICK);
161
}
162
163
static
Ns3WimaxFragmentationTestSuite
ns3WimaxFragmentationTestSuite
;
ns3WimaxFragmentationTestSuite
static Ns3WimaxFragmentationTestSuite ns3WimaxFragmentationTestSuite
the test suite
Definition:
wimax-fragmentation-test.cc:163
ns3::WimaxConnection::FragmentEnqueue
void FragmentEnqueue(Ptr< const Packet > fragment)
enqueue a received packet (that is a fragment) into the fragments queue
Definition:
wimax-connection.cc:191
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
ns3::Cid
Cid class.
Definition:
cid.h:38
ns3::Packet::GetSize
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition:
packet.h:852
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ManagementMessageType
Mac Management messages Section 6.3.2.3 MAC Management messages page 42, Table 14 page 43.
Definition:
mac-messages.h:44
ns3::FragmentationSubheader::GetFc
uint8_t GetFc(void) const
Get FC field.
Definition:
wimax-mac-header.cc:611
ns3::GenericMacHeader::GetSerializedSize
uint32_t GetSerializedSize(void) const
Definition:
wimax-mac-header.cc:227
Ns3WimaxFragmentationTestCase
Test the wimax packet fragmentation.
Definition:
wimax-fragmentation-test.cc:40
ns3::WimaxConnection
Class to represent WiMAX connections.
Definition:
wimax-connection.h:43
ns3::WimaxConnection::FragmentsQueue
std::list< Ptr< const Packet > > FragmentsQueue
Definition of Fragments Queue data type.
Definition:
wimax-connection.h:132
Ns3WimaxFragmentationTestSuite::Ns3WimaxFragmentationTestSuite
Ns3WimaxFragmentationTestSuite()
Definition:
wimax-fragmentation-test.cc:157
ns3::TestCase
encapsulates test code
Definition:
test.h:1154
ns3::GenericMacHeader::SetLen
void SetLen(uint16_t len)
Set length field.
Definition:
wimax-mac-header.cc:145
ns3::Ptr< Packet >
ns3::WimaxConnection::ClearFragmentsQueue
void ClearFragmentsQueue(void)
delete all enqueued fragments
Definition:
wimax-connection.cc:197
ns3::WimaxConnection::Enqueue
bool Enqueue(Ptr< Packet > packet, const MacHeaderType &hdrType, const GenericMacHeader &hdr)
enqueue a packet in the queue of the connection
Definition:
wimax-connection.cc:123
ns3::WimaxConnection::GetFragmentsQueue
const FragmentsQueue GetFragmentsQueue(void) const
get a queue of received fragments
Definition:
wimax-connection.cc:185
ns3::MacHeaderType::HeaderType
HeaderType
Header type enumeration.
Definition:
wimax-mac-header.h:41
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition:
packet.cc:280
Ns3WimaxFragmentationTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
wimax-fragmentation-test.cc:60
NS_TEST_EXPECT_MSG_EQ
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition:
test.h:283
ns3::GenericMacHeader::GetType
uint8_t GetType(void) const
Get type field.
Definition:
wimax-mac-header.cc:170
ns3::FragmentationSubheader
This class implements the fragmentation sub-header as described by IEEE Standard for Local and metrop...
Definition:
wimax-mac-header.h:458
ns3::WimaxConnection::GetCid
Cid GetCid(void) const
Get CID function.
Definition:
wimax-connection.cc:87
Ns3WimaxFragmentationTestCase::~Ns3WimaxFragmentationTestCase
virtual ~Ns3WimaxFragmentationTestCase()
Definition:
wimax-fragmentation-test.cc:55
list
#define list
Definition:
openflow-interface.h:47
ns3::GenericMacHeader
This class implements the Generic mac Header as described by IEEE Standard for Local and metropolitan...
Definition:
wimax-mac-header.h:109
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1344
ns3::Packet::AddAtEnd
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition:
packet.cc:335
ns3::WimaxConnection::GetQueue
Ptr< WimaxMacQueue > GetQueue(void) const
Definition:
wimax-connection.cc:99
Ns3WimaxFragmentationTestCase::Ns3WimaxFragmentationTestCase
Ns3WimaxFragmentationTestCase()
Definition:
wimax-fragmentation-test.cc:50
ns3::GenericMacHeader::SetCid
void SetCid(Cid cid)
Set CID field.
Definition:
wimax-mac-header.cc:150
Ns3WimaxFragmentationTestSuite
Ns3 Wimax Fragmentation Test Suite.
Definition:
wimax-fragmentation-test.cc:152
ns3::WimaxConnection::Dequeue
Ptr< Packet > Dequeue(MacHeaderType::HeaderType packetType=MacHeaderType::HEADER_TYPE_GENERIC)
dequeue a packet from the queue of the connection
Definition:
wimax-connection.cc:130
src
wimax
test
wimax-fragmentation-test.cc
Generated on Fri Oct 1 2021 17:03:55 for ns-3 by
1.8.20