示例#1
0
 def setUp(self):
     self.relayed_solicit_message = RelayForwardMessage(
         hop_count=1,
         link_address=IPv6Address('2001:db8:ffff:1::1'),
         peer_address=IPv6Address('fe80::3631:c4ff:fe3c:b2f1'),
         options=[
             RelayMessageOption(relayed_message=RelayForwardMessage(
                 hop_count=0,
                 link_address=IPv6Address('::'),
                 peer_address=IPv6Address('fe80::3631:c4ff:fe3c:b2f1'),
                 options=[
                     RelayMessageOption(relayed_message=SolicitMessage(
                         transaction_id=bytes.fromhex('f350d6'),
                         options=[
                             ElapsedTimeOption(elapsed_time=0),
                             ClientIdOption(duid=LinkLayerDUID(hardware_type=1,
                                                               link_layer_address=bytes.fromhex('3431c43cb2f1'))),
                             IANAOption(iaid=bytes.fromhex('c43cb2f1')),
                             IAPDOption(iaid=bytes.fromhex('c43cb2f1')),
                             OptionRequestOption(requested_options=[
                                 OPTION_DNS_SERVERS,
                             ]),
                         ],
                     )),
                     InterfaceIdOption(interface_id=b'Fa2/3'),
                     RemoteIdOption(enterprise_number=9,
                                    remote_id=bytes.fromhex('020023000001000a0003000100211c7d486e')),
                 ])
             ),
             InterfaceIdOption(interface_id=b'Gi0/0/0'),
             RemoteIdOption(enterprise_number=9, remote_id=bytes.fromhex('020000000000000a0003000124e9b36e8100')),
             RelayIdOption(duid=LinkLayerDUID(hardware_type=1, link_layer_address=bytes.fromhex('121212121212'))),
         ],
     )
    def test_absent_option_echo_request(self):
        relayed_solicit_message = RelayForwardMessage(
            hop_count=1,
            link_address=IPv6Address('2001:db8:ffff:1::1'),
            peer_address=IPv6Address('fe80::3631:c4ff:fe3c:b2f1'),
            options=[
                RelayMessageOption(relayed_message=SolicitMessage(
                    transaction_id=bytes.fromhex('f350d6'),
                    options=[
                        ElapsedTimeOption(elapsed_time=0),
                        ClientIdOption(duid=LinkLayerDUID(hardware_type=1,
                                                          link_layer_address=bytes.fromhex('3431c43cb2f1'))),
                        IANAOption(iaid=bytes.fromhex('c43cb2f1')),
                    ],
                )),
                EchoRequestOption(requested_options=[OPTION_SUBSCRIBER_ID]),
                UnknownOption(option_type=65535),
                InterfaceIdOption(interface_id=b'Fa2/3'),
                RemoteIdOption(enterprise_number=9,
                               remote_id=bytes.fromhex('020023000001000a0003000100211c7d486e')),
            ]
        )

        bundle = TransactionBundle(incoming_message=relayed_solicit_message, received_over_multicast=True)
        self.message_handler.handle(bundle, StatisticsSet())

        self.assertIsInstance(bundle.outgoing_message, RelayReplyMessage)
        self.assertEqual(len(bundle.outgoing_message.options), 2)
        self.assertIsInstance(bundle.outgoing_message.options[0], InterfaceIdOption)
        self.assertIsInstance(bundle.outgoing_message.options[1], RelayMessageOption)
 def setUp(self):
     # The following attributes must be overruled by child classes
     # The basics are tested with a simple SolicitMessage
     self.packet_fixture = bytes.fromhex(
         '01'  # message_type
         '58595a'  # transaction_id
         '0001'  # option_type: OPTION_CLIENTID
         '0015'  # option_length
         '0002'  # duid_type: DUID_EN
         '00009d10'  # enterprise_number
         '444843504b6974556e697454657374'  # "DHCPKitUnitTest"
         '0008'  # option_type: OPTION_ELAPSED_TIME
         '0002'  # option_length
         '0000')  # elapsed_time
     self.message_fixture = SolicitMessage(
         transaction_id=b'XYZ',
         options=[
             ClientIdOption(duid=EnterpriseDUID(
                 enterprise_number=40208, identifier=b'DHCPKitUnitTest')),
             ElapsedTimeOption(elapsed_time=0)
         ])
     self.parse_packet()
示例#4
0
#         Remote-ID: 020000000000000a0003000124e9b36e8100

relayed_solicit_message = RelayForwardMessage(
    hop_count=1,
    link_address=IPv6Address('2001:db8:ffff:1::1'),
    peer_address=IPv6Address('fe80::3631:c4ff:fe3c:b2f1'),
    options=[
        RelayMessageOption(relayed_message=RelayForwardMessage(
            hop_count=0,
            link_address=IPv6Address('::'),
            peer_address=IPv6Address('fe80::3631:c4ff:fe3c:b2f1'),
            options=[
                RelayMessageOption(relayed_message=SolicitMessage(
                    transaction_id=bytes.fromhex('f350d6'),
                    options=[
                        ElapsedTimeOption(elapsed_time=0),
                        ClientIdOption(duid=LinkLayerDUID(
                            hardware_type=1,
                            link_layer_address=bytes.fromhex('3431c43cb2f1'))),
                        RapidCommitOption(),
                        IANAOption(iaid=bytes.fromhex('c43cb2f1')),
                        IAPDOption(iaid=bytes.fromhex('c43cb2f1'),
                                   options=[
                                       IAPrefixOption(
                                           prefix=IPv6Network('::/0')),
                                   ]),
                        ReconfigureAcceptOption(),
                        OptionRequestOption(requested_options=[
                            OPTION_DNS_SERVERS,
                            OPTION_NTP_SERVER,
                            OPTION_SNTP_SERVERS,
#         Requested Option code: Simple Network Time Protocol Server (31)
#         Requested Option code: Identity Association for Prefix Delegation (25)
#         Requested Option code: Identity Association for Non-temporary Address (3)
#         Requested Option code: Vendor-specific Information (17)
#         Requested Option code: SOL_MAX_RT (82)
#         Requested Option code: INF_MAX_RT (83)
#     Vendor Class
#         Option: Vendor Class (16)
#         Length: 4
#         Value: 00000368
#         Enterprise ID: AVM GmbH (872)

request_message = RequestMessage(
    transaction_id=bytes.fromhex('f350d6'),
    options=[
        ElapsedTimeOption(elapsed_time=104),
        ClientIdOption(duid=LinkLayerDUID(hardware_type=1,
                                          link_layer_address=bytes.fromhex(
                                              '3431c43cb2f1'))),
        ServerIdOption(duid=LinkLayerTimeDUID(hardware_type=1,
                                              time=488458703,
                                              link_layer_address=bytes.fromhex(
                                                  '00137265ca42'))),
        IANAOption(iaid=bytes.fromhex('c43cb2f1'),
                   options=[
                       IAAddressOption(
                           address=IPv6Address('2001:db8:ffff:1:c::e09c'),
                           preferred_lifetime=375,
                           valid_lifetime=600),
                   ]),
        IAPDOption(iaid=bytes.fromhex('c43cb2f1'),
示例#6
0
    def test_bad_option_length(self):
        with self.assertRaisesRegex(ValueError, 'must have length 2'):
            ElapsedTimeOption.parse(bytes.fromhex('000800000000ffff'))

        with self.assertRaisesRegex(ValueError, 'must have length 2'):
            ElapsedTimeOption.parse(bytes.fromhex('000800030000ffff'))
示例#7
0
 def setUp(self):
     self.option_bytes = bytes.fromhex('0008000204d2')
     self.option_object = ElapsedTimeOption(elapsed_time=1234)
     self.parse_option()
    def test_bad_option_length(self):
        with self.assertRaisesRegex(ValueError, 'must have length 2'):
            ElapsedTimeOption.parse(bytes.fromhex('000800000000ffff'))

        with self.assertRaisesRegex(ValueError, 'must have length 2'):
            ElapsedTimeOption.parse(bytes.fromhex('000800030000ffff'))
 def test_bad_option_length(self):
     with self.assertRaisesRegex(ValueError, "must have length 2"):
         ElapsedTimeOption.parse(bytes.fromhex("000800000000ffff"))