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/wifi-module.h"
58 NS_LOG_INFO(
"Sent frame counted in " << datac->GetKey());
63 main(
int argc,
char* argv[])
65 double distance = 50.0;
66 std::string format(
"omnet");
69 std::string strategy(
"wifi-default");
74 std::stringstream sstr;
75 sstr <<
"run-" << time(
nullptr);
81 cmd.AddValue(
"distance",
"Distance apart to place nodes (in meters).", distance);
82 cmd.AddValue(
"format",
"Format to use for data output.", format);
83 cmd.AddValue(
"experiment",
"Identifier for experiment.",
experiment);
84 cmd.AddValue(
"strategy",
"Identifier for strategy.", strategy);
85 cmd.AddValue(
"run",
"Identifier for run.", runID);
86 cmd.Parse(argc, argv);
88 if (format !=
"omnet" && format !=
"db")
90 NS_LOG_ERROR(
"Unknown output format '" << format <<
"'");
103 std::stringstream sstr(
"");
115 NS_LOG_INFO(
"Installing WiFi and Internet stack.");
118 wifiMac.
SetType(
"ns3::AdhocWifiMac");
127 ipAddrs.
SetBase(
"192.168.0.0",
"255.255.255.0");
128 ipAddrs.
Assign(nodeDevices);
133 NS_LOG_INFO(
"Installing static mobility; distance " << distance <<
" .");
136 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
137 positionAlloc->Add(Vector(0.0, distance, 0.0));
138 mobility.SetPositionAllocator(positionAlloc);
148 sender->SetStartTime(
Seconds(1));
153 receiver->SetStartTime(
Seconds(0));
155 Config::Set(
"/NodeList/*/ApplicationList/*/$Sender/Destination",
156 Ipv4AddressValue(
"192.168.0.2"));
167 data.AddMetadata(
"author",
"tjkopena");
174 totalTx->SetKey(
"wifi-tx-frames");
175 totalTx->SetContext(
"node[0]");
176 Config::Connect(
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
178 data.AddDataCalculator(totalTx);
185 totalRx->SetKey(
"wifi-rx-frames");
186 totalRx->SetContext(
"node[1]");
187 Config::Connect(
"/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
189 data.AddDataCalculator(totalRx);
195 appTx->SetKey(
"sender-tx-packets");
196 appTx->SetContext(
"node[0]");
199 data.AddDataCalculator(appTx);
206 appRx->SetKey(
"receiver-rx-packets");
207 appRx->SetContext(
"node[1]");
208 receiver->SetCounter(appRx);
209 data.AddDataCalculator(appRx);
230 CreateObject<PacketSizeMinMaxAvgTotalCalculator>();
231 appTxPkts->SetKey(
"tx-pkt-size");
232 appTxPkts->SetContext(
"node[0]");
235 data.AddDataCalculator(appTxPkts);
242 delayStat->
SetKey(
"delay");
244 receiver->SetDelayTracker(delayStat);
245 data.AddDataCalculator(delayStat);
259 if (format ==
"omnet")
261 NS_LOG_INFO(
"Creating omnet formatted data output.");
262 output = CreateObject<OmnetDataOutput>();
264 else if (format ==
"db")
267 NS_LOG_INFO(
"Creating sqlite formatted data output.");
268 output = CreateObject<SqliteDataOutput>();
280 output->Output(
data);
Parse command-line arguments.
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.
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...
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.
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.
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.