1 // Copyright 2012 Google, Inc. All rights reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
18 "github.com/google/gopacket"
19 "github.com/google/gopacket/layers"
22 var netFlow gopacket.Flow
27 netFlow, _ = gopacket.FlowFromEndpoints(
28 layers.NewIPEndpoint(net.IP{1, 2, 3, 4}),
29 layers.NewIPEndpoint(net.IP{5, 6, 7, 8}))
32 type Reassembly struct {
39 type testSequence struct {
44 /* For benchmark: do nothing */
45 type testFactoryBench struct {
48 func (t *testFactoryBench) New(a, b gopacket.Flow, tcp *layers.TCP, ac AssemblerContext) Stream {
51 func (t *testFactoryBench) Accept(tcp *layers.TCP, ci gopacket.CaptureInfo, dir TCPFlowDirection, seq Sequence, start *bool, ac AssemblerContext) bool {
54 func (t *testFactoryBench) ReassembledSG(sg ScatterGather, ac AssemblerContext) {
56 func (t *testFactoryBench) ReassemblyComplete(ac AssemblerContext) bool {
60 /* For tests: append bytes */
61 type testFactory struct {
62 reassembly []Reassembly
65 func (t *testFactory) New(a, b gopacket.Flow, tcp *layers.TCP, ac AssemblerContext) Stream {
68 func (t *testFactory) Reassembled(r []Reassembly) {
70 for i := 0; i < len(r); i++ {
71 //t.reassembly[i].Seen = time.Time{}
74 func (t *testFactory) ReassembledSG(sg ScatterGather, ac AssemblerContext) {
75 _, start, end, skip := sg.Info()
77 t.reassembly = append(t.reassembly, Reassembly{
85 func (t *testFactory) ReassemblyComplete(ac AssemblerContext) bool {
89 func (t *testFactory) Accept(tcp *layers.TCP, ci gopacket.CaptureInfo, dir TCPFlowDirection, seq Sequence, start *bool, ac AssemblerContext) bool {
93 /* For memory checks: counts bytes */
94 type testMemoryFactory struct {
98 func (tf *testMemoryFactory) New(a, b gopacket.Flow, tcp *layers.TCP, ac AssemblerContext) Stream {
101 func (tf *testMemoryFactory) Accept(tcp *layers.TCP, ci gopacket.CaptureInfo, dir TCPFlowDirection, seq Sequence, start *bool, ac AssemblerContext) bool {
104 func (tf *testMemoryFactory) ReassembledSG(sg ScatterGather, ac AssemblerContext) {
105 bytes, _ := sg.Lengths()
108 func (tf *testMemoryFactory) ReassemblyComplete(ac AssemblerContext) bool {
116 func test(t *testing.T, s []testSequence) {
117 fact := &testFactory{}
118 p := NewStreamPool(fact)
120 a.MaxBufferedPagesPerConnection = 4
121 for i, test := range s {
122 fact.reassembly = []Reassembly{}
124 fmt.Printf("#### test: #%d: sending:%s\n", i, hex.EncodeToString(test.in.BaseLayer.Payload))
126 a.Assemble(netFlow, &test.in)
127 final := []Reassembly{}
128 if len(test.want) > 0 {
129 final = append(final, Reassembly{})
130 for _, w := range test.want {
131 final[0].Bytes = append(final[0].Bytes, w.Bytes...)
136 final[0].Start = true
139 final[0].Skip = w.Skip
143 if !reflect.DeepEqual(fact.reassembly, final) {
144 t.Fatalf("test %v:\nwant: %v\n got: %v\n", i, final, fact.reassembly)
147 fmt.Printf("test %v passing...(%s)\n", i, final)
152 func TestReorder(t *testing.T) {
153 test(t, []testSequence{
159 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3}},
161 want: []Reassembly{},
168 BaseLayer: layers.BaseLayer{Payload: []byte{4, 5, 6}},
170 want: []Reassembly{},
177 BaseLayer: layers.BaseLayer{Payload: []byte{10, 11, 12}},
179 want: []Reassembly{},
186 BaseLayer: layers.BaseLayer{Payload: []byte{7, 8, 9}},
191 Bytes: []byte{1, 2, 3},
194 Bytes: []byte{4, 5, 6},
197 Bytes: []byte{7, 8, 9},
200 Bytes: []byte{10, 11, 12},
209 BaseLayer: layers.BaseLayer{Payload: []byte{2, 2, 3}},
211 want: []Reassembly{},
218 BaseLayer: layers.BaseLayer{Payload: []byte{3, 2, 3}},
220 want: []Reassembly{},
227 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3}},
231 Bytes: []byte{1, 2, 3},
234 Bytes: []byte{2, 2, 3},
237 Bytes: []byte{3, 2, 3},
244 func TestMaxPerSkip(t *testing.T) {
245 test(t, []testSequence{
252 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3}},
257 Bytes: []byte{1, 2, 3},
266 BaseLayer: layers.BaseLayer{Payload: []byte{3, 2, 3}},
268 want: []Reassembly{},
275 BaseLayer: layers.BaseLayer{Payload: []byte{4, 2, 3}},
277 want: []Reassembly{},
284 BaseLayer: layers.BaseLayer{Payload: []byte{5, 2, 3}},
286 want: []Reassembly{},
293 BaseLayer: layers.BaseLayer{Payload: []byte{6, 2, 3}},
298 Bytes: []byte{3, 2, 3},
301 Bytes: []byte{4, 2, 3},
304 Bytes: []byte{5, 2, 3},
307 Bytes: []byte{6, 2, 3},
314 func TestReorderFast(t *testing.T) {
315 test(t, []testSequence{
322 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3}},
327 Bytes: []byte{1, 2, 3},
336 BaseLayer: layers.BaseLayer{Payload: []byte{3, 2, 3}},
338 want: []Reassembly{},
345 BaseLayer: layers.BaseLayer{Payload: []byte{2, 2, 3}},
349 Bytes: []byte{2, 2, 3},
352 Bytes: []byte{3, 2, 3},
359 func TestOverlap(t *testing.T) {
360 test(t, []testSequence{
367 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
372 Bytes: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
381 BaseLayer: layers.BaseLayer{Payload: []byte{7, 8, 9, 0, 1, 2, 3, 4, 5}},
385 Bytes: []byte{1, 2, 3, 4, 5},
394 BaseLayer: layers.BaseLayer{Payload: []byte{0, 1, 2, 3, 4, 5, 6, 7}},
405 func TestBufferedOverlap1(t *testing.T) {
406 test(t, []testSequence{
412 BaseLayer: layers.BaseLayer{Payload: []byte{7, 8, 9, 0, 1, 2, 3, 4, 5}},
414 want: []Reassembly{},
421 BaseLayer: layers.BaseLayer{Payload: []byte{0, 1, 2, 3, 4, 5, 6, 7}},
423 want: []Reassembly{},
431 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
436 Bytes: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
439 Bytes: []byte{1, 2, 3, 4, 5},
449 func TestBufferedOverlapCase6(t *testing.T) {
450 test(t, []testSequence{
456 BaseLayer: layers.BaseLayer{Payload: []byte{7, 8, 9, 0, 1, 2, 3, 4, 5}},
458 want: []Reassembly{},
465 BaseLayer: layers.BaseLayer{Payload: []byte{10, 11, 12, 13, 14}},
467 want: []Reassembly{},
475 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
480 Bytes: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
483 Bytes: []byte{11, 12, 13, 14, 5},
490 func TestBufferedOverlapExisting(t *testing.T) {
491 test(t, []testSequence{
498 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7}},
503 Bytes: []byte{1, 2, 3, 4, 5, 6, 7},
512 BaseLayer: layers.BaseLayer{Payload: []byte{5, 6, 7, 8, 9, 10}},
516 Bytes: []byte{8, 9, 10},
523 func TestBufferedOverlapReemit(t *testing.T) {
524 test(t, []testSequence{
531 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7}},
536 Bytes: []byte{1, 2, 3, 4, 5, 6, 7},
545 BaseLayer: layers.BaseLayer{Payload: []byte{3, 4, 5}},
547 want: []Reassembly{},
552 func TestReorderRetransmission2(t *testing.T) {
553 test(t, []testSequence{
559 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3}},
561 want: []Reassembly{},
568 BaseLayer: layers.BaseLayer{Payload: []byte{2, 2, 3}},
570 want: []Reassembly{},
577 BaseLayer: layers.BaseLayer{Payload: []byte{2, 2, 3}},
579 want: []Reassembly{},
586 BaseLayer: layers.BaseLayer{Payload: []byte{10, 11}},
588 want: []Reassembly{},
595 BaseLayer: layers.BaseLayer{Payload: []byte{6, 6, 6, 2, 2}},
600 Bytes: []byte{1, 2, 3},
603 Bytes: []byte{6, 6, 6},
606 Bytes: []byte{2, 2, 3},
609 Bytes: []byte{10, 11},
616 func TestOverrun1(t *testing.T) {
617 test(t, []testSequence{
624 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
629 Bytes: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
638 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4}},
642 Bytes: []byte{1, 2, 3, 4},
649 func TestOverrun2(t *testing.T) {
650 test(t, []testSequence{
656 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4}},
658 want: []Reassembly{},
666 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
671 Bytes: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
674 Bytes: []byte{1, 2, 3, 4},
681 func TestCacheLargePacket(t *testing.T) {
682 data := make([]byte, pageBytes*3)
683 test(t, []testSequence{
689 BaseLayer: layers.BaseLayer{Payload: data},
691 want: []Reassembly{},
699 BaseLayer: layers.BaseLayer{Payload: []byte{}},
707 Bytes: data[:pageBytes],
710 Bytes: data[pageBytes : pageBytes*2],
713 Bytes: data[pageBytes*2 : pageBytes*3],
723 type testKeepFactory struct {
730 func (tkf *testKeepFactory) New(a, b gopacket.Flow, tcp *layers.TCP, ac AssemblerContext) Stream {
733 func (tkf *testKeepFactory) ReassembledSG(sg ScatterGather, ac AssemblerContext) {
735 _, _, _, tkf.skipped = sg.Info()
736 tkf.bytes = sg.Fetch(l)
737 sg.KeepFrom(tkf.keep)
739 func (tkf *testKeepFactory) ReassemblyComplete(ac AssemblerContext) bool {
743 func (tkf *testKeepFactory) Accept(tcp *layers.TCP, ci gopacket.CaptureInfo, dir TCPFlowDirection, seq Sequence, start *bool, ac AssemblerContext) bool {
747 type testKeepSequence struct {
754 func testKeep(t *testing.T, s []testKeepSequence) {
755 fact := &testKeepFactory{t: t}
756 p := NewStreamPool(fact)
758 a.MaxBufferedPagesPerConnection = 4
759 port := layers.TCPPort(0)
760 for i, test := range s {
761 // Fake some values according to ports
763 dir := TCPDirClientToServer
765 port = test.tcp.SrcPort
767 if port != test.tcp.SrcPort {
769 flow = flow.Reverse()
771 test.tcp.SetInternalPortsForTesting()
772 fact.keep = test.keep
773 fact.bytes = []byte{}
775 fmt.Printf("#### testKeep: #%d: sending:%s\n", i, hex.EncodeToString(test.tcp.BaseLayer.Payload))
777 a.Assemble(flow, &test.tcp)
778 if !reflect.DeepEqual(fact.bytes, test.want) {
779 t.Fatalf("#%d: invalid bytes: got %v, expected %v", i, fact.bytes, test.want)
781 if fact.skipped != test.skipped {
782 t.Fatalf("#%d: expecting %d skipped bytes, got %d", i, test.skipped, fact.skipped)
785 fmt.Printf("#### testKeep: #%d: bytes: %s\n", i, hex.EncodeToString(fact.bytes))
790 func TestKeepSimpleOnBoundary(t *testing.T) {
791 testKeep(t, []testKeepSequence{
798 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
801 want: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
808 BaseLayer: layers.BaseLayer{Payload: []byte{7, 8, 9, 0, 1, 2, 3, 4, 5}},
810 want: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5},
815 func TestKeepSimpleNotBoundaryLive(t *testing.T) {
816 testKeep(t, []testKeepSequence{
823 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
826 want: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
833 BaseLayer: layers.BaseLayer{Payload: []byte{7, 8, 9, 0, 1, 2, 3, 4, 5}},
835 want: []byte{2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5},
840 func TestKeepSimpleNotBoundaryAlreadyKept(t *testing.T) {
841 testKeep(t, []testKeepSequence{
848 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0x10}},
851 want: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0x10},
858 BaseLayer: layers.BaseLayer{Payload: []byte{7, 8, 9, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15}},
861 want: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15},
868 BaseLayer: layers.BaseLayer{Payload: []byte{0x16, 0x17, 0x18}},
870 want: []byte{0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18},
875 func TestKeepLonger(t *testing.T) {
876 testKeep(t, []testKeepSequence{
883 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
886 want: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
893 BaseLayer: layers.BaseLayer{Payload: []byte{7, 8, 9, 10, 11, 12, 13, 14, 15}},
896 want: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
903 BaseLayer: layers.BaseLayer{Payload: []byte{10, 11, 12, 13, 14, 15, 16, 17}},
905 want: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17},
910 func TestKeepWithFlush(t *testing.T) {
911 testKeep(t, []testKeepSequence{
918 BaseLayer: layers.BaseLayer{Payload: []byte{1}},
928 BaseLayer: layers.BaseLayer{Payload: []byte{3}},
938 BaseLayer: layers.BaseLayer{Payload: []byte{4}},
948 BaseLayer: layers.BaseLayer{Payload: []byte{6}},
953 // Exceeding 4 pages: flushing first continuous pages
959 BaseLayer: layers.BaseLayer{Payload: []byte{8}},
970 BaseLayer: layers.BaseLayer{Payload: []byte{10}},
981 BaseLayer: layers.BaseLayer{Payload: []byte{12}},
993 /* For FSM: bump nb on accepted packet */
994 type testFSMFactory struct {
999 func (t *testFSMFactory) New(a, b gopacket.Flow, tcp *layers.TCP, ac AssemblerContext) Stream {
1002 func (t *testFSMFactory) ReassembledSG(sg ScatterGather, ac AssemblerContext) {
1004 func (t *testFSMFactory) ReassemblyComplete(ac AssemblerContext) bool {
1008 func (t *testFSMFactory) Accept(tcp *layers.TCP, ci gopacket.CaptureInfo, dir TCPFlowDirection, seq Sequence, start *bool, ac AssemblerContext) bool {
1009 ok := t.fsm.CheckState(tcp, dir)
1016 type testFSMSequence struct {
1018 ci gopacket.CaptureInfo
1022 func (seq *testFSMSequence) GetCaptureInfo() gopacket.CaptureInfo {
1026 func testFSM(t *testing.T, s []testFSMSequence) {
1027 fact := &testFSMFactory{}
1028 p := NewStreamPool(fact)
1029 a := NewAssembler(p)
1030 //a.MaxBufferedPagesPerConnection = 4
1032 port := layers.TCPPort(0)
1033 for i, test := range s {
1034 // Fake some values according to ports
1036 dir := TCPDirClientToServer
1038 port = test.tcp.SrcPort
1040 if port != test.tcp.SrcPort {
1042 flow = flow.Reverse()
1044 test.tcp.SetInternalPortsForTesting()
1045 a.AssembleWithContext(flow, &test.tcp, &test)
1046 if fact.nb != test.nb {
1047 t.Fatalf("#%d: packet rejected: got %d, expected %d", i, fact.nb, test.nb)
1052 func TestFSMnormalFlow(t *testing.T) {
1053 testFSM(t, []testFSMSequence{
1061 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1063 ci: gopacket.CaptureInfo{
1064 Timestamp: time.Unix(1432538521, 566690000),
1076 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1078 ci: gopacket.CaptureInfo{
1079 Timestamp: time.Unix(1432538521, 590332000),
1090 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1092 ci: gopacket.CaptureInfo{
1093 Timestamp: time.Unix(1432538521, 590346000),
1104 BaseLayer: layers.BaseLayer{Payload: []byte{0, 31, 104, 196, 0, 32, 0, 1, 0, 0, 0, 0, 0, 1, 2, 85, 83, 0, 0, 6, 0, 1, 0, 0, 41, 16, 0, 0, 0, 128, 0, 0, 0}},
1106 ci: gopacket.CaptureInfo{
1107 Timestamp: time.Unix(1432538521, 590387000),
1118 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1120 ci: gopacket.CaptureInfo{
1121 Timestamp: time.Unix(1432538521, 613687000),
1132 BaseLayer: layers.BaseLayer{Payload: []byte{8, 133, 104, 196, 132, 0, 0, 1, 0, 2, 0, 7, 0, 19, 2, 85, 83, 0, 0, 6, 0, 1, 2, 117, 115, 0, 0, 6, 0, 1, 0, 0, 3, 132, 0, 54, 1, 97, 5, 99, 99, 116, 108, 100, 192, 20, 10, 104, 111, 115, 116, 109, 97, 115, 116, 101, 114, 7, 110, 101, 117, 115, 116, 97, 114, 3, 98, 105, 122, 0, 120, 18, 40, 205, 0, 0, 3, 132, 0, 0, 3, 132, 0, 9, 58, 128, 0, 1, 81, 128, 192, 20, 0, 46, 0, 1, 0, 0, 3, 132, 0, 150, 0, 6, 5, 1, 0, 0, 3, 132, 85, 138, 90, 146, 85, 98, 191, 130, 27, 78, 2, 117, 115, 0, 69, 13, 35, 189, 141, 225, 107, 238, 108, 182, 207, 44, 105, 31, 212, 103, 32, 93, 217, 108, 20, 231, 188, 28, 241, 237, 104, 182, 117, 121, 195, 112, 64, 96, 237, 248, 6, 181, 186, 96, 60, 6, 18, 29, 188, 96, 201, 140, 251, 61, 71, 177, 108, 156, 9, 83, 125, 172, 188, 75, 81, 67, 218, 55, 93, 131, 243, 15, 190, 75, 4, 165, 226, 124, 49, 67, 142, 131, 239, 240, 76, 225, 10, 242, 68, 88, 240, 200, 27, 97, 102, 73, 92, 73, 133, 170, 175, 198, 99, 109, 90, 16, 162, 101, 95, 96, 102, 250, 91, 74, 80, 3, 87, 167, 50, 230, 9, 213, 7, 222, 197, 87, 183, 190, 148, 247, 207, 204, 192, 118, 0, 2, 0, 1, 0, 7, 233, 0, 0, 10, 1, 102, 5, 99, 99, 116, 108, 100, 192, 12, 192, 118, 0, 2, 0, 1, 0, 7, 233, 0, 0, 4, 1, 97, 193, 8, 192, 118, 0, 2, 0, 1, 0, 7, 233, 0, 0, 4, 1, 98, 193, 8, 192, 118, 0, 2, 0, 1, 0, 7, 233, 0, 0, 4, 1, 99, 193, 8, 192, 118, 0, 2, 0, 1, 0, 7, 233, 0, 0, 4, 1, 101, 193, 8, 192, 118, 0, 2, 0, 1, 0, 7, 233, 0, 0, 4, 1, 107, 193, 8, 192, 118, 0, 46, 0, 1, 0, 7, 233, 0, 0, 150, 0, 2, 5, 1, 0, 7, 233, 0, 85, 127, 33, 92, 85, 87, 134, 98, 27, 78, 2, 117, 115, 0, 19, 227, 175, 75, 88, 245, 164, 158, 150, 198, 57, 253, 150, 179, 161, 52, 24, 56, 229, 176, 175, 40, 45, 232, 188, 171, 131, 197, 107, 125, 218, 192, 78, 221, 146, 33, 114, 55, 43, 12, 131, 213, 51, 98, 37, 2, 102, 161, 232, 115, 177, 210, 51, 169, 215, 133, 56, 190, 91, 75, 8, 222, 231, 202, 139, 28, 187, 249, 72, 21, 23, 56, 63, 72, 126, 142, 242, 195, 242, 64, 208, 134, 100, 157, 197, 159, 43, 148, 20, 70, 117, 152, 159, 35, 200, 220, 49, 234, 173, 210, 91, 34, 210, 192, 7, 197, 112, 117, 208, 234, 42, 49, 133, 237, 197, 14, 244, 149, 191, 142, 36, 252, 42, 48, 182, 189, 9, 68, 1, 65, 5, 67, 67, 84, 76, 68, 193, 126, 0, 1, 0, 1, 0, 0, 28, 32, 0, 4, 156, 154, 124, 70, 1, 66, 194, 4, 0, 1, 0, 1, 0, 0, 28, 32, 0, 4, 156, 154, 125, 70, 194, 26, 0, 28, 0, 1, 0, 0, 28, 32, 0, 16, 32, 1, 5, 3, 209, 174, 255, 255, 255, 255, 255, 255, 255, 255, 255, 126, 1, 67, 194, 4, 0, 1, 0, 1, 0, 0, 28, 32, 0, 4, 156, 154, 127, 70, 1, 69, 194, 4, 0, 1, 0, 1, 0, 0, 28, 32, 0, 4, 156, 154, 126, 70, 1, 70, 194, 4, 0, 1, 0, 1, 0, 0, 28, 32, 0, 4, 209, 173, 58, 70, 194, 108, 0, 28, 0, 1, 0, 0, 28, 32, 0, 16, 32, 1, 5, 0, 54, 130, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 1, 75, 194, 4, 0, 1, 0, 1, 0, 0, 28, 32, 0, 4, 156, 154, 128, 70, 194, 154, 0, 28, 0, 1, 0, 0, 28, 32, 0, 16, 32, 1, 5, 3, 226, 57, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 194, 2, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 1, 5, 3, 0, 0, 28, 32, 85, 112, 230, 49, 85, 73, 83, 2, 27, 78, 2, 117, 115, 0, 82, 36, 11, 141, 74, 85, 70, 98, 179, 63, 173, 83, 8, 70, 155, 41, 102, 166, 140, 62, 71, 178, 130, 38, 171, 200, 180, 68, 2, 215, 45, 6, 43, 59, 171, 146, 223, 215, 9, 77, 5, 104, 167, 42, 237, 170, 30, 114, 205, 129, 59, 225, 152, 224, 79, 1, 65, 68, 208, 153, 121, 237, 199, 87, 2, 251, 100, 105, 59, 24, 73, 226, 169, 121, 250, 91, 41, 124, 14, 23, 135, 52, 2, 86, 72, 224, 100, 135, 70, 216, 16, 107, 84, 59, 13, 168, 58, 187, 54, 98, 230, 167, 246, 42, 46, 156, 206, 238, 120, 199, 25, 144, 98, 249, 70, 162, 34, 43, 145, 114, 186, 233, 47, 42, 75, 95, 152, 235, 194, 26, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 1, 5, 3, 0, 0, 28, 32, 85, 112, 190, 140, 85, 73, 36, 78, 27, 78, 2, 117, 115, 0, 160, 95, 100, 37, 167, 82, 93, 165, 126, 247, 147, 173, 238, 154, 206, 174, 96, 175, 209, 7, 8, 169, 171, 223, 29, 201, 161, 177, 98, 54, 94, 62, 70, 127, 142, 109, 206, 42, 179, 109, 156, 160, 156, 20, 59, 24, 147, 164, 13, 121, 192, 84, 157, 26, 56, 177, 151, 210, 7, 197, 229, 110, 60, 58, 224, 42, 77, 5, 59, 80, 216, 221, 248, 19, 66, 102, 74, 199, 238, 120, 231, 201, 187, 29, 11, 46, 195, 164, 8, 221, 128, 25, 205, 42, 247, 152, 112, 176, 14, 117, 150, 223, 245, 32, 212, 107, 4, 245, 27, 126, 224, 216, 0, 89, 106, 238, 185, 206, 44, 56, 204, 175, 7, 139, 233, 228, 127, 175, 194, 26, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 28, 5, 3, 0, 0, 28, 32, 85, 108, 217, 174, 85, 69, 70, 242, 27, 78, 2, 117, 115, 0, 172, 117, 89, 89, 73, 249, 245, 211, 100, 127, 48, 135, 224, 97, 172, 146, 128, 30, 190, 72, 199, 170, 97, 179, 136, 109, 86, 110, 235, 214, 47, 50, 115, 11, 226, 168, 56, 198, 24, 212, 205, 207, 2, 116, 104, 112, 99, 234, 236, 44, 70, 19, 19, 215, 127, 200, 162, 215, 142, 45, 135, 91, 219, 217, 86, 231, 154, 87, 222, 161, 32, 66, 196, 55, 117, 20, 186, 9, 134, 252, 249, 219, 9, 196, 128, 8, 222, 201, 131, 210, 182, 232, 142, 72, 160, 171, 95, 231, 232, 156, 28, 34, 54, 94, 73, 183, 38, 160, 123, 175, 157, 21, 163, 8, 214, 155, 172, 237, 169, 28, 15, 138, 105, 107, 251, 109, 131, 240, 194, 72, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 1, 5, 3, 0, 0, 28, 32, 85, 112, 190, 140, 85, 73, 36, 78, 27, 78, 2, 117, 115, 0, 77, 207, 197, 130, 236, 138, 192, 241, 225, 114, 8, 22, 76, 54, 43, 121, 42, 44, 9, 92, 56, 253, 224, 179, 191, 131, 40, 176, 94, 61, 33, 12, 43, 82, 156, 236, 211, 29, 187, 100, 220, 243, 24, 134, 42, 204, 46, 161, 214, 91, 68, 119, 40, 252, 53, 54, 146, 136, 196, 168, 204, 195, 131, 110, 6, 73, 16, 161, 86, 35, 150, 153, 162, 185, 227, 65, 228, 160, 203, 42, 250, 121, 14, 42, 115, 221, 232, 96, 99, 164, 230, 29, 195, 149, 85, 206, 41, 1, 252, 77, 188, 88, 8, 182, 37, 249, 6, 158, 6, 244, 158, 254, 141, 203, 6, 158, 198, 103, 130, 98, 123, 34, 245, 44, 126, 77, 24, 187, 194, 90, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 1, 5, 3, 0, 0, 28, 32, 85, 108, 194, 203, 85, 69, 51, 125, 27, 78, 2, 117, 115, 0, 86, 26, 187, 56, 252, 194, 199, 140, 229, 133, 186, 187, 20, 174, 26, 48, 212, 129, 10, 20, 167, 179, 53, 72, 176, 92, 153, 48, 146, 15, 163, 182, 80, 138, 181, 135, 98, 129, 17, 66, 55, 184, 76, 225, 72, 104, 7, 221, 40, 71, 41, 202, 246, 154, 166, 199, 74, 175, 146, 54, 25, 56, 115, 243}},
1134 ci: gopacket.CaptureInfo{
1135 Timestamp: time.Unix(1432538521, 621198000),
1146 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1148 ci: gopacket.CaptureInfo{
1149 Timestamp: time.Unix(1432538521, 621220000),
1160 BaseLayer: layers.BaseLayer{Payload: []byte{153, 141, 101, 187, 110, 15, 63, 42, 81, 100, 95, 68, 241, 85, 160, 227, 3, 1, 12, 80, 166, 1, 98, 2, 44, 98, 63, 203, 70, 164, 99, 195, 23, 152, 223, 253, 208, 10, 12, 19, 66, 121, 9, 158, 205, 96, 218, 0, 80, 70, 58, 95, 41, 124, 216, 13, 122, 135, 102, 200, 181, 233, 129, 174, 194, 108, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 1, 5, 3, 0, 0, 28, 32, 85, 108, 223, 157, 85, 69, 74, 55, 27, 78, 2, 117, 115, 0, 149, 71, 215, 149, 16, 165, 115, 229, 141, 136, 187, 158, 88, 225, 131, 231, 182, 218, 235, 27, 48, 65, 244, 77, 186, 135, 72, 18, 87, 52, 180, 128, 130, 67, 75, 173, 160, 243, 104, 178, 103, 117, 96, 209, 36, 51, 108, 47, 232, 214, 254, 15, 208, 182, 218, 174, 248, 237, 88, 150, 35, 190, 239, 249, 171, 151, 9, 236, 2, 252, 255, 13, 79, 190, 147, 36, 161, 210, 202, 80, 209, 136, 167, 180, 186, 68, 246, 249, 48, 123, 46, 11, 132, 103, 132, 207, 186, 68, 110, 133, 142, 109, 194, 19, 122, 57, 203, 217, 120, 93, 67, 168, 91, 252, 87, 38, 33, 228, 229, 162, 190, 170, 23, 188, 89, 15, 241, 71, 194, 108, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 28, 5, 3, 0, 0, 28, 32, 85, 108, 217, 174, 85, 69, 70, 242, 27, 78, 2, 117, 115, 0, 206, 97, 120, 37, 255, 252, 7, 156, 162, 192, 43, 84, 105, 94, 125, 55, 13, 247, 234, 9, 25, 100, 246, 25, 77, 168, 199, 208, 187, 209, 164, 123, 234, 138, 238, 15, 86, 45, 163, 108, 162, 117, 247, 128, 3, 187, 100, 185, 193, 191, 134, 86, 161, 254, 236, 99, 66, 66, 35, 173, 91, 243, 175, 3, 175, 94, 79, 68, 246, 109, 200, 154, 209, 185, 11, 210, 50, 147, 136, 213, 158, 81, 111, 17, 149, 239, 110, 114, 25, 234, 247, 158, 233, 33, 36, 181, 66, 84, 189, 37, 207, 58, 9, 171, 143, 66, 69, 137, 192, 6, 187, 59, 16, 51, 80, 56, 89, 170, 12, 195, 69, 133, 188, 110, 171, 17, 17, 213, 194, 154, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 1, 5, 3, 0, 0, 28, 32, 85, 112, 190, 140, 85, 73, 36, 78, 27, 78, 2, 117, 115, 0, 123, 36, 154, 4, 158, 41, 96, 252, 116, 114, 16, 137, 28, 177, 206, 33, 192, 88, 89, 1, 69, 252, 206, 88, 89, 152, 210, 179, 248, 44, 202, 239, 95, 131, 126, 147, 249, 93, 57, 166, 215, 184, 211, 164, 196, 71, 170, 3, 25, 18, 177, 214, 94, 147, 181, 148, 197, 11, 171, 219, 107, 48, 105, 81, 239, 110, 249, 140, 68, 127, 193, 146, 176, 161, 246, 108, 75, 141, 205, 211, 73, 247, 125, 205, 120, 156, 82, 55, 130, 250, 26, 15, 44, 214, 91, 115, 11, 103, 22, 83, 184, 96, 107, 138, 2, 127, 168, 191, 92, 102, 137, 161, 63, 225, 134, 17, 178, 242, 11, 43, 8, 30, 164, 28, 140, 195, 83, 121, 194, 154, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 28, 5, 3, 0, 0, 28, 32, 85, 112, 190, 140, 85, 73, 36, 78, 27, 78, 2, 117, 115, 0, 189, 98, 234, 251, 237, 24, 143, 210, 30, 242, 97, 66, 50, 211, 47, 109, 110, 121, 244, 239, 89, 0, 39, 92, 218, 155, 71, 5, 23, 136, 231, 107, 95, 52, 231, 118, 253, 206, 250, 178, 209, 136, 13, 36, 36, 54, 157, 237, 35, 110, 134, 253, 80, 237, 162, 163, 38, 21, 54, 241, 240, 253, 73, 33, 191, 128, 32, 6, 198, 165, 35, 203, 244, 15, 166, 250, 159, 67, 149, 56, 19, 243, 230, 87, 6, 44, 150, 90, 79, 107, 18, 121, 112, 23, 176, 104, 50, 110, 176, 138, 250, 6, 209, 22, 41, 73, 234, 4, 124, 233, 208, 218, 236, 117, 232, 217, 10, 172, 18, 215, 143, 119, 193, 113, 10, 59, 255, 221, 0, 0, 41, 16, 0, 0, 0, 128, 0, 0, 0}},
1162 ci: gopacket.CaptureInfo{
1163 Timestamp: time.Unix(1432538521, 622508000),
1174 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1176 ci: gopacket.CaptureInfo{
1177 Timestamp: time.Unix(1432538521, 622531000),
1189 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1191 ci: gopacket.CaptureInfo{
1192 Timestamp: time.Unix(1432538521, 622907000),
1204 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1206 ci: gopacket.CaptureInfo{
1207 Timestamp: time.Unix(1432538521, 652784000),
1218 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1220 ci: gopacket.CaptureInfo{
1221 Timestamp: time.Unix(1432538521, 652809000),
1228 func TestFSMearlyRST(t *testing.T) {
1229 testFSM(t, []testFSMSequence{
1237 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1239 ci: gopacket.CaptureInfo{
1240 Timestamp: time.Unix(1432538521, 566690000),
1252 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1254 ci: gopacket.CaptureInfo{
1255 Timestamp: time.Unix(1432538521, 590332000),
1266 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1268 ci: gopacket.CaptureInfo{
1269 Timestamp: time.Unix(1432538521, 590346000),
1280 BaseLayer: layers.BaseLayer{Payload: []byte{0, 31, 104, 196, 0, 32, 0, 1, 0, 0, 0, 0, 0, 1, 2, 85, 83, 0, 0, 6, 0, 1, 0, 0, 41, 16, 0, 0, 0, 128, 0, 0, 0}},
1282 ci: gopacket.CaptureInfo{
1283 Timestamp: time.Unix(1432538521, 590387000),
1294 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1296 ci: gopacket.CaptureInfo{
1297 Timestamp: time.Unix(1432538521, 613687000),
1304 func TestFSMestablishedThenRST(t *testing.T) {
1305 testFSM(t, []testFSMSequence{
1313 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1315 ci: gopacket.CaptureInfo{
1316 Timestamp: time.Unix(1432538521, 566690000),
1328 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1330 ci: gopacket.CaptureInfo{
1331 Timestamp: time.Unix(1432538521, 590332000),
1342 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1344 ci: gopacket.CaptureInfo{
1345 Timestamp: time.Unix(1432538521, 590346000),
1356 BaseLayer: layers.BaseLayer{Payload: []byte{0, 31, 104, 196, 0, 32, 0, 1, 0, 0, 0, 0, 0, 1, 2, 85, 83, 0, 0, 6, 0, 1, 0, 0, 41, 16, 0, 0, 0, 128, 0, 0, 0}},
1358 ci: gopacket.CaptureInfo{
1359 Timestamp: time.Unix(1432538521, 590387000),
1370 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1372 ci: gopacket.CaptureInfo{
1373 Timestamp: time.Unix(1432538521, 613687000),
1384 BaseLayer: layers.BaseLayer{Payload: []byte{8, 133, 104, 196, 132, 0, 0, 1, 0, 2, 0, 7, 0, 19, 2, 85, 83, 0, 0, 6, 0, 1, 2, 117, 115, 0, 0, 6, 0, 1, 0, 0, 3, 132, 0, 54, 1, 97, 5, 99, 99, 116, 108, 100, 192, 20, 10, 104, 111, 115, 116, 109, 97, 115, 116, 101, 114, 7, 110, 101, 117, 115, 116, 97, 114, 3, 98, 105, 122, 0, 120, 18, 40, 205, 0, 0, 3, 132, 0, 0, 3, 132, 0, 9, 58, 128, 0, 1, 81, 128, 192, 20, 0, 46, 0, 1, 0, 0, 3, 132, 0, 150, 0, 6, 5, 1, 0, 0, 3, 132, 85, 138, 90, 146, 85, 98, 191, 130, 27, 78, 2, 117, 115, 0, 69, 13, 35, 189, 141, 225, 107, 238, 108, 182, 207, 44, 105, 31, 212, 103, 32, 93, 217, 108, 20, 231, 188, 28, 241, 237, 104, 182, 117, 121, 195, 112, 64, 96, 237, 248, 6, 181, 186, 96, 60, 6, 18, 29, 188, 96, 201, 140, 251, 61, 71, 177, 108, 156, 9, 83, 125, 172, 188, 75, 81, 67, 218, 55, 93, 131, 243, 15, 190, 75, 4, 165, 226, 124, 49, 67, 142, 131, 239, 240, 76, 225, 10, 242, 68, 88, 240, 200, 27, 97, 102, 73, 92, 73, 133, 170, 175, 198, 99, 109, 90, 16, 162, 101, 95, 96, 102, 250, 91, 74, 80, 3, 87, 167, 50, 230, 9, 213, 7, 222, 197, 87, 183, 190, 148, 247, 207, 204, 192, 118, 0, 2, 0, 1, 0, 7, 233, 0, 0, 10, 1, 102, 5, 99, 99, 116, 108, 100, 192, 12, 192, 118, 0, 2, 0, 1, 0, 7, 233, 0, 0, 4, 1, 97, 193, 8, 192, 118, 0, 2, 0, 1, 0, 7, 233, 0, 0, 4, 1, 98, 193, 8, 192, 118, 0, 2, 0, 1, 0, 7, 233, 0, 0, 4, 1, 99, 193, 8, 192, 118, 0, 2, 0, 1, 0, 7, 233, 0, 0, 4, 1, 101, 193, 8, 192, 118, 0, 2, 0, 1, 0, 7, 233, 0, 0, 4, 1, 107, 193, 8, 192, 118, 0, 46, 0, 1, 0, 7, 233, 0, 0, 150, 0, 2, 5, 1, 0, 7, 233, 0, 85, 127, 33, 92, 85, 87, 134, 98, 27, 78, 2, 117, 115, 0, 19, 227, 175, 75, 88, 245, 164, 158, 150, 198, 57, 253, 150, 179, 161, 52, 24, 56, 229, 176, 175, 40, 45, 232, 188, 171, 131, 197, 107, 125, 218, 192, 78, 221, 146, 33, 114, 55, 43, 12, 131, 213, 51, 98, 37, 2, 102, 161, 232, 115, 177, 210, 51, 169, 215, 133, 56, 190, 91, 75, 8, 222, 231, 202, 139, 28, 187, 249, 72, 21, 23, 56, 63, 72, 126, 142, 242, 195, 242, 64, 208, 134, 100, 157, 197, 159, 43, 148, 20, 70, 117, 152, 159, 35, 200, 220, 49, 234, 173, 210, 91, 34, 210, 192, 7, 197, 112, 117, 208, 234, 42, 49, 133, 237, 197, 14, 244, 149, 191, 142, 36, 252, 42, 48, 182, 189, 9, 68, 1, 65, 5, 67, 67, 84, 76, 68, 193, 126, 0, 1, 0, 1, 0, 0, 28, 32, 0, 4, 156, 154, 124, 70, 1, 66, 194, 4, 0, 1, 0, 1, 0, 0, 28, 32, 0, 4, 156, 154, 125, 70, 194, 26, 0, 28, 0, 1, 0, 0, 28, 32, 0, 16, 32, 1, 5, 3, 209, 174, 255, 255, 255, 255, 255, 255, 255, 255, 255, 126, 1, 67, 194, 4, 0, 1, 0, 1, 0, 0, 28, 32, 0, 4, 156, 154, 127, 70, 1, 69, 194, 4, 0, 1, 0, 1, 0, 0, 28, 32, 0, 4, 156, 154, 126, 70, 1, 70, 194, 4, 0, 1, 0, 1, 0, 0, 28, 32, 0, 4, 209, 173, 58, 70, 194, 108, 0, 28, 0, 1, 0, 0, 28, 32, 0, 16, 32, 1, 5, 0, 54, 130, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 1, 75, 194, 4, 0, 1, 0, 1, 0, 0, 28, 32, 0, 4, 156, 154, 128, 70, 194, 154, 0, 28, 0, 1, 0, 0, 28, 32, 0, 16, 32, 1, 5, 3, 226, 57, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 194, 2, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 1, 5, 3, 0, 0, 28, 32, 85, 112, 230, 49, 85, 73, 83, 2, 27, 78, 2, 117, 115, 0, 82, 36, 11, 141, 74, 85, 70, 98, 179, 63, 173, 83, 8, 70, 155, 41, 102, 166, 140, 62, 71, 178, 130, 38, 171, 200, 180, 68, 2, 215, 45, 6, 43, 59, 171, 146, 223, 215, 9, 77, 5, 104, 167, 42, 237, 170, 30, 114, 205, 129, 59, 225, 152, 224, 79, 1, 65, 68, 208, 153, 121, 237, 199, 87, 2, 251, 100, 105, 59, 24, 73, 226, 169, 121, 250, 91, 41, 124, 14, 23, 135, 52, 2, 86, 72, 224, 100, 135, 70, 216, 16, 107, 84, 59, 13, 168, 58, 187, 54, 98, 230, 167, 246, 42, 46, 156, 206, 238, 120, 199, 25, 144, 98, 249, 70, 162, 34, 43, 145, 114, 186, 233, 47, 42, 75, 95, 152, 235, 194, 26, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 1, 5, 3, 0, 0, 28, 32, 85, 112, 190, 140, 85, 73, 36, 78, 27, 78, 2, 117, 115, 0, 160, 95, 100, 37, 167, 82, 93, 165, 126, 247, 147, 173, 238, 154, 206, 174, 96, 175, 209, 7, 8, 169, 171, 223, 29, 201, 161, 177, 98, 54, 94, 62, 70, 127, 142, 109, 206, 42, 179, 109, 156, 160, 156, 20, 59, 24, 147, 164, 13, 121, 192, 84, 157, 26, 56, 177, 151, 210, 7, 197, 229, 110, 60, 58, 224, 42, 77, 5, 59, 80, 216, 221, 248, 19, 66, 102, 74, 199, 238, 120, 231, 201, 187, 29, 11, 46, 195, 164, 8, 221, 128, 25, 205, 42, 247, 152, 112, 176, 14, 117, 150, 223, 245, 32, 212, 107, 4, 245, 27, 126, 224, 216, 0, 89, 106, 238, 185, 206, 44, 56, 204, 175, 7, 139, 233, 228, 127, 175, 194, 26, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 28, 5, 3, 0, 0, 28, 32, 85, 108, 217, 174, 85, 69, 70, 242, 27, 78, 2, 117, 115, 0, 172, 117, 89, 89, 73, 249, 245, 211, 100, 127, 48, 135, 224, 97, 172, 146, 128, 30, 190, 72, 199, 170, 97, 179, 136, 109, 86, 110, 235, 214, 47, 50, 115, 11, 226, 168, 56, 198, 24, 212, 205, 207, 2, 116, 104, 112, 99, 234, 236, 44, 70, 19, 19, 215, 127, 200, 162, 215, 142, 45, 135, 91, 219, 217, 86, 231, 154, 87, 222, 161, 32, 66, 196, 55, 117, 20, 186, 9, 134, 252, 249, 219, 9, 196, 128, 8, 222, 201, 131, 210, 182, 232, 142, 72, 160, 171, 95, 231, 232, 156, 28, 34, 54, 94, 73, 183, 38, 160, 123, 175, 157, 21, 163, 8, 214, 155, 172, 237, 169, 28, 15, 138, 105, 107, 251, 109, 131, 240, 194, 72, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 1, 5, 3, 0, 0, 28, 32, 85, 112, 190, 140, 85, 73, 36, 78, 27, 78, 2, 117, 115, 0, 77, 207, 197, 130, 236, 138, 192, 241, 225, 114, 8, 22, 76, 54, 43, 121, 42, 44, 9, 92, 56, 253, 224, 179, 191, 131, 40, 176, 94, 61, 33, 12, 43, 82, 156, 236, 211, 29, 187, 100, 220, 243, 24, 134, 42, 204, 46, 161, 214, 91, 68, 119, 40, 252, 53, 54, 146, 136, 196, 168, 204, 195, 131, 110, 6, 73, 16, 161, 86, 35, 150, 153, 162, 185, 227, 65, 228, 160, 203, 42, 250, 121, 14, 42, 115, 221, 232, 96, 99, 164, 230, 29, 195, 149, 85, 206, 41, 1, 252, 77, 188, 88, 8, 182, 37, 249, 6, 158, 6, 244, 158, 254, 141, 203, 6, 158, 198, 103, 130, 98, 123, 34, 245, 44, 126, 77, 24, 187, 194, 90, 0, 46, 0, 1, 0, 0, 28, 32, 0, 150, 0, 1, 5, 3, 0, 0, 28, 32, 85, 108, 194, 203, 85, 69, 51, 125, 27, 78, 2, 117, 115, 0, 86, 26, 187, 56, 252, 194, 199, 140, 229, 133, 186, 187, 20, 174, 26, 48, 212, 129, 10, 20, 167, 179, 53, 72, 176, 92, 153, 48, 146, 15, 163, 182, 80, 138, 181, 135, 98, 129, 17, 66, 55, 184, 76, 225, 72, 104, 7, 221, 40, 71, 41, 202, 246, 154, 166, 199, 74, 175, 146, 54, 25, 56, 115, 243}},
1386 ci: gopacket.CaptureInfo{
1387 Timestamp: time.Unix(1432538521, 621198000),
1398 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1400 ci: gopacket.CaptureInfo{
1401 Timestamp: time.Unix(1432538521, 621220000),
1408 func TestFSMmissingSYNACK(t *testing.T) {
1409 testFSM(t, []testFSMSequence{
1417 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1419 ci: gopacket.CaptureInfo{
1420 Timestamp: time.Unix(1432538521, 566690000),
1431 BaseLayer: layers.BaseLayer{Payload: []byte{}},
1433 ci: gopacket.CaptureInfo{
1434 Timestamp: time.Unix(1432538521, 590346000),
1445 BaseLayer: layers.BaseLayer{Payload: []byte{0, 31, 104, 196, 0, 32, 0, 1, 0, 0, 0, 0, 0, 1, 2, 85, 83, 0, 0, 6, 0, 1, 0, 0, 41, 16, 0, 0, 0, 128, 0, 0, 0}},
1447 ci: gopacket.CaptureInfo{
1448 Timestamp: time.Unix(1432538521, 590387000),
1458 func TestMemoryShrink(t *testing.T) {
1464 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
1466 a := NewAssembler(NewStreamPool(&testFactoryBench{}))
1467 var before runtime.MemStats
1469 runtime.ReadMemStats(&before)
1471 // Allocate > initial
1472 for i := 0; i < run; i++ {
1473 a.Assemble(netFlow, &tcp)
1480 var after runtime.MemStats
1483 runtime.ReadMemStats(&after)
1484 if after.HeapAlloc < before.HeapAlloc {
1485 t.Fatalf("Nothing allocated for %d run: before: %d, after: %d", run, before.HeapAlloc, after.HeapAlloc)
1488 // Do ~ initial allocs+free()
1490 for i := 0; i < run; i++ {
1491 a.Assemble(netFlow, &tcp)
1498 runtime.ReadMemStats(&after)
1499 if after.HeapAlloc >= before.HeapAlloc {
1500 t.Fatalf("Nothing freed for %d run: before: %d, after: %d", run, before.HeapAlloc, after.HeapAlloc)
1507 func BenchmarkSingleStreamNo(b *testing.B) {
1513 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
1515 a := NewAssembler(NewStreamPool(&testFactoryBench{}))
1516 for i := 0; i < b.N; i++ {
1517 a.Assemble(netFlow, &t)
1526 func BenchmarkSingleStreamSkips(b *testing.B) {
1532 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
1534 a := NewAssembler(NewStreamPool(&testFactoryBench{}))
1536 for i := 0; i < b.N; i++ {
1543 a.Assemble(netFlow, &t)
1556 func BenchmarkSingleStreamLoss(b *testing.B) {
1562 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
1564 a := NewAssembler(NewStreamPool(&testFactoryBench{}))
1565 for i := 0; i < b.N; i++ {
1566 a.Assemble(netFlow, &t)
1572 func BenchmarkMultiStreamGrow(b *testing.B) {
1577 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
1579 a := NewAssembler(NewStreamPool(&testFactoryBench{}))
1580 for i := 0; i < b.N; i++ {
1581 t.SrcPort = layers.TCPPort(i)
1582 a.Assemble(netFlow, &t)
1587 func BenchmarkMultiStreamConn(b *testing.B) {
1593 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
1595 a := NewAssembler(NewStreamPool(&testFactoryBench{}))
1596 for i := 0; i < b.N; i++ {
1597 t.SrcPort = layers.TCPPort(i)
1598 a.Assemble(netFlow, &t)
1599 if i%65536 == 65535 {
1609 type testMemoryContext struct{}
1611 func (t *testMemoryContext) GetCaptureInfo() gopacket.CaptureInfo {
1612 return gopacket.CaptureInfo{
1613 Timestamp: time.Unix(1432538521, 590387000),
1617 func TestFullyOrderedAndCompleteStreamDoesNotAlloc(t *testing.T) {
1623 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
1626 SrcPort: c2s.DstPort,
1627 DstPort: c2s.SrcPort,
1631 BaseLayer: layers.BaseLayer{Payload: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}},
1633 tf := testMemoryFactory{}
1634 a := NewAssembler(NewStreamPool(&tf))
1636 ctx := &testMemoryContext{}
1638 a.AssembleWithContext(netFlow, &c2s, ctx)
1639 a.AssembleWithContext(netFlow.Reverse(), &s2c, ctx)
1640 c2s.SYN, s2c.SYN = false, false
1645 if n := testing.AllocsPerRun(N, func() {
1650 a.AssembleWithContext(netFlow, &c2s, ctx)
1651 a.AssembleWithContext(netFlow.Reverse(), &s2c, ctx)
1653 t.Error(n, "mallocs for normal TCP stream")
1655 // Ensure all bytes have been through the stream
1656 // +1 for first packet and +1 because AllocsPerRun seems to run fun N+1 times.
1657 if tf.bytes != 10*2*(N+1+1) {
1658 t.Error(tf.bytes, "bytes handled, expected", 10*2*(N+1+1))