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 "ht-capabilities.h"
27 #include "vht-capabilities.h"
28 #include "he-capabilities.h"
29 #include "mac-low.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("AdhocWifiMac");
34 
35 NS_OBJECT_ENSURE_REGISTERED (AdhocWifiMac);
36 
37 TypeId
39 {
40  static TypeId tid = TypeId ("ns3::AdhocWifiMac")
42  .SetGroupName ("Wifi")
43  .AddConstructor<AdhocWifiMac> ()
44  ;
45  return tid;
46 }
47 
49 {
50  NS_LOG_FUNCTION (this);
51  //Let the lower layers know that we are acting in an IBSS
53 }
54 
56 {
57  NS_LOG_FUNCTION (this);
58 }
59 
60 void
62 {
63  NS_LOG_FUNCTION (this << address);
64  //In an IBSS, the BSSID is supposed to be generated per Section
65  //11.1.3 of IEEE 802.11. We don't currently do this - instead we
66  //make an IBSS STA a bit like an AP, with the BSSID for frames
67  //transmitted by each STA set to that STA's address.
68  //
69  //This is why we're overriding this method.
72 }
73 
74 void
76 {
77  NS_LOG_FUNCTION (this << packet << to);
78  if (m_stationManager->IsBrandNew (to))
79  {
80  //In ad hoc mode, we assume that every destination supports all
81  //the rates we support.
83  {
85  }
86  if (GetHtSupported ())
87  {
89  }
90  if (GetVhtSupported ())
91  {
93  }
94  if (GetHeSupported ())
95  {
97  }
100  }
101 
102  WifiMacHeader hdr;
103 
104  //If we are not a QoS STA then we definitely want to use AC_BE to
105  //transmit the packet. A TID of zero will map to AC_BE (through \c
106  //QosUtilsMapTidToAc()), so we use that as our default here.
107  uint8_t tid = 0;
108 
109  //For now, a STA that supports QoS does not support non-QoS
110  //associations, and vice versa. In future the STA model should fall
111  //back to non-QoS if talking to a peer that is also non-QoS. At
112  //that point there will need to be per-station QoS state maintained
113  //by the association state machine, and consulted here.
114  if (GetQosSupported ())
115  {
118  hdr.SetQosNoEosp ();
119  hdr.SetQosNoAmsdu ();
120  //Transmission of multiple frames in the same TXOP is not
121  //supported for now
122  hdr.SetQosTxopLimit (0);
123 
124  //Fill in the QoS control field in the MAC header
125  tid = QosUtilsGetTidForPacket (packet);
126  //Any value greater than 7 is invalid and likely indicates that
127  //the packet had no QoS tag, so we revert to zero, which will
128  //mean that AC_BE is used.
129  if (tid > 7)
130  {
131  tid = 0;
132  }
133  hdr.SetQosTid (tid);
134  }
135  else
136  {
137  hdr.SetType (WIFI_MAC_DATA);
138  }
139 
140  if (GetHtSupported () || GetVhtSupported () || GetHeSupported ())
141  {
142  hdr.SetNoOrder (); // explicitly set to 0 for the time being since HT/VHT/HE control field is not yet implemented (set it to 1 when implemented)
143  }
144  hdr.SetAddr1 (to);
145  hdr.SetAddr2 (m_low->GetAddress ());
146  hdr.SetAddr3 (GetBssid ());
147  hdr.SetDsNotFrom ();
148  hdr.SetDsNotTo ();
149 
150  if (GetQosSupported ())
151  {
152  //Sanity check that the TID is valid
153  NS_ASSERT (tid < 8);
154  m_edca[QosUtilsMapTidToAc (tid)]->Queue (packet, hdr);
155  }
156  else
157  {
158  m_txop->Queue (packet, hdr);
159  }
160 }
161 
162 void
164 {
165  NS_LOG_FUNCTION (this << &linkUp);
167 
168  //The approach taken here is that, from the point of view of a STA
169  //in IBSS mode, the link is always up, so we immediately invoke the
170  //callback if one is set
171  linkUp ();
172 }
173 
174 void
176 {
177  NS_LOG_FUNCTION (this << packet << hdr);
178  NS_ASSERT (!hdr->IsCtl ());
179  Mac48Address from = hdr->GetAddr2 ();
180  Mac48Address to = hdr->GetAddr1 ();
181  if (m_stationManager->IsBrandNew (from))
182  {
183  //In ad hoc mode, we assume that every destination supports all
184  //the rates we support.
185  if (GetHtSupported () || GetVhtSupported () || GetHeSupported ())
186  {
189  }
190  if (GetHtSupported ())
191  {
193  }
194  if (GetVhtSupported ())
195  {
197  }
198  if (GetHeSupported ())
199  {
201  }
204  }
205  if (hdr->IsData ())
206  {
207  if (hdr->IsQosData () && hdr->IsQosAmsdu ())
208  {
209  NS_LOG_DEBUG ("Received A-MSDU from" << from);
210  DeaggregateAmsduAndForward (packet, hdr);
211  }
212  else
213  {
214  ForwardUp (packet, from, to);
215  }
216  return;
217  }
218 
219  //Invoke the receive handler of our parent class to deal with any
220  //other frames. Specifically, this will handle Block Ack-related
221  //Management Action frames.
222  RegularWifiMac::Receive (packet, hdr);
223 }
224 
225 } //namespace ns3
void SetLinkUpCallback(Callback< void > linkUp)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
bool GetHeSupported() const
Return whether the device supports HE.
Ptr< Txop > m_txop
This holds a pointer to the TXOP instance for this WifiMac - used for transmission of frames to non-Q...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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...
bool IsCtl(void) const
Return true if the Type is Control.
bool GetQosSupported() const
Return whether the device supports QoS.
void Enqueue(Ptr< const Packet > packet, Mac48Address to)
EdcaQueues m_edca
This is a map from Access Category index to the corresponding channel access function.
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
#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:204
virtual void DeaggregateAmsduAndForward(Ptr< Packet > aggregatedPacket, const WifiMacHeader *hdr)
This method can be called to de-aggregate an A-MSDU and forward the constituent packets up the stack...
virtual void Receive(Ptr< Packet > packet, const WifiMacHeader *hdr)
This method acts as the MacRxMiddle receive callback and is invoked to notify us that a frame has bee...
void Receive(Ptr< Packet > packet, const WifiMacHeader *hdr)
This method acts as the MacRxMiddle receive callback and is invoked to notify us that a frame has bee...
uint8_t QosUtilsGetTidForPacket(Ptr< const Packet > packet)
If a qos tag is attached to the packet, returns a value < 8.
Definition: qos-utils.cc:58
void RecordDisassociated(Mac48Address address)
Records that the STA was disassociated.
void SetBssid(Mac48Address bssid)
void ForwardUp(Ptr< Packet > packet, Mac48Address from, Mac48Address to)
Forward the packet up to the device.
base class for all MAC-level wifi objects.
void SetAddress(Mac48Address address)
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
void SetTypeOfStation(TypeOfStation type)
This method is invoked by a subclass to specify what type of station it is implementing.
void SetDsNotTo(void)
Un-set the To DS bit in the Frame Control field.
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
bool GetVhtSupported() const
Return whether the device supports VHT.
void AddStationHtCapabilities(Mac48Address from, HtCapabilities htcapabilities)
Records HT capabilities of the remote station.
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:32
void SetAddress(Mac48Address address)
Mac48Address GetBssid(void) const
HeCapabilities GetHeCapabilities(void) const
Return the HE capabilities of the device.
static TypeId GetTypeId(void)
Get the type ID.
void AddStationHeCapabilities(Mac48Address from, HeCapabilities hecapabilities)
Records HE capabilities of the remote station.
Ptr< MacLow > m_low
MacLow (RTS, CTS, DATA, ACK etc.)
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
void SetLinkUpCallback(Callback< void > linkUp)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool IsData(void) const
Return true if the Type is DATA.
address
Definition: first.py:37
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
an EUI-48 address
Definition: mac48-address.h:43
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
void SetQosTxopLimit(uint8_t txop)
Set TXOP limit in the QoS control field.
virtual void Queue(Ptr< const Packet > packet, const WifiMacHeader &hdr)
Definition: txop.cc:308
bool GetHtSupported() const
Return whether the device supports HT.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:272
void SetQosNoAmsdu(void)
Set that A-MSDU is not present.
virtual ~AdhocWifiMac()
void SetNoOrder(void)
Unset order bit in the frame control field.
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS DATA...
Ptr< WifiRemoteStationManager > m_stationManager
Remote station manager (rate control, RTS/CTS/fragmentation thresholds etc.)
void SetQosNoEosp()
Un-set the end of service period (EOSP) bit in the QoS control field.
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...
VhtCapabilities GetVhtCapabilities(void) const
Return the VHT capabilities of the device.
bool IsBrandNew(Mac48Address address) const
Return whether the station state is brand new.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void AddStationVhtCapabilities(Mac48Address from, VhtCapabilities vhtcapabilities)
Records VHT capabilities of the remote station.
Implements the IEEE 802.11 MAC header.
HtCapabilities GetHtCapabilities(void) const
Return the HT capabilities of the device.
void SetDsNotFrom(void)
Un-set the From DS bit in the Frame Control field.
void SetQosAckPolicy(QosAckPolicy policy)
Set the QoS ACK policy in the QoS control field.