author | Stefano Avallone <stefano.avallone@unina.it> |
Fri, 05 Sep 2014 16:33:57 -0700 | |
changeset 10883 | d919e7194e23 |
child 10968 | 2d29fee2b7b8 |
permissions | -rw-r--r-- |
10883
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
2 |
/* |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
3 |
* Copyright (c) 2009 The Boeing Company |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
4 |
* 2014 Universita' degli Studi di Napoli "Federico II" |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
5 |
* |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
6 |
* This program is free software; you can redistribute it and/or modify |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
7 |
* it under the terms of the GNU General Public License version 2 as |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
8 |
* published by the Free Software Foundation; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
9 |
* |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
13 |
* GNU General Public License for more details. |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
14 |
* |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
18 |
* |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
19 |
*/ |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
20 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
21 |
// |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
22 |
// This script configures two nodes on an 802.11b physical layer, with |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
23 |
// 802.11b NICs in adhoc mode. One of the nodes generates on-off traffic |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
24 |
// destined to the other node. |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
25 |
// |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
26 |
// The purpose is to test the energy depletion on the nodes and the |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
27 |
// activation of the callback that puts a node in the sleep state when |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
28 |
// its energy is depleted. Furthermore, this script can be used to test |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
29 |
// the available policies for updating the transmit current based on |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
30 |
// the nominal tx power used to transmit each frame. |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
31 |
// |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
32 |
// There are a number of command-line options available to control |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
33 |
// the default behavior. The list of available command-line options |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
34 |
// can be listed with the following command: |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
35 |
// ./waf --run "wifi-sleep --help" |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
36 |
// |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
37 |
// Note that all ns-3 attributes (not just the ones exposed in the below |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
38 |
// script) can be changed at command line; see the documentation. |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
39 |
// |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
40 |
// This script can also be helpful to put the Wifi layer into verbose |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
41 |
// logging mode; this command will turn on all wifi logging: |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
42 |
// |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
43 |
// ./waf --run "wifi-sleep --verbose=1" |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
44 |
// |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
45 |
// When you are done, you will notice four trace files in your directory: |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
46 |
// two for the remaining energy on each node and two for the state transitions |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
47 |
// of each node. |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
48 |
// |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
49 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
50 |
#include "ns3/core-module.h" |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
51 |
#include "ns3/network-module.h" |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
52 |
#include "ns3/mobility-module.h" |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
53 |
#include "ns3/config-store-module.h" |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
54 |
#include "ns3/wifi-module.h" |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
55 |
#include "ns3/internet-module.h" |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
56 |
#include "ns3/applications-module.h" |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
57 |
#include "ns3/energy-module.h" |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
58 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
59 |
#include <iostream> |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
60 |
#include <fstream> |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
61 |
#include <vector> |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
62 |
#include <string> |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
63 |
#include <sstream> |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
64 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
65 |
NS_LOG_COMPONENT_DEFINE ("WifiSleep"); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
66 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
67 |
using namespace ns3; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
68 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
69 |
template <int node> |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
70 |
void RemainingEnergyTrace (double oldValue, double newValue) |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
71 |
{ |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
72 |
std::stringstream ss; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
73 |
ss << "energy_" << node << ".log"; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
74 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
75 |
static std::fstream f (ss.str().c_str(), std::ios::out); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
76 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
77 |
f << Simulator::Now().GetSeconds() << " remaining energy=" << newValue << std::endl; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
78 |
} |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
79 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
80 |
template <int node> |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
81 |
void PhyStateTrace (std::string context, Time start, Time duration, enum WifiPhy::State state) |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
82 |
{ |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
83 |
std::stringstream ss; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
84 |
ss << "state_" << node << ".log"; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
85 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
86 |
static std::fstream f (ss.str().c_str(), std::ios::out); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
87 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
88 |
f << Simulator::Now().GetSeconds() << " state=" << state << " start=" << start << " duration=" << duration << std::endl; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
89 |
} |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
90 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
91 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
92 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
93 |
int main (int argc, char *argv[]) |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
94 |
{ |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
95 |
std::string dataRate = "1Mbps"; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
96 |
uint32_t packetSize = 1000; // bytes |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
97 |
double duration = 10.0; // seconds |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
98 |
double initialEnergy = 7.5; // joule |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
99 |
double voltage = 3.0; // volts |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
100 |
double txPowerStart = 0.0; // dbm |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
101 |
double txPowerEnd = 15.0; // dbm |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
102 |
uint32_t nTxPowerLevels = 16; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
103 |
uint32_t txPowerLevel = 0; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
104 |
double idleCurrent = 0.273; // Ampere |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
105 |
double txCurrent = 0.380; // Ampere |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
106 |
bool verbose = false; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
107 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
108 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
109 |
CommandLine cmd; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
110 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
111 |
cmd.AddValue ("dataRate", "Data rate", dataRate); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
112 |
cmd.AddValue ("packetSize", "size of application packet sent", packetSize); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
113 |
cmd.AddValue ("duration", "duration (seconds) of the experiment", duration); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
114 |
cmd.AddValue ("initialEnergy", "Initial Energy (Joule) of each node", initialEnergy); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
115 |
cmd.AddValue ("voltage", "Supply voltage (Joule)", voltage); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
116 |
cmd.AddValue ("txPowerStart", "Minimum available transmission level (dbm)", txPowerStart); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
117 |
cmd.AddValue ("txPowerEnd", "Maximum available transmission level (dbm)", txPowerEnd); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
118 |
cmd.AddValue ("nTxPowerLevels", "Number of transmission power levels available between txPowerStart and txPowerEnd included", nTxPowerLevels); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
119 |
cmd.AddValue ("txPowerLevel", "Transmission power level", txPowerLevel); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
120 |
cmd.AddValue ("idleCurrent", "The radio Idle current in Ampere", idleCurrent); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
121 |
cmd.AddValue ("txCurrent", "The radio Tx current in Ampere", txCurrent); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
122 |
cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
123 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
124 |
cmd.Parse (argc, argv); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
125 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
126 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
127 |
NodeContainer c; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
128 |
c.Create (2); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
129 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
130 |
// The below set of helpers will help us to put together the wifi NICs we want |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
131 |
WifiHelper wifi; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
132 |
if (verbose) |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
133 |
{ |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
134 |
wifi.EnableLogComponents (); // Turn on all Wifi logging |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
135 |
} |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
136 |
wifi.SetStandard (WIFI_PHY_STANDARD_80211b); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
137 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
138 |
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
139 |
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
140 |
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
141 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
142 |
wifiPhy.Set ("TxPowerStart", DoubleValue (txPowerStart)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
143 |
wifiPhy.Set ("TxPowerEnd", DoubleValue (txPowerEnd)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
144 |
wifiPhy.Set ("TxPowerLevels", UintegerValue (nTxPowerLevels)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
145 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
146 |
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
147 |
wifiPhy.SetChannel (wifiChannel.Create ()); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
148 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
149 |
// Add a non-QoS upper mac, and set the selected tx power level |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
150 |
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
151 |
wifi.SetRemoteStationManager ("ns3::ArfWifiManager", "DefaultTxPowerLevel", UintegerValue (txPowerLevel)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
152 |
// Set it to adhoc mode |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
153 |
wifiMac.SetType ("ns3::AdhocWifiMac"); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
154 |
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
155 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
156 |
MobilityHelper mobility; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
157 |
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
158 |
positionAlloc->Add (Vector (0.0, 0.0, 0.0)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
159 |
positionAlloc->Add (Vector (10.0, 0.0, 0.0)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
160 |
mobility.SetPositionAllocator (positionAlloc); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
161 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
162 |
mobility.Install (c); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
163 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
164 |
InternetStackHelper internet; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
165 |
internet.Install (c); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
166 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
167 |
Ipv4AddressHelper ipv4; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
168 |
NS_LOG_INFO ("Assign IP Addresses."); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
169 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
170 |
Ipv4InterfaceContainer i = ipv4.Assign (devices); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
171 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
172 |
ApplicationContainer apps; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
173 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
174 |
std::string transportProto = std::string("ns3::UdpSocketFactory"); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
175 |
OnOffHelper onOff(transportProto, InetSocketAddress (Ipv4Address ("10.1.1.2"), 9000)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
176 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
177 |
onOff.SetAttribute ("DataRate", DataRateValue (DataRate (dataRate))); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
178 |
onOff.SetAttribute ("PacketSize", UintegerValue (packetSize)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
179 |
onOff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.001]")); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
180 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
181 |
apps = onOff.Install (c.Get (0)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
182 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
183 |
apps.Start (Seconds (0.01)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
184 |
apps.Stop (Seconds (duration)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
185 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
186 |
// Create a packet sink to receive these packets |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
187 |
PacketSinkHelper sink (transportProto, InetSocketAddress (Ipv4Address::GetAny (), 9001)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
188 |
apps = sink.Install (c.Get (1)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
189 |
apps.Start (Seconds (0.01)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
190 |
apps.Stop (Seconds (duration)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
191 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
192 |
// Energy sources |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
193 |
EnergySourceContainer eSources; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
194 |
BasicEnergySourceHelper basicSourceHelper; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
195 |
WifiRadioEnergyModelHelper radioEnergyHelper; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
196 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
197 |
basicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (initialEnergy)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
198 |
basicSourceHelper.Set ("BasicEnergySupplyVoltageV", DoubleValue (voltage)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
199 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
200 |
radioEnergyHelper.Set ("IdleCurrentA", DoubleValue (idleCurrent)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
201 |
radioEnergyHelper.Set ("TxCurrentA", DoubleValue (txCurrent)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
202 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
203 |
// compute the efficiency of the power amplifier (eta) assuming that the provided value for tx current |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
204 |
// corresponds to the minimum tx power level |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
205 |
double eta = WifiTxCurrentModel::DbmToW (txPowerStart) / ((txCurrent - idleCurrent) * voltage); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
206 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
207 |
radioEnergyHelper.SetTxCurrentModel ("ns3::LinearWifiTxCurrentModel", |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
208 |
"Voltage", DoubleValue (voltage), |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
209 |
"IdleCurrent", DoubleValue (idleCurrent), |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
210 |
"Eta", DoubleValue (eta)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
211 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
212 |
// install an energy source on each node |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
213 |
for (NodeContainer::Iterator n = c.Begin(); n != c.End(); n++) |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
214 |
{ |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
215 |
eSources.Add (basicSourceHelper.Install (*n)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
216 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
217 |
Ptr<WifiNetDevice> wnd; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
218 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
219 |
for (uint32_t i = 0; i < (*n)->GetNDevices (); ++i) |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
220 |
{ |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
221 |
wnd = (*n)->GetDevice (i)->GetObject<WifiNetDevice> (); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
222 |
// if it is a WifiNetDevice |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
223 |
if (wnd != 0) |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
224 |
{ |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
225 |
// this device draws power from the last created energy source |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
226 |
radioEnergyHelper.Install (wnd, eSources.Get (eSources.GetN()-1)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
227 |
} |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
228 |
} |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
229 |
} |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
230 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
231 |
// Tracing |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
232 |
eSources.Get (0)->TraceConnectWithoutContext ("RemainingEnergy", MakeCallback(&RemainingEnergyTrace<0>)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
233 |
eSources.Get (1)->TraceConnectWithoutContext ("RemainingEnergy", MakeCallback(&RemainingEnergyTrace<1>)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
234 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
235 |
Config::Connect ("/NodeList/0/DeviceList/*/Phy/State/State", MakeCallback (&PhyStateTrace<0>)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
236 |
Config::Connect ("/NodeList/1/DeviceList/*/Phy/State/State", MakeCallback (&PhyStateTrace<1>)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
237 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
238 |
// wifiPhy.EnablePcap ("wifi-sleep", devices); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
239 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
240 |
Simulator::Stop (Seconds(duration+1)); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
241 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
242 |
Simulator::Run (); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
243 |
Simulator::Destroy (); |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
244 |
|
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
245 |
return 0; |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
246 |
} |
d919e7194e23
add support for a Wifi sleep mode
Stefano Avallone <stefano.avallone@unina.it>
parents:
diff
changeset
|
247 |