A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mesh-information-element-vector-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Pavel Boyko <boyko@iitp.ru>
7 */
8
9#include "ns3/mesh-information-element-vector.h"
10#include "ns3/test.h"
11// All information elements:
12#include "ns3/ie-dot11s-beacon-timing.h"
13#include "ns3/ie-dot11s-configuration.h"
14#include "ns3/ie-dot11s-id.h"
15#include "ns3/ie-dot11s-metric-report.h"
16#include "ns3/ie-dot11s-peer-management.h"
17#include "ns3/ie-dot11s-peering-protocol.h"
18#include "ns3/ie-dot11s-perr.h"
19#include "ns3/ie-dot11s-prep.h"
20#include "ns3/ie-dot11s-preq.h"
21#include "ns3/ie-dot11s-rann.h"
22
23using namespace ns3;
24
25/**
26 * @ingroup mesh
27 * @ingroup tests
28 * @defgroup mesh-test mesh module tests
29 */
30
31/**
32 * @ingroup mesh-test
33 *
34 * @brief Built-in self test for MeshInformationElementVector and all IE
35 */
37{
39 : TestCase("Serialization test for all mesh information elements")
40 {
41 }
42
43 void DoRun() override;
44};
45
46void
48{
50 {
51 // Mesh ID test
53 vector.AddInformationElement(meshId);
54 }
55 {
57 vector.AddInformationElement(config);
58 }
59 {
61 vector.AddInformationElement(report);
62 }
63 {
65 peerMan1->SetPeerOpen(1);
67 peerMan2->SetPeerConfirm(1, 2);
69 peerMan3->SetPeerClose(1, 2, dot11s::REASON11S_MESH_CAPABILITY_POLICY_VIOLATION);
70 vector.AddInformationElement(peerMan1);
71 vector.AddInformationElement(peerMan2);
72 vector.AddInformationElement(peerMan3);
73 }
74 {
76 beaconTiming->AddNeighboursTimingElementUnit(1, Seconds(1), Seconds(4));
77 beaconTiming->AddNeighboursTimingElementUnit(2, Seconds(2), Seconds(3));
78 beaconTiming->AddNeighboursTimingElementUnit(3, Seconds(3), Seconds(2));
79 beaconTiming->AddNeighboursTimingElementUnit(4, Seconds(4), Seconds(1));
80 vector.AddInformationElement(beaconTiming);
81 }
82 {
84 rann->SetFlags(1);
85 rann->SetHopcount(2);
86 rann->SetTTL(4);
87 rann->DecrementTtl();
88 NS_TEST_ASSERT_MSG_EQ(rann->GetTtl(), 3, "SetTtl works");
89 rann->SetOriginatorAddress(Mac48Address("11:22:33:44:55:66"));
90 rann->SetDestSeqNumber(5);
91 rann->SetMetric(6);
92 rann->IncrementMetric(2);
93 NS_TEST_ASSERT_MSG_EQ(rann->GetMetric(), 8, "SetMetric works");
94 vector.AddInformationElement(rann);
95 }
96 {
98 preq->SetHopcount(0);
99 preq->SetTTL(1);
100 preq->SetPreqID(2);
101 preq->SetOriginatorAddress(Mac48Address("11:22:33:44:55:66"));
102 preq->SetOriginatorSeqNumber(3);
103 preq->SetLifetime(4);
104 preq->AddDestinationAddressElement(false, false, Mac48Address("11:11:11:11:11:11"), 5);
105 preq->AddDestinationAddressElement(false, false, Mac48Address("22:22:22:22:22:22"), 6);
106 vector.AddInformationElement(preq);
107 }
108 {
110 prep->SetFlags(12);
111 prep->SetHopcount(11);
112 prep->SetTtl(10);
113 prep->SetDestinationAddress(Mac48Address("11:22:33:44:55:66"));
114 prep->SetDestinationSeqNumber(123);
115 prep->SetLifetime(5000);
116 prep->SetMetric(4321);
117 prep->SetOriginatorAddress(Mac48Address("33:00:22:00:11:00"));
118 prep->SetOriginatorSeqNumber(666);
119 vector.AddInformationElement(prep);
120 }
121 {
124 dest.destination = Mac48Address("11:22:33:44:55:66");
125 dest.seqnum = 1;
126 perr->AddAddressUnit(dest);
127 dest.destination = Mac48Address("10:20:30:40:50:60");
128 dest.seqnum = 2;
129 perr->AddAddressUnit(dest);
130 dest.destination = Mac48Address("01:02:03:04:05:06");
131 dest.seqnum = 3;
132 perr->AddAddressUnit(dest);
133 vector.AddInformationElement(perr);
134 }
135 Ptr<Packet> packet = Create<Packet>();
136 packet->AddHeader(vector);
137 uint32_t size = vector.GetSerializedSize();
138 MeshInformationElementVector resultVector;
139 packet->RemoveHeader(resultVector, size);
141 resultVector,
142 "Roundtrip serialization of all known information elements works");
143}
144
145/**
146 * @ingroup mesh-test
147 *
148 * @brief Mesh Test Suite
149 */
151{
152 public:
154};
155
157 : TestSuite("devices-mesh", Type::UNIT)
158{
159 AddTestCase(new MeshInformationElementVectorBist, TestCase::Duration::QUICK);
160}
161
162static MeshTestSuite g_meshTestSuite; ///< the test suite
an EUI-48 address
bool AddInformationElement(Ptr< WifiInformationElement > element)
add an IE, if maxSize has exceeded, returns false
Smart pointer class similar to boost::intrusive_ptr.
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
static MeshTestSuite g_meshTestSuite
the test suite
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Built-in self test for MeshInformationElementVector and all IE.
void DoRun() override
Implementation to actually run this TestCase.
structure of unreachable destination - address and sequence number
Mac48Address destination
destination address