|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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>();
holds a vector of ns3::NetDevice pointers
virtual void Output(DataCollector &dc)=0
Outputs information from the provided DataCollector.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
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.
Parse command-line arguments.
void Add(Vector v)
Add a position to the list of positions.
void Set(std::string path, const AttributeValue &value)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
helps to create WifiNetDevice objects
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetContext(const std::string context)
Sets the DataCalculator context to the provided context.
void SetChannel(Ptr< YansWifiChannel > channel)
void SetDelayTracker(Ptr< TimeMinMaxAvgTotalCalculator > delay)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Smart pointer class similar to boost::intrusive_ptr.
void SetStartTime(Time start)
Specify application start time.
Ptr< YansWifiChannel > Create(void) const
void experiment(std::string queue_disc_type)
void PacketUpdate(std::string path, Ptr< const Packet > packet)
Increments the packet stats by the size of the packet.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
void PacketUpdate(std::string path, Ptr< const Packet > packet)
Increments the packet counter by one.
void SetKey(const std::string key)
Sets the DataCalculator key to the provided key.
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...
static void Run(void)
Run the simulation.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
void Connect(std::string path, const CallbackBase &cb)
Time Seconds(double value)
Construct a Time in the indicated unit.
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
keep track of a set of node pointers.
void SetType(std::string type, Args &&... args)
void TxCallback(Ptr< CounterCalculator< uint32_t > > datac, std::string path, Ptr< const Packet > packet)
manage and create wifi channel objects for the YANS model.
create MAC layers for a ns3::WifiNetDevice.
void SetCounter(Ptr< CounterCalculator<> > calc)
aggregate IP/TCP/UDP functionality to existing Nodes.
static Ptr< Node > GetNode(uint32_t n)
Helper class used to assign positions and mobility models to nodes.
AttributeValue implementation for Ipv4Address.