A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mesh-helper.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008,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: Kirill Andreev <andreev@iitp.ru>
19  * Pavel Boyko <boyko@iitp.ru>
20  */
21 #include "mesh-helper.h"
22 #include "ns3/simulator.h"
23 #include "ns3/mesh-point-device.h"
24 #include "ns3/wifi-net-device.h"
25 #include "ns3/minstrel-wifi-manager.h"
26 #include "ns3/mesh-wifi-interface-mac.h"
27 namespace ns3
28 {
30  m_nInterfaces (1),
31  m_spreadChannelPolicy (ZERO_CHANNEL),
32  m_stack (0),
33  m_standard (WIFI_PHY_STANDARD_80211a)
34 {
35 }
37 {
38  m_stack = 0;
39 }
40 void
42 {
43  m_spreadChannelPolicy = policy;
44 }
45 void
47  std::string n0, const AttributeValue &v0,
48  std::string n1, const AttributeValue &v1,
49  std::string n2, const AttributeValue &v2,
50  std::string n3, const AttributeValue &v3,
51  std::string n4, const AttributeValue &v4,
52  std::string n5, const AttributeValue &v5,
53  std::string n6, const AttributeValue &v6,
54  std::string n7, const AttributeValue &v7)
55 {
56  m_stackFactory.SetTypeId (type);
57  m_stackFactory.Set (n0, v0);
58  m_stackFactory.Set (n1, v1);
59  m_stackFactory.Set (n2, v2);
60  m_stackFactory.Set (n3, v3);
61  m_stackFactory.Set (n4, v4);
62  m_stackFactory.Set (n5, v5);
63  m_stackFactory.Set (n6, v6);
64  m_stackFactory.Set (n7, v7);
65 
66  m_stack = m_stackFactory.Create<MeshStack> ();
67  if (m_stack == 0)
68  {
69  NS_FATAL_ERROR ("Stack has not been created: " << type);
70  }
71 }
72 
73 void
74 MeshHelper::SetNumberOfInterfaces (uint32_t nInterfaces)
75 {
76  m_nInterfaces = nInterfaces;
77 }
79 MeshHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c) const
80 {
81  NetDeviceContainer devices;
82  NS_ASSERT (m_stack != 0);
83  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
84  {
85  Ptr<Node> node = *i;
86  // Create a mesh point device
87  Ptr<MeshPointDevice> mp = CreateObject<MeshPointDevice> ();
88  node->AddDevice (mp);
89  // Create wifi interfaces (single interface by default)
90  for (uint32_t i = 0; i < m_nInterfaces; ++i)
91  {
92  uint32_t channel = 0;
93  if (m_spreadChannelPolicy == ZERO_CHANNEL)
94  {
95  channel = 0;
96  }
97  if (m_spreadChannelPolicy == SPREAD_CHANNELS)
98  {
99  channel = i * 5;
100  }
101  Ptr<WifiNetDevice> iface = CreateInterface (phyHelper, node, channel);
102  mp->AddInterface (iface);
103  }
104  if (!m_stack->InstallStack (mp))
105  {
106  NS_FATAL_ERROR ("Stack is not installed!");
107  }
108  devices.Add (mp);
109  }
110  return devices;
111 }
114 {
115  MeshHelper helper;
116  helper.SetMacType ();
117  helper.SetRemoteStationManager ("ns3::ArfWifiManager");
118  helper.SetSpreadInterfaceChannels (SPREAD_CHANNELS);
119  return helper;
120 }
121 
122 void
123 MeshHelper::SetMacType (std::string n0, const AttributeValue &v0,
124  std::string n1, const AttributeValue &v1,
125  std::string n2, const AttributeValue &v2,
126  std::string n3, const AttributeValue &v3,
127  std::string n4, const AttributeValue &v4,
128  std::string n5, const AttributeValue &v5,
129  std::string n6, const AttributeValue &v6,
130  std::string n7, const AttributeValue &v7)
131 {
132  m_mac.SetTypeId ("ns3::MeshWifiInterfaceMac");
133  m_mac.Set (n0, v0);
134  m_mac.Set (n1, v1);
135  m_mac.Set (n2, v2);
136  m_mac.Set (n3, v3);
137  m_mac.Set (n4, v4);
138  m_mac.Set (n5, v5);
139  m_mac.Set (n6, v6);
140  m_mac.Set (n7, v7);
141 }
142 void
144  std::string n0, const AttributeValue &v0,
145  std::string n1, const AttributeValue &v1,
146  std::string n2, const AttributeValue &v2,
147  std::string n3, const AttributeValue &v3,
148  std::string n4, const AttributeValue &v4,
149  std::string n5, const AttributeValue &v5,
150  std::string n6, const AttributeValue &v6,
151  std::string n7, const AttributeValue &v7)
152 {
153  m_stationManager = ObjectFactory ();
154  m_stationManager.SetTypeId (type);
155  m_stationManager.Set (n0, v0);
156  m_stationManager.Set (n1, v1);
157  m_stationManager.Set (n2, v2);
158  m_stationManager.Set (n3, v3);
159  m_stationManager.Set (n4, v4);
160  m_stationManager.Set (n5, v5);
161  m_stationManager.Set (n6, v6);
162  m_stationManager.Set (n7, v7);
163 }
164 void
166 {
167  m_standard = standard;
168 }
169 
171 MeshHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr<Node> node, uint16_t channelId) const
172 {
173  Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
174 
176  NS_ASSERT (mac != 0);
177  mac->SetSsid (Ssid ());
178  Ptr<WifiRemoteStationManager> manager = m_stationManager.Create<WifiRemoteStationManager> ();
179  NS_ASSERT (manager != 0);
180  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
181  mac->SetAddress (Mac48Address::Allocate ());
182  mac->ConfigureStandard (m_standard);
183  phy->ConfigureStandard (m_standard);
184  device->SetMac (mac);
185  device->SetPhy (phy);
186  device->SetRemoteStationManager (manager);
187  node->AddDevice (device);
188  mac->SwitchFrequencyChannel (channelId);
189  return device;
190 }
191 void
192 MeshHelper::Report (const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
193 {
194  NS_ASSERT (m_stack != 0);
196  NS_ASSERT (mp != 0);
197  std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
198  os << "<MeshPointDevice time=\"" << Simulator::Now ().GetSeconds () << "\" address=\""
199  << Mac48Address::ConvertFrom (mp->GetAddress ()) << "\">\n";
200  m_stack->Report (mp, os);
201  os << "</MeshPointDevice>\n";
202 }
203 void
205 {
206  NS_ASSERT (m_stack != 0);
208  NS_ASSERT (mp != 0);
209  m_stack->ResetStats (mp);
210 }
211 int64_t
213 {
214  int64_t currentStream = stream;
215  Ptr<NetDevice> netDevice;
216  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
217  {
218  netDevice = (*i);
219  Ptr<MeshPointDevice> mpd = DynamicCast<MeshPointDevice> (netDevice);
220  Ptr<WifiNetDevice> wifi;
222  if (mpd)
223  {
224  // To access, we need the underlying WifiNetDevices
225  std::vector<Ptr<NetDevice> > ifaces = mpd->GetInterfaces ();
226  for (std::vector<Ptr<NetDevice> >::iterator i = ifaces.begin (); i != ifaces.end (); i++)
227  {
228  wifi = DynamicCast<WifiNetDevice> (*i);
229 
230  // Handle any random numbers in the PHY objects.
231  currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
232 
233  // Handle any random numbers in the station managers.
234  Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
235  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
236  if (minstrel)
237  {
238  currentStream += minstrel->AssignStreams (currentStream);
239  }
240  // Handle any random numbers in the mesh mac and plugins
241  mac = DynamicCast<MeshWifiInterfaceMac> (wifi->GetMac ());
242  if (mac)
243  {
244  currentStream += mac->AssignStreams (currentStream);
245  }
246  }
247  }
248  }
249  return (currentStream - stream);
250 }
251 
252 } // namespace ns3
253 
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
Hold a value for an Attribute.
Definition: attribute.h:51
create PHY objects
Definition: wifi-helper.h:50
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), 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())
Definition: mesh-helper.cc:143
#define NS_ASSERT(condition)
Definition: assert.h:64
void SetTypeId(TypeId tid)
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
Ptr< WifiNetDevice > CreateInterface(const WifiPhyHelper &phyHelper, Ptr< Node > node, uint16_t channelId) const
Definition: mesh-helper.cc:171
void Report(const ns3::Ptr< ns3::NetDevice > &, std::ostream &)
Print statistics.
Definition: mesh-helper.cc:192
void SetNumberOfInterfaces(uint32_t nInterfaces)
Set a number of interfaces in a mesh network.
Definition: mesh-helper.cc:74
Prototype for class, which helps to install MAC-layer routing stack to ns3::MeshPointDevice.
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
double GetSeconds(void) const
Definition: nstime.h:262
static Mac48Address Allocate(void)
Ptr< Object > Create(void) const
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
holds a vector of ns3::NetDevice pointers
hold a list of per-remote-station state.
void SetMacType(std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), 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())
Definition: mesh-helper.cc:123
static Mac48Address ConvertFrom(const Address &address)
ChannelPolicy
Spread/not spread frequency channels of MP interfaces.
Definition: mesh-helper.h:129
keep track of a set of node pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
void Set(std::string name, const AttributeValue &value)
virtual Ptr< WifiPhy > Create(Ptr< Node > node, Ptr< WifiNetDevice > device) const =0
static Time Now(void)
Definition: simulator.cc:179
void SetSpreadInterfaceChannels(ChannelPolicy)
set the channel policy
Definition: mesh-helper.cc:41
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Definition: mesh-helper.cc:212
void SetStackInstaller(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), 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())
Definition: mesh-helper.cc:46
void ResetStats(const ns3::Ptr< ns3::NetDevice > &)
Reset statistics.
Definition: mesh-helper.cc:204
Virtual net device modeling mesh point.
Definition: ssid.h:35
void SetStandard(enum WifiPhyStandard standard)
Definition: mesh-helper.cc:165
instantiate subclasses of ns3::Object.
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:119
NetDeviceContainer Install(const WifiPhyHelper &phyHelper, NodeContainer c) const
Install 802.11s mesh device & protocols on given node list.
Definition: mesh-helper.cc:79
static MeshHelper Default()
Set the helper to the default values for the MAC type, remote station manager and channel policy...
Definition: mesh-helper.cc:113
Helper to create IEEE 802.11s mesh networks.
Definition: mesh-helper.h:38
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
Ptr< T > GetObject(void) const
Definition: object.h:332
Basic MAC of mesh point Wi-Fi interface. Its function is extendable through plugins mechanism...