def __init__(self, duid: DUID): """ Create a handler function based on the provided DUID :param duid: The DUID of this server """ option = ServerIdOption(duid) option.validate() super().__init__(option, always_send=True)
def construct_plain_status_reply(self, bundle: TransactionBundle, option: StatusCodeOption) -> ReplyMessage: """ Construct a reply message signalling a status code to the client. :param bundle: The transaction bundle containing the incoming request :param option: The status code option to include in the reply :return: A reply with only the bare necessities and a status code """ return ReplyMessage( bundle.request.transaction_id, options=[ bundle.request.get_option_of_type(ClientIdOption), ServerIdOption(duid=self.server_id), option ])
def construct_use_multicast_reply(self, bundle: TransactionBundle) -> ReplyMessage: """ Construct a message signalling to the client that they should have used multicast. :param bundle: The transaction bundle containing the incoming request :return: The proper answer to tell a client to use multicast """ # Make sure we only tell this to requests that came in over unicast if bundle.received_over_multicast: logger.error("Not telling client to use multicast, they already did...") return None return ReplyMessage(bundle.request.transaction_id, options=[ bundle.request.get_option_of_type(ClientIdOption), ServerIdOption(duid=self.server_id), StatusCodeOption(STATUS_USE_MULTICAST, "You cannot send requests directly to this server, " "please use the proper multicast addresses") ])
address=IPv6Address('2001:db8:ffff:1:c::e09c'), preferred_lifetime=375, valid_lifetime=600), ]), IAPDOption(iaid=bytes.fromhex('c43cb2f1'), options=[ IAPrefixOption( prefix=IPv6Network('2001:db8:ffcc:fe00::/56'), preferred_lifetime=375, valid_lifetime=600), ]), 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'))), ReconfigureAcceptOption(), RecursiveNameServersOption( dns_servers=[IPv6Address('2001:4860:4860::8888')]), ], ) reply_packet = codecs.decode( '07f350d600030028c43cb2f100000000' '000000000005001820010db8ffff0001' '000c00000000e09c0000017700000258' '00190029c43cb2f10000000000000000' '001a001900000177000002583820010d' 'b8ffccfe000000000000000000000100' '0a000300013431c43cb2f10002000e00'
def setUp(self): self.option_bytes = b'\x00\x02\x00\x15\x00\x02\x00\x00\x9d\x100123456789abcde' self.option_object = ServerIdOption( EnterpriseDUID(40208, b'0123456789abcde')) self.parse_option()