@@ -520,4 +520,95 @@ def test_sctp_parser_selective_ack():
520
520
assert number_inbound_streams_fd .position == 0
521
521
assert number_inbound_streams_fd .value == Buffer (content = b'\x00 \x00 ' , length = 16 )
522
522
523
-
523
+
524
+ def test_sctp_parser_parse_heartbeat ():
525
+ """test: SCTP header parser parses SCTP Header with HEARTBEAT chunk
526
+
527
+ The packet is made of a SCTP header with the following fields:
528
+ - id='Source Port Number' length=16 position=0 value=b'\x0b \x59 '
529
+ - id='Destination Port Number' length=16 position=0 value=b'\x0b \x59 '
530
+ - id='Verification Tag' length=32 position=0 value=b'\x00 \x00 \x0e \x50 '
531
+ - id='Checksum' length=32 position=0 value=b'\x53 \xc3 \x05 \x5f '
532
+ - id='Chunk Type' length=8 position=0 value=b'\x04 '
533
+ - id='Chunk Flags' length=8 position=0 value=b'\x00 '
534
+ - id='Chunk Length' length=16 position=0 value=b'\x00 \x18 '
535
+ - id='Parameter Type' length=16 position=0 value=b'\x00 \x01 '
536
+ - id='Parameter Length' length=16 position=0 value=b'\x00 \x14 '
537
+ - id='Parameter Value' length=16 position=0 value=b'\x40 \xe4 \x4b \x92 \x0a \x1c \x06 \x2c \x1b \x66 \xaf \x7e \x00 \x00 \x00 \x00 '
538
+
539
+ """
540
+
541
+ valid_sctp_packet :bytes = bytes (b'\x0b \x59 \x0b \x59 \x00 \x00 \x0e \x50 \x53 \xc3 \x05 \x5f \x04 \x00 \x00 \x18 '
542
+ b'\x00 \x01 \x00 \x14 \x40 \xe4 \x4b \x92 \x0a \x1c \x06 \x2c \x1b \x66 \xaf \x7e '
543
+ b'\x00 \x00 \x00 \x00 '
544
+
545
+ )
546
+
547
+ valid_sctp_packet_buffer : Buffer = Buffer (content = valid_sctp_packet , length = len (valid_sctp_packet )* 8 )
548
+ parser :SCTPParser = SCTPParser ()
549
+
550
+ sctp_header_descriptor : HeaderDescriptor = parser .parse (buffer = valid_sctp_packet_buffer )
551
+
552
+ # test sctp_header_descriptor type
553
+ assert isinstance (sctp_header_descriptor , HeaderDescriptor )
554
+
555
+ # test for sctp_header_descriptor.fields length
556
+ assert len (sctp_header_descriptor .fields ) == 10
557
+
558
+ # test for sctp_header_descriptor.fields types
559
+ for field in sctp_header_descriptor .fields :
560
+ assert isinstance (field , FieldDescriptor )
561
+
562
+ # assert field descriptors match SCTP header content
563
+ # - common header fields
564
+ source_port_fd :FieldDescriptor = sctp_header_descriptor .fields [0 ]
565
+ assert source_port_fd .id == SCTPFields .SOURCE_PORT
566
+ assert source_port_fd .position == 0
567
+ assert source_port_fd .value == Buffer (content = b'\x0b \x59 ' , length = 16 )
568
+
569
+ destination_port_fd :FieldDescriptor = sctp_header_descriptor .fields [1 ]
570
+ assert destination_port_fd .id == SCTPFields .DESTINATION_PORT
571
+ assert destination_port_fd .position == 0
572
+ assert destination_port_fd .value == Buffer (content = b'\x0b \x59 ' , length = 16 )
573
+
574
+ verification_tag_fd :FieldDescriptor = sctp_header_descriptor .fields [2 ]
575
+ assert verification_tag_fd .id == SCTPFields .VERIFICATION_TAG
576
+ assert verification_tag_fd .position == 0
577
+ assert verification_tag_fd .value == Buffer (content = b'\x00 \x00 \x0e \x50 ' , length = 32 )
578
+
579
+ checksum_fd :FieldDescriptor = sctp_header_descriptor .fields [3 ]
580
+ assert checksum_fd .id == SCTPFields .CHECKSUM
581
+ assert checksum_fd .position == 0
582
+ assert checksum_fd .value == Buffer (content = b'\x53 \xc3 \x05 \x5f ' , length = 32 )
583
+
584
+
585
+ # - chunk common header fields
586
+ chunk_type_fd :FieldDescriptor = sctp_header_descriptor .fields [4 ]
587
+ assert chunk_type_fd .id == SCTPFields .CHUNK_TYPE
588
+ assert chunk_type_fd .position == 0
589
+ assert chunk_type_fd .value == Buffer (content = b'\x04 ' , length = 8 )
590
+
591
+ chunk_flags_fd :FieldDescriptor = sctp_header_descriptor .fields [5 ]
592
+ assert chunk_flags_fd .id == SCTPFields .CHUNK_FLAGS
593
+ assert chunk_flags_fd .position == 0
594
+ assert chunk_flags_fd .value == Buffer (content = b'\x00 ' , length = 8 )
595
+
596
+ chunk_length_fd :FieldDescriptor = sctp_header_descriptor .fields [6 ]
597
+ assert chunk_length_fd .id == SCTPFields .CHUNK_LENGTH
598
+ assert chunk_length_fd .position == 0
599
+ assert chunk_length_fd .value == Buffer (content = b'\x00 \x18 ' , length = 16 )
600
+
601
+ parameter_type_fd :FieldDescriptor = sctp_header_descriptor .fields [7 ]
602
+ assert parameter_type_fd .id == SCTPFields .PARAMETER_TYPE
603
+ assert parameter_type_fd .position == 0
604
+ assert parameter_type_fd .value == Buffer (content = b'\x00 \x01 ' , length = 16 )
605
+
606
+ parameter_length_fd :FieldDescriptor = sctp_header_descriptor .fields [8 ]
607
+ assert parameter_length_fd .id == SCTPFields .PARAMETER_LENGTH
608
+ assert parameter_length_fd .position == 0
609
+ assert parameter_length_fd .value == Buffer (content = b'\x00 \x14 ' , length = 16 )
610
+
611
+ parameter_value_fd :FieldDescriptor = sctp_header_descriptor .fields [9 ]
612
+ assert parameter_value_fd .id == SCTPFields .PARAMETER_VALUE
613
+ assert parameter_value_fd .position == 0
614
+ assert parameter_value_fd .value == Buffer (content = b'\x40 \xe4 \x4b \x92 \x0a \x1c \x06 \x2c \x1b \x66 \xaf \x7e \x00 \x00 \x00 \x00 ' , length = 128 )
0 commit comments