A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mesh-information-element-vector-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
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  * Author: Pavel Boyko <boyko@iitp.ru>
19  */
20 
21 #include "ns3/test.h"
22 #include "ns3/mesh-information-element-vector.h"
23 // All information elements:
24 #include "ns3/ie-dot11s-beacon-timing.h"
25 #include "ns3/ie-dot11s-configuration.h"
26 #include "ns3/ie-dot11s-id.h"
27 #include "ns3/ie-dot11s-metric-report.h"
28 #include "ns3/ie-dot11s-peer-management.h"
29 #include "ns3/ie-dot11s-peering-protocol.h"
30 #include "ns3/ie-dot11s-perr.h"
31 #include "ns3/ie-dot11s-prep.h"
32 #include "ns3/ie-dot11s-preq.h"
33 #include "ns3/ie-dot11s-rann.h"
34 
35 namespace ns3 {
36 
37 // Unit tests
38 //-----------------------------------------------------------------------------
41 {
43  TestCase ("Serializarion test for all mesh information elements")
44  {
45  };
46  void DoRun ();
47 };
48 
49 void
51 {
53  {
54  //Mesh ID test
55  Ptr<dot11s::IeMeshId> meshId = Create<dot11s::IeMeshId> ("qwerty");
56  vector.AddInformationElement (meshId);
57  }
58  {
59  Ptr<dot11s::IeConfiguration> config = Create<dot11s::IeConfiguration> ();
60  vector.AddInformationElement (config);
61  }
62  {
63  Ptr<dot11s::IeLinkMetricReport> report = Create<dot11s::IeLinkMetricReport> (123456);
64  vector.AddInformationElement (report);
65  }
66  {
67  Ptr<dot11s::IePeerManagement> peerMan1 = Create<dot11s::IePeerManagement> ();
68  peerMan1->SetPeerOpen (1);
69  Ptr<dot11s::IePeerManagement> peerMan2 = Create<dot11s::IePeerManagement> ();
70  peerMan2->SetPeerConfirm (1, 2);
71  Ptr<dot11s::IePeerManagement> peerMan3 = Create<dot11s::IePeerManagement> ();
72  peerMan3->SetPeerClose (1, 2, dot11s::REASON11S_MESH_CAPABILITY_POLICY_VIOLATION);
73  vector.AddInformationElement (peerMan1);
74  vector.AddInformationElement (peerMan2);
75  vector.AddInformationElement (peerMan3);
76  }
77  {
78  Ptr<dot11s::IeBeaconTiming> beaconTiming = Create<dot11s::IeBeaconTiming> ();
79  beaconTiming->AddNeighboursTimingElementUnit (1, Seconds (1.0), Seconds (4.0));
80  beaconTiming->AddNeighboursTimingElementUnit (2, Seconds (2.0), Seconds (3.0));
81  beaconTiming->AddNeighboursTimingElementUnit (3, Seconds (3.0), Seconds (2.0));
82  beaconTiming->AddNeighboursTimingElementUnit (4, Seconds (4.0), Seconds (1.0));
83  vector.AddInformationElement (beaconTiming);
84  }
85  {
86  Ptr<dot11s::IeRann> rann = Create<dot11s::IeRann> ();
87  rann->SetFlags (1);
88  rann->SetHopcount (2);
89  rann->SetTTL (4);
90  rann->DecrementTtl ();
91  NS_TEST_ASSERT_MSG_EQ (rann->GetTtl (), 3, "SetTtl works");
92  rann->SetOriginatorAddress (Mac48Address ("11:22:33:44:55:66"));
93  rann->SetDestSeqNumber (5);
94  rann->SetMetric (6);
95  rann->IncrementMetric (2);
96  NS_TEST_ASSERT_MSG_EQ (rann->GetMetric (), 8, "SetMetric works");
97  vector.AddInformationElement (rann);
98  }
99  {
100  Ptr<dot11s::IePreq> preq = Create<dot11s::IePreq> ();
101  preq->SetHopcount (0);
102  preq->SetTTL (1);
103  preq->SetPreqID (2);
104  preq->SetOriginatorAddress (Mac48Address ("11:22:33:44:55:66"));
105  preq->SetOriginatorSeqNumber (3);
106  preq->SetLifetime (4);
107  preq->AddDestinationAddressElement (false, false, Mac48Address ("11:11:11:11:11:11"), 5);
108  preq->AddDestinationAddressElement (false, false, Mac48Address ("22:22:22:22:22:22"), 6);
109  vector.AddInformationElement (preq);
110  }
111  {
112  Ptr<dot11s::IePrep> prep = Create<dot11s::IePrep> ();
113  prep->SetFlags (12);
114  prep->SetHopcount (11);
115  prep->SetTtl (10);
116  prep->SetDestinationAddress (Mac48Address ("11:22:33:44:55:66"));
117  prep->SetDestinationSeqNumber (123);
118  prep->SetLifetime (5000);
119  prep->SetMetric (4321);
120  prep->SetOriginatorAddress (Mac48Address ("33:00:22:00:11:00"));
121  prep->SetOriginatorSeqNumber (666);
122  vector.AddInformationElement (prep);
123  }
124  {
125  Ptr<dot11s::IePerr> perr = Create<dot11s::IePerr> ();
127  dest.destination = Mac48Address ("11:22:33:44:55:66");
128  dest.seqnum = 1;
129  perr->AddAddressUnit (dest);
130  dest.destination = Mac48Address ("10:20:30:40:50:60");
131  dest.seqnum = 2;
132  perr->AddAddressUnit (dest);
133  dest.destination = Mac48Address ("01:02:03:04:05:06");
134  dest.seqnum = 3;
135  perr->AddAddressUnit (dest);
136  vector.AddInformationElement (perr);
137  }
138  Ptr<Packet> packet = Create<Packet> ();
139  packet->AddHeader (vector);
140  MeshInformationElementVector resultVector;
141  packet->RemoveHeader (resultVector);
142  NS_TEST_ASSERT_MSG_EQ (vector, resultVector, "Roundtrip serialization of all known information elements works");
143 }
144 
145 class MeshTestSuite : public TestSuite
146 {
147 public:
148  MeshTestSuite ();
149 };
150 
152  : TestSuite ("devices-mesh", UNIT)
153 {
155 }
156 
158 
159 } // namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
A suite of tests to run.
Definition: test.h:1025
structure of unreachable destination - address and sequence number
Definition: hwmp-protocol.h:57
encapsulates test code
Definition: test.h:849
Built-in self test for MeshInformationElementVector and all IE.
bool AddInformationElement(Ptr< WifiInformationElement > element)
add an IE, if maxSize has exceeded, returns false
static MeshTestSuite g_meshTestSuite
an EUI-48 address
Definition: mac48-address.h:41
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:173
Fast test.
Definition: test.h:857
void DoRun()
Implementation to actually run this TestCase.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253
#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:137