A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lte-hex-grid-enb-topology-helper.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright 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 #include "lte-hex-grid-enb-topology-helper.h"
23 #include <ns3/double.h>
24 #include <ns3/log.h>
25 #include <ns3/abort.h>
26 #include <ns3/pointer.h>
27 #include <ns3/epc-helper.h>
28 #include <iostream>
29 
30 
31 NS_LOG_COMPONENT_DEFINE ("LteHexGridEnbTopologyHelper");
32 
33 namespace ns3 {
34 
35 NS_OBJECT_ENSURE_REGISTERED (LteHexGridEnbTopologyHelper);
36 
37 LteHexGridEnbTopologyHelper::LteHexGridEnbTopologyHelper ()
38 {
39  NS_LOG_FUNCTION (this);
40 }
41 
42 LteHexGridEnbTopologyHelper::~LteHexGridEnbTopologyHelper (void)
43 {
44  NS_LOG_FUNCTION (this);
45 }
46 
47 TypeId LteHexGridEnbTopologyHelper::GetTypeId (void)
48 {
49  static TypeId
50  tid =
51  TypeId ("ns3::LteHexGridEnbTopologyHelper")
52  .SetParent<Object> ()
53  .AddConstructor<LteHexGridEnbTopologyHelper> ()
54  .AddAttribute ("InterSiteDistance",
55  "The distance [m] between nearby sites",
56  DoubleValue (500),
57  MakeDoubleAccessor (&LteHexGridEnbTopologyHelper::m_d),
58  MakeDoubleChecker<double> ())
59  .AddAttribute ("SectorOffset",
60  "The offset [m] in the position for the node of each sector with respect "
61  "to the center of the three-sector site",
62  DoubleValue (0.5),
63  MakeDoubleAccessor (&LteHexGridEnbTopologyHelper::m_offset),
64  MakeDoubleChecker<double> ())
65  .AddAttribute ("SiteHeight",
66  "The height [m] of each site",
67  DoubleValue (30),
68  MakeDoubleAccessor (&LteHexGridEnbTopologyHelper::m_siteHeight),
69  MakeDoubleChecker<double> ())
70  .AddAttribute ("MinX", "The x coordinate where the hex grid starts.",
71  DoubleValue (0.0),
72  MakeDoubleAccessor (&LteHexGridEnbTopologyHelper::m_xMin),
73  MakeDoubleChecker<double> ())
74  .AddAttribute ("MinY", "The y coordinate where the hex grid starts.",
75  DoubleValue (0.0),
76  MakeDoubleAccessor (&LteHexGridEnbTopologyHelper::m_yMin),
77  MakeDoubleChecker<double> ())
78  .AddAttribute ("GridWidth", "The number of sites in even rows (odd rows will have one additional site).",
79  UintegerValue (1),
80  MakeUintegerAccessor (&LteHexGridEnbTopologyHelper::m_gridWidth),
81  MakeUintegerChecker<uint32_t> ())
82  ;
83  return tid;
84 }
85 
86 void
88 {
89  NS_LOG_FUNCTION (this);
91 }
92 
93 
94 void
96 {
97  NS_LOG_FUNCTION (this << h);
98  m_lteHelper = h;
99 }
100 
103 {
104  NS_LOG_FUNCTION (this);
105  NetDeviceContainer enbDevs;
106  const double xydfactor = std::sqrt (0.75);
107  double yd = xydfactor*m_d;
108  for (uint32_t n = 0; n < c.GetN (); ++n)
109  {
110  uint32_t currentSite = n / 3;
111  uint32_t biRowIndex = (currentSite / (m_gridWidth + m_gridWidth + 1));
112  uint32_t biRowRemainder = currentSite % (m_gridWidth + m_gridWidth + 1);
113  uint32_t rowIndex = biRowIndex*2;
114  uint32_t colIndex = biRowRemainder;
115  if (biRowRemainder >= m_gridWidth)
116  {
117  ++rowIndex;
118  colIndex -= m_gridWidth;
119  }
120  NS_LOG_LOGIC ("node " << n << " site " << currentSite
121  << " rowIndex " << rowIndex
122  << " colIndex " << colIndex
123  << " biRowIndex " << biRowIndex
124  << " biRowRemainder " << biRowRemainder);
125  double y = m_yMin + yd * rowIndex;
126  double x;
127  double antennaOrientation;
128  if ((rowIndex % 2) == 0)
129  {
130  x = m_xMin + m_d * colIndex;
131  }
132  else // row is odd
133  {
134  x = m_xMin -(0.5*m_d) + m_d * colIndex;
135  }
136 
137  switch (n%3)
138  {
139  case 0:
140  antennaOrientation = 0;
141  x += m_offset;
142  break;
143 
144  case 1:
145  antennaOrientation = 120;
146  x -= m_offset/2.0;
147  y += m_offset*xydfactor;
148  break;
149 
150  case 2:
151  antennaOrientation = -120;
152  x -= m_offset/2.0;
153  y -= m_offset*xydfactor;
154  break;
155 
156  default:
157  break;
158  }
159  Ptr<Node> node = c.Get (n);
161  Vector pos (x, y, m_siteHeight);
162  NS_LOG_LOGIC ("node " << n << " at " << pos << " antennaOrientation " << antennaOrientation);
163  mm->SetPosition (Vector (x, y, m_siteHeight));
164  m_lteHelper->SetEnbAntennaModelAttribute ("Orientation", DoubleValue (antennaOrientation));
165  enbDevs.Add (m_lteHelper->InstallEnbDevice (node));
166  }
167  return enbDevs;
168 }
169 
170 } // namespace ns3
171 
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
virtual void DoDispose(void)
Definition: object.cc:335
a 3d vector
Definition: vector.h:31
NetDeviceContainer SetPositionAndInstallEnbDevice(NodeContainer c)
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
Keep track of the current position and velocity of an object.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
holds a vector of ns3::NetDevice pointers
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
keep track of a set of node pointers.
void SetPosition(const Vector &position)
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Hold an floating point type.
Definition: double.h:41
Ptr< T > GetObject(void) const
Definition: object.h:332