@@ -11,7 +11,7 @@ def test_sctp_parser_import():
11
11
parser = SCTPParser ()
12
12
assert ( isinstance (parser , SCTPParser ) )
13
13
14
- def test_sctp_parser_parse ():
14
+ def test_sctp_parser_parse_data ():
15
15
"""test: SCTP header parser parses SCTP Header
16
16
17
17
The packet is made of a SCTP header with the following fields:
@@ -129,4 +129,143 @@ def test_sctp_parser_parse():
129
129
chunk_padding_fd :FieldDescriptor = sctp_header_descriptor .fields [12 ]
130
130
assert chunk_padding_fd .id == SCTPFields .CHUNK_PADDING
131
131
assert chunk_padding_fd .position == 0
132
- assert chunk_padding_fd .value == Buffer (content = b'\x00 \x00 \x00 ' , length = 24 )
132
+ assert chunk_padding_fd .value == Buffer (content = b'\x00 \x00 \x00 ' , length = 24 )
133
+
134
+
135
+ def test_sctp_parser_parse_init ():
136
+ """test: SCTP header parser parses SCTP Header
137
+
138
+ The packet is made of a SCTP header with the following fields:
139
+ - id='Source Port Number' length=16 position=0 value=b'\x00 \x07 '
140
+ - id='Destination Port Number' length=16 position=0 value=b'\x00 \x07 '
141
+ - id='Verification Tag' length=32 position=0 value=b'\x00 \x00 \x00 \x00 '
142
+ - id='Checksum' length=32 position=0 value=b'\x37 \x61 \xa7 \x46 '
143
+ - id='Chunk Type' length=8 position=0 value=b'\x01 '
144
+ - id='Chunk Flags' length=8 position=0 value=b'\x00 '
145
+ - id='Chunk Length' length=16 position=0 value=b'\x00 \x20 '
146
+ - id='Initiate Tag length=32 position=0 value=b'\x43 \x23 \x25 \x44 '
147
+ - id='Advertised Receiver Window Credit' length=32 position=0 value=b'\x00 \x00 \xff \xff '
148
+ - id='Number of Outbound Streams' length=16 position=0 value=b'\x00 \x11 '
149
+ - id='Number of Inbound Streams' length=16 position=0 value=b'\x00 \x11 '
150
+ - id='Initial TSN length=32 position=0 value=b'\x5c \xfe \x37 \x9f '
151
+ - id='Parameter Type' length=16 position=0 value=b'\xc0 \x00 '
152
+ - id='Parameter Length' length=16 position=0 value=b'\x00 \x04 '
153
+ - id='Parameter Type' length=16 position=0 value=b'\x00 \x0c '
154
+ - id='Parameter Length' length=16 position=0 value=b'\x00 \x06 '
155
+ - id='Parameter Value' length=16 position=0 value=b'\x00 \x05 '
156
+ - id='Parameter Padding' length=16 position=0 value=b'\x00 \x00 '
157
+
158
+ """
159
+
160
+ valid_sctp_packet :bytes = bytes (b'\x00 \x07 \x00 \x07 \x00 \x00 \x00 \x00 \x37 \x61 \xa7 \x46 \x01 \x00 \x00 \x20 '
161
+ b'\x43 \x23 \x25 \x44 \x00 \x00 \xff \xff \x00 \x11 \x00 \x11 \x5c \xfe \x37 \x9f '
162
+ b'\xc0 \x00 \x00 \x04 \x00 \x0c \x00 \x06 \x00 \x05 \x00 \x00 '
163
+ )
164
+ valid_sctp_packet_buffer : Buffer = Buffer (content = valid_sctp_packet , length = len (valid_sctp_packet )* 8 )
165
+ parser :SCTPParser = SCTPParser ()
166
+
167
+ sctp_header_descriptor : HeaderDescriptor = parser .parse (buffer = valid_sctp_packet_buffer )
168
+
169
+ # test sctp_header_descriptor type
170
+ assert isinstance (sctp_header_descriptor , HeaderDescriptor )
171
+
172
+ # test for sctp_header_descriptor.fields length
173
+ assert len (sctp_header_descriptor .fields ) == 18
174
+
175
+ # test for sctp_header_descriptor.fields types
176
+ for field in sctp_header_descriptor .fields :
177
+ assert isinstance (field , FieldDescriptor )
178
+
179
+ # assert field descriptors match SCTP header content
180
+ # - common header fields
181
+ source_port_fd :FieldDescriptor = sctp_header_descriptor .fields [0 ]
182
+ assert source_port_fd .id == SCTPFields .SOURCE_PORT
183
+ assert source_port_fd .position == 0
184
+ assert source_port_fd .value == Buffer (content = b'\x00 \x07 ' , length = 16 )
185
+
186
+ destination_port_fd :FieldDescriptor = sctp_header_descriptor .fields [1 ]
187
+ assert destination_port_fd .id == SCTPFields .DESTINATION_PORT
188
+ assert destination_port_fd .position == 0
189
+ assert destination_port_fd .value == Buffer (content = b'\x00 \x07 ' , length = 16 )
190
+
191
+ verification_tag_fd :FieldDescriptor = sctp_header_descriptor .fields [2 ]
192
+ assert verification_tag_fd .id == SCTPFields .VERIFICATION_TAG
193
+ assert verification_tag_fd .position == 0
194
+ assert verification_tag_fd .value == Buffer (content = b'\x00 \x00 \x00 \x00 ' , length = 32 )
195
+
196
+ checksum_fd :FieldDescriptor = sctp_header_descriptor .fields [3 ]
197
+ assert checksum_fd .id == SCTPFields .CHECKSUM
198
+ assert checksum_fd .position == 0
199
+ assert checksum_fd .value == Buffer (content = b'\x37 \x61 \xa7 \x46 ' , length = 32 )
200
+
201
+
202
+ # - chunk common header fields
203
+ chunk_type_fd :FieldDescriptor = sctp_header_descriptor .fields [4 ]
204
+ assert chunk_type_fd .id == SCTPFields .CHUNK_TYPE
205
+ assert chunk_type_fd .position == 0
206
+ assert chunk_type_fd .value == Buffer (content = b'\x01 ' , length = 8 )
207
+
208
+ chunk_flags_fd :FieldDescriptor = sctp_header_descriptor .fields [5 ]
209
+ assert chunk_flags_fd .id == SCTPFields .CHUNK_FLAGS
210
+ assert chunk_flags_fd .position == 0
211
+ assert chunk_flags_fd .value == Buffer (content = b'\x00 ' , length = 8 )
212
+
213
+ chunk_length_fd :FieldDescriptor = sctp_header_descriptor .fields [6 ]
214
+ assert chunk_length_fd .id == SCTPFields .CHUNK_LENGTH
215
+ assert chunk_length_fd .position == 0
216
+ assert chunk_length_fd .value == Buffer (content = b'\x00 \x20 ' , length = 16 )
217
+
218
+ initiate_tag_fd :FieldDescriptor = sctp_header_descriptor .fields [7 ]
219
+ assert initiate_tag_fd .id == SCTPFields .CHUNK_INIT_INITIATE_TAG
220
+ assert initiate_tag_fd .position == 0
221
+ assert initiate_tag_fd .value == Buffer (content = b'\x43 \x23 \x25 \x44 ' , length = 32 )
222
+
223
+ advertised_receiver_window_credit_fd :FieldDescriptor = sctp_header_descriptor .fields [8 ]
224
+ assert advertised_receiver_window_credit_fd .id == SCTPFields .CHUNK_INIT_ADVERTISED_RECEIVER_WINDOW_CREDIT
225
+ assert advertised_receiver_window_credit_fd .position == 0
226
+ assert advertised_receiver_window_credit_fd .value == Buffer (content = b'\x00 \x00 \xff \xff ' , length = 32 )
227
+
228
+ number_outbound_streams_fd :FieldDescriptor = sctp_header_descriptor .fields [9 ]
229
+ assert number_outbound_streams_fd .id == SCTPFields .CHUNK_INIT_NUMBER_OF_OUTBOUND_STREAMS
230
+ assert number_outbound_streams_fd .position == 0
231
+ assert number_outbound_streams_fd .value == Buffer (content = b'\x00 \x11 ' , length = 16 )
232
+
233
+ number_inbound_streams_fd :FieldDescriptor = sctp_header_descriptor .fields [10 ]
234
+ assert number_inbound_streams_fd .id == SCTPFields .CHUNK_INIT_NUMBER_OF_INBOUND_STREAMS
235
+ assert number_inbound_streams_fd .position == 0
236
+ assert number_inbound_streams_fd .value == Buffer (content = b'\x00 \x11 ' , length = 16 )
237
+
238
+ initial_tsn_fd :FieldDescriptor = sctp_header_descriptor .fields [11 ]
239
+ assert initial_tsn_fd .id == SCTPFields .CHUNK_INIT_INITIAL_TSN
240
+ assert initial_tsn_fd .position == 0
241
+ assert initial_tsn_fd .value == Buffer (content = b'\x5c \xfe \x37 \x9f ' , length = 32 )
242
+
243
+ parameter_type_fd :FieldDescriptor = sctp_header_descriptor .fields [12 ]
244
+ assert parameter_type_fd .id == SCTPFields .PARAMETER_TYPE
245
+ assert parameter_type_fd .position == 0
246
+ assert parameter_type_fd .value == Buffer (content = b'\xc0 \x00 ' , length = 16 )
247
+
248
+ parameter_length_fd :FieldDescriptor = sctp_header_descriptor .fields [13 ]
249
+ assert parameter_length_fd .id == SCTPFields .PARAMETER_LENGTH
250
+ assert parameter_length_fd .position == 0
251
+ assert parameter_length_fd .value == Buffer (content = b'\x00 \x04 ' , length = 16 )
252
+
253
+ parameter_type_fd :FieldDescriptor = sctp_header_descriptor .fields [14 ]
254
+ assert parameter_type_fd .id == SCTPFields .PARAMETER_TYPE
255
+ assert parameter_type_fd .position == 0
256
+ assert parameter_type_fd .value == Buffer (content = b'\x00 \x0c ' , length = 16 )
257
+
258
+ parameter_length_fd :FieldDescriptor = sctp_header_descriptor .fields [15 ]
259
+ assert parameter_length_fd .id == SCTPFields .PARAMETER_LENGTH
260
+ assert parameter_length_fd .position == 0
261
+ assert parameter_length_fd .value == Buffer (content = b'\x00 \x06 ' , length = 16 )
262
+
263
+ parameter_value_fd :FieldDescriptor = sctp_header_descriptor .fields [16 ]
264
+ assert parameter_value_fd .id == SCTPFields .PARAMETER_VALUE
265
+ assert parameter_value_fd .position == 0
266
+ assert parameter_value_fd .value == Buffer (content = b'\x00 \x05 ' , length = 16 )
267
+
268
+ parameter_padding_fd :FieldDescriptor = sctp_header_descriptor .fields [17 ]
269
+ assert parameter_padding_fd .id == SCTPFields .PARAMETER_PADDING
270
+ assert parameter_padding_fd .position == 0
271
+ assert parameter_padding_fd .value == Buffer (content = b'\x00 \x00 ' , length = 16 )
0 commit comments