-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet_test.go
79 lines (75 loc) · 3.19 KB
/
packet_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package quic
import (
"testing"
"github.com/ami-GS/gQUIC/qtype"
. "github.com/smartystreets/goconvey/convey"
)
func TestNewPacket(t *testing.T) {
dstConnID, _ := qtype.NewConnectionID(nil)
srcConnID, _ := qtype.NewConnectionID(nil)
pn := qtype.PacketNumber(1)
Convey("InitialPacketType", t, func() {
sFrame := NewStreamFrame(0, 0, true, true, true, []byte{0x11, 0x22})
header := NewLongHeader(InitialPacketType, qtype.VersionQuicTLS, dstConnID, srcConnID, pn, InitialPacketMinimumPayloadSize)
ePacket := NewInitialPacket(qtype.VersionQuicTLS, dstConnID, srcConnID, pn, sFrame)
aPacket, err := newPacket(header, []Frame{sFrame})
So(err, ShouldBeNil)
So(aPacket, ShouldResemble, ePacket)
})
Convey("RetryPacketType", t, func() {
sFrame := NewStreamFrame(0, 0, true, true, true, []byte{0x11, 0x22})
aFrame := NewAckFrame(2, 3, []AckBlock{AckBlock{32, 0}})
frames := []Frame{sFrame, aFrame}
payloadLen := 0
for _, f := range frames {
payloadLen += f.GetWireSize()
}
header := NewLongHeader(RetryPacketType, qtype.VersionQuicTLS, dstConnID, srcConnID, pn, qtype.QuicInt(payloadLen))
ePacket := NewRetryPacket(qtype.VersionQuicTLS, dstConnID, srcConnID, pn, []Frame{sFrame, aFrame})
aPacket, err := newPacket(header, []Frame{sFrame, aFrame})
So(err, ShouldBeNil)
So(aPacket, ShouldResemble, ePacket)
})
Convey("HandshakePacketType", t, func() {
sFrame := NewStreamFrame(0, 0, true, true, true, []byte{0x11, 0x22})
frames := []Frame{sFrame}
header := NewLongHeader(HandshakePacketType, qtype.VersionQuicTLS, dstConnID, srcConnID, pn, qtype.QuicInt(frames[0].GetWireSize()))
aPacket, err := newPacket(header, frames)
ePacket := NewHandshakePacket(qtype.VersionQuicTLS, dstConnID, srcConnID, pn, frames)
So(err, ShouldBeNil)
So(aPacket, ShouldResemble, ePacket)
})
Convey("ZeroRTTPacketType", t, func() {
sFrame := NewStreamFrame(0, 0, true, true, true, []byte{0x11, 0x22})
frames := []Frame{sFrame}
header := NewLongHeader(ZeroRTTProtectedPacketType, qtype.VersionQuicTLS, dstConnID, srcConnID, pn, qtype.QuicInt(frames[0].GetWireSize()))
aPacket, err := newPacket(header, frames)
ePacket := NewProtectedPacket(qtype.VersionQuicTLS, false, dstConnID, srcConnID, pn, 0, frames)
So(err, ShouldBeNil)
So(aPacket, ShouldResemble, ePacket)
})
Convey("OneRTTPacketType", t, func() {
sFrame := NewStreamFrame(0, 0, true, true, true, []byte{0x11, 0x22})
frames := []Frame{sFrame}
header := NewShortHeader(false, dstConnID, pn)
aPacket, err := newPacket(header, frames)
ePacket := NewProtectedPacket(qtype.VersionQuicTLS, false, dstConnID, srcConnID, pn, 1, frames)
So(err, ShouldBeNil)
So(aPacket, ShouldResemble, ePacket)
})
}
func TestParsePacket(t *testing.T) {
dstConnID, _ := qtype.NewConnectionID(nil)
srcConnID, _ := qtype.NewConnectionID(nil)
pn := qtype.PacketNumber(1)
Convey("InitialPacketType", t, func() {
sFrame := NewStreamFrame(0, 0, true, true, true, []byte{0x11, 0x22})
ePacket := NewInitialPacket(qtype.VersionQuicTLS, dstConnID, srcConnID, pn, sFrame)
wire, err := ePacket.GetWire()
So(err, ShouldBeNil)
aPacket, length, err := ParsePacket(wire)
So(err, ShouldBeNil)
So(length, ShouldEqual, len(wire))
So(aPacket, ShouldResemble, ePacket)
})
}