@@ -12,7 +12,7 @@ def test_sctp_parser_import():
12
12
assert ( isinstance (parser , SCTPParser ) )
13
13
14
14
def test_sctp_parser_parse_data ():
15
- """test: SCTP header parser parses SCTP Header
15
+ """test: SCTP header parser parses SCTP Header with DATA chunk
16
16
17
17
The packet is made of a SCTP header with the following fields:
18
18
- id='Source Port Number' length=16 position=0 value=b'\x25 \x0f '
@@ -133,7 +133,7 @@ def test_sctp_parser_parse_data():
133
133
134
134
135
135
def test_sctp_parser_parse_init ():
136
- """test: SCTP header parser parses SCTP Header
136
+ """test: SCTP header parser parses SCTP Header with INIT chunk
137
137
138
138
The packet is made of a SCTP header with the following fields:
139
139
- id='Source Port Number' length=16 position=0 value=b'\x00 \x07 '
@@ -268,4 +268,161 @@ def test_sctp_parser_parse_init():
268
268
parameter_padding_fd :FieldDescriptor = sctp_header_descriptor .fields [17 ]
269
269
assert parameter_padding_fd .id == SCTPFields .PARAMETER_PADDING
270
270
assert parameter_padding_fd .position == 0
271
- assert parameter_padding_fd .value == Buffer (content = b'\x00 \x00 ' , length = 16 )
271
+ assert parameter_padding_fd .value == Buffer (content = b'\x00 \x00 ' , length = 16 )
272
+
273
+
274
+
275
+
276
+
277
+ def test_sctp_parser_parse_init_ack ():
278
+ """test: SCTP header parser parses SCTP Header with INIT_ACK chunk
279
+
280
+ The packet is made of a SCTP header with the following fields:
281
+ - id='Source Port Number' length=16 position=0 value=b'\x00 \x07 '
282
+ - id='Destination Port Number' length=16 position=0 value=b'\x00 \x07 '
283
+ - id='Verification Tag' length=32 position=0 value=b'\x43 \x23 \x25 \x44 '
284
+ - id='Checksum' length=32 position=0 value=b'\xc9 \x01 \x85 \x24 '
285
+ - id='Chunk Type' length=8 position=0 value=b'\x02 '
286
+ - id='Chunk Flags' length=8 position=0 value=b'\x00 '
287
+ - id='Chunk Length' length=16 position=0 value=b'\x00 \x80 '
288
+ - id='Initiate Tag length=32 position=0 value=b'\x00 \x00 \x0e \xb0 '
289
+ - id='Advertised Receiver Window Credit' length=32 position=0 value=b'\x00 \x00 \x10 \x00 '
290
+ - id='Number of Outbound Streams' length=16 position=0 value=b'\x00 \x11 '
291
+ - id='Number of Inbound Streams' length=16 position=0 value=b'\x00 \x11 '
292
+ - id='Initial TSN length=32 position=0 value=b'\x00 \x00 \x36 \x14 '
293
+ - id='Parameter Type' length=16 position=0 value=b'\x00 \x07 '
294
+ - id='Parameter Length' length=16 position=0 value=b'\x00 \x68 '
295
+ - id='Parameter Value' length=800 position=0 value=b'\x00 \x00 \x0e \xb0 \x00 \x00 \x10 \x00 \x00 \x11 \x00 \x11 '
296
+ b'\x00 \x00 \x36 \x14 \x43 \x23 \x25 \x44 \x00 \x00 \xff \xff \x00 \x11 \x00 \x11 '
297
+ b'\x5c \xfe \x37 \x9f \x07 \x00 \x07 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 '
298
+ b'\xa2 \x85 \xb1 \x3f \x10 \x27 \x00 \x00 \x17 \xcd \x8f \x1c \x11 \x76 \x9b \x04 '
299
+ b'\x55 \xc0 \xd0 \xf2 \x2c \x3e \x7c \x35 \x00 \x01 \x00 \x01 \x00 \x00 \x00 \x00 '
300
+ b'\x00 \x00 \x00 \x00 \x00 \x05 \x00 \x08 \xc0 \xa8 \xaa \x38 \x00 \x05 \x00 \x08 '
301
+ b'\xc0 \xa8 \xaa \x08 \xc0 \x00 \x00 \x04 '
302
+ - id='Parameter Type' length=16 position=0 value=b'\xc0 \x00 '
303
+ - id='Parameter Length' length=16 position=0 value=b'\x00 \x04 '
304
+
305
+ """
306
+
307
+ valid_sctp_packet :bytes = bytes (b'\x00 \x07 \x00 \x07 \x43 \x23 \x25 \x44 \xc9 \x01 \x85 \x24 \x02 \x00 \x00 \x80 '
308
+ b'\x00 \x00 \x0e \xb0 \x00 \x00 \x10 \x00 \x00 \x11 \x00 \x11 \x00 \x00 \x36 \x14 '
309
+ b'\x00 \x07 \x00 \x68 \x00 \x00 \x0e \xb0 \x00 \x00 \x10 \x00 \x00 \x11 \x00 \x11 '
310
+ b'\x00 \x00 \x36 \x14 \x43 \x23 \x25 \x44 \x00 \x00 \xff \xff \x00 \x11 \x00 \x11 '
311
+ b'\x5c \xfe \x37 \x9f \x07 \x00 \x07 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 '
312
+ b'\xa2 \x85 \xb1 \x3f \x10 \x27 \x00 \x00 \x17 \xcd \x8f \x1c \x11 \x76 \x9b \x04 '
313
+ b'\x55 \xc0 \xd0 \xf2 \x2c \x3e \x7c \x35 \x00 \x01 \x00 \x01 \x00 \x00 \x00 \x00 '
314
+ b'\x00 \x00 \x00 \x00 \x00 \x05 \x00 \x08 \xc0 \xa8 \xaa \x38 \x00 \x05 \x00 \x08 '
315
+ b'\xc0 \xa8 \xaa \x08 \xc0 \x00 \x00 \x04 \xc0 \x00 \x00 \x04 '
316
+ )
317
+ valid_sctp_packet_buffer : Buffer = Buffer (content = valid_sctp_packet , length = len (valid_sctp_packet )* 8 )
318
+ parser :SCTPParser = SCTPParser ()
319
+
320
+ sctp_header_descriptor : HeaderDescriptor = parser .parse (buffer = valid_sctp_packet_buffer )
321
+
322
+ # test sctp_header_descriptor type
323
+ assert isinstance (sctp_header_descriptor , HeaderDescriptor )
324
+
325
+ # test for sctp_header_descriptor.fields length
326
+ assert len (sctp_header_descriptor .fields ) == 17
327
+
328
+ # test for sctp_header_descriptor.fields types
329
+ for field in sctp_header_descriptor .fields :
330
+ assert isinstance (field , FieldDescriptor )
331
+
332
+ # assert field descriptors match SCTP header content
333
+ # - common header fields
334
+ source_port_fd :FieldDescriptor = sctp_header_descriptor .fields [0 ]
335
+ assert source_port_fd .id == SCTPFields .SOURCE_PORT
336
+ assert source_port_fd .position == 0
337
+ assert source_port_fd .value == Buffer (content = b'\x00 \x07 ' , length = 16 )
338
+
339
+ destination_port_fd :FieldDescriptor = sctp_header_descriptor .fields [1 ]
340
+ assert destination_port_fd .id == SCTPFields .DESTINATION_PORT
341
+ assert destination_port_fd .position == 0
342
+ assert destination_port_fd .value == Buffer (content = b'\x00 \x07 ' , length = 16 )
343
+
344
+ verification_tag_fd :FieldDescriptor = sctp_header_descriptor .fields [2 ]
345
+ assert verification_tag_fd .id == SCTPFields .VERIFICATION_TAG
346
+ assert verification_tag_fd .position == 0
347
+ assert verification_tag_fd .value == Buffer (content = b'\x43 \x23 \x25 \x44 ' , length = 32 )
348
+
349
+ checksum_fd :FieldDescriptor = sctp_header_descriptor .fields [3 ]
350
+ assert checksum_fd .id == SCTPFields .CHECKSUM
351
+ assert checksum_fd .position == 0
352
+ assert checksum_fd .value == Buffer (content = b'\xc9 \x01 \x85 \x24 ' , length = 32 )
353
+
354
+
355
+ # - chunk common header fields
356
+ chunk_type_fd :FieldDescriptor = sctp_header_descriptor .fields [4 ]
357
+ assert chunk_type_fd .id == SCTPFields .CHUNK_TYPE
358
+ assert chunk_type_fd .position == 0
359
+ assert chunk_type_fd .value == Buffer (content = b'\x02 ' , length = 8 )
360
+
361
+ chunk_flags_fd :FieldDescriptor = sctp_header_descriptor .fields [5 ]
362
+ assert chunk_flags_fd .id == SCTPFields .CHUNK_FLAGS
363
+ assert chunk_flags_fd .position == 0
364
+ assert chunk_flags_fd .value == Buffer (content = b'\x00 ' , length = 8 )
365
+
366
+ chunk_length_fd :FieldDescriptor = sctp_header_descriptor .fields [6 ]
367
+ assert chunk_length_fd .id == SCTPFields .CHUNK_LENGTH
368
+ assert chunk_length_fd .position == 0
369
+ assert chunk_length_fd .value == Buffer (content = b'\x00 \x80 ' , length = 16 )
370
+
371
+ initiate_tag_fd :FieldDescriptor = sctp_header_descriptor .fields [7 ]
372
+ assert initiate_tag_fd .id == SCTPFields .CHUNK_INIT_ACK_INITIATE_TAG
373
+ assert initiate_tag_fd .position == 0
374
+ assert initiate_tag_fd .value == Buffer (content = b'\x00 \x00 \x0e \xb0 ' , length = 32 )
375
+
376
+ advertised_receiver_window_credit_fd :FieldDescriptor = sctp_header_descriptor .fields [8 ]
377
+ assert advertised_receiver_window_credit_fd .id == SCTPFields .CHUNK_INIT_ACK_ADVERTISED_RECEIVER_WINDOW_CREDIT
378
+ assert advertised_receiver_window_credit_fd .position == 0
379
+ assert advertised_receiver_window_credit_fd .value == Buffer (content = b'\x00 \x00 \x10 \x00 ' , length = 32 )
380
+
381
+ number_outbound_streams_fd :FieldDescriptor = sctp_header_descriptor .fields [9 ]
382
+ assert number_outbound_streams_fd .id == SCTPFields .CHUNK_INIT_ACK_NUMBER_OF_OUTBOUND_STREAMS
383
+ assert number_outbound_streams_fd .position == 0
384
+ assert number_outbound_streams_fd .value == Buffer (content = b'\x00 \x11 ' , length = 16 )
385
+
386
+ number_inbound_streams_fd :FieldDescriptor = sctp_header_descriptor .fields [10 ]
387
+ assert number_inbound_streams_fd .id == SCTPFields .CHUNK_INIT_ACK_NUMBER_OF_INBOUND_STREAMS
388
+ assert number_inbound_streams_fd .position == 0
389
+ assert number_inbound_streams_fd .value == Buffer (content = b'\x00 \x11 ' , length = 16 )
390
+
391
+ initial_tsn_fd :FieldDescriptor = sctp_header_descriptor .fields [11 ]
392
+ assert initial_tsn_fd .id == SCTPFields .CHUNK_INIT_ACK_INITIAL_TSN
393
+ assert initial_tsn_fd .position == 0
394
+ assert initial_tsn_fd .value == Buffer (content = b'\x00 \x00 \x36 \x14 ' , length = 32 )
395
+
396
+ parameter_type_fd :FieldDescriptor = sctp_header_descriptor .fields [12 ]
397
+ assert parameter_type_fd .id == SCTPFields .PARAMETER_TYPE
398
+ assert parameter_type_fd .position == 0
399
+ assert parameter_type_fd .value == Buffer (content = b'\x00 \x07 ' , length = 16 )
400
+
401
+ parameter_length_fd :FieldDescriptor = sctp_header_descriptor .fields [13 ]
402
+ assert parameter_length_fd .id == SCTPFields .PARAMETER_LENGTH
403
+ assert parameter_length_fd .position == 0
404
+ assert parameter_length_fd .value == Buffer (content = b'\x00 \x68 ' , length = 16 )
405
+
406
+ parameter_value_fd :FieldDescriptor = sctp_header_descriptor .fields [14 ]
407
+ assert parameter_value_fd .id == SCTPFields .PARAMETER_VALUE
408
+ assert parameter_value_fd .position == 0
409
+ assert parameter_value_fd .value == Buffer (content = b'\x00 \x00 \x0e \xb0 \x00 \x00 \x10 \x00 \x00 \x11 \x00 \x11 '
410
+ b'\x00 \x00 \x36 \x14 \x43 \x23 \x25 \x44 \x00 \x00 \xff \xff \x00 \x11 \x00 \x11 '
411
+ b'\x5c \xfe \x37 \x9f \x07 \x00 \x07 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 '
412
+ b'\xa2 \x85 \xb1 \x3f \x10 \x27 \x00 \x00 \x17 \xcd \x8f \x1c \x11 \x76 \x9b \x04 '
413
+ b'\x55 \xc0 \xd0 \xf2 \x2c \x3e \x7c \x35 \x00 \x01 \x00 \x01 \x00 \x00 \x00 \x00 '
414
+ b'\x00 \x00 \x00 \x00 \x00 \x05 \x00 \x08 \xc0 \xa8 \xaa \x38 \x00 \x05 \x00 \x08 '
415
+ b'\xc0 \xa8 \xaa \x08 \xc0 \x00 \x00 \x04 ' ,
416
+ length = 800 )
417
+
418
+ parameter_type_fd :FieldDescriptor = sctp_header_descriptor .fields [15 ]
419
+ assert parameter_type_fd .id == SCTPFields .PARAMETER_TYPE
420
+ assert parameter_type_fd .position == 0
421
+ assert parameter_type_fd .value == Buffer (content = b'\xc0 \x00 ' , length = 16 )
422
+
423
+ parameter_length_fd :FieldDescriptor = sctp_header_descriptor .fields [16 ]
424
+ assert parameter_length_fd .id == SCTPFields .PARAMETER_LENGTH
425
+ assert parameter_length_fd .position == 0
426
+ assert parameter_length_fd .value == Buffer (content = b'\x00 \x04 ' , length = 16 )
427
+
428
+
0 commit comments