From 6fcdcdbea184e2cfb5df2007674ef582757b1fd1 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 23 Feb 2018 20:56:07 +0800 Subject: [PATCH] make golint happy about the congestion tests --- internal/congestion/cubic_sender_test.go | 344 +++++++++--------- internal/congestion/cubic_test.go | 93 +++-- internal/congestion/hybrid_slow_start_test.go | 54 +-- internal/congestion/prr_sender_test.go | 66 ++-- internal/congestion/rtt_stats_test.go | 102 +++--- 5 files changed, 329 insertions(+), 330 deletions(-) diff --git a/internal/congestion/cubic_sender_test.go b/internal/congestion/cubic_sender_test.go index 28cd600b9..a4dceaab9 100644 --- a/internal/congestion/cubic_sender_test.go +++ b/internal/congestion/cubic_sender_test.go @@ -45,14 +45,14 @@ var _ = Describe("Cubic Sender", func() { SendAvailableSendWindowLen := func(packetLength protocol.ByteCount) int { // Send as long as TimeUntilSend returns InfDuration. - packets_sent := 0 + packetsSent := 0 for bytesInFlight < sender.GetCongestionWindow() { sender.OnPacketSent(clock.Now(), bytesInFlight, packetNumber, packetLength, true) packetNumber++ - packets_sent++ + packetsSent++ bytesInFlight += packetLength } - return packets_sent + return packetsSent } // Normal is that TCP acks every other segment. @@ -108,14 +108,14 @@ var _ = Describe("Cubic Sender", func() { It("application limited slow start", func() { // Send exactly 10 packets and ensure the CWND ends at 14 packets. - const kNumberOfAcks = 5 + const numberOfAcks = 5 // At startup make sure we can send. Expect(sender.TimeUntilSend(0)).To(BeZero()) // Make sure we can send. Expect(sender.TimeUntilSend(0)).To(BeZero()) SendAvailableSendWindow() - for i := 0; i < kNumberOfAcks; i++ { + for i := 0; i < numberOfAcks; i++ { AckNPackets(2) } bytesToSend := sender.GetCongestionWindow() @@ -125,59 +125,59 @@ var _ = Describe("Cubic Sender", func() { }) It("exponential slow start", func() { - const kNumberOfAcks = 20 + const numberOfAcks = 20 // At startup make sure we can send. Expect(sender.TimeUntilSend(0)).To(BeZero()) Expect(sender.BandwidthEstimate()).To(BeZero()) // Make sure we can send. Expect(sender.TimeUntilSend(0)).To(BeZero()) - for i := 0; i < kNumberOfAcks; i++ { + for i := 0; i < numberOfAcks; i++ { // Send our full send window. SendAvailableSendWindow() AckNPackets(2) } cwnd := sender.GetCongestionWindow() - Expect(cwnd).To(Equal(defaultWindowTCP + protocol.DefaultTCPMSS*2*kNumberOfAcks)) + Expect(cwnd).To(Equal(defaultWindowTCP + protocol.DefaultTCPMSS*2*numberOfAcks)) Expect(sender.BandwidthEstimate()).To(Equal(BandwidthFromDelta(cwnd, rttStats.SmoothedRTT()))) }) It("slow start packet loss", func() { sender.SetNumEmulatedConnections(1) - const kNumberOfAcks = 10 - for i := 0; i < kNumberOfAcks; i++ { + const numberOfAcks = 10 + for i := 0; i < numberOfAcks; i++ { // Send our full send window. SendAvailableSendWindow() AckNPackets(2) } SendAvailableSendWindow() - expected_send_window := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * kNumberOfAcks) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * numberOfAcks) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Lose a packet to exit slow start. LoseNPackets(1) - packets_in_recovery_window := expected_send_window / protocol.DefaultTCPMSS + packetsInRecoveryWindow := expectedSendWindow / protocol.DefaultTCPMSS // We should now have fallen out of slow start with a reduced window. - expected_send_window = protocol.ByteCount(float32(expected_send_window) * renoBeta) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow = protocol.ByteCount(float32(expectedSendWindow) * renoBeta) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Recovery phase. We need to ack every packet in the recovery window before // we exit recovery. - number_of_packets_in_window := expected_send_window / protocol.DefaultTCPMSS - AckNPackets(int(packets_in_recovery_window)) + numberOfPacketsInWindow := expectedSendWindow / protocol.DefaultTCPMSS + AckNPackets(int(packetsInRecoveryWindow)) SendAvailableSendWindow() - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // We need to ack an entire window before we increase CWND by 1. - AckNPackets(int(number_of_packets_in_window) - 2) + AckNPackets(int(numberOfPacketsInWindow) - 2) SendAvailableSendWindow() - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Next ack should increase cwnd by 1. AckNPackets(1) - expected_send_window += protocol.DefaultTCPMSS - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow += protocol.DefaultTCPMSS + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Now RTO and ensure slow start gets reset. Expect(sender.HybridSlowStart().Started()).To(BeTrue()) @@ -189,46 +189,46 @@ var _ = Describe("Cubic Sender", func() { sender.SetSlowStartLargeReduction(true) sender.SetNumEmulatedConnections(1) - const kNumberOfAcks = 10 - for i := 0; i < kNumberOfAcks; i++ { + const numberOfAcks = 10 + for i := 0; i < numberOfAcks; i++ { // Send our full send window. SendAvailableSendWindow() AckNPackets(2) } SendAvailableSendWindow() - expected_send_window := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * kNumberOfAcks) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * numberOfAcks) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Lose a packet to exit slow start. We should now have fallen out of // slow start with a window reduced by 1. LoseNPackets(1) - expected_send_window -= protocol.DefaultTCPMSS - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow -= protocol.DefaultTCPMSS + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Lose 5 packets in recovery and verify that congestion window is reduced // further. LoseNPackets(5) - expected_send_window -= 5 * protocol.DefaultTCPMSS - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow -= 5 * protocol.DefaultTCPMSS + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) - packets_in_recovery_window := expected_send_window / protocol.DefaultTCPMSS + packetsInRecoveryWindow := expectedSendWindow / protocol.DefaultTCPMSS // Recovery phase. We need to ack every packet in the recovery window before // we exit recovery. - number_of_packets_in_window := expected_send_window / protocol.DefaultTCPMSS - AckNPackets(int(packets_in_recovery_window)) + numberOfPacketsInWindow := expectedSendWindow / protocol.DefaultTCPMSS + AckNPackets(int(packetsInRecoveryWindow)) SendAvailableSendWindow() - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // We need to ack the rest of the window before cwnd increases by 1. - AckNPackets(int(number_of_packets_in_window - 1)) + AckNPackets(int(numberOfPacketsInWindow - 1)) SendAvailableSendWindow() - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Next ack should increase cwnd by 1. AckNPackets(1) - expected_send_window += protocol.DefaultTCPMSS - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow += protocol.DefaultTCPMSS + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Now RTO and ensure slow start gets reset. Expect(sender.HybridSlowStart().Started()).To(BeTrue()) @@ -240,27 +240,27 @@ var _ = Describe("Cubic Sender", func() { sender.SetSlowStartLargeReduction(true) sender.SetNumEmulatedConnections(1) - const kNumberOfAcks = 10 - for i := 0; i < kNumberOfAcks; i++ { + const numberOfAcks = 10 + for i := 0; i < numberOfAcks; i++ { // Send our full send window in half sized packets. SendAvailableSendWindowLen(protocol.DefaultTCPMSS / 2) AckNPackets(2) } SendAvailableSendWindowLen(protocol.DefaultTCPMSS / 2) - expected_send_window := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * kNumberOfAcks) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * numberOfAcks) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Lose a packet to exit slow start. We should now have fallen out of // slow start with a window reduced by 1. LoseNPackets(1) - expected_send_window -= protocol.DefaultTCPMSS - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow -= protocol.DefaultTCPMSS + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Lose 10 packets in recovery and verify that congestion window is reduced // by 5 packets. LoseNPacketsLen(10, protocol.DefaultTCPMSS/2) - expected_send_window -= 5 * protocol.DefaultTCPMSS - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow -= 5 * protocol.DefaultTCPMSS + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) }) // this test doesn't work any more after introducing the pacing needed for QUIC @@ -280,47 +280,47 @@ var _ = Describe("Cubic Sender", func() { sender.SetNumEmulatedConnections(1) // Test based on the first example in RFC6937. // Ack 10 packets in 5 acks to raise the CWND to 20, as in the example. - const kNumberOfAcks = 5 - for i := 0; i < kNumberOfAcks; i++ { + const numberOfAcks = 5 + for i := 0; i < numberOfAcks; i++ { // Send our full send window. SendAvailableSendWindow() AckNPackets(2) } SendAvailableSendWindow() - expected_send_window := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * kNumberOfAcks) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * numberOfAcks) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) LoseNPackets(1) // We should now have fallen out of slow start with a reduced window. - send_window_before_loss := expected_send_window - expected_send_window = protocol.ByteCount(float32(expected_send_window) * renoBeta) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + sendWindowBeforeLoss := expectedSendWindow + expectedSendWindow = protocol.ByteCount(float32(expectedSendWindow) * renoBeta) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Testing TCP proportional rate reduction. // We should send packets paced over the received acks for the remaining // outstanding packets. The number of packets before we exit recovery is the // original CWND minus the packet that has been lost and the one which // triggered the loss. - remaining_packets_in_recovery := send_window_before_loss/protocol.DefaultTCPMSS - 2 + remainingPacketsInRecovery := sendWindowBeforeLoss/protocol.DefaultTCPMSS - 2 - for i := protocol.ByteCount(0); i < remaining_packets_in_recovery; i++ { + for i := protocol.ByteCount(0); i < remainingPacketsInRecovery; i++ { AckNPackets(1) SendAvailableSendWindow() - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) } // We need to ack another window before we increase CWND by 1. - number_of_packets_in_window := expected_send_window / protocol.DefaultTCPMSS - for i := protocol.ByteCount(0); i < number_of_packets_in_window; i++ { + numberOfPacketsInWindow := expectedSendWindow / protocol.DefaultTCPMSS + for i := protocol.ByteCount(0); i < numberOfPacketsInWindow; i++ { AckNPackets(1) Expect(SendAvailableSendWindow()).To(Equal(1)) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) } AckNPackets(1) - expected_send_window += protocol.DefaultTCPMSS - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow += protocol.DefaultTCPMSS + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) }) It("slow start burst packet loss PRR", func() { @@ -329,29 +329,29 @@ var _ = Describe("Cubic Sender", func() { // forward acknowledgements, so the first two incoming acks will trigger // PRR immediately. // Ack 20 packets in 10 acks to raise the CWND to 30. - const kNumberOfAcks = 10 - for i := 0; i < kNumberOfAcks; i++ { + const numberOfAcks = 10 + for i := 0; i < numberOfAcks; i++ { // Send our full send window. SendAvailableSendWindow() AckNPackets(2) } SendAvailableSendWindow() - expected_send_window := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * kNumberOfAcks) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * numberOfAcks) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Lose one more than the congestion window reduction, so that after loss, // bytes_in_flight is lesser than the congestion window. - send_window_after_loss := protocol.ByteCount(renoBeta * float32(expected_send_window)) - num_packets_to_lose := (expected_send_window-send_window_after_loss)/protocol.DefaultTCPMSS + 1 - LoseNPackets(int(num_packets_to_lose)) + sendWindowAfterLoss := protocol.ByteCount(renoBeta * float32(expectedSendWindow)) + numPacketsToLose := (expectedSendWindow-sendWindowAfterLoss)/protocol.DefaultTCPMSS + 1 + LoseNPackets(int(numPacketsToLose)) // Immediately after the loss, ensure at least one packet can be sent. // Losses without subsequent acks can occur with timer based loss detection. Expect(sender.TimeUntilSend(bytesInFlight)).To(BeZero()) AckNPackets(1) // We should now have fallen out of slow start with a reduced window. - expected_send_window = protocol.ByteCount(float32(expected_send_window) * renoBeta) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow = protocol.ByteCount(float32(expectedSendWindow) * renoBeta) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Only 2 packets should be allowed to be sent, per PRR-SSRB Expect(SendAvailableSendWindow()).To(Equal(2)) @@ -371,7 +371,7 @@ var _ = Describe("Cubic Sender", func() { Expect(SendAvailableSendWindow()).To(Equal(2)) // Exit recovery and return to sending at the new rate. - for i := 0; i < kNumberOfAcks; i++ { + for i := 0; i < numberOfAcks; i++ { AckNPackets(1) Expect(SendAvailableSendWindow()).To(Equal(1)) } @@ -398,114 +398,114 @@ var _ = Describe("Cubic Sender", func() { }) It("retransmission delay", func() { - const kRttMs = 10 * time.Millisecond - const kDeviationMs = 3 * time.Millisecond + const rtt = 10 * time.Millisecond + const deviation = 3 * time.Millisecond Expect(sender.RetransmissionDelay()).To(BeZero()) - rttStats.UpdateRTT(kRttMs, 0, clock.Now()) + rttStats.UpdateRTT(rtt, 0, clock.Now()) // Initial value is to set the median deviation to half of the initial // rtt, the median in then multiplied by a factor of 4 and finally the // smoothed rtt is added which is the initial rtt. - expected_delay := kRttMs + kRttMs/2*4 - Expect(sender.RetransmissionDelay()).To(Equal(expected_delay)) + expectedDelay := rtt + rtt/2*4 + Expect(sender.RetransmissionDelay()).To(Equal(expectedDelay)) for i := 0; i < 100; i++ { // run to make sure that we converge. - rttStats.UpdateRTT(kRttMs+kDeviationMs, 0, clock.Now()) - rttStats.UpdateRTT(kRttMs-kDeviationMs, 0, clock.Now()) + rttStats.UpdateRTT(rtt+deviation, 0, clock.Now()) + rttStats.UpdateRTT(rtt-deviation, 0, clock.Now()) } - expected_delay = kRttMs + kDeviationMs*4 + expectedDelay = rtt + deviation*4 - Expect(rttStats.SmoothedRTT()).To(BeNumerically("~", kRttMs, time.Millisecond)) - Expect(sender.RetransmissionDelay()).To(BeNumerically("~", expected_delay, time.Millisecond)) + Expect(rttStats.SmoothedRTT()).To(BeNumerically("~", rtt, time.Millisecond)) + Expect(sender.RetransmissionDelay()).To(BeNumerically("~", expectedDelay, time.Millisecond)) Expect(sender.BandwidthEstimate() / BytesPerSecond).To(Equal(Bandwidth( sender.GetCongestionWindow() * protocol.ByteCount(time.Second) / protocol.ByteCount(rttStats.SmoothedRTT()), ))) }) It("slow start max send window", func() { - const kMaxCongestionWindowTCP = 50 - const kNumberOfAcks = 100 - sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindowTCP) + const maxCongestionWindowTCP = 50 + const numberOfAcks = 100 + sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, maxCongestionWindowTCP) - for i := 0; i < kNumberOfAcks; i++ { + for i := 0; i < numberOfAcks; i++ { // Send our full send window. SendAvailableSendWindow() AckNPackets(2) } - expected_send_window := kMaxCongestionWindowTCP * protocol.DefaultTCPMSS - Expect(sender.GetCongestionWindow()).To(Equal(protocol.ByteCount(expected_send_window))) + expectedSendWindow := maxCongestionWindowTCP * protocol.DefaultTCPMSS + Expect(sender.GetCongestionWindow()).To(Equal(protocol.ByteCount(expectedSendWindow))) }) It("tcp reno max congestion window", func() { - const kMaxCongestionWindowTCP = 50 - const kNumberOfAcks = 1000 - sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindowTCP) + const maxCongestionWindowTCP = 50 + const numberOfAcks = 1000 + sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, maxCongestionWindowTCP) SendAvailableSendWindow() AckNPackets(2) // Make sure we fall out of slow start. LoseNPackets(1) - for i := 0; i < kNumberOfAcks; i++ { + for i := 0; i < numberOfAcks; i++ { // Send our full send window. SendAvailableSendWindow() AckNPackets(2) } - expected_send_window := kMaxCongestionWindowTCP * protocol.DefaultTCPMSS - Expect(sender.GetCongestionWindow()).To(Equal(protocol.ByteCount(expected_send_window))) + expectedSendWindow := maxCongestionWindowTCP * protocol.DefaultTCPMSS + Expect(sender.GetCongestionWindow()).To(Equal(protocol.ByteCount(expectedSendWindow))) }) It("tcp cubic max congestion window", func() { - const kMaxCongestionWindowTCP = 50 + const maxCongestionWindowTCP = 50 // Set to 10000 to compensate for small cubic alpha. - const kNumberOfAcks = 10000 + const numberOfAcks = 10000 - sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindowTCP) + sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, maxCongestionWindowTCP) SendAvailableSendWindow() AckNPackets(2) // Make sure we fall out of slow start. LoseNPackets(1) - for i := 0; i < kNumberOfAcks; i++ { + for i := 0; i < numberOfAcks; i++ { // Send our full send window. SendAvailableSendWindow() AckNPackets(2) } - expected_send_window := kMaxCongestionWindowTCP * protocol.DefaultTCPMSS - Expect(sender.GetCongestionWindow()).To(Equal(protocol.ByteCount(expected_send_window))) + expectedSendWindow := maxCongestionWindowTCP * protocol.DefaultTCPMSS + Expect(sender.GetCongestionWindow()).To(Equal(protocol.ByteCount(expectedSendWindow))) }) It("tcp cubic reset epoch on quiescence", func() { - const kMaxCongestionWindow = 50 - const kMaxCongestionWindowBytes = kMaxCongestionWindow * protocol.DefaultTCPMSS - sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindow) + const maxCongestionWindow = 50 + const maxCongestionWindowBytes = maxCongestionWindow * protocol.DefaultTCPMSS + sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, maxCongestionWindow) - num_sent := SendAvailableSendWindow() + numSent := SendAvailableSendWindow() // Make sure we fall out of slow start. - saved_cwnd := sender.GetCongestionWindow() + saveCwnd := sender.GetCongestionWindow() LoseNPackets(1) - Expect(saved_cwnd).To(BeNumerically(">", sender.GetCongestionWindow())) + Expect(saveCwnd).To(BeNumerically(">", sender.GetCongestionWindow())) // Ack the rest of the outstanding packets to get out of recovery. - for i := 1; i < num_sent; i++ { + for i := 1; i < numSent; i++ { AckNPackets(1) } Expect(bytesInFlight).To(BeZero()) // Send a new window of data and ack all; cubic growth should occur. - saved_cwnd = sender.GetCongestionWindow() - num_sent = SendAvailableSendWindow() - for i := 0; i < num_sent; i++ { + saveCwnd = sender.GetCongestionWindow() + numSent = SendAvailableSendWindow() + for i := 0; i < numSent; i++ { AckNPackets(1) } - Expect(saved_cwnd).To(BeNumerically("<", sender.GetCongestionWindow())) - Expect(kMaxCongestionWindowBytes).To(BeNumerically(">", sender.GetCongestionWindow())) + Expect(saveCwnd).To(BeNumerically("<", sender.GetCongestionWindow())) + Expect(maxCongestionWindowBytes).To(BeNumerically(">", sender.GetCongestionWindow())) Expect(bytesInFlight).To(BeZero()) // Quiescent time of 100 seconds @@ -513,39 +513,39 @@ var _ = Describe("Cubic Sender", func() { // Send new window of data and ack one packet. Cubic epoch should have // been reset; ensure cwnd increase is not dramatic. - saved_cwnd = sender.GetCongestionWindow() + saveCwnd = sender.GetCongestionWindow() SendAvailableSendWindow() AckNPackets(1) - Expect(saved_cwnd).To(BeNumerically("~", sender.GetCongestionWindow(), protocol.DefaultTCPMSS)) - Expect(kMaxCongestionWindowBytes).To(BeNumerically(">", sender.GetCongestionWindow())) + Expect(saveCwnd).To(BeNumerically("~", sender.GetCongestionWindow(), protocol.DefaultTCPMSS)) + Expect(maxCongestionWindowBytes).To(BeNumerically(">", sender.GetCongestionWindow())) }) It("tcp cubic shifted epoch on quiescence", func() { - const kMaxCongestionWindow = 50 - const kMaxCongestionWindowBytes = kMaxCongestionWindow * protocol.DefaultTCPMSS - sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, kMaxCongestionWindow) + const maxCongestionWindow = 50 + const maxCongestionWindowBytes = maxCongestionWindow * protocol.DefaultTCPMSS + sender = NewCubicSender(&clock, rttStats, false, initialCongestionWindowPackets, maxCongestionWindow) - num_sent := SendAvailableSendWindow() + numSent := SendAvailableSendWindow() // Make sure we fall out of slow start. - saved_cwnd := sender.GetCongestionWindow() + saveCwnd := sender.GetCongestionWindow() LoseNPackets(1) - Expect(saved_cwnd).To(BeNumerically(">", sender.GetCongestionWindow())) + Expect(saveCwnd).To(BeNumerically(">", sender.GetCongestionWindow())) // Ack the rest of the outstanding packets to get out of recovery. - for i := 1; i < num_sent; i++ { + for i := 1; i < numSent; i++ { AckNPackets(1) } Expect(bytesInFlight).To(BeZero()) // Send a new window of data and ack all; cubic growth should occur. - saved_cwnd = sender.GetCongestionWindow() - num_sent = SendAvailableSendWindow() - for i := 0; i < num_sent; i++ { + saveCwnd = sender.GetCongestionWindow() + numSent = SendAvailableSendWindow() + for i := 0; i < numSent; i++ { AckNPackets(1) } - Expect(saved_cwnd).To(BeNumerically("<", sender.GetCongestionWindow())) - Expect(kMaxCongestionWindowBytes).To(BeNumerically(">", sender.GetCongestionWindow())) + Expect(saveCwnd).To(BeNumerically("<", sender.GetCongestionWindow())) + Expect(maxCongestionWindowBytes).To(BeNumerically(">", sender.GetCongestionWindow())) Expect(bytesInFlight).To(BeZero()) // Quiescent time of 100 seconds @@ -553,27 +553,27 @@ var _ = Describe("Cubic Sender", func() { // Send new window of data and ack one packet. Cubic epoch should have // been reset; ensure cwnd increase is not dramatic. - saved_cwnd = sender.GetCongestionWindow() + saveCwnd = sender.GetCongestionWindow() SendAvailableSendWindow() AckNPackets(1) - Expect(saved_cwnd).To(BeNumerically("~", sender.GetCongestionWindow(), protocol.DefaultTCPMSS)) - Expect(kMaxCongestionWindowBytes).To(BeNumerically(">", sender.GetCongestionWindow())) + Expect(saveCwnd).To(BeNumerically("~", sender.GetCongestionWindow(), protocol.DefaultTCPMSS)) + Expect(maxCongestionWindowBytes).To(BeNumerically(">", sender.GetCongestionWindow())) }) It("multiple losses in one window", func() { SendAvailableSendWindow() - initial_window := sender.GetCongestionWindow() + initialWindow := sender.GetCongestionWindow() LosePacket(ackedPacketNumber + 1) - post_loss_window := sender.GetCongestionWindow() - Expect(initial_window).To(BeNumerically(">", post_loss_window)) + postLossWindow := sender.GetCongestionWindow() + Expect(initialWindow).To(BeNumerically(">", postLossWindow)) LosePacket(ackedPacketNumber + 3) - Expect(sender.GetCongestionWindow()).To(Equal(post_loss_window)) + Expect(sender.GetCongestionWindow()).To(Equal(postLossWindow)) LosePacket(packetNumber - 1) - Expect(sender.GetCongestionWindow()).To(Equal(post_loss_window)) + Expect(sender.GetCongestionWindow()).To(Equal(postLossWindow)) // Lose a later packet and ensure the window decreases. LosePacket(packetNumber) - Expect(post_loss_window).To(BeNumerically(">", sender.GetCongestionWindow())) + Expect(postLossWindow).To(BeNumerically(">", sender.GetCongestionWindow())) }) It("don't track ack packets", func() { @@ -628,21 +628,21 @@ var _ = Describe("Cubic Sender", func() { It("2 connection congestion avoidance at end of recovery", func() { sender.SetNumEmulatedConnections(2) // Ack 10 packets in 5 acks to raise the CWND to 20. - const kNumberOfAcks = 5 - for i := 0; i < kNumberOfAcks; i++ { + const numberOfAcks = 5 + for i := 0; i < numberOfAcks; i++ { // Send our full send window. SendAvailableSendWindow() AckNPackets(2) } SendAvailableSendWindow() - expected_send_window := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * kNumberOfAcks) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * numberOfAcks) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) LoseNPackets(1) // We should now have fallen out of slow start with a reduced window. - expected_send_window = protocol.ByteCount(float32(expected_send_window) * sender.RenoBeta()) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow = protocol.ByteCount(float32(expectedSendWindow) * sender.RenoBeta()) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // No congestion window growth should occur in recovery phase, i.e., until the // currently outstanding 20 packets are acked. @@ -651,53 +651,53 @@ var _ = Describe("Cubic Sender", func() { SendAvailableSendWindow() Expect(sender.InRecovery()).To(BeTrue()) AckNPackets(2) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) } Expect(sender.InRecovery()).To(BeFalse()) // Out of recovery now. Congestion window should not grow for half an RTT. - packets_in_send_window := expected_send_window / protocol.DefaultTCPMSS + packetsInSendWindow := expectedSendWindow / protocol.DefaultTCPMSS SendAvailableSendWindow() - AckNPackets(int(packets_in_send_window/2 - 2)) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + AckNPackets(int(packetsInSendWindow/2 - 2)) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Next ack should increase congestion window by 1MSS. SendAvailableSendWindow() AckNPackets(2) - expected_send_window += protocol.DefaultTCPMSS - packets_in_send_window += 1 - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow += protocol.DefaultTCPMSS + packetsInSendWindow++ + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Congestion window should remain steady again for half an RTT. SendAvailableSendWindow() - AckNPackets(int(packets_in_send_window/2 - 1)) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + AckNPackets(int(packetsInSendWindow/2 - 1)) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Next ack should cause congestion window to grow by 1MSS. SendAvailableSendWindow() AckNPackets(2) - expected_send_window += protocol.DefaultTCPMSS - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow += protocol.DefaultTCPMSS + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) }) It("1 connection congestion avoidance at end of recovery", func() { sender.SetNumEmulatedConnections(1) // Ack 10 packets in 5 acks to raise the CWND to 20. - const kNumberOfAcks = 5 - for i := 0; i < kNumberOfAcks; i++ { + const numberOfAcks = 5 + for i := 0; i < numberOfAcks; i++ { // Send our full send window. SendAvailableSendWindow() AckNPackets(2) } SendAvailableSendWindow() - expected_send_window := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * kNumberOfAcks) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * numberOfAcks) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) LoseNPackets(1) // We should now have fallen out of slow start with a reduced window. - expected_send_window = protocol.ByteCount(float32(expected_send_window) * renoBeta) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow = protocol.ByteCount(float32(expectedSendWindow) * renoBeta) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // No congestion window growth should occur in recovery phase, i.e., until the // currently outstanding 20 packets are acked. @@ -706,23 +706,23 @@ var _ = Describe("Cubic Sender", func() { SendAvailableSendWindow() Expect(sender.InRecovery()).To(BeTrue()) AckNPackets(2) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) } Expect(sender.InRecovery()).To(BeFalse()) // Out of recovery now. Congestion window should not grow during RTT. - for i := protocol.ByteCount(0); i < expected_send_window/protocol.DefaultTCPMSS-2; i += 2 { + for i := protocol.ByteCount(0); i < expectedSendWindow/protocol.DefaultTCPMSS-2; i += 2 { // Send our full send window. SendAvailableSendWindow() AckNPackets(2) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) } // Next ack should cause congestion window to grow by 1MSS. SendAvailableSendWindow() AckNPackets(2) - expected_send_window += protocol.DefaultTCPMSS - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow += protocol.DefaultTCPMSS + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) }) // TEST_F(TcpCubicSenderPacketsTest, BandwidthResumption) { @@ -747,9 +747,9 @@ var _ = Describe("Cubic Sender", func() { // // // Resumed CWND is limited to be in a sensible range. // cached_network_params.set_bandwidth_estimate_bytes_per_second( - // (kMaxCongestionWindow + 1) * protocol.DefaultTCPMSS); + // (maxCongestionWindow + 1) * protocol.DefaultTCPMSS); // sender.ResumeConnectionState(cached_network_params, false); - // Expect( sender.congestion_window()).To(Equal(kMaxCongestionWindow)) + // Expect( sender.congestion_window()).To(Equal(maxCongestionWindow)) // // cached_network_params.set_bandwidth_estimate_bytes_per_second( // (kMinCongestionWindowForBandwidthResumption - 1) * protocol.DefaultTCPMSS); @@ -792,24 +792,24 @@ var _ = Describe("Cubic Sender", func() { // Starts with slow start. sender.SetNumEmulatedConnections(1) - const kNumberOfAcks = 10 - for i := 0; i < kNumberOfAcks; i++ { + const numberOfAcks = 10 + for i := 0; i < numberOfAcks; i++ { // Send our full send window. SendAvailableSendWindow() AckNPackets(2) } SendAvailableSendWindow() - expected_send_window := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * kNumberOfAcks) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) + expectedSendWindow := defaultWindowTCP + (protocol.DefaultTCPMSS * 2 * numberOfAcks) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) // Loses a packet to exit slow start. LoseNPackets(1) // We should now have fallen out of slow start with a reduced window. Slow // start threshold is also updated. - expected_send_window = protocol.ByteCount(float32(expected_send_window) * renoBeta) - Expect(sender.GetCongestionWindow()).To(Equal(expected_send_window)) - Expect(sender.SlowstartThreshold()).To(Equal(protocol.PacketNumber(expected_send_window / protocol.DefaultTCPMSS))) + expectedSendWindow = protocol.ByteCount(float32(expectedSendWindow) * renoBeta) + Expect(sender.GetCongestionWindow()).To(Equal(expectedSendWindow)) + Expect(sender.SlowstartThreshold()).To(Equal(protocol.PacketNumber(expectedSendWindow / protocol.DefaultTCPMSS))) // Resets cwnd and slow start threshold on connection migrations. sender.OnConnectionMigration() diff --git a/internal/congestion/cubic_test.go b/internal/congestion/cubic_test.go index 713e919ce..8372df0ec 100644 --- a/internal/congestion/cubic_test.go +++ b/internal/congestion/cubic_test.go @@ -9,10 +9,9 @@ import ( . "github.com/onsi/gomega" ) -const kBeta float32 = 0.7 // Default Cubic backoff factor. -const kNumConnections uint32 = 2 -const kNConnectionBeta float32 = (float32(kNumConnections) - 1 + kBeta) / float32(kNumConnections) -const kNConnectionAlpha float32 = 3 * float32(kNumConnections) * float32(kNumConnections) * (1 - kNConnectionBeta) / (1 + kNConnectionBeta) +const numConnections uint32 = 2 +const nConnectionBeta float32 = (float32(numConnections) - 1 + beta) / float32(numConnections) +const nConnectionAlpha float32 = 3 * float32(numConnections) * float32(numConnections) * (1 - nConnectionBeta) / (1 + nConnectionBeta) var _ = Describe("Cubic", func() { var ( @@ -27,86 +26,86 @@ var _ = Describe("Cubic", func() { It("works above origin", func() { // Convex growth. - const rtt_min = 100 * time.Millisecond - const rtt_min_s = float32(rtt_min/time.Millisecond) / 1000.0 - current_cwnd := protocol.PacketNumber(10) + const rttMin = 100 * time.Millisecond + const rttMinS = float32(rttMin/time.Millisecond) / 1000.0 + currentCwnd := protocol.PacketNumber(10) // Without the signed-integer, cubic-convex fix, we mistakenly // increment cwnd after only one_ms_ and a single ack. - expected_cwnd := current_cwnd + expectedCwnd := currentCwnd // Initialize the state. clock.Advance(time.Millisecond) - initial_time := clock.Now() - current_cwnd = cubic.CongestionWindowAfterAck(current_cwnd, rtt_min) - Expect(current_cwnd).To(Equal(expected_cwnd)) - current_cwnd = expected_cwnd - initial_cwnd := current_cwnd + initialTime := clock.Now() + currentCwnd = cubic.CongestionWindowAfterAck(currentCwnd, rttMin) + Expect(currentCwnd).To(Equal(expectedCwnd)) + currentCwnd = expectedCwnd + initialCwnd := currentCwnd // Normal TCP phase. // The maximum number of expected reno RTTs can be calculated by // finding the point where the cubic curve and the reno curve meet. - max_reno_rtts := int(math.Sqrt(float64(kNConnectionAlpha/(0.4*rtt_min_s*rtt_min_s*rtt_min_s))) - 1) - for i := 0; i < max_reno_rtts; i++ { - max_per_ack_cwnd := current_cwnd - for n := uint64(1); n < uint64(float32(max_per_ack_cwnd)/kNConnectionAlpha); n++ { + maxRenoRtts := int(math.Sqrt(float64(nConnectionAlpha/(0.4*rttMinS*rttMinS*rttMinS))) - 1) + for i := 0; i < maxRenoRtts; i++ { + maxPerAckCwnd := currentCwnd + for n := uint64(1); n < uint64(float32(maxPerAckCwnd)/nConnectionAlpha); n++ { // Call once per ACK. - next_cwnd := cubic.CongestionWindowAfterAck(current_cwnd, rtt_min) - Expect(next_cwnd).To(Equal(current_cwnd)) + nextCwnd := cubic.CongestionWindowAfterAck(currentCwnd, rttMin) + Expect(nextCwnd).To(Equal(currentCwnd)) } clock.Advance(100 * time.Millisecond) - current_cwnd = cubic.CongestionWindowAfterAck(current_cwnd, rtt_min) + currentCwnd = cubic.CongestionWindowAfterAck(currentCwnd, rttMin) // When we fix convex mode and the uint64 arithmetic, we // increase the expected_cwnd only after after the first 100ms, // rather than after the initial 1ms. - expected_cwnd++ - Expect(current_cwnd).To(Equal(expected_cwnd)) + expectedCwnd++ + Expect(currentCwnd).To(Equal(expectedCwnd)) } // Cubic phase. for i := 0; i < 52; i++ { - for n := protocol.PacketNumber(1); n < current_cwnd; n++ { + for n := protocol.PacketNumber(1); n < currentCwnd; n++ { // Call once per ACK. - Expect(cubic.CongestionWindowAfterAck(current_cwnd, rtt_min)).To(Equal(current_cwnd)) + Expect(cubic.CongestionWindowAfterAck(currentCwnd, rttMin)).To(Equal(currentCwnd)) } clock.Advance(100 * time.Millisecond) - current_cwnd = cubic.CongestionWindowAfterAck(current_cwnd, rtt_min) + currentCwnd = cubic.CongestionWindowAfterAck(currentCwnd, rttMin) } // Total time elapsed so far; add min_rtt (0.1s) here as well. - elapsed_time_s := float32(clock.Now().Sub(initial_time)+rtt_min) / float32(time.Second) + elapsedTimeS := float32(clock.Now().Sub(initialTime)+rttMin) / float32(time.Second) // |expected_cwnd| is initial value of cwnd + K * t^3, where K = 0.4. - expected_cwnd = initial_cwnd + protocol.PacketNumber((elapsed_time_s*elapsed_time_s*elapsed_time_s*410)/1024) - Expect(current_cwnd).To(Equal(expected_cwnd)) + expectedCwnd = initialCwnd + protocol.PacketNumber((elapsedTimeS*elapsedTimeS*elapsedTimeS*410)/1024) + Expect(currentCwnd).To(Equal(expectedCwnd)) }) It("manages loss events", func() { - rtt_min := 100 * time.Millisecond - current_cwnd := protocol.PacketNumber(422) - expected_cwnd := current_cwnd + rttMin := 100 * time.Millisecond + currentCwnd := protocol.PacketNumber(422) + expectedCwnd := currentCwnd // Initialize the state. clock.Advance(time.Millisecond) - Expect(cubic.CongestionWindowAfterAck(current_cwnd, rtt_min)).To(Equal(expected_cwnd)) - expected_cwnd = protocol.PacketNumber(float32(current_cwnd) * kNConnectionBeta) - Expect(cubic.CongestionWindowAfterPacketLoss(current_cwnd)).To(Equal(expected_cwnd)) - expected_cwnd = protocol.PacketNumber(float32(current_cwnd) * kNConnectionBeta) - Expect(cubic.CongestionWindowAfterPacketLoss(current_cwnd)).To(Equal(expected_cwnd)) + Expect(cubic.CongestionWindowAfterAck(currentCwnd, rttMin)).To(Equal(expectedCwnd)) + expectedCwnd = protocol.PacketNumber(float32(currentCwnd) * nConnectionBeta) + Expect(cubic.CongestionWindowAfterPacketLoss(currentCwnd)).To(Equal(expectedCwnd)) + expectedCwnd = protocol.PacketNumber(float32(currentCwnd) * nConnectionBeta) + Expect(cubic.CongestionWindowAfterPacketLoss(currentCwnd)).To(Equal(expectedCwnd)) }) It("works below origin", func() { // Concave growth. - rtt_min := 100 * time.Millisecond - current_cwnd := protocol.PacketNumber(422) - expected_cwnd := current_cwnd + rttMin := 100 * time.Millisecond + currentCwnd := protocol.PacketNumber(422) + expectedCwnd := currentCwnd // Initialize the state. clock.Advance(time.Millisecond) - Expect(cubic.CongestionWindowAfterAck(current_cwnd, rtt_min)).To(Equal(expected_cwnd)) - expected_cwnd = protocol.PacketNumber(float32(current_cwnd) * kNConnectionBeta) - Expect(cubic.CongestionWindowAfterPacketLoss(current_cwnd)).To(Equal(expected_cwnd)) - current_cwnd = expected_cwnd + Expect(cubic.CongestionWindowAfterAck(currentCwnd, rttMin)).To(Equal(expectedCwnd)) + expectedCwnd = protocol.PacketNumber(float32(currentCwnd) * nConnectionBeta) + Expect(cubic.CongestionWindowAfterPacketLoss(currentCwnd)).To(Equal(expectedCwnd)) + currentCwnd = expectedCwnd // First update after loss to initialize the epoch. - current_cwnd = cubic.CongestionWindowAfterAck(current_cwnd, rtt_min) + currentCwnd = cubic.CongestionWindowAfterAck(currentCwnd, rttMin) // Cubic phase. for i := 0; i < 40; i++ { clock.Advance(100 * time.Millisecond) - current_cwnd = cubic.CongestionWindowAfterAck(current_cwnd, rtt_min) + currentCwnd = cubic.CongestionWindowAfterAck(currentCwnd, rttMin) } - expected_cwnd = 422 - Expect(current_cwnd).To(Equal(expected_cwnd)) + expectedCwnd = 422 + Expect(currentCwnd).To(Equal(expectedCwnd)) }) }) diff --git a/internal/congestion/hybrid_slow_start_test.go b/internal/congestion/hybrid_slow_start_test.go index 967c0dbc1..fee8945e2 100644 --- a/internal/congestion/hybrid_slow_start_test.go +++ b/internal/congestion/hybrid_slow_start_test.go @@ -18,53 +18,53 @@ var _ = Describe("Hybrid slow start", func() { }) It("works in a simple case", func() { - packet_number := protocol.PacketNumber(1) - end_packet_number := protocol.PacketNumber(3) - slowStart.StartReceiveRound(end_packet_number) + packetNumber := protocol.PacketNumber(1) + endPacketNumber := protocol.PacketNumber(3) + slowStart.StartReceiveRound(endPacketNumber) - packet_number++ - Expect(slowStart.IsEndOfRound(packet_number)).To(BeFalse()) + packetNumber++ + Expect(slowStart.IsEndOfRound(packetNumber)).To(BeFalse()) // Test duplicates. - Expect(slowStart.IsEndOfRound(packet_number)).To(BeFalse()) + Expect(slowStart.IsEndOfRound(packetNumber)).To(BeFalse()) - packet_number++ - Expect(slowStart.IsEndOfRound(packet_number)).To(BeFalse()) - packet_number++ - Expect(slowStart.IsEndOfRound(packet_number)).To(BeTrue()) + packetNumber++ + Expect(slowStart.IsEndOfRound(packetNumber)).To(BeFalse()) + packetNumber++ + Expect(slowStart.IsEndOfRound(packetNumber)).To(BeTrue()) // Test without a new registered end_packet_number; - packet_number++ - Expect(slowStart.IsEndOfRound(packet_number)).To(BeTrue()) + packetNumber++ + Expect(slowStart.IsEndOfRound(packetNumber)).To(BeTrue()) - end_packet_number = 20 - slowStart.StartReceiveRound(end_packet_number) - for packet_number < end_packet_number { - packet_number++ - Expect(slowStart.IsEndOfRound(packet_number)).To(BeFalse()) + endPacketNumber = 20 + slowStart.StartReceiveRound(endPacketNumber) + for packetNumber < endPacketNumber { + packetNumber++ + Expect(slowStart.IsEndOfRound(packetNumber)).To(BeFalse()) } - packet_number++ - Expect(slowStart.IsEndOfRound(packet_number)).To(BeTrue()) + packetNumber++ + Expect(slowStart.IsEndOfRound(packetNumber)).To(BeTrue()) }) It("works with delay", func() { rtt := 60 * time.Millisecond // We expect to detect the increase at +1/8 of the RTT; hence at a typical // RTT of 60ms the detection will happen at 67.5 ms. - const kHybridStartMinSamples = 8 // Number of acks required to trigger. + const hybridStartMinSamples = 8 // Number of acks required to trigger. - end_packet_number := protocol.PacketNumber(1) - end_packet_number++ - slowStart.StartReceiveRound(end_packet_number) + endPacketNumber := protocol.PacketNumber(1) + endPacketNumber++ + slowStart.StartReceiveRound(endPacketNumber) // Will not trigger since our lowest RTT in our burst is the same as the long // term RTT provided. - for n := 0; n < kHybridStartMinSamples; n++ { + for n := 0; n < hybridStartMinSamples; n++ { Expect(slowStart.ShouldExitSlowStart(rtt+time.Duration(n)*time.Millisecond, rtt, 100)).To(BeFalse()) } - end_packet_number++ - slowStart.StartReceiveRound(end_packet_number) - for n := 1; n < kHybridStartMinSamples; n++ { + endPacketNumber++ + slowStart.StartReceiveRound(endPacketNumber) + for n := 1; n < hybridStartMinSamples; n++ { Expect(slowStart.ShouldExitSlowStart(rtt+(time.Duration(n)+10)*time.Millisecond, rtt, 100)).To(BeFalse()) } // Expect to trigger since all packets in this burst was above the long term diff --git a/internal/congestion/prr_sender_test.go b/internal/congestion/prr_sender_test.go index e6b4f7281..52f417148 100644 --- a/internal/congestion/prr_sender_test.go +++ b/internal/congestion/prr_sender_test.go @@ -18,91 +18,91 @@ var _ = Describe("PRR sender", func() { }) It("single loss results in send on every other ack", func() { - num_packets_in_flight := protocol.ByteCount(50) - bytes_in_flight := num_packets_in_flight * protocol.DefaultTCPMSS - ssthresh_after_loss := num_packets_in_flight / 2 - congestion_window := ssthresh_after_loss * protocol.DefaultTCPMSS + numPacketsInFlight := protocol.ByteCount(50) + bytesInFlight := numPacketsInFlight * protocol.DefaultTCPMSS + sshthreshAfterLoss := numPacketsInFlight / 2 + congestionWindow := sshthreshAfterLoss * protocol.DefaultTCPMSS - prr.OnPacketLost(bytes_in_flight) + prr.OnPacketLost(bytesInFlight) // Ack a packet. PRR allows one packet to leave immediately. prr.OnPacketAcked(protocol.DefaultTCPMSS) - bytes_in_flight -= protocol.DefaultTCPMSS - Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(BeZero()) + bytesInFlight -= protocol.DefaultTCPMSS + Expect(prr.TimeUntilSend(congestionWindow, bytesInFlight, sshthreshAfterLoss*protocol.DefaultTCPMSS)).To(BeZero()) // Send retransmission. prr.OnPacketSent(protocol.DefaultTCPMSS) // PRR shouldn't allow sending any more packets. - Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(Equal(utils.InfDuration)) + Expect(prr.TimeUntilSend(congestionWindow, bytesInFlight, sshthreshAfterLoss*protocol.DefaultTCPMSS)).To(Equal(utils.InfDuration)) // One packet is lost, and one ack was consumed above. PRR now paces // transmissions through the remaining 48 acks. PRR will alternatively // disallow and allow a packet to be sent in response to an ack. - for i := protocol.ByteCount(0); i < ssthresh_after_loss-1; i++ { + for i := protocol.ByteCount(0); i < sshthreshAfterLoss-1; i++ { // Ack a packet. PRR shouldn't allow sending a packet in response. prr.OnPacketAcked(protocol.DefaultTCPMSS) - bytes_in_flight -= protocol.DefaultTCPMSS - Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(Equal(utils.InfDuration)) + bytesInFlight -= protocol.DefaultTCPMSS + Expect(prr.TimeUntilSend(congestionWindow, bytesInFlight, sshthreshAfterLoss*protocol.DefaultTCPMSS)).To(Equal(utils.InfDuration)) // Ack another packet. PRR should now allow sending a packet in response. prr.OnPacketAcked(protocol.DefaultTCPMSS) - bytes_in_flight -= protocol.DefaultTCPMSS - Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(BeZero()) + bytesInFlight -= protocol.DefaultTCPMSS + Expect(prr.TimeUntilSend(congestionWindow, bytesInFlight, sshthreshAfterLoss*protocol.DefaultTCPMSS)).To(BeZero()) // Send a packet in response. prr.OnPacketSent(protocol.DefaultTCPMSS) - bytes_in_flight += protocol.DefaultTCPMSS + bytesInFlight += protocol.DefaultTCPMSS } // Since bytes_in_flight is now equal to congestion_window, PRR now maintains // packet conservation, allowing one packet to be sent in response to an ack. - Expect(bytes_in_flight).To(Equal(congestion_window)) + Expect(bytesInFlight).To(Equal(congestionWindow)) for i := 0; i < 10; i++ { // Ack a packet. prr.OnPacketAcked(protocol.DefaultTCPMSS) - bytes_in_flight -= protocol.DefaultTCPMSS - Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(BeZero()) + bytesInFlight -= protocol.DefaultTCPMSS + Expect(prr.TimeUntilSend(congestionWindow, bytesInFlight, sshthreshAfterLoss*protocol.DefaultTCPMSS)).To(BeZero()) // Send a packet in response, since PRR allows it. prr.OnPacketSent(protocol.DefaultTCPMSS) - bytes_in_flight += protocol.DefaultTCPMSS + bytesInFlight += protocol.DefaultTCPMSS // Since bytes_in_flight is equal to the congestion_window, // PRR disallows sending. - Expect(bytes_in_flight).To(Equal(congestion_window)) - Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(Equal(utils.InfDuration)) + Expect(bytesInFlight).To(Equal(congestionWindow)) + Expect(prr.TimeUntilSend(congestionWindow, bytesInFlight, sshthreshAfterLoss*protocol.DefaultTCPMSS)).To(Equal(utils.InfDuration)) } }) It("burst loss results in slow start", func() { - bytes_in_flight := protocol.ByteCount(20 * protocol.DefaultTCPMSS) - const num_packets_lost = 13 - const ssthresh_after_loss = 10 - const congestion_window = ssthresh_after_loss * protocol.DefaultTCPMSS + bytesInFlight := protocol.ByteCount(20 * protocol.DefaultTCPMSS) + const numPacketsLost = 13 + const ssthreshAfterLoss = 10 + const congestionWindow = ssthreshAfterLoss * protocol.DefaultTCPMSS // Lose 13 packets. - bytes_in_flight -= num_packets_lost * protocol.DefaultTCPMSS - prr.OnPacketLost(bytes_in_flight) + bytesInFlight -= numPacketsLost * protocol.DefaultTCPMSS + prr.OnPacketLost(bytesInFlight) // PRR-SSRB will allow the following 3 acks to send up to 2 packets. for i := 0; i < 3; i++ { prr.OnPacketAcked(protocol.DefaultTCPMSS) - bytes_in_flight -= protocol.DefaultTCPMSS + bytesInFlight -= protocol.DefaultTCPMSS // PRR-SSRB should allow two packets to be sent. for j := 0; j < 2; j++ { - Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(BeZero()) + Expect(prr.TimeUntilSend(congestionWindow, bytesInFlight, ssthreshAfterLoss*protocol.DefaultTCPMSS)).To(BeZero()) // Send a packet in response. prr.OnPacketSent(protocol.DefaultTCPMSS) - bytes_in_flight += protocol.DefaultTCPMSS + bytesInFlight += protocol.DefaultTCPMSS } // PRR should allow no more than 2 packets in response to an ack. - Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(Equal(utils.InfDuration)) + Expect(prr.TimeUntilSend(congestionWindow, bytesInFlight, ssthreshAfterLoss*protocol.DefaultTCPMSS)).To(Equal(utils.InfDuration)) } // Out of SSRB mode, PRR allows one send in response to each ack. for i := 0; i < 10; i++ { prr.OnPacketAcked(protocol.DefaultTCPMSS) - bytes_in_flight -= protocol.DefaultTCPMSS - Expect(prr.TimeUntilSend(congestion_window, bytes_in_flight, ssthresh_after_loss*protocol.DefaultTCPMSS)).To(BeZero()) + bytesInFlight -= protocol.DefaultTCPMSS + Expect(prr.TimeUntilSend(congestionWindow, bytesInFlight, ssthreshAfterLoss*protocol.DefaultTCPMSS)).To(BeZero()) // Send a packet in response. prr.OnPacketSent(protocol.DefaultTCPMSS) - bytes_in_flight += protocol.DefaultTCPMSS + bytesInFlight += protocol.DefaultTCPMSS } }) }) diff --git a/internal/congestion/rtt_stats_test.go b/internal/congestion/rtt_stats_test.go index 718bec3e3..76aaafa5d 100644 --- a/internal/congestion/rtt_stats_test.go +++ b/internal/congestion/rtt_stats_test.go @@ -82,8 +82,8 @@ var _ = Describe("RTT stats", func() { rttStats.SetRecentMinRTTwindow((99 * time.Millisecond)) now := time.Time{} - rtt_sample := (10 * time.Millisecond) - rttStats.UpdateRTT(rtt_sample, 0, now) + rttSample := (10 * time.Millisecond) + rttStats.UpdateRTT(rttSample, 0, now) Expect(rttStats.MinRTT()).To(Equal((10 * time.Millisecond))) Expect(rttStats.RecentMinRTT()).To(Equal((10 * time.Millisecond))) @@ -91,11 +91,11 @@ var _ = Describe("RTT stats", func() { // rising. for i := 0; i < 8; i++ { now = now.Add((25 * time.Millisecond)) - rtt_sample += (10 * time.Millisecond) - rttStats.UpdateRTT(rtt_sample, 0, now) + rttSample += (10 * time.Millisecond) + rttStats.UpdateRTT(rttSample, 0, now) Expect(rttStats.MinRTT()).To(Equal((10 * time.Millisecond))) - Expect(rttStats.GetQuarterWindowRTT()).To(Equal(rtt_sample)) - Expect(rttStats.GetHalfWindowRTT()).To(Equal(rtt_sample - (10 * time.Millisecond))) + Expect(rttStats.GetQuarterWindowRTT()).To(Equal(rttSample)) + Expect(rttStats.GetHalfWindowRTT()).To(Equal(rttSample - (10 * time.Millisecond))) if i < 3 { Expect(rttStats.RecentMinRTT()).To(Equal(10 * time.Millisecond)) } else if i < 5 { @@ -108,91 +108,91 @@ var _ = Describe("RTT stats", func() { } // A new quarter rtt low sets that, but nothing else. - rtt_sample -= (5 * time.Millisecond) - rttStats.UpdateRTT(rtt_sample, 0, now) + rttSample -= (5 * time.Millisecond) + rttStats.UpdateRTT(rttSample, 0, now) Expect(rttStats.MinRTT()).To(Equal((10 * time.Millisecond))) - Expect(rttStats.GetQuarterWindowRTT()).To(Equal(rtt_sample)) - Expect(rttStats.GetHalfWindowRTT()).To(Equal(rtt_sample - (5 * time.Millisecond))) + Expect(rttStats.GetQuarterWindowRTT()).To(Equal(rttSample)) + Expect(rttStats.GetHalfWindowRTT()).To(Equal(rttSample - (5 * time.Millisecond))) Expect(rttStats.RecentMinRTT()).To(Equal((70 * time.Millisecond))) // A new half rtt low sets that and the quarter rtt low. - rtt_sample -= (15 * time.Millisecond) - rttStats.UpdateRTT(rtt_sample, 0, now) + rttSample -= (15 * time.Millisecond) + rttStats.UpdateRTT(rttSample, 0, now) Expect(rttStats.MinRTT()).To(Equal((10 * time.Millisecond))) - Expect(rttStats.GetQuarterWindowRTT()).To(Equal(rtt_sample)) - Expect(rttStats.GetHalfWindowRTT()).To(Equal(rtt_sample)) + Expect(rttStats.GetQuarterWindowRTT()).To(Equal(rttSample)) + Expect(rttStats.GetHalfWindowRTT()).To(Equal(rttSample)) Expect(rttStats.RecentMinRTT()).To(Equal((70 * time.Millisecond))) // A new full window loss sets the RecentMinRTT, but not MinRTT. - rtt_sample = (65 * time.Millisecond) - rttStats.UpdateRTT(rtt_sample, 0, now) + rttSample = (65 * time.Millisecond) + rttStats.UpdateRTT(rttSample, 0, now) Expect(rttStats.MinRTT()).To(Equal((10 * time.Millisecond))) - Expect(rttStats.GetQuarterWindowRTT()).To(Equal(rtt_sample)) - Expect(rttStats.GetHalfWindowRTT()).To(Equal(rtt_sample)) - Expect(rttStats.RecentMinRTT()).To(Equal(rtt_sample)) + Expect(rttStats.GetQuarterWindowRTT()).To(Equal(rttSample)) + Expect(rttStats.GetHalfWindowRTT()).To(Equal(rttSample)) + Expect(rttStats.RecentMinRTT()).To(Equal(rttSample)) // A new all time low sets both the MinRTT and the RecentMinRTT. - rtt_sample = (5 * time.Millisecond) - rttStats.UpdateRTT(rtt_sample, 0, now) + rttSample = (5 * time.Millisecond) + rttStats.UpdateRTT(rttSample, 0, now) - Expect(rttStats.MinRTT()).To(Equal(rtt_sample)) - Expect(rttStats.GetQuarterWindowRTT()).To(Equal(rtt_sample)) - Expect(rttStats.GetHalfWindowRTT()).To(Equal(rtt_sample)) - Expect(rttStats.RecentMinRTT()).To(Equal(rtt_sample)) + Expect(rttStats.MinRTT()).To(Equal(rttSample)) + Expect(rttStats.GetQuarterWindowRTT()).To(Equal(rttSample)) + Expect(rttStats.GetHalfWindowRTT()).To(Equal(rttSample)) + Expect(rttStats.RecentMinRTT()).To(Equal(rttSample)) }) It("ExpireSmoothedMetrics", func() { - initial_rtt := (10 * time.Millisecond) - rttStats.UpdateRTT(initial_rtt, 0, time.Time{}) - Expect(rttStats.MinRTT()).To(Equal(initial_rtt)) - Expect(rttStats.RecentMinRTT()).To(Equal(initial_rtt)) - Expect(rttStats.SmoothedRTT()).To(Equal(initial_rtt)) + initialRtt := (10 * time.Millisecond) + rttStats.UpdateRTT(initialRtt, 0, time.Time{}) + Expect(rttStats.MinRTT()).To(Equal(initialRtt)) + Expect(rttStats.RecentMinRTT()).To(Equal(initialRtt)) + Expect(rttStats.SmoothedRTT()).To(Equal(initialRtt)) - Expect(rttStats.MeanDeviation()).To(Equal(initial_rtt / 2)) + Expect(rttStats.MeanDeviation()).To(Equal(initialRtt / 2)) // Update once with a 20ms RTT. - doubled_rtt := initial_rtt * (2) - rttStats.UpdateRTT(doubled_rtt, 0, time.Time{}) - Expect(rttStats.SmoothedRTT()).To(Equal(time.Duration(float32(initial_rtt) * 1.125))) + doubledRtt := initialRtt * (2) + rttStats.UpdateRTT(doubledRtt, 0, time.Time{}) + Expect(rttStats.SmoothedRTT()).To(Equal(time.Duration(float32(initialRtt) * 1.125))) // Expire the smoothed metrics, increasing smoothed rtt and mean deviation. rttStats.ExpireSmoothedMetrics() - Expect(rttStats.SmoothedRTT()).To(Equal(doubled_rtt)) - Expect(rttStats.MeanDeviation()).To(Equal(time.Duration(float32(initial_rtt) * 0.875))) + Expect(rttStats.SmoothedRTT()).To(Equal(doubledRtt)) + Expect(rttStats.MeanDeviation()).To(Equal(time.Duration(float32(initialRtt) * 0.875))) // Now go back down to 5ms and expire the smoothed metrics, and ensure the // mean deviation increases to 15ms. - half_rtt := initial_rtt / 2 - rttStats.UpdateRTT(half_rtt, 0, time.Time{}) - Expect(doubled_rtt).To(BeNumerically(">", rttStats.SmoothedRTT())) - Expect(initial_rtt).To(BeNumerically("<", rttStats.MeanDeviation())) + halfRtt := initialRtt / 2 + rttStats.UpdateRTT(halfRtt, 0, time.Time{}) + Expect(doubledRtt).To(BeNumerically(">", rttStats.SmoothedRTT())) + Expect(initialRtt).To(BeNumerically("<", rttStats.MeanDeviation())) }) It("UpdateRTTWithBadSendDeltas", func() { // Make sure we ignore bad RTTs. // base::test::MockLog log; - initial_rtt := (10 * time.Millisecond) - rttStats.UpdateRTT(initial_rtt, 0, time.Time{}) - Expect(rttStats.MinRTT()).To(Equal(initial_rtt)) - Expect(rttStats.RecentMinRTT()).To(Equal(initial_rtt)) - Expect(rttStats.SmoothedRTT()).To(Equal(initial_rtt)) + initialRtt := (10 * time.Millisecond) + rttStats.UpdateRTT(initialRtt, 0, time.Time{}) + Expect(rttStats.MinRTT()).To(Equal(initialRtt)) + Expect(rttStats.RecentMinRTT()).To(Equal(initialRtt)) + Expect(rttStats.SmoothedRTT()).To(Equal(initialRtt)) - bad_send_deltas := []time.Duration{ + badSendDeltas := []time.Duration{ 0, utils.InfDuration, -1000 * time.Microsecond, } // log.StartCapturingLogs(); - for _, bad_send_delta := range bad_send_deltas { + for _, badSendDelta := range badSendDeltas { // SCOPED_TRACE(Message() << "bad_send_delta = " // << bad_send_delta.ToMicroseconds()); // EXPECT_CALL(log, Log(LOG_WARNING, _, _, _, HasSubstr("Ignoring"))); - rttStats.UpdateRTT(bad_send_delta, 0, time.Time{}) - Expect(rttStats.MinRTT()).To(Equal(initial_rtt)) - Expect(rttStats.RecentMinRTT()).To(Equal(initial_rtt)) - Expect(rttStats.SmoothedRTT()).To(Equal(initial_rtt)) + rttStats.UpdateRTT(badSendDelta, 0, time.Time{}) + Expect(rttStats.MinRTT()).To(Equal(initialRtt)) + Expect(rttStats.RecentMinRTT()).To(Equal(initialRtt)) + Expect(rttStats.SmoothedRTT()).To(Equal(initialRtt)) } })