def test_should_create_HopByHop_object_instance_when_to_bytes_method_is_called_with_data( self): # GIVEN hop_by_hop_option = any_hop_by_hop_mpl_option() hop_by_hop_option_type = hop_by_hop_option.header.type next_header = any_next_header() hdr_ext_len = self._calculate_hdr_ext_len(2 + len(hop_by_hop_option)) hop_by_hop_factory = HopByHopFactory( hop_by_hop_options_factory=HopByHopOptionsFactory( options_factories={hop_by_hop_option_type: MPLOptionFactory() })) data = bytearray([next_header, hdr_ext_len ]) + hop_by_hop_option.to_bytes() data += self.padding(len(data)) # WHEN hop_by_hop = hop_by_hop_factory.parse(io.BytesIO(data), any_message_info()) # THEN self.assertEqual(hop_by_hop_option.value.S, hop_by_hop.options[0].value.S) self.assertEqual(hop_by_hop_option.value.V, hop_by_hop.options[0].value.V) self.assertEqual(hop_by_hop_option.value.M, hop_by_hop.options[0].value.M) self.assertEqual(hop_by_hop_option.value.sequence, hop_by_hop.options[0].value.sequence) self.assertEqual(hop_by_hop_option.value.seed_id, hop_by_hop.options[0].value.seed_id)
def test_should_create_IPv6Packet_with_MPL_extension_header_and_ICMP_upper_layer_protocol_when_to_bytes_method_is_called(self): # GIVEN ipv6_packet_bytes = bytearray([0x60, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x40, 0xfd, 0x00, 0x12, 0x34, 0x45, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x18, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3a, 0x00, 0x6d, 0x04, 0x40, 0x02, 0x00, 0x18, 0x80, 0x00, 0x87, 0x12, 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0xc7, 0xbf, 0x00, 0x00, 0x00, 0x01, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41]) ipv6_factory = IPv6PacketFactory( ehf={ 0: HopByHopFactory( hop_by_hop_options_factory=HopByHopOptionsFactory( options_factories={ 109: MPLOptionFactory() } ) ) }, ulpf={ 58: ICMPv6Factory(body_factories={ 128: ICMPv6EchoBodyFactory() }) }) # WHEN ipv6_packet = ipv6_factory.parse(io.BytesIO(ipv6_packet_bytes), any_message_info()) # THEN self.assertEqual('fd00:1234:4555::ff:fe00:1800', ipv6_packet.ipv6_header.source_address.compressed) self.assertEqual('ff03::1', ipv6_packet.ipv6_header.destination_address.compressed) self.assertEqual(64, ipv6_packet.ipv6_header.hop_limit) self.assertEqual(0, ipv6_packet.ipv6_header.next_header) self.assertEqual(34, ipv6_packet.ipv6_header.payload_length) self.assertEqual(0, ipv6_packet.ipv6_header.flow_label) self.assertEqual(0, ipv6_packet.ipv6_header.traffic_class) self.assertEqual(6, ipv6_packet.ipv6_header.version) self.assertEqual(1, ipv6_packet.extension_headers[0].options[0].value.S) self.assertEqual(0, ipv6_packet.extension_headers[0].options[0].value.M) self.assertEqual(0, ipv6_packet.extension_headers[0].options[0].value.V) self.assertEqual(2, ipv6_packet.extension_headers[0].options[0].value.sequence) self.assertEqual(bytearray([0x00, 0x18]), ipv6_packet.extension_headers[0].options[0].value.seed_id) self.assertEqual(34578, ipv6_packet.upper_layer_protocol.header.checksum) self.assertEqual(128, ipv6_packet.upper_layer_protocol.header.type) self.assertEqual(0, ipv6_packet.upper_layer_protocol.header.code) self.assertEqual(0, ipv6_packet.upper_layer_protocol.body.identifier) self.assertEqual(2, ipv6_packet.upper_layer_protocol.body.sequence_number) self.assertEqual(b'\x80\x00\xc7\xbf\x00\x00\x00\x01AAAAAAAAAA', ipv6_packet.upper_layer_protocol.body.data)
def test_should_produce_MPLOption_from_bytes_when_to_bytes_method_is_called_with_data(self): # GIVEN S = any_mpl_S() M = any_mpl_M() V = any_mpl_V() sequence = any_mpl_sequence() seed_id = any_mpl_seed_id(S) SMV = (S << 6) | (M << 5) | (V << 4) data = bytearray([SMV, sequence]) + seed_id factory = MPLOptionFactory() # WHEN mpl_opt = factory.parse(io.BytesIO(data), any_message_info()) # THEN self.assertEqual(mpl_opt.S, S) self.assertEqual(mpl_opt.M, M) self.assertEqual(mpl_opt.V, V) self.assertEqual(mpl_opt.sequence, sequence) self.assertEqual(mpl_opt.seed_id, seed_id)