examples: (fix #575) Update tcp-variants-comparison to log multiple flows
This commit is contained in:
committed by
Tom Henderson
parent
452750347b
commit
e576878f22
@@ -55,150 +55,179 @@ using namespace ns3;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("TcpVariantsComparison");
|
||||
|
||||
static bool firstCwnd = true;
|
||||
static bool firstSshThr = true;
|
||||
static bool firstRtt = true;
|
||||
static bool firstRto = true;
|
||||
static Ptr<OutputStreamWrapper> cWndStream;
|
||||
static Ptr<OutputStreamWrapper> ssThreshStream;
|
||||
static Ptr<OutputStreamWrapper> rttStream;
|
||||
static Ptr<OutputStreamWrapper> rtoStream;
|
||||
static Ptr<OutputStreamWrapper> nextTxStream;
|
||||
static Ptr<OutputStreamWrapper> nextRxStream;
|
||||
static Ptr<OutputStreamWrapper> inFlightStream;
|
||||
static uint32_t cWndValue;
|
||||
static uint32_t ssThreshValue;
|
||||
static std::map<uint32_t, bool> firstCwnd;
|
||||
static std::map<uint32_t, bool> firstSshThr;
|
||||
static std::map<uint32_t, bool> firstRtt;
|
||||
static std::map<uint32_t, bool> firstRto;
|
||||
static std::map<uint32_t, Ptr<OutputStreamWrapper>> cWndStream;
|
||||
static std::map<uint32_t, Ptr<OutputStreamWrapper>> ssThreshStream;
|
||||
static std::map<uint32_t, Ptr<OutputStreamWrapper>> rttStream;
|
||||
static std::map<uint32_t, Ptr<OutputStreamWrapper>> rtoStream;
|
||||
static std::map<uint32_t, Ptr<OutputStreamWrapper>> nextTxStream;
|
||||
static std::map<uint32_t, Ptr<OutputStreamWrapper>> nextRxStream;
|
||||
static std::map<uint32_t, Ptr<OutputStreamWrapper>> inFlightStream;
|
||||
static std::map<uint32_t, uint32_t> cWndValue;
|
||||
static std::map<uint32_t, uint32_t> ssThreshValue;
|
||||
|
||||
static uint32_t
|
||||
GetNodeNumberFromContext (std::string context)
|
||||
{
|
||||
std::size_t const n1 = context.find_first_of ("/", 1);
|
||||
std::size_t const n2 = context.find_first_of ("/", n1 + 1);
|
||||
return std::stoul (context.substr (n1 + 1, n2 - n1 - 1));
|
||||
}
|
||||
|
||||
static void
|
||||
CwndTracer (uint32_t oldval, uint32_t newval)
|
||||
CwndTracer (std::string context, uint32_t oldval, uint32_t newval)
|
||||
{
|
||||
if (firstCwnd)
|
||||
{
|
||||
*cWndStream->GetStream () << "0.0 " << oldval << std::endl;
|
||||
firstCwnd = false;
|
||||
}
|
||||
*cWndStream->GetStream () << Simulator::Now ().GetSeconds () << " " << newval << std::endl;
|
||||
cWndValue = newval;
|
||||
uint32_t nodeNumber = GetNodeNumberFromContext (context);
|
||||
|
||||
if (!firstSshThr)
|
||||
if (firstCwnd[nodeNumber])
|
||||
{
|
||||
*ssThreshStream->GetStream () << Simulator::Now ().GetSeconds () << " " << ssThreshValue << std::endl;
|
||||
*cWndStream[nodeNumber]->GetStream () << "0.0 " << oldval << std::endl;
|
||||
firstCwnd[nodeNumber] = false;
|
||||
}
|
||||
*cWndStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << newval << std::endl;
|
||||
cWndValue[nodeNumber] = newval;
|
||||
|
||||
if (!firstSshThr[nodeNumber])
|
||||
{
|
||||
*ssThreshStream[nodeNumber]->GetStream ()
|
||||
<< Simulator::Now ().GetSeconds () << " " << ssThreshValue[nodeNumber] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SsThreshTracer (uint32_t oldval, uint32_t newval)
|
||||
SsThreshTracer (std::string context, uint32_t oldval, uint32_t newval)
|
||||
{
|
||||
if (firstSshThr)
|
||||
{
|
||||
*ssThreshStream->GetStream () << "0.0 " << oldval << std::endl;
|
||||
firstSshThr = false;
|
||||
}
|
||||
*ssThreshStream->GetStream () << Simulator::Now ().GetSeconds () << " " << newval << std::endl;
|
||||
ssThreshValue = newval;
|
||||
uint32_t nodeNumber = GetNodeNumberFromContext (context);
|
||||
|
||||
if (!firstCwnd)
|
||||
if (firstSshThr[nodeNumber])
|
||||
{
|
||||
*cWndStream->GetStream () << Simulator::Now ().GetSeconds () << " " << cWndValue << std::endl;
|
||||
*ssThreshStream[nodeNumber]->GetStream () << "0.0 " << oldval << std::endl;
|
||||
firstSshThr[nodeNumber] = false;
|
||||
}
|
||||
*ssThreshStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << newval << std::endl;
|
||||
ssThreshValue[nodeNumber] = newval;
|
||||
|
||||
if (!firstCwnd[nodeNumber])
|
||||
{
|
||||
*cWndStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << cWndValue[nodeNumber] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
RttTracer (Time oldval, Time newval)
|
||||
RttTracer (std::string context, Time oldval, Time newval)
|
||||
{
|
||||
if (firstRtt)
|
||||
uint32_t nodeNumber = GetNodeNumberFromContext (context);
|
||||
|
||||
if (firstRtt[nodeNumber])
|
||||
{
|
||||
*rttStream->GetStream () << "0.0 " << oldval.GetSeconds () << std::endl;
|
||||
firstRtt = false;
|
||||
*rttStream[nodeNumber]->GetStream () << "0.0 " << oldval.GetSeconds () << std::endl;
|
||||
firstRtt[nodeNumber] = false;
|
||||
}
|
||||
*rttStream->GetStream () << Simulator::Now ().GetSeconds () << " " << newval.GetSeconds () << std::endl;
|
||||
*rttStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << newval.GetSeconds () << std::endl;
|
||||
}
|
||||
|
||||
static void
|
||||
RtoTracer (Time oldval, Time newval)
|
||||
RtoTracer (std::string context, Time oldval, Time newval)
|
||||
{
|
||||
if (firstRto)
|
||||
uint32_t nodeNumber = GetNodeNumberFromContext (context);
|
||||
|
||||
if (firstRto[nodeNumber])
|
||||
{
|
||||
*rtoStream->GetStream () << "0.0 " << oldval.GetSeconds () << std::endl;
|
||||
firstRto = false;
|
||||
*rtoStream[nodeNumber]->GetStream () << "0.0 " << oldval.GetSeconds () << std::endl;
|
||||
firstRto[nodeNumber] = false;
|
||||
}
|
||||
*rtoStream->GetStream () << Simulator::Now ().GetSeconds () << " " << newval.GetSeconds () << std::endl;
|
||||
*rtoStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << newval.GetSeconds () << std::endl;
|
||||
}
|
||||
|
||||
static void
|
||||
NextTxTracer ([[maybe_unused]] SequenceNumber32 old, SequenceNumber32 nextTx)
|
||||
NextTxTracer (std::string context, [[maybe_unused]] SequenceNumber32 old, SequenceNumber32 nextTx)
|
||||
{
|
||||
*nextTxStream->GetStream () << Simulator::Now ().GetSeconds () << " " << nextTx << std::endl;
|
||||
uint32_t nodeNumber = GetNodeNumberFromContext (context);
|
||||
|
||||
*nextTxStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << nextTx << std::endl;
|
||||
}
|
||||
|
||||
static void
|
||||
InFlightTracer ([[maybe_unused]] uint32_t old, uint32_t inFlight)
|
||||
InFlightTracer (std::string context, [[maybe_unused]] uint32_t old, uint32_t inFlight)
|
||||
{
|
||||
*inFlightStream->GetStream () << Simulator::Now ().GetSeconds () << " " << inFlight << std::endl;
|
||||
uint32_t nodeNumber = GetNodeNumberFromContext (context);
|
||||
|
||||
*inFlightStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << inFlight << std::endl;
|
||||
}
|
||||
|
||||
static void
|
||||
NextRxTracer ([[maybe_unused]] SequenceNumber32 old, SequenceNumber32 nextRx)
|
||||
NextRxTracer (std::string context, [[maybe_unused]] SequenceNumber32 old, SequenceNumber32 nextRx)
|
||||
{
|
||||
*nextRxStream->GetStream () << Simulator::Now ().GetSeconds () << " " << nextRx << std::endl;
|
||||
uint32_t nodeNumber = GetNodeNumberFromContext (context);
|
||||
|
||||
*nextRxStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << nextRx << std::endl;
|
||||
}
|
||||
|
||||
static void
|
||||
TraceCwnd (std::string cwnd_tr_file_name)
|
||||
TraceCwnd (std::string cwnd_tr_file_name, uint32_t streamNumber)
|
||||
{
|
||||
AsciiTraceHelper ascii;
|
||||
cWndStream = ascii.CreateFileStream (cwnd_tr_file_name.c_str ());
|
||||
Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", MakeCallback (&CwndTracer));
|
||||
cWndStream[streamNumber +1] = ascii.CreateFileStream (cwnd_tr_file_name.c_str ());
|
||||
Config::Connect ("/NodeList/" + std::to_string (streamNumber + 1) + "/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow",
|
||||
MakeCallback (&CwndTracer));
|
||||
}
|
||||
|
||||
static void
|
||||
TraceSsThresh (std::string ssthresh_tr_file_name)
|
||||
TraceSsThresh (std::string ssthresh_tr_file_name, uint32_t streamNumber)
|
||||
{
|
||||
AsciiTraceHelper ascii;
|
||||
ssThreshStream = ascii.CreateFileStream (ssthresh_tr_file_name.c_str ());
|
||||
Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/SlowStartThreshold", MakeCallback (&SsThreshTracer));
|
||||
ssThreshStream[streamNumber +1] = ascii.CreateFileStream (ssthresh_tr_file_name.c_str ());
|
||||
Config::Connect ("/NodeList/" + std::to_string (streamNumber + 1) + "/$ns3::TcpL4Protocol/SocketList/0/SlowStartThreshold",
|
||||
MakeCallback (&SsThreshTracer));
|
||||
}
|
||||
|
||||
static void
|
||||
TraceRtt (std::string rtt_tr_file_name)
|
||||
TraceRtt (std::string rtt_tr_file_name, uint32_t streamNumber)
|
||||
{
|
||||
AsciiTraceHelper ascii;
|
||||
rttStream = ascii.CreateFileStream (rtt_tr_file_name.c_str ());
|
||||
Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/RTT", MakeCallback (&RttTracer));
|
||||
rttStream[streamNumber +1] = ascii.CreateFileStream (rtt_tr_file_name.c_str ());
|
||||
Config::Connect ("/NodeList/" + std::to_string (streamNumber + 1) + "/$ns3::TcpL4Protocol/SocketList/0/RTT",
|
||||
MakeCallback (&RttTracer));
|
||||
}
|
||||
|
||||
static void
|
||||
TraceRto (std::string rto_tr_file_name)
|
||||
TraceRto (std::string rto_tr_file_name, uint32_t streamNumber)
|
||||
{
|
||||
AsciiTraceHelper ascii;
|
||||
rtoStream = ascii.CreateFileStream (rto_tr_file_name.c_str ());
|
||||
Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/RTO", MakeCallback (&RtoTracer));
|
||||
rtoStream[streamNumber +1] = ascii.CreateFileStream (rto_tr_file_name.c_str ());
|
||||
Config::Connect ("/NodeList/" + std::to_string (streamNumber + 1) + "/$ns3::TcpL4Protocol/SocketList/0/RTO",
|
||||
MakeCallback (&RtoTracer));
|
||||
}
|
||||
|
||||
static void
|
||||
TraceNextTx (std::string &next_tx_seq_file_name)
|
||||
TraceNextTx (std::string &next_tx_seq_file_name, uint32_t streamNumber)
|
||||
{
|
||||
AsciiTraceHelper ascii;
|
||||
nextTxStream = ascii.CreateFileStream (next_tx_seq_file_name.c_str ());
|
||||
Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/NextTxSequence", MakeCallback (&NextTxTracer));
|
||||
nextTxStream[streamNumber +1] = ascii.CreateFileStream (next_tx_seq_file_name.c_str ());
|
||||
Config::Connect ("/NodeList/" + std::to_string (streamNumber + 1) + "/$ns3::TcpL4Protocol/SocketList/0/NextTxSequence",
|
||||
MakeCallback (&NextTxTracer));
|
||||
}
|
||||
|
||||
static void
|
||||
TraceInFlight (std::string &in_flight_file_name)
|
||||
TraceInFlight (std::string &in_flight_file_name, uint32_t streamNumber)
|
||||
{
|
||||
AsciiTraceHelper ascii;
|
||||
inFlightStream = ascii.CreateFileStream (in_flight_file_name.c_str ());
|
||||
Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/BytesInFlight", MakeCallback (&InFlightTracer));
|
||||
inFlightStream[streamNumber +1] = ascii.CreateFileStream (in_flight_file_name.c_str ());
|
||||
Config::Connect ("/NodeList/" + std::to_string (streamNumber + 1) + "/$ns3::TcpL4Protocol/SocketList/0/BytesInFlight",
|
||||
MakeCallback (&InFlightTracer));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
TraceNextRx (std::string &next_rx_seq_file_name)
|
||||
TraceNextRx (std::string &next_rx_seq_file_name, uint32_t streamNumber, uint32_t totStreams)
|
||||
{
|
||||
AsciiTraceHelper ascii;
|
||||
nextRxStream = ascii.CreateFileStream (next_rx_seq_file_name.c_str ());
|
||||
Config::ConnectWithoutContext ("/NodeList/2/$ns3::TcpL4Protocol/SocketList/1/RxBuffer/NextRxSequence", MakeCallback (&NextRxTracer));
|
||||
nextRxStream[totStreams + streamNumber + 1] = ascii.CreateFileStream (next_rx_seq_file_name.c_str ());
|
||||
Config::Connect ("/NodeList/" + std::to_string (totStreams + streamNumber + 1) +
|
||||
"/$ns3::TcpL4Protocol/SocketList/1/RxBuffer/NextRxSequence",
|
||||
MakeCallback (&NextRxTracer));
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
@@ -413,13 +442,34 @@ int main (int argc, char *argv[])
|
||||
std::ios::out);
|
||||
stack.EnableAsciiIpv4All (ascii_wrap);
|
||||
|
||||
Simulator::Schedule (Seconds (0.00001), &TraceCwnd, prefix_file_name + "-cwnd.data");
|
||||
Simulator::Schedule (Seconds (0.00001), &TraceSsThresh, prefix_file_name + "-ssth.data");
|
||||
Simulator::Schedule (Seconds (0.00001), &TraceRtt, prefix_file_name + "-rtt.data");
|
||||
Simulator::Schedule (Seconds (0.00001), &TraceRto, prefix_file_name + "-rto.data");
|
||||
Simulator::Schedule (Seconds (0.00001), &TraceNextTx, prefix_file_name + "-next-tx.data");
|
||||
Simulator::Schedule (Seconds (0.00001), &TraceInFlight, prefix_file_name + "-inflight.data");
|
||||
Simulator::Schedule (Seconds (0.1), &TraceNextRx, prefix_file_name + "-next-rx.data");
|
||||
for (uint16_t index = 0; index < num_flows; index++)
|
||||
{
|
||||
std::string flowString ("");
|
||||
if (num_flows>1)
|
||||
{
|
||||
flowString = "-flow" + std::to_string (index);
|
||||
}
|
||||
|
||||
firstCwnd[index+1] = true;
|
||||
firstSshThr[index+1] = true;
|
||||
firstRtt[index+1] = true;
|
||||
firstRto[index+1] = true;
|
||||
|
||||
Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceCwnd,
|
||||
prefix_file_name + flowString + "-cwnd.data", index);
|
||||
Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceSsThresh,
|
||||
prefix_file_name + flowString + "-ssth.data", index);
|
||||
Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceRtt,
|
||||
prefix_file_name + flowString + "-rtt.data", index);
|
||||
Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceRto,
|
||||
prefix_file_name + flowString + "-rto.data", index);
|
||||
Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceNextTx,
|
||||
prefix_file_name + flowString + "-next-tx.data", index);
|
||||
Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceInFlight,
|
||||
prefix_file_name + flowString + "-inflight.data", index);
|
||||
Simulator::Schedule (Seconds (start_time * index + 0.1), &TraceNextRx,
|
||||
prefix_file_name + flowString + "-next-rx.data", index, num_flows);
|
||||
}
|
||||
}
|
||||
|
||||
if (pcap)
|
||||
|
||||
Reference in New Issue
Block a user