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 "ns3/ht-capabilities.h"
27 #include "ns3/vht-capabilities.h"
28 #include "ns3/he-capabilities.h"
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("AdhocWifiMac");
33 
34 NS_OBJECT_ENSURE_REGISTERED (AdhocWifiMac);
35 
36 TypeId
38 {
39  static TypeId tid = TypeId ("ns3::AdhocWifiMac")
41  .SetGroupName ("Wifi")
42  .AddConstructor<AdhocWifiMac> ()
43  ;
44  return tid;
45 }
46 
48 {
49  NS_LOG_FUNCTION (this);
50  //Let the lower layers know that we are acting in an IBSS
52 }
53 
55 {
56  NS_LOG_FUNCTION (this);
57 }
58 
59 void
61 {
62  NS_LOG_FUNCTION (this << address);
63  //In an IBSS, the BSSID is supposed to be generated per Section
64  //11.1.3 of IEEE 802.11. We don't currently do this - instead we
65  //make an IBSS STA a bit like an AP, with the BSSID for frames
66  //transmitted by each STA set to that STA's address.
67  //
68  //This is why we're overriding this method.
71 }
72 
73 void
75 {
76  NS_LOG_FUNCTION (this << packet << to);
77  if (m_stationManager->IsBrandNew (to))
78  {
79  //In ad hoc mode, we assume that every destination supports all the rates we support.
80  if (GetHtSupported ())
81  {
84  }
85  if (GetVhtSupported ())
86  {
88  }
89  if (GetHeSupported ())
90  {
92  }
95  }
96 
97  WifiMacHeader hdr;
98 
99  //If we are not a QoS STA then we definitely want to use AC_BE to
100  //transmit the packet. A TID of zero will map to AC_BE (through \c
101  //QosUtilsMapTidToAc()), so we use that as our default here.
102  uint8_t tid = 0;
103 
104  //For now, a STA that supports QoS does not support non-QoS
105  //associations, and vice versa. In future the STA model should fall
106  //back to non-QoS if talking to a peer that is also non-QoS. At
107  //that point there will need to be per-station QoS state maintained
108  //by the association state machine, and consulted here.
109  if (GetQosSupported ())
110  {
113  hdr.SetQosNoEosp ();
114  hdr.SetQosNoAmsdu ();
115  //Transmission of multiple frames in the same TXOP is not
116  //supported for now
117  hdr.SetQosTxopLimit (0);
118 
119  //Fill in the QoS control field in the MAC header
120  tid = QosUtilsGetTidForPacket (packet);
121  //Any value greater than 7 is invalid and likely indicates that
122  //the packet had no QoS tag, so we revert to zero, which will
123  //mean that AC_BE is used.
124  if (tid > 7)
125  {
126  tid = 0;
127  }
128  hdr.SetQosTid (tid);
129  }
130  else
131  {
132  hdr.SetType (WIFI_MAC_DATA);
133  }
134 
135  if (GetHtSupported ())
136  {
137  hdr.SetNoOrder (); // explicitly set to 0 for the time being since HT control field is not yet implemented (set it to 1 when implemented)
138  }
139  hdr.SetAddr1 (to);
140  hdr.SetAddr2 (GetAddress ());
141  hdr.SetAddr3 (GetBssid ());
142  hdr.SetDsNotFrom ();
143  hdr.SetDsNotTo ();
144 
145  if (GetQosSupported ())
146  {
147  //Sanity check that the TID is valid
148  NS_ASSERT (tid < 8);
149  m_edca[QosUtilsMapTidToAc (tid)]->Queue (packet, hdr);
150  }
151  else
152  {
153  m_txop->Queue (packet, hdr);
154  }
155 }
156 
157 void
159 {
160  NS_LOG_FUNCTION (this << &linkUp);
162 
163  //The approach taken here is that, from the point of view of a STA
164  //in IBSS mode, the link is always up, so we immediately invoke the
165  //callback if one is set
166  linkUp ();
167 }
168 
169 void
171 {
172  NS_LOG_FUNCTION (this << *mpdu);
173  const WifiMacHeader* hdr = &mpdu->GetHeader ();
174  NS_ASSERT (!hdr->IsCtl ());
175  Mac48Address from = hdr->GetAddr2 ();
176  Mac48Address to = hdr->GetAddr1 ();
177  if (m_stationManager->IsBrandNew (from))
178  {
179  //In ad hoc mode, we assume that every destination supports all the rates we support.
180  if (GetHtSupported ())
181  {
184  }
185  if (GetVhtSupported ())
186  {
188  }
189  if (GetHeSupported ())
190  {
192  }
195  }
196  if (hdr->IsData ())
197  {
198  if (hdr->IsQosData () && hdr->IsQosAmsdu ())
199  {
200  NS_LOG_DEBUG ("Received A-MSDU from" << from);
202  }
203  else
204  {
205  ForwardUp (mpdu->GetPacket ()->Copy (), 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.
214 }
215 
216 } //namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::WifiMacHeader::SetQosNoEosp
void SetQosNoEosp()
Un-set the end of service period (EOSP) bit in the QoS control field.
Definition: wifi-mac-header.cc:362
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT
#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
ns3::WifiMacQueueItem::GetPacket
Ptr< const Packet > GetPacket(void) const
Get the packet stored in this item.
Definition: wifi-mac-queue-item.cc:57
ns3::WifiRemoteStationManager::AddStationHeCapabilities
void AddStationHeCapabilities(Mac48Address from, HeCapabilities heCapabilities)
Records HE capabilities of the remote station.
Definition: wifi-remote-station-manager.cc:1361
ns3::AdhocWifiMac::SetLinkUpCallback
void SetLinkUpCallback(Callback< void > linkUp) override
Definition: adhoc-wifi-mac.cc:158
ns3::WifiMacHeader::IsData
bool IsData(void) const
Return true if the Type is DATA.
Definition: wifi-mac-header.cc:558
ns3::Callback< void >
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::AdhocWifiMac::Receive
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...
Definition: adhoc-wifi-mac.cc:170
ns3::RegularWifiMac::SetBssid
void SetBssid(Mac48Address bssid)
Definition: regular-wifi-mac.cc:691
ns3::RegularWifiMac::GetHeSupported
bool GetHeSupported() const
Return whether the device supports HE.
Definition: regular-wifi-mac.cc:618
ns3::WifiMacHeader::SetDsNotFrom
void SetDsNotFrom(void)
Un-set the From DS bit in the Frame Control field.
Definition: wifi-mac-header.cc:90
ns3::AdhocWifiMac
Wifi MAC high model for an ad-hoc Wifi MAC.
Definition: adhoc-wifi-mac.h:36
ns3::AdhocWifiMac::SetAddress
void SetAddress(Mac48Address address) override
Definition: adhoc-wifi-mac.cc:60
ns3::RegularWifiMac::GetBssid
Mac48Address GetBssid(void) const override
Definition: regular-wifi-mac.cc:702
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
ns3::ADHOC_STA
@ ADHOC_STA
Definition: wifi-mac.h:44
ns3::WifiMacHeader::GetAddr1
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
Definition: wifi-mac-header.cc:424
ns3::WifiMacHeader::SetAddr3
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
Definition: wifi-mac-header.cc:120
ns3::RegularWifiMac::SetLinkUpCallback
void SetLinkUpCallback(Callback< void > linkUp) override
Definition: regular-wifi-mac.cc:571
ns3::RegularWifiMac
base class for all MAC-level wifi objects.
Definition: regular-wifi-mac.h:51
ns3::WifiMacQueueItem::GetHeader
const WifiMacHeader & GetHeader(void) const
Get the header stored in this item.
Definition: wifi-mac-queue-item.cc:63
ns3::RegularWifiMac::DeaggregateAmsduAndForward
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: regular-wifi-mac.cc:863
ns3::WifiRemoteStationManager::AddAllSupportedModes
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...
Definition: wifi-remote-station-manager.cc:364
ns3::RegularWifiMac::GetQosSupported
bool GetQosSupported() const
Return whether the device supports QoS.
Definition: regular-wifi-mac.cc:592
ns3::WifiRemoteStationManager::AddAllSupportedMcs
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...
Definition: wifi-remote-station-manager.cc:381
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::WifiMacHeader::SetAddr1
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
Definition: wifi-mac-header.cc:108
ns3::RegularWifiMac::GetAddress
Mac48Address GetAddress(void) const override
Definition: regular-wifi-mac.cc:672
ns3::WifiMacHeader
Implements the IEEE 802.11 MAC header.
Definition: wifi-mac-header.h:85
ns3::Ptr< Packet >
ns3::WifiMacHeader::SetQosAckPolicy
void SetQosAckPolicy(QosAckPolicy policy)
Set the QoS Ack policy in the QoS control field.
Definition: wifi-mac-header.cc:367
ns3::RegularWifiMac::m_edca
EdcaQueues m_edca
This is a map from Access Category index to the corresponding channel access function.
Definition: regular-wifi-mac.h:233
ns3::WifiMacHeader::IsQosAmsdu
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
Definition: wifi-mac-header.cc:855
ns3::RegularWifiMac::GetVhtSupported
bool GetVhtSupported() const
Return whether the device supports VHT.
Definition: regular-wifi-mac.cc:608
ns3::RegularWifiMac::SetAddress
void SetAddress(Mac48Address address) override
Definition: regular-wifi-mac.cc:665
ns3::AdhocWifiMac::AdhocWifiMac
AdhocWifiMac()
Definition: adhoc-wifi-mac.cc:47
ns3::QosUtilsMapTidToAc
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:126
ns3::RegularWifiMac::m_txop
Ptr< Txop > m_txop
This holds a pointer to the TXOP instance for this WifiMac - used for transmission of frames to non-Q...
Definition: regular-wifi-mac.h:225
ns3::WifiMacHeader::NORMAL_ACK
@ NORMAL_ACK
Definition: wifi-mac-header.h:92
ns3::RegularWifiMac::m_stationManager
Ptr< WifiRemoteStationManager > m_stationManager
Remote station manager (rate control, RTS/CTS/fragmentation thresholds etc.)
Definition: regular-wifi-mac.h:215
ns3::WifiMacHeader::IsQosData
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data.
Definition: wifi-mac-header.cc:565
first.address
address
Definition: first.py:44
ns3::WifiRemoteStationManager::IsBrandNew
bool IsBrandNew(Mac48Address address) const
Return whether the station state is brand new.
Definition: wifi-remote-station-manager.cc:438
ns3::WifiMacHeader::SetNoOrder
void SetNoOrder(void)
Unset order bit in the frame control field.
Definition: wifi-mac-header.cc:337
ns3::RegularWifiMac::SetTypeOfStation
void SetTypeOfStation(TypeOfStation type) override
This method is invoked by a subclass to specify what type of station it is implementing.
Definition: regular-wifi-mac.cc:482
ns3::RegularWifiMac::ForwardUp
void ForwardUp(Ptr< const Packet > packet, Mac48Address from, Mac48Address to)
Forward the packet up to the device.
Definition: regular-wifi-mac.cc:746
ns3::WifiRemoteStationManager::AddStationHtCapabilities
void AddStationHtCapabilities(Mac48Address from, HtCapabilities htCapabilities)
Records HT capabilities of the remote station.
Definition: wifi-remote-station-manager.cc:1301
ns3::WifiRemoteStationManager::AddStationVhtCapabilities
void AddStationVhtCapabilities(Mac48Address from, VhtCapabilities vhtCapabilities)
Records VHT capabilities of the remote station.
Definition: wifi-remote-station-manager.cc:1327
ns3::WifiMacHeader::SetAddr2
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
Definition: wifi-mac-header.cc:114
ns3::AdhocWifiMac::~AdhocWifiMac
virtual ~AdhocWifiMac()
Definition: adhoc-wifi-mac.cc:54
ns3::WifiRemoteStationManager::RecordDisassociated
void RecordDisassociated(Mac48Address address)
Records that the STA was disassociated.
Definition: wifi-remote-station-manager.cc:489
ns3::AdhocWifiMac::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: adhoc-wifi-mac.cc:37
ns3::RegularWifiMac::GetHtCapabilities
HtCapabilities GetHtCapabilities(void) const
Return the HT capabilities of the device.
Definition: regular-wifi-mac.cc:206
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::RegularWifiMac::GetHeCapabilities
HeCapabilities GetHeCapabilities(void) const
Return the HE capabilities of the device.
Definition: regular-wifi-mac.cc:345
ns3::Packet::Copy
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
ns3::WIFI_MAC_DATA
@ WIFI_MAC_DATA
Definition: wifi-mac-header.h:62
ns3::WIFI_MAC_QOSDATA
@ WIFI_MAC_QOSDATA
Definition: wifi-mac-header.h:70
ns3::WifiMacHeader::SetQosTxopLimit
void SetQosTxopLimit(uint8_t txop)
Set TXOP limit in the QoS control field.
Definition: wifi-mac-header.cc:396
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::WifiMacHeader::IsCtl
bool IsCtl(void) const
Return true if the Type is Control.
Definition: wifi-mac-header.cc:571
ns3::WifiMacHeader::SetType
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
Definition: wifi-mac-header.cc:132
ns3::RegularWifiMac::GetVhtCapabilities
VhtCapabilities GetVhtCapabilities(void) const
Return the VHT capabilities of the device.
Definition: regular-wifi-mac.cc:262
ns3::WifiMacHeader::SetDsNotTo
void SetDsNotTo(void)
Un-set the To DS bit in the Frame Control field.
Definition: wifi-mac-header.cc:102
ns3::WifiMacHeader::SetQosTid
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
Definition: wifi-mac-header.cc:352
ns3::WifiMacHeader::GetAddr2
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
Definition: wifi-mac-header.cc:430
ns3::RegularWifiMac::GetHtSupported
bool GetHtSupported() const
Return whether the device supports HT.
Definition: regular-wifi-mac.cc:598
ns3::Txop::Queue
virtual void Queue(Ptr< Packet > packet, const WifiMacHeader &hdr)
Definition: txop.cc:289
ns3::RegularWifiMac::Receive
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: regular-wifi-mac.cc:753
adhoc-wifi-mac.h
ns3::AdhocWifiMac::Enqueue
void Enqueue(Ptr< Packet > packet, Mac48Address to) override
Definition: adhoc-wifi-mac.cc:74
ns3::QosUtilsGetTidForPacket
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
ns3::WifiMacHeader::SetQosNoAmsdu
void SetQosNoAmsdu(void)
Set that A-MSDU is not present.
Definition: wifi-mac-header.cc:391