A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
buildings-helper-test.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011, 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 
22 
23 #include "ns3/log.h"
24 #include "ns3/test.h"
25 #include <ns3/mobility-building-info.h>
26 #include <ns3/constant-position-mobility-model.h>
27 #include <ns3/building.h>
28 #include <ns3/buildings-helper.h>
29 #include <ns3/mobility-helper.h>
30 #include <ns3/simulator.h>
31 
32 NS_LOG_COMPONENT_DEFINE ("BuildingsHelperTest");
33 
34 namespace ns3 {
35 
36 
38 {
40  Vector pos; // coordinates of the mobility model instance
41  bool indoor; // true if indoor, false otherwise
42  uint32_t bid; // building id
43  uint16_t rx; // room x
44  uint16_t ry; // room y
45  uint16_t fn; // floor number
46 };
47 
49  : pos (0,0,0),
50  indoor (false),
51  bid (0xffffffff),
52  rx (0),
53  ry (0),
54  fn (0)
55 {
56 }
57 
66 {
67  BuildingData ();
68  double xmin;
69  double xmax;
70  double ymin;
71  double ymax;
72  double zmin;
73  double zmax;
74  uint16_t nrx;
75  uint16_t nry;
76  uint16_t nf;
77 };
78 
80  : xmin (0),
81  xmax (0),
82  ymin (0),
83  ymax (0),
84  zmin (0),
85  zmax (0),
86  nrx (0),
87  nry (0),
88  nf (0)
89 {
90 }
91 
93 {
94 public:
95  static std::string BuildNameString (PositionInBuilding pib, BuildingData bd);
97 
98 private:
99  virtual void DoRun (void);
100 
103 
104 };
105 
107 {
108  std::ostringstream oss;
109  oss << "pos=" << pib.pos;
110  if (pib.indoor)
111  {
112  oss << ", bid=" << pib.bid
113  << ", rx=" << pib.rx
114  << ", ry=" << pib.ry
115  << ", fn=" << pib.fn;
116  }
117  else
118  {
119  oss << ", outdoor";
120  }
121  return oss.str ();
122 }
123 
124 
126  : TestCase (BuildNameString (pib, bd)),
127  m_pib (pib),
128  m_bd (bd)
129 {
130 }
131 
132 void
134 {
136  MobilityHelper mobility;
137  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
138 
140  nodes.Create (1);
141  mobility.Install (nodes);
142 
144  bmm->SetPosition (m_pib.pos);
145 
146  NS_LOG_LOGIC ("create building");
147  Ptr<Building> b = CreateObject<Building> ();
148  b->SetBoundaries (Box (m_bd.xmin, m_bd.xmax, m_bd.ymin, m_bd.ymax, m_bd.zmin, m_bd.zmax));
149  b->SetNFloors (m_bd.nf);
150  b->SetNRoomsX (m_bd.nrx);
151  b->SetNRoomsY (m_bd.nry);
152  Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo> (b);
153  bmm->AggregateObject (buildingInfo); // operation usually done by BuildingsHelper::Install
155 
156 
157  NS_TEST_ASSERT_MSG_EQ (buildingInfo->IsIndoor (), m_pib.indoor, "indoor/outdoor mismatch");
158  if (m_pib.indoor)
159  {
160  NS_LOG_LOGIC (" got bid=" << buildingInfo->GetBuilding ()->GetId () << ", f=" << (uint32_t) buildingInfo->GetFloorNumber () << ", rx=" << (uint32_t) buildingInfo->GetRoomNumberX () << ", roomY=" << (uint32_t) buildingInfo->GetRoomNumberY ());
161  // only one building in this test, so Id will be 0
162  NS_TEST_ASSERT_MSG_EQ (buildingInfo->GetBuilding ()->GetId (), 0, "Building ID mismatch");
163  NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetFloorNumber (), m_pib.fn, "floor number mismatch");
164  NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetRoomNumberX (), m_pib.rx, "x room number mismatch");
165  NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetRoomNumberY (), m_pib.ry, "y room number mismatch");
166  }
167 
168  Simulator::Destroy ();
169 }
170 
171 
172 
173 
174 
175 
176 
178 {
179 public:
181 };
182 
183 
185  : TestSuite ("buildings-helper", UNIT)
186 {
187  NS_LOG_FUNCTION (this);
188 
189  BuildingData b1;
190  b1.xmin = 1;
191  b1.xmax = 3;
192  b1.ymin = 1;
193  b1.ymax = 2;
194  b1.zmin = 0;
195  b1.zmax = 4;
196  b1.nrx = 1;
197  b1.nry = 1;
198  b1.nf = 1;
199 
200  Vector vp1 (1.5, 1.5, 0.5);
202  p1.pos = vp1;
203  p1.indoor = true;
204  p1.bid = 0;
205  p1.rx = 1;
206  p1.ry = 1;
207  p1.fn = 1;
209 
210  Vector vp2 (1.5, 0.5, 0.5);
212  p2.pos = vp2;
213  p2.indoor = false;
215 
216  Vector vp3 (1.5, 2.5, 0.5);
218  p3.pos = vp3;
219  p3.indoor = false;
221 
222  Vector vp4 (1.5, 1.5, 5);
224  p4.pos = vp4;
225  p4.indoor = false;
227 
228  Vector vp5 (2.5, 1.6, 3.5);
230  p5.pos = vp5;
231  p5.indoor = true;
232  p5.bid = 0;
233  p5.rx = 1;
234  p5.ry = 1;
235  p5.fn = 1;
237 
238  Vector vp6 (0.9999, 1.5, 1.5);
240  p6.pos = vp6;
241  p6.indoor = false;
243 
244  Vector vp7 (3.0001, 1.5, 2.5);
246  p7.pos = vp7;
247  p7.indoor = false;
249 
250  Vector vp8 (1.001, 1.001, -0.01);
252  p8.pos = vp8;
253  p8.indoor = false;
255 
256  Vector vp9 (1.5, 1.5, 4.001);
258  p9.pos = vp9;
259  p9.indoor = false;
261 
262 
263 
264 
265  BuildingData b2;
266  b2.xmin = -1;
267  b2.xmax = 0.5;
268  b2.ymin = -2;
269  b2.ymax = 0.5;
270  b2.zmin = 0;
271  b2.zmax = 2;
272  b2.nrx = 3;
273  b2.nry = 5;
274  b2.nf = 4;
275 
276  Vector vq1 (-0.7, -1.1, 1.2);
278  q1.pos = vq1;
279  q1.indoor = true;
280  q1.bid = 1;
281  q1.rx = 1;
282  q1.ry = 2;
283  q1.fn = 3;
285 
286  Vector vq2 (0.2, 0.3, 0.2);
288  q2.pos = vq2;
289  q2.indoor = true;
290  q2.bid = 1;
291  q2.rx = 3;
292  q2.ry = 5;
293  q2.fn = 1;
295 
296  Vector vq3 (0.6, -1.75, 1.5);
298  q3.pos = vq3;
299  q3.indoor = false;
301 
302  Vector vq4 (-1.01, 0.3, 1.99);
304  q4.pos = vq4;
305  q4.indoor = false;
307 
308  Vector vq5 (-0.8, 0.7, 0.01);
310  q5.pos = vq5;
311  q5.indoor = false;
313 
314  Vector vq6 (0.2, 0.3, -0.2);
316  q6.pos = vq6;
317  q6.indoor = false;
319 
320  Vector vq7 (0.2, 0.3, 2.001);
322  q7.pos = vq7;
323  q7.indoor = false;
325 }
326 
328 
329 } // namespace ns3
330 
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
BuildingsHelperOneTestCase(PositionInBuilding pib, BuildingData bd)
A suite of tests to run.
Definition: test.h:1025
Mobility model for which the current position does not change once it has been set and until it is se...
virtual void DoRun(void)
Implementation to actually run this TestCase.
encapsulates test code
Definition: test.h:849
a 3d vector
Definition: vector.h:31
a 3d box
Definition: box.h:33
tuple nodes
Definition: first.py:25
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
static void MakeMobilityModelConsistent()
This method goes through the whole NodeList and, for each node in the list, calls BuildingsHelper::Ma...
static std::string BuildNameString(PositionInBuilding pib, BuildingData bd)
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
data to construct a Building object.
keep track of a set of node pointers.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
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
Helper class used to assign positions and mobility models to nodes.
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
static BuildingsHelperTestSuite buildingsHelperAntennaTestSuiteInstance
NS_LOG_COMPONENT_DEFINE("BuildingsHelperTest")
Ptr< T > GetObject(void) const
Definition: object.h:361
#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