31 #include "ns3/core-module.h"
32 #include "ns3/network-module.h"
33 #include "ns3/applications-module.h"
34 #include "ns3/mobility-module.h"
35 #include "ns3/config-store-module.h"
36 #include "ns3/wifi-module.h"
37 #include "ns3/internet-module.h"
38 #include "ns3/dsdv-helper.h"
73 void CaseRun (uint32_t nWifis,
79 uint32_t periodicUpdateInterval,
80 uint32_t settlingTime,
83 std::string CSVfileName);
111 void CreateDevices (std::string tr_name);
116 void InstallInternetStack (std::string tr_name);
118 void InstallApplications ();
120 void SetupMobility ();
134 void CheckThroughput ();
138 int main (
int argc,
char **argv)
141 uint32_t nWifis = 30;
142 uint32_t nSinks = 10;
143 double totalTime = 100.0;
144 std::string rate (
"8kbps");
145 std::string phyMode (
"DsssRate11Mbps");
146 uint32_t nodeSpeed = 10;
147 std::string appl =
"all";
148 uint32_t periodicUpdateInterval = 15;
149 uint32_t settlingTime = 6;
150 double dataStart = 50.0;
151 bool printRoutingTable =
true;
152 std::string CSVfileName =
"DsdvManetExample.csv";
155 cmd.
AddValue (
"nWifis",
"Number of wifi nodes[Default:30]", nWifis);
156 cmd.
AddValue (
"nSinks",
"Number of wifi sink nodes[Default:10]", nSinks);
157 cmd.
AddValue (
"totalTime",
"Total Simulation time[Default:100]", totalTime);
158 cmd.
AddValue (
"phyMode",
"Wifi Phy mode[Default:DsssRate11Mbps]", phyMode);
159 cmd.
AddValue (
"rate",
"CBR traffic rate[Default:8kbps]", rate);
160 cmd.
AddValue (
"nodeSpeed",
"Node speed in RandomWayPoint model[Default:10]", nodeSpeed);
161 cmd.
AddValue (
"periodicUpdateInterval",
"Periodic Interval Time[Default=15]", periodicUpdateInterval);
162 cmd.
AddValue (
"settlingTime",
"Settling Time before sending out an update for changed metric[Default=6]", settlingTime);
163 cmd.
AddValue (
"dataStart",
"Time at which nodes start to transmit data[Default=50.0]", dataStart);
164 cmd.
AddValue (
"printRoutingTable",
"print routing table for nodes[Default:1]", printRoutingTable);
165 cmd.
AddValue (
"CSVfileName",
"The name of the CSV output file name[Default:DsdvManetExample.csv]", CSVfileName);
166 cmd.
Parse (argc, argv);
168 std::ofstream out (CSVfileName.c_str ());
169 out <<
"SimulationSecond," <<
171 "PacketsReceived," <<
184 test.
CaseRun (nWifis, nSinks, totalTime, rate, phyMode, nodeSpeed, periodicUpdateInterval,
185 settlingTime, dataStart, printRoutingTable, CSVfileName);
201 while ((packet = socket->
Recv ()))
227 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
238 std::string phyMode, uint32_t nodeSpeed, uint32_t periodicUpdateInterval, uint32_t settlingTime,
239 double dataStart,
bool printRoutes, std::string CSVfileName)
253 std::stringstream ss;
255 std::string t_nodes = ss.str ();
257 std::stringstream ss3;
259 std::string sTotalTime = ss3.str ();
261 std::string tr_name =
"Dsdv_Manet_" + t_nodes +
"Nodes_" + sTotalTime +
"SimTime";
262 std::cout <<
"Trace file generated is " << tr_name <<
".tr\n";
270 std::cout <<
"\nStarting simulation for " << m_totalTime <<
" s ...\n";
274 Simulator::Stop (
Seconds (m_totalTime));
276 Simulator::Destroy ();
282 std::cout <<
"Creating " << (unsigned)
m_nWifis <<
" nodes.\n";
292 pos.
SetTypeId (
"ns3::RandomRectanglePositionAllocator");
293 pos.
Set (
"X",
StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1000.0]"));
294 pos.
Set (
"Y",
StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1000.0]"));
296 std::ostringstream speedConstantRandomVariableStream;
297 speedConstantRandomVariableStream <<
"ns3::ConstantRandomVariable[Constant="
303 "Pause",
StringValue (
"ns3::ConstantRandomVariable[Constant=2.0]"),
"PositionAllocator",
PointerValue (taPositionAlloc));
312 wifiMac.
SetType (
"ns3::AdhocWifiMac");
339 address.
SetBase (
"10.1.1.0",
"255.255.255.0");
351 for (uint32_t i = 0; i <=
m_nSinks - 1; i++ )
358 for (uint32_t clientNode = 0; clientNode <=
m_nWifis - 1; clientNode++ )
360 for (uint32_t j = 0; j <=
m_nSinks - 1; j++ )
364 onoff1.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0.0]"));
void AddPropagationLoss(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())
Ptr< Socket > SetupPacketReceive(Ipv4Address addr, Ptr< Node > node)
Setup packet receivers.
holds a vector of ns3::Application pointers.
Ipv4InterfaceContainer interfaces
the collection of interfaces
Manage ASCII trace files for device models.
holds a vector of std::pair of Ptr and interface index.
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.
void CaseRun(uint32_t nWifis, uint32_t nSinks, double totalTime, std::string rate, std::string phyMode, uint32_t nodeSpeed, uint32_t periodicUpdateInterval, uint32_t settlingTime, double dataStart, bool printRoutes, std::string CSVfileName)
Run function.
uint32_t packetsReceived
total packets received by all nodes
void ReceivePacket(Ptr< Socket > socket)
void SetupMobility()
Setup mobility model.
std::string m_CSVfileName
CSV file name.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
double m_totalTime
total simulation time (in seconds)
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
aggregate IP/TCP/UDP functionality to existing Nodes.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void InstallApplications()
Create data sinks and sources.
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. ...
helps to create WifiNetDevice objects
double m_dataStart
time to start data transmissions (seconds)
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
a polymophic address class
void CreateDevices(std::string tr_name)
Create and initialize all devices.
void ReceivePacket(Ptr< Socket > socket)
Packet receive function.
virtual void SetStandard(WifiPhyStandard standard)
void SetChannel(Ptr< YansWifiChannel > channel)
NS_ASSERT_MSG(false,"Ipv4AddressGenerator::MaskToIndex(): Impossible")
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
uint32_t m_nodeSpeed
mobility speed
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
AttributeValue implementation for Time.
NodeContainer nodes
the collection of nodes
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
std::string m_rate
network bandwidth
uint32_t m_settlingTime
routing setting time
holds a vector of ns3::NetDevice pointers
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
NetDeviceContainer devices
the collection of devices
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.
Access to the IPv4 forwarding table, interfaces, and configuration.
uint32_t m_nSinks
number of receiver nodes
Ptr< Socket > SetupPacketReceive(Ptr< Node > node)
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Hold objects of type Ptr.
uint32_t m_nWifis
total number of nodes
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
bool m_printRoutes
print routing table
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
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...
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionaly.
uint32_t bytesTotal
total bytes received by all nodes
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
manage and create wifi channel objects for the yans model.
void InstallInternetStack(std::string tr_name)
Create network.
create MAC layers for a ns3::WifiNetDevice.
std::string m_phyMode
remote station manager data mode
void CreateNodes()
Create and initialize all nodes.
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())
static void SetSeed(uint32_t seed)
Set the seed.
Helper class used to assign positions and mobility models to nodes.
Instantiate subclasses of ns3::Object.
void Set(std::string name, const AttributeValue &value)
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...
uint32_t m_periodicUpdateInterval
routing update interval
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
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 SetDefault(std::string name, const AttributeValue &value)
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.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
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...
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetPropagationDelay(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())
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
Helper class that adds DSDV routing to nodes.
a unique identifier for an interface.
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
static void PrintRoutingTableAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of all nodes at a particular time.
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Allocate a set of positions.
void CheckThroughput()
Check network throughput.