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
wimax-fragmentation-test.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009-2010 TELEMATICS LAB - Poliotecnico di Bari
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Giuseppe Piro <g.piro@poliba.it>
7
* <peppe.piro@gmail.com>
8
*/
9
#include "ns3/cid.h"
10
#include "ns3/log.h"
11
#include "ns3/mac-messages.h"
12
#include "ns3/packet.h"
13
#include "ns3/ptr.h"
14
#include "ns3/simulator.h"
15
#include "ns3/test.h"
16
#include "ns3/wimax-connection.h"
17
#include "ns3/wimax-mac-header.h"
18
19
using namespace
ns3
;
20
21
/**
22
* \ingroup wimax-test
23
* \ingroup tests
24
*
25
* \brief Test the wimax packet fragmentation.
26
*/
27
class
Ns3WimaxFragmentationTestCase
:
public
TestCase
28
{
29
public
:
30
Ns3WimaxFragmentationTestCase
();
31
~Ns3WimaxFragmentationTestCase
()
override
;
32
33
private
:
34
void
DoRun
()
override
;
35
};
36
37
Ns3WimaxFragmentationTestCase::Ns3WimaxFragmentationTestCase
()
38
:
TestCase
(
"Test the packet fragmentation and defragmentation."
)
39
{
40
}
41
42
Ns3WimaxFragmentationTestCase::~Ns3WimaxFragmentationTestCase
()
43
{
44
}
45
46
void
47
Ns3WimaxFragmentationTestCase::DoRun
()
48
{
49
GenericMacHeader
gnrcMacHdr;
50
ManagementMessageType
msgType;
51
FragmentationSubheader
fragSubhdr;
52
GenericMacHeader
hdr;
53
54
Cid
cid;
55
auto
connectionTx =
new
WimaxConnection
(cid,
Cid::TRANSPORT
);
56
auto
connectionRx =
new
WimaxConnection
(cid,
Cid::TRANSPORT
);
57
58
// A Packet of 1000 bytes has been created.
59
// It will be fragmentated into 4 fragments and then defragmentated into fullPacket.
60
Ptr<Packet>
packet =
Create<Packet>
(1000);
61
Ptr<Packet>
fragment;
62
Ptr<Packet>
fullPacket =
Create<Packet>
();
63
64
// Enqueued packet
65
hdr.
SetLen
(packet->GetSize() + hdr.
GetSerializedSize
());
66
hdr.
SetCid
(connectionTx->GetCid());
67
MacHeaderType::HeaderType
packetType =
MacHeaderType::HEADER_TYPE_GENERIC
;
68
69
connectionTx->Enqueue(packet, packetType, hdr);
70
71
uint32_t
availableByteForFragment = 280;
72
for
(
int
i = 0; i < 4; i++)
73
{
74
// dequeue a fragment
75
if
(connectionTx->GetQueue()->GetFirstPacketRequiredByte(packetType) >
76
availableByteForFragment)
77
{
78
fragment = connectionTx->Dequeue(packetType, availableByteForFragment);
79
}
80
else
81
{
82
fragment = connectionTx->Dequeue(packetType);
83
}
84
// *** send packet -----> receive packet ----**
85
86
// check if receive packet is a fragment
87
fragment->RemoveHeader(gnrcMacHdr);
88
uint8_t type = gnrcMacHdr.
GetType
();
89
if
(type)
90
{
91
// Check if there is a fragmentation Subheader
92
NS_TEST_EXPECT_MSG_EQ
(((type >> 2) & 1), 1,
"The packet is not a fragment"
);
93
}
94
95
// remove header from the received fragment
96
fragment->RemoveHeader(fragSubhdr);
97
uint32_t
fc = fragSubhdr.
GetFc
();
98
99
NS_TEST_EXPECT_MSG_EQ
((fc == 1 && i != 0),
false
,
"The fragment in not the first one"
);
100
NS_TEST_EXPECT_MSG_EQ
((fc == 2 && i != 3),
false
,
"The fragment in not the latest one"
);
101
NS_TEST_EXPECT_MSG_EQ
(((fc == 3 && i != 1) && (fc == 3 && i != 2)),
102
false
,
103
"The fragment in not the middle one"
);
104
105
if
(fc != 2)
106
{
107
// This is the first or middle fragment.
108
// Take the fragment queue, store the fragment into the queue
109
connectionRx->FragmentEnqueue(fragment);
110
}
111
else
112
{
113
// This is the latest fragment.
114
// Take the fragment queue, defragment a packet and send it to the upper layer
115
connectionRx->FragmentEnqueue(fragment);
116
WimaxConnection::FragmentsQueue
fragmentsQueue = connectionRx->GetFragmentsQueue();
117
118
// DEFRAGMENTATION
119
for
(
auto
iter = fragmentsQueue.begin(); iter != fragmentsQueue.end(); ++iter)
120
{
121
// Create the whole Packet
122
fullPacket->AddAtEnd(*iter);
123
}
124
connectionRx->ClearFragmentsQueue();
125
126
NS_TEST_EXPECT_MSG_EQ
(fullPacket->GetSize(), 1000,
"The defragmentation is incorrect"
);
127
}
128
}
129
delete
connectionTx;
130
delete
connectionRx;
131
Simulator::Destroy
();
132
}
133
134
/**
135
* \ingroup wimax-test
136
* \ingroup tests
137
*
138
* \brief Ns3 Wimax Fragmentation Test Suite
139
*/
140
class
Ns3WimaxFragmentationTestSuite
:
public
TestSuite
141
{
142
public
:
143
Ns3WimaxFragmentationTestSuite
();
144
};
145
146
Ns3WimaxFragmentationTestSuite::Ns3WimaxFragmentationTestSuite
()
147
:
TestSuite
(
"wimax-fragmentation"
,
Type
::UNIT)
148
{
149
AddTestCase
(
new
Ns3WimaxFragmentationTestCase
, TestCase::Duration::QUICK);
150
}
151
152
static
Ns3WimaxFragmentationTestSuite
ns3WimaxFragmentationTestSuite
;
///< the test suite
Ns3WimaxFragmentationTestCase
Test the wimax packet fragmentation.
Definition
wimax-fragmentation-test.cc:28
Ns3WimaxFragmentationTestCase::Ns3WimaxFragmentationTestCase
Ns3WimaxFragmentationTestCase()
Definition
wimax-fragmentation-test.cc:37
Ns3WimaxFragmentationTestCase::~Ns3WimaxFragmentationTestCase
~Ns3WimaxFragmentationTestCase() override
Definition
wimax-fragmentation-test.cc:42
Ns3WimaxFragmentationTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
wimax-fragmentation-test.cc:47
Ns3WimaxFragmentationTestSuite
Ns3 Wimax Fragmentation Test Suite.
Definition
wimax-fragmentation-test.cc:141
Ns3WimaxFragmentationTestSuite::Ns3WimaxFragmentationTestSuite
Ns3WimaxFragmentationTestSuite()
Definition
wimax-fragmentation-test.cc:146
ns3::Cid
Cid class.
Definition
cid.h:26
ns3::Cid::TRANSPORT
@ TRANSPORT
Definition
cid.h:35
ns3::FragmentationSubheader
This class implements the fragmentation sub-header as described by IEEE Standard for Local and metrop...
Definition
wimax-mac-header.h:461
ns3::FragmentationSubheader::GetFc
uint8_t GetFc() const
Get FC field.
Definition
wimax-mac-header.cc:655
ns3::GenericMacHeader
This class implements the Generic mac Header as described by IEEE Standard for Local and metropolitan...
Definition
wimax-mac-header.h:103
ns3::GenericMacHeader::GetType
uint8_t GetType() const
Get type field.
Definition
wimax-mac-header.cc:175
ns3::GenericMacHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
wimax-mac-header.cc:242
ns3::GenericMacHeader::SetLen
void SetLen(uint16_t len)
Set length field.
Definition
wimax-mac-header.cc:145
ns3::GenericMacHeader::SetCid
void SetCid(Cid cid)
Set CID field.
Definition
wimax-mac-header.cc:151
ns3::MacHeaderType::HeaderType
HeaderType
Header type enumeration.
Definition
wimax-mac-header.h:31
ns3::MacHeaderType::HEADER_TYPE_GENERIC
@ HEADER_TYPE_GENERIC
Definition
wimax-mac-header.h:32
ns3::ManagementMessageType
Mac Management messages Section 6.3.2.3 MAC Management messages page 42, Table 14 page 43.
Definition
mac-messages.h:33
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::WimaxConnection
Class to represent WiMAX connections.
Definition
wimax-connection.h:34
ns3::WimaxConnection::FragmentsQueue
std::list< Ptr< const Packet > > FragmentsQueue
Definition of Fragments Queue data type.
Definition
wimax-connection.h:124
uint32_t
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
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:241
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3WimaxFragmentationTestSuite
static Ns3WimaxFragmentationTestSuite ns3WimaxFragmentationTestSuite
the test suite
Definition
wimax-fragmentation-test.cc:152
src
wimax
test
wimax-fragmentation-test.cc
Generated on Fri Nov 8 2024 13:59:09 for ns-3 by
1.11.0