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
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/abort.h"
23
#include "ns3/test.h"
24
#include "ns3/uinteger.h"
25
#include "ns3/inet-socket-address.h"
26
#include "ns3/point-to-point-helper.h"
27
#include "ns3/internet-stack-helper.h"
28
#include "ns3/ipv4-address-helper.h"
29
#include "ns3/ipv4-header.h"
30
#include "ns3/packet-sink-helper.h"
31
#include "ns3/udp-client-server-helper.h"
32
#include "ns3/udp-header.h"
33
#include "ns3/simulator.h"
34
#include "ns3/wimax-helper.h"
35
#include "ns3/mobility-helper.h"
36
#include "ns3/global-route-manager.h"
37
#include "ns3/wimax-tlv.h"
38
#include "ns3/ipcs-classifier-record.h"
39
#include "ns3/service-flow.h"
40
#include "ns3/wimax-connection.h"
41
#include <iostream>
42
43
using namespace
ns3;
44
45
/*
46
* Test the wimax packet fragmentation.
47
*/
48
class
Ns3WimaxFragmentationTestCase
:
public
TestCase
49
{
50
public
:
51
Ns3WimaxFragmentationTestCase
();
52
virtual
~
Ns3WimaxFragmentationTestCase
();
53
54
private
:
55
virtual
void
DoRun (
void
);
56
57
};
58
59
Ns3WimaxFragmentationTestCase::Ns3WimaxFragmentationTestCase
()
60
:
TestCase
(
"Test the packet fragmentation and defragmentation."
)
61
{
62
}
63
64
Ns3WimaxFragmentationTestCase::~Ns3WimaxFragmentationTestCase
()
65
{
66
}
67
68
void
69
Ns3WimaxFragmentationTestCase::DoRun
(
void
)
70
{
71
GenericMacHeader
gnrcMacHdr;
72
ManagementMessageType
msgType;
73
FragmentationSubheader
fragSubhdr;
74
GenericMacHeader
hdr;
75
76
Cid
cid;
77
WimaxConnection
*connectionTx =
new
WimaxConnection
(cid, Cid::TRANSPORT);
78
WimaxConnection
*connectionRx =
new
WimaxConnection
(cid, Cid::TRANSPORT);
79
80
// A Packet of 1000 bytes has been created.
81
// It will be fragmentated into 4 fragments and then defragmentated into fullPacket.
82
Ptr<Packet>
packet = Create<Packet> (1000);
83
Ptr<Packet>
fragment;
84
Ptr<Packet>
fullPacket = Create<Packet> ();
85
86
// Enqueued packet
87
hdr.
SetLen
(packet->
GetSize
() + hdr.
GetSerializedSize
());
88
hdr.
SetCid
(connectionTx->
GetCid
());
89
MacHeaderType::HeaderType
packetType = MacHeaderType::HEADER_TYPE_GENERIC;
90
91
connectionTx->
Enqueue
(packet, packetType, hdr);
92
93
uint32_t availableByteForFragment = 280;
94
for
(
int
i = 0; i < 4; i++)
95
{
96
// dequeue a fragment
97
if
(connectionTx->
GetQueue
()->
GetFirstPacketRequiredByte
(packetType) > availableByteForFragment)
98
{
99
fragment = connectionTx->
Dequeue
(packetType, availableByteForFragment);
100
}
101
else
102
{
103
fragment = connectionTx->
Dequeue
(packetType);
104
}
105
// *** send packet -----> receive packet ----**
106
107
// check if receive packet is a fragment
108
fragment->
RemoveHeader
(gnrcMacHdr);
109
uint8_t type = gnrcMacHdr.
GetType
();
110
if
(type)
111
{
112
// Check if there is a fragmentation Subheader
113
NS_TEST_EXPECT_MSG_EQ
(((type >> 2) & 1), 1,
"The packet is not a fragment"
);
114
}
115
116
// remove header from the received fragment
117
fragment->RemoveHeader (fragSubhdr);
118
uint32_t fc = fragSubhdr.
GetFc
();
119
120
NS_TEST_EXPECT_MSG_EQ
((fc == 1 && i != 0),
false
,
"The fragment in not the first one"
);
121
NS_TEST_EXPECT_MSG_EQ
((fc == 2 && i != 3),
false
,
"The fragment in not the latest one"
);
122
NS_TEST_EXPECT_MSG_EQ
(((fc == 3 && i != 1) && (fc == 3 && i != 2)),
false
,
"The fragment in not the middle one"
);
123
124
if
(fc != 2)
125
{
126
// This is the first or middle fragment.
127
// Take the fragment queue, store the fragment into the queue
128
connectionRx->
FragmentEnqueue
(fragment);
129
}
130
else
131
{
132
// This is the latest fragment.
133
// Take the fragment queue, defragment a packet and send it to the upper layer
134
connectionRx->
FragmentEnqueue
(fragment);
135
WimaxConnection::FragmentsQueue
fragmentsQueue = connectionRx->
GetFragmentsQueue
();
136
137
// DEFRAGMENTATION
138
for
(
std::list
<
Ptr<const Packet>
>::const_iterator iter = fragmentsQueue.begin ();
139
iter != fragmentsQueue.end (); ++iter)
140
{
141
// Create the whole Packet
142
fullPacket->
AddAtEnd
(*iter);
143
}
144
connectionRx->
ClearFragmentsQueue
();
145
146
NS_TEST_EXPECT_MSG_EQ
(fullPacket->
GetSize
(), 1000,
"The defragmentation is incorrect"
);
147
}
148
}
149
delete
connectionTx;
150
delete
connectionRx;
151
Simulator::Destroy ();
152
}
153
// ==============================================================================
154
155
class
Ns3WimaxFragmentationTestSuite
:
public
TestSuite
156
{
157
public
:
158
Ns3WimaxFragmentationTestSuite
();
159
};
160
161
Ns3WimaxFragmentationTestSuite::Ns3WimaxFragmentationTestSuite
()
162
:
TestSuite
(
"wimax-fragmentation"
, UNIT)
163
{
164
AddTestCase
(
new
Ns3WimaxFragmentationTestCase
);
165
}
166
167
static
Ns3WimaxFragmentationTestSuite
ns3WimaxFragmentationTestSuite
;
src
wimax
test
wimax-fragmentation-test.cc
Generated on Tue Oct 9 2012 16:45:50 for ns-3 by
1.8.1.2