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 
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")
41  .SetParent<WifiMac> ()
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 bool
76 {
77  return true;
78 }
79 
80 void
82 {
83  NS_LOG_FUNCTION (this << packet << to);
84  if (GetWifiRemoteStationManager ()->IsBrandNew (to))
85  {
86  //In ad hoc mode, we assume that every destination supports all the rates we support.
87  if (GetHtSupported ())
88  {
91  }
92  if (GetVhtSupported ())
93  {
95  }
96  if (GetHeSupported ())
97  {
99  }
102  }
103 
104  WifiMacHeader hdr;
105 
106  //If we are not a QoS STA then we definitely want to use AC_BE to
107  //transmit the packet. A TID of zero will map to AC_BE (through \c
108  //QosUtilsMapTidToAc()), so we use that as our default here.
109  uint8_t tid = 0;
110 
111  //For now, a STA that supports QoS does not support non-QoS
112  //associations, and vice versa. In future the STA model should fall
113  //back to non-QoS if talking to a peer that is also non-QoS. At
114  //that point there will need to be per-station QoS state maintained
115  //by the association state machine, and consulted here.
116  if (GetQosSupported ())
117  {
120  hdr.SetQosNoEosp ();
121  hdr.SetQosNoAmsdu ();
122  //Transmission of multiple frames in the same TXOP is not
123  //supported for now
124  hdr.SetQosTxopLimit (0);
125 
126  //Fill in the QoS control field in the MAC header
127  tid = QosUtilsGetTidForPacket (packet);
128  //Any value greater than 7 is invalid and likely indicates that
129  //the packet had no QoS tag, so we revert to zero, which will
130  //mean that AC_BE is used.
131  if (tid > 7)
132  {
133  tid = 0;
134  }
135  hdr.SetQosTid (tid);
136  }
137  else
138  {
139  hdr.SetType (WIFI_MAC_DATA);
140  }
141 
142  if (GetHtSupported ())
143  {
144  hdr.SetNoOrder (); // explicitly set to 0 for the time being since HT control field is not yet implemented (set it to 1 when implemented)
145  }
146  hdr.SetAddr1 (to);
147  hdr.SetAddr2 (GetAddress ());
148  hdr.SetAddr3 (GetBssid ());
149  hdr.SetDsNotFrom ();
150  hdr.SetDsNotTo ();
151 
152  if (GetQosSupported ())
153  {
154  //Sanity check that the TID is valid
155  NS_ASSERT (tid < 8);
156  GetQosTxop (tid)->Queue (packet, hdr);
157  }
158  else
159  {
160  GetTxop ()->Queue (packet, hdr);
161  }
162 }
163 
164 void
166 {
167  NS_LOG_FUNCTION (this << &linkUp);
169 
170  //The approach taken here is that, from the point of view of a STA
171  //in IBSS mode, the link is always up, so we immediately invoke the
172  //callback if one is set
173  linkUp ();
174 }
175 
176 void
178 {
179  NS_LOG_FUNCTION (this << *mpdu);
180  const WifiMacHeader* hdr = &mpdu->GetHeader ();
181  NS_ASSERT (!hdr->IsCtl ());
182  Mac48Address from = hdr->GetAddr2 ();
183  Mac48Address to = hdr->GetAddr1 ();
184  if (GetWifiRemoteStationManager ()->IsBrandNew (from))
185  {
186  //In ad hoc mode, we assume that every destination supports all the rates we support.
187  if (GetHtSupported ())
188  {
191  }
192  if (GetVhtSupported ())
193  {
195  }
196  if (GetHeSupported ())
197  {
199  }
202  }
203  if (hdr->IsData ())
204  {
205  if (hdr->IsQosData () && hdr->IsQosAmsdu ())
206  {
207  NS_LOG_DEBUG ("Received A-MSDU from" << from);
209  }
210  else
211  {
212  ForwardUp (mpdu->GetPacket ()->Copy (), from, to);
213  }
214  return;
215  }
216 
217  //Invoke the receive handler of our parent class to deal with any
218  //other frames. Specifically, this will handle Block Ack-related
219  //Management Action frames.
220  WifiMac::Receive (mpdu);
221 }
222 
223 } //namespace ns3
Wifi MAC high model for an ad-hoc Wifi MAC.
void Receive(Ptr< WifiMacQueueItem > mpdu) override
This method acts as the MacRxMiddle receive callback and is invoked to notify us that a frame has bee...
void SetAddress(Mac48Address address) override
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:294
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:85
bool GetVhtSupported() const
Return whether the device supports VHT.
Definition: wifi-mac.cc:1075
bool GetQosSupported() const
Return whether the device supports QoS.
Definition: wifi-mac.cc:822
virtual void SetAddress(Mac48Address address)
Definition: wifi-mac.cc:396
HeCapabilities GetHeCapabilities(void) const
Return the HE capabilities of the device.
Definition: wifi-mac.cc:1325
Mac48Address GetAddress(void) const
Definition: wifi-mac.cc:403
bool GetHtSupported() const
Return whether the device supports HT.
Definition: wifi-mac.cc:1065
void SetTypeOfStation(TypeOfStation type)
This method is invoked by a subclass to specify what type of station it is implementing.
Definition: wifi-mac.cc:371
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager(void) const
Definition: wifi-mac.cc:757
Mac48Address GetBssid(void) const
Definition: wifi-mac.cc:433
bool GetHeSupported() const
Return whether the device supports HE.
Definition: wifi-mac.cc:1085
virtual void Receive(Ptr< WifiMacQueueItem > mpdu)
This method acts as the MacRxMiddle receive callback and is invoked to notify us that a frame has bee...
Definition: wifi-mac.cc:923
virtual void DeaggregateAmsduAndForward(Ptr< WifiMacQueueItem > mpdu)
This method can be called to de-aggregate an A-MSDU and forward the constituent packets up the stack.
Definition: wifi-mac.cc:1036
virtual void SetLinkUpCallback(Callback< void > linkUp)
Definition: wifi-mac.cc:891
void ForwardUp(Ptr< const Packet > packet, Mac48Address from, Mac48Address to)
Forward the packet up to the device.
Definition: wifi-mac.cc:916
VhtCapabilities GetVhtCapabilities(void) const
Return the VHT capabilities of the device.
Definition: wifi-mac.cc:1242
HtCapabilities GetHtCapabilities(void) const
Return the HT capabilities of the device.
Definition: wifi-mac.cc:1186
Ptr< QosTxop > GetQosTxop(AcIndex ac) const
Accessor for a specified EDCA object.
Definition: wifi-mac.cc:452
void SetBssid(Mac48Address bssid)
Definition: wifi-mac.cc:422
Ptr< Txop > GetTxop(void) const
Accessor for the Txop object.
Definition: wifi-mac.cc:446
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 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:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ ADHOC_STA
Definition: wifi-mac.h:55
@ WIFI_MAC_DATA
@ WIFI_MAC_QOSDATA