Skip to content

Commit

Permalink
window size error at fill_window()
Browse files Browse the repository at this point in the history
  • Loading branch information
dentiny committed May 19, 2021
1 parent c5cfdc3 commit 6730d05
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 18 additions & 4 deletions libsponge/tcp_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "tcp_config.hh"

#include <iostream>
#include <random>

// Dummy implementation of a TCP sender
Expand Down Expand Up @@ -65,10 +66,10 @@ void TCPSender::fill_window() {
size_t size = max(window_size_, static_cast<decltype(window_size_)>(1)); // If received window size is 0, set it to 1.
size = min(TCPConfig::MAX_PAYLOAD_SIZE, size);
string content = stream_.read(size);

string content_copy = content;

size = min(size, content.length());
if (size == 0) { // there's no unread content within ByteStream
return;
}
segment.payload() = Buffer(move(content));
next_seqno_ += size;

Expand All @@ -78,11 +79,24 @@ void TCPSender::fill_window() {
fin_seqno_ = next_seqno_++;
}

// Check whether the current segment is empty: since sequence space includes
// SYN and FIN mark, so have to calculate just before actually sending out.
if (segment.length_in_sequence_space() == 0) {
return;
}

// Segment already set, send the segment out.
bytes_in_flight_ += segment.length_in_sequence_space();
flying_segments_.push(segment);
segments_out_.push(segment);

if (content_copy == string("01") || content_copy == string("23")) {
cout << "Sending content = " << content_copy << endl;
cout << "after sending, bytes in flight = " << bytes_in_flight_ << endl;
cout << "flying segment # = " << flying_segments_.size() << endl;
cout << "segments out # = " << segments_out_.size() << endl;
}

// Start the timer if needed.
if (!timer_starts_) {
timer_starts_ = true;
Expand All @@ -103,7 +117,7 @@ void TCPSender::fill_window() {
void TCPSender::ack_received(const WrappingInt32 ackno, const uint16_t window_size) {
// Check whether ack valid(ackno_64 < next_acknp_64).
uint64_t abs_ack_seqno64 = unwrap(ackno, isn_, next_seqno_);
if (abs_ack_seqno64 >= next_seqno_) {
if (abs_ack_seqno64 > next_seqno_) { // NOTE: consider SYN.
return;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/send_transmit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ int main() {
test.execute(ExpectSegment{}.with_no_flags().with_syn(true).with_payload_size(0).with_seqno(isn));
test.execute(AckReceived{WrappingInt32{isn + 1}}.with_win(3));
test.execute(ExpectState{TCPSenderStateSummary::SYN_ACKED});

test.execute(WriteBytes("01"));
test.execute(ExpectBytesInFlight{2});
test.execute(ExpectSegment{}.with_data("01"));
test.execute(ExpectNoSegment{});
test.execute(ExpectSeqno{WrappingInt32{isn + 1 + 2}});

test.execute(WriteBytes("23"));
test.execute(ExpectBytesInFlight{3});
test.execute(ExpectSegment{}.with_data("2"));
Expand Down

0 comments on commit 6730d05

Please sign in to comment.