54 #include "uan-rc-example.h"
55 #include "ns3/core-module.h"
56 #include "ns3/network-module.h"
57 #include "ns3/applications-module.h"
58 #include "ns3/mobility-module.h"
60 #include "ns3/config.h"
61 #include "ns3/callback.h"
62 #include "ns3/tools-module.h"
71 Experiment::Experiment ()
83 m_gnuplotfile (
"uan-rc-example.gpl"),
92 while ((packet = socket->
Recv ()))
94 m_bytesTotal += packet->
GetSize ();
99 Experiment::CreateMode (uint32_t kass,
105 std::ostringstream buf;
106 buf << name <<
" " << kass;
108 uint32_t rate = m_totalRate/(m_numRates+1)* (kass);
109 uint32_t bw = kass * m_totalRate / (m_numRates+1);
112 fcmode = (m_totalRate - bw)/2 + fc;
114 fcmode = (uint32_t)((-((
double) m_totalRate ) + (
double) bw)/2.0 + (
double) fc);
117 uint32_t phyrate = m_totalRate;
120 mode = UanTxModeFactory::CreateMode (UanTxMode::OTHER,
133 Experiment::CreateDualModes (uint32_t fc)
137 for (uint32_t i=1; i < m_numRates+1; i++)
139 m_controlModes.
AppendMode (CreateMode (i, fc,
false,
"control "));
141 for (uint32_t i=m_numRates; i > 0; i--)
143 m_dataModes.
AppendMode (CreateMode (i, fc,
true,
"data "));
148 Experiment::Run (uint32_t param)
167 Time pDelay =
Seconds ((
double) m_maxRange / 1500.0);
169 uan.
SetPhy (
"ns3::UanPhyDual",
170 "SupportedModesPhy1", UanModesListValue (m_dataModes),
171 "SupportedModesPhy2", UanModesListValue (m_controlModes));
173 uan.
SetMac (
"ns3::UanMacRcGw",
187 uan.
SetMac (
"ns3::UanMacRc",
201 pos->
Add (
Vector (m_maxRange, m_maxRange, depth));
203 for (uint32_t i=0; i<nNodes; i++)
205 double theta = utheta->GetValue (0, 2.0*M_PI);
206 double r = urv->GetValue (0,m_maxRange);
208 double x = m_maxRange + r*std::cos (theta);
209 double y = m_maxRange + r*std::sin (theta);
225 socket.SetSingleDevice (sinkDev.
Get (0)->GetIfIndex ());
226 socket.SetPhysicalAddress (sinkDev.
Get (0)->GetAddress ());
227 socket.SetProtocol (0);
230 app.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
231 app.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
237 apps.
Start (Seconds (0.5));
238 apps.
Stop (m_simTime + Seconds (0.5));
241 TypeId psfid = TypeId::LookupByName (
"ns3::PacketSocketFactory");
243 Ptr<Socket> sinkSocket = Socket::CreateSocket (sinkNode, psfid);
244 sinkSocket->
Bind (socket);
247 Simulator::Stop (m_simTime + Seconds (0.6));
249 Simulator::Destroy ();
254 main (
int argc,
char *argv[])
262 cmd.
AddValue (
"TotalRate",
"Total channel capacity", exp.m_totalRate);
263 cmd.
AddValue (
"NumberRates",
"Number of divided rates ( (NumberRates+1)%TotalRate should be 0)", exp.m_numRates);
264 cmd.
AddValue (
"MaxRange",
"Maximum range between gateway and acoustic node", exp.m_maxRange);
265 cmd.
AddValue (
"SimMin",
"Minimum parameter to test (nodes if DoNode=1, \"a\" param otherwise)", exp.m_simMin);
266 cmd.
AddValue (
"SimMax",
"Maximum parameter to test (nodes if DoNode=1, \"a\" param otherwise)", exp.m_simMax);
267 cmd.
AddValue (
"SimStep",
"Ammount to increment param per trial", exp.m_simStep);
268 cmd.
AddValue (
"DataFile",
"Filename for GnuPlot", exp.m_gnuplotfile);
269 cmd.
AddValue (
"NumberNodes",
"Number of nodes (invalid for doNode=1)", exp.m_numNodes);
270 cmd.
AddValue (
"SIFS",
"SIFS time duration", exp.m_sifs);
271 cmd.
AddValue (
"PktSize",
"Packet size in bytes", exp.m_pktSize);
272 cmd.
AddValue (
"SimTime",
"Simulation time per trial", exp.m_simTime);
273 cmd.
AddValue (
"DoNode",
"1 for do max nodes simulation (invalidates AMin and AMax values)", exp.m_doNode);
274 cmd.
Parse (argc, argv);
278 exp.CreateDualModes (12000);
283 for (uint32_t param=exp.m_simMin; param<=exp.m_simMax; param += exp.m_simStep)
285 uint32_t bytesRx = exp.Run (param);
286 NS_LOG_DEBUG (
"param=" << param <<
": Received " << bytesRx <<
" bytes at sink");
288 double util = bytesRx*8.0/(exp.m_simTime.
GetSeconds ()*exp.m_totalRate);
290 ds.
Add (param, util);
292 SeedManager::SetRun (SeedManager::GetRun () + 1);
297 std::ofstream of (exp.m_gnuplotfile.c_str ());
300 NS_FATAL_ERROR (
"Can not open GNU Plot outfile: " << exp.m_gnuplotfile);
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_LOG_COMPONENT_DEFINE(name)
uint32_t GetSize(void) const
void AddDataset(const GnuplotDataset &dataset)
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Give ns3::PacketSocket powers to ns3::Node.
#define NS_FATAL_ERROR(msg)
fatal error handling
a polymophic address class
double GetSeconds(void) const
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
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 Add(double x, double y)
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
parse command-line argumentsInstances of this class can be used to parse command-line arguments: user...
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
keep track of a set of node pointers.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
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
Helper class used to assign positions and mobility models to nodes.
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)
#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
Hold an floating point type.
a unique identifier for an interface.
void SetPhy(std::string phyType, 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())
void LogComponentEnable(char const *name, enum LogLevel level)