examples: simplify manet-routing-compare.cc
This commit is contained in:
@@ -95,20 +95,15 @@ class RoutingExperiment
|
||||
RoutingExperiment();
|
||||
/**
|
||||
* Run the experiment.
|
||||
* \param nSinks The number of Sink Nodes.
|
||||
* \param txp The Tx power.
|
||||
* \param CSVfileName The output CSV filename.
|
||||
*/
|
||||
void Run(int nSinks, double txp, std::string CSVfileName);
|
||||
// static void SetMACParam (ns3::NetDeviceContainer & devices,
|
||||
// int slotDistance);
|
||||
void Run();
|
||||
|
||||
/**
|
||||
* Handles the command-line parameters.
|
||||
* \param argc The argument count.
|
||||
* \param argv The argument vector.
|
||||
* \return the CSV filename.
|
||||
*/
|
||||
std::string CommandSetup(int argc, char** argv);
|
||||
void CommandSetup(int argc, char** argv);
|
||||
|
||||
private:
|
||||
/**
|
||||
@@ -128,26 +123,19 @@ class RoutingExperiment
|
||||
*/
|
||||
void CheckThroughput();
|
||||
|
||||
uint32_t port; //!< Receiving port number.
|
||||
uint32_t bytesTotal; //!< Total received bytes.
|
||||
uint32_t packetsReceived; //!< Total received packets.
|
||||
uint32_t port{9}; //!< Receiving port number.
|
||||
uint32_t bytesTotal{0}; //!< Total received bytes.
|
||||
uint32_t packetsReceived{0}; //!< Total received packets.
|
||||
|
||||
std::string m_CSVfileName; //!< CSV filename.
|
||||
int m_nSinks; //!< Number of sink nodes.
|
||||
std::string m_protocolName; //!< Protocol name.
|
||||
double m_txp; //!< Tx power.
|
||||
bool m_traceMobility; //!< Enavle mobility tracing.
|
||||
uint32_t m_protocol; //!< Protocol type.
|
||||
bool m_flowMonitor{false}; //!< Enable FlowMonitor.
|
||||
std::string m_CSVfileName{"manet-routing.output.csv"}; //!< CSV filename.
|
||||
int m_nSinks{10}; //!< Number of sink nodes.
|
||||
std::string m_protocolName{"AODV"}; //!< Protocol name.
|
||||
double m_txp{7.5}; //!< Tx power.
|
||||
bool m_traceMobility{false}; //!< Enable mobility tracing.
|
||||
bool m_flowMonitor{false}; //!< Enable FlowMonitor.
|
||||
};
|
||||
|
||||
RoutingExperiment::RoutingExperiment()
|
||||
: port(9),
|
||||
bytesTotal(0),
|
||||
packetsReceived(0),
|
||||
m_CSVfileName("manet-routing.output.csv"),
|
||||
m_traceMobility(false),
|
||||
m_protocol(2) // AODV
|
||||
{
|
||||
}
|
||||
|
||||
@@ -211,26 +199,44 @@ RoutingExperiment::SetupPacketReceive(Ipv4Address addr, Ptr<Node> node)
|
||||
return sink;
|
||||
}
|
||||
|
||||
std::string
|
||||
void
|
||||
RoutingExperiment::CommandSetup(int argc, char** argv)
|
||||
{
|
||||
CommandLine cmd(__FILE__);
|
||||
cmd.AddValue("CSVfileName", "The name of the CSV output file name", m_CSVfileName);
|
||||
cmd.AddValue("traceMobility", "Enable mobility tracing", m_traceMobility);
|
||||
cmd.AddValue("protocol", "1=OLSR;2=AODV;3=DSDV;4=DSR", m_protocol);
|
||||
cmd.AddValue("protocol", "Routing protocol (OLSR, AODV, DSDV, DSR)", m_protocolName);
|
||||
cmd.AddValue("flowMonitor", "enable FlowMonitor", m_flowMonitor);
|
||||
cmd.Parse(argc, argv);
|
||||
return m_CSVfileName;
|
||||
|
||||
std::vector<std::string> allowedProtocols{"OLSR", "AODV", "DSDV", "DSR"};
|
||||
|
||||
if (std::find(std::begin(allowedProtocols), std::end(allowedProtocols), m_protocolName) ==
|
||||
std::end(allowedProtocols))
|
||||
{
|
||||
NS_FATAL_ERROR("No such protocol:" << m_protocolName);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
RoutingExperiment experiment;
|
||||
std::string CSVfileName = experiment.CommandSetup(argc, argv);
|
||||
experiment.CommandSetup(argc, argv);
|
||||
experiment.Run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
RoutingExperiment::Run()
|
||||
{
|
||||
Packet::EnablePrinting();
|
||||
|
||||
// blank out the last output file and write the column headers
|
||||
std::ofstream out(CSVfileName);
|
||||
std::ofstream out(m_CSVfileName);
|
||||
out << "SimulationSecond,"
|
||||
<< "ReceiveRate,"
|
||||
<< "PacketsReceived,"
|
||||
@@ -239,22 +245,6 @@ main(int argc, char* argv[])
|
||||
<< "TransmissionPower" << std::endl;
|
||||
out.close();
|
||||
|
||||
int nSinks = 10;
|
||||
double txp = 7.5;
|
||||
|
||||
experiment.Run(nSinks, txp, CSVfileName);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
RoutingExperiment::Run(int nSinks, double txp, std::string CSVfileName)
|
||||
{
|
||||
Packet::EnablePrinting();
|
||||
m_nSinks = nSinks;
|
||||
m_txp = txp;
|
||||
m_CSVfileName = CSVfileName;
|
||||
|
||||
int nWifis = 50;
|
||||
|
||||
double TotalTime = 200.0;
|
||||
@@ -263,7 +253,6 @@ RoutingExperiment::Run(int nSinks, double txp, std::string CSVfileName)
|
||||
std::string tr_name("manet-routing-compare");
|
||||
int nodeSpeed = 20; // in m/s
|
||||
int nodePause = 0; // in s
|
||||
m_protocolName = "protocol";
|
||||
|
||||
Config::SetDefault("ns3::OnOffApplication::PacketSize", StringValue("64"));
|
||||
Config::SetDefault("ns3::OnOffApplication::DataRate", StringValue(rate));
|
||||
@@ -292,8 +281,8 @@ RoutingExperiment::Run(int nSinks, double txp, std::string CSVfileName)
|
||||
"ControlMode",
|
||||
StringValue(phyMode));
|
||||
|
||||
wifiPhy.Set("TxPowerStart", DoubleValue(txp));
|
||||
wifiPhy.Set("TxPowerEnd", DoubleValue(txp));
|
||||
wifiPhy.Set("TxPowerStart", DoubleValue(m_txp));
|
||||
wifiPhy.Set("TxPowerEnd", DoubleValue(m_txp));
|
||||
|
||||
wifiMac.SetType("ns3::AdhocWifiMac");
|
||||
NetDeviceContainer adhocDevices = wifi.Install(wifiPhy, wifiMac, adhocNodes);
|
||||
@@ -332,33 +321,25 @@ RoutingExperiment::Run(int nSinks, double txp, std::string CSVfileName)
|
||||
Ipv4ListRoutingHelper list;
|
||||
InternetStackHelper internet;
|
||||
|
||||
switch (m_protocol)
|
||||
if (m_protocolName == "OLSR")
|
||||
{
|
||||
case 1:
|
||||
list.Add(olsr, 100);
|
||||
m_protocolName = "OLSR";
|
||||
break;
|
||||
case 2:
|
||||
list.Add(aodv, 100);
|
||||
m_protocolName = "AODV";
|
||||
break;
|
||||
case 3:
|
||||
list.Add(dsdv, 100);
|
||||
m_protocolName = "DSDV";
|
||||
break;
|
||||
case 4:
|
||||
m_protocolName = "DSR";
|
||||
break;
|
||||
default:
|
||||
NS_FATAL_ERROR("No such protocol:" << m_protocol);
|
||||
}
|
||||
|
||||
if (m_protocol < 4)
|
||||
{
|
||||
internet.SetRoutingHelper(list);
|
||||
internet.Install(adhocNodes);
|
||||
}
|
||||
else if (m_protocol == 4)
|
||||
else if (m_protocolName == "AODV")
|
||||
{
|
||||
list.Add(aodv, 100);
|
||||
internet.SetRoutingHelper(list);
|
||||
internet.Install(adhocNodes);
|
||||
}
|
||||
else if (m_protocolName == "DSDV")
|
||||
{
|
||||
list.Add(dsdv, 100);
|
||||
internet.SetRoutingHelper(list);
|
||||
internet.Install(adhocNodes);
|
||||
}
|
||||
else if (m_protocolName == "DSR")
|
||||
{
|
||||
internet.Install(adhocNodes);
|
||||
dsrMain.Install(dsr, adhocNodes);
|
||||
@@ -367,6 +348,10 @@ RoutingExperiment::Run(int nSinks, double txp, std::string CSVfileName)
|
||||
NS_FATAL_ERROR("Error: FlowMonitor does not work with DSR. Terminating.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_FATAL_ERROR("No such protocol:" << m_protocolName);
|
||||
}
|
||||
|
||||
NS_LOG_INFO("assigning ip address");
|
||||
|
||||
@@ -379,7 +364,7 @@ RoutingExperiment::Run(int nSinks, double txp, std::string CSVfileName)
|
||||
onoff1.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1.0]"));
|
||||
onoff1.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0.0]"));
|
||||
|
||||
for (int i = 0; i < nSinks; i++)
|
||||
for (int i = 0; i < m_nSinks; i++)
|
||||
{
|
||||
Ptr<Socket> sink = SetupPacketReceive(adhocInterfaces.GetAddress(i), adhocNodes.Get(i));
|
||||
|
||||
@@ -387,7 +372,7 @@ RoutingExperiment::Run(int nSinks, double txp, std::string CSVfileName)
|
||||
onoff1.SetAttribute("Remote", remoteAddress);
|
||||
|
||||
Ptr<UniformRandomVariable> var = CreateObject<UniformRandomVariable>();
|
||||
ApplicationContainer temp = onoff1.Install(adhocNodes.Get(i + nSinks));
|
||||
ApplicationContainer temp = onoff1.Install(adhocNodes.Get(i + m_nSinks));
|
||||
temp.Start(Seconds(var->GetValue(100.0, 101.0)));
|
||||
temp.Stop(Seconds(TotalTime));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user