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);
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");
208 Config::Connect (
"/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
211 data.AddDataCalculator (totalRx);
220 CreateObject<PacketCounterCalculator>();
221 appTx->
SetKey (
"sender-tx-packets");
226 data.AddDataCalculator (appTx);
233 CreateObject<CounterCalculator<> >();
234 appRx->SetKey (
"receiver-rx-packets");
235 appRx->SetContext (
"node[1]");
237 data.AddDataCalculator (appRx);
260 CreateObject<PacketSizeMinMaxAvgTotalCalculator>();
261 appTxPkts->
SetKey (
"tx-pkt-size");
267 data.AddDataCalculator (appTxPkts);
275 CreateObject<TimeMinMaxAvgTotalCalculator>();
276 delayStat->
SetKey (
"delay");
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>();
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Smart pointer class similar to boost::intrusive_ptr.
virtual void Output(DataCollector &dc)=0
Outputs information from the provided DataCollector.
static Ptr< Node > GetNode(uint32_t n)
Make it easy to create and manage PHY objects for the yans model.
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
void Set(std::string path, const AttributeValue &value)
void SetKey(const std::string key)
Sets the DataCalculator key to the provided key.
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
void TxCallback(Ptr< CounterCalculator< uint32_t > > datac, std::string path, Ptr< const Packet > packet)
void PacketUpdate(std::string path, Ptr< const Packet > packet)
Increments the packet stats by the size of the packet.
Ptr< YansWifiChannel > Create(void) const
void SetChannel(Ptr< YansWifiChannel > channel)
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Parse command-line arguments.
void Connect(std::string path, const CallbackBase &cb)
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void PacketUpdate(std::string path, Ptr< const Packet > packet)
Increments the packet counter by one.
void SetDelayTracker(Ptr< TimeMinMaxAvgTotalCalculator > delay)
manage and create wifi channel objects for the yans model.
AttributeValue implementation for Ipv4Address.
create MAC layers for a ns3::WifiNetDevice.
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Helper class used to assign positions and mobility models to nodes.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void SetContext(const std::string context)
Sets the DataCalculator context to the provided context.
Time Seconds(double value)
Construct a Time in the indicated unit.
void Add(Vector v)
Add a position to the list of positions.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
void SetStartTime(Time start)
Specify application start time.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
void experiment(bool enableCtsRts, std::string wifiManager)
Run single 10 seconds experiment.
void SetCounter(Ptr< CounterCalculator<> > calc)