23#include "ns3/core-module.h"
24#include "ns3/internet-module.h"
25#include "ns3/mobility-module.h"
26#include "ns3/network-module.h"
27#include "ns3/stats-module.h"
28#include "ns3/wifi-module.h"
47 NS_LOG_INFO(
"Sent frame counted in " << datac->GetKey());
52main(
int argc,
char* argv[])
54 double distance = 50.0;
55 std::string format(
"omnet");
58 std::string strategy(
"wifi-default");
63 std::stringstream sstr;
64 sstr <<
"run-" << time(
nullptr);
70 cmd.AddValue(
"distance",
"Distance apart to place nodes (in meters).", distance);
71 cmd.AddValue(
"format",
"Format to use for data output.", format);
72 cmd.AddValue(
"experiment",
"Identifier for experiment.",
experiment);
73 cmd.AddValue(
"strategy",
"Identifier for strategy.", strategy);
74 cmd.AddValue(
"run",
"Identifier for run.", runID);
75 cmd.Parse(argc, argv);
77 if (format !=
"omnet" && format !=
"db")
79 NS_LOG_ERROR(
"Unknown output format '" << format <<
"'");
92 std::stringstream sstr(
"");
104 NS_LOG_INFO(
"Installing WiFi and Internet stack.");
107 wifiMac.
SetType(
"ns3::AdhocWifiMac");
116 ipAddrs.
SetBase(
"192.168.0.0",
"255.255.255.0");
117 ipAddrs.
Assign(nodeDevices);
122 NS_LOG_INFO(
"Installing static mobility; distance " << distance <<
" .");
125 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
126 positionAlloc->Add(Vector(0.0, distance, 0.0));
127 mobility.SetPositionAllocator(positionAlloc);
136 appSource->AddApplication(sender);
137 sender->SetStartTime(
Seconds(1));
141 appSink->AddApplication(receiver);
142 receiver->SetStartTime(
Seconds(0));
144 Config::Set(
"/NodeList/*/ApplicationList/*/$Sender/Destination",
156 data.AddMetadata(
"author",
"tjkopena");
163 totalTx->SetKey(
"wifi-tx-frames");
164 totalTx->SetContext(
"node[0]");
165 Config::Connect(
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
167 data.AddDataCalculator(totalTx);
174 totalRx->SetKey(
"wifi-rx-frames");
175 totalRx->SetContext(
"node[1]");
176 Config::Connect(
"/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
178 data.AddDataCalculator(totalRx);
184 appTx->SetKey(
"sender-tx-packets");
185 appTx->SetContext(
"node[0]");
188 data.AddDataCalculator(appTx);
195 appRx->SetKey(
"receiver-rx-packets");
196 appRx->SetContext(
"node[1]");
197 receiver->SetCounter(appRx);
198 data.AddDataCalculator(appRx);
220 appTxPkts->SetKey(
"tx-pkt-size");
221 appTxPkts->SetContext(
"node[0]");
224 data.AddDataCalculator(appTxPkts);
231 delayStat->SetKey(
"delay");
232 delayStat->SetContext(
".");
233 receiver->SetDelayTracker(delayStat);
234 data.AddDataCalculator(delayStat);
248 if (format ==
"omnet")
250 NS_LOG_INFO(
"Creating omnet formatted data output.");
253 else if (format ==
"db")
256 NS_LOG_INFO(
"Creating sqlite formatted data output.");
269 output->Output(
data);
Parse command-line arguments.
Template class CounterCalculator.
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.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
AttributeValue implementation for Ipv4Address.
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
static Ptr< Node > GetNode(uint32_t n)
void PacketUpdate(std::string path, Ptr< const Packet > packet)
Increments the packet counter by one.
void PacketUpdate(std::string path, Ptr< const Packet > packet)
Increments the packet stats by the size of the packet.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
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)
void experiment(std::string queue_disc_type)
void Connect(std::string path, const CallbackBase &cb)
void Set(std::string path, const AttributeValue &value)
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#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.
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
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.
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...
void TxCallback(Ptr< CounterCalculator< uint32_t > > datac, std::string path, Ptr< const Packet > packet)
Function called when a packet is transmitted.