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
lr-wpan-packet-test.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011 The Boeing Company
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Tom Henderson <thomas.r.henderson@boeing.com>
18
*/
19
#include <ns3/log.h>
20
#include <ns3/lr-wpan-mac-header.h>
21
#include <ns3/lr-wpan-mac-trailer.h>
22
#include <ns3/mac16-address.h>
23
#include <ns3/mac64-address.h>
24
#include <ns3/packet.h>
25
#include <ns3/test.h>
26
27
#include <vector>
28
29
using namespace
ns3
;
30
using namespace
ns3::lrwpan
;
31
32
NS_LOG_COMPONENT_DEFINE
(
"lr-wpan-packet-test"
);
33
34
/**
35
* \ingroup lr-wpan-test
36
* \ingroup tests
37
*
38
* \brief LrWpan header and trailer Test
39
*/
40
class
LrWpanPacketTestCase
:
public
TestCase
41
{
42
public
:
43
LrWpanPacketTestCase
();
44
~LrWpanPacketTestCase
()
override
;
45
46
private
:
47
void
DoRun
()
override
;
48
};
49
50
LrWpanPacketTestCase::LrWpanPacketTestCase
()
51
:
TestCase
(
"Test the 802.15.4 MAC header and trailer classes"
)
52
{
53
}
54
55
LrWpanPacketTestCase::~LrWpanPacketTestCase
()
56
{
57
}
58
59
void
60
LrWpanPacketTestCase::DoRun
()
61
{
62
LrWpanMacHeader
macHdr(
LrWpanMacHeader::LRWPAN_MAC_BEACON
, 0);
// sequence number set to 0
63
macHdr.
SetSrcAddrMode
(
LrWpanMacHeader::SHORTADDR
);
// short addr
64
macHdr.
SetDstAddrMode
(
LrWpanMacHeader::NOADDR
);
65
macHdr.
SetSecDisable
();
66
macHdr.
SetNoPanIdComp
();
67
// ... other setters
68
69
uint16_t srcPanId = 100;
70
Mac16Address
srcWpanAddr(
"00:11"
);
71
macHdr.
SetSrcAddrFields
(srcPanId, srcWpanAddr);
72
73
LrWpanMacTrailer
macTrailer;
74
75
Ptr<Packet>
p = Create<Packet>(20);
// 20 bytes of dummy data
76
NS_TEST_ASSERT_MSG_EQ
(p->GetSize(), 20,
"Packet created with unexpected size"
);
77
p->AddHeader(macHdr);
78
std::cout <<
" <--Mac Header added "
<< std::endl;
79
80
NS_TEST_ASSERT_MSG_EQ
(p->GetSize(), 27,
"Packet wrong size after macHdr addition"
);
81
p->AddTrailer(macTrailer);
82
NS_TEST_ASSERT_MSG_EQ
(p->GetSize(), 29,
"Packet wrong size after macTrailer addition"
);
83
84
// Test serialization and deserialization
85
uint32_t
size = p->GetSerializedSize();
86
std::vector<uint8_t> buffer(size);
87
p->Serialize(buffer.data(), size);
88
Ptr<Packet>
p2 = Create<Packet>(buffer.data(), size,
true
);
89
90
p2->Print(std::cout);
91
std::cout <<
" <--Packet P2 "
<< std::endl;
92
93
NS_TEST_ASSERT_MSG_EQ
(p2->GetSize(), 29,
"Packet wrong size after deserialization"
);
94
95
LrWpanMacHeader
receivedMacHdr;
96
p2->RemoveHeader(receivedMacHdr);
97
98
receivedMacHdr.
Print
(std::cout);
99
std::cout <<
" <--P2 Mac Header "
<< std::endl;
100
101
NS_TEST_ASSERT_MSG_EQ
(p2->GetSize(), 22,
"Packet wrong size after removing machdr"
);
102
103
LrWpanMacTrailer
receivedMacTrailer;
104
p2->RemoveTrailer(receivedMacTrailer);
105
NS_TEST_ASSERT_MSG_EQ
(p2->GetSize(),
106
20,
107
"Packet wrong size after removing headers and trailers"
);
108
// Compare macHdr with receivedMacHdr, macTrailer with receivedMacTrailer,...
109
}
110
111
/**
112
* \ingroup lr-wpan-test
113
* \ingroup tests
114
*
115
* \brief LrWpan header and trailer TestSuite
116
*/
117
class
LrWpanPacketTestSuite
:
public
TestSuite
118
{
119
public
:
120
LrWpanPacketTestSuite
();
121
};
122
123
LrWpanPacketTestSuite::LrWpanPacketTestSuite
()
124
:
TestSuite
(
"lr-wpan-packet"
,
Type
::UNIT)
125
{
126
AddTestCase
(
new
LrWpanPacketTestCase
, TestCase::Duration::QUICK);
127
}
128
129
static
LrWpanPacketTestSuite
g_lrWpanPacketTestSuite
;
//!< Static variable for test initialization
LrWpanPacketTestCase
LrWpan header and trailer Test.
Definition:
lr-wpan-packet-test.cc:41
LrWpanPacketTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
lr-wpan-packet-test.cc:60
LrWpanPacketTestCase::LrWpanPacketTestCase
LrWpanPacketTestCase()
Definition:
lr-wpan-packet-test.cc:50
LrWpanPacketTestCase::~LrWpanPacketTestCase
~LrWpanPacketTestCase() override
Definition:
lr-wpan-packet-test.cc:55
LrWpanPacketTestSuite
LrWpan header and trailer TestSuite.
Definition:
lr-wpan-packet-test.cc:118
LrWpanPacketTestSuite::LrWpanPacketTestSuite
LrWpanPacketTestSuite()
Definition:
lr-wpan-packet-test.cc:123
ns3::Mac16Address
This class can contain 16 bit addresses.
Definition:
mac16-address.h:44
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:77
ns3::TestCase
encapsulates test code
Definition:
test.h:1061
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:302
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1273
ns3::TestSuite::Type
Type
Type of test.
Definition:
test.h:1280
ns3::lrwpan::LrWpanMacHeader
Represent the Mac Header with the Frame Control and Sequence Number fields.
Definition:
lr-wpan-mac-header.h:54
ns3::lrwpan::LrWpanMacHeader::SetDstAddrMode
void SetDstAddrMode(uint8_t addrMode)
Set the Destination address mode.
Definition:
lr-wpan-mac-header.cc:341
ns3::lrwpan::LrWpanMacHeader::SHORTADDR
@ SHORTADDR
Definition:
lr-wpan-mac-header.h:75
ns3::lrwpan::LrWpanMacHeader::NOADDR
@ NOADDR
Definition:
lr-wpan-mac-header.h:73
ns3::lrwpan::LrWpanMacHeader::Print
void Print(std::ostream &os) const override
Definition:
lr-wpan-mac-header.cc:461
ns3::lrwpan::LrWpanMacHeader::LRWPAN_MAC_BEACON
@ LRWPAN_MAC_BEACON
LRWPAN_MAC_BEACON.
Definition:
lr-wpan-mac-header.h:61
ns3::lrwpan::LrWpanMacHeader::SetSrcAddrMode
void SetSrcAddrMode(uint8_t addrMode)
Set the Source address mode.
Definition:
lr-wpan-mac-header.cc:353
ns3::lrwpan::LrWpanMacHeader::SetSrcAddrFields
void SetSrcAddrFields(uint16_t panId, Mac16Address addr)
Set Source address fields.
Definition:
lr-wpan-mac-header.cc:365
ns3::lrwpan::LrWpanMacHeader::SetNoPanIdComp
void SetNoPanIdComp()
Set the Frame Control field "PAN ID Compression" bit to false.
Definition:
lr-wpan-mac-header.cc:329
ns3::lrwpan::LrWpanMacHeader::SetSecDisable
void SetSecDisable()
Set the Frame Control field "Security Enabled" bit to false.
Definition:
lr-wpan-mac-header.cc:293
ns3::lrwpan::LrWpanMacTrailer
Represent the Mac Trailer with the Frame Check Sequence field.
Definition:
lr-wpan-mac-trailer.h:42
uint32_t
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
NS_TEST_ASSERT_MSG_EQ
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition:
test.h:145
g_lrWpanPacketTestSuite
static LrWpanPacketTestSuite g_lrWpanPacketTestSuite
Static variable for test initialization.
Definition:
lr-wpan-packet-test.cc:129
ns3::lrwpan
Definition:
lr-wpan-constants.h:34
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
lr-wpan
test
lr-wpan-packet-test.cc
Generated on Tue May 28 2024 23:36:58 for ns-3 by
1.9.6