OLD | NEW |
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) 2010 Network Security Lab, University of Washington, Seattle. | 3 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. |
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 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 bool DoRun (void); | 54 bool DoRun (void); |
55 | 55 |
56 private: | 56 private: |
57 /** | 57 /** |
58 * \param state Radio state to switch to. | 58 * \param state Radio state to switch to. |
59 * \return False if no error occurs. | 59 * \return False if no error occurs. |
60 * | 60 * |
61 * Runs simulation for a while, check if final state & remaining energy is | 61 * Runs simulation for a while, check if final state & remaining energy is |
62 * correctly updated. | 62 * correctly updated. |
63 */ | 63 */ |
64 bool StateSwitchTest (WifiPhy::State state); | 64 bool StateSwitchTest (WifiPhyState state); |
65 | 65 |
66 private: | 66 private: |
67 double m_timeS; // in seconds | 67 double m_timeS; // in seconds |
68 double m_tolerance; // tolerance for power estimation | 68 double m_tolerance; // tolerance for power estimation |
69 | 69 |
70 ObjectFactory m_energySource; | 70 ObjectFactory m_energySource; |
71 ObjectFactory m_deviceEnergyModel; | 71 ObjectFactory m_deviceEnergyModel; |
72 }; | 72 }; |
73 | 73 |
74 BasicEnergyUpdateTest::BasicEnergyUpdateTest () | 74 BasicEnergyUpdateTest::BasicEnergyUpdateTest () |
75 { | 75 { |
76 m_timeS = 15.5; // idle for 15 seconds before changing state | 76 m_timeS = 15.5; // idle for 15 seconds before changing state |
77 m_tolerance = 1.0e-13; // | 77 m_tolerance = 1.0e-13; // |
78 } | 78 } |
79 | 79 |
80 BasicEnergyUpdateTest::~BasicEnergyUpdateTest () | 80 BasicEnergyUpdateTest::~BasicEnergyUpdateTest () |
81 { | 81 { |
82 } | 82 } |
83 | 83 |
84 bool | 84 bool |
85 BasicEnergyUpdateTest::DoRun (void) | 85 BasicEnergyUpdateTest::DoRun (void) |
86 { | 86 { |
87 // set types | 87 // set types |
88 m_energySource.SetTypeId ("ns3::BasicEnergySource"); | 88 m_energySource.SetTypeId ("ns3::BasicEnergySource"); |
89 m_deviceEnergyModel.SetTypeId ("ns3::WifiRadioEnergyModel"); | 89 m_deviceEnergyModel.SetTypeId ("ns3::WifiRadioEnergyModel"); |
90 | 90 |
91 // run state switch tests | 91 // run state switch tests |
92 if (StateSwitchTest (WifiPhy::IDLE)) | 92 if (StateSwitchTest (WifiPhyState::IDLE)) |
93 { | 93 { |
94 return 1; | 94 return 1; |
95 std::cerr << "Problem with state switch test (WifiPhy idle)." << std::endl
; | 95 std::cerr << "Problem with state switch test (WifiPhy idle)." << std::endl
; |
96 } | 96 } |
97 if (StateSwitchTest (WifiPhy::CCA_BUSY)) | 97 if (StateSwitchTest (WifiPhyState::CCA_BUSY)) |
98 { | 98 { |
99 return 1; | 99 return 1; |
100 std::cerr << "Problem with state switch test (WifiPhy cca busy)." << std::
endl; | 100 std::cerr << "Problem with state switch test (WifiPhy cca busy)." << std::
endl; |
101 } | 101 } |
102 if (StateSwitchTest (WifiPhy::TX)) | 102 if (StateSwitchTest (WifiPhyState::TX)) |
103 { | 103 { |
104 return 1; | 104 return 1; |
105 std::cerr << "Problem with state switch test (WifiPhy tx)." << std::endl; | 105 std::cerr << "Problem with state switch test (WifiPhy tx)." << std::endl; |
106 } | 106 } |
107 if (StateSwitchTest (WifiPhy::RX)) | 107 if (StateSwitchTest (WifiPhyState::RX)) |
108 { | 108 { |
109 return 1; | 109 return 1; |
110 std::cerr << "Problem with state switch test (WifiPhy rx)." << std::endl; | 110 std::cerr << "Problem with state switch test (WifiPhy rx)." << std::endl; |
111 } | 111 } |
112 if (StateSwitchTest (WifiPhy::SWITCHING)) | 112 if (StateSwitchTest (WifiPhyState::SWITCHING)) |
113 { | 113 { |
114 return 1; | 114 return 1; |
115 std::cerr << "Problem with state switch test (WifiPhy switching)." << std:
:endl; | 115 std::cerr << "Problem with state switch test (WifiPhy switching)." << std:
:endl; |
116 } | 116 } |
117 if (StateSwitchTest (WifiPhy::SLEEP)) | 117 if (StateSwitchTest (WifiPhyState::SLEEP)) |
118 { | 118 { |
119 return 1; | 119 return 1; |
120 std::cerr << "Problem with state switch test (WifiPhy sleep)." << std::end
l; | 120 std::cerr << "Problem with state switch test (WifiPhy sleep)." << std::end
l; |
121 } | 121 } |
122 return 0; | 122 return 0; |
123 } | 123 } |
124 | 124 |
125 bool | 125 bool |
126 BasicEnergyUpdateTest::StateSwitchTest (WifiPhy::State state) | 126 BasicEnergyUpdateTest::StateSwitchTest (WifiPhyState state) |
127 { | 127 { |
128 // create node | 128 // create node |
129 Ptr<Node> node = CreateObject<Node> (); | 129 Ptr<Node> node = CreateObject<Node> (); |
130 | 130 |
131 // create energy source | 131 // create energy source |
132 Ptr<BasicEnergySource> source = m_energySource.Create<BasicEnergySource> (); | 132 Ptr<BasicEnergySource> source = m_energySource.Create<BasicEnergySource> (); |
133 source->SetInitialEnergy (50); | 133 source->SetInitialEnergy (50); |
134 // aggregate energy source to node | 134 // aggregate energy source to node |
135 node->AggregateObject (source); | 135 node->AggregateObject (source); |
136 source->SetNode (node); | 136 source->SetNode (node); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 184 |
185 // calculate idle power consumption | 185 // calculate idle power consumption |
186 double estRemainingEnergy = source->GetInitialEnergy (); | 186 double estRemainingEnergy = source->GetInitialEnergy (); |
187 double voltage = source->GetSupplyVoltage (); | 187 double voltage = source->GetSupplyVoltage (); |
188 estRemainingEnergy -= devModel->GetIdleCurrentA () * voltage * m_timeS; | 188 estRemainingEnergy -= devModel->GetIdleCurrentA () * voltage * m_timeS; |
189 | 189 |
190 // calculate new state power consumption | 190 // calculate new state power consumption |
191 double current = 0.0; | 191 double current = 0.0; |
192 switch (state) | 192 switch (state) |
193 { | 193 { |
194 case WifiPhy::IDLE: | 194 case WifiPhyState::IDLE: |
195 current = devModel->GetIdleCurrentA (); | 195 current = devModel->GetIdleCurrentA (); |
196 break; | 196 break; |
197 case WifiPhy::CCA_BUSY: | 197 case WifiPhyState::CCA_BUSY: |
198 current = devModel->GetCcaBusyCurrentA (); | 198 current = devModel->GetCcaBusyCurrentA (); |
199 break; | 199 break; |
200 case WifiPhy::TX: | 200 case WifiPhyState::TX: |
201 current = devModel->GetTxCurrentA (); | 201 current = devModel->GetTxCurrentA (); |
202 break; | 202 break; |
203 case WifiPhy::RX: | 203 case WifiPhyState::RX: |
204 current = devModel->GetRxCurrentA (); | 204 current = devModel->GetRxCurrentA (); |
205 break; | 205 break; |
206 case WifiPhy::SWITCHING: | 206 case WifiPhyState::SWITCHING: |
207 current = devModel->GetSwitchingCurrentA (); | 207 current = devModel->GetSwitchingCurrentA (); |
208 break; | 208 break; |
209 case WifiPhy::SLEEP: | 209 case WifiPhyState::SLEEP: |
210 current = devModel->GetSleepCurrentA (); | 210 current = devModel->GetSleepCurrentA (); |
211 break; | 211 break; |
212 case WifiPhy::OFF: | 212 case WifiPhyState::OFF: |
213 current = 0; | 213 current = 0; |
214 break; | 214 break; |
215 default: | 215 default: |
216 NS_FATAL_ERROR ("Undefined radio state: " << state); | 216 NS_FATAL_ERROR ("Undefined radio state: " << state); |
217 break; | 217 break; |
218 } | 218 } |
219 estRemainingEnergy -= current * voltage * m_timeS; | 219 estRemainingEnergy -= current * voltage * m_timeS; |
220 estRemainingEnergy = std::max(0.0, estRemainingEnergy); | 220 estRemainingEnergy = std::max(0.0, estRemainingEnergy); |
221 | 221 |
222 // obtain remaining energy from source | 222 // obtain remaining energy from source |
223 double remainingEnergy = source->GetRemainingEnergy (); | 223 double remainingEnergy = source->GetRemainingEnergy (); |
224 NS_LOG_DEBUG ("Remaining energy is " << remainingEnergy); | 224 NS_LOG_DEBUG ("Remaining energy is " << remainingEnergy); |
225 NS_LOG_DEBUG ("Estimated remaining energy is " << estRemainingEnergy); | 225 NS_LOG_DEBUG ("Estimated remaining energy is " << estRemainingEnergy); |
226 NS_LOG_DEBUG ("Difference is " << estRemainingEnergy - remainingEnergy); | 226 NS_LOG_DEBUG ("Difference is " << estRemainingEnergy - remainingEnergy); |
227 | 227 |
228 // check remaining energy | 228 // check remaining energy |
229 if ((remainingEnergy > (estRemainingEnergy + m_tolerance)) || | 229 if ((remainingEnergy > (estRemainingEnergy + m_tolerance)) || |
230 (remainingEnergy < (estRemainingEnergy - m_tolerance))) | 230 (remainingEnergy < (estRemainingEnergy - m_tolerance))) |
231 { | 231 { |
232 std::cerr << "Incorrect remaining energy!" << std::endl; | 232 std::cerr << "Incorrect remaining energy!" << std::endl; |
233 return true; | 233 return true; |
234 } | 234 } |
235 | 235 |
236 // obtain radio state | 236 // obtain radio state |
237 WifiPhy::State endState = devModel->GetCurrentState (); | 237 WifiPhyState endState = devModel->GetCurrentState (); |
238 NS_LOG_DEBUG ("Radio state is " << endState); | 238 NS_LOG_DEBUG ("Radio state is " << endState); |
239 // check end state | 239 // check end state |
240 if (endState != state) | 240 if (endState != state) |
241 { | 241 { |
242 std::cerr << "Incorrect end state!" << std::endl; | 242 std::cerr << "Incorrect end state!" << std::endl; |
243 return true; | 243 return true; |
244 } | 244 } |
245 Simulator::Destroy (); | 245 Simulator::Destroy (); |
246 | 246 |
247 return false; // no error | 247 return false; // no error |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 } | 434 } |
435 | 435 |
436 BasicEnergyDepletionTest testEnergyDepletion; | 436 BasicEnergyDepletionTest testEnergyDepletion; |
437 if (testEnergyDepletion.DoRun ()) | 437 if (testEnergyDepletion.DoRun ()) |
438 { | 438 { |
439 return 1; | 439 return 1; |
440 } | 440 } |
441 | 441 |
442 return 0; | 442 return 0; |
443 } | 443 } |
OLD | NEW |