cong ctrl in progress
authorvictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Thu, 5 Nov 2009 10:51:15 +0000 (10:51 +0000)
committervictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Thu, 5 Nov 2009 10:51:15 +0000 (10:51 +0000)
git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@499 e16421f0-f15b-0410-abcd-98678b794739

datagram.cpp
ext/send_control.cpp
ext/send_control.h
sendrecv.cpp

index 50ef4d8..3a50a98 100644 (file)
@@ -26,12 +26,14 @@ uint64_t Datagram::dgrams_up=0, Datagram::dgrams_down=0,
          Datagram::bytes_up=0, Datagram::bytes_down=0;
 
 char* Datagram::TimeStr (tint time) {
-    static char ret_str[32][4]; // wow
+    assert(!time || time>=epoch);
+    static char ret_str[4][32]; // wow
     static int i;
     i = (i+1) & 3;
     if (time==0)
         time = now;
     time -= epoch;
+    assert(time>=0);
     int hours = time/TINT_HOUR;
     time %= TINT_HOUR;
     int mins = time/TINT_MIN;
index 50d569e..62c0f24 100644 (file)
@@ -38,8 +38,8 @@ void    PingPongController::OnDataRecvd(bin64_t b) {
 }
     
 void    PingPongController::OnAckRcvd(bin64_t ackd) {
-    if (ch_->data_out_.empty())
-        Swap(new SlowStartController(this));
+    //if (ch_->data_out_.empty())
+    Swap(new SlowStartController(this));
 }
 
 
@@ -66,14 +66,19 @@ void    KeepAliveController::OnAckRcvd(bin64_t ackd) {
 
 
 bool    CwndController::MaySendData() {
+    dprintf("%s #%i maysend %i < %f & %s (rtt %lli)\n",Datagram::TimeStr(),
+            ch_->id,(int)ch_->data_out_.size(),cwnd_,Datagram::TimeStr(NextSendTime()),
+            ch_->rtt_avg_);
     return ch_->data_out_.size() < cwnd_  &&  Datagram::now >= NextSendTime();
 }
     
 tint    CwndController::NextSendTime () {
+    tint sendtime;
     if (ch_->data_out_.size() < cwnd_)
-        return ch_->last_send_time_ + ch_->rtt_avg_ / cwnd_;
+        sendtime = ch_->last_send_time_ + (ch_->rtt_avg_ / cwnd_);
     else
-        return ch_->last_send_time_ + ch_->rtt_avg_ + ch_->dev_avg_ * 4 ;
+        sendtime = ch_->last_send_time_ + ch_->rtt_avg_ + ch_->dev_avg_ * 4 ;
+    return sendtime;
 }
     
 void    CwndController::OnDataSent(bin64_t b) {
index b8d4a77..f21560f 100644 (file)
@@ -77,7 +77,7 @@ struct KeepAliveController : public SendController {
 
 struct CwndController : public SendController {
     
-    float   cwnd_;
+    double   cwnd_;
     
     CwndController(SendController* orig, int cwnd=1) :
     SendController(orig), cwnd_(cwnd) {    }
index dc17aa9..be91314 100644 (file)
@@ -227,6 +227,11 @@ void       Channel::AddAck (Datagram& dgram) {
 
 
 void   Channel::Recv (Datagram& dgram) {
+    if (last_send_time_ && rtt_avg_==TINT_SEC && dev_avg_==0) {
+        rtt_avg_ = Datagram::now - last_send_time_;
+        dev_avg_ = rtt_avg_;
+        dprintf("%s #%i rtt init %lli\n",Datagram::TimeStr(),id,rtt_avg_);
+    }
     bin64_t data = dgram.size() ? bin64_t::NONE : bin64_t::ALL;
        while (dgram.size()) {
                uint8_t type = dgram.Pull8();
@@ -284,18 +289,16 @@ void      Channel::OnAck (Datagram& dgram) {
     dprintf("%s #%i -ack (%i,%lli)\n",Datagram::TimeStr(),id,ackd_pos.layer(),ackd_pos.offset());
     for (int i=0; i<8 && i<data_out_.size(); i++) 
         if (data_out_[i].bin.within(ackd_pos)) {
-            tintbin x = data_out_[i];
-            data_out_[i].bin = bin64_t::ALL;
-            tint rtt = Datagram::now-x.time;
+            tint rtt = Datagram::now-data_out_[i].time;
             rtt_avg_ = (rtt_avg_*3 + rtt) >> 2;
             dev_avg_ = ( dev_avg_*3 + abs(rtt-rtt_avg_) ) >> 2;
             dprintf("%s #%i rtt %lli dev %lli\n",
                     Datagram::TimeStr(),id,rtt_avg_,dev_avg_);
-            cc_->OnAckRcvd(x.bin);
+            cc_->OnAckRcvd(data_out_[i].bin);
         }
-    while (data_out_.size() && data_out_.front().bin==bin64_t::ALL)
-        data_out_.pop_front();
        ack_in_.set(ackd_pos);
+    while (data_out_.size() && ack_in_.get(data_out_.front().bin)==bins::FILLED)
+        data_out_.pop_front();
 }