|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
51 #include "ns3/gnuplot.h"
52 #include "ns3/command-line.h"
53 #include "ns3/config.h"
54 #include "ns3/uinteger.h"
55 #include "ns3/boolean.h"
56 #include "ns3/double.h"
57 #include "ns3/string.h"
59 #include "ns3/yans-wifi-helper.h"
60 #include "ns3/mobility-helper.h"
61 #include "ns3/internet-stack-helper.h"
62 #include "ns3/ipv4-address-helper.h"
63 #include "ns3/on-off-helper.h"
64 #include "ns3/yans-wifi-channel.h"
65 #include "ns3/mobility-model.h"
66 #include "ns3/olsr-helper.h"
67 #include "ns3/ipv4-static-routing-helper.h"
68 #include "ns3/ipv4-list-routing-helper.h"
69 #include "ns3/rectangle.h"
70 #include "ns3/flow-monitor-helper.h"
84 bool CommandSetup (
int argc,
char **argv);
87 return (enableRouting == 1) ? 1 : 0;
91 return (enableMobility == 1) ? 1 : 0;
105 return outputFileName;
120 void CheckThroughput ();
155 samplingPeriod (0.1),
164 enableTracing (true),
165 enableFlowMon (false),
166 enableRouting (false),
167 enableMobility (false),
168 rtsThreshold (
"2200"),
170 rateManager (
"ns3::MinstrelWifiManager"),
171 outputFileName (
"minstrel")
179 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
192 while ((packet = socket->
Recv ()))
218 uint32_t totalNodes = c.
GetN ();
219 for (uint32_t i = 0; i < totalNodes; i++)
224 if ( i < totalNodes / 2 )
230 if ( i >= (uint32_t)(4 * totalNodes) / 10 )
238 if ( i < totalNodes / 2 )
244 if ( i >= (uint32_t)(4 * totalNodes) / 10 )
260 uint32_t limit = senderId + 2;
261 for (uint32_t i = senderId - 2; i <= limit; i++)
281 uint32_t totalNodes = c.
GetN ();
289 for (uint32_t i = 0; i < totalNodes / 3; i++)
315 double start = 0.0, stop;
318 for (uint32_t i = 0; i < c.
GetN (); i++)
325 destIndex = (uint32_t) uv->
GetValue ();
327 while ( (c.
Get (destIndex))->GetId () == sender->
GetId ());
347 static inline std::string
359 Ipv4Address ipv4AddrServer = iaddrServer.GetLocal ();
362 std::ostringstream oss;
363 oss <<
"Set up Server Device " << (server->
GetDevice (0))->GetAddress ()
364 <<
" with ip " << ipv4AddrServer
365 <<
" position (" << serverPos.x <<
"," << serverPos.y <<
"," << serverPos.z <<
")";
367 oss <<
"Set up Client Device " << (client->
GetDevice (0))->GetAddress ()
368 <<
" with ip " << ipv4AddrClient
369 <<
" position (" << clientPos.x <<
"," << clientPos.y <<
"," << clientPos.z <<
")"
380 Ipv4Address ipv4AddrServer = iaddrServer.GetLocal ();
422 list.Add (staticRouting, 0);
436 address.SetBase (
"10.0.0.0",
"255.255.255.0");
457 "Speed",
StringValue (
"ns3::ConstantRandomVariable[Constant=10]"),
458 "Pause",
StringValue (
"ns3::ConstantRandomVariable[Constant=0.2]"));
469 for (uint32_t i = 0; i < nodeSize - 1; i = i + 2)
524 phy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
549 Simulator::Destroy ();
560 cmd.AddValue (
"totalTime",
"simulation time",
totalTime);
579 cmd.Parse (argc, argv);
583 int main (
int argc,
char *argv[])
592 std::ofstream outfile ((
experiment.GetOutputFileName () +
".plt").c_str ());
603 wifiMac.
SetType (
"ns3::AdhocWifiMac",
holds a vector of ns3::NetDevice pointers
bool CommandSetup(int argc, char **argv)
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void SetStyle(enum Style style)
Make it easy to create and manage PHY objects for the YANS model.
Parse command-line arguments.
static std::string PrintPosition(Ptr< Node > client, Ptr< Node > server)
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.
std::string GetRateManager()
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
uint32_t GetId(void) const
void ReceivePacket(Ptr< Socket > socket)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Helper class that adds ns3::Ipv4ListRouting objects.
Ipv4Address GetAddress(void) const
Get the local address.
helps to create WifiNetDevice objects
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
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(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
AttributeValue implementation for Address.
AttributeValue implementation for Rectangle.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Ipv4 addresses are stored in host order in this class.
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
void Add(double x, double y)
Class to represent a 2D points plot.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetConstantRate(DataRate dataRate, uint32_t packetSize=512)
Helper function to set a constant rate source.
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
Access to the IPv4 forwarding table, interfaces, and configuration.
Helper class that adds ns3::Ipv4StaticRouting objects.
static Vector GetPosition(Ptr< Node > node)
Class for representing data rates.
Helper to enable IP flow monitoring on a set of Nodes.
Ptr< YansWifiChannel > Create(void) const
void experiment(std::string queue_disc_type)
Helper class that adds OLSR routing to nodes.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
a polymophic address class
a class to store IPv4 address information on an interface
Gnuplot2dDataset m_output
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
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.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Helper class for UAN CW MAC example.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Gnuplot2dDataset Run(const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, const WifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel)
NodeContainer GenerateNeighbors(NodeContainer c, uint32_t senderId)
Generate 1-hop and 2-hop neighbors of a node in grid topology.
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
void AddDataset(const GnuplotDataset &dataset)
Ptr< Socket > SetupPacketReceive(Ptr< Node > node)
std::string outputFileName
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Hold variables of type string.
void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but writes to a file instead.
Manage ASCII trace files for device models.
virtual Ipv4InterfaceAddress GetAddress(uint32_t interface, uint32_t addressIndex) const =0
Because addresses can be removed, the addressIndex is not guaranteed to be static across calls to thi...
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
void SelectSrcDest(NodeContainer c)
Sources and destinations are randomly selected such that a node may be the source for multiple destin...
static const uint32_t packetSize
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
holds a vector of ns3::Application pointers.
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
void ApplicationSetup(Ptr< Node > client, Ptr< Node > server, double start, double stop)
std::string GetOutputFileName()
Keep track of the current position and velocity of an object.
keep track of a set of node pointers.
Ipv4Address GetLocal(void) const
Get the local address.
void SetType(std::string type, Args &&... args)
Hold an unsigned integer type.
manage and create wifi channel objects for the YANS model.
create MAC layers for a ns3::WifiNetDevice.
std::string GetRtsThreshold()
aggregate IP/TCP/UDP functionality to existing Nodes.
double GetValue(double mean, double bound)
Get the next random value, as a double from the exponential distribution with the specified mean and ...
Experiment(std::string name)
Helper class used to assign positions and mobility models to nodes.
Ptr< Socket > SetupPacketReceive(Ptr< Node > node)
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
void AssignNeighbors(NodeContainer c)
Take the grid map, divide it into 4 quadrants Assign all nodes from each quadrant to a specific conta...