48 #include "ns3/core-module.h"
49 #include "ns3/mobility-module.h"
50 #include "ns3/wifi-module.h"
51 #include "ns3/internet-module.h"
52 #include "ns3/applications-module.h"
53 #include "ns3/energy-module.h"
63 ss <<
"energy_" << node <<
".log";
65 static std::fstream
f (ss.str ().c_str (), std::ios::out);
74 ss <<
"state_" << node <<
".log";
76 static std::fstream
f (ss.str ().c_str (), std::ios::out);
78 f <<
Simulator::Now ().
GetSeconds () <<
" state=" << state <<
" start=" << start <<
" duration=" << duration << std::endl;
81 int main (
int argc,
char *argv[])
83 std::string dataRate =
"1Mbps";
85 double duration = 10.0;
86 double initialEnergy = 7.5;
88 double txPowerStart = 0.0;
89 double txPowerEnd = 15.0;
90 uint32_t nTxPowerLevels = 16;
91 uint32_t txPowerLevel = 0;
92 double idleCurrent = 0.273;
93 double txCurrent = 0.380;
97 cmd.
AddValue (
"dataRate",
"Data rate", dataRate);
98 cmd.
AddValue (
"packetSize",
"size of application packet sent", packetSize);
99 cmd.
AddValue (
"duration",
"duration (seconds) of the experiment", duration);
100 cmd.
AddValue (
"initialEnergy",
"Initial Energy (Joule) of each node", initialEnergy);
101 cmd.
AddValue (
"voltage",
"Supply voltage (Joule)", voltage);
102 cmd.
AddValue (
"txPowerStart",
"Minimum available transmission level (dbm)", txPowerStart);
103 cmd.
AddValue (
"txPowerEnd",
"Maximum available transmission level (dbm)", txPowerEnd);
104 cmd.
AddValue (
"nTxPowerLevels",
"Number of transmission power levels available between txPowerStart and txPowerEnd included", nTxPowerLevels);
105 cmd.
AddValue (
"txPowerLevel",
"Transmission power level", txPowerLevel);
106 cmd.
AddValue (
"idleCurrent",
"The radio Idle current in Ampere", idleCurrent);
107 cmd.
AddValue (
"txCurrent",
"The radio Tx current in Ampere", txCurrent);
108 cmd.
AddValue (
"verbose",
"turn on all WifiNetDevice log components", verbose);
109 cmd.
Parse (argc, argv);
137 wifiMac.
SetType (
"ns3::AdhocWifiMac");
142 positionAlloc->
Add (Vector (0.0, 0.0, 0.0));
143 positionAlloc->
Add (Vector (10.0, 0.0, 0.0));
153 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
158 std::string transportProto = std::string (
"ns3::UdpSocketFactory");
162 onOff.SetAttribute (
"PacketSize",
UintegerValue (packetSize));
163 onOff.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0.001]"));
165 apps = onOff.Install (c.
Get (0));
172 apps =
sink.Install (c.
Get (1));
181 basicSourceHelper.
Set (
"BasicEnergySourceInitialEnergyJ",
DoubleValue (initialEnergy));
182 basicSourceHelper.
Set (
"BasicEnergySupplyVoltageV",
DoubleValue (voltage));
184 radioEnergyHelper.
Set (
"IdleCurrentA",
DoubleValue (idleCurrent));
189 double eta =
DbmToW (txPowerStart) / ((txCurrent - idleCurrent) * voltage);
199 eSources.
Add (basicSourceHelper.
Install (*n));
203 for (uint32_t i = 0; i < (*n)->GetNDevices (); ++i)
210 radioEnergyHelper.
Install (wnd, eSources.
Get (eSources.
GetN () - 1));
216 eSources.
Get (0)->TraceConnectWithoutContext (
"RemainingEnergy",
MakeCallback (&RemainingEnergyTrace<0>));
217 eSources.
Get (1)->TraceConnectWithoutContext (
"RemainingEnergy",
MakeCallback (&RemainingEnergyTrace<1>));
void Set(std::string name, const AttributeValue &v)
DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< EnergySource > source) const
holds a vector of ns3::Application pointers.
Simulation virtual time values and global simulation resolution.
Assign WifiRadioEnergyModel to wifi devices.
static Ipv4Address GetAny(void)
Smart pointer class similar to boost::intrusive_ptr.
Holds a vector of ns3::EnergySource pointers.
void Add(EnergySourceContainer container)
holds a vector of std::pair of Ptr and interface index.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Ptr< YansWifiChannel > Create(void) const
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Hold variables of type string.
Make it easy to create and manage PHY objects for the yans model.
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
double DbmToW(double dBm)
Convert from dBm to Watts.
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
aggregate IP/TCP/UDP functionality to existing Nodes.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Class for representing data rates.
virtual void SetStandard(WifiPhyStandard standard)
void SetChannel(Ptr< YansWifiChannel > channel)
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
Hold an unsigned integer type.
Creates a BasicEnergySource object.
holds a vector of ns3::NetDevice pointers
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
Hold together all Wifi-related objects.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
void Connect(std::string path, const CallbackBase &cb)
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
double f(double x, void *params)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
WifiPhyState
The state of the PHY layer.
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
void Set(std::string name, const AttributeValue &v)
EnergySourceContainer Install(Ptr< Node > node) const
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
manage and create wifi channel objects for the yans model.
create MAC layers for a ns3::WifiNetDevice.
static Time Now(void)
Return the current simulation virtual time.
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
void PhyStateTrace(std::string context, Time start, Time duration, WifiPhyState state)
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr stored in this container.
void RemainingEnergyTrace(double oldValue, double newValue)
Helper class used to assign positions and mobility models to nodes.
Ipv4 addresses are stored in host order in this class.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
static void EnableLogComponents(void)
Helper to enable all WifiNetDevice log components with one statement.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
AttributeValue implementation for DataRate.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Time Seconds(double value)
Construct a Time in the indicated unit.
void Set(std::string name, const AttributeValue &v)
void Add(Vector v)
Add a position to the list of positions.
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
static const uint32_t packetSize
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
This class can be used to hold variables of floating point type such as 'double' or 'float'...
void SetTxCurrentModel(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Include Radiotap link layer information.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.