|
1 |
| -// Copyright (C) 2011 Werner Dittmann |
2 |
| -// |
3 |
| -// This program is free software: you can redistribute it and/or modify |
4 |
| -// it under the terms of the GNU General Public License as published by |
5 |
| -// the Free Software Foundation, either version 3 of the License, or |
6 |
| -// (at your option) any later version. |
7 |
| -// |
8 |
| -// This program is distributed in the hope that it will be useful, |
9 |
| -// but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 |
| -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 |
| -// GNU General Public License for more details. |
12 |
| -// |
13 |
| -// You should have received a copy of the GNU General Public License |
14 |
| -// along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 |
| -// |
16 |
| -// Authors: Werner Dittmann <[email protected]> |
17 |
| -// |
18 |
| - |
19 |
| -package rtp |
20 |
| - |
21 |
| -import ( |
22 |
| - "fmt" |
23 |
| -// "net" |
24 |
| - "testing" |
25 |
| -) |
26 |
| - |
27 |
| -// V=2, P=0, chunks=2; PT=SDES; length=5 32bit words (24 bytes) |
28 |
| -var sdes_1 = []byte{0x81, 202, 0x00, 0x05, |
29 |
| - 0x01, 0x02, 0x03, 0x04, // SSRC 0x01020304 |
30 |
| - 0x01, 0x01, 0x02, // CNAME, len=1, content=2 |
31 |
| - 0x00, // END (chunk length: 8) |
32 |
| - 0x05, 0x06, 0x07, 0x08, // SSRC 0x05060707 |
33 |
| - 0x01, 0x03, 0x05, 0x06, 0x07, // CNAME, len=3, content=5,6,7 |
34 |
| - 0x00, 0x00, 0x00 } // END plus 2 padding (chunk length: 12) |
35 |
| -// V=2, P=0, chunks=2; PT=SDES; length=8 32bit words (36 bytes) |
36 |
| -var sdes_2 = []byte{0x81, 202, 0x00, 0x08, |
37 |
| - // first chunk, two items: CNAME, NAME, END) |
38 |
| - 0x01, 0x02, 0x03, 0x04, // SSRC 0x01020304 |
39 |
| - 0x01, 0x01, 0x02, // CNAME, len=1, content=2 (item length: 3) |
40 |
| - 0x02, 0x07, // NAME, len=7 |
41 |
| - 0x05, 0x06, 0x07, 0x07, 0x06, 0x05, 0x04, // content 5,6,7,7,6,5,4 (item length 9) |
42 |
| - 0x00, 0x00, 0x00, 0x00, // END plus 3 padding (chunk length: 20) |
43 |
| - // second chunk, one item (CNAME, END) |
44 |
| - 0x05, 0x06, 0x07, 0x08, // SSRC 0x05060707 |
45 |
| - 0x01, 0x03, 0x05, 0x06, 0x07, // CNAME, len=3, content=5,6,7 |
46 |
| - 0x00, 0x00, 0x00 } // END plus 2 padding (chunk length: 12) |
47 |
| - |
48 |
| -// V=2, P=0, chunks=2; PT=SDES; length=5 32bit words (24 bytes) |
49 |
| -var sdes_1_wrong = []byte{0x81, 202, 0x00, 0x05, |
50 |
| - 0x01, 0x02, 0x03, 0x04, // SSRC 0x01020304 |
51 |
| - 0x01, 0x03, 0x02, // CNAME, len=3 (wrong, should be 1), content=2 |
52 |
| - 0x00, // END (chunk length: 8) |
53 |
| - 0x05, 0x06, 0x07, 0x08, // SSRC 0x05060707 |
54 |
| - 0x01, 0x03, 0x05, 0x06, 0x07, // CNAME, len=3, content=5,6,7 |
55 |
| - 0x00, 0x00, 0x00 } // END plus 2 padding (chunk length: 12) |
56 |
| - |
57 |
| -func sdesCheck(t *testing.T) (result bool) { |
58 |
| - result = false |
59 |
| - |
60 |
| - rp := new(CtrlPacket) // allocate a new CTRL packet. |
61 |
| - rp.buffer = sdes_1 |
62 |
| - |
63 |
| - cnt := int((rp.Length(0) + 1) * 4) // SDES Length incl. header word |
64 |
| - if cnt != 24 { |
65 |
| - t.Error(fmt.Sprintf("Basic first SDES length check failed. Expected: 24, got: %d\n", cnt)) |
66 |
| - return |
67 |
| - } |
68 |
| - offset := 4 |
69 |
| - // first SDES chunk starts ofter first header word |
70 |
| - sdesChunk := rp.toSdesChunk(offset, cnt-4) |
71 |
| - |
72 |
| - // Get length of first chunk - must be 8 |
73 |
| - chunkLen, _ := sdesChunk.chunkLen() |
74 |
| - if chunkLen != 8 { |
75 |
| - t.Error(fmt.Sprintf("Basic first SDES chunk length check failed. Expected: 8, got: %d\n", chunkLen)) |
76 |
| - return |
77 |
| - } |
78 |
| - offset += chunkLen |
79 |
| - cnt -= chunkLen |
80 |
| - // second SDES chunk starts ofter first chunk :-) |
81 |
| - sdesChunk = rp.toSdesChunk(offset, cnt-4) |
82 |
| - |
83 |
| - // Get length of second chunk - must be 12 |
84 |
| - chunkLen, _ = sdesChunk.chunkLen() |
85 |
| - if chunkLen != 12 { |
86 |
| - t.Error(fmt.Sprintf("Basic first SDES chunk length check failed. Expected: 12, got: %d\n", chunkLen)) |
87 |
| - return |
88 |
| - } |
89 |
| - |
90 |
| - rp.buffer = sdes_2 |
91 |
| - cnt = int((rp.Length(0) + 1) * 4) // SDES Length incl. header word |
92 |
| - if cnt != 36 { |
93 |
| - t.Error(fmt.Sprintf("Basic second SDES length check failed. Expected: 36, got: %d\n", cnt)) |
94 |
| - return |
95 |
| - } |
96 |
| - offset = 4 |
97 |
| - // first SDES chunk starts ofter first header word |
98 |
| - sdesChunk = rp.toSdesChunk(offset, cnt-4) |
99 |
| - |
100 |
| - // Get length of first chunk - must be 20 |
101 |
| - chunkLen, _ = sdesChunk.chunkLen() |
102 |
| - if chunkLen != 20 { |
103 |
| - t.Error(fmt.Sprintf("Basic second SDES chunk length check failed. Expected: 20, got: %d\n", chunkLen)) |
104 |
| - return |
105 |
| - } |
106 |
| - offset += chunkLen |
107 |
| - cnt -= chunkLen |
108 |
| - // second SDES chunk starts ofter first chunk :-) |
109 |
| - sdesChunk = rp.toSdesChunk(offset, cnt-4) |
110 |
| - |
111 |
| - // Get length of second chunk - must be 12 |
112 |
| - chunkLen, _ = sdesChunk.chunkLen() |
113 |
| - if chunkLen != 12 { |
114 |
| - t.Error(fmt.Sprintf("Basic second SDES chunk length check failed. Expected: 12, got: %d\n", chunkLen)) |
115 |
| - return |
116 |
| - } |
117 |
| - |
118 |
| - rp.buffer = sdes_1_wrong |
119 |
| - offset = 4 |
120 |
| - // SDES chunk starts ofter first header word |
121 |
| - sdesChunk = rp.toSdesChunk(offset, cnt-4) |
122 |
| - |
123 |
| - // Get length of chunk - must fail |
124 |
| - chunkLen, ok := sdesChunk.chunkLen() |
125 |
| - if ok { |
126 |
| - t.Errorf("Chunk length error handling failed, expected: 0, false; got: %d, %v\n", chunkLen, ok) |
127 |
| - return |
128 |
| - } |
129 |
| - |
130 |
| - result = true |
131 |
| - return |
132 |
| -} |
133 |
| - |
134 |
| -func rtcpPacketBasic(t *testing.T) { |
135 |
| - sdesCheck(t) |
136 |
| -} |
137 |
| - |
138 |
| -func TestRtcpPacket(t *testing.T) { |
139 |
| - parseFlags() |
140 |
| - rtcpPacketBasic(t) |
141 |
| -} |
| 1 | +// Copyright (C) 2011 Werner Dittmann |
| 2 | +// |
| 3 | +// This program is free software: you can redistribute it and/or modify |
| 4 | +// it under the terms of the GNU General Public License as published by |
| 5 | +// the Free Software Foundation, either version 3 of the License, or |
| 6 | +// (at your option) any later version. |
| 7 | +// |
| 8 | +// This program is distributed in the hope that it will be useful, |
| 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +// GNU General Public License for more details. |
| 12 | +// |
| 13 | +// You should have received a copy of the GNU General Public License |
| 14 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | +// |
| 16 | +// Authors: Werner Dittmann <[email protected]> |
| 17 | +// |
| 18 | + |
| 19 | +package rtp |
| 20 | + |
| 21 | +import ( |
| 22 | + "fmt" |
| 23 | + // "net" |
| 24 | + "testing" |
| 25 | +) |
| 26 | + |
| 27 | +// V=2, P=0, chunks=2; PT=SDES; length=5 32bit words (24 bytes) |
| 28 | +var sdes_1 = []byte{0x81, 202, 0x00, 0x05, |
| 29 | + 0x01, 0x02, 0x03, 0x04, // SSRC 0x01020304 |
| 30 | + 0x01, 0x01, 0x02, // CNAME, len=1, content=2 |
| 31 | + 0x00, // END (chunk length: 8) |
| 32 | + 0x05, 0x06, 0x07, 0x08, // SSRC 0x05060707 |
| 33 | + 0x01, 0x03, 0x05, 0x06, 0x07, // CNAME, len=3, content=5,6,7 |
| 34 | + 0x00, 0x00, 0x00} // END plus 2 padding (chunk length: 12) |
| 35 | +// V=2, P=0, chunks=2; PT=SDES; length=8 32bit words (36 bytes) |
| 36 | +var sdes_2 = []byte{0x81, 202, 0x00, 0x08, |
| 37 | + // first chunk, two items: CNAME, NAME, END) |
| 38 | + 0x01, 0x02, 0x03, 0x04, // SSRC 0x01020304 |
| 39 | + 0x01, 0x01, 0x02, // CNAME, len=1, content=2 (item length: 3) |
| 40 | + 0x02, 0x07, // NAME, len=7 |
| 41 | + 0x05, 0x06, 0x07, 0x07, 0x06, 0x05, 0x04, // content 5,6,7,7,6,5,4 (item length 9) |
| 42 | + 0x00, 0x00, 0x00, 0x00, // END plus 3 padding (chunk length: 20) |
| 43 | + // second chunk, one item (CNAME, END) |
| 44 | + 0x05, 0x06, 0x07, 0x08, // SSRC 0x05060707 |
| 45 | + 0x01, 0x03, 0x05, 0x06, 0x07, // CNAME, len=3, content=5,6,7 |
| 46 | + 0x00, 0x00, 0x00} // END plus 2 padding (chunk length: 12) |
| 47 | + |
| 48 | +// V=2, P=0, chunks=2; PT=SDES; length=5 32bit words (24 bytes) |
| 49 | +var sdes_1_wrong = []byte{0x81, 202, 0x00, 0x05, |
| 50 | + 0x01, 0x02, 0x03, 0x04, // SSRC 0x01020304 |
| 51 | + 0x01, 0x03, 0x02, // CNAME, len=3 (wrong, should be 1), content=2 |
| 52 | + 0x00, // END (chunk length: 8) |
| 53 | + 0x05, 0x06, 0x07, 0x08, // SSRC 0x05060707 |
| 54 | + 0x01, 0x03, 0x05, 0x06, 0x07, // CNAME, len=3, content=5,6,7 |
| 55 | + 0x00, 0x00, 0x00} // END plus 2 padding (chunk length: 12) |
| 56 | + |
| 57 | +func sdesCheck(t *testing.T) (result bool) { |
| 58 | + result = false |
| 59 | + |
| 60 | + rp := new(CtrlPacket) // allocate a new CTRL packet. |
| 61 | + rp.buffer = sdes_1 |
| 62 | + |
| 63 | + cnt := int((rp.Length(0) + 1) * 4) // SDES Length incl. header word |
| 64 | + if cnt != 24 { |
| 65 | + t.Error(fmt.Sprintf("Basic first SDES length check failed. Expected: 24, got: %d\n", cnt)) |
| 66 | + return |
| 67 | + } |
| 68 | + offset := 4 |
| 69 | + // first SDES chunk starts ofter first header word |
| 70 | + sdesChunk := rp.toSdesChunk(offset, cnt-4) |
| 71 | + |
| 72 | + // Get length of first chunk - must be 8 |
| 73 | + chunkLen, _ := sdesChunk.chunkLen() |
| 74 | + if chunkLen != 8 { |
| 75 | + t.Error(fmt.Sprintf("Basic first SDES chunk length check failed. Expected: 8, got: %d\n", chunkLen)) |
| 76 | + return |
| 77 | + } |
| 78 | + offset += chunkLen |
| 79 | + cnt -= chunkLen |
| 80 | + // second SDES chunk starts ofter first chunk :-) |
| 81 | + sdesChunk = rp.toSdesChunk(offset, cnt-4) |
| 82 | + |
| 83 | + // Get length of second chunk - must be 12 |
| 84 | + chunkLen, _ = sdesChunk.chunkLen() |
| 85 | + if chunkLen != 12 { |
| 86 | + t.Error(fmt.Sprintf("Basic first SDES chunk length check failed. Expected: 12, got: %d\n", chunkLen)) |
| 87 | + return |
| 88 | + } |
| 89 | + |
| 90 | + rp.buffer = sdes_2 |
| 91 | + cnt = int((rp.Length(0) + 1) * 4) // SDES Length incl. header word |
| 92 | + if cnt != 36 { |
| 93 | + t.Error(fmt.Sprintf("Basic second SDES length check failed. Expected: 36, got: %d\n", cnt)) |
| 94 | + return |
| 95 | + } |
| 96 | + offset = 4 |
| 97 | + // first SDES chunk starts ofter first header word |
| 98 | + sdesChunk = rp.toSdesChunk(offset, cnt-4) |
| 99 | + |
| 100 | + // Get length of first chunk - must be 20 |
| 101 | + chunkLen, _ = sdesChunk.chunkLen() |
| 102 | + if chunkLen != 20 { |
| 103 | + t.Error(fmt.Sprintf("Basic second SDES chunk length check failed. Expected: 20, got: %d\n", chunkLen)) |
| 104 | + return |
| 105 | + } |
| 106 | + offset += chunkLen |
| 107 | + cnt -= chunkLen |
| 108 | + // second SDES chunk starts ofter first chunk :-) |
| 109 | + sdesChunk = rp.toSdesChunk(offset, cnt-4) |
| 110 | + |
| 111 | + // Get length of second chunk - must be 12 |
| 112 | + chunkLen, _ = sdesChunk.chunkLen() |
| 113 | + if chunkLen != 12 { |
| 114 | + t.Error(fmt.Sprintf("Basic second SDES chunk length check failed. Expected: 12, got: %d\n", chunkLen)) |
| 115 | + return |
| 116 | + } |
| 117 | + |
| 118 | + rp.buffer = sdes_1_wrong |
| 119 | + offset = 4 |
| 120 | + // SDES chunk starts ofter first header word |
| 121 | + sdesChunk = rp.toSdesChunk(offset, cnt-4) |
| 122 | + |
| 123 | + // Get length of chunk - must fail |
| 124 | + chunkLen, ok := sdesChunk.chunkLen() |
| 125 | + if ok { |
| 126 | + t.Errorf("Chunk length error handling failed, expected: 0, false; got: %d, %v\n", chunkLen, ok) |
| 127 | + return |
| 128 | + } |
| 129 | + |
| 130 | + result = true |
| 131 | + return |
| 132 | +} |
| 133 | + |
| 134 | +func rtcpPacketBasic(t *testing.T) { |
| 135 | + sdesCheck(t) |
| 136 | +} |
| 137 | + |
| 138 | +func TestRtcpPacket(t *testing.T) { |
| 139 | + parseFlags() |
| 140 | + rtcpPacketBasic(t) |
| 141 | +} |
0 commit comments