A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
cara-wifi-manager.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2004,2005,2006 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: Federico Maguolo <maguolof@dei.unipd.it>
19  */
20 
21 #include "cara-wifi-manager.h"
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 #include "ns3/double.h"
25 #include "ns3/uinteger.h"
26 #include "ns3/simulator.h"
27 
29 
30 
31 namespace ns3 {
32 
34 {
35  uint32_t m_timer;
36  uint32_t m_success;
37  uint32_t m_failed;
38  uint32_t m_rate;
39 };
40 
41 NS_OBJECT_ENSURE_REGISTERED (CaraWifiManager);
42 
43 TypeId
44 CaraWifiManager::GetTypeId (void)
45 {
46  static TypeId tid = TypeId ("ns3::CaraWifiManager")
48  .AddConstructor<CaraWifiManager> ()
49  .AddAttribute ("ProbeThreshold",
50  "The number of consecutive transmissions failure to activate the RTS probe.",
51  UintegerValue (1),
52  MakeUintegerAccessor (&CaraWifiManager::m_probeThreshold),
53  MakeUintegerChecker<uint32_t> ())
54  .AddAttribute ("FailureThreshold",
55  "The number of consecutive transmissions failure to decrease the rate.",
56  UintegerValue (2),
57  MakeUintegerAccessor (&CaraWifiManager::m_failureThreshold),
58  MakeUintegerChecker<uint32_t> ())
59  .AddAttribute ("SuccessThreshold",
60  "The minimum number of sucessfull transmissions to try a new rate.",
61  UintegerValue (10),
62  MakeUintegerAccessor (&CaraWifiManager::m_successThreshold),
63  MakeUintegerChecker<uint32_t> ())
64  .AddAttribute ("Timeout",
65  "The 'timer' in the CARA algorithm",
66  UintegerValue (15),
67  MakeUintegerAccessor (&CaraWifiManager::m_timerTimeout),
68  MakeUintegerChecker<uint32_t> ())
69  ;
70  return tid;
71 }
72 
73 CaraWifiManager::CaraWifiManager ()
74  : WifiRemoteStationManager ()
75 {
76  NS_LOG_FUNCTION (this);
77 }
78 CaraWifiManager::~CaraWifiManager ()
79 {
80  NS_LOG_FUNCTION (this);
81 }
82 
83 WifiRemoteStation *
85 {
86  NS_LOG_FUNCTION (this);
88  station->m_rate = 0;
89  station->m_success = 0;
90  station->m_failed = 0;
91  station->m_timer = 0;
92  return station;
93 }
94 
95 void
96 CaraWifiManager::DoReportRtsFailed (WifiRemoteStation *st)
97 {
98  NS_LOG_FUNCTION (this << st);
99 }
100 
101 void
102 CaraWifiManager::DoReportDataFailed (WifiRemoteStation *st)
103 {
104  NS_LOG_FUNCTION (this << st);
105  CaraWifiRemoteStation *station = (CaraWifiRemoteStation *) st;
106  station->m_timer++;
107  station->m_failed++;
108  station->m_success = 0;
109  if (station->m_failed >= m_failureThreshold)
110  {
111  NS_LOG_DEBUG ("self=" << station << " dec rate");
112  if (station->m_rate != 0)
113  {
114  station->m_rate--;
115  }
116  station->m_failed = 0;
117  station->m_timer = 0;
118  }
119 }
120 void
121 CaraWifiManager::DoReportRxOk (WifiRemoteStation *st,
122  double rxSnr, WifiMode txMode)
123 {
124  NS_LOG_FUNCTION (this << st << rxSnr << txMode);
125 }
126 void
127 CaraWifiManager::DoReportRtsOk (WifiRemoteStation *st,
128  double ctsSnr, WifiMode ctsMode, double rtsSnr)
129 {
130  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
131  NS_LOG_DEBUG ("self=" << st << " rts ok");
132 }
133 void
134 CaraWifiManager::DoReportDataOk (WifiRemoteStation *st,
135  double ackSnr, WifiMode ackMode, double dataSnr)
136 {
137  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
138  CaraWifiRemoteStation *station = (CaraWifiRemoteStation *) st;
139  station->m_timer++;
140  station->m_success++;
141  station->m_failed = 0;
142  NS_LOG_DEBUG ("self=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
143  if ((station->m_success == m_successThreshold
144  || station->m_timer >= m_timerTimeout))
145  {
146  if (station->m_rate < GetNSupported (station) - 1)
147  {
148  station->m_rate++;
149  }
150  NS_LOG_DEBUG ("self=" << station << " inc rate=" << station->m_rate);
151  station->m_timer = 0;
152  station->m_success = 0;
153  }
154 }
155 void
156 CaraWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *st)
157 {
158  NS_LOG_FUNCTION (this << st);
159 }
160 void
161 CaraWifiManager::DoReportFinalDataFailed (WifiRemoteStation *st)
162 {
163  NS_LOG_FUNCTION (this << st);
164 }
165 
166 WifiMode
168  uint32_t size)
169 {
170  NS_LOG_FUNCTION (this << st << size);
172  return GetSupported (station, station->m_rate);
173 }
174 WifiMode
176 {
177  NS_LOG_FUNCTION (this << st);
178  // XXX: we could/should implement the Arf algorithm for
179  // RTS only by picking a single rate within the BasicRateSet.
180  return GetSupported (st, 0);
181 }
182 
183 bool
185  Ptr<const Packet> packet, bool normally)
186 {
187  NS_LOG_FUNCTION (this << st << normally);
189  return normally || station->m_failed >= m_probeThreshold;
190 }
191 
192 bool
194 {
195  NS_LOG_FUNCTION (this);
196  return true;
197 }
198 
199 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
virtual WifiMode DoGetRtsMode(WifiRemoteStation *station)
virtual WifiRemoteStation * DoCreateStation(void) const
virtual bool IsLowLatency(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:88
Hold an unsigned integer type.
Definition: uinteger.h:46
hold a list of per-remote-station state.
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
virtual WifiMode DoGetDataMode(WifiRemoteStation *station, uint32_t size)
implement the CARA rate control algorithmImplement the CARA algorithm from: J. Kim, S. Kim, S. Choi, and D. Qiao. "CARA: Collision-Aware Rate Adaptation for IEEE 802.11 WLANs."
virtual bool DoNeedRts(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
a unique identifier for an interface.
Definition: type-id.h:44
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
hold per-remote-station state.