31 #include "ns3/applications-module.h"
32 #include "ns3/core-module.h"
33 #include "ns3/dsr-module.h"
34 #include "ns3/internet-module.h"
35 #include "ns3/mobility-module.h"
36 #include "ns3/network-module.h"
37 #include "ns3/yans-wifi-helper.h"
46 main(
int argc,
char* argv[])
80 double TotalTime = 600.0;
81 double dataTime = 500.0;
84 double dataStart = 100.0;
87 double pauseTime = 0.0;
88 double nodeSpeed = 20.0;
89 double txpDistance = 250.0;
91 std::string rate =
"0.512kbps";
92 std::string dataMode(
"DsssRate11Mbps");
93 std::string phyMode(
"DsssRate11Mbps");
97 cmd.AddValue(
"nWifis",
"Number of wifi nodes", nWifis);
98 cmd.AddValue(
"nSinks",
"Number of SINK traffic nodes", nSinks);
99 cmd.AddValue(
"rate",
"CBR traffic rate(in kbps), Default:8", rate);
100 cmd.AddValue(
"nodeSpeed",
"Node speed in RandomWayPoint model, Default:20", nodeSpeed);
102 cmd.AddValue(
"txpDistance",
"Specify node's transmit range, Default:300", txpDistance);
103 cmd.AddValue(
"pauseTime",
"pauseTime for mobility model, Default: 0", pauseTime);
104 cmd.Parse(argc, argv);
110 adhocNodes.
Create(nWifis);
113 NS_LOG_INFO(
"setting the default phy and channel parameters");
120 NS_LOG_INFO(
"setting the default phy and channel parameters ");
134 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
140 wifiMac.
SetType(
"ns3::AdhocWifiMac");
141 allDevices =
wifi.Install(wifiPhy, wifiMac, adhocNodes);
151 pos.
SetTypeId(
"ns3::RandomRectanglePositionAllocator");
152 pos.
Set(
"X",
StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=300.0]"));
153 pos.
Set(
"Y",
StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=1500.0]"));
156 std::ostringstream speedUniformRandomVariableStream;
157 speedUniformRandomVariableStream <<
"ns3::UniformRandomVariable[Min=0.0|Max=" << nodeSpeed
160 std::ostringstream pauseConstantRandomVariableStream;
161 pauseConstantRandomVariableStream <<
"ns3::ConstantRandomVariable[Constant=" << pauseTime
165 "ns3::RandomWaypointMobilityModel",
169 StringValue(speedUniformRandomVariableStream.str()),
171 StringValue(pauseConstantRandomVariableStream.str()),
174 adhocMobility.
Install(adhocNodes);
180 dsrMain.
Install(dsr, adhocNodes);
184 address.SetBase(
"10.1.1.0",
"255.255.255.0");
186 allInterfaces =
address.Assign(allDevices);
189 double randomStartTime =
190 (1 / ppers) / nSinks;
192 for (uint32_t i = 0; i < nSinks; ++i)
202 onoff1.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1.0]"));
203 onoff1.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0.0]"));
205 onoff1.SetAttribute(
"DataRate", DataRateValue(
DataRate(rate)));
209 apps1.
Stop(
Seconds(dataTime + i * randomStartTime));
a polymophic address class
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.
void EnableAsciiAll(std::string prefix)
Enable ascii trace output on each device (which is of the appropriate type) in the set of all nodes c...
Manage ASCII trace files for device models.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
DSR helper class to manage creation of DSR routing instance and to insert it on a node as a sublayer ...
Helper class that adds DSR routing to nodes.
void Install(DsrHelper &dsrHelper, NodeContainer nodes)
Install routing to the nodes.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static Ipv4Address GetAny()
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class used to assign positions and mobility models to nodes.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetMobilityModel(std::string type, Ts &&... args)
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
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.
Hold objects of type Ptr<T>.
Allocate a set of positions.
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
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.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
manage and create wifi channel objects for the YANS model.
void SetPropagationDelay(std::string name, Ts &&... args)
void AddPropagationLoss(std::string name, Ts &&... args)
Ptr< YansWifiChannel > Create() const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
void SetDefault(std::string name, const AttributeValue &value)
#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.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
@ LOG_LEVEL_ALL
Print everything.
static const uint32_t packetSize
Packet size generated at the AP.
Ptr< PacketSink > sink
Pointer to the packet sink application.