1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* |
2 /* |
3 * Copyright (c) 2006 INRIA |
3 * Copyright (c) 2006 INRIA |
4 * |
4 * |
5 * This program is free software; you can redistribute it and/or modify |
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 |
6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; |
7 * published by the Free Software Foundation; |
8 * |
8 * |
9 * This program is distributed in the hope that it will be useful, |
9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
30 double m_lastSnr; |
30 double m_lastSnr; |
31 }; |
31 }; |
32 |
32 |
33 NS_OBJECT_ENSURE_REGISTERED (IdealWifiManager); |
33 NS_OBJECT_ENSURE_REGISTERED (IdealWifiManager); |
34 |
34 |
35 TypeId |
35 TypeId |
36 IdealWifiManager::GetTypeId (void) |
36 IdealWifiManager::GetTypeId (void) |
37 { |
37 { |
38 static TypeId tid = TypeId ("ns3::IdealWifiManager") |
38 static TypeId tid = TypeId ("ns3::IdealWifiManager") |
39 .SetParent<WifiRemoteStationManager> () |
39 .SetParent<WifiRemoteStationManager> () |
40 .AddConstructor<IdealWifiManager> () |
40 .AddConstructor<IdealWifiManager> () |
41 .AddAttribute ("BerThreshold", |
41 .AddAttribute ("BerThreshold", |
42 "The maximum Bit Error Rate acceptable at any transmission mode", |
42 "The maximum Bit Error Rate acceptable at any transmission mode", |
43 DoubleValue (10e-6), |
43 DoubleValue (10e-6), |
44 MakeDoubleAccessor (&IdealWifiManager::m_ber), |
44 MakeDoubleAccessor (&IdealWifiManager::m_ber), |
45 MakeDoubleChecker<double> ()) |
45 MakeDoubleChecker<double> ()) |
46 ; |
46 ; |
47 return tid; |
47 return tid; |
48 } |
48 } |
49 |
49 |
50 IdealWifiManager::IdealWifiManager () |
50 IdealWifiManager::IdealWifiManager () |
51 {} |
51 { |
|
52 } |
52 IdealWifiManager::~IdealWifiManager () |
53 IdealWifiManager::~IdealWifiManager () |
53 {} |
54 { |
|
55 } |
54 |
56 |
55 void |
57 void |
56 IdealWifiManager::SetupPhy (Ptr<WifiPhy> phy) |
58 IdealWifiManager::SetupPhy (Ptr<WifiPhy> phy) |
57 { |
59 { |
58 uint32_t nModes = phy->GetNModes (); |
60 uint32_t nModes = phy->GetNModes (); |
59 for (uint32_t i = 0; i < nModes; i++) |
61 for (uint32_t i = 0; i < nModes; i++) |
60 { |
62 { |
61 WifiMode mode = phy->GetMode (i); |
63 WifiMode mode = phy->GetMode (i); |
62 AddModeSnrThreshold (mode, phy->CalculateSnr (mode, m_ber)); |
64 AddModeSnrThreshold (mode, phy->CalculateSnr (mode, m_ber)); |
63 } |
65 } |
64 |
66 |
65 WifiRemoteStationManager::SetupPhy (phy); |
67 WifiRemoteStationManager::SetupPhy (phy); |
66 } |
68 } |
67 |
69 |
68 double |
70 double |
69 IdealWifiManager::GetSnrThreshold (WifiMode mode) const |
71 IdealWifiManager::GetSnrThreshold (WifiMode mode) const |
70 { |
72 { |
71 for (Thresholds::const_iterator i = m_thresholds.begin (); i != m_thresholds.end (); i++) |
73 for (Thresholds::const_iterator i = m_thresholds.begin (); i != m_thresholds.end (); i++) |
72 { |
74 { |
73 if (mode == i->second) |
75 if (mode == i->second) |
74 { |
76 { |
75 return i->first; |
77 return i->first; |
76 } |
78 } |
77 } |
79 } |
78 NS_ASSERT (false); |
80 NS_ASSERT (false); |
79 return 0.0; |
81 return 0.0; |
80 } |
82 } |
81 |
83 |
82 void |
84 void |
83 IdealWifiManager::AddModeSnrThreshold (WifiMode mode, double snr) |
85 IdealWifiManager::AddModeSnrThreshold (WifiMode mode, double snr) |
84 { |
86 { |
85 m_thresholds.push_back (std::make_pair (snr,mode)); |
87 m_thresholds.push_back (std::make_pair (snr,mode)); |
86 } |
88 } |
87 |
89 |
92 station->m_lastSnr = 0.0; |
94 station->m_lastSnr = 0.0; |
93 return station; |
95 return station; |
94 } |
96 } |
95 |
97 |
96 |
98 |
97 void |
99 void |
98 IdealWifiManager::DoReportRxOk (WifiRemoteStation *station, |
100 IdealWifiManager::DoReportRxOk (WifiRemoteStation *station, |
99 double rxSnr, WifiMode txMode) |
101 double rxSnr, WifiMode txMode) |
100 {} |
102 { |
101 void |
103 } |
|
104 void |
102 IdealWifiManager::DoReportRtsFailed (WifiRemoteStation *station) |
105 IdealWifiManager::DoReportRtsFailed (WifiRemoteStation *station) |
103 {} |
106 { |
104 void |
107 } |
|
108 void |
105 IdealWifiManager::DoReportDataFailed (WifiRemoteStation *station) |
109 IdealWifiManager::DoReportDataFailed (WifiRemoteStation *station) |
106 {} |
110 { |
107 void |
111 } |
|
112 void |
108 IdealWifiManager::DoReportRtsOk (WifiRemoteStation *st, |
113 IdealWifiManager::DoReportRtsOk (WifiRemoteStation *st, |
109 double ctsSnr, WifiMode ctsMode, double rtsSnr) |
114 double ctsSnr, WifiMode ctsMode, double rtsSnr) |
110 { |
115 { |
111 IdealWifiRemoteStation *station = (IdealWifiRemoteStation *)st; |
116 IdealWifiRemoteStation *station = (IdealWifiRemoteStation *)st; |
112 station->m_lastSnr = rtsSnr; |
117 station->m_lastSnr = rtsSnr; |
113 } |
118 } |
114 void |
119 void |
115 IdealWifiManager::DoReportDataOk (WifiRemoteStation *st, |
120 IdealWifiManager::DoReportDataOk (WifiRemoteStation *st, |
116 double ackSnr, WifiMode ackMode, double dataSnr) |
121 double ackSnr, WifiMode ackMode, double dataSnr) |
117 { |
122 { |
118 IdealWifiRemoteStation *station = (IdealWifiRemoteStation *)st; |
123 IdealWifiRemoteStation *station = (IdealWifiRemoteStation *)st; |
119 station->m_lastSnr = dataSnr; |
124 station->m_lastSnr = dataSnr; |
120 } |
125 } |
121 void |
126 void |
122 IdealWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *station) |
127 IdealWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *station) |
123 {} |
128 { |
124 void |
129 } |
|
130 void |
125 IdealWifiManager::DoReportFinalDataFailed (WifiRemoteStation *station) |
131 IdealWifiManager::DoReportFinalDataFailed (WifiRemoteStation *station) |
126 {} |
132 { |
|
133 } |
127 |
134 |
128 WifiMode |
135 WifiMode |
129 IdealWifiManager::DoGetDataMode (WifiRemoteStation *st, uint32_t size) |
136 IdealWifiManager::DoGetDataMode (WifiRemoteStation *st, uint32_t size) |
130 { |
137 { |
131 IdealWifiRemoteStation *station = (IdealWifiRemoteStation *)st; |
138 IdealWifiRemoteStation *station = (IdealWifiRemoteStation *)st; |
132 // We search within the Supported rate set the mode with the |
139 // We search within the Supported rate set the mode with the |
133 // highest snr threshold possible which is smaller than m_lastSnr |
140 // highest snr threshold possible which is smaller than m_lastSnr |
134 // to ensure correct packet delivery. |
141 // to ensure correct packet delivery. |
135 double maxThreshold = 0.0; |
142 double maxThreshold = 0.0; |
136 WifiMode maxMode = GetDefaultMode (); |
143 WifiMode maxMode = GetDefaultMode (); |
137 for (uint32_t i = 0; i < GetNSupported (station); i++) |
144 for (uint32_t i = 0; i < GetNSupported (station); i++) |
138 { |
145 { |
139 WifiMode mode = GetSupported (station, i); |
146 WifiMode mode = GetSupported (station, i); |
140 double threshold = GetSnrThreshold (mode); |
147 double threshold = GetSnrThreshold (mode); |
141 if (threshold > maxThreshold && |
148 if (threshold > maxThreshold |
142 threshold < station->m_lastSnr) |
149 && threshold < station->m_lastSnr) |
143 { |
150 { |
144 maxThreshold = threshold; |
151 maxThreshold = threshold; |
145 maxMode = mode; |
152 maxMode = mode; |
146 } |
153 } |
147 } |
154 } |
149 } |
156 } |
150 WifiMode |
157 WifiMode |
151 IdealWifiManager::DoGetRtsMode (WifiRemoteStation *st) |
158 IdealWifiManager::DoGetRtsMode (WifiRemoteStation *st) |
152 { |
159 { |
153 IdealWifiRemoteStation *station = (IdealWifiRemoteStation *)st; |
160 IdealWifiRemoteStation *station = (IdealWifiRemoteStation *)st; |
154 // We search within the Basic rate set the mode with the highest |
161 // We search within the Basic rate set the mode with the highest |
155 // snr threshold possible which is smaller than m_lastSnr to |
162 // snr threshold possible which is smaller than m_lastSnr to |
156 // ensure correct packet delivery. |
163 // ensure correct packet delivery. |
157 double maxThreshold = 0.0; |
164 double maxThreshold = 0.0; |
158 WifiMode maxMode = GetDefaultMode (); |
165 WifiMode maxMode = GetDefaultMode (); |
159 for (uint32_t i = 0; i < GetNBasicModes (); i++) |
166 for (uint32_t i = 0; i < GetNBasicModes (); i++) |
160 { |
167 { |
161 WifiMode mode = GetBasicMode (i); |
168 WifiMode mode = GetBasicMode (i); |
162 double threshold = GetSnrThreshold (mode); |
169 double threshold = GetSnrThreshold (mode); |
163 if (threshold > maxThreshold && |
170 if (threshold > maxThreshold |
164 threshold < station->m_lastSnr) |
171 && threshold < station->m_lastSnr) |
165 { |
172 { |
166 maxThreshold = threshold; |
173 maxThreshold = threshold; |
167 maxMode = mode; |
174 maxMode = mode; |
168 } |
175 } |
169 } |
176 } |
170 return maxMode; |
177 return maxMode; |
171 } |
178 } |
172 |
179 |
173 bool |
180 bool |
174 IdealWifiManager::IsLowLatency (void) const |
181 IdealWifiManager::IsLowLatency (void) const |
175 { |
182 { |
176 return true; |
183 return true; |
177 } |
184 } |
178 |
185 |