|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
61 #include "ns3/command-line.h"
62 #include "ns3/string.h"
63 #include "ns3/yans-wifi-helper.h"
65 #include "ns3/mobility-helper.h"
66 #include "ns3/internet-stack-helper.h"
67 #include "ns3/ipv4-address-helper.h"
68 #include "ns3/on-off-helper.h"
69 #include "ns3/yans-wifi-channel.h"
70 #include "ns3/qos-txop.h"
71 #include "ns3/packet-sink-helper.h"
72 #include "ns3/olsr-helper.h"
73 #include "ns3/csma-helper.h"
74 #include "ns3/animation-interface.h"
91 std::cout <<
"CourseChange " << path <<
" x=" << position.x <<
", y=" << position.y <<
", z=" << position.z << std::endl;
95 main (
int argc,
char *argv[])
101 uint32_t backboneNodes = 10;
102 uint32_t infraNodes = 2;
103 uint32_t lanNodes = 2;
105 bool useCourseChangeCallback =
false;
120 cmd.AddValue (
"backboneNodes",
"number of backbone nodes", backboneNodes);
121 cmd.AddValue (
"infraNodes",
"number of leaf nodes", infraNodes);
122 cmd.AddValue (
"lanNodes",
"number of LAN nodes", lanNodes);
123 cmd.AddValue (
"stopTime",
"simulation stop time (seconds)",
stopTime);
124 cmd.AddValue (
"useCourseChangeCallback",
"whether to enable course change tracing", useCourseChangeCallback);
130 cmd.Parse (argc, argv);
134 std::cout <<
"Use a simulation stop time >= 10 seconds" << std::endl;
148 backbone.
Create (backboneNodes);
155 mac.SetType (
"ns3::AdhocWifiMac");
156 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
166 NS_LOG_INFO (
"Enabling OLSR routing on all backbone nodes");
180 ipAddrs.
SetBase (
"192.168.0.0",
"255.255.255.0");
181 ipAddrs.
Assign (backboneDevices);
188 mobility.SetPositionAllocator (
"ns3::GridPositionAllocator",
195 mobility.SetMobilityModel (
"ns3::RandomDirection2dMobilityModel",
197 "Speed",
StringValue (
"ns3::ConstantRandomVariable[Constant=2]"),
198 "Pause",
StringValue (
"ns3::ConstantRandomVariable[Constant=0.2]"));
209 ipAddrs.
SetBase (
"172.16.0.0",
"255.255.255.0");
212 for (uint32_t i = 0; i < backboneNodes; ++i)
214 NS_LOG_INFO (
"Configuring local area network for backbone node " << i);
221 newLanNodes.
Create (lanNodes - 1);
229 csma.SetChannelAttribute (
"DataRate",
236 internet.
Install (newLanNodes);
241 ipAddrs.
Assign (lanDevices);
253 CreateObject<ListPositionAllocator> ();
254 for (uint32_t j = 0; j < newLanNodes.
GetN (); ++j)
256 subnetAlloc->
Add (Vector (0.0, j * 10 + 10, 0.0));
261 mobilityLan.
Install (newLanNodes);
272 ipAddrs.
SetBase (
"10.0.0.0",
"255.255.255.0");
274 for (uint32_t i = 0; i < backboneNodes; ++i)
276 NS_LOG_INFO (
"Configuring wireless network for backbone node " << i);
283 stas.
Create (infraNodes - 1);
293 std::string ssidString (
"wifi-infra");
294 std::stringstream ss;
296 ssidString += ss.str ();
300 macInfra.
SetType (
"ns3::StaWifiMac",
304 macInfra.
SetType (
"ns3::ApWifiMac",
317 ipAddrs.
Assign (infraDevices);
328 CreateObject<ListPositionAllocator> ();
329 for (uint32_t j = 0; j < infra.GetN (); ++j)
331 subnetAlloc->
Add (Vector (0.0, j, 0.0));
333 mobility.PushReferenceMobilityModel (backbone.
Get (i));
334 mobility.SetPositionAllocator (subnetAlloc);
335 mobility.SetMobilityModel (
"ns3::RandomDirection2dMobilityModel",
337 "Speed",
StringValue (
"ns3::ConstantRandomVariable[Constant=3]"),
338 "Pause",
StringValue (
"ns3::ConstantRandomVariable[Constant=0.4]"));
359 NS_ASSERT (lanNodes > 1 && infraNodes > 1);
364 uint32_t lastNodeIndex = backboneNodes + backboneNodes * (lanNodes - 1) + backboneNodes * (infraNodes - 1) - 1;
379 apps =
sink.Install (appSink);
397 csma.EnableAsciiAll (stream);
401 csma.EnablePcapAll (
"mixed-wireless",
false);
403 wifiPhy.
EnablePcap (
"mixed-wireless", backboneDevices,
false);
407 if (useCourseChangeCallback ==
true)
holds a vector of ns3::NetDevice pointers
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
AttributeValue implementation for DataRate.
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
Make it easy to create and manage PHY objects for the YANS model.
Parse command-line arguments.
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 Add(Vector v)
Add a position to the list of positions.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
Ipv4Address NewNetwork(void)
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
uint32_t GetId(void) const
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.
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.
void EnableAsciiIpv4All(std::string prefix)
Enable ascii trace output on all Ipv4 and interface pairs existing in the set of all nodes created in...
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
AttributeValue implementation for Rectangle.
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.
Interface to network animator.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
void SetChannel(Ptr< YansWifiChannel > channel)
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.
AttributeValue implementation for Ssid.
build a set of CsmaNetDevice objects
The IEEE 802.11 SSID Information Element.
void PushReferenceMobilityModel(Ptr< Object > reference)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Access to the IPv4 forwarding table, interfaces, and configuration.
Smart pointer class similar to boost::intrusive_ptr.
Class for representing data rates.
Ptr< YansWifiChannel > Create(void) const
Helper class that adds OLSR routing to nodes.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
a polymophic address class
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.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
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...
static void Run(void)
Run the simulation.
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())
Hold variables of type string.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Manage ASCII trace files for device models.
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
void Connect(std::string path, const CallbackBase &cb)
static Ipv4Address GetAny(void)
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)
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
holds a vector of ns3::Application pointers.
AttributeValue implementation for Time.
keep track of a set of node pointers.
void SetType(std::string type, Args &&... args)
Hold an unsigned integer type.
static void CourseChangeCallback(std::string path, Ptr< const MobilityModel > model)
manage and create wifi channel objects for the YANS model.
create MAC layers for a ns3::WifiNetDevice.
void SetDefault(std::string name, const AttributeValue &value)
aggregate IP/TCP/UDP functionality to existing Nodes.
Vector GetPosition(void) const
static Ptr< Node > GetNode(uint32_t n)
Helper class used to assign positions and mobility models to nodes.
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const