A Discrete-Event Network Simulator
API
wifi-net-device.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ns3/llc-snap-header.h"
22 #include "ns3/channel.h"
23 #include "ns3/pointer.h"
24 #include "ns3/log.h"
25 #include "ns3/node.h"
26 #include "ns3/uinteger.h"
27 #include "wifi-net-device.h"
28 #include "wifi-phy.h"
29 #include "wifi-mac.h"
30 #include "ht-configuration.h"
31 #include "vht-configuration.h"
32 #include "he-configuration.h"
33 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("WifiNetDevice");
37 
38 NS_OBJECT_ENSURE_REGISTERED (WifiNetDevice);
39 
40 TypeId
42 {
43  static TypeId tid = TypeId ("ns3::WifiNetDevice")
44  .SetParent<NetDevice> ()
45  .AddConstructor<WifiNetDevice> ()
46  .SetGroupName ("Wifi")
47  .AddAttribute ("Mtu", "The MAC-level Maximum Transmission Unit",
51  MakeUintegerChecker<uint16_t> (1,MAX_MSDU_SIZE - LLC_SNAP_HEADER_LENGTH))
52  .AddAttribute ("Channel", "The channel attached to this device",
53  PointerValue (),
55  MakePointerChecker<Channel> ())
56  .AddAttribute ("Phy", "The PHY layer attached to this device.",
57  PointerValue (),
60  MakePointerChecker<WifiPhy> ())
61  .AddAttribute ("Mac", "The MAC layer attached to this device.",
62  PointerValue (),
65  MakePointerChecker<WifiMac> ())
66  .AddAttribute ("RemoteStationManager", "The station manager attached to this device.",
67  PointerValue (),
70  MakePointerChecker<WifiRemoteStationManager> ())
71  .AddAttribute ("HtConfiguration",
72  "The HtConfiguration object.",
73  PointerValue (),
75  MakePointerChecker<HtConfiguration> ())
76  .AddAttribute ("VhtConfiguration",
77  "The VhtConfiguration object.",
78  PointerValue (),
80  MakePointerChecker<VhtConfiguration> ())
81  .AddAttribute ("HeConfiguration",
82  "The HeConfiguration object.",
83  PointerValue (),
85  MakePointerChecker<HeConfiguration> ())
86  ;
87  return tid;
88 }
89 
91  : m_configComplete (false)
92 {
94 }
95 
97 {
99 }
100 
101 void
103 {
105  m_node = 0;
106  if (m_mac)
107  {
108  m_mac->Dispose ();
109  m_mac = 0;
110  }
111  if (m_phy)
112  {
113  m_phy->Dispose ();
114  m_phy = 0;
115  }
116  if (m_stationManager)
117  {
119  m_stationManager = 0;
120  }
121  if (m_htConfiguration)
122  {
123  m_htConfiguration->Dispose ();
124  m_htConfiguration = 0;
125  }
126  if (m_vhtConfiguration)
127  {
128  m_vhtConfiguration->Dispose ();
129  m_vhtConfiguration = 0;
130  }
131  if (m_heConfiguration)
132  {
133  m_heConfiguration->Dispose ();
134  m_heConfiguration = 0;
135  }
137 }
138 
139 void
141 {
143  m_phy->Initialize ();
144  m_mac->Initialize ();
147 }
148 
149 void
151 {
152  if (m_mac == 0
153  || m_phy == 0
154  || m_stationManager == 0
155  || m_node == 0
156  || m_configComplete)
157  {
158  return;
159  }
160  m_mac->SetWifiRemoteStationManager (m_stationManager);
161  m_mac->SetWifiPhy (m_phy);
162  m_mac->SetForwardUpCallback (MakeCallback (&WifiNetDevice::ForwardUp, this));
163  m_mac->SetLinkUpCallback (MakeCallback (&WifiNetDevice::LinkUp, this));
164  m_mac->SetLinkDownCallback (MakeCallback (&WifiNetDevice::LinkDown, this));
167  m_configComplete = true;
168 }
169 
170 void
172 {
173  m_mac = mac;
174  CompleteConfig ();
175 }
176 
177 void
179 {
180  m_phy = phy;
181  CompleteConfig ();
182 }
183 
184 void
186 {
187  m_stationManager = manager;
188  CompleteConfig ();
189 }
190 
193 {
194  return m_mac;
195 }
196 
199 {
200  return m_phy;
201 }
202 
205 {
206  return m_stationManager;
207 }
208 
209 void
210 WifiNetDevice::SetIfIndex (const uint32_t index)
211 {
212  m_ifIndex = index;
213 }
214 
215 uint32_t
217 {
218  return m_ifIndex;
219 }
220 
223 {
224  return m_phy->GetChannel ();
225 }
226 
227 void
229 {
230  m_mac->SetAddress (Mac48Address::ConvertFrom (address));
231 }
232 
233 Address
235 {
236  return m_mac->GetAddress ();
237 }
238 
239 bool
240 WifiNetDevice::SetMtu (const uint16_t mtu)
241 {
243  {
244  return false;
245  }
246  m_mtu = mtu;
247  return true;
248 }
249 
250 uint16_t
252 {
253  return m_mtu;
254 }
255 
256 bool
258 {
259  return m_phy != 0 && m_linkUp;
260 }
261 
262 void
264 {
266 }
267 
268 bool
270 {
271  return true;
272 }
273 
274 Address
276 {
277  return Mac48Address::GetBroadcast ();
278 }
279 
280 bool
282 {
283  return true;
284 }
285 
286 Address
288 {
289  return Mac48Address::GetMulticast (multicastGroup);
290 }
291 
293 {
294  return Mac48Address::GetMulticast (addr);
295 }
296 
297 bool
299 {
300  return false;
301 }
302 
303 bool
305 {
306  return false;
307 }
308 
309 bool
310 WifiNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
311 {
312  NS_LOG_FUNCTION (this << packet << dest << protocolNumber);
314 
315  Mac48Address realTo = Mac48Address::ConvertFrom (dest);
316 
317  LlcSnapHeader llc;
318  llc.SetType (protocolNumber);
319  packet->AddHeader (llc);
320 
321  m_mac->NotifyTx (packet);
322  m_mac->Enqueue (packet, realTo);
323  return true;
324 }
325 
326 Ptr<Node>
328 {
329  return m_node;
330 }
331 
332 void
334 {
335  m_node = node;
336  CompleteConfig ();
337 }
338 
339 bool
341 {
342  return true;
343 }
344 
345 void
347 {
348  m_forwardUp = cb;
349 }
350 
351 void
353 {
354  NS_LOG_FUNCTION (this << packet << from << to);
355  LlcSnapHeader llc;
357  if (to.IsBroadcast ())
358  {
360  }
361  else if (to.IsGroup ())
362  {
364  }
365  else if (to == m_mac->GetAddress ())
366  {
367  type = NetDevice::PACKET_HOST;
368  }
369  else
370  {
372  }
373 
374  if (type != NetDevice::PACKET_OTHERHOST)
375  {
376  m_mac->NotifyRx (packet);
377  packet->RemoveHeader (llc);
378  m_forwardUp (this, packet, llc.GetType (), from);
379  }
380  else
381  {
382  packet->RemoveHeader (llc);
383  }
384 
385  if (!m_promiscRx.IsNull ())
386  {
387  m_mac->NotifyPromiscRx (packet);
388  m_promiscRx (this, packet, llc.GetType (), from, to, type);
389  }
390 }
391 
392 void
394 {
395  m_linkUp = true;
396  m_linkChanges ();
397 }
398 
399 void
401 {
402  m_linkUp = false;
403  m_linkChanges ();
404 }
405 
406 bool
407 WifiNetDevice::SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
408 {
409  NS_LOG_FUNCTION (this << packet << source << dest << protocolNumber);
412 
413  Mac48Address realTo = Mac48Address::ConvertFrom (dest);
414  Mac48Address realFrom = Mac48Address::ConvertFrom (source);
415 
416  LlcSnapHeader llc;
417  llc.SetType (protocolNumber);
418  packet->AddHeader (llc);
419 
420  m_mac->NotifyTx (packet);
421  m_mac->Enqueue (packet, realTo, realFrom);
422 
423  return true;
424 }
425 
426 void
428 {
429  m_promiscRx = cb;
430  m_mac->SetPromisc ();
431 }
432 
433 bool
435 {
436  return m_mac->SupportsSendFrom ();
437 }
438 
439 void
441 {
442  m_htConfiguration = htConfiguration;
443 }
444 
447 {
448  return m_htConfiguration;
449 }
450 
451 void
453 {
454  m_vhtConfiguration = vhtConfiguration;
455 }
456 
459 {
460  return m_vhtConfiguration;
461 }
462 
463 void
465 {
466  m_heConfiguration = heConfiguration;
467 }
468 
471 {
472  return m_heConfiguration;
473 }
474 
475 } //namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void Dispose(void)
Dispose of this Object.
Definition: object.cc:214
static bool IsMatchingType(const Address &address)
virtual void DoInitialize(void)
Initialize() implementation.
Definition: object.cc:353
bool m_linkUp
link up
bool SetMtu(const uint16_t mtu)
bool IsBroadcast(void) const
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Ptr< HeConfiguration > GetHeConfiguration(void) const
void LinkUp(void)
Set that the link is up.
Packet addressed to someone else.
Definition: net-device.h:304
Ptr< HeConfiguration > m_heConfiguration
the HeConfiguration
Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Ptr< WifiRemoteStationManager > m_stationManager
the station manager
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
void SetHtConfiguration(Ptr< HtConfiguration > htConfiguration)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
bool SupportsSendFrom(void) const
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
void SetType(uint16_t type)
Set the Ethertype.
void ForwardUp(Ptr< Packet > packet, Mac48Address from, Mac48Address to)
Receive a packet from the lower layer and pass the packet up the stack.
uint32_t GetIfIndex(void) const
Address GetAddress(void) const
uint16_t GetMtu(void) const
a polymophic address class
Definition: address.h:90
phy
Definition: third.py:86
virtual Ptr< Channel > GetChannel(void) const =0
Return the Channel this WifiPhy is connected to.
uint16_t m_mtu
MTU.
void SetHeConfiguration(Ptr< HeConfiguration > heConfiguration)
void DoDispose(void)
Destructor implementation.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: pointer.h:220
Ptr< WifiRemoteStationManager > GetRemoteStationManager(void) const
static Mac48Address GetMulticast(Ipv4Address address)
void SetMac(const Ptr< WifiMac > mac)
uint16_t GetType(void)
Return the Ethertype.
static const uint16_t MAX_MSDU_SIZE
This value conforms to the 802.11 specification.
bool IsMulticast(void) const
Hold an unsigned integer type.
Definition: uinteger.h:44
Ptr< WifiMac > m_mac
the MAC
mac
Definition: third.py:92
Ptr< WifiPhy > m_phy
the phy
Address GetBroadcast(void) const
static Mac48Address GetBroadcast(void)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
Ptr< Channel > GetChannel(void) const
virtual void SetupPhy(const Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
bool IsBroadcast(void) const
static Mac48Address ConvertFrom(const Address &address)
static const uint16_t LLC_SNAP_HEADER_LENGTH
The length in octects of the LLC/SNAP header.
Ptr< WifiPhy > GetPhy(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
TracedCallback m_linkChanges
link change callback
Hold objects of type Ptr<T>.
Definition: pointer.h:36
address
Definition: first.py:37
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Ptr< Node > m_node
the node
an EUI-48 address
Definition: mac48-address.h:43
void DoInitialize(void)
Initialize() implementation.
uint32_t m_ifIndex
IF index.
bool IsGroup(void) const
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Describes an IPv6 address.
Definition: ipv6-address.h:49
void SetPhy(const Ptr< WifiPhy > phy)
virtual void SetupMac(const Ptr< WifiMac > mac)
Set up MAC associated with this device since it is the object that knows the full set of timing param...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
void SetIfIndex(const uint32_t index)
Ptr< WifiMac > GetMac(void) const
NetDevice::ReceiveCallback m_forwardUp
forward up callback
bool IsBridge(void) const
Return true if the net device is acting as a bridge.
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
Packet addressed oo us.
Definition: net-device.h:298
Network layer to device interface.
Definition: net-device.h:95
Ptr< VhtConfiguration > m_vhtConfiguration
the VhtConfiguration
Ptr< HtConfiguration > m_htConfiguration
the HtConfiguration
void AddLinkChangeCallback(Callback< void > callback)
void CompleteConfig(void)
Complete the configuration of this Wi-Fi device by connecting all lower components (e...
void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
bool IsLinkUp(void) const
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:296
void LinkDown(void)
Set that the link is down (i.e.
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
Ptr< VhtConfiguration > GetVhtConfiguration(void) const
Packet addressed to multicast group.
Definition: net-device.h:302
Ptr< HtConfiguration > GetHtConfiguration(void) const
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
Packet addressed to all.
Definition: net-device.h:300
void SetReceiveCallback(NetDevice::ReceiveCallback cb)
void SetVhtConfiguration(Ptr< VhtConfiguration > vhtConfiguration)
static TypeId GetTypeId(void)
Get the type ID.
NetDevice::PromiscReceiveCallback m_promiscRx
promiscious receive callback
void Initialize(void)
Invoke DoInitialize on all Objects aggregated to this one.
Definition: object.cc:183
bool m_configComplete
configuration complete
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
void SetNode(const Ptr< Node > node)
void SetAddress(Address address)
Set the address of this interface.
bool NeedsArp(void) const
Header for the LLC/SNAP encapsulation.
void SetRemoteStationManager(const Ptr< WifiRemoteStationManager > manager)
Ptr< Node > GetNode(void) const