summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorIan Gudger <igudger@google.com>2018-11-29 15:45:02 -0800
committerShentubot <shentubot@google.com>2018-11-29 15:46:38 -0800
commit99fb1138696c520f8db7064320e14ec63c2458b6 (patch)
tree7eed6f8d79ac3216faaea8310a6b1b30e16f48a2 /pkg
parentdb0473b1bec1481e5a7807752b5eaa72c816c562 (diff)
Test that full segments will be sent when delay/cork is enabled
PiperOrigin-RevId: 223425575 Change-Id: Idd777e04c69e6ffcbfb0bdbea828a8b8b42d7672
Diffstat (limited to 'pkg')
-rw-r--r--pkg/tcpip/transport/tcp/tcp_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/pkg/tcpip/transport/tcp/tcp_test.go b/pkg/tcpip/transport/tcp/tcp_test.go
index 467d9c156..557cc258d 100644
--- a/pkg/tcpip/transport/tcp/tcp_test.go
+++ b/pkg/tcpip/transport/tcp/tcp_test.go
@@ -1449,6 +1449,71 @@ func TestUndelay(t *testing.T) {
})
}
+func TestMSSNotDelayed(t *testing.T) {
+ tests := []struct {
+ name string
+ fn func(tcpip.Endpoint)
+ }{
+ {"no-op", func(tcpip.Endpoint) {}},
+ {"delay", func(ep tcpip.Endpoint) { ep.SetSockOpt(tcpip.DelayOption(1)) }},
+ {"cork", func(ep tcpip.Endpoint) { ep.SetSockOpt(tcpip.CorkOption(1)) }},
+ }
+
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ const maxPayload = 100
+ c := context.New(t, defaultMTU)
+ defer c.Cleanup()
+
+ c.CreateConnectedWithRawOptions(789, 30000, nil, []byte{
+ header.TCPOptionMSS, 4, byte(maxPayload / 256), byte(maxPayload % 256),
+ })
+
+ test.fn(c.EP)
+
+ allData := [][]byte{{0}, make([]byte, maxPayload), make([]byte, maxPayload)}
+ for i, data := range allData {
+ view := buffer.NewViewFromBytes(data)
+ if _, _, err := c.EP.Write(tcpip.SlicePayload(view), tcpip.WriteOptions{}); err != nil {
+ t.Fatalf("Write #%d failed: %v", i+1, err)
+ }
+ }
+
+ seq := c.IRS.Add(1)
+
+ for i, data := range allData {
+ // Check that data is received.
+ packet := c.GetPacket()
+ checker.IPv4(t, packet,
+ checker.PayloadLen(len(data)+header.TCPMinimumSize),
+ checker.TCP(
+ checker.DstPort(context.TestPort),
+ checker.SeqNum(uint32(seq)),
+ checker.AckNum(790),
+ checker.TCPFlagsMatch(header.TCPFlagAck, ^uint8(header.TCPFlagPsh)),
+ ),
+ )
+
+ if got, want := packet[header.IPv4MinimumSize+header.TCPMinimumSize:], data; !bytes.Equal(got, want) {
+ t.Fatalf("got packet #%d's data = %v, want = %v", i+1, got, want)
+ }
+
+ seq = seq.Add(seqnum.Size(len(data)))
+ }
+
+ // Acknowledge the data.
+ c.SendPacket(nil, &context.Headers{
+ SrcPort: context.TestPort,
+ DstPort: c.Port,
+ Flags: header.TCPFlagAck,
+ SeqNum: 790,
+ AckNum: seq,
+ RcvWnd: 30000,
+ })
+ })
+ }
+}
+
func testBrokenUpWrite(t *testing.T, c *context.Context, maxPayload int) {
payloadMultiplier := 10
dataLen := payloadMultiplier * maxPayload