<s> try : <EOL> from impacket import IP6_Address , IP6 , ImpactDecoder , ICMP6 <EOL> except : <EOL> pass <EOL> try : <EOL> import sys <EOL> sys . path . insert ( <NUM_LIT:0> , "<STR_LIT>" ) <EOL> import IP6_Address , IP6 , ImpactDecoder , ICMP6 <EOL> except : <EOL> pass <EOL> import unittest <EOL> class TestICMP6 ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . packet_list = self . generate_icmp6_constructed_packets ( ) <EOL> self . message_description_list = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> self . reference_data_list = [ <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> ] <EOL> def encapsulate_icmp6_packet_in_ip6_packet ( self , icmp6_packet ) : <EOL> ip6_packet = IP6 . IP6 ( ) <EOL> ip6_packet . set_traffic_class ( <NUM_LIT:0> ) <EOL> ip6_packet . set_flow_label ( <NUM_LIT:0> ) <EOL> ip6_packet . set_hop_limit ( <NUM_LIT:1> ) <EOL> ip6_packet . set_source_address ( "<STR_LIT>" ) <EOL> ip6_packet . set_destination_address ( "<STR_LIT>" ) <EOL> ip6_packet . contains ( icmp6_packet ) <EOL> ip6_packet . set_next_header ( ip6_packet . child ( ) . get_ip_protocol_number ( ) ) <EOL> ip6_packet . set_payload_length ( ip6_packet . child ( ) . get_size ( ) ) <EOL> icmp6_packet . calculate_checksum ( ) <EOL> return ip6_packet <EOL> def compare_icmp6_packet_with_reference_buffer ( self , icmp6_packet , reference_buffer , test_fail_message ) : <EOL> ip6_packet = self . encapsulate_icmp6_packet_in_ip6_packet ( icmp6_packet ) <EOL> icmp6_header_buffer = ip6_packet . child ( ) . get_bytes ( ) . tolist ( ) <EOL> icmp6_payload_buffer = icmp6_packet . child ( ) . get_bytes ( ) . tolist ( ) <EOL> generated_buffer = icmp6_header_buffer + icmp6_payload_buffer <EOL> self . assertEquals ( generated_buffer , reference_buffer , test_fail_message ) <EOL> def generate_icmp6_constructed_packets ( self ) : <EOL> packet_list = [ ] <EOL> arbitrary_data = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> echo_id = <NUM_LIT:1> <EOL> echo_sequence_number = <NUM_LIT:2> <EOL> icmp6_packet = ICMP6 . ICMP6 . Echo_Request ( echo_id , echo_sequence_number , arbitrary_data ) <EOL> packet_list . append ( icmp6_packet ) <EOL> icmp6_packet = ICMP6 . ICMP6 . Echo_Reply ( echo_id , echo_sequence_number , arbitrary_data ) <EOL> packet_list . append ( icmp6_packet ) <EOL> originating_packet_data = arbitrary_data <EOL> for code in range ( <NUM_LIT:0> , <NUM_LIT:3> ) : <EOL> problem_pointer = <NUM_LIT:2> <EOL> icmp6_packet = ICMP6 . ICMP6 . Parameter_Problem ( code , problem_pointer , originating_packet_data ) <EOL> packet_list . append ( icmp6_packet ) <EOL> for code in range ( <NUM_LIT:0> , <NUM_LIT:7> ) : <EOL> icmp6_packet = ICMP6 . ICMP6 . Destination_Unreachable ( code , originating_packet_data ) <EOL> packet_list . append ( icmp6_packet ) <EOL> for code in range ( <NUM_LIT:0> , <NUM_LIT:2> ) : <EOL> icmp6_packet = ICMP6 . ICMP6 . Time_Exceeded ( code , originating_packet_data ) <EOL> packet_list . append ( icmp6_packet ) <EOL> icmp6_packet = ICMP6 . ICMP6 . Packet_Too_Big ( <NUM_LIT> , originating_packet_data ) <EOL> packet_list . append ( icmp6_packet ) <EOL> return packet_list <EOL> def test_message_construction ( self ) : <EOL> for packet , reference , msg in zip ( self . packet_list , self . reference_data_list , self . message_description_list ) : <EOL> self . compare_icmp6_packet_with_reference_buffer ( packet , reference , "<STR_LIT>" + msg + "<STR_LIT>" ) <EOL> def test_message_decoding ( self ) : <EOL> d = ImpactDecoder . ICMP6Decoder ( ) <EOL> msg_types = [ <EOL> ICMP6 . ICMP6 . ECHO_REQUEST , <EOL> ICMP6 . ICMP6 . ECHO_REPLY , <EOL> ICMP6 . ICMP6 . PARAMETER_PROBLEM , <EOL> ICMP6 . ICMP6 . PARAMETER_PROBLEM , <EOL> ICMP6 . ICMP6 . PARAMETER_PROBLEM , <EOL> ICMP6 . ICMP6 . DESTINATION_UNREACHABLE , <EOL> ICMP6 . ICMP6 . DESTINATION_UNREACHABLE , <EOL> ICMP6 . ICMP6 . DESTINATION_UNREACHABLE , <EOL> ICMP6 . ICMP6 . DESTINATION_UNREACHABLE , <EOL> ICMP6 . ICMP6 . DESTINATION_UNREACHABLE , <EOL> ICMP6 . ICMP6 . DESTINATION_UNREACHABLE , <EOL> ICMP6 . ICMP6 . DESTINATION_UNREACHABLE , <EOL> ICMP6 . ICMP6 . TIME_EXCEEDED , <EOL> ICMP6 . ICMP6 . TIME_EXCEEDED , <EOL> ICMP6 . ICMP6 . PACKET_TOO_BIG <EOL> ] <EOL> msg_codes = [ <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> ICMP6 . ICMP6 . ERRONEOUS_HEADER_FIELD_ENCOUNTERED , <EOL> ICMP6 . ICMP6 . UNRECOGNIZED_NEXT_HEADER_TYPE_ENCOUNTERED , <EOL> ICMP6 . ICMP6 . UNRECOGNIZED_IPV6_OPTION_ENCOUNTERED , <EOL> ICMP6 . ICMP6 . NO_ROUTE_TO_DESTINATION , <EOL> ICMP6 . ICMP6 . ADMINISTRATIVELY_PROHIBITED , <EOL> ICMP6 . ICMP6 . BEYOND_SCOPE_OF_SOURCE_ADDRESS , <EOL> ICMP6 . ICMP6 . ADDRESS_UNREACHABLE , <EOL> ICMP6 . ICMP6 . PORT_UNREACHABLE , <EOL> ICMP6 . ICMP6 . SOURCE_ADDRESS_FAILED_INGRESS_EGRESS_POLICY , <EOL> ICMP6 . ICMP6 . REJECT_ROUTE_TO_DESTINATION , <EOL> ICMP6 . ICMP6 . HOP_LIMIT_EXCEEDED_IN_TRANSIT , <EOL> ICMP6 . ICMP6 . FRAGMENT_REASSEMBLY_TIME_EXCEEDED , <EOL> <NUM_LIT:0> <EOL> ] <EOL> for i in range ( <NUM_LIT:0> , len ( self . reference_data_list ) ) : <EOL> p = d . decode ( self . reference_data_list [ i ] ) <EOL> self . assertEquals ( p . get_type ( ) , msg_types [ i ] , self . message_description_list [ i ] + "<STR_LIT>" ) <EOL> self . assertEquals ( p . get_code ( ) , msg_codes [ i ] , self . message_description_list [ i ] + "<STR_LIT>" ) <EOL> if i in range ( <NUM_LIT:0> , <NUM_LIT:2> ) : <EOL> self . assertEquals ( p . get_echo_id ( ) , <NUM_LIT:1> , self . message_description_list [ i ] + "<STR_LIT>" ) <EOL> self . assertEquals ( p . get_echo_sequence_number ( ) , <NUM_LIT:2> , self . message_description_list [ i ] + "<STR_LIT>" ) <EOL> self . assertEquals ( p . get_echo_arbitrary_data ( ) . tolist ( ) , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , self . message_description_list [ i ] + "<STR_LIT>" ) <EOL> if i in range ( <NUM_LIT:2> , <NUM_LIT:5> ) : <EOL> self . assertEquals ( p . get_parm_problem_pointer ( ) , <NUM_LIT:2> , self . message_description_list [ i ] + "<STR_LIT>" ) <EOL> if i in range ( <NUM_LIT:5> , <NUM_LIT:15> ) : <EOL> self . assertEquals ( p . get_originating_packet_data ( ) . tolist ( ) , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , self . message_description_list [ i ] + "<STR_LIT>" ) <EOL> if i in range ( <NUM_LIT> , <NUM_LIT:15> ) : <EOL> self . assertEquals ( p . get_mtu ( ) , <NUM_LIT> , self . message_description_list [ i ] + "<STR_LIT>" ) <EOL> suite = unittest . TestLoader ( ) . loadTestsFromTestCase ( TestICMP6 ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( suite ) </s>
