Skip to content

Commit

Permalink
goodput
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonyangZhang committed Jan 23, 2022
1 parent dacfb3d commit 08caac8
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 16 deletions.
20 changes: 18 additions & 2 deletions plot-script/data_plot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gnuplot<<!
set xlabel "time/s"
set ylabel "rate/kbps"
set xrange [0:200]
set yrange [0:4500]
set yrange [0:4000]
set term "png"
set output "${output}-send-rate.png"
plot "${file1}" u 1:2 title "flow1" with lines lw 2 lc 1,\
Expand All @@ -21,7 +21,23 @@ plot "${file1}" u 1:2 title "flow1" with lines lw 2 lc 1,\
set output
exit
!

file1=${prefix1}_goodput.txt
file2=${prefix2}_goodput.txt
file3=${prefix3}_goodput.txt
output=${id}-${algo}
gnuplot<<!
set xlabel "time/s"
set ylabel "rate/kbps"
set xrange [0:200]
set yrange [0:4000]
set term "png"
set output "${output}-goodput.png"
plot "${file1}" u 1:2 title "flow1" with lines lw 2 lc 1,\
"${file2}" u 1:2 title "flow2" with lines lw 2 lc 2,\
"${file3}" u 1:2 title "flow3" with lines lw 2 lc 3
set output
exit
!
file1=${prefix1}_inflight.txt
file2=${prefix2}_inflight.txt
file3=${prefix3}_inflight.txt
Expand Down
112 changes: 103 additions & 9 deletions quic/model/ns3-quic-trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
#include "ns3-quic-trace.h"
#include "ns3-quic-util.h"
namespace ns3{
std::string Ns3QuicTracePath;
int uuid=1;
namespace{
std::string Ns3QuicTracePath;
int g_uuid=1;
Time g_goodputInterval=MilliSeconds(1000);
}
static inline int uuid_allocator(){
return uuid++;
return g_uuid++;
}
void set_quic_trace_folder(const std::string &path){
int len=path.size();
Expand All @@ -18,6 +21,9 @@ void set_quic_trace_folder(const std::string &path){
Ns3QuicTracePath=path;
}
}
void set_quic_goodput_interval(Time interval){
g_goodputInterval=interval;
}
Ns3QuicClientTrace::Ns3QuicClientTrace(){
m_uuid=uuid_allocator();
}
Expand Down Expand Up @@ -100,32 +106,100 @@ Ns3QuicServerTrace::Ns3QuicServerTrace(std::string &prefix,uint8_t e){
if(e&E_QS_OWD){
OpenOwdFile(name);
}
if(e&E_QS_LOST){
OpenLostFile(name);
}
if(e&E_QS_GOODPUT){
OpenGoodputFile(name);
}
}
Ns3QuicServerTrace::~Ns3QuicServerTrace(){
LogGoodput(true);
LogLostPackets();
Close();
}
void Ns3QuicServerTrace::OnOwd(int seq,int owd,int len){
if(m_owd.is_open()){
if(m_owd.is_open()||m_goodput.is_open()){
Time now=Simulator::Now();
m_readBytes+=len;
if(Time(0)==m_firstPacketTime){
m_firstPacketTime=now;
m_lastRateTime=now;
}
m_readBytes+=len;
if(m_owd.is_open()){
m_owd<<now.GetSeconds()<<"\t"<<seq<<"\t"<<owd<<"\t"<<len<<std::endl;
m_receiptTime=now;
}
m_owd<<now.GetSeconds()<<"\t"<<seq<<"\t"<<owd<<"\t"<<len<<std::endl;
m_receiptTime=now;
LogGoodput(false);
}

if(m_lost.is_open()){
if(seq>m_lastSeq-1){
int lost=seq-m_lastSeq-1;
m_lostPackets+=lost;
}
if(seq>m_lastSeq){
m_lastSeq=seq;
}
if(seq>m_largestSeq){
m_largestSeq=seq;
}
}
}
void Ns3QuicServerTrace::OpenOwdFile(const std::string& name){
std::string path_name=name+"_owd.txt";
m_owd.open(path_name.c_str(), std::fstream::out);
}
void Ns3QuicServerTrace::OpenLostFile(const std::string& name){
std::string path_name=name+"_lost.txt";
m_lost.open(path_name.c_str(), std::fstream::out);
}
void Ns3QuicServerTrace::OpenGoodputFile(const std::string& name){
std::string path_name=name+"_goodput.txt";
m_goodput.open(path_name.c_str(), std::fstream::out);
}
void Ns3QuicServerTrace::LogLostPackets(){
if(m_lost.is_open()){
float ratio=0.0;
if(m_largestSeq>0){
ratio=1.0*m_lostPackets*100/m_largestSeq;
}
m_lost<<m_lostPackets<<"\t"<<m_largestSeq<<"\t"<<ratio<<std::endl;
}
}
void Ns3QuicServerTrace::LogGoodput(bool dtor){
if(m_goodput.is_open()){
if(dtor){
if(m_receiptTime>m_lastRateTime){
Time delta=m_receiptTime-m_lastRateTime;
float kbps=1.0*(m_readBytes-m_lastRateBytes)*8/delta.GetMilliSeconds();
m_goodput<<m_receiptTime.GetSeconds()<<" "<<kbps<<std::endl;
}
}else{
if(m_receiptTime>=m_lastRateTime+g_goodputInterval){
Time delta=m_receiptTime-m_lastRateTime;
float kbps=1.0*(m_readBytes-m_lastRateBytes)*8/delta.GetMilliSeconds();
m_goodput<<m_receiptTime.GetSeconds()<<" "<<kbps<<std::endl;
m_lastRateBytes=m_readBytes;
m_lastRateTime=m_receiptTime;
}
}
}
}
void Ns3QuicServerTrace::Close(){
if(m_owd.is_open()){
m_owd.close();
}
if(m_lost.is_open()){
m_lost.close();
}
if(m_goodput.is_open()){
m_goodput.close();
}
}
Ns3QuicServerTraceDispatcher::Ns3QuicServerTraceDispatcher(){}
Ns3QuicServerTraceDispatcher::Ns3QuicServerTraceDispatcher(DataRate rate,Time start_time):
m_bottleneckRate(rate),
m_startTime(start_time){}
Ns3QuicServerTraceDispatcher::~Ns3QuicServerTraceDispatcher(){
Shutdown();
}
Expand All @@ -136,10 +210,18 @@ void Ns3QuicServerTraceDispatcher::Shutdown(){
m_traceDb.erase(it);
delete trace;
}
if(m_util.is_open()){
Time duration=m_receiptTime-m_startTime;
int64_t channel_bit=m_bottleneckRate.GetBitRate()*duration.GetMilliSeconds()/1000;
float util=1.0*m_readBytes*8*100/(channel_bit);
m_util<<util<<std::endl;
m_util.close();
}
}
void Ns3QuicServerTraceDispatcher::LogEnable(std::string &topo_id,uint8_t e){
m_topoId=topo_id;
m_e=e;
OpenUtilFile(topo_id);
}
bool Ns3QuicServerTraceDispatcher::AddMonitorAddressPair(const Ns3QuicAddressPair &addr_pair){
bool success=false;
Expand All @@ -158,12 +240,24 @@ void Ns3QuicServerTraceDispatcher::OnOwd(const InetSocketAddress &c,const InetSo
if(Time(0)==m_firstPacketTime){
m_firstPacketTime=now;
}
m_receiptTime=now;
Ns3QuicAddressPair addr_pair(c,s);
auto it=m_traceDb.find(addr_pair);
if(it!=m_traceDb.end()){
it->second->OnOwd(seq,owd,len);
}
m_receiptTime=now;
}
void Ns3QuicServerTraceDispatcher::OpenUtilFile(const std::string& topo_id){
char buf[FILENAME_MAX];
memset(buf,0,FILENAME_MAX);
std::string name;
if(0==Ns3QuicTracePath.size()){
name=std::string (getcwd(buf, FILENAME_MAX))+
"/traces/"+topo_id+"_util.txt";
}else{
name=std::string(Ns3QuicTracePath)+topo_id+"_util.txt";
}
m_util.open(name.c_str(), std::fstream::out);
}

}
24 changes: 21 additions & 3 deletions quic/model/ns3-quic-trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ns3/nstime.h"
#include "ns3/inet-socket-address.h"
#include "ns3/callback.h"
#include "ns3/data-rate.h"
#include "ns3/ns3-quic-util.h"
namespace ns3{
//log name format: topoid_ip1:port_ip2:port_type.txt
Expand All @@ -17,9 +18,11 @@ enum QuicClientTraceEnable:uint8_t{
enum QuicServerTraceEnabel:uint8_t{
E_QS_OWD=0x01,
E_QS_GOODPUT=0x02,
E_QS_ALL=E_QS_OWD,
E_QS_LOST=0x04,
E_QS_ALL=E_QS_OWD|E_QS_GOODPUT|E_QS_LOST,
};
void set_quic_trace_folder(const std::string &path);
void set_quic_goodput_interval(Time interval);
class Ns3QuicClientTrace{
public:
Ns3QuicClientTrace();
Expand All @@ -45,26 +48,41 @@ class Ns3QuicServerTrace{
void OnOwd(int seq,int owd,int len);
private:
void OpenOwdFile(const std::string& name);
void OpenLostFile(const std::string& name);
void OpenGoodputFile(const std::string& name);
void LogLostPackets();
void LogGoodput(bool dtor);
void Close();
std::fstream m_owd;
int m_lastSeq=0;
int m_largestSeq=0;
int m_lostPackets=0;
int64_t m_lastRateBytes=0;
Time m_lastRateTime=Time(0);
int64_t m_readBytes=0;
Time m_firstPacketTime=Time(0);
Time m_receiptTime=Time(0);
std::fstream m_owd;
std::fstream m_lost;
std::fstream m_goodput;
};
class Ns3QuicServerTraceDispatcher{
public:
Ns3QuicServerTraceDispatcher();
Ns3QuicServerTraceDispatcher(DataRate rate,Time start_time);
~Ns3QuicServerTraceDispatcher();
void Shutdown();
void LogEnable(std::string &topo_id,uint8_t e);
bool AddMonitorAddressPair(const Ns3QuicAddressPair &addr_pair);
void OnOwd(const InetSocketAddress &c,const InetSocketAddress & s,int seq,int owd,int len);
private:
void OpenUtilFile(const std::string& topo_id);
DataRate m_bottleneckRate;
Time m_startTime;
std::string m_topoId;
uint8_t m_e=0;
int64_t m_readBytes=0;
Time m_firstPacketTime=Time(0);
Time m_receiptTime=Time(0);
std::map<Ns3QuicAddressPair,Ns3QuicServerTrace*> m_traceDb;
std::fstream m_util;
};
}
5 changes: 3 additions & 2 deletions scratch/quic-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void test_app(Time app_start,Time app_stop,uint8_t client_log_flag,
std::vector<Ns3QuicClientTrace*> client_traces;
Ns3QuicServerTraceDispatcher *server_trace=nullptr;
if(server_log_flag&E_QS_ALL){
server_trace=new Ns3QuicServerTraceDispatcher();
DataRate bottleneck_bw(bps);
server_trace=new Ns3QuicServerTraceDispatcher(bottleneck_bw,app_start);
server_trace->LogEnable(topo_id,server_log_flag);
server_app->set_trace(server_trace);
}
Expand Down Expand Up @@ -211,7 +212,7 @@ int main(int argc, char* argv[]){
//BANDWIDTH
quic::BackendType type=quic::BackendType::BANDWIDTH;
uint8_t client_log_flag=E_QC_IN_FLIGHT|E_QC_SEND_RATE;
uint8_t server_log_flag=E_QS_OWD;
uint8_t server_log_flag=E_QS_OWD|E_QS_LOST|E_QS_GOODPUT;
test_app(Seconds(0.001),Seconds(200),client_log_flag,server_log_flag,type,cc_type);
return 0;
}

0 comments on commit 08caac8

Please sign in to comment.