A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Author: Mirko Banchi <mk.banchi@gmail.com>
21  */
22 #include "adhoc-wifi-mac.h"
23 
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 
30 #include "qos-tag.h"
31 #include "mac-low.h"
32 #include "dcf-manager.h"
33 #include "mac-rx-middle.h"
34 #include "mac-tx-middle.h"
35 #include "msdu-aggregator.h"
36 #include "amsdu-subframe-header.h"
37 #include "mgt-headers.h"
38 
39 NS_LOG_COMPONENT_DEFINE ("AdhocWifiMac");
40 
41 namespace ns3 {
42 
43 NS_OBJECT_ENSURE_REGISTERED (AdhocWifiMac)
44  ;
45 
46 TypeId
48 {
49  static TypeId tid = TypeId ("ns3::AdhocWifiMac")
51  .AddConstructor<AdhocWifiMac> ()
52  ;
53  return tid;
54 }
55 
57 {
58  NS_LOG_FUNCTION (this);
59 
60  // Let the lower layers know that we are acting in an IBSS
62 }
63 
65 {
66  NS_LOG_FUNCTION (this);
67 }
68 
69 void
71 {
72  NS_LOG_FUNCTION (this << address);
73  // In an IBSS, the BSSID is supposed to be generated per Section
74  // 11.1.3 of IEEE 802.11. We don't currently do this - instead we
75  // make an IBSS STA a bit like an AP, with the BSSID for frames
76  // transmitted by each STA set to that STA's address.
77  //
78  // This is why we're overriding this method.
80  RegularWifiMac::SetBssid (address);
81 }
82 
83 void
85 {
86  NS_LOG_FUNCTION (this << packet << to);
87  if (m_stationManager->IsBrandNew (to))
88  {
89  // In ad hoc mode, we assume that every destination supports all
90  // the rates we support.
91  for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
92  {
93  m_stationManager->AddSupportedMode (to, m_phy->GetMode (i));
94  }
95  m_stationManager->RecordDisassociated (to);
96  }
97 
98  WifiMacHeader hdr;
99 
100  // If we are not a QoS STA then we definitely want to use AC_BE to
101  // transmit the packet. A TID of zero will map to AC_BE (through \c
102  // QosUtilsMapTidToAc()), so we use that as our default here.
103  uint8_t tid = 0;
104 
105  // For now, a STA that supports QoS does not support non-QoS
106  // associations, and vice versa. In future the STA model should fall
107  // back to non-QoS if talking to a peer that is also non-QoS. At
108  // that point there will need to be per-station QoS state maintained
109  // by the association state machine, and consulted here.
110  if (m_qosSupported)
111  {
114  hdr.SetQosNoEosp ();
115  hdr.SetQosNoAmsdu ();
116  // Transmission of multiple frames in the same TXOP is not
117  // supported for now
118  hdr.SetQosTxopLimit (0);
119 
120  // Fill in the QoS control field in the MAC header
121  tid = QosUtilsGetTidForPacket (packet);
122  // Any value greater than 7 is invalid and likely indicates that
123  // the packet had no QoS tag, so we revert to zero, which'll
124  // mean that AC_BE is used.
125  if (tid >= 7)
126  {
127  tid = 0;
128  }
129  hdr.SetQosTid (tid);
130  }
131  else
132  {
133  hdr.SetTypeData ();
134  }
135 
136  hdr.SetAddr1 (to);
137  hdr.SetAddr2 (m_low->GetAddress ());
138  hdr.SetAddr3 (GetBssid ());
139  hdr.SetDsNotFrom ();
140  hdr.SetDsNotTo ();
141 
142  if (m_qosSupported)
143  {
144  // Sanity check that the TID is valid
145  NS_ASSERT (tid < 8);
146  m_edca[QosUtilsMapTidToAc (tid)]->Queue (packet, hdr);
147  }
148  else
149  {
150  m_dca->Queue (packet, hdr);
151  }
152 }
153 
154 void
156 {
157  NS_LOG_FUNCTION (this << &linkUp);
159 
160  // The approach taken here is that, from the point of view of a STA
161  // in IBSS mode, the link is always up, so we immediately invoke the
162  // callback if one is set
163  linkUp ();
164 }
165 
166 void
168 {
169  NS_LOG_FUNCTION (this << packet << hdr);
170  NS_ASSERT (!hdr->IsCtl ());
171  Mac48Address from = hdr->GetAddr2 ();
172  Mac48Address to = hdr->GetAddr1 ();
173  if (hdr->IsData ())
174  {
175  if (hdr->IsQosData () && hdr->IsQosAmsdu ())
176  {
177  NS_LOG_DEBUG ("Received A-MSDU from" << from);
178  DeaggregateAmsduAndForward (packet, hdr);
179  }
180  else
181  {
182  ForwardUp (packet, from, to);
183  }
184  return;
185  }
186 
187  // Invoke the receive handler of our parent class to deal with any
188  // other frames. Specifically, this will handle Block Ack-related
189  // Management Action frames.
190  RegularWifiMac::Receive (packet, hdr);
191 }
192 
193 } // namespace ns3
virtual void SetLinkUpCallback(Callback< void > linkUp)
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
void SetQosAckPolicy(enum QosAckPolicy policy)
Set the QoS ACK policy in the QoS control field.
virtual uint32_t GetNModes(void) const =0
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
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)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
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...
Ptr< WifiPhy > m_phy
Wifi PHY.
bool IsCtl(void) const
Return true if the Type is Control.
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
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:60
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.
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:27
virtual void SetAddress(Mac48Address address)
static TypeId GetTypeId(void)
Ptr< MacLow > m_low
MacLow (RTS, CTS, DATA, ACK etc.)
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
virtual void SetLinkUpCallback(Callback< void > linkUp)
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
an EUI-48 address
Definition: mac48-address.h:41
virtual WifiMode GetMode(uint32_t mode) const =0
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
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)
Definition: log.h:289
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 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.
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
NS_LOG_COMPONENT_DEFINE("AdhocWifiMac")
void SetDsNotFrom(void)
Un-set the From DS bit in the Frame Control field.