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/object-vector.h"
22#include "ns3/llc-snap-header.h"
23#include "ns3/channel.h"
24#include "ns3/pointer.h"
25#include "ns3/log.h"
26#include "ns3/node.h"
27#include "ns3/uinteger.h"
28#include "wifi-net-device.h"
29#include "wifi-phy.h"
30#include "wifi-mac.h"
31#include "ns3/ht-configuration.h"
32#include "ns3/vht-configuration.h"
33#include "ns3/he-configuration.h"
34#include "ns3/eht-configuration.h"
35
36namespace ns3 {
37
38NS_LOG_COMPONENT_DEFINE ("WifiNetDevice");
39
40NS_OBJECT_ENSURE_REGISTERED (WifiNetDevice);
41
42TypeId
44{
45 static TypeId tid = TypeId ("ns3::WifiNetDevice")
47 .AddConstructor<WifiNetDevice> ()
48 .SetGroupName ("Wifi")
49 .AddAttribute ("Mtu", "The MAC-level Maximum Transmission Unit",
53 MakeUintegerChecker<uint16_t> (1,MAX_MSDU_SIZE - LLC_SNAP_HEADER_LENGTH))
54 .AddAttribute ("Channel", "The channel attached to this device",
55 PointerValue (),
57 MakePointerChecker<Channel> (),
59 "Use the Channel attribute of WifiPhy")
60 .AddAttribute ("Phy", "The PHY layer attached to this device.",
61 PointerValue (),
64 MakePointerChecker<WifiPhy> ())
65 .AddAttribute ("Phys", "The PHY layers attached to this device (11be multi-link devices only).",
69 MakeObjectVectorChecker<WifiPhy> ())
70 .AddAttribute ("Mac", "The MAC layer attached to this device.",
71 PointerValue (),
74 MakePointerChecker<WifiMac> ())
75 .AddAttribute ("RemoteStationManager", "The station manager attached to this device.",
76 PointerValue (),
79 MakePointerChecker<WifiRemoteStationManager> ())
80 .AddAttribute ("RemoteStationManagers",
81 "The remote station managers attached to this device (11be multi-link devices only).",
85 MakeObjectVectorChecker<WifiPhy> ())
86 .AddAttribute ("HtConfiguration",
87 "The HtConfiguration object.",
88 PointerValue (),
90 MakePointerChecker<HtConfiguration> ())
91 .AddAttribute ("VhtConfiguration",
92 "The VhtConfiguration object.",
93 PointerValue (),
95 MakePointerChecker<VhtConfiguration> ())
96 .AddAttribute ("HeConfiguration",
97 "The HeConfiguration object.",
98 PointerValue (),
100 MakePointerChecker<HeConfiguration> ())
101 .AddAttribute ("EhtConfiguration",
102 "The EhtConfiguration object.",
103 PointerValue (),
105 MakePointerChecker<EhtConfiguration> ())
106 ;
107 return tid;
108}
109
111 : m_standard (WIFI_STANDARD_UNSPECIFIED),
112 m_configComplete (false)
113{
115}
116
118{
120}
121
122void
124{
126 m_node = 0;
127 if (m_mac)
128 {
129 m_mac->Dispose ();
130 m_mac = 0;
131 }
132 for (auto& phy : m_phys)
133 {
134 if (phy != nullptr)
135 {
136 phy->Dispose ();
137 phy = nullptr;
138 }
139 }
140 m_phys.clear ();
141 for (auto& stationManager : m_stationManagers)
142 {
143 if (stationManager != nullptr)
144 {
145 stationManager->Dispose ();
146 stationManager = nullptr;
147 }
148 }
149 m_stationManagers.clear ();
151 {
152 m_htConfiguration->Dispose ();
154 }
156 {
159 }
161 {
162 m_heConfiguration->Dispose ();
164 }
166 {
167 m_ehtConfiguration->Dispose ();
169 }
171}
172
173void
175{
177
178 for (const auto& phy : m_phys)
179 {
180 if (phy)
181 {
182 phy->Initialize ();
183 }
184 }
185 if (m_mac)
186 {
187 m_mac->Initialize ();
188 }
189 for (const auto& stationManager : m_stationManagers)
190 {
191 if (stationManager)
192 {
193 stationManager->Initialize ();
194 }
195 }
197}
198
199void
201{
202 if (m_mac == 0
203 || m_phys.empty ()
204 || m_stationManagers.empty ()
205 || m_node == 0
207 {
208 return;
209 }
210 NS_ABORT_IF (m_phys.size () != m_stationManagers.size ());
211 m_mac->SetWifiPhys (m_phys);
212 m_mac->SetWifiRemoteStationManagers (m_stationManagers);
213 m_mac->SetForwardUpCallback (MakeCallback (&WifiNetDevice::ForwardUp, this));
214 m_mac->SetLinkUpCallback (MakeCallback (&WifiNetDevice::LinkUp, this));
215 m_mac->SetLinkDownCallback (MakeCallback (&WifiNetDevice::LinkDown, this));
216 for (uint8_t linkId = 0; linkId < m_stationManagers.size (); linkId++)
217 {
218 m_stationManagers.at (linkId)->SetupPhy (m_phys.at (linkId));
219 m_stationManagers.at (linkId)->SetupMac (m_mac);
220 }
221 m_configComplete = true;
222}
223
224void
226{
227 NS_ABORT_MSG_IF (m_standard != WIFI_STANDARD_UNSPECIFIED, "Wifi standard already set");
228 m_standard = standard;
229}
230
233{
234 return m_standard;
235}
236
237void
239{
240 m_mac = mac;
242}
243
244void
246{
247 m_phys.clear ();
248 m_phys.push_back (phy);
249 m_linkUp = true;
251}
252
253void
254WifiNetDevice::SetPhys (const std::vector<Ptr<WifiPhy>>& phys)
255{
256 NS_ABORT_MSG_IF (phys.size () > 1 && m_ehtConfiguration == nullptr,
257 "Multiple PHYs only allowed for 11be multi-link devices");
258 m_phys = phys;
259 m_linkUp = true;
261}
262
263void
265{
266 m_stationManagers.clear ();
267 m_stationManagers.push_back (manager);
269}
270
271void
273{
274 NS_ABORT_MSG_IF (managers.size () > 1 && m_ehtConfiguration == nullptr,
275 "Multiple remote station managers only allowed for 11be multi-link devices");
276 m_stationManagers = managers;
278}
279
282{
283 return m_mac;
284}
285
288{
289 return GetPhy (SINGLE_LINK_OP_ID);
290}
291
293WifiNetDevice::GetPhy (uint8_t i) const
294{
295 NS_ASSERT (i < GetPhys ().size ());
296 return GetPhys ().at (i);
297}
298
299const std::vector<Ptr<WifiPhy>>&
301{
302 return m_phys;
303}
304
305uint8_t
307{
308 return GetPhys ().size ();
309}
310
313{
314 return GetRemoteStationManager (0);
315}
316
319{
320 NS_ASSERT (linkId < GetRemoteStationManagers ().size ());
321 return GetRemoteStationManagers ().at (linkId);
322}
323
324const std::vector<Ptr<WifiRemoteStationManager>>&
326{
327 return m_stationManagers;
328}
329
330uint8_t
332{
333 return GetRemoteStationManagers ().size ();
334}
335
336void
338{
339 m_ifIndex = index;
340}
341
344{
345 return m_ifIndex;
346}
347
350{
351 for (uint8_t i = 1; i < GetNPhys (); i++)
352 {
353 if (GetPhy (i)->GetChannel () != GetPhy (i - 1)->GetChannel ())
354 {
355 NS_ABORT_MSG ("Do not call WifiNetDevice::GetChannel() when using multiple channels");
356 }
357 }
358
359 return m_phys[SINGLE_LINK_OP_ID]->GetChannel ();
360}
361
362void
364{
366}
367
370{
371 return m_mac->GetAddress ();
372}
373
374bool
375WifiNetDevice::SetMtu (const uint16_t mtu)
376{
378 {
379 return false;
380 }
381 m_mtu = mtu;
382 return true;
383}
384
385uint16_t
387{
388 return m_mtu;
389}
390
391bool
393{
394 return !m_phys.empty () && m_linkUp;
395}
396
397void
399{
401}
402
403bool
405{
406 return true;
407}
408
411{
413}
414
415bool
417{
418 return true;
419}
420
423{
424 return Mac48Address::GetMulticast (multicastGroup);
425}
426
428{
429 return Mac48Address::GetMulticast (addr);
430}
431
432bool
434{
435 return false;
436}
437
438bool
440{
441 return false;
442}
443
444bool
445WifiNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
446{
447 NS_LOG_FUNCTION (this << packet << dest << protocolNumber);
449
451
452 LlcSnapHeader llc;
453 llc.SetType (protocolNumber);
454 packet->AddHeader (llc);
455
456 m_mac->NotifyTx (packet);
457 m_mac->Enqueue (packet, realTo);
458 return true;
459}
460
463{
464 return m_node;
465}
466
467void
469{
470 m_node = node;
472}
473
474bool
476{
477 return true;
478}
479
480void
482{
483 m_forwardUp = cb;
484}
485
486void
488{
489 NS_LOG_FUNCTION (this << packet << from << to);
490 LlcSnapHeader llc;
492 if (to.IsBroadcast ())
493 {
495 }
496 else if (to.IsGroup ())
497 {
499 }
500 else if (to == m_mac->GetAddress ())
501 {
503 }
504 else
505 {
507 }
508
509 Ptr<Packet> copy = packet->Copy ();
511 {
512 m_mac->NotifyRx (packet);
513 copy->RemoveHeader (llc);
514 m_forwardUp (this, copy, llc.GetType (), from);
515 }
516 else
517 {
518 copy->RemoveHeader (llc);
519 }
520
521 if (!m_promiscRx.IsNull ())
522 {
523 m_mac->NotifyPromiscRx (copy);
524 m_promiscRx (this, copy, llc.GetType (), from, to, type);
525 }
526}
527
528void
530{
531 m_linkUp = true;
532 m_linkChanges ();
533}
534
535void
537{
538 m_linkUp = false;
539 m_linkChanges ();
540}
541
542bool
543WifiNetDevice::SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
544{
545 NS_LOG_FUNCTION (this << packet << source << dest << protocolNumber);
548
550 Mac48Address realFrom = Mac48Address::ConvertFrom (source);
551
552 LlcSnapHeader llc;
553 llc.SetType (protocolNumber);
554 packet->AddHeader (llc);
555
556 m_mac->NotifyTx (packet);
557 m_mac->Enqueue (packet, realTo, realFrom);
558
559 return true;
560}
561
562void
564{
565 m_promiscRx = cb;
566 m_mac->SetPromisc ();
567}
568
569bool
571{
572 return m_mac->SupportsSendFrom ();
573}
574
575void
577{
578 m_htConfiguration = htConfiguration;
579}
580
583{
584 return (m_standard >= WIFI_STANDARD_80211n ? m_htConfiguration : nullptr);
585}
586
587void
589{
590 m_vhtConfiguration = vhtConfiguration;
591}
592
595{
597 ? m_vhtConfiguration : nullptr);
598}
599
600void
602{
603 m_heConfiguration = heConfiguration;
604}
605
608{
609 return (m_standard >= WIFI_STANDARD_80211ax ? m_heConfiguration : nullptr);
610}
611
612void
614{
615 m_ehtConfiguration = ehtConfiguration;
616}
617
620{
622}
623
624} //namespace ns3
a polymophic address class
Definition: address.h:91
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1386
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Describes an IPv6 address.
Definition: ipv6-address.h:50
Header for the LLC/SNAP encapsulation.
uint16_t GetType(void)
Return the Ethertype.
void SetType(uint16_t type)
Set the Ethertype.
an EUI-48 address
Definition: mac48-address.h:44
static Mac48Address GetMulticast(Ipv4Address address)
static Mac48Address GetBroadcast(void)
static bool IsMatchingType(const Address &address)
bool IsGroup(void) const
bool IsBroadcast(void) const
static Mac48Address ConvertFrom(const Address &address)
Network layer to device interface.
Definition: net-device.h:96
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:297
@ PACKET_HOST
Packet addressed oo us.
Definition: net-device.h:298
@ PACKET_OTHERHOST
Packet addressed to someone else.
Definition: net-device.h:304
@ PACKET_BROADCAST
Packet addressed to all.
Definition: net-device.h:300
@ PACKET_MULTICAST
Packet addressed to multicast group.
Definition: net-device.h:302
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
virtual void DoInitialize(void)
Initialize() implementation.
Definition: object.cc:353
void Dispose(void)
Dispose of this Object.
Definition: object.cc:214
Container for a set of ns3::Object pointers.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
Hold objects of type Ptr<T>.
Definition: pointer.h:37
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
@ DEPRECATED
Attribute or trace source is deprecated; user is warned.
Definition: type-id.h:73
Hold an unsigned integer type.
Definition: uinteger.h:44
Hold together all Wifi-related objects.
void ForwardUp(Ptr< const Packet > packet, Mac48Address from, Mac48Address to)
Receive a packet from the lower layer and pass the packet up the stack.
bool NeedsArp(void) const override
void LinkUp(void)
Set that the link is up.
void SetMac(const Ptr< WifiMac > mac)
Ptr< HtConfiguration > m_htConfiguration
the HtConfiguration
uint16_t GetMtu(void) const override
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
Ptr< HtConfiguration > GetHtConfiguration(void) const
Ptr< EhtConfiguration > m_ehtConfiguration
the EhtConfiguration
bool IsMulticast(void) const override
void SetPhys(const std::vector< Ptr< WifiPhy > > &phys)
void DoInitialize(void) override
Initialize() implementation.
void SetHeConfiguration(Ptr< HeConfiguration > heConfiguration)
bool IsBroadcast(void) const override
void LinkDown(void)
Set that the link is down (i.e.
void SetHtConfiguration(Ptr< HtConfiguration > htConfiguration)
Ptr< WifiMac > GetMac(void) const
std::vector< Ptr< WifiPhy > > m_phys
the phy objects
bool SetMtu(const uint16_t mtu) override
bool IsPointToPoint(void) const override
Return true if the net device is on a point-to-point link.
virtual const std::vector< Ptr< WifiPhy > > & GetPhys(void) const
uint32_t m_ifIndex
IF index.
Ptr< VhtConfiguration > m_vhtConfiguration
the VhtConfiguration
bool m_configComplete
configuration complete
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
void SetIfIndex(const uint32_t index) override
Ptr< Channel > GetChannel(void) const override
NetDevice::ReceiveCallback m_forwardUp
forward up callback
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
Address GetAddress(void) const override
bool SupportsSendFrom(void) const override
bool IsLinkUp(void) const override
Ptr< HeConfiguration > m_heConfiguration
the HeConfiguration
uint8_t GetNPhys(void) const
WifiStandard GetStandard(void) const
Get the Wifi standard.
Address GetBroadcast(void) const override
void SetVhtConfiguration(Ptr< VhtConfiguration > vhtConfiguration)
NetDevice::PromiscReceiveCallback m_promiscRx
promiscuous receive callback
Ptr< WifiPhy > GetPhy(void) const
TracedCallback m_linkChanges
link change callback
void CompleteConfig(void)
Complete the configuration of this Wi-Fi device by connecting all lower components (e....
void SetRemoteStationManager(const Ptr< WifiRemoteStationManager > manager)
static TypeId GetTypeId(void)
Get the type ID.
void SetNode(const Ptr< Node > node) override
void SetRemoteStationManagers(const std::vector< Ptr< WifiRemoteStationManager > > &managers)
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
virtual const std::vector< Ptr< WifiRemoteStationManager > > & GetRemoteStationManagers(void) const
std::vector< Ptr< WifiRemoteStationManager > > m_stationManagers
the station managers
uint32_t GetIfIndex(void) const override
Ptr< VhtConfiguration > GetVhtConfiguration(void) const
void SetAddress(Address address) override
Set the address of this interface.
Ptr< EhtConfiguration > GetEhtConfiguration(void) const
void SetStandard(WifiStandard standard)
Set the Wifi standard.
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
bool IsBridge(void) const override
Return true if the net device is acting as a bridge.
Ptr< WifiRemoteStationManager > GetRemoteStationManager(void) const
Ptr< Node > m_node
the node
void SetEhtConfiguration(Ptr< EhtConfiguration > ehtConfiguration)
WifiStandard m_standard
Wifi standard.
void SetPhy(const Ptr< WifiPhy > phy)
Ptr< WifiMac > m_mac
the MAC
uint8_t GetNRemoteStationManagers(void) const
void AddLinkChangeCallback(Callback< void > callback) override
void DoDispose(void) override
Destructor implementation.
Ptr< HeConfiguration > GetHeConfiguration(void) const
Ptr< Node > GetNode(void) const override
virtual Ptr< Channel > GetChannel(void) const =0
Return the Channel this WifiPhy is connected to.
#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
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:81
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:45
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
@ WIFI_STANDARD_80211be
@ WIFI_STANDARD_80211n
@ WIFI_STANDARD_80211ax
@ WIFI_STANDARD_UNSPECIFIED
@ WIFI_STANDARD_80211ac
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Definition: wifi-phy-band.h:37
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static constexpr uint8_t SINGLE_LINK_OP_ID
Link ID for single link operations (helps tracking places where correct link ID is to be used to supp...
Definition: wifi-utils.h:138
static const uint16_t MAX_MSDU_SIZE
This value conforms to the 802.11 specification.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
static const uint16_t LLC_SNAP_HEADER_LENGTH
The length in octects of the LLC/SNAP header.
mac
Definition: third.py:87
phy
Definition: third.py:84