A Discrete-Event Network Simulator
API
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) 2008 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/packet.h"
23 #include "wifi-mac.h"
24 #include "txop.h"
25 #include "ssid.h"
26 #include "wifi-net-device.h"
27 #include "ns3/ht-configuration.h"
28 #include "ns3/vht-configuration.h"
29 #include "ns3/he-configuration.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("WifiMac");
34 
36 
37 TypeId
39 {
40  static TypeId tid = TypeId ("ns3::WifiMac")
41  .SetParent<Object> ()
42  .SetGroupName ("Wifi")
43  .AddAttribute ("Ssid", "The ssid we want to belong to.",
44  SsidValue (Ssid ("default")),
47  MakeSsidChecker ())
48  .AddTraceSource ("MacTx",
49  "A packet has been received from higher layers and is being processed in preparation for "
50  "queueing for transmission.",
52  "ns3::Packet::TracedCallback")
53  .AddTraceSource ("MacTxDrop",
54  "A packet has been dropped in the MAC layer before being queued for transmission. "
55  "This trace source is fired, e.g., when an AP's MAC receives from the upper layer "
56  "a packet destined to a station that is not associated with the AP or a STA's MAC "
57  "receives a packet from the upper layer while it is not associated with any AP.",
59  "ns3::Packet::TracedCallback")
60  .AddTraceSource ("MacPromiscRx",
61  "A packet has been received by this device, has been passed up from the physical layer "
62  "and is being forwarded up the local protocol stack. This is a promiscuous trace.",
64  "ns3::Packet::TracedCallback")
65  .AddTraceSource ("MacRx",
66  "A packet has been received by this device, has been passed up from the physical layer "
67  "and is being forwarded up the local protocol stack. This is a non-promiscuous trace.",
69  "ns3::Packet::TracedCallback")
70  .AddTraceSource ("MacRxDrop",
71  "A packet has been dropped in the MAC layer after it has been passed up from the physical layer.",
73  "ns3::Packet::TracedCallback")
74  ;
75  return tid;
76 }
77 
78 void
80 {
81  m_device = 0;
82 }
83 
84 void
86 {
87  m_device = device;
88 }
89 
91 WifiMac::GetDevice (void) const
92 {
93  return m_device;
94 }
95 
96 void
98 {
99  m_macTxTrace (packet);
100 }
101 
102 void
104 {
105  m_macTxDropTrace (packet);
106 }
107 
108 void
110 {
111  m_macRxTrace (packet);
112 }
113 
114 void
116 {
117  m_macPromiscRxTrace (packet);
118 }
119 
120 void
122 {
123  m_macRxDropTrace (packet);
124 }
125 
126 void
127 WifiMac::ConfigureDcf (Ptr<Txop> dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, AcIndex ac)
128 {
129  NS_LOG_FUNCTION (this << dcf << cwmin << cwmax << isDsss << ac);
130  /* see IEEE 802.11 section 7.3.2.29 */
131  switch (ac)
132  {
133  case AC_VO:
134  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
135  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
136  dcf->SetAifsn (2);
137  if (isDsss)
138  {
139  dcf->SetTxopLimit (MicroSeconds (3264));
140  }
141  else
142  {
143  dcf->SetTxopLimit (MicroSeconds (1504));
144  }
145  break;
146  case AC_VI:
147  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
148  dcf->SetMaxCw (cwmin);
149  dcf->SetAifsn (2);
150  if (isDsss)
151  {
152  dcf->SetTxopLimit (MicroSeconds (6016));
153  }
154  else
155  {
156  dcf->SetTxopLimit (MicroSeconds (3008));
157  }
158  break;
159  case AC_BE:
160  dcf->SetMinCw (cwmin);
161  dcf->SetMaxCw (cwmax);
162  dcf->SetAifsn (3);
163  dcf->SetTxopLimit (MicroSeconds (0));
164  break;
165  case AC_BK:
166  dcf->SetMinCw (cwmin);
167  dcf->SetMaxCw (cwmax);
168  dcf->SetAifsn (7);
169  dcf->SetTxopLimit (MicroSeconds (0));
170  break;
171  case AC_BE_NQOS:
172  dcf->SetMinCw (cwmin);
173  dcf->SetMaxCw (cwmax);
174  dcf->SetAifsn (2);
175  dcf->SetTxopLimit (MicroSeconds (0));
176  break;
177  case AC_BEACON:
178  // done by ApWifiMac
179  break;
180  case AC_UNDEF:
181  NS_FATAL_ERROR ("I don't know what to do with this");
182  break;
183  }
184 }
185 
188 {
189  return GetDevice ()->GetHtConfiguration ();
190 }
191 
194 {
195  return GetDevice ()->GetVhtConfiguration ();
196 }
197 
200 {
201  return GetDevice ()->GetHeConfiguration ();
202 }
203 
204 } //namespace ns3
205 
ns3::WifiMac::NotifyPromiscRx
void NotifyPromiscRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:115
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
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::WifiNetDevice::GetHtConfiguration
Ptr< HtConfiguration > GetHtConfiguration(void) const
Definition: wifi-net-device.cc:456
ns3::WifiMac::NotifyTxDrop
void NotifyTxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:103
ns3::Txop::SetMaxCw
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: txop.cc:173
ns3::MakeSsidChecker
Ptr< const AttributeChecker > MakeSsidChecker(void)
Definition: ssid.cc:118
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WifiMac::NotifyTx
void NotifyTx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:97
ns3::WifiMac::DoDispose
virtual void DoDispose()
Destructor implementation.
Definition: wifi-mac.cc:79
ns3::MicroSeconds
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
ssid.h
ns3::WifiMac::GetVhtConfiguration
Ptr< VhtConfiguration > GetVhtConfiguration(void) const
Definition: wifi-mac.cc:193
ns3::WifiMac::NotifyRx
void NotifyRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:109
ns3::AC_BEACON
@ AC_BEACON
Beacon queue.
Definition: qos-utils.h:83
ns3::WifiMac::m_macRxTrace
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: wifi-mac.h:331
txop.h
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::SsidValue
AttributeValue implementation for Ssid.
Definition: ssid.h:105
ns3::Ssid
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
ns3::MakeTraceSourceAccessor
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition: trace-source-accessor.h:202
ns3::WifiNetDevice::GetHeConfiguration
Ptr< HeConfiguration > GetHeConfiguration(void) const
Definition: wifi-net-device.cc:480
wifi-mac.h
ns3::Txop::SetMinCw
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:161
ns3::Ptr< WifiNetDevice >
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
ns3::AC_VI
@ AC_VI
Video.
Definition: qos-utils.h:77
ns3::WifiMac::SetDevice
void SetDevice(const Ptr< WifiNetDevice > device)
Sets the device this PHY is associated with.
Definition: wifi-mac.cc:85
ns3::Object
A base class which provides memory management and object aggregation.
Definition: object.h:88
wifi-net-device.h
ns3::WifiNetDevice::GetVhtConfiguration
Ptr< VhtConfiguration > GetVhtConfiguration(void) const
Definition: wifi-net-device.cc:468
ns3::AC_UNDEF
@ AC_UNDEF
Total number of ACs.
Definition: qos-utils.h:85
ns3::AC_BE
@ AC_BE
Best Effort.
Definition: qos-utils.h:73
ns3::AC_BE_NQOS
@ AC_BE_NQOS
Non-QoS.
Definition: qos-utils.h:81
ns3::WifiMac::GetHeConfiguration
Ptr< HeConfiguration > GetHeConfiguration(void) const
Definition: wifi-mac.cc:199
ns3::AC_BK
@ AC_BK
Background.
Definition: qos-utils.h:75
ns3::WifiMac::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: wifi-mac.cc:38
ns3::WifiMac::m_macPromiscRxTrace
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: wifi-mac.h:323
ns3::WifiMac::NotifyRxDrop
void NotifyRxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:121
ns3::AC_VO
@ AC_VO
Voice.
Definition: qos-utils.h:79
ns3::WifiMac::GetSsid
virtual Ssid GetSsid(void) const =0
ns3::WifiMac::m_macTxDropTrace
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets coming into the "top" of the device are dropped at the MAC layer ...
Definition: wifi-mac.h:315
ns3::WifiMac::GetHtConfiguration
Ptr< HtConfiguration > GetHtConfiguration(void) const
Definition: wifi-mac.cc:187
ns3::WifiMac::SetSsid
virtual void SetSsid(Ssid ssid)=0
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::AcIndex
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:71
ns3::Txop::SetTxopLimit
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:254
ns3::WifiMac::m_macRxDropTrace
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired when packets coming into the "top" of the device are dropped at the MAC layer ...
Definition: wifi-mac.h:338
ns3::WifiMac::ConfigureDcf
void ConfigureDcf(Ptr< Txop > dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, AcIndex ac)
Definition: wifi-mac.cc:127
ns3::MakeSsidAccessor
Ptr< const AttributeAccessor > MakeSsidAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: ssid.h:105
ns3::WifiMac::GetDevice
Ptr< WifiNetDevice > GetDevice(void) const
Return the device this PHY is associated with.
Definition: wifi-mac.cc:91
ns3::WifiMac::m_device
Ptr< WifiNetDevice > m_device
Pointer to the device.
Definition: wifi-mac.h:300
ns3::WifiMac::m_macTxTrace
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
Definition: wifi-mac.h:308
ns3::Txop::SetAifsn
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
Definition: txop.cc:247