Пример #1
0
    def test_bad_ipv6_prefix_length(self):
        S46RuleOption.parse(bytes.fromhex('00590020011020010203008020010db8000000000000000000000000ffff0000fffe0000'))

        with self.assertRaisesRegex(ValueError, 'range from 0 to 128'):
            S46RuleOption.parse(
                bytes.fromhex('00590021011020010203008120010db800000000000000000000000000ffff0000fffe0000')
            )
Пример #2
0
    def test_bad_ipv4_prefix_length(self):
        S46RuleOption.parse(
            bytes.fromhex(
                '00590015011020010203002220010db800ffff0000fffe0000'))

        with self.assertRaisesRegex(ValueError, 'range from 0 to 32'):
            S46RuleOption.parse(
                bytes.fromhex(
                    '00590015011021010203002220010db800ffff0000fffe0000'))
Пример #3
0
    def test_bad_option_length(self):
        with self.assertRaisesRegex(ValueError,
                                    'shorter than the minimum length'):
            S46RuleOption.parse(
                bytes.fromhex(
                    '00590000011018010203002220010db800ffff0000fffe0000'))

        with self.assertRaisesRegex(ValueError, 'length does not match'):
            S46RuleOption.parse(
                bytes.fromhex(
                    '00590014011018010203002220010db800ffff0000fffe0000'))
Пример #4
0
    def create(self) -> S46RuleOption:
        """
        Create a MAP rule option based on the configuration.

        :return: The mapping rule
        """

        option = S46RuleOption(
            ea_len=self.ea_len,
            ipv4_prefix=self.ipv4_prefix,
            ipv6_prefix=self.ipv6_prefix,
            options=[S46PortParametersOption(offset=self.a_bits)])
        option.fmr = self.forwarding_mapping
        return option
Пример #5
0
                                                            psid=127)

# S46RuleOption
s46_rule_option_bytes = (
    bytes.fromhex('0059'  # option_type: OPTION_S46_RULE
                  '0015'  # option_length
                  '01'  # flags
                  '10'  # ea_len
                  '18'  # ipv4_prefix_len
                  '01020300'  # ipv4_prefix
                  '22'  # ipv6_prefix_len
                  '20010db800')  # ipv6_prefix
    + s46_port_parameters_option_bytes)
s46_rule_option_object = S46RuleOption(
    flags=1,
    ea_len=16,
    ipv4_prefix=IPv4Network('1.2.3.0/24'),
    ipv6_prefix=IPv6Network('2001:db8::/34'),
    options=[s46_port_parameters_option_object])

# S46BROption
s46_br_option_bytes = bytes.fromhex(
    '005a'  # option_type: OPTION_S46_BR
    '0010'  # option_length
    '20010db8000000000000000000000001')  # 2001:db8::1
s46_br_option_object = S46BROption(br_address=IPv6Address('2001:db8::1'))

# S46DMROption
s46_dmr_option_bytes = bytes.fromhex('005b'  # option_type: OPTION_S46_DMR
                                     '0006'  # option_length
                                     '21'  # prefix_len
                                     '20010db800')  # 2001:db8::1
Пример #6
0
    def test_bad_option_length(self):
        with self.assertRaisesRegex(ValueError, 'shorter than the minimum length'):
            S46RuleOption.parse(bytes.fromhex('00590000011018010203002220010db800ffff0000fffe0000'))

        with self.assertRaisesRegex(ValueError, 'length does not match'):
            S46RuleOption.parse(bytes.fromhex('00590014011018010203002220010db800ffff0000fffe0000'))