47 #include "ns3/basic-energy-source-helper.h"
48 #include "ns3/command-line.h"
49 #include "ns3/config.h"
50 #include "ns3/internet-stack-helper.h"
51 #include "ns3/ipv4-address-helper.h"
53 #include "ns3/mobility-helper.h"
54 #include "ns3/mobility-model.h"
55 #include "ns3/on-off-helper.h"
56 #include "ns3/packet-sink-helper.h"
57 #include "ns3/string.h"
58 #include "ns3/wifi-net-device.h"
59 #include "ns3/wifi-radio-energy-model-helper.h"
60 #include "ns3/wifi-utils.h"
61 #include "ns3/yans-wifi-channel.h"
62 #include "ns3/yans-wifi-helper.h"
80 ss <<
"energy_" << node <<
".log";
82 static std::fstream
f(ss.str(), std::ios::out);
100 std::stringstream ss;
101 ss <<
"state_" << node <<
".log";
103 static std::fstream
f(ss.str(), std::ios::out);
106 <<
" duration=" << duration << std::endl;
110 main(
int argc,
char* argv[])
112 std::string dataRate =
"1Mbps";
114 double duration = 10.0;
115 double initialEnergy = 7.5;
116 double voltage = 3.0;
117 double txPowerStart = 0.0;
118 double txPowerEnd = 15.0;
119 uint32_t nTxPowerLevels = 16;
120 uint32_t txPowerLevel = 0;
121 double idleCurrent = 0.273;
122 double txCurrent = 0.380;
126 cmd.AddValue(
"dataRate",
"Data rate", dataRate);
127 cmd.AddValue(
"packetSize",
"size of application packet sent",
packetSize);
128 cmd.AddValue(
"duration",
"duration (seconds) of the experiment", duration);
129 cmd.AddValue(
"initialEnergy",
"Initial Energy (Joule) of each node", initialEnergy);
130 cmd.AddValue(
"voltage",
"Supply voltage (Joule)", voltage);
131 cmd.AddValue(
"txPowerStart",
"Minimum available transmission level (dbm)", txPowerStart);
132 cmd.AddValue(
"txPowerEnd",
"Maximum available transmission level (dbm)", txPowerEnd);
133 cmd.AddValue(
"nTxPowerLevels",
134 "Number of transmission power levels available between txPowerStart and "
135 "txPowerEnd included",
137 cmd.AddValue(
"txPowerLevel",
"Transmission power level", txPowerLevel);
138 cmd.AddValue(
"idleCurrent",
"The radio Idle current in Ampere", idleCurrent);
139 cmd.AddValue(
"txCurrent",
"The radio Tx current in Ampere", txCurrent);
140 cmd.AddValue(
"verbose",
"turn on all WifiNetDevice log components",
verbose);
141 cmd.Parse(argc, argv);
164 wifi.SetRemoteStationManager(
"ns3::ArfWifiManager",
165 "DefaultTxPowerLevel",
168 wifiMac.
SetType(
"ns3::AdhocWifiMac");
173 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
174 positionAlloc->Add(Vector(10.0, 0.0, 0.0));
175 mobility.SetPositionAllocator(positionAlloc);
176 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
184 ipv4.SetBase(
"10.1.1.0",
"255.255.255.0");
189 std::string transportProto = std::string(
"ns3::UdpSocketFactory");
192 onOff.SetAttribute(
"DataRate", DataRateValue(
DataRate(dataRate)));
194 onOff.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0.001]"));
196 apps = onOff.Install(c.
Get(0));
212 basicSourceHelper.
Set(
"BasicEnergySourceInitialEnergyJ",
DoubleValue(initialEnergy));
213 basicSourceHelper.
Set(
"BasicEnergySupplyVoltageV",
DoubleValue(voltage));
220 double eta =
DbmToW(txPowerStart) / ((txCurrent - idleCurrent) * voltage);
231 for (
auto n = c.
Begin(); n != c.
End(); n++)
237 for (uint32_t i = 0; i < (*n)->GetNDevices(); ++i)
244 radioEnergyHelper.
Install(wnd, eSources.
Get(eSources.
GetN() - 1));
250 eSources.
Get(0)->TraceConnectWithoutContext(
"RemainingEnergy",
252 eSources.
Get(1)->TraceConnectWithoutContext(
"RemainingEnergy",
double f(double x, void *params)
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Creates a BasicEnergySource object.
void Set(std::string name, const AttributeValue &v) override
Parse command-line arguments.
DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< EnergySource > source) const
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Holds a vector of ns3::EnergySource pointers.
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr<EnergySource> stored in this container.
uint32_t GetN() const
Get the number of Ptr<EnergySource> stored in this container.
void Add(EnergySourceContainer container)
EnergySourceContainer Install(Ptr< Node > node) const
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
static void EnableLogComponents()
Helper to enable all WifiNetDevice log components with one statement.
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
Hold together all Wifi-related objects.
void Set(std::string name, const AttributeValue &v)
Assign WifiRadioEnergyModel to wifi devices.
void Set(std::string name, const AttributeValue &v) override
void SetTxCurrentModel(std::string name, Ts &&... args)
manage and create wifi channel objects for the YANS model.
static YansWifiChannelHelper Default()
Create a channel helper in a default working state.
Ptr< YansWifiChannel > Create() const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
void Connect(std::string path, const CallbackBase &cb)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
double DbmToW(double dBm)
Convert from dBm to Watts.
WifiPhyState
The state of the PHY layer.
static const uint32_t packetSize
Packet size generated at the AP.
void RemainingEnergyTrace(double oldValue, double newValue)
Remaining energy trace sink.
void PhyStateTrace(std::string context, Time start, Time duration, WifiPhyState state)
PHY state trace sink.
Ptr< PacketSink > sink
Pointer to the packet sink application.