7#include "ns3/boolean.h"
8#include "ns3/command-line.h"
10#include "ns3/double.h"
11#include "ns3/flow-monitor-helper.h"
12#include "ns3/gnuplot.h"
13#include "ns3/internet-stack-helper.h"
14#include "ns3/ipv4-address-helper.h"
15#include "ns3/ipv4-list-routing-helper.h"
16#include "ns3/ipv4-static-routing-helper.h"
18#include "ns3/mobility-helper.h"
19#include "ns3/mobility-model.h"
20#include "ns3/olsr-helper.h"
21#include "ns3/on-off-helper.h"
22#include "ns3/rectangle.h"
23#include "ns3/string.h"
24#include "ns3/uinteger.h"
25#include "ns3/yans-wifi-channel.h"
26#include "ns3/yans-wifi-helper.h"
220 void CheckThroughput();
309 while ((packet = socket->Recv()))
330 for (
uint32_t i = 0; i < totalNodes; i++)
335 if (i < totalNodes / 2)
341 if (i >= (
uint32_t)(4 * totalNodes) / 10)
349 if (i < totalNodes / 2)
355 if (i >= (
uint32_t)(4 * totalNodes) / 10)
368 for (
uint32_t i = senderId - 2; i <= limit; i++)
386 uvSrc->SetAttribute(
"Max",
DoubleValue(totalNodes / 2 - 1));
388 uvDest->SetAttribute(
"Min",
DoubleValue(totalNodes / 2));
389 uvDest->SetAttribute(
"Max",
DoubleValue(totalNodes));
391 for (
uint32_t i = 0; i < totalNodes / 3; i++)
416 stop = start + ev->GetValue();
421 destIndex = (
uint32_t)uv->GetValue();
422 }
while ((c.
Get(destIndex))->GetId() == sender->GetId());
445 Vector serverPos = server->GetObject<
MobilityModel>()->GetPosition();
446 Vector clientPos = client->GetObject<
MobilityModel>()->GetPosition();
454 Ipv4Address ipv4AddrServer = iaddrServer.GetLocal();
457 std::ostringstream oss;
458 oss <<
"Set up Server Device " << (server->GetDevice(0))->GetAddress() <<
" with ip "
459 << ipv4AddrServer <<
" position (" << serverPos.x <<
"," << serverPos.y <<
","
460 << serverPos.z <<
")";
462 oss <<
"Set up Client Device " << (client->GetDevice(0))->GetAddress() <<
" with ip "
463 << ipv4AddrClient <<
" position (" << clientPos.x <<
"," << clientPos.y <<
","
464 << clientPos.z <<
")"
475 Ipv4Address ipv4AddrServer = iaddrServer.GetLocal();
482 onoff.SetConstantRate(
DataRate(54000000));
505 phy.SetChannel(wifiChannel.
Create());
516 list.Add(staticRouting, 0);
524 internet.SetRoutingHelper(list);
529 address.SetBase(
"10.0.0.0",
"255.255.255.0");
532 ipInterfaces = address.Assign(devices);
558 StringValue(
"ns3::ConstantRandomVariable[Constant=10]"),
560 StringValue(
"ns3::ConstantRandomVariable[Constant=0.2]"));
571 for (
uint32_t i = 0; i < nodeSize - 1; i = i + 2)
669 cmd.AddValue(
"packetSize",
"packet size",
m_packetSize);
670 cmd.AddValue(
"totalTime",
"simulation time",
m_totalTime);
687 cmd.AddValue(
"scenario",
"scenario ",
m_scenario);
689 cmd.Parse(argc, argv);
696main(
int argc,
char* argv[])
704 std::ofstream outfile(
experiment.GetOutputFileName() +
".plt");
717 wifi.SetRemoteStationManager(
experiment.GetRateManager());
726 dataset =
experiment.Run(wifi, wifiPhy, wifiMac, wifiChannel, mobility);
Ptr< Socket > SetupPacketReceive(Ptr< Node > node)
Create a socket and prepare it for packet reception.
void AssignNeighbors(NodeContainer c)
Take the grid map, divide it into 4 quadrants Assign all nodes from each quadrant to a specific conta...
void SelectSrcDest(NodeContainer c)
Sources and destinations are randomly selected such that a node may be the source for multiple destin...
std::string GetOutputFileName() const
Get the Output File Name.
NodeContainer m_containerA
Node containers for each quadrant.
std::string m_outputFileName
Output file name.
void CheckThroughput()
Calculate the throughput.
NodeContainer m_containerB
Node containers for each quadrant.
std::string GetRtsThreshold() const
Get the RTS Threshold.
NodeContainer GenerateNeighbors(NodeContainer c, uint32_t senderId)
Generate 1-hop and 2-hop neighbors of a node in grid topology.
std::string m_rtsThreshold
Rts threshold.
bool m_enablePcap
True if PCAP output is enabled.
uint32_t m_scenario
Scenario number.
bool m_enableTracing
True if tracing output is enabled.
uint32_t m_bytesTotal
Total number of received bytes.
Gnuplot2dDataset m_output
Output dataset.
bool m_enableMobility
True if mobility is enabled.
std::string m_rateManager
Rate manager.
void ReceivePacket(Ptr< Socket > socket)
Receive a packet.
bool m_enableRouting
True if routing is enabled.
uint32_t m_nodeDistance
Node distance.
NodeContainer m_containerC
Node containers for each quadrant.
uint32_t GetScenario() const
Get the Scenario number.
double m_totalTime
Total experiment time.
uint32_t m_gridSize
Grid size.
uint32_t m_packetSize
Packet size.
NodeContainer m_containerD
Node containers for each quadrant.
void ApplicationSetup(Ptr< Node > client, Ptr< Node > server, double start, double stop)
Setup the application in the nodes.
Ptr< Socket > SetupPacketReceive(Ptr< Node > node)
Setup the receiving socket.
uint32_t m_port
Listening port.
Gnuplot2dDataset Run(const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, const WifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel, const MobilityHelper &mobility)
Run an experiment.
bool IsMobility() const
Check if mobility is enabled.
bool m_enableFlowMon
True if FlowMon is enabled.
double m_expMean
Exponential parameter for sending packets.
bool CommandSetup(int argc, char **argv)
Setup the experiment from the command line arguments.
std::string GetRateManager() const
Get the Rate Manager.
void SendMultiDestinations(Ptr< Node > sender, NodeContainer c)
A sender node will set up a flow to each of the its neighbors in its quadrant randomly.
double m_samplingPeriod
Sampling period.
bool IsRouting() const
Check if routing is enabled.
a polymophic address class
AttributeValue implementation for Address.
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.
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.
Class for representing data rates.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Helper to enable IP flow monitoring on a set of Nodes.
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but writes to a file instead.
Class to represent a 2D points plot.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
void AddDataset(const GnuplotDataset &dataset)
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
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()
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to store IPv4 address information on an interface
Ipv4Address GetAddress() const
Get the local address.
Ipv4Address GetLocal() const
Get the local address.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Helper class that adds ns3::Ipv4ListRouting objects.
Helper class that adds ns3::Ipv4StaticRouting objects.
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)
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Helper class that adds OLSR routing to nodes.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Smart pointer class similar to boost::intrusive_ptr.
AttributeValue implementation for Rectangle.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
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.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Hold variables of type string.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
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 experiment(std::string queue_disc_type)
void ReceivePacket(Ptr< Socket > socket)
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...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Time Seconds(double value)
Construct a Time in the indicated unit.
std::string PrintPosition(Ptr< Node > client, Ptr< Node > server)
Print the position of two nodes.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< PacketSink > sink
Pointer to the packet sink application.