39 #include "uan-cw-example.h"
40 #include "ns3/core-module.h"
41 #include "ns3/network-module.h"
42 #include "ns3/mobility-module.h"
43 #include "ns3/tools-module.h"
44 #include "ns3/applications-module.h"
52 Experiment::Experiment ()
65 m_gnudatfile (
"uan-cw-example.gpl"),
66 m_asciitracefile (
"uan-cw-example.asc"),
67 m_bhCfgFile (
"uan-apps/dat/default.cfg")
72 Experiment::ResetData ()
75 m_throughputs.push_back (m_bytesTotal * 8.0 / m_simTime.GetSeconds ());
80 Experiment::IncrementCw (uint32_t cw)
82 NS_ASSERT (m_throughputs.size () == m_avgs);
84 double avgThroughput = 0.0;
85 for (uint32_t i=0; i<m_avgs; i++)
87 avgThroughput += m_throughputs[i];
89 avgThroughput /= m_avgs;
90 m_data.Add (cw, avgThroughput);
91 m_throughputs.clear ();
97 NS_LOG_DEBUG (
"Average for cw=" << cw <<
" over " << m_avgs <<
" runs: " << avgThroughput);
104 NodeContainer::Iterator it = nodes.
Begin ();
106 for (; it != nodes.
End (); it++)
118 while ((packet = socket->
Recv ()))
120 m_bytesTotal += packet->
GetSize ();
138 #ifdef UAN_PROP_BH_INSTALLED
142 #endif //UAN_PROP_BH_INSTALLED
154 pos->
Add (
Vector (m_boundary / 2.0, m_boundary / 2.0, m_depth));
157 double minr = 2 * m_boundary;
158 for (uint32_t i = 0; i < m_numNodes; i++)
160 double x = urv->
GetValue (0, m_boundary);
161 double y = urv->
GetValue (0, m_boundary);
162 double newr = std::sqrt ((x - m_boundary / 2.0) * (x - m_boundary / 2.0)
163 + (y - m_boundary / 2.0) * (y - m_boundary / 2.0));
165 minr = std::min (minr, newr);
169 NS_LOG_DEBUG (
"Mean range from gateway: " << rsum / m_numNodes
170 <<
" min. range " << minr);
181 socket.SetSingleDevice (sinkdev.
Get (0)->GetIfIndex ());
182 socket.SetPhysicalAddress (sinkdev.
Get (0)->GetAddress ());
183 socket.SetProtocol (0);
186 app.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
187 app.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
189 app.SetAttribute (
"PacketSize",
UintegerValue (m_packetSize));
196 for (uint32_t cw = m_cwMin; cw <= m_cwMax; cw += m_cwStep)
199 for (uint32_t an = 0; an < m_avgs; an++)
201 nextEvent += m_simTime;
207 apps.
Stop (nextEvent + m_simTime);
217 sinkSocket->
Bind (socket);
222 std::ofstream ascii (m_asciitracefile.c_str ());
223 if (!ascii.is_open ())
226 << m_asciitracefile);
236 for (uint32_t i=0; i < nc.
GetN (); i++)
240 for (uint32_t i=0; i < sink.
GetN (); i++)
245 for (uint32_t i=0; i < devices.GetN (); i++)
249 for (uint32_t i=0; i < sinkdev.
GetN (); i++)
260 main (
int argc,
char **argv)
267 std::string gnudatfile (
"cwexpgnuout.dat");
268 std::string perModel =
"ns3::UanPhyPerGenDefault";
269 std::string sinrModel =
"ns3::UanPhyCalcSinrDefault";
272 cmd.
AddValue (
"NumNodes",
"Number of transmitting nodes", exp.m_numNodes);
273 cmd.
AddValue (
"Depth",
"Depth of transmitting and sink nodes", exp.m_depth);
274 cmd.
AddValue (
"RegionSize",
"Size of boundary in meters", exp.m_boundary);
275 cmd.
AddValue (
"PacketSize",
"Generated packet size in bytes", exp.m_packetSize);
276 cmd.
AddValue (
"DataRate",
"DataRate in bps", exp.m_dataRate);
277 cmd.
AddValue (
"CwMin",
"Min CW to simulate", exp.m_cwMin);
278 cmd.
AddValue (
"CwMax",
"Max CW to simulate", exp.m_cwMax);
279 cmd.
AddValue (
"SlotTime",
"Slot time duration", exp.m_slotTime);
280 cmd.
AddValue (
"Averages",
"Number of topologies to test for each cw point", exp.m_avgs);
281 cmd.
AddValue (
"GnuFile",
"Name for GNU Plot output", exp.m_gnudatfile);
282 cmd.
AddValue (
"PerModel",
"PER model name", perModel);
283 cmd.
AddValue (
"SinrModel",
"SINR model name", sinrModel);
284 cmd.
Parse (argc, argv);
295 exp.m_dataRate, 12000,
301 uan.SetPhy (
"ns3::UanPhyGen",
304 "SupportedModes", UanModesListValue (myModes));
312 std::ofstream of (exp.m_gnudatfile.c_str ());
315 NS_FATAL_ERROR (
"Can not open GNU Plot outfile: " << exp.m_gnudatfile);
Helper class for UAN CW MAC example.
holds a vector of ns3::Application pointers.
Class to represent a 2D points plot. Set the line or points style using SetStyle() and set points usi...
hold variables of type string
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
void GenerateOutput(std::ostream &os) const
an address for a packet socket
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
void SetTypeId(TypeId tid)
uint32_t GetSize(void) const
void AddDataset(const GnuplotDataset &dataset)
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
Container for UanTxModes.
void Set(std::string path, const AttributeValue &value)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Object to create transport layer instances that provide a socket API to applications.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Give ns3::PacketSocket powers to ns3::Node.
static UanTxMode CreateMode(UanTxMode::ModulationType type, uint32_t dataRateBps, uint32_t phyRateSps, uint32_t cfHz, uint32_t bwHz, uint32_t constSize, std::string name)
#define NS_FATAL_ERROR(msg)
fatal error handling
static void SetRun(uint64_t run)
Set the run number of simulation.
a polymophic address class
static uint64_t GetRun(void)
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
uint32_t GetN(void) const
Get the number of Ptr<NetDevice> stored in this container.
Keep track of the current position and velocity of an object.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
void SetMac(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())
hold objects of type ns3::Time
Ptr< Object > Create(void) const
Hold an unsigned integer type.
Abstraction of packet modulation information.
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
void AggregateObject(Ptr< Object > other)
parse command-line argumentsInstances of this class can be used to parse command-line arguments: user...
static void Destroy(void)
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
keep track of a set of node pointers.
hold objects of type Ptr<T>
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
void SetMobilityModel(std::string type, 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())
void Install(Ptr< Node > node) const
static void EnableAsciiAll(std::ostream &os)
void SetPosition(const Vector &position)
Helper class used to assign positions and mobility models to nodes.
instantiate subclasses of ns3::Object.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
hold objects of type ns3::DataRate
void AddValue(const std::string &name, const std::string &help, T &value)
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
#define NS_LOG_DEBUG(msg)
void Parse(int argc, char *argv[]) const
void AppendMode(UanTxMode mode)
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
NetDeviceContainer Install(NodeContainer c) const
Ptr< T > GetObject(void) const
a unique identifier for an interface.
void LogComponentEnable(char const *name, enum LogLevel level)
static TypeId LookupByName(std::string name)