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
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Tom Henderson <thomas.r.henderson@boeing.com>
7
*/
8
#include <ns3/log.h>
9
#include <ns3/lr-wpan-mac-header.h>
10
#include <ns3/lr-wpan-mac-trailer.h>
11
#include <ns3/mac16-address.h>
12
#include <ns3/mac64-address.h>
13
#include <ns3/packet.h>
14
#include <ns3/test.h>
15
16
#include <vector>
17
18
using namespace
ns3
;
19
using namespace
ns3::lrwpan
;
20
21
NS_LOG_COMPONENT_DEFINE
(
"lr-wpan-packet-test"
);
22
23
/**
24
* @ingroup lr-wpan-test
25
* @ingroup tests
26
*
27
* @brief LrWpan header and trailer Test
28
*/
29
class
LrWpanPacketTestCase
:
public
TestCase
30
{
31
public
:
32
LrWpanPacketTestCase
();
33
~LrWpanPacketTestCase
()
override
;
34
35
private
:
36
void
DoRun
()
override
;
37
};
38
39
LrWpanPacketTestCase::LrWpanPacketTestCase
()
40
:
TestCase
(
"Test the 802.15.4 MAC header and trailer classes"
)
41
{
42
}
43
44
LrWpanPacketTestCase::~LrWpanPacketTestCase
()
45
{
46
}
47
48
void
49
LrWpanPacketTestCase::DoRun
()
50
{
51
LrWpanMacHeader
macHdr(
LrWpanMacHeader::LRWPAN_MAC_BEACON
, 0);
// sequence number set to 0
52
macHdr.
SetSrcAddrMode
(
LrWpanMacHeader::SHORTADDR
);
// short addr
53
macHdr.
SetDstAddrMode
(
LrWpanMacHeader::NOADDR
);
54
macHdr.
SetSecDisable
();
55
macHdr.
SetNoPanIdComp
();
56
// ... other setters
57
58
uint16_t srcPanId = 100;
59
Mac16Address
srcWpanAddr(
"00:11"
);
60
macHdr.
SetSrcAddrFields
(srcPanId, srcWpanAddr);
61
62
LrWpanMacTrailer
macTrailer;
63
64
Ptr<Packet>
p =
Create<Packet>
(20);
// 20 bytes of dummy data
65
NS_TEST_ASSERT_MSG_EQ
(p->GetSize(), 20,
"Packet created with unexpected size"
);
66
p->AddHeader(macHdr);
67
std::cout <<
" <--Mac Header added "
<< std::endl;
68
69
NS_TEST_ASSERT_MSG_EQ
(p->GetSize(), 27,
"Packet wrong size after macHdr addition"
);
70
p->AddTrailer(macTrailer);
71
NS_TEST_ASSERT_MSG_EQ
(p->GetSize(), 29,
"Packet wrong size after macTrailer addition"
);
72
73
// Test serialization and deserialization
74
uint32_t
size = p->GetSerializedSize();
75
std::vector<uint8_t> buffer(size);
76
p->Serialize(buffer.data(), size);
77
Ptr<Packet>
p2 =
Create<Packet>
(buffer.data(), size,
true
);
78
79
p2->Print(std::cout);
80
std::cout <<
" <--Packet P2 "
<< std::endl;
81
82
NS_TEST_ASSERT_MSG_EQ
(p2->GetSize(), 29,
"Packet wrong size after deserialization"
);
83
84
LrWpanMacHeader
receivedMacHdr;
85
p2->RemoveHeader(receivedMacHdr);
86
87
receivedMacHdr.
Print
(std::cout);
88
std::cout <<
" <--P2 Mac Header "
<< std::endl;
89
90
NS_TEST_ASSERT_MSG_EQ
(p2->GetSize(), 22,
"Packet wrong size after removing machdr"
);
91
92
LrWpanMacTrailer
receivedMacTrailer;
93
p2->RemoveTrailer(receivedMacTrailer);
94
NS_TEST_ASSERT_MSG_EQ
(p2->GetSize(),
95
20,
96
"Packet wrong size after removing headers and trailers"
);
97
// Compare macHdr with receivedMacHdr, macTrailer with receivedMacTrailer,...
98
}
99
100
/**
101
* @ingroup lr-wpan-test
102
* @ingroup tests
103
*
104
* @brief LrWpan header and trailer TestSuite
105
*/
106
class
LrWpanPacketTestSuite
:
public
TestSuite
107
{
108
public
:
109
LrWpanPacketTestSuite
();
110
};
111
112
LrWpanPacketTestSuite::LrWpanPacketTestSuite
()
113
:
TestSuite
(
"lr-wpan-packet"
,
Type
::UNIT)
114
{
115
AddTestCase
(
new
LrWpanPacketTestCase
, TestCase::Duration::QUICK);
116
}
117
118
static
LrWpanPacketTestSuite
g_lrWpanPacketTestSuite
;
//!< Static variable for test initialization
LrWpanPacketTestCase
LrWpan header and trailer Test.
Definition
lr-wpan-packet-test.cc:30
LrWpanPacketTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
lr-wpan-packet-test.cc:49
LrWpanPacketTestCase::LrWpanPacketTestCase
LrWpanPacketTestCase()
Definition
lr-wpan-packet-test.cc:39
LrWpanPacketTestCase::~LrWpanPacketTestCase
~LrWpanPacketTestCase() override
Definition
lr-wpan-packet-test.cc:44
LrWpanPacketTestSuite
LrWpan header and trailer TestSuite.
Definition
lr-wpan-packet-test.cc:107
LrWpanPacketTestSuite::LrWpanPacketTestSuite
LrWpanPacketTestSuite()
Definition
lr-wpan-packet-test.cc:112
ns3::Mac16Address
This class can contain 16 bit addresses.
Definition
mac16-address.h:33
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
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::lrwpan::LrWpanMacHeader
Represent the Mac Header with the Frame Control and Sequence Number fields.
Definition
lr-wpan-mac-header.h:43
ns3::lrwpan::LrWpanMacHeader::SetDstAddrMode
void SetDstAddrMode(uint8_t addrMode)
Set the Destination address mode.
Definition
lr-wpan-mac-header.cc:330
ns3::lrwpan::LrWpanMacHeader::SHORTADDR
@ SHORTADDR
Definition
lr-wpan-mac-header.h:64
ns3::lrwpan::LrWpanMacHeader::NOADDR
@ NOADDR
Definition
lr-wpan-mac-header.h:62
ns3::lrwpan::LrWpanMacHeader::Print
void Print(std::ostream &os) const override
Definition
lr-wpan-mac-header.cc:451
ns3::lrwpan::LrWpanMacHeader::LRWPAN_MAC_BEACON
@ LRWPAN_MAC_BEACON
LRWPAN_MAC_BEACON.
Definition
lr-wpan-mac-header.h:50
ns3::lrwpan::LrWpanMacHeader::SetSrcAddrMode
void SetSrcAddrMode(uint8_t addrMode)
Set the Source address mode.
Definition
lr-wpan-mac-header.cc:342
ns3::lrwpan::LrWpanMacHeader::SetSrcAddrFields
void SetSrcAddrFields(uint16_t panId, Mac16Address addr)
Set Source address fields.
Definition
lr-wpan-mac-header.cc:354
ns3::lrwpan::LrWpanMacHeader::SetNoPanIdComp
void SetNoPanIdComp()
Set the Frame Control field "PAN ID Compression" bit to false.
Definition
lr-wpan-mac-header.cc:318
ns3::lrwpan::LrWpanMacHeader::SetSecDisable
void SetSecDisable()
Set the Frame Control field "Security Enabled" bit to false.
Definition
lr-wpan-mac-header.cc:282
ns3::lrwpan::LrWpanMacTrailer
Represent the Mac Trailer with the Frame Check Sequence field.
Definition
lr-wpan-mac-trailer.h:31
uint32_t
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
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_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:134
g_lrWpanPacketTestSuite
static LrWpanPacketTestSuite g_lrWpanPacketTestSuite
Static variable for test initialization.
Definition
lr-wpan-packet-test.cc:118
ns3::lrwpan
Definition
lr-wpan-constants.h:23
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 Dec 10 2024 18:20:42 for ns-3 by
1.11.0