mtp: Modify examples to keep them update

This commit is contained in:
F5
2023-11-14 20:40:40 +08:00
parent 55d6b56a89
commit ac6d1f3920
5 changed files with 65 additions and 69 deletions

View File

@@ -212,10 +212,9 @@ main(int argc, char* argv[])
Simulator::Schedule(Seconds(14), &Ipv4::SetUp, ipv41, ipv4ifIndex1);
// Trace routing tables
Ipv4GlobalRoutingHelper g;
Ptr<OutputStreamWrapper> routingStream =
Create<OutputStreamWrapper>("dynamic-global-routing.routes", std::ios::out);
g.PrintRoutingTableAllAt(Seconds(12), routingStream);
Ipv4RoutingHelper::PrintRoutingTableAllAt(Seconds(12), routingStream);
NS_LOG_INFO("Run Simulation.");
Simulator::Run();

View File

@@ -38,13 +38,13 @@
//
// The output will consist of a number of ping Rtt such as:
//
// /NodeList/0/ApplicationList/2/$ns3::V4Ping/Rtt=111 ms
// /NodeList/0/ApplicationList/2/$ns3::V4Ping/Rtt=111 ms
// /NodeList/0/ApplicationList/2/$ns3::V4Ping/Rtt=110 ms
// /NodeList/0/ApplicationList/2/$ns3::V4Ping/Rtt=111 ms
// /NodeList/0/ApplicationList/2/$ns3::V4Ping/Rtt=111 ms
// /NodeList/0/ApplicationList/2/$ns3::V4Ping/Rtt=112 ms
// /NodeList/0/ApplicationList/2/$ns3::V4Ping/Rtt=111 ms
// /NodeList/0/ApplicationList/2/$ns3::Ping/Rtt=111 ms
// /NodeList/0/ApplicationList/2/$ns3::Ping/Rtt=111 ms
// /NodeList/0/ApplicationList/2/$ns3::Ping/Rtt=110 ms
// /NodeList/0/ApplicationList/2/$ns3::Ping/Rtt=111 ms
// /NodeList/0/ApplicationList/2/$ns3::Ping/Rtt=111 ms
// /NodeList/0/ApplicationList/2/$ns3::Ping/Rtt=112 ms
// /NodeList/0/ApplicationList/2/$ns3::Ping/Rtt=111 ms
//
// The files output will consist of a trace file with bytes in queue and of a trace file for limits
// (when BQL is enabled) both for bottleneck NetDevice on n2, two files with upload and download
@@ -68,9 +68,9 @@ using namespace ns3;
NS_LOG_COMPONENT_DEFINE("BenchmarkQueueDiscs");
/**
* Print the queue limitis.
* Print the queue limits.
*
* \param stream The ouput stream.
* \param stream The output stream.
* \param oldVal Old value.
* \param newVal New value.
*/
@@ -83,7 +83,7 @@ LimitsTrace(Ptr<OutputStreamWrapper> stream, uint32_t oldVal, uint32_t newVal)
/**
* Print the bytes in the queue.
*
* \param stream The ouput stream.
* \param stream The output stream.
* \param oldVal Old value.
* \param newVal New value.
*/
@@ -97,7 +97,7 @@ BytesInQueueTrace(Ptr<OutputStreamWrapper> stream, uint32_t oldVal, uint32_t new
* Sample and print the queue goodput.
*
* \param app The Tx app.
* \param stream The ouput stream.
* \param stream The output stream.
* \param period The sampling period.
*/
static void
@@ -117,7 +117,7 @@ GoodputSampling(ApplicationContainer app, Ptr<OutputStreamWrapper> stream, float
* \param rtt The RTT.
*/
static void
PingRtt(std::string context, Time rtt)
PingRtt(std::string context, uint16_t, Time rtt)
{
std::cout << context << "=" << rtt.GetMilliSeconds() << " ms" << std::endl;
}
@@ -328,10 +328,11 @@ main(int argc, char* argv[])
sourceApps.Add(onOffHelperDown.Install(n3));
// Configure and install ping
V4PingHelper ping = V4PingHelper(n3Interface.GetAddress(0));
PingHelper ping(n3Interface.GetAddress(0));
ping.SetAttribute("VerboseMode", EnumValue(Ping::VerboseMode::QUIET));
ping.Install(n1);
Config::Connect("/NodeList/*/ApplicationList/*/$ns3::V4Ping/Rtt", MakeCallback(&PingRtt));
Config::Connect("/NodeList/*/ApplicationList/*/$ns3::Ping/Rtt", MakeCallback(&PingRtt));
uploadApp.Start(Seconds(0));
uploadApp.Stop(Seconds(stopTime));
@@ -361,6 +362,8 @@ main(int argc, char* argv[])
FlowMonitorHelper flowHelper;
flowMonitor = flowHelper.InstallAll();
accessLink.EnablePcapAll("queue");
Simulator::Stop(Seconds(stopTime));
Simulator::Run();

View File

@@ -98,12 +98,7 @@ main(int argc, char** argv)
LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL);
LogComponentEnable("Icmpv6L4Protocol", LOG_LEVEL_ALL);
LogComponentEnable("NdiscCache", LOG_LEVEL_ALL);
LogComponentEnable("Ping6Application", LOG_LEVEL_ALL);
}
if (showPings)
{
LogComponentEnable("Ping6Application", LOG_LEVEL_INFO);
LogComponentEnable("Ping", LOG_LEVEL_ALL);
}
if (SplitHorizon == "NoSplitHorizon")
@@ -225,38 +220,36 @@ main(int argc, char** argv)
if (printRoutingTables)
{
RipNgHelper routingHelper;
Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper>(&std::cout);
routingHelper.PrintRoutingTableAt(Seconds(30.0), a, routingStream);
routingHelper.PrintRoutingTableAt(Seconds(30.0), b, routingStream);
routingHelper.PrintRoutingTableAt(Seconds(30.0), c, routingStream);
routingHelper.PrintRoutingTableAt(Seconds(30.0), d, routingStream);
Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(30.0), a, routingStream);
Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(30.0), b, routingStream);
Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(30.0), c, routingStream);
Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(30.0), d, routingStream);
routingHelper.PrintRoutingTableAt(Seconds(60.0), a, routingStream);
routingHelper.PrintRoutingTableAt(Seconds(60.0), b, routingStream);
routingHelper.PrintRoutingTableAt(Seconds(60.0), c, routingStream);
routingHelper.PrintRoutingTableAt(Seconds(60.0), d, routingStream);
Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(60.0), a, routingStream);
Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(60.0), b, routingStream);
Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(60.0), c, routingStream);
Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(60.0), d, routingStream);
routingHelper.PrintRoutingTableAt(Seconds(90.0), a, routingStream);
routingHelper.PrintRoutingTableAt(Seconds(90.0), b, routingStream);
routingHelper.PrintRoutingTableAt(Seconds(90.0), c, routingStream);
routingHelper.PrintRoutingTableAt(Seconds(90.0), d, routingStream);
Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(90.0), a, routingStream);
Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(90.0), b, routingStream);
Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(90.0), c, routingStream);
Ipv6RoutingHelper::PrintRoutingTableAt(Seconds(90.0), d, routingStream);
}
NS_LOG_INFO("Create Applications.");
uint32_t packetSize = 1024;
uint32_t maxPacketCount = 100;
Time interPacketInterval = Seconds(1.0);
Ping6Helper ping6;
PingHelper ping(iic7.GetAddress(1, 1));
ping6.SetLocal(iic1.GetAddress(0, 1));
ping6.SetRemote(iic7.GetAddress(1, 1));
ping6.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
ping6.SetAttribute("Interval", TimeValue(interPacketInterval));
ping6.SetAttribute("PacketSize", UintegerValue(packetSize));
ApplicationContainer apps = ping6.Install(src);
ping.SetAttribute("Interval", TimeValue(interPacketInterval));
ping.SetAttribute("Size", UintegerValue(packetSize));
if (showPings)
{
ping.SetAttribute("VerboseMode", EnumValue(Ping::VerboseMode::VERBOSE));
}
ApplicationContainer apps = ping.Install(src);
apps.Start(Seconds(1.0));
apps.Stop(Seconds(110.0));

View File

@@ -36,7 +36,7 @@
// ./ns3 run "tcp-star-server --ns3::OnOffApplication::DataRate=10000"
// ./ns3 run "tcp-star-server --ns3::OnOffApplication::PacketSize=500"
// See the ns-3 tutorial for more info on the command line:
// http://www.nsnam.org/tutorials.html
// https://www.nsnam.org/docs/tutorial/html/index.html
#include "ns3/applications-module.h"
#include "ns3/core-module.h"

View File

@@ -34,7 +34,7 @@
// This program is designed to observe long-running TCP congestion control
// behavior over a configurable bottleneck link. The program is also
// instrumented to check progam data against validated results, when
// instrumented to check program data against validated results, when
// the validation option is enabled.
//
// ---> downstream (primary data transfer from servers to clients)
@@ -182,7 +182,7 @@ TraceFirstCwnd(std::ofstream* ofStream, uint32_t oldCwnd, uint32_t newCwnd)
{
// TCP segment size is configured below to be 1448 bytes
// so that we can report cwnd in units of segments
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " " << static_cast<double>(newCwnd) / 1448
<< std::endl;
@@ -226,7 +226,7 @@ TraceFirstCwnd(std::ofstream* ofStream, uint32_t oldCwnd, uint32_t newCwnd)
void
TraceFirstDctcp(std::ofstream* ofStream, uint32_t bytesMarked, uint32_t bytesAcked, double alpha)
{
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " " << alpha << std::endl;
}
@@ -278,7 +278,7 @@ TraceFirstDctcp(std::ofstream* ofStream, uint32_t bytesMarked, uint32_t bytesAck
void
TraceFirstRtt(std::ofstream* ofStream, Time oldRtt, Time newRtt)
{
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " " << newRtt.GetSeconds() * 1000
<< std::endl;
@@ -297,7 +297,7 @@ TraceSecondCwnd(std::ofstream* ofStream, uint32_t oldCwnd, uint32_t newCwnd)
{
// TCP segment size is configured below to be 1448 bytes
// so that we can report cwnd in units of segments
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " " << static_cast<double>(newCwnd) / 1448
<< std::endl;
@@ -314,7 +314,7 @@ TraceSecondCwnd(std::ofstream* ofStream, uint32_t oldCwnd, uint32_t newCwnd)
void
TraceSecondRtt(std::ofstream* ofStream, Time oldRtt, Time newRtt)
{
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " " << newRtt.GetSeconds() * 1000
<< std::endl;
@@ -332,7 +332,7 @@ TraceSecondRtt(std::ofstream* ofStream, Time oldRtt, Time newRtt)
void
TraceSecondDctcp(std::ofstream* ofStream, uint32_t bytesMarked, uint32_t bytesAcked, double alpha)
{
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " " << alpha << std::endl;
}
@@ -345,9 +345,9 @@ TraceSecondDctcp(std::ofstream* ofStream, uint32_t bytesMarked, uint32_t bytesAc
* \param rtt RTT value.
*/
void
TracePingRtt(std::ofstream* ofStream, Time rtt)
TracePingRtt(std::ofstream* ofStream, uint16_t, Time rtt)
{
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " " << rtt.GetSeconds() * 1000 << std::endl;
}
@@ -386,7 +386,7 @@ TraceSecondRx(Ptr<const Packet> packet, const Address& address)
void
TraceQueueDrop(std::ofstream* ofStream, Ptr<const QueueDiscItem> item)
{
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " " << std::hex << item->Hash() << std::endl;
}
@@ -403,7 +403,7 @@ TraceQueueDrop(std::ofstream* ofStream, Ptr<const QueueDiscItem> item)
void
TraceQueueMark(std::ofstream* ofStream, Ptr<const QueueDiscItem> item, const char* reason)
{
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " " << std::hex << item->Hash() << std::endl;
}
@@ -422,7 +422,7 @@ void
TraceQueueLength(std::ofstream* ofStream, DataRate queueLinkRate, uint32_t oldVal, uint32_t newVal)
{
// output in units of ms
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " " << std::fixed
<< static_cast<double>(newVal * 8) / (queueLinkRate.GetBitRate() / 1000)
@@ -439,7 +439,7 @@ TraceQueueLength(std::ofstream* ofStream, DataRate queueLinkRate, uint32_t oldVa
void
TraceMarksFrequency(std::ofstream* ofStream, Time marksSamplingInterval)
{
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " " << g_marksObserved << std::endl;
}
@@ -460,7 +460,7 @@ void
TraceFirstThroughput(std::ofstream* ofStream, Time throughputInterval)
{
double throughput = g_firstBytesReceived * 8 / throughputInterval.GetSeconds() / 1e6;
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " " << throughput << std::endl;
}
@@ -509,7 +509,7 @@ TraceFirstThroughput(std::ofstream* ofStream, Time throughputInterval)
void
TraceSecondThroughput(std::ofstream* ofStream, Time throughputInterval)
{
if (g_validate == "")
if (g_validate.empty())
{
*ofStream << Simulator::Now().GetSeconds() << " "
<< g_secondBytesReceived * 8 / throughputInterval.GetSeconds() / 1e6 << std::endl;
@@ -683,7 +683,7 @@ main(int argc, char* argv[])
cmd.Parse(argc, argv);
// If validation is selected, perform some configuration checks
if (g_validate != "")
if (!g_validate.empty())
{
NS_ABORT_MSG_UNLESS(g_validate == "dctcp-10ms" || g_validate == "dctcp-80ms" ||
g_validate == "cubic-50ms-no-ecn" || g_validate == "cubic-50ms-ecn",
@@ -691,7 +691,7 @@ main(int argc, char* argv[])
if (g_validate == "dctcp-10ms" || g_validate == "dctcp-80ms")
{
NS_ABORT_MSG_UNLESS(firstTcpType == "dctcp", "Incorrect TCP");
NS_ABORT_MSG_UNLESS(secondTcpType == "", "Incorrect TCP");
NS_ABORT_MSG_UNLESS(secondTcpType.empty(), "Incorrect TCP");
NS_ABORT_MSG_UNLESS(linkRate == DataRate("50Mbps"), "Incorrect data rate");
NS_ABORT_MSG_UNLESS(queueUseEcn == true, "Incorrect ECN configuration");
NS_ABORT_MSG_UNLESS(stopTime >= Seconds(15), "Incorrect stopTime");
@@ -707,7 +707,7 @@ main(int argc, char* argv[])
else if (g_validate == "cubic-50ms-no-ecn" || g_validate == "cubic-50ms-ecn")
{
NS_ABORT_MSG_UNLESS(firstTcpType == "cubic", "Incorrect TCP");
NS_ABORT_MSG_UNLESS(secondTcpType == "", "Incorrect TCP");
NS_ABORT_MSG_UNLESS(secondTcpType.empty(), "Incorrect TCP");
NS_ABORT_MSG_UNLESS(baseRtt == MilliSeconds(50), "Incorrect RTT");
NS_ABORT_MSG_UNLESS(linkRate == DataRate("50Mbps"), "Incorrect data rate");
NS_ABORT_MSG_UNLESS(stopTime >= Seconds(20), "Incorrect stopTime");
@@ -773,7 +773,7 @@ main(int argc, char* argv[])
enableSecondTcp = true;
secondTcpTypeId = TcpDctcp::GetTypeId();
}
else if (secondTcpType == "")
else if (secondTcpType.empty())
{
enableSecondTcp = false;
NS_LOG_DEBUG("No second TCP selected");
@@ -843,7 +843,7 @@ main(int argc, char* argv[])
std::ofstream queueMarkOfStream;
std::ofstream queueMarksFrequencyOfStream;
std::ofstream queueLengthOfStream;
if (g_validate == "")
if (g_validate.empty())
{
pingOfStream.open(pingTraceFile, std::ofstream::out);
firstTcpRttOfStream.open(firstTcpRttTraceFile, std::ofstream::out);
@@ -977,12 +977,13 @@ main(int argc, char* argv[])
////////////////////////////////////////////////////////////
// application setup //
////////////////////////////////////////////////////////////
V4PingHelper pingHelper("192.168.1.2");
PingHelper pingHelper(Ipv4Address("192.168.1.2"));
pingHelper.SetAttribute("Interval", TimeValue(pingInterval));
pingHelper.SetAttribute("Size", UintegerValue(pingSize));
pingHelper.SetAttribute("VerboseMode", EnumValue(Ping::VerboseMode::SILENT));
ApplicationContainer pingContainer = pingHelper.Install(pingServer);
Ptr<V4Ping> v4Ping = pingContainer.Get(0)->GetObject<V4Ping>();
v4Ping->TraceConnectWithoutContext("Rtt", MakeBoundCallback(&TracePingRtt, &pingOfStream));
Ptr<Ping> ping = pingContainer.Get(0)->GetObject<Ping>();
ping->TraceConnectWithoutContext("Rtt", MakeBoundCallback(&TracePingRtt, &pingOfStream));
pingContainer.Start(Seconds(1));
pingContainer.Stop(stopTime - Seconds(1));
@@ -1090,7 +1091,7 @@ main(int argc, char* argv[])
Simulator::Run();
Simulator::Destroy();
if (g_validate == "")
if (g_validate.empty())
{
pingOfStream.close();
firstTcpCwndOfStream.close();