70 #include "ns3/core-module.h"
71 #include "ns3/network-module.h"
72 #include "ns3/internet-module.h"
73 #include "ns3/mobility-module.h"
74 #include "ns3/aodv-module.h"
75 #include "ns3/olsr-module.h"
76 #include "ns3/dsdv-module.h"
77 #include "ns3/dsr-module.h"
78 #include "ns3/applications-module.h"
79 #include "ns3/yans-wifi-helper.h"
90 void Run (
int nSinks,
double txp, std::string CSVfileName);
93 std::string CommandSetup (
int argc,
char **argv);
98 void CheckThroughput ();
116 m_CSVfileName (
"manet-routing.output.csv"),
117 m_traceMobility (false),
122 static inline std::string
125 std::ostringstream oss;
129 if (InetSocketAddress::IsMatchingType (senderAddress))
132 oss <<
" received one packet from " << addr.
GetIpv4 ();
136 oss <<
" received one packet!";
146 while ((packet = socket->
RecvFrom (senderAddress)))
178 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
191 cmd.AddValue (
"CSVfileName",
"The name of the CSV output file name",
m_CSVfileName);
193 cmd.AddValue (
"protocol",
"1=OLSR;2=AODV;3=DSDV;4=DSR",
m_protocol);
194 cmd.Parse (argc, argv);
199 main (
int argc,
char *argv[])
202 std::string CSVfileName =
experiment.CommandSetup (argc,argv);
205 std::ofstream out (CSVfileName.c_str ());
206 out <<
"SimulationSecond," <<
208 "PacketsReceived," <<
210 "RoutingProtocol," <<
211 "TransmissionPower" <<
224 Packet::EnablePrinting ();
231 double TotalTime = 200.0;
232 std::string rate (
"2048bps");
233 std::string phyMode (
"DsssRate11Mbps");
234 std::string tr_name (
"manet-routing-compare");
246 adhocNodes.
Create (nWifis);
260 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
267 wifiMac.
SetType (
"ns3::AdhocWifiMac");
271 int64_t streamIndex = 0;
274 pos.
SetTypeId (
"ns3::RandomRectanglePositionAllocator");
275 pos.
Set (
"X",
StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=300.0]"));
276 pos.
Set (
"Y",
StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1500.0]"));
279 streamIndex += taPositionAlloc->AssignStreams (streamIndex);
281 std::stringstream ssSpeed;
282 ssSpeed <<
"ns3::UniformRandomVariable[Min=0.0|Max=" << nodeSpeed <<
"]";
283 std::stringstream ssPause;
284 ssPause <<
"ns3::ConstantRandomVariable[Constant=" << nodePause <<
"]";
290 mobilityAdhoc.
Install (adhocNodes);
291 streamIndex += mobilityAdhoc.
AssignStreams (adhocNodes, streamIndex);
309 list.Add (aodv, 100);
313 list.Add (dsdv, 100);
331 dsrMain.
Install (dsr, adhocNodes);
337 addressAdhoc.
SetBase (
"10.1.1.0",
"255.255.255.0");
339 adhocInterfaces = addressAdhoc.
Assign (adhocDevices);
345 for (
int i = 0; i < nSinks; i++)
358 std::stringstream ss;
360 std::string
nodes = ss.str ();
362 std::stringstream ss2;
364 std::string sNodeSpeed = ss2.str ();
366 std::stringstream ss3;
368 std::string sNodePause = ss3.str ();
370 std::stringstream ss4;
372 std::string sRate = ss4.str ();
392 Simulator::Stop (
Seconds (TotalTime));
397 Simulator::Destroy ();
Ptr< Socket > SetupPacketReceive(Ptr< Node > node)
void Run(int nSinks, double txp, std::string CSVfileName)
std::string CommandSetup(int argc, char **argv)
std::string m_protocolName
void ReceivePacket(Ptr< Socket > socket)
std::string m_CSVfileName
Ptr< Socket > SetupPacketReceive(Ipv4Address addr, Ptr< Node > node)
a polymophic address class
AttributeValue implementation for Address.
Helper class that adds AODV routing to nodes.
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Manage ASCII trace files for device models.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Helper class that adds DSDV routing to nodes.
DSR helper class to manage creation of DSR routing instance and to insert it on a node as a sublayer ...
Helper class that adds DSR routing to nodes.
void Install(DsrHelper &dsrHelper, NodeContainer nodes)
Install routing to the nodes.
Ipv4Address GetIpv4(void) const
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...
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
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...
Ipv4 addresses are stored in host order in this class.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class that adds ns3::Ipv4ListRouting objects.
Helper class used to assign positions and mobility models to nodes.
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())
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the mobility models on t...
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t GetId(void) const
Instantiate subclasses of ns3::Object.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Helper class that adds OLSR routing to nodes.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Hold objects of type Ptr<T>.
Allocate a set of positions.
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
Hold variables of type string.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
void Set(std::string name, const AttributeValue &v)
manage and create wifi channel objects for the YANS model.
void SetPropagationDelay(std::string name, 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())
Ptr< YansWifiChannel > Create(void) const
void AddPropagationLoss(std::string name, 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())
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 ReceivePacket(Ptr< Socket > socket)
void SetDefault(std::string name, const AttributeValue &value)
#define NS_UNUSED(x)
Mark a local variable as unused.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
#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.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Time Seconds(double value)
Construct a Time in the indicated unit.
static std::string PrintReceivedPacket(Ptr< Socket > socket, Ptr< Packet > packet, Address senderAddress)
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...
std::map< Mac48Address, uint64_t > packetsReceived
Map that stores the total packets received per STA (and addressed to that STA)