A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cara-wifi-manager.cc
Go to the documentation of this file.
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 
42 
43 TypeId
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 
75 {
76 }
78 {
79 }
80 
83 {
85  station->m_rate = 0;
86  station->m_success = 0;
87  station->m_failed = 0;
88  station->m_timer = 0;
89  return station;
90 }
91 
92 void
94 {
95 }
96 
97 void
99 {
101  NS_LOG_FUNCTION (station);
102  station->m_timer++;
103  station->m_failed++;
104  station->m_success = 0;
105  if (station->m_failed >= m_failureThreshold)
106  {
107  NS_LOG_DEBUG ("self=" << station << " dec rate");
108  if (station->m_rate != 0)
109  {
110  station->m_rate--;
111  }
112  station->m_failed = 0;
113  station->m_timer = 0;
114  }
115 }
116 void
118  double rxSnr, WifiMode txMode)
119 {
120 }
121 void
123  double ctsSnr, WifiMode ctsMode, double rtsSnr)
124 {
125  NS_LOG_DEBUG ("self=" << st << " rts ok");
126 }
127 void
129  double ackSnr, WifiMode ackMode, double dataSnr)
130 {
132  station->m_timer++;
133  station->m_success++;
134  station->m_failed = 0;
135  NS_LOG_DEBUG ("self=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
136  if ((station->m_success == m_successThreshold
137  || station->m_timer >= m_timerTimeout))
138  {
139  if (station->m_rate < GetNSupported (station) - 1)
140  {
141  station->m_rate++;
142  }
143  NS_LOG_DEBUG ("self=" << station << " inc rate=" << station->m_rate);
144  station->m_timer = 0;
145  station->m_success = 0;
146  }
147 }
148 void
150 {
151 }
152 void
154 {
155 }
156 
157 WifiMode
159  uint32_t size)
160 {
162  return GetSupported (station, station->m_rate);
163 }
164 WifiMode
166 {
167  // XXX: we could/should implement the Arf algorithm for
168  // RTS only by picking a single rate within the BasicRateSet.
169  return GetSupported (st, 0);
170 }
171 
172 bool
174  Ptr<const Packet> packet, bool normally)
175 {
177  return normally || station->m_failed >= m_probeThreshold;
178 }
179 
180 bool
182 {
183  return true;
184 }
185 
186 } // namespace ns3