35 #include "ns3/core-module.h"
36 #include "ns3/network-module.h"
37 #include "ns3/mobility-module.h"
38 #include "ns3/internet-module.h"
39 #include "ns3/stats-module.h"
40 #include "ns3/yans-wifi-helper.h"
62 int main (
int argc,
char *argv[]) {
64 double distance = 50.0;
65 string format (
"omnet");
68 string strategy (
"wifi-default");
74 sstr <<
"run-" << time (NULL);
80 cmd.AddValue (
"distance",
"Distance apart to place nodes (in meters).",
82 cmd.AddValue (
"format",
"Format to use for data output.",
84 cmd.AddValue (
"experiment",
"Identifier for experiment.",
86 cmd.AddValue (
"strategy",
"Identifier for strategy.",
88 cmd.AddValue (
"run",
"Identifier for run.",
90 cmd.Parse (argc, argv);
92 if (format !=
"omnet" && format !=
"db") {
93 NS_LOG_ERROR (
"Unknown output format '" << format <<
"'");
97 #ifndef STATS_HAS_SQLITE3
105 stringstream sstr (
"");
120 NS_LOG_INFO (
"Installing WiFi and Internet stack.");
123 wifiMac.
SetType (
"ns3::AdhocWifiMac");
132 ipAddrs.
SetBase (
"192.168.0.0",
"255.255.255.0");
133 ipAddrs.
Assign (nodeDevices);
141 NS_LOG_INFO (
"Installing static mobility; distance " << distance <<
" .");
144 CreateObject<ListPositionAllocator>();
145 positionAlloc->Add (Vector (0.0, 0.0, 0.0));
146 positionAlloc->Add (Vector (0.0, distance, 0.0));
147 mobility.SetPositionAllocator (positionAlloc);
160 sender->SetStartTime (
Seconds (1));
165 receiver->SetStartTime (
Seconds (0));
167 Config::Set (
"/NodeList/*/ApplicationList/*/$Sender/Destination",
185 data.AddMetadata (
"author",
"tjkopena");
193 CreateObject<CounterCalculator<uint32_t> >();
194 totalTx->SetKey (
"wifi-tx-frames");
195 totalTx->SetContext (
"node[0]");
196 Config::Connect (
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
198 data.AddDataCalculator (totalTx);
205 CreateObject<PacketCounterCalculator>();
206 totalRx->SetKey (
"wifi-rx-frames");
207 totalRx->SetContext (
"node[1]");
208 Config::Connect (
"/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
211 data.AddDataCalculator (totalRx);
220 CreateObject<PacketCounterCalculator>();
221 appTx->SetKey (
"sender-tx-packets");
222 appTx->SetContext (
"node[0]");
226 data.AddDataCalculator (appTx);
233 CreateObject<CounterCalculator<> >();
234 appRx->SetKey (
"receiver-rx-packets");
235 appRx->SetContext (
"node[1]");
236 receiver->SetCounter (appRx);
237 data.AddDataCalculator (appRx);
260 CreateObject<PacketSizeMinMaxAvgTotalCalculator>();
261 appTxPkts->SetKey (
"tx-pkt-size");
262 appTxPkts->SetContext (
"node[0]");
267 data.AddDataCalculator (appTxPkts);
275 CreateObject<TimeMinMaxAvgTotalCalculator>();
276 delayStat->
SetKey (
"delay");
278 receiver->SetDelayTracker (delayStat);
279 data.AddDataCalculator (delayStat);
299 if (format ==
"omnet") {
300 NS_LOG_INFO (
"Creating omnet formatted data output.");
301 output = CreateObject<OmnetDataOutput>();
302 }
else if (format ==
"db") {
303 #ifdef STATS_HAS_SQLITE3
304 NS_LOG_INFO (
"Creating sqlite formatted data output.");
305 output = CreateObject<SqliteDataOutput>();
314 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.
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.
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(void)
Execute the events scheduled with ScheduleDestroy().
static void Run(void)
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.
Ptr< YansWifiChannel > Create(void) const
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.
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.
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
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, Ts... > MakeCallback(R(T::*memPtr)(Ts...), 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)