-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathtcp_assembly_test.go
38 lines (31 loc) · 1.3 KB
/
tcp_assembly_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"github.com/google/gopacket/layers"
"github.com/stretchr/testify/assert"
"testing"
)
func TestReceiveWindow(t *testing.T) {
window := newReceiveWindow(4)
// init insert
window.insert(&layers.TCP{Seq: 10005, BaseLayer: layers.BaseLayer{Payload: []byte{1, 2}}})
window.insert(&layers.TCP{Seq: 10000, BaseLayer: layers.BaseLayer{Payload: []byte{7, 8, 9, 0}}})
window.insert(&layers.TCP{Seq: 10010, BaseLayer: layers.BaseLayer{Payload: []byte{2, 3, 4, 5}}})
window.insert(&layers.TCP{Seq: 10005, BaseLayer: layers.BaseLayer{Payload: []byte{1, 2}}})
assert.Equal(t, 3, window.size)
assert.Equal(t, 0, window.start)
assert.Equal(t, uint32(10000), window.buffer[0].Seq)
assert.Equal(t, uint32(10005), window.buffer[1].Seq)
assert.Equal(t, uint32(10010), window.buffer[2].Seq)
window.insert(&layers.TCP{Seq: 10009, BaseLayer: layers.BaseLayer{Payload: []byte{7, 8, 9, 0}}})
assert.Equal(t, uint32(10000), window.buffer[0].Seq)
assert.Equal(t, uint32(10005), window.buffer[1].Seq)
// expand
window.insert(&layers.TCP{Seq: 10030, BaseLayer: layers.BaseLayer{Payload: []byte{7, 8, 9, 0}}})
assert.Equal(t, 5, window.size)
assert.Equal(t, 0, window.start)
c := make(chan *layers.TCP, 1000)
// confirm
window.confirm(10020, c)
assert.Equal(t, 1, window.size)
assert.Equal(t, 4, window.start)
}