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 "ht-configuration.h"
28 #include "vht-configuration.h"
29 #include "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 transmission.",
56  "ns3::Packet::TracedCallback")
57  .AddTraceSource ("MacPromiscRx",
58  "A packet has been received by this device, has been passed up from the physical layer "
59  "and is being forwarded up the local protocol stack. This is a promiscuous trace.",
61  "ns3::Packet::TracedCallback")
62  .AddTraceSource ("MacRx",
63  "A packet has been received by this device, has been passed up from the physical layer "
64  "and is being forwarded up the local protocol stack. This is a non-promiscuous trace.",
66  "ns3::Packet::TracedCallback")
67  .AddTraceSource ("MacRxDrop",
68  "A packet has been dropped in the MAC layer after it has been passed up from the physical layer.",
70  "ns3::Packet::TracedCallback")
71  ;
72  return tid;
73 }
74 
75 void
77 {
78  m_device = 0;
79 }
80 
81 void
83 {
84  m_device = device;
85 }
86 
88 WifiMac::GetDevice (void) const
89 {
90  return m_device;
91 }
92 
93 void
95 {
96  m_macTxTrace (packet);
97 }
98 
99 void
101 {
102  m_macTxDropTrace (packet);
103 }
104 
105 void
107 {
108  m_macRxTrace (packet);
109 }
110 
111 void
113 {
114  m_macPromiscRxTrace (packet);
115 }
116 
117 void
119 {
120  m_macRxDropTrace (packet);
121 }
122 
123 void
124 WifiMac::ConfigureDcf (Ptr<Txop> dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, AcIndex ac)
125 {
126  NS_LOG_FUNCTION (this << dcf << cwmin << cwmax << isDsss << ac);
127  /* see IEEE 802.11 section 7.3.2.29 */
128  switch (ac)
129  {
130  case AC_VO:
131  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
132  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
133  dcf->SetAifsn (2);
134  if (isDsss)
135  {
136  dcf->SetTxopLimit (MicroSeconds (3264));
137  }
138  else
139  {
140  dcf->SetTxopLimit (MicroSeconds (1504));
141  }
142  break;
143  case AC_VI:
144  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
145  dcf->SetMaxCw (cwmin);
146  dcf->SetAifsn (2);
147  if (isDsss)
148  {
149  dcf->SetTxopLimit (MicroSeconds (6016));
150  }
151  else
152  {
153  dcf->SetTxopLimit (MicroSeconds (3008));
154  }
155  break;
156  case AC_BE:
157  dcf->SetMinCw (cwmin);
158  dcf->SetMaxCw (cwmax);
159  dcf->SetAifsn (3);
160  dcf->SetTxopLimit (MicroSeconds (0));
161  break;
162  case AC_BK:
163  dcf->SetMinCw (cwmin);
164  dcf->SetMaxCw (cwmax);
165  dcf->SetAifsn (7);
166  dcf->SetTxopLimit (MicroSeconds (0));
167  break;
168  case AC_BE_NQOS:
169  dcf->SetMinCw (cwmin);
170  dcf->SetMaxCw (cwmax);
171  dcf->SetAifsn (2);
172  dcf->SetTxopLimit (MicroSeconds (0));
173  break;
174  case AC_UNDEF:
175  NS_FATAL_ERROR ("I don't know what to do with this");
176  break;
177  }
178 }
179 
182 {
183  Ptr<WifiNetDevice> device = DynamicCast<WifiNetDevice> (GetDevice ());
184  return device->GetHtConfiguration ();
185 }
186 
189 {
190  Ptr<WifiNetDevice> device = DynamicCast<WifiNetDevice> (GetDevice ());
191  return device->GetVhtConfiguration ();
192 }
193 
196 {
197  Ptr<WifiNetDevice> device = DynamicCast<WifiNetDevice> (GetDevice ());
198  return device->GetHeConfiguration ();
199 }
200 
201 } //namespace ns3
202 
Ptr< HeConfiguration > GetHeConfiguration(void) const
Definition: wifi-mac.cc:195
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Ptr< HeConfiguration > GetHeConfiguration(void) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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:288
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
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:265
void NotifyRxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:118
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
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:273
Video.
Definition: qos-utils.h:45
Voice.
Definition: qos-utils.h:47
Best Effort.
Definition: qos-utils.h:41
void ConfigureDcf(Ptr< Txop > dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, AcIndex ac)
Definition: wifi-mac.cc:124
virtual void SetSsid(Ssid ssid)=0
Ptr< NetDevice > GetDevice(void) const
Return the device this PHY is associated with.
Definition: wifi-mac.cc:88
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual Ssid GetSsid(void) const =0
Background.
Definition: qos-utils.h:43
Ptr< HtConfiguration > GetHtConfiguration(void) const
Definition: wifi-mac.cc:181
void SetDevice(const Ptr< NetDevice > device)
Sets the device this PHY is associated with.
Definition: wifi-mac.cc:82
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:258
void NotifyTxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:100
Ptr< const AttributeChecker > MakeSsidChecker(void)
Definition: ssid.cc:118
void NotifyPromiscRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:112
virtual void DoDispose()
Destructor implementation.
Definition: wifi-mac.cc:76
void NotifyTx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:94
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
void NotifyRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:106
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:281
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:186
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: txop.cc:199
Ptr< VhtConfiguration > GetVhtConfiguration(void) const
Definition: wifi-mac.cc:188
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:277
AttributeValue implementation for Ssid.
Definition: ssid.h:105
Total number of ACs.
Definition: qos-utils.h:49
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1078
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
Definition: txop.cc:270
Ptr< NetDevice > m_device
Pointer to the device.
Definition: wifi-mac.h:250
A base class which provides memory management and object aggregation.
Definition: object.h:87
Ptr< VhtConfiguration > GetVhtConfiguration(void) const
Ptr< HtConfiguration > GetHtConfiguration(void) const
a unique identifier for an interface.
Definition: type-id.h:58
static TypeId GetTypeId(void)
Get the type ID.
Definition: wifi-mac.cc:38
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:38