examples: Clarify variable names in tcp-variants-comparison.cc

This commit is contained in:
Tommaso Pecorella
2022-02-28 22:48:41 +01:00
committed by Tom Henderson
parent e576878f22
commit d5ca973afb

View File

@@ -70,7 +70,7 @@ static std::map<uint32_t, uint32_t> cWndValue;
static std::map<uint32_t, uint32_t> ssThreshValue; static std::map<uint32_t, uint32_t> ssThreshValue;
static uint32_t static uint32_t
GetNodeNumberFromContext (std::string context) GetNodeIdFromContext (std::string context)
{ {
std::size_t const n1 = context.find_first_of ("/", 1); std::size_t const n1 = context.find_first_of ("/", 1);
std::size_t const n2 = context.find_first_of ("/", n1 + 1); std::size_t const n2 = context.find_first_of ("/", n1 + 1);
@@ -80,152 +80,152 @@ GetNodeNumberFromContext (std::string context)
static void static void
CwndTracer (std::string context, uint32_t oldval, uint32_t newval) CwndTracer (std::string context, uint32_t oldval, uint32_t newval)
{ {
uint32_t nodeNumber = GetNodeNumberFromContext (context); uint32_t nodeId = GetNodeIdFromContext (context);
if (firstCwnd[nodeNumber]) if (firstCwnd[nodeId])
{ {
*cWndStream[nodeNumber]->GetStream () << "0.0 " << oldval << std::endl; *cWndStream[nodeId]->GetStream () << "0.0 " << oldval << std::endl;
firstCwnd[nodeNumber] = false; firstCwnd[nodeId] = false;
} }
*cWndStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << newval << std::endl; *cWndStream[nodeId]->GetStream () << Simulator::Now ().GetSeconds () << " " << newval << std::endl;
cWndValue[nodeNumber] = newval; cWndValue[nodeId] = newval;
if (!firstSshThr[nodeNumber]) if (!firstSshThr[nodeId])
{ {
*ssThreshStream[nodeNumber]->GetStream () *ssThreshStream[nodeId]->GetStream ()
<< Simulator::Now ().GetSeconds () << " " << ssThreshValue[nodeNumber] << std::endl; << Simulator::Now ().GetSeconds () << " " << ssThreshValue[nodeId] << std::endl;
} }
} }
static void static void
SsThreshTracer (std::string context, uint32_t oldval, uint32_t newval) SsThreshTracer (std::string context, uint32_t oldval, uint32_t newval)
{ {
uint32_t nodeNumber = GetNodeNumberFromContext (context); uint32_t nodeId = GetNodeIdFromContext (context);
if (firstSshThr[nodeNumber]) if (firstSshThr[nodeId])
{ {
*ssThreshStream[nodeNumber]->GetStream () << "0.0 " << oldval << std::endl; *ssThreshStream[nodeId]->GetStream () << "0.0 " << oldval << std::endl;
firstSshThr[nodeNumber] = false; firstSshThr[nodeId] = false;
} }
*ssThreshStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << newval << std::endl; *ssThreshStream[nodeId]->GetStream () << Simulator::Now ().GetSeconds () << " " << newval << std::endl;
ssThreshValue[nodeNumber] = newval; ssThreshValue[nodeId] = newval;
if (!firstCwnd[nodeNumber]) if (!firstCwnd[nodeId])
{ {
*cWndStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << cWndValue[nodeNumber] << std::endl; *cWndStream[nodeId]->GetStream () << Simulator::Now ().GetSeconds () << " " << cWndValue[nodeId] << std::endl;
} }
} }
static void static void
RttTracer (std::string context, Time oldval, Time newval) RttTracer (std::string context, Time oldval, Time newval)
{ {
uint32_t nodeNumber = GetNodeNumberFromContext (context); uint32_t nodeId = GetNodeIdFromContext (context);
if (firstRtt[nodeNumber]) if (firstRtt[nodeId])
{ {
*rttStream[nodeNumber]->GetStream () << "0.0 " << oldval.GetSeconds () << std::endl; *rttStream[nodeId]->GetStream () << "0.0 " << oldval.GetSeconds () << std::endl;
firstRtt[nodeNumber] = false; firstRtt[nodeId] = false;
} }
*rttStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << newval.GetSeconds () << std::endl; *rttStream[nodeId]->GetStream () << Simulator::Now ().GetSeconds () << " " << newval.GetSeconds () << std::endl;
} }
static void static void
RtoTracer (std::string context, Time oldval, Time newval) RtoTracer (std::string context, Time oldval, Time newval)
{ {
uint32_t nodeNumber = GetNodeNumberFromContext (context); uint32_t nodeId = GetNodeIdFromContext (context);
if (firstRto[nodeNumber]) if (firstRto[nodeId])
{ {
*rtoStream[nodeNumber]->GetStream () << "0.0 " << oldval.GetSeconds () << std::endl; *rtoStream[nodeId]->GetStream () << "0.0 " << oldval.GetSeconds () << std::endl;
firstRto[nodeNumber] = false; firstRto[nodeId] = false;
} }
*rtoStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << newval.GetSeconds () << std::endl; *rtoStream[nodeId]->GetStream () << Simulator::Now ().GetSeconds () << " " << newval.GetSeconds () << std::endl;
} }
static void static void
NextTxTracer (std::string context, [[maybe_unused]] SequenceNumber32 old, SequenceNumber32 nextTx) NextTxTracer (std::string context, [[maybe_unused]] SequenceNumber32 old, SequenceNumber32 nextTx)
{ {
uint32_t nodeNumber = GetNodeNumberFromContext (context); uint32_t nodeId = GetNodeIdFromContext (context);
*nextTxStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << nextTx << std::endl; *nextTxStream[nodeId]->GetStream () << Simulator::Now ().GetSeconds () << " " << nextTx << std::endl;
} }
static void static void
InFlightTracer (std::string context, [[maybe_unused]] uint32_t old, uint32_t inFlight) InFlightTracer (std::string context, [[maybe_unused]] uint32_t old, uint32_t inFlight)
{ {
uint32_t nodeNumber = GetNodeNumberFromContext (context); uint32_t nodeId = GetNodeIdFromContext (context);
*inFlightStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << inFlight << std::endl; *inFlightStream[nodeId]->GetStream () << Simulator::Now ().GetSeconds () << " " << inFlight << std::endl;
} }
static void static void
NextRxTracer (std::string context, [[maybe_unused]] SequenceNumber32 old, SequenceNumber32 nextRx) NextRxTracer (std::string context, [[maybe_unused]] SequenceNumber32 old, SequenceNumber32 nextRx)
{ {
uint32_t nodeNumber = GetNodeNumberFromContext (context); uint32_t nodeId = GetNodeIdFromContext (context);
*nextRxStream[nodeNumber]->GetStream () << Simulator::Now ().GetSeconds () << " " << nextRx << std::endl; *nextRxStream[nodeId]->GetStream () << Simulator::Now ().GetSeconds () << " " << nextRx << std::endl;
} }
static void static void
TraceCwnd (std::string cwnd_tr_file_name, uint32_t streamNumber) TraceCwnd (std::string cwnd_tr_file_name, uint32_t nodeId)
{ {
AsciiTraceHelper ascii; AsciiTraceHelper ascii;
cWndStream[streamNumber +1] = ascii.CreateFileStream (cwnd_tr_file_name.c_str ()); cWndStream[nodeId] = ascii.CreateFileStream (cwnd_tr_file_name.c_str ());
Config::Connect ("/NodeList/" + std::to_string (streamNumber + 1) + "/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", Config::Connect ("/NodeList/" + std::to_string (nodeId) + "/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow",
MakeCallback (&CwndTracer)); MakeCallback (&CwndTracer));
} }
static void static void
TraceSsThresh (std::string ssthresh_tr_file_name, uint32_t streamNumber) TraceSsThresh (std::string ssthresh_tr_file_name, uint32_t nodeId)
{ {
AsciiTraceHelper ascii; AsciiTraceHelper ascii;
ssThreshStream[streamNumber +1] = ascii.CreateFileStream (ssthresh_tr_file_name.c_str ()); ssThreshStream[nodeId] = ascii.CreateFileStream (ssthresh_tr_file_name.c_str ());
Config::Connect ("/NodeList/" + std::to_string (streamNumber + 1) + "/$ns3::TcpL4Protocol/SocketList/0/SlowStartThreshold", Config::Connect ("/NodeList/" + std::to_string (nodeId) + "/$ns3::TcpL4Protocol/SocketList/0/SlowStartThreshold",
MakeCallback (&SsThreshTracer)); MakeCallback (&SsThreshTracer));
} }
static void static void
TraceRtt (std::string rtt_tr_file_name, uint32_t streamNumber) TraceRtt (std::string rtt_tr_file_name, uint32_t nodeId)
{ {
AsciiTraceHelper ascii; AsciiTraceHelper ascii;
rttStream[streamNumber +1] = ascii.CreateFileStream (rtt_tr_file_name.c_str ()); rttStream[nodeId] = ascii.CreateFileStream (rtt_tr_file_name.c_str ());
Config::Connect ("/NodeList/" + std::to_string (streamNumber + 1) + "/$ns3::TcpL4Protocol/SocketList/0/RTT", Config::Connect ("/NodeList/" + std::to_string (nodeId) + "/$ns3::TcpL4Protocol/SocketList/0/RTT",
MakeCallback (&RttTracer)); MakeCallback (&RttTracer));
} }
static void static void
TraceRto (std::string rto_tr_file_name, uint32_t streamNumber) TraceRto (std::string rto_tr_file_name, uint32_t nodeId)
{ {
AsciiTraceHelper ascii; AsciiTraceHelper ascii;
rtoStream[streamNumber +1] = ascii.CreateFileStream (rto_tr_file_name.c_str ()); rtoStream[nodeId] = ascii.CreateFileStream (rto_tr_file_name.c_str ());
Config::Connect ("/NodeList/" + std::to_string (streamNumber + 1) + "/$ns3::TcpL4Protocol/SocketList/0/RTO", Config::Connect ("/NodeList/" + std::to_string (nodeId) + "/$ns3::TcpL4Protocol/SocketList/0/RTO",
MakeCallback (&RtoTracer)); MakeCallback (&RtoTracer));
} }
static void static void
TraceNextTx (std::string &next_tx_seq_file_name, uint32_t streamNumber) TraceNextTx (std::string &next_tx_seq_file_name, uint32_t nodeId)
{ {
AsciiTraceHelper ascii; AsciiTraceHelper ascii;
nextTxStream[streamNumber +1] = ascii.CreateFileStream (next_tx_seq_file_name.c_str ()); nextTxStream[nodeId] = ascii.CreateFileStream (next_tx_seq_file_name.c_str ());
Config::Connect ("/NodeList/" + std::to_string (streamNumber + 1) + "/$ns3::TcpL4Protocol/SocketList/0/NextTxSequence", Config::Connect ("/NodeList/" + std::to_string (nodeId) + "/$ns3::TcpL4Protocol/SocketList/0/NextTxSequence",
MakeCallback (&NextTxTracer)); MakeCallback (&NextTxTracer));
} }
static void static void
TraceInFlight (std::string &in_flight_file_name, uint32_t streamNumber) TraceInFlight (std::string &in_flight_file_name, uint32_t nodeId)
{ {
AsciiTraceHelper ascii; AsciiTraceHelper ascii;
inFlightStream[streamNumber +1] = ascii.CreateFileStream (in_flight_file_name.c_str ()); inFlightStream[nodeId] = ascii.CreateFileStream (in_flight_file_name.c_str ());
Config::Connect ("/NodeList/" + std::to_string (streamNumber + 1) + "/$ns3::TcpL4Protocol/SocketList/0/BytesInFlight", Config::Connect ("/NodeList/" + std::to_string (nodeId) + "/$ns3::TcpL4Protocol/SocketList/0/BytesInFlight",
MakeCallback (&InFlightTracer)); MakeCallback (&InFlightTracer));
} }
static void static void
TraceNextRx (std::string &next_rx_seq_file_name, uint32_t streamNumber, uint32_t totStreams) TraceNextRx (std::string &next_rx_seq_file_name, uint32_t nodeId)
{ {
AsciiTraceHelper ascii; AsciiTraceHelper ascii;
nextRxStream[totStreams + streamNumber + 1] = ascii.CreateFileStream (next_rx_seq_file_name.c_str ()); nextRxStream[nodeId] = ascii.CreateFileStream (next_rx_seq_file_name.c_str ());
Config::Connect ("/NodeList/" + std::to_string (totStreams + streamNumber + 1) + Config::Connect ("/NodeList/" + std::to_string (nodeId) +
"/$ns3::TcpL4Protocol/SocketList/1/RxBuffer/NextRxSequence", "/$ns3::TcpL4Protocol/SocketList/1/RxBuffer/NextRxSequence",
MakeCallback (&NextRxTracer)); MakeCallback (&NextRxTracer));
} }
@@ -456,19 +456,19 @@ int main (int argc, char *argv[])
firstRto[index+1] = true; firstRto[index+1] = true;
Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceCwnd, Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceCwnd,
prefix_file_name + flowString + "-cwnd.data", index); prefix_file_name + flowString + "-cwnd.data", index+1);
Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceSsThresh, Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceSsThresh,
prefix_file_name + flowString + "-ssth.data", index); prefix_file_name + flowString + "-ssth.data", index+1);
Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceRtt, Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceRtt,
prefix_file_name + flowString + "-rtt.data", index); prefix_file_name + flowString + "-rtt.data", index+1);
Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceRto, Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceRto,
prefix_file_name + flowString + "-rto.data", index); prefix_file_name + flowString + "-rto.data", index+1);
Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceNextTx, Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceNextTx,
prefix_file_name + flowString + "-next-tx.data", index); prefix_file_name + flowString + "-next-tx.data", index+1);
Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceInFlight, Simulator::Schedule (Seconds (start_time * index + 0.00001), &TraceInFlight,
prefix_file_name + flowString + "-inflight.data", index); prefix_file_name + flowString + "-inflight.data", index+1);
Simulator::Schedule (Seconds (start_time * index + 0.1), &TraceNextRx, Simulator::Schedule (Seconds (start_time * index + 0.1), &TraceNextRx,
prefix_file_name + flowString + "-next-rx.data", index, num_flows); prefix_file_name + flowString + "-next-rx.data", num_flows+index+1);
} }
} }