34#include "ns3/core-module.h"
35#include "ns3/internet-module.h"
36#include "ns3/mobility-module.h"
37#include "ns3/network-module.h"
38#include "ns3/stats-module.h"
39#include "ns3/yans-wifi-helper.h"
58 NS_LOG_INFO(
"Sent frame counted in " << datac->GetKey());
67main(
int argc,
char* argv[])
69 double distance = 50.0;
70 std::string format(
"omnet");
73 std::string strategy(
"wifi-default");
78 std::stringstream sstr;
79 sstr <<
"run-" << time(
nullptr);
85 cmd.AddValue(
"distance",
"Distance apart to place nodes (in meters).", distance);
86 cmd.AddValue(
"format",
"Format to use for data output.", format);
87 cmd.AddValue(
"experiment",
"Identifier for experiment.",
experiment);
88 cmd.AddValue(
"strategy",
"Identifier for strategy.", strategy);
89 cmd.AddValue(
"run",
"Identifier for run.", runID);
90 cmd.Parse(argc, argv);
92 if (format !=
"omnet" && format !=
"db")
94 NS_LOG_ERROR(
"Unknown output format '" << format <<
"'");
107 std::stringstream sstr(
"");
119 NS_LOG_INFO(
"Installing WiFi and Internet stack.");
122 wifiMac.
SetType(
"ns3::AdhocWifiMac");
131 ipAddrs.
SetBase(
"192.168.0.0",
"255.255.255.0");
132 ipAddrs.
Assign(nodeDevices);
137 NS_LOG_INFO(
"Installing static mobility; distance " << distance <<
" .");
140 positionAlloc->Add(
Vector(0.0, 0.0, 0.0));
141 positionAlloc->Add(
Vector(0.0, distance, 0.0));
142 mobility.SetPositionAllocator(positionAlloc);
149 Ptr<Node> appSource = NodeList::GetNode(0);
152 sender->SetStartTime(
Seconds(1));
154 Ptr<Node> appSink = NodeList::GetNode(1);
157 receiver->SetStartTime(
Seconds(0));
159 Config::Set(
"/NodeList/*/ApplicationList/*/$Sender/Destination",
171 data.AddMetadata(
"author",
"tjkopena");
178 totalTx->SetKey(
"wifi-tx-frames");
179 totalTx->SetContext(
"node[0]");
180 Config::Connect(
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
182 data.AddDataCalculator(totalTx);
189 totalRx->SetKey(
"wifi-rx-frames");
190 totalRx->SetContext(
"node[1]");
191 Config::Connect(
"/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
192 MakeCallback(&PacketCounterCalculator::PacketUpdate, totalRx));
193 data.AddDataCalculator(totalRx);
199 appTx->SetKey(
"sender-tx-packets");
200 appTx->SetContext(
"node[0]");
202 MakeCallback(&PacketCounterCalculator::PacketUpdate, appTx));
203 data.AddDataCalculator(appTx);
210 appRx->SetKey(
"receiver-rx-packets");
211 appRx->SetContext(
"node[1]");
212 receiver->SetCounter(appRx);
213 data.AddDataCalculator(appRx);
233 CreateObject<PacketSizeMinMaxAvgTotalCalculator>();
234 appTxPkts->SetKey(
"tx-pkt-size");
235 appTxPkts->SetContext(
"node[0]");
237 MakeCallback(&PacketSizeMinMaxAvgTotalCalculator::PacketUpdate, appTxPkts));
238 data.AddDataCalculator(appTxPkts);
245 delayStat->
SetKey(
"delay");
247 receiver->SetDelayTracker(delayStat);
248 data.AddDataCalculator(delayStat);
262 if (format ==
"omnet")
264 NS_LOG_INFO(
"Creating omnet formatted data output.");
265 output = CreateObject<OmnetDataOutput>();
267 else if (format ==
"db")
270 NS_LOG_INFO(
"Creating sqlite formatted data output.");
271 output = CreateObject<SqliteDataOutput>();
283 output->Output(
data);
287 Simulator::Destroy();
Parse command-line arguments.
Introspection did not find any typical Config paths.
void SetContext(const std::string context)
Sets the DataCalculator context to the provided context.
void SetKey(const std::string key)
Sets the DataCalculator key to the provided key.
aggregate IP/TCP/UDP functionality to existing Nodes.
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 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.
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Smart pointer class similar to boost::intrusive_ptr.
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
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.
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.
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.