A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
qos-wifi-mac-helper.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 MIRKO BANCHI
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: Mirko Banchi <mk.banchi@gmail.com>
19  */
20 #include "qos-wifi-mac-helper.h"
21 #include "ns3/msdu-aggregator.h"
22 #include "ns3/wifi-mac.h"
23 #include "ns3/edca-txop-n.h"
24 #include "ns3/pointer.h"
25 #include "ns3/boolean.h"
26 #include "ns3/uinteger.h"
27 
28 namespace ns3 {
29 
31 {
32 }
33 
35 {
36 }
37 
40 {
41  QosWifiMacHelper helper;
42 
43  // We're making QoS-enabled Wi-Fi MACs here, so we set the necessary
44  // attribute. I've carefully positioned this here so that someone
45  // who knows what they're doing can override with explicit
46  // attributes.
47  helper.SetType ("ns3::StaWifiMac",
48  "QosSupported", BooleanValue (true));
49 
50  return helper;
51 }
52 
53 void
54 QosWifiMacHelper::SetType (std::string type,
55  std::string n0, const AttributeValue &v0,
56  std::string n1, const AttributeValue &v1,
57  std::string n2, const AttributeValue &v2,
58  std::string n3, const AttributeValue &v3,
59  std::string n4, const AttributeValue &v4,
60  std::string n5, const AttributeValue &v5,
61  std::string n6, const AttributeValue &v6,
62  std::string n7, const AttributeValue &v7)
63 {
64  m_mac.SetTypeId (type);
65  m_mac.Set (n0, v0);
66  m_mac.Set (n1, v1);
67  m_mac.Set (n2, v2);
68  m_mac.Set (n3, v3);
69  m_mac.Set (n4, v4);
70  m_mac.Set (n5, v5);
71  m_mac.Set (n6, v6);
72  m_mac.Set (n7, v7);
73 }
74 
75 void
77  std::string n0, const AttributeValue &v0,
78  std::string n1, const AttributeValue &v1,
79  std::string n2, const AttributeValue &v2,
80  std::string n3, const AttributeValue &v3)
81 {
82  std::map<AcIndex, ObjectFactory>::iterator it = m_aggregators.find (ac);
83  if (it != m_aggregators.end ())
84  {
85  it->second.SetTypeId (type);
86  it->second.Set (n0, v0);
87  it->second.Set (n1, v1);
88  it->second.Set (n2, v2);
89  it->second.Set (n3, v3);
90  }
91  else
92  {
93  ObjectFactory factory;
94  factory.SetTypeId (type);
95  factory.Set (n0, v0);
96  factory.Set (n1, v1);
97  factory.Set (n2, v2);
98  factory.Set (n3, v3);
99  m_aggregators.insert (std::make_pair (ac, factory));
100  }
101 }
102 
103 void
105 {
106  m_bAckThresholds[ac] = threshold;
107 }
108 
109 void
111 {
112  m_bAckInactivityTimeouts[ac] = timeout;
113 }
114 
115 void
116 QosWifiMacHelper::Setup (Ptr<WifiMac> mac, enum AcIndex ac, std::string dcaAttrName) const
117 {
118  std::map<AcIndex, ObjectFactory>::const_iterator it = m_aggregators.find (ac);
119  PointerValue ptr;
120  mac->GetAttribute (dcaAttrName, ptr);
121  Ptr<EdcaTxopN> edca = ptr.Get<EdcaTxopN> ();
122 
123  if (it != m_aggregators.end ())
124  {
125  ObjectFactory factory = it->second;
126  Ptr<MsduAggregator> aggregator = factory.Create<MsduAggregator> ();
127  edca->SetMsduAggregator (aggregator);
128  }
129  if (m_bAckThresholds.find (ac) != m_bAckThresholds.end ())
130  {
131  edca->SetBlockAckThreshold (m_bAckThresholds.find (ac)->second);
132  }
133  if (m_bAckInactivityTimeouts.find (ac) != m_bAckInactivityTimeouts.end ())
134  {
135  edca->SetBlockAckInactivityTimeout (m_bAckInactivityTimeouts.find (ac)->second);
136  }
137 }
138 
139 
140 Ptr<WifiMac>
142 {
143  Ptr<WifiMac> mac = m_mac.Create<WifiMac> ();
144 
145  Setup (mac, AC_VO, "VO_EdcaTxopN");
146  Setup (mac, AC_VI, "VI_EdcaTxopN");
147  Setup (mac, AC_BE, "BE_EdcaTxopN");
148  Setup (mac, AC_BK, "BK_EdcaTxopN");
149 
150  return mac;
151 }
152 
153 } // namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Hold a bool native type.
Definition: boolean.h:38
Hold a value for an Attribute.
Definition: attribute.h:51
void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
void SetTypeId(TypeId tid)
void SetMsduAggregatorForAc(AcIndex ac, std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue())
void SetBlockAckThresholdForAc(enum AcIndex ac, uint8_t threshold)
Ptr< Object > Create(void) const
base class for all MAC-level wifi objects.This class encapsulates all the low-level MAC functionality...
Definition: wifi-mac.h:47
static QosWifiMacHelper Default(void)
create QoS-enabled MAC layers for a ns3::WifiNetDevice.
hold objects of type Ptr<T>
Definition: pointer.h:33
virtual Ptr< WifiMac > Create(void) const
void Set(std::string name, const AttributeValue &value)
instantiate subclasses of ns3::Object.
void SetBlockAckInactivityTimeoutForAc(enum AcIndex ac, uint16_t timeout)
Abstract class that concrete msdu aggregators have to implement.
AcIndex
Definition: qos-utils.h:35