|
|
@@ -9,6 +9,7 @@ import (
|
|
|
"testing"
|
|
|
|
|
|
"golang.org/x/net/ipv6"
|
|
|
+ "tailscale.com/net/packet"
|
|
|
)
|
|
|
|
|
|
func setGSOSize(control *[]byte, gsoSize uint16) {
|
|
|
@@ -154,6 +155,10 @@ func Test_linuxBatchingConn_coalesceMessages(t *testing.T) {
|
|
|
getGSOSizeFromControl: getGSOSize,
|
|
|
}
|
|
|
|
|
|
+ withGeneveSpace := func(len, cap int) []byte {
|
|
|
+ return make([]byte, len+packet.GeneveFixedHeaderLength, cap+packet.GeneveFixedHeaderLength)
|
|
|
+ }
|
|
|
+
|
|
|
cases := []struct {
|
|
|
name string
|
|
|
buffs [][]byte
|
|
|
@@ -163,7 +168,7 @@ func Test_linuxBatchingConn_coalesceMessages(t *testing.T) {
|
|
|
{
|
|
|
name: "one message no coalesce",
|
|
|
buffs: [][]byte{
|
|
|
- make([]byte, 1, 1),
|
|
|
+ withGeneveSpace(1, 1),
|
|
|
},
|
|
|
wantLens: []int{1},
|
|
|
wantGSO: []int{0},
|
|
|
@@ -171,8 +176,8 @@ func Test_linuxBatchingConn_coalesceMessages(t *testing.T) {
|
|
|
{
|
|
|
name: "two messages equal len coalesce",
|
|
|
buffs: [][]byte{
|
|
|
- make([]byte, 1, 2),
|
|
|
- make([]byte, 1, 1),
|
|
|
+ withGeneveSpace(1, 2),
|
|
|
+ withGeneveSpace(1, 1),
|
|
|
},
|
|
|
wantLens: []int{2},
|
|
|
wantGSO: []int{1},
|
|
|
@@ -180,8 +185,8 @@ func Test_linuxBatchingConn_coalesceMessages(t *testing.T) {
|
|
|
{
|
|
|
name: "two messages unequal len coalesce",
|
|
|
buffs: [][]byte{
|
|
|
- make([]byte, 2, 3),
|
|
|
- make([]byte, 1, 1),
|
|
|
+ withGeneveSpace(2, 3),
|
|
|
+ withGeneveSpace(1, 1),
|
|
|
},
|
|
|
wantLens: []int{3},
|
|
|
wantGSO: []int{2},
|
|
|
@@ -189,9 +194,9 @@ func Test_linuxBatchingConn_coalesceMessages(t *testing.T) {
|
|
|
{
|
|
|
name: "three messages second unequal len coalesce",
|
|
|
buffs: [][]byte{
|
|
|
- make([]byte, 2, 3),
|
|
|
- make([]byte, 1, 1),
|
|
|
- make([]byte, 2, 2),
|
|
|
+ withGeneveSpace(2, 3),
|
|
|
+ withGeneveSpace(1, 1),
|
|
|
+ withGeneveSpace(2, 2),
|
|
|
},
|
|
|
wantLens: []int{3, 2},
|
|
|
wantGSO: []int{2, 0},
|
|
|
@@ -199,9 +204,9 @@ func Test_linuxBatchingConn_coalesceMessages(t *testing.T) {
|
|
|
{
|
|
|
name: "three messages limited cap coalesce",
|
|
|
buffs: [][]byte{
|
|
|
- make([]byte, 2, 4),
|
|
|
- make([]byte, 2, 2),
|
|
|
- make([]byte, 2, 2),
|
|
|
+ withGeneveSpace(2, 4),
|
|
|
+ withGeneveSpace(2, 2),
|
|
|
+ withGeneveSpace(2, 2),
|
|
|
},
|
|
|
wantLens: []int{4, 2},
|
|
|
wantGSO: []int{2, 0},
|
|
|
@@ -219,7 +224,7 @@ func Test_linuxBatchingConn_coalesceMessages(t *testing.T) {
|
|
|
msgs[i].Buffers = make([][]byte, 1)
|
|
|
msgs[i].OOB = make([]byte, 0, 2)
|
|
|
}
|
|
|
- got := c.coalesceMessages(addr, tt.buffs, msgs)
|
|
|
+ got := c.coalesceMessages(addr, tt.buffs, msgs, packet.GeneveFixedHeaderLength)
|
|
|
if got != len(tt.wantLens) {
|
|
|
t.Fatalf("got len %d want: %d", got, len(tt.wantLens))
|
|
|
}
|