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
31
NS_LOG_COMPONENT_DEFINE
(
"lr-wpan-packet-test"
);
32
39
class
LrWpanPacketTestCase
:
public
TestCase
40
{
41
public
:
42
LrWpanPacketTestCase
();
43
~LrWpanPacketTestCase
()
override
;
44
45
private
:
46
void
DoRun
()
override
;
47
};
48
49
LrWpanPacketTestCase::LrWpanPacketTestCase
()
50
:
TestCase
(
"Test the 802.15.4 MAC header and trailer classes"
)
51
{
52
}
53
54
LrWpanPacketTestCase::~LrWpanPacketTestCase
()
55
{
56
}
57
58
void
59
LrWpanPacketTestCase::DoRun
()
60
{
61
LrWpanMacHeader
macHdr(
LrWpanMacHeader::LRWPAN_MAC_BEACON
, 0);
// sequence number set to 0
62
macHdr.
SetSrcAddrMode
(
LrWpanMacHeader::SHORTADDR
);
// short addr
63
macHdr.
SetDstAddrMode
(
LrWpanMacHeader::NOADDR
);
64
macHdr.
SetSecDisable
();
65
macHdr.
SetNoPanIdComp
();
66
// ... other setters
67
68
uint16_t srcPanId = 100;
69
Mac16Address
srcWpanAddr(
"00:11"
);
70
macHdr.
SetSrcAddrFields
(srcPanId, srcWpanAddr);
71
72
LrWpanMacTrailer
macTrailer;
73
74
Ptr<Packet>
p = Create<Packet>(20);
// 20 bytes of dummy data
75
NS_TEST_ASSERT_MSG_EQ
(p->GetSize(), 20,
"Packet created with unexpected size"
);
76
p->AddHeader(macHdr);
77
std::cout <<
" <--Mac Header added "
<< std::endl;
78
79
NS_TEST_ASSERT_MSG_EQ
(p->GetSize(), 27,
"Packet wrong size after macHdr addition"
);
80
p->AddTrailer(macTrailer);
81
NS_TEST_ASSERT_MSG_EQ
(p->GetSize(), 29,
"Packet wrong size after macTrailer addition"
);
82
83
// Test serialization and deserialization
84
uint32_t
size = p->GetSerializedSize();
85
std::vector<uint8_t> buffer(size);
86
p->Serialize(buffer.data(), size);
87
Ptr<Packet>
p2 = Create<Packet>(buffer.data(), size,
true
);
88
89
p2->Print(std::cout);
90
std::cout <<
" <--Packet P2 "
<< std::endl;
91
92
NS_TEST_ASSERT_MSG_EQ
(p2->GetSize(), 29,
"Packet wrong size after deserialization"
);
93
94
LrWpanMacHeader
receivedMacHdr;
95
p2->RemoveHeader(receivedMacHdr);
96
97
receivedMacHdr.
Print
(std::cout);
98
std::cout <<
" <--P2 Mac Header "
<< std::endl;
99
100
NS_TEST_ASSERT_MSG_EQ
(p2->GetSize(), 22,
"Packet wrong size after removing machdr"
);
101
102
LrWpanMacTrailer
receivedMacTrailer;
103
p2->RemoveTrailer(receivedMacTrailer);
104
NS_TEST_ASSERT_MSG_EQ
(p2->GetSize(),
105
20,
106
"Packet wrong size after removing headers and trailers"
);
107
// Compare macHdr with receivedMacHdr, macTrailer with receivedMacTrailer,...
108
}
109
116
class
LrWpanPacketTestSuite
:
public
TestSuite
117
{
118
public
:
119
LrWpanPacketTestSuite
();
120
};
121
122
LrWpanPacketTestSuite::LrWpanPacketTestSuite
()
123
:
TestSuite
(
"lr-wpan-packet"
, UNIT)
124
{
125
AddTestCase
(
new
LrWpanPacketTestCase
,
TestCase::QUICK
);
126
}
127
128
static
LrWpanPacketTestSuite
g_lrWpanPacketTestSuite
;
LrWpanPacketTestCase
LrWpan header and trailer Test.
Definition:
lr-wpan-packet-test.cc:40
LrWpanPacketTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
lr-wpan-packet-test.cc:59
LrWpanPacketTestCase::LrWpanPacketTestCase
LrWpanPacketTestCase()
Definition:
lr-wpan-packet-test.cc:49
LrWpanPacketTestCase::~LrWpanPacketTestCase
~LrWpanPacketTestCase() override
Definition:
lr-wpan-packet-test.cc:54
LrWpanPacketTestSuite
LrWpan header and trailer TestSuite.
Definition:
lr-wpan-packet-test.cc:117
LrWpanPacketTestSuite::LrWpanPacketTestSuite
LrWpanPacketTestSuite()
Definition:
lr-wpan-packet-test.cc:122
ns3::LrWpanMacHeader
Represent the Mac Header with the Frame Control and Sequence Number fields.
Definition:
lr-wpan-mac-header.h:52
ns3::LrWpanMacHeader::LRWPAN_MAC_BEACON
@ LRWPAN_MAC_BEACON
LRWPAN_MAC_BEACON.
Definition:
lr-wpan-mac-header.h:59
ns3::LrWpanMacHeader::SetNoPanIdComp
void SetNoPanIdComp()
Set the Frame Control field "PAN ID Compression" bit to false.
Definition:
lr-wpan-mac-header.cc:327
ns3::LrWpanMacHeader::SetSrcAddrMode
void SetSrcAddrMode(uint8_t addrMode)
Set the Source address mode.
Definition:
lr-wpan-mac-header.cc:351
ns3::LrWpanMacHeader::SetSecDisable
void SetSecDisable()
Set the Frame Control field "Security Enabled" bit to false.
Definition:
lr-wpan-mac-header.cc:291
ns3::LrWpanMacHeader::SetSrcAddrFields
void SetSrcAddrFields(uint16_t panId, Mac16Address addr)
Set Source address fields.
Definition:
lr-wpan-mac-header.cc:363
ns3::LrWpanMacHeader::Print
void Print(std::ostream &os) const override
Definition:
lr-wpan-mac-header.cc:459
ns3::LrWpanMacHeader::SetDstAddrMode
void SetDstAddrMode(uint8_t addrMode)
Set the Destination address mode.
Definition:
lr-wpan-mac-header.cc:339
ns3::LrWpanMacHeader::NOADDR
@ NOADDR
Definition:
lr-wpan-mac-header.h:71
ns3::LrWpanMacHeader::SHORTADDR
@ SHORTADDR
Definition:
lr-wpan-mac-header.h:73
ns3::LrWpanMacTrailer
Represent the Mac Trailer with the Frame Check Sequence field.
Definition:
lr-wpan-mac-trailer.h:39
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:78
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::QUICK
@ QUICK
Fast test.
Definition:
test.h:1065
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
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:144
g_lrWpanPacketTestSuite
static LrWpanPacketTestSuite g_lrWpanPacketTestSuite
Static variable for test initialization.
Definition:
lr-wpan-packet-test.cc:128
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 Sun Jul 2 2023 18:21:45 for ns-3 by
1.9.6