gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/tcpip/transport/tcp/test/e2e/rcv_test.go (about) 1 // Copyright 2020 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package rcv_test 16 17 import ( 18 "testing" 19 20 "gvisor.dev/gvisor/pkg/tcpip/header" 21 "gvisor.dev/gvisor/pkg/tcpip/seqnum" 22 ) 23 24 func TestAcceptable(t *testing.T) { 25 for _, tt := range []struct { 26 segSeq seqnum.Value 27 segLen seqnum.Size 28 rcvNxt, rcvAcc seqnum.Value 29 want bool 30 }{ 31 // The segment is smaller than the window. 32 {105, 2, 100, 104, false}, 33 {105, 2, 101, 105, true}, 34 {105, 2, 102, 106, true}, 35 {105, 2, 103, 107, true}, 36 {105, 2, 104, 108, true}, 37 {105, 2, 105, 109, true}, 38 {105, 2, 106, 110, true}, 39 {105, 2, 107, 111, false}, 40 41 // The segment is larger than the window. 42 {105, 4, 103, 105, true}, 43 {105, 4, 104, 106, true}, 44 {105, 4, 105, 107, true}, 45 {105, 4, 106, 108, true}, 46 {105, 4, 107, 109, true}, 47 {105, 4, 108, 110, true}, 48 {105, 4, 109, 111, false}, 49 {105, 4, 110, 112, false}, 50 51 // The segment has no width. 52 {105, 0, 100, 102, false}, 53 {105, 0, 101, 103, false}, 54 {105, 0, 102, 104, false}, 55 {105, 0, 103, 105, true}, 56 {105, 0, 104, 106, true}, 57 {105, 0, 105, 107, true}, 58 {105, 0, 106, 108, false}, 59 {105, 0, 107, 109, false}, 60 61 // The receive window has no width. 62 {105, 2, 103, 103, false}, 63 {105, 2, 104, 104, false}, 64 {105, 2, 105, 105, false}, 65 {105, 2, 106, 106, false}, 66 {105, 2, 107, 107, false}, 67 {105, 2, 108, 108, false}, 68 {105, 2, 109, 109, false}, 69 } { 70 if got := header.Acceptable(tt.segSeq, tt.segLen, tt.rcvNxt, tt.rcvAcc); got != tt.want { 71 t.Errorf("header.Acceptable(%d, %d, %d, %d) = %t, want %t", tt.segSeq, tt.segLen, tt.rcvNxt, tt.rcvAcc, got, tt.want) 72 } 73 } 74 }