# HG changeset patch # Parent df9115f64a3538a2808bc4d5dceeb36e33194ac9 # User Tommaso Pecorella # Date 1407945036 -7200 Bug 1831 - Improvements to tcp-variants-comparison example diff --git a/examples/tcp/tcp-variants-comparison.cc b/examples/tcp/tcp-variants-comparison.cc --- a/examples/tcp/tcp-variants-comparison.cc +++ b/examples/tcp/tcp-variants-comparison.cc @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013 ResiliNets, ITTC, University of Kansas + * Copyright (c) 2013 ResiliNets, ITTC, University of Kansas * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -54,91 +54,78 @@ NS_LOG_COMPONENT_DEFINE ("TcpVariantsComparison"); -double old_time = 0.0; -EventId output; -Time current = Time::FromInteger(3, Time::S); //Only record cwnd and ssthresh values every 3 seconds -bool first = true; +bool firstCwnd = true; +bool firstSshThr = true; +Ptr cWndStream; +Ptr ssThreshStream; +uint32_t cWndValue; +uint32_t ssThreshValue; + static void -OutputTrace () +CwndTracer (uint32_t oldval, uint32_t newval) { - // *stream->GetStream() << newtime << " " << newval << std::endl; - // old_time = newval; + if (firstCwnd) + { + *cWndStream->GetStream () << "0.0 " << oldval << std::endl; + firstCwnd = false; + } + *cWndStream->GetStream () << Simulator::Now ().GetSeconds () << " " << newval << std::endl; + cWndValue = newval; + + if (!firstSshThr) + { + *ssThreshStream->GetStream () << Simulator::Now ().GetSeconds () << " " << ssThreshValue << std::endl; + } } static void -CwndTracer (Ptrstream, uint32_t oldval, uint32_t newval) +SsThreshTracer (uint32_t oldval, uint32_t newval) { - double new_time = Simulator::Now().GetSeconds(); - if (old_time == 0 && first) - { - double mycurrent = current.GetSeconds(); - *stream->GetStream() << new_time << " " << mycurrent << " " << newval << std::endl; - first = false; - output = Simulator::Schedule(current,&OutputTrace); - } - else - { - if (output.IsExpired()) + if (firstSshThr) { - *stream->GetStream() << new_time << " " << newval << std::endl; - output.Cancel(); - output = Simulator::Schedule(current,&OutputTrace); + *ssThreshStream->GetStream () << "0.0 " << oldval << std::endl; + firstSshThr = false; } - } + *ssThreshStream->GetStream () << Simulator::Now ().GetSeconds () << " " << newval << std::endl; + ssThreshValue = newval; + + if (!firstCwnd) + { + *cWndStream->GetStream () << Simulator::Now ().GetSeconds () << " " << cWndValue << std::endl; + } } -static void -SsThreshTracer (Ptrstream, uint32_t oldval, uint32_t newval) -{ - double new_time = Simulator::Now().GetSeconds(); - if (old_time == 0 && first) - { - double mycurrent = current.GetSeconds(); - *stream->GetStream() << new_time << " " << mycurrent << " " << newval << std::endl; - first = false; - output = Simulator::Schedule(current,&OutputTrace); - } - else - { - if (output.IsExpired()) - { - *stream->GetStream() << new_time << " " << newval << std::endl; - output.Cancel(); - output = Simulator::Schedule(current,&OutputTrace); - } - } -} static void TraceCwnd (std::string cwnd_tr_file_name) { AsciiTraceHelper ascii; - if (cwnd_tr_file_name.compare("") == 0) - { - NS_LOG_DEBUG ("No trace file for cwnd provided"); - return; - } + if (cwnd_tr_file_name.compare ("") == 0) + { + NS_LOG_DEBUG ("No trace file for cwnd provided"); + return; + } else { - Ptr stream = ascii.CreateFileStream(cwnd_tr_file_name.c_str()); - Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow",MakeBoundCallback (&CwndTracer, stream)); + cWndStream = ascii.CreateFileStream (cwnd_tr_file_name.c_str ()); + Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", MakeCallback (&CwndTracer)); } } static void -TraceSsThresh(std::string ssthresh_tr_file_name) +TraceSsThresh (std::string ssthresh_tr_file_name) { AsciiTraceHelper ascii; - if (ssthresh_tr_file_name.compare("") == 0) + if (ssthresh_tr_file_name.compare ("") == 0) { NS_LOG_DEBUG ("No trace file for ssthresh provided"); return; } else { - Ptr stream = ascii.CreateFileStream(ssthresh_tr_file_name.c_str()); - Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/SlowStartThreshold",MakeBoundCallback (&SsThreshTracer, stream)); + ssThreshStream = ascii.CreateFileStream (ssthresh_tr_file_name.c_str ()); + Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/SlowStartThreshold",MakeCallback (&SsThreshTracer)); } } @@ -162,25 +149,25 @@ CommandLine cmd; - cmd.AddValue("transport_prot", "Transport protocol to use: TcpTahoe, TcpReno, TcpNewReno, TcpWestwood, TcpWestwoodPlus ", transport_prot); - cmd.AddValue("error_p", "Packet error rate", error_p); - cmd.AddValue("bandwidth", "Bottleneck bandwidth", bandwidth); - cmd.AddValue("access_bandwidth", "Access link bandwidth", access_bandwidth); - cmd.AddValue("delay", "Access link delay", access_delay); - cmd.AddValue("tracing", "Flag to enable/disable tracing", tracing); - cmd.AddValue("tr_name", "Name of output trace file", tr_file_name); - cmd.AddValue("cwnd_tr_name", "Name of output trace file", cwnd_tr_file_name); - cmd.AddValue("ssthresh_tr_name", "Name of output trace file", ssthresh_tr_file_name); - cmd.AddValue("data", "Number of Megabytes of data to transmit", data_mbytes); - cmd.AddValue("mtu", "Size of IP packets to send in bytes", mtu_bytes); - cmd.AddValue("num_flows", "Number of flows", num_flows); - cmd.AddValue("duration", "Time to allow flows to run in seconds", duration); - cmd.AddValue("run", "Run index (for setting repeatable seeds)", run); - cmd.AddValue("flow_monitor", "Enable flow monitor", flow_monitor); + cmd.AddValue ("transport_prot", "Transport protocol to use: TcpTahoe, TcpReno, TcpNewReno, TcpWestwood, TcpWestwoodPlus ", transport_prot); + cmd.AddValue ("error_p", "Packet error rate", error_p); + cmd.AddValue ("bandwidth", "Bottleneck bandwidth", bandwidth); + cmd.AddValue ("access_bandwidth", "Access link bandwidth", access_bandwidth); + cmd.AddValue ("delay", "Access link delay", access_delay); + cmd.AddValue ("tracing", "Flag to enable/disable tracing", tracing); + cmd.AddValue ("tr_name", "Name of output trace file", tr_file_name); + cmd.AddValue ("cwnd_tr_name", "Name of output trace file", cwnd_tr_file_name); + cmd.AddValue ("ssthresh_tr_name", "Name of output trace file", ssthresh_tr_file_name); + cmd.AddValue ("data", "Number of Megabytes of data to transmit", data_mbytes); + cmd.AddValue ("mtu", "Size of IP packets to send in bytes", mtu_bytes); + cmd.AddValue ("num_flows", "Number of flows", num_flows); + cmd.AddValue ("duration", "Time to allow flows to run in seconds", duration); + cmd.AddValue ("run", "Run index (for setting repeatable seeds)", run); + cmd.AddValue ("flow_monitor", "Enable flow monitor", flow_monitor); cmd.Parse (argc, argv); - SeedManager::SetSeed(1); - SeedManager::SetRun(run); + SeedManager::SetSeed (1); + SeedManager::SetRun (run); // User may find it convenient to enable logging //LogComponentEnable("TcpVariantsComparison", LOG_LEVEL_ALL); @@ -188,12 +175,12 @@ //LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL); // Calculate the ADU size - Header* temp_header = new Ipv4Header(); - uint32_t ip_header = temp_header->GetSerializedSize(); + Header* temp_header = new Ipv4Header (); + uint32_t ip_header = temp_header->GetSerializedSize (); NS_LOG_LOGIC ("IP Header size is: " << ip_header); delete temp_header; - temp_header = new TcpHeader(); - uint32_t tcp_header = temp_header->GetSerializedSize(); + temp_header = new TcpHeader (); + uint32_t tcp_header = temp_header->GetSerializedSize (); NS_LOG_LOGIC ("TCP Header size is: " << tcp_header); delete temp_header; uint32_t tcp_adu_size = mtu_bytes - (ip_header + tcp_header); @@ -204,22 +191,28 @@ float stop_time = start_time + duration; // Select TCP variant - if (transport_prot.compare("TcpTahoe") == 0) - Config::SetDefault("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpTahoe::GetTypeId())); - else if (transport_prot.compare("TcpReno") == 0) - Config::SetDefault("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpReno::GetTypeId())); - else if (transport_prot.compare("TcpNewReno") == 0) - Config::SetDefault("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpNewReno::GetTypeId())); - else if (transport_prot.compare("TcpWestwood") == 0) - {// the default protocol type in ns3::TcpWestwood is WESTWOOD - Config::SetDefault("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpWestwood::GetTypeId())); - Config::SetDefault("ns3::TcpWestwood::FilterType", EnumValue(TcpWestwood::TUSTIN)); + if (transport_prot.compare ("TcpTahoe") == 0) + { + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpTahoe::GetTypeId ())); } - else if (transport_prot.compare("TcpWestwoodPlus") == 0) + else if (transport_prot.compare ("TcpReno") == 0) { - Config::SetDefault("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpWestwood::GetTypeId())); - Config::SetDefault("ns3::TcpWestwood::ProtocolType", EnumValue(TcpWestwood::WESTWOODPLUS)); - Config::SetDefault("ns3::TcpWestwood::FilterType", EnumValue(TcpWestwood::TUSTIN)); + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpReno::GetTypeId ())); + } + else if (transport_prot.compare ("TcpNewReno") == 0) + { + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpNewReno::GetTypeId ())); + } + else if (transport_prot.compare ("TcpWestwood") == 0) + { // the default protocol type in ns3::TcpWestwood is WESTWOOD + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpWestwood::GetTypeId ())); + Config::SetDefault ("ns3::TcpWestwood::FilterType", EnumValue (TcpWestwood::TUSTIN)); + } + else if (transport_prot.compare ("TcpWestwoodPlus") == 0) + { + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpWestwood::GetTypeId ())); + Config::SetDefault ("ns3::TcpWestwood::ProtocolType", EnumValue (TcpWestwood::WESTWOODPLUS)); + Config::SetDefault ("ns3::TcpWestwood::FilterType", EnumValue (TcpWestwood::TUSTIN)); } else { @@ -231,18 +224,18 @@ NodeContainer gateways; gateways.Create (1); NodeContainer sources; - sources.Create(num_flows); + sources.Create (num_flows); NodeContainer sinks; - sinks.Create(num_flows); + sinks.Create (num_flows); // Configure the error model // Here we use RateErrorModel with packet error rate - Ptr uv = CreateObject(); + Ptr uv = CreateObject (); uv->SetStream (50); RateErrorModel error_model; - error_model.SetRandomVariable(uv); - error_model.SetUnit(RateErrorModel::ERROR_UNIT_PACKET); - error_model.SetRate(error_p); + error_model.SetRandomVariable (uv); + error_model.SetUnit (RateErrorModel::ERROR_UNIT_PACKET); + error_model.SetRate (error_p); PointToPointHelper UnReLink; UnReLink.SetDeviceAttribute ("DataRate", StringValue (bandwidth)); @@ -262,16 +255,16 @@ LocalLink.SetDeviceAttribute ("DataRate", StringValue (access_bandwidth)); LocalLink.SetChannelAttribute ("Delay", StringValue (access_delay)); Ipv4InterfaceContainer sink_interfaces; - for (int i=0; i ascii_wrap; - if (tr_file_name.compare("") == 0) + if (tr_file_name.compare ("") == 0) { NS_LOG_DEBUG ("No trace file provided"); exit (1); } else { - ascii.open (tr_file_name.c_str()); - ascii_wrap = new OutputStreamWrapper(tr_file_name.c_str(), std::ios::out); + ascii.open (tr_file_name.c_str ()); + ascii_wrap = new OutputStreamWrapper (tr_file_name.c_str (), std::ios::out); } stack.EnableAsciiIpv4All (ascii_wrap); - Simulator::Schedule(Seconds(0.00001), &TraceCwnd, cwnd_tr_file_name); - Simulator::Schedule(Seconds(0.00001), &TraceSsThresh, ssthresh_tr_file_name); + Simulator::Schedule (Seconds (0.00001), &TraceCwnd, cwnd_tr_file_name); + Simulator::Schedule (Seconds (0.00001), &TraceSsThresh, ssthresh_tr_file_name); } - UnReLink.EnablePcapAll("TcpVariantsComparison", true); - LocalLink.EnablePcapAll("TcpVariantsComparison", true); + UnReLink.EnablePcapAll ("TcpVariantsComparison", true); + LocalLink.EnablePcapAll ("TcpVariantsComparison", true); // Flow monitor FlowMonitorHelper flowHelper; if (flow_monitor) { - flowHelper.InstallAll(); + flowHelper.InstallAll (); } - Simulator::Stop (Seconds(stop_time)); + Simulator::Stop (Seconds (stop_time)); Simulator::Run (); if (flow_monitor) { - flowHelper.SerializeToXmlFile("TcpVariantsComparison.flowmonitor", true, true); + flowHelper.SerializeToXmlFile ("TcpVariantsComparison.flowmonitor", true, true); } Simulator::Destroy ();