A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mesh-helper.cc
Go to the documentation of this file.
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 {
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 
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;
94  {
95  channel = 0;
96  }
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");
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 {
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 ());
179  NS_ASSERT (manager != 0);
180  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
181  mac->SetAddress (Mac48Address::Allocate ());
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