60 #include "ns3/animation-interface.h"
61 #include "ns3/command-line.h"
62 #include "ns3/csma-helper.h"
63 #include "ns3/internet-stack-helper.h"
64 #include "ns3/ipv4-address-helper.h"
65 #include "ns3/mobility-helper.h"
66 #include "ns3/olsr-helper.h"
67 #include "ns3/on-off-helper.h"
68 #include "ns3/packet-sink-helper.h"
69 #include "ns3/qos-txop.h"
71 #include "ns3/string.h"
72 #include "ns3/yans-wifi-channel.h"
73 #include "ns3/yans-wifi-helper.h"
92 Vector position = model->GetPosition();
93 std::cout <<
"CourseChange " << path <<
" x=" << position.x <<
", y=" << position.y
94 <<
", z=" << position.z << std::endl;
98 main(
int argc,
char* argv[])
104 uint32_t backboneNodes = 10;
105 uint32_t infraNodes = 2;
106 uint32_t lanNodes = 2;
108 bool useCourseChangeCallback =
false;
123 cmd.AddValue(
"backboneNodes",
"number of backbone nodes", backboneNodes);
124 cmd.AddValue(
"infraNodes",
"number of leaf nodes", infraNodes);
125 cmd.AddValue(
"lanNodes",
"number of LAN nodes", lanNodes);
126 cmd.AddValue(
"stopTime",
"simulation stop time (seconds)",
stopTime);
127 cmd.AddValue(
"useCourseChangeCallback",
128 "whether to enable course change tracing",
129 useCourseChangeCallback);
135 cmd.Parse(argc, argv);
139 std::cout <<
"Use a simulation stop time >= 10 seconds" << std::endl;
153 backbone.
Create(backboneNodes);
160 mac.SetType(
"ns3::AdhocWifiMac");
161 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
172 NS_LOG_INFO(
"Enabling OLSR routing on all backbone nodes");
186 ipAddrs.
SetBase(
"192.168.0.0",
"255.255.255.0");
187 ipAddrs.
Assign(backboneDevices);
194 mobility.SetPositionAllocator(
"ns3::GridPositionAllocator",
207 mobility.SetMobilityModel(
"ns3::RandomDirection2dMobilityModel",
209 RectangleValue(
Rectangle(-500, 500, -500, 500)),
211 StringValue(
"ns3::ConstantRandomVariable[Constant=2]"),
213 StringValue(
"ns3::ConstantRandomVariable[Constant=0.2]"));
224 ipAddrs.
SetBase(
"172.16.0.0",
"255.255.255.0");
226 for (uint32_t i = 0; i < backboneNodes; ++i)
228 NS_LOG_INFO(
"Configuring local area network for backbone node " << i);
235 newLanNodes.
Create(lanNodes - 1);
243 csma.SetChannelAttribute(
"DataRate", DataRateValue(
DataRate(5000000)));
254 ipAddrs.
Assign(lanDevices);
266 for (uint32_t j = 0; j < newLanNodes.
GetN(); ++j)
268 subnetAlloc->Add(Vector(0.0, j * 10 + 10, 0.0));
273 mobilityLan.
Install(newLanNodes);
284 ipAddrs.
SetBase(
"10.0.0.0",
"255.255.255.0");
286 for (uint32_t i = 0; i < backboneNodes; ++i)
288 NS_LOG_INFO(
"Configuring wireless network for backbone node " << i);
295 stas.
Create(infraNodes - 1);
305 std::string ssidString(
"wifi-infra");
306 std::stringstream ss;
308 ssidString += ss.str();
311 macInfra.
SetType(
"ns3::StaWifiMac",
"Ssid", SsidValue(
ssid));
314 macInfra.
SetType(
"ns3::ApWifiMac",
"Ssid", SsidValue(
ssid));
326 ipAddrs.
Assign(infraDevices);
337 for (uint32_t j = 0; j < infra.GetN(); ++j)
339 subnetAlloc->Add(Vector(0.0, j, 0.0));
341 mobility.PushReferenceMobilityModel(backbone.
Get(i));
342 mobility.SetPositionAllocator(subnetAlloc);
343 mobility.SetMobilityModel(
"ns3::RandomDirection2dMobilityModel",
345 RectangleValue(
Rectangle(-10, 10, -10, 10)),
347 StringValue(
"ns3::ConstantRandomVariable[Constant=3]"),
349 StringValue(
"ns3::ConstantRandomVariable[Constant=0.4]"));
370 NS_ASSERT(lanNodes > 1 && infraNodes > 1);
375 uint32_t lastNodeIndex =
376 backboneNodes + backboneNodes * (lanNodes - 1) + backboneNodes * (infraNodes - 1) - 1;
389 apps =
sink.Install(appSink);
407 csma.EnableAsciiAll(stream);
408 internet.EnableAsciiIpv4All(stream);
411 csma.EnablePcapAll(
"mixed-wireless",
false);
413 wifiPhy.
EnablePcap(
"mixed-wireless", backboneDevices,
false);
417 if (useCourseChangeCallback)
a polymophic address class
Interface to network animator.
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.
build a set of CsmaNetDevice objects
This class can be used to hold variables of floating point type such as 'double' or 'float'.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address NewNetwork()
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
Access to the IPv4 forwarding table, interfaces, and configuration.
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 PushReferenceMobilityModel(Ptr< Object > reference)
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
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.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
static Ptr< Node > GetNode(uint32_t n)
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Helper class that adds OLSR routing to nodes.
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.
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
Smart pointer class similar to boost::intrusive_ptr.
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.
The IEEE 802.11 SSID Information Element.
Hold variables of type string.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
@ 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 SetChannel(Ptr< YansWifiChannel > channel)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
void SetDefault(std::string name, const AttributeValue &value)
void Connect(std::string path, const CallbackBase &cb)
#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.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
AnimationInterface * anim
static void CourseChangeCallback(std::string path, Ptr< const MobilityModel > model)
This function will be used below as a trace sink, if the command-line argument or default value "useC...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...
Ptr< PacketSink > sink
Pointer to the packet sink application.