A Discrete-Event Network Simulator
API
adhoc-wifi-mac.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2006, 2009 INRIA
4 * Copyright (c) 2009 MIRKO BANCHI
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20 * Mirko Banchi <mk.banchi@gmail.com>
21 */
22
23#include "ns3/log.h"
24#include "ns3/packet.h"
25#include "adhoc-wifi-mac.h"
26#include "qos-txop.h"
27#include "ns3/ht-capabilities.h"
28#include "ns3/vht-capabilities.h"
29#include "ns3/he-capabilities.h"
30#include "ns3/eht-capabilities.h"
31
32namespace ns3 {
33
34NS_LOG_COMPONENT_DEFINE ("AdhocWifiMac");
35
36NS_OBJECT_ENSURE_REGISTERED (AdhocWifiMac);
37
38TypeId
40{
41 static TypeId tid = TypeId ("ns3::AdhocWifiMac")
43 .SetGroupName ("Wifi")
44 .AddConstructor<AdhocWifiMac> ()
45 ;
46 return tid;
47}
48
50{
51 NS_LOG_FUNCTION (this);
52 //Let the lower layers know that we are acting in an IBSS
54}
55
57{
58 NS_LOG_FUNCTION (this);
59}
60
61bool
63{
64 return true;
65}
66
67void
69{
70 NS_LOG_FUNCTION (this << packet << to);
71 if (GetWifiRemoteStationManager ()->IsBrandNew (to))
72 {
73 //In ad hoc mode, we assume that every destination supports all the rates we support.
74 if (GetHtSupported ())
75 {
78 }
80 {
82 }
83 if (GetHeSupported ())
84 {
86 }
87 if (GetEhtSupported ())
88 {
90 }
93 }
94
95 WifiMacHeader hdr;
96
97 //If we are not a QoS STA then we definitely want to use AC_BE to
98 //transmit the packet. A TID of zero will map to AC_BE (through \c
99 //QosUtilsMapTidToAc()), so we use that as our default here.
100 uint8_t tid = 0;
101
102 //For now, a STA that supports QoS does not support non-QoS
103 //associations, and vice versa. In future the STA model should fall
104 //back to non-QoS if talking to a peer that is also non-QoS. At
105 //that point there will need to be per-station QoS state maintained
106 //by the association state machine, and consulted here.
107 if (GetQosSupported ())
108 {
111 hdr.SetQosNoEosp ();
112 hdr.SetQosNoAmsdu ();
113 //Transmission of multiple frames in the same TXOP is not
114 //supported for now
115 hdr.SetQosTxopLimit (0);
116
117 //Fill in the QoS control field in the MAC header
118 tid = QosUtilsGetTidForPacket (packet);
119 //Any value greater than 7 is invalid and likely indicates that
120 //the packet had no QoS tag, so we revert to zero, which will
121 //mean that AC_BE is used.
122 if (tid > 7)
123 {
124 tid = 0;
125 }
126 hdr.SetQosTid (tid);
127 }
128 else
129 {
131 }
132
133 if (GetHtSupported ())
134 {
135 hdr.SetNoOrder (); // explicitly set to 0 for the time being since HT control field is not yet implemented (set it to 1 when implemented)
136 }
137 hdr.SetAddr1 (to);
138 hdr.SetAddr2 (GetAddress ());
139 hdr.SetAddr3 (GetBssid (0));
140 hdr.SetDsNotFrom ();
141 hdr.SetDsNotTo ();
142
143 if (GetQosSupported ())
144 {
145 //Sanity check that the TID is valid
146 NS_ASSERT (tid < 8);
147 GetQosTxop (tid)->Queue (packet, hdr);
148 }
149 else
150 {
151 GetTxop ()->Queue (packet, hdr);
152 }
153}
154
155void
157{
158 NS_LOG_FUNCTION (this << &linkUp);
160
161 //The approach taken here is that, from the point of view of a STA
162 //in IBSS mode, the link is always up, so we immediately invoke the
163 //callback if one is set
164 linkUp ();
165}
166
167void
169{
170 NS_LOG_FUNCTION (this << *mpdu << +linkId);
171 const WifiMacHeader* hdr = &mpdu->GetHeader ();
172 NS_ASSERT (!hdr->IsCtl ());
173 Mac48Address from = hdr->GetAddr2 ();
174 Mac48Address to = hdr->GetAddr1 ();
175 if (GetWifiRemoteStationManager ()->IsBrandNew (from))
176 {
177 //In ad hoc mode, we assume that every destination supports all the rates we support.
178 if (GetHtSupported ())
179 {
182 }
184 {
186 }
187 if (GetHeSupported ())
188 {
190 }
191 if (GetEhtSupported ())
192 {
194 }
197 }
198 if (hdr->IsData ())
199 {
200 if (hdr->IsQosData () && hdr->IsQosAmsdu ())
201 {
202 NS_LOG_DEBUG ("Received A-MSDU from" << from);
204 }
205 else
206 {
207 ForwardUp (mpdu->GetPacket ()->Copy (), from, to);
208 }
209 return;
210 }
211
212 //Invoke the receive handler of our parent class to deal with any
213 //other frames. Specifically, this will handle Block Ack-related
214 //Management Action frames.
215 WifiMac::Receive (mpdu, linkId);
216}
217
218} //namespace ns3
Wifi MAC high model for an ad-hoc Wifi MAC.
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...
virtual ~AdhocWifiMac()
void SetLinkUpCallback(Callback< void > linkUp) override
static TypeId GetTypeId(void)
Get the type ID.
bool CanForwardPacketsTo(Mac48Address to) const override
Return true if packets can be forwarded to the given destination, false otherwise.
void Enqueue(Ptr< Packet > packet, Mac48Address to) override
an EUI-48 address
Definition: mac48-address.h:44
virtual void Queue(Ptr< Packet > packet, const WifiMacHeader &hdr)
Definition: txop.cc:487
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Implements the IEEE 802.11 MAC header.
void SetDsNotFrom(void)
Un-set the From DS bit in the Frame Control field.
bool IsCtl(void) const
Return true if the Type is Control.
void SetQosAckPolicy(QosAckPolicy policy)
Set the QoS Ack policy in the QoS control field.
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data.
void SetQosTxopLimit(uint8_t txop)
Set TXOP limit in the QoS control field.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
void SetQosNoEosp()
Un-set the end of service period (EOSP) bit in the QoS control field.
void SetDsNotTo(void)
Un-set the To DS bit in the Frame Control field.
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
void SetNoOrder(void)
Unset order bit in the frame control field.
void SetQosNoAmsdu(void)
Set that A-MSDU is not present.
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
bool IsData(void) const
Return true if the Type is DATA.
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
base class for all MAC-level wifi objects.
Definition: wifi-mac.h:91
Mac48Address GetBssid(uint8_t linkId) const
Definition: wifi-mac.cc:438
VhtCapabilities GetVhtCapabilities(uint8_t linkId) const
Return the VHT capabilities of the device for the given link.
Definition: wifi-mac.cc:1383
bool GetQosSupported() const
Return whether the device supports QoS.
Definition: wifi-mac.cc:961
Mac48Address GetAddress(void) const
Definition: wifi-mac.cc:412
bool GetHtSupported() const
Return whether the device supports HT.
Definition: wifi-mac.cc:1211
void SetTypeOfStation(TypeOfStation type)
This method is invoked by a subclass to specify what type of station it is implementing.
Definition: wifi-mac.cc:380
bool GetEhtSupported() const
Return whether the device supports EHT.
Definition: wifi-mac.cc:1230
bool GetHeSupported() const
Return whether the device supports HE.
Definition: wifi-mac.cc:1224
HtCapabilities GetHtCapabilities(uint8_t linkId) const
Return the HT capabilities of the device for the given link.
Definition: wifi-mac.cc:1327
bool GetVhtSupported(uint8_t linkId) const
Return whether the device supports VHT on the given link.
Definition: wifi-mac.cc:1217
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:1176
virtual void SetLinkUpCallback(Callback< void > linkUp)
Definition: wifi-mac.cc:1030
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager(uint8_t linkId=0) const
Definition: wifi-mac.cc:834
void ForwardUp(Ptr< const Packet > packet, Mac48Address from, Mac48Address to)
Forward the packet up to the device.
Definition: wifi-mac.cc:1055
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:1062
EhtCapabilities GetEhtCapabilities(uint8_t linkId) const
Return the EHT capabilities of the device for the given link.
Definition: wifi-mac.cc:1515
HeCapabilities GetHeCapabilities(uint8_t linkId) const
Return the HE capabilities of the device for the given link.
Definition: wifi-mac.cc:1461
Ptr< QosTxop > GetQosTxop(AcIndex ac) const
Accessor for a specified EDCA object.
Definition: wifi-mac.cc:459
Ptr< Txop > GetTxop(void) const
Accessor for the Txop object.
Definition: wifi-mac.cc:453
void AddAllSupportedMcs(Mac48Address address)
Invoked in a STA or AP to store all of the MCS supported by a destination which is also supported loc...
void AddAllSupportedModes(Mac48Address address)
Invoked in a STA or AP to store all of the modes supported by a destination which is also supported l...
void AddStationVhtCapabilities(Mac48Address from, VhtCapabilities vhtCapabilities)
Records VHT capabilities of the remote station.
void AddStationHeCapabilities(Mac48Address from, HeCapabilities heCapabilities)
Records HE capabilities of the remote station.
void AddStationEhtCapabilities(Mac48Address from, EhtCapabilities ehtCapabilities)
Records EHT capabilities of the remote station.
void RecordDisassociated(Mac48Address address)
Records that the STA was disassociated.
void AddStationHtCapabilities(Mac48Address from, HtCapabilities htCapabilities)
Records HT capabilities of the remote station.
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:206
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:274
#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
uint8_t QosUtilsGetTidForPacket(Ptr< const Packet > packet)
If a QoS tag is attached to the packet, returns a value < 8.
Definition: qos-utils.cc:152
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ ADHOC_STA
Definition: wifi-mac.h:61
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
@ WIFI_MAC_DATA
@ WIFI_MAC_QOSDATA