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 "adhoc-wifi-mac.h"
24 #include "ns3/pointer.h"
25 #include "ns3/log.h"
26 #include "ns3/string.h"
27 #include "ns3/boolean.h"
28 #include "ns3/trace-source-accessor.h"
29 #include "mac-low.h"
30 #include "dcf-manager.h"
31 #include "mac-rx-middle.h"
32 #include "mac-tx-middle.h"
33 #include "msdu-aggregator.h"
34 #include "amsdu-subframe-header.h"
35 #include "mgt-headers.h"
36 
37 namespace ns3 {
38 
39 NS_LOG_COMPONENT_DEFINE ("AdhocWifiMac");
40 
41 NS_OBJECT_ENSURE_REGISTERED (AdhocWifiMac);
42 
43 TypeId
45 {
46  static TypeId tid = TypeId ("ns3::AdhocWifiMac")
48  .SetGroupName ("Wifi")
49  .AddConstructor<AdhocWifiMac> ()
50  ;
51  return tid;
52 }
53 
55 {
56  NS_LOG_FUNCTION (this);
57  //Let the lower layers know that we are acting in an IBSS
59 }
60 
62 {
63  NS_LOG_FUNCTION (this);
64 }
65 
66 void
68 {
69  NS_LOG_FUNCTION (this << address);
70  //In an IBSS, the BSSID is supposed to be generated per Section
71  //11.1.3 of IEEE 802.11. We don't currently do this - instead we
72  //make an IBSS STA a bit like an AP, with the BSSID for frames
73  //transmitted by each STA set to that STA's address.
74  //
75  //This is why we're overriding this method.
77  RegularWifiMac::SetBssid (address);
78 }
79 
80 void
82 {
83  NS_LOG_FUNCTION (this << packet << to);
84  if (m_stationManager->IsBrandNew (to))
85  {
86  //In ad hoc mode, we assume that every destination supports all
87  //the rates we support.
89  {
92  }
93  if (m_vhtSupported)
94  {
96  }
99  }
100 
101  WifiMacHeader hdr;
102 
103  //If we are not a QoS STA then we definitely want to use AC_BE to
104  //transmit the packet. A TID of zero will map to AC_BE (through \c
105  //QosUtilsMapTidToAc()), so we use that as our default here.
106  uint8_t tid = 0;
107 
108  //For now, a STA that supports QoS does not support non-QoS
109  //associations, and vice versa. In future the STA model should fall
110  //back to non-QoS if talking to a peer that is also non-QoS. At
111  //that point there will need to be per-station QoS state maintained
112  //by the association state machine, and consulted here.
113  if (m_qosSupported)
114  {
117  hdr.SetQosNoEosp ();
118  hdr.SetQosNoAmsdu ();
119  //Transmission of multiple frames in the same TXOP is not
120  //supported for now
121  hdr.SetQosTxopLimit (0);
122 
123  //Fill in the QoS control field in the MAC header
124  tid = QosUtilsGetTidForPacket (packet);
125  //Any value greater than 7 is invalid and likely indicates that
126  //the packet had no QoS tag, so we revert to zero, which will
127  //mean that AC_BE is used.
128  if (tid > 7)
129  {
130  tid = 0;
131  }
132  hdr.SetQosTid (tid);
133  }
134  else
135  {
136  hdr.SetTypeData ();
137  }
138 
140  {
141  hdr.SetNoOrder ();
142  }
143  hdr.SetAddr1 (to);
144  hdr.SetAddr2 (m_low->GetAddress ());
145  hdr.SetAddr3 (GetBssid ());
146  hdr.SetDsNotFrom ();
147  hdr.SetDsNotTo ();
148 
149  if (m_qosSupported)
150  {
151  //Sanity check that the TID is valid
152  NS_ASSERT (tid < 8);
153  m_edca[QosUtilsMapTidToAc (tid)]->Queue (packet, hdr);
154  }
155  else
156  {
157  m_dca->Queue (packet, hdr);
158  }
159 }
160 
161 void
163 {
164  NS_LOG_FUNCTION (this << &linkUp);
166 
167  //The approach taken here is that, from the point of view of a STA
168  //in IBSS mode, the link is always up, so we immediately invoke the
169  //callback if one is set
170  linkUp ();
171 }
172 
173 void
175 {
176  NS_LOG_FUNCTION (this << packet << hdr);
177  NS_ASSERT (!hdr->IsCtl ());
178  Mac48Address from = hdr->GetAddr2 ();
179  Mac48Address to = hdr->GetAddr1 ();
180  if (m_stationManager->IsBrandNew (from))
181  {
182  //In ad hoc mode, we assume that every destination supports all
183  //the rates we support.
185  {
188  }
189  if (m_vhtSupported)
190  {
192  }
195  }
196  if (hdr->IsData ())
197  {
198  if (hdr->IsQosData () && hdr->IsQosAmsdu ())
199  {
200  NS_LOG_DEBUG ("Received A-MSDU from" << from);
201  DeaggregateAmsduAndForward (packet, hdr);
202  }
203  else
204  {
205  ForwardUp (packet, from, to);
206  }
207  return;
208  }
209 
210  //Invoke the receive handler of our parent class to deal with any
211  //other frames. Specifically, this will handle Block Ack-related
212  //Management Action frames.
213  RegularWifiMac::Receive (packet, hdr);
214 }
215 
216 } //namespace ns3
virtual 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 "...
void SetQosAckPolicy(enum QosAckPolicy policy)
Set the QoS ACK policy in the QoS control field.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
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...
virtual 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.
#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:201
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...
bool IsCtl(void) const
Return true if the Type is Control.
bool IsBrandNew(Mac48Address address) const
Return whether the station state is brand new.
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
VhtCapabilities GetVhtCapabilities(void) const
Return the VHT capability of the device.
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...
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...
uint8_t QosUtilsGetTidForPacket(Ptr< const Packet > packet)
If a qos tag is attached to the packet, returns a value < 8.
Definition: qos-utils.cc:62
void RecordDisassociated(Mac48Address address)
Records that the STA was disassociated.
virtual 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.
bool m_qosSupported
This Boolean is set true iff this WifiMac is to model 802.11e/WMM style Quality of Service...
virtual 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.
Ptr< DcaTxop > m_dca
This holds a pointer to the DCF instance for this WifiMac - used for transmission of frames to non-Qo...
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
void AddStationHtCapabilities(Mac48Address from, HtCapabilities htcapabilities)
Records HT capabilities of the remote station.
bool m_vhtSupported
This Boolean is set true iff this WifiMac is to model 802.11ac.
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:28
virtual void SetAddress(Mac48Address address)
Mac48Address GetAddress(void) const
Return the MAC address of this MacLow.
Definition: mac-low.cc:627
static TypeId GetTypeId(void)
Ptr< MacLow > m_low
MacLow (RTS, CTS, DATA, ACK etc.)
HtCapabilities GetHtCapabilities(void) const
Return the HT capability of the device.
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
virtual void SetLinkUpCallback(Callback< void > linkUp)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
an EUI-48 address
Definition: mac48-address.h:43
bool m_htSupported
This Boolean is set true iff this WifiMac is to model 802.11n.
virtual Mac48Address GetBssid(void) const
void SetQosTxopLimit(uint8_t txop)
Set TXOP limit in the QoS control field.
bool IsData(void) const
Return true if the Type is DATA.
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS DATA...
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
void SetTypeData(void)
Set Type/Subtype values for a data packet with no subtype equal to 0.
void SetQosNoAmsdu(void)
Set that A-MSDU is not present.
virtual ~AdhocWifiMac()
void SetNoOrder(void)
Unset order bit in the frame control field.
void SetType(enum WifiMacType type)
Set Type/Subtype values with the correct values depending on the given type.
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
tuple address
Definition: first.py:37
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...
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
void AddStationVhtCapabilities(Mac48Address from, VhtCapabilities vhtcapabilities)
Records VHT capabilities of the remote station.
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
void SetDsNotFrom(void)
Un-set the From DS bit in the Frame Control field.