-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add an integration test for DPLPMTUD
- Loading branch information
1 parent
4f4da04
commit 03d1f6e
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// We can't reliably set the DF bit on macOS, so we can't do Path MTU discovery. | ||
//go:build !darwin | ||
|
||
package self_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"net" | ||
"sync" | ||
"time" | ||
|
||
"github.com/quic-go/quic-go" | ||
quicproxy "github.com/quic-go/quic-go/integrationtests/tools/proxy" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("DPLPMTUD", func() { | ||
It("discovers the MTU", func() { | ||
const rtt = 100 * time.Millisecond | ||
const mtu = 1400 | ||
|
||
ln, err := quic.ListenAddr("localhost:0", getTLSConfig(), getQuicConfig(&quic.Config{DisablePathMTUDiscovery: true})) | ||
Expect(err).ToNot(HaveOccurred()) | ||
defer ln.Close() | ||
go func() { | ||
defer GinkgoRecover() | ||
conn, err := ln.Accept(context.Background()) | ||
Expect(err).ToNot(HaveOccurred()) | ||
str, err := conn.AcceptStream(context.Background()) | ||
Expect(err).ToNot(HaveOccurred()) | ||
_, err = io.Copy(str, str) | ||
Expect(err).ToNot(HaveOccurred()) | ||
str.Close() | ||
}() | ||
|
||
var mx sync.Mutex | ||
var maxPacketSizeClient, maxPacketSizeServer int | ||
serverPort := ln.Addr().(*net.UDPAddr).Port | ||
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{ | ||
RemoteAddr: fmt.Sprintf("localhost:%d", serverPort), | ||
DelayPacket: func(quicproxy.Direction, []byte) time.Duration { return rtt / 2 }, | ||
DropPacket: func(dir quicproxy.Direction, packet []byte) bool { | ||
if len(packet) > mtu { | ||
return true | ||
} | ||
mx.Lock() | ||
defer mx.Unlock() | ||
switch dir { | ||
case quicproxy.DirectionIncoming: | ||
if len(packet) > maxPacketSizeClient { | ||
maxPacketSizeClient = len(packet) | ||
} | ||
case quicproxy.DirectionOutgoing: | ||
if len(packet) > maxPacketSizeServer { | ||
maxPacketSizeServer = len(packet) | ||
} | ||
} | ||
return false | ||
}, | ||
}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
defer proxy.Close() | ||
|
||
conn, err := quic.DialAddr( | ||
context.Background(), | ||
fmt.Sprintf("localhost:%d", proxy.LocalPort()), | ||
getTLSClientConfig(), | ||
getQuicConfig(nil), | ||
) | ||
Expect(err).ToNot(HaveOccurred()) | ||
defer conn.CloseWithError(0, "") | ||
str, err := conn.OpenStream() | ||
Expect(err).ToNot(HaveOccurred()) | ||
done := make(chan struct{}) | ||
go func() { | ||
defer close(done) | ||
defer GinkgoRecover() | ||
data, err := io.ReadAll(str) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(data).To(Equal(PRDataLong)) | ||
}() | ||
_, err = str.Write(PRDataLong) | ||
Expect(err).ToNot(HaveOccurred()) | ||
str.Close() | ||
Eventually(done).Should(BeClosed()) | ||
|
||
mx.Lock() | ||
defer mx.Unlock() | ||
fmt.Fprintf(GinkgoWriter, "max client packet size: %d, MTU: %d\n", maxPacketSizeClient, mtu) | ||
fmt.Fprintf(GinkgoWriter, "max server packet size: %d, MTU: %d\n", maxPacketSizeServer, mtu) | ||
Expect(maxPacketSizeClient).To(BeNumerically(">=", mtu-25)) | ||
}) | ||
}) |