From: JoriPaananen Date: Tue, 6 Oct 2009 10:22:28 +0000 (+0000) Subject: Added tests/ledbattest2.cpp. It has command line options for destination address... X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=1eb2eeb881364f44a1a0241d700dc1b1229b1a67;p=swift-upb.git Added tests/ledbattest2.cpp. It has command line options for destination address, send and ack ports. git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@390 e16421f0-f15b-0410-abcd-98678b794739 --- diff --git a/tests/SConscript b/tests/SConscript index 21bad71..9bce647 100644 --- a/tests/SConscript +++ b/tests/SConscript @@ -35,6 +35,13 @@ env.Program( LIBS=['p2tp','stdc++','gtest','glog','crypto'], LIBPATH='..' ) +env.Program( + target='ledbattest2', + source=['ledbattest2.cpp'], + CPPPATH=['..'], + LIBS=['p2tp','stdc++','gtest','glog','crypto'], + LIBPATH='..' ) + env.Program( target='bin64test', source=['bin64test.cpp','../bin64.h'], diff --git a/tests/ledbattest2.cpp b/tests/ledbattest2.cpp new file mode 100644 index 0000000..0eb0792 --- /dev/null +++ b/tests/ledbattest2.cpp @@ -0,0 +1,206 @@ +#include +#include +#include +#include +#include +#include +#include +#include "datagram.h" +#include "p2tp.h" +#include +#include + +using namespace p2tp; +using namespace std; + +/** + TODO + * losses + * smooth rate + * seq 12345 stop + * busy pipe => negative cwnd +*/ + +unsigned long dest_addr; +int send_port = 10001; +int ack_port = 10002; + +TEST(Datagram,LedbatTest) { + + int MAX_REORDERING = 3; + tint TARGET = 25*MSEC; + float GAIN = 1.0/TARGET; + int seq_off = 0; + float cwnd = 1; + tint DELAY_BIN = SEC*30; + tint min_delay = NEVER; + tint rtt_avg = NEVER>>4, dev_avg = NEVER>>4; + tint last_bin_time = 0; + tint last_drop_time = 0; + int delay_bin = 0; + deque history, delay_history; + tint min_delay_bins[4] = {NEVER,NEVER, + NEVER,NEVER}; + tint cur_delays[4] = {NEVER,NEVER, + NEVER,NEVER}; + tint last_sec = 0; + int sec_ackd = 0; + + int send_sock = Datagram::Bind(send_port); // bind sending socket + int ack_sock = Datagram::Bind(ack_port); // bind receiving socket + struct sockaddr_in send_to, ack_to; + send_to.sin_family = AF_INET; + send_to.sin_port = htons(ack_port); + send_to.sin_addr.s_addr = dest_addr; + ack_to.sin_family = AF_INET; + ack_to.sin_port = htons(send_port); + ack_to.sin_addr.s_addr = dest_addr; + uint8_t* garbage = (uint8_t*) malloc(1024); + int socks[2] = {send_sock,ack_sock}; + int sock2read; + tint wait_time = 100*MSEC; + + while (sock2read = Datagram::Wait(2,socks,wait_time)) { + tint now = Datagram::Time(); + if (sock2read==ack_sock) { + Datagram data(ack_sock); // send an acknowledgement + data.Recv(); + int seq = data.Pull32(); + Datagram ack(ack_sock,ack_to); + ack.Push32(seq); + ack.Push64(now); + if (4+8!=ack.Send()) + fprintf(stderr,"short write\n"); + fprintf(stderr,"%lli rcvd%i\n",now/SEC,seq); + // TODO: peer cwnd !!! + continue; + } + if (sock2read==send_sock) { // process an acknowledgement + Datagram ack(send_sock); + ack.Recv(); + int seq = ack.Pull32(); + tint arrival_time = ack.Pull64(); + seq -= seq_off; + if (seq<0) + continue; + if (seq>=history.size()) + continue; + if (history[seq]==0) + continue; + tint send_time = history[seq]; + history[seq] = 0; + if (seq>MAX_REORDERING*2) { //loss + if (last_drop_time delay) + min_delay_bins[delay_bin] = delay; + if (delay < min_delay) + min_delay = delay; + cur_delays[(seq_off+seq)%4] = delay; + tint current_delay = NEVER; + for(int i=0; i<4; i++) + if (current_delay > cur_delays[i]) + current_delay = cur_delays[i]; // FIXME avg + tint queueing_delay = current_delay - min_delay; + // adjust cwnd + tint off_target = TARGET - queueing_delay; + //cerr<<"\t"<