Skip to content

Commit fc56de0

Browse files
tcp: Fixed SND ack comparison
1 parent 9641e46 commit fc56de0

2 files changed

Lines changed: 47 additions & 59 deletions

File tree

src/net/tcp/connection.cpp

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ void Connection::offer(size_t& packets)
170170

171171
// write until we either cant send more (window closes or no more in queue),
172172
// or we're out of packets.
173+
174+
static bool congested=false;
175+
if (!can_send())
176+
{
177+
if (sendq_remaining() > 0)
178+
{
179+
printf("Window_blocked %d data %zu empty packets sw=%ld fs=%ld WND=%d\n",sendq_remaining(),packets,(int64_t)send_window(), (int64_t)flight_size(),cb.SND.WND);
180+
congested=true;
181+
}
182+
}
183+
if (can_send() && congested)
184+
{
185+
printf("Window released congestion removed %zu packets\n",packets);
186+
congested=false;
187+
}
188+
173189
while(can_send() and packets)
174190
{
175191
auto packet = create_outgoing_packet();
@@ -397,49 +413,44 @@ bool Connection::handle_ack(const Packet_view& in)
397413
} // < dup ack
398414

399415
// new ack
400-
else if(LIKELY(in.ack() >= cb.SND.UNA))
401-
{
402-
if(is_win_update(in, true_win))
403-
{
404-
cb.SND.WND = true_win;
405-
cb.SND.WL1 = in.seq();
406-
cb.SND.WL2 = in.ack();
407-
//printf("<Connection::handle_ack> Window update (%u)\n", cb.SND.WND);
408-
}
409-
//pred_flags = htonl((in.tcp_header_length() << 26) | 0x10 | cb.SND.WND >> cb.SND.wind_shift);
410-
411-
// [RFC 6582] p. 8
412-
prev_highest_ack_ = cb.SND.UNA;
413-
highest_ack_ = in.ack();
414416

415-
if(cb.SND.TS_OK)
416-
{
417-
const auto* ts = in.ts_option();
418-
if(ts != nullptr) // TODO: not sure the packet is valid if TS missing
419-
last_acked_ts_ = ts->ecr;
420-
}
417+
if(is_win_update(in, true_win))
418+
{
419+
cb.SND.WND = true_win;
420+
cb.SND.WL1 = in.seq();
421+
cb.SND.WL2 = in.ack();
422+
//printf("<Connection::handle_ack> Window update (%u)\n", cb.SND.WND);
423+
}
424+
//pred_flags = htonl((in.tcp_header_length() << 26) | 0x10 | cb.SND.WND >> cb.SND.wind_shift);
421425

422-
cb.SND.UNA = in.ack();
426+
// [RFC 6582] p. 8
427+
prev_highest_ack_ = cb.SND.UNA;
428+
highest_ack_ = in.ack();
423429

424-
rtx_ack(in.ack());
430+
if(cb.SND.TS_OK)
431+
{
432+
const auto* ts = in.ts_option();
433+
if(ts != nullptr) // TODO: not sure the packet is valid if TS missing
434+
last_acked_ts_ = ts->ecr;
435+
}
425436

426-
take_rtt_measure(in);
437+
cb.SND.UNA = in.ack();
427438

428-
// do either congctrl or fastrecov according to New Reno
429-
(not fast_recovery_)
430-
? congestion_control(in) : fast_recovery(in);
439+
rtx_ack(in.ack());
431440

432-
dup_acks_ = 0;
441+
take_rtt_measure(in);
433442

434-
if(in.has_tcp_data() or in.isset(FIN))
435-
return true;
443+
// do either congctrl or fastrecov according to New Reno
444+
(not fast_recovery_)
445+
? congestion_control(in) : fast_recovery(in);
436446

437-
} // < new ack
447+
dup_acks_ = 0;
438448

439-
// ACK outside
440-
else {
449+
if(in.has_tcp_data() or in.isset(FIN))
441450
return true;
442-
}
451+
452+
// < new ack
453+
// Nothing to process
443454
return false;
444455
}
445456

src/net/tcp/connection_states.cpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,10 @@ bool Connection::State::check_ack(Connection& tcp, const Packet_view& in) {
240240
// Correction: [RFC 1122 p. 94]
241241
// ACK is inside sequence space
242242
//return tcp.handle_ack(in);
243-
if(in.ack() <= tcb.SND.NXT ) {
243+
244+
if ( (in.ack()-tcb.SND.UNA) <= (tcb.SND.NXT-tcb.SND.UNA)) {
244245

245246
return tcp.handle_ack(in);
246-
// this is a "new" ACK
247-
//if(tcb.SND.UNA <= in->ack()) {
248-
249-
// this is a NEW ACK
250-
//if(tcb.SND.UNA < in->ack())
251-
//{
252-
// tcp.acknowledge(in->ack());
253-
//}
254247
// [RFC 5681]
255248
/*
256249
DUPLICATE ACKNOWLEDGMENT:
@@ -268,23 +261,7 @@ bool Connection::State::check_ack(Connection& tcp, const Packet_view& in) {
268261
new data unless the incoming duplicate acknowledgment contains
269262
new SACK information.
270263
*/
271-
// this is a RFC 5681 DUP ACK
272-
//!in->isset(FIN) and !in->isset(SYN)
273-
//else if(tcp.reno_is_dup_ack(in)) {
274-
// debug2("<Connection::State::check_ack> Reno Dup ACK %u\n", in->ack());
275-
// tcp.reno_dup_ack(in->ack());
276-
//}
277-
// this is an RFC 793 DUP ACK
278-
//else {
279-
//printf("<Connection::State::check_ack> RFC 793 Dup ACK %u\n", in->ack());
280-
//}
281-
//}
282-
// this is an "old" ACK out of order
283-
//else {
284-
// printf("<Connection::State::check_ack> ACK out of order (SND.UNA > ACK)\n");
285-
//}
286-
// tcp.signal_sent();
287-
// return that buffer has been SENT - currently no support to receipt sent buffer.
264+
288265
}
289266
/* If the ACK acks something not yet sent (SEG.ACK > SND.NXT) then send an ACK, drop the segment, and return. */
290267
else {

0 commit comments

Comments
 (0)