A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
adhoc-wifi-mac.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006, 2009 INRIA
3 * Copyright (c) 2009 MIRKO BANCHI
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8 * Mirko Banchi <mk.banchi@gmail.com>
9 */
10
11#include "adhoc-wifi-mac.h"
12
13#include "qos-txop.h"
14
15#include "ns3/eht-capabilities.h"
16#include "ns3/he-capabilities.h"
17#include "ns3/ht-capabilities.h"
18#include "ns3/log.h"
19#include "ns3/packet.h"
20#include "ns3/vht-capabilities.h"
21
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("AdhocWifiMac");
26
27NS_OBJECT_ENSURE_REGISTERED(AdhocWifiMac);
28
29TypeId
31{
32 static TypeId tid = TypeId("ns3::AdhocWifiMac")
34 .SetGroupName("Wifi")
35 .AddConstructor<AdhocWifiMac>();
36 return tid;
37}
38
40{
41 NS_LOG_FUNCTION(this);
42 // Let the lower layers know that we are acting in an IBSS
44}
45
50
51void
56
57bool
59{
60 return true;
61}
62
63void
65{
66 NS_LOG_FUNCTION(this << *mpdu << to << from);
67
68 if (GetWifiRemoteStationManager()->IsBrandNew(to))
69 {
70 // In ad hoc mode, we assume that every destination supports all the rates we support.
72 {
73 GetWifiRemoteStationManager()->AddAllSupportedMcs(to);
74 GetWifiRemoteStationManager()->AddStationHtCapabilities(
75 to,
77 }
79 {
80 GetWifiRemoteStationManager()->AddStationVhtCapabilities(
81 to,
83 }
84 if (GetHeSupported())
85 {
86 GetWifiRemoteStationManager()->AddStationHeCapabilities(
87 to,
90 {
91 GetWifiRemoteStationManager()->AddStationHe6GhzCapabilities(
92 to,
94 }
95 }
96 if (GetEhtSupported())
97 {
98 GetWifiRemoteStationManager()->AddStationEhtCapabilities(
99 to,
101 }
102 GetWifiRemoteStationManager()->AddAllSupportedModes(to);
103 GetWifiRemoteStationManager()->RecordDisassociated(to);
104 }
105
106 auto& hdr = mpdu->GetHeader();
107
108 hdr.SetAddr1(to);
109 hdr.SetAddr2(GetAddress());
110 hdr.SetAddr3(GetBssid(SINGLE_LINK_OP_ID));
111 hdr.SetDsNotFrom();
112 hdr.SetDsNotTo();
113
114 auto txop = hdr.IsQosData() ? StaticCast<Txop>(GetQosTxop(hdr.GetQosTid())) : GetTxop();
116 txop->Queue(mpdu);
117}
118
119void
121{
122 NS_LOG_FUNCTION(this << &linkUp);
124
125 // The approach taken here is that, from the point of view of a STA
126 // in IBSS mode, the link is always up, so we immediately invoke the
127 // callback if one is set
128 linkUp();
129}
130
131void
133{
134 NS_LOG_FUNCTION(this << *mpdu << +linkId);
135 const WifiMacHeader* hdr = &mpdu->GetHeader();
136 NS_ASSERT(!hdr->IsCtl());
137 Mac48Address from = hdr->GetAddr2();
138 Mac48Address to = hdr->GetAddr1();
139 if (GetWifiRemoteStationManager()->IsBrandNew(from))
140 {
141 // In ad hoc mode, we assume that every destination supports all the rates we support.
143 {
144 GetWifiRemoteStationManager()->AddAllSupportedMcs(from);
145 GetWifiRemoteStationManager()->AddStationHtCapabilities(
146 from,
148 }
150 {
151 GetWifiRemoteStationManager()->AddStationVhtCapabilities(
152 from,
154 }
155 if (GetHeSupported())
156 {
157 GetWifiRemoteStationManager()->AddStationHeCapabilities(
158 from,
160 }
161 if (GetEhtSupported())
162 {
163 GetWifiRemoteStationManager()->AddStationEhtCapabilities(
164 from,
166 }
167 GetWifiRemoteStationManager()->AddAllSupportedModes(from);
168 GetWifiRemoteStationManager()->RecordDisassociated(from);
169 }
170 if (hdr->IsData())
171 {
172 if (hdr->IsQosData() && hdr->IsQosAmsdu())
173 {
174 NS_LOG_DEBUG("Received A-MSDU from" << from);
176 }
177 else
178 {
179 ForwardUp(mpdu->GetPacket(), from, to);
180 }
181 return;
182 }
183
184 // Invoke the receive handler of our parent class to deal with any other frames
185 WifiMac::Receive(mpdu, linkId);
186}
187
188} // namespace ns3
Wifi MAC high model for an ad-hoc Wifi MAC.
void Enqueue(Ptr< WifiMpdu > mpdu, Mac48Address to, Mac48Address from) override
void DoCompleteConfig() override
Allow subclasses to complete the configuration of the MAC layer components.
~AdhocWifiMac() override
void Receive(Ptr< const WifiMpdu > mpdu, uint8_t linkId) override
This method acts as the MacRxMiddle receive callback and is invoked to notify us that a frame has bee...
static TypeId GetTypeId()
Get the type ID.
void SetLinkUpCallback(Callback< void > linkUp) override
bool CanForwardPacketsTo(Mac48Address to) const override
Return true if packets can be forwarded to the given destination, false otherwise.
Callback template class.
Definition callback.h:422
an EUI-48 address
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Implements the IEEE 802.11 MAC header.
base class for all MAC-level wifi objects.
Definition wifi-mac.h:90
Mac48Address GetBssid(uint8_t linkId) const
Definition wifi-mac.cc:547
Ptr< Txop > GetTxop() const
Accessor for the Txop object.
Definition wifi-mac.cc:572
VhtCapabilities GetVhtCapabilities(uint8_t linkId) const
Return the VHT capabilities of the device for the given link.
Definition wifi-mac.cc:2261
void SetTypeOfStation(TypeOfStation type)
This method is invoked by a subclass to specify what type of station it is implementing.
Definition wifi-mac.cc:484
bool GetEhtSupported() const
Return whether the device supports EHT.
Definition wifi-mac.cc:2013
bool GetHeSupported() const
Return whether the device supports HE.
Definition wifi-mac.cc:2007
HtCapabilities GetHtCapabilities(uint8_t linkId) const
Return the HT capabilities of the device for the given link.
Definition wifi-mac.cc:2202
bool GetVhtSupported(uint8_t linkId) const
Return whether the device supports VHT on the given link.
Definition wifi-mac.cc:1999
virtual void DeaggregateAmsduAndForward(Ptr< const WifiMpdu > mpdu)
This method can be called to de-aggregate an A-MSDU and forward the constituent packets up the stack.
Definition wifi-mac.cc:1846
He6GhzBandCapabilities GetHe6GhzBandCapabilities(uint8_t linkId) const
Return the HE 6GHz band capabilities of the device for the given 6 GHz link.
Definition wifi-mac.cc:2397
virtual void SetLinkUpCallback(Callback< void > linkUp)
Definition wifi-mac.cc:1478
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager(uint8_t linkId=0) const
Definition wifi-mac.cc:1079
bool GetHtSupported(uint8_t linkId) const
Return whether the device supports HT on the given link.
Definition wifi-mac.cc:1992
void ForwardUp(Ptr< const Packet > packet, Mac48Address from, Mac48Address to)
Forward the packet up to the device.
Definition wifi-mac.cc:1809
bool Is6GhzBand(uint8_t linkId) const
Indicate if a given link is on the 6 GHz band.
Definition wifi-mac.cc:1261
virtual void Receive(Ptr< const WifiMpdu > mpdu, uint8_t linkId)
This method acts as the MacRxMiddle receive callback and is invoked to notify us that a frame has bee...
Definition wifi-mac.cc:1816
Mac48Address GetAddress() const
Definition wifi-mac.cc:521
EhtCapabilities GetEhtCapabilities(uint8_t linkId) const
Return the EHT capabilities of the device for the given link.
Definition wifi-mac.cc:2432
HeCapabilities GetHeCapabilities(uint8_t linkId) const
Return the HE capabilities of the device for the given link.
Definition wifi-mac.cc:2341
Ptr< QosTxop > GetQosTxop(AcIndex ac) const
Accessor for a specified EDCA object.
Definition wifi-mac.cc:618
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
@ ADHOC_STA
Definition wifi-mac.h:61
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:272