Check if the current settings conform to the LISP specifications and
        fix them where possible.

def sanitize(self):
        '''
        Check if the current settings conform to the LISP specifications and
        fix them where possible.
        '''
        super(MapRegisterMessage, self).sanitize()

        # P: This is the proxy-map-reply bit, when set to 1 an ETR sends a Map-
        # Register message requesting for the Map-Server to proxy Map-Reply.
        # The Map-Server will send non-authoritative Map-Replies on behalf
        # of the ETR.  Details on this usage can be found in [LISP-MS].
        if not isinstance(self.proxy_map_reply, bool):
            raise ValueError('Proxy Map Reply flag must be a boolean')

        # The third bit after the Type field in the Map-Register message is
        # allocated as "I" bit.  I bit indicates that a 128 bit xTR-ID and a 64
        # bit site-ID field is present at the end of the Map-Register message.
        # If an xTR is configured with an xTR-ID or site-ID, it MUST set the I
        # bit to 1 and include its xTR-ID and site-ID in the Map-Register
        # messages it generates, if either the xTR-ID or site-ID is not
        # configured an unspecified value is encoded for the ID not configured.
        # If the R bit in the Map-Register is set to 1, the I bit must also be
        # set to 1, and an xTR-ID must be included in the Map-Register message
        # sent to an RTR.
        #
        # xTR-ID is a 128 bit field at the end of the Map-Register message,
        # starting after the final Record in the message.  The xTR-ID is used
        # to identify the intended recipient xTR for a Map-Notify message,
        # especially in the case where a site has more than one xTR.  A value
        # of all zeros indicate that an xTR-ID is not specified, though encoded
        # in the message.  This is useful in the case where a site-ID is
        # specified, but no xTR-ID is configured.  When a Map-Server receives a
        # Map-Register with an xTR-ID specified (I bit set and xTR-ID has a
        # non-zero value), it MUST copy the XTR-ID from the Map-Register to the
        # associated Map-Notify message.  When a Map-Server is sending an
        # unsolicited Map-Notify to an xTR to notify the xTR of a change in
        # locators, the Map-Server must include the xTR-ID for the intended
        # recipient xTR, if it has one stored locally.
        if not isinstance(self.xtr_id, numbers.Integral) \
        or self.xtr_id < 0 or self.xtr_id >= 2 ** 128:
            raise ValueError('Invalid xTR-ID')

        # site-ID is a 64 bit field at the end of the Map-Register message,
        # following the xTR-ID.  The site-ID is used by the Map-Server
        # receiving the Map-Register message to identify which xTRs belong to
        # the same site.  A value of 0 indicate that a site-ID is not
        # specified, though encoded in the message.  When a Map-Server receives
        # a Map-Regeter with a site-ID specified (I bit set and site-ID has
        # non-zero value), it must copy the site-ID from the Map-Register to
        # the associated Map-Notify message.  When a Map-Server is sending an
        # unsolicited Map-Notify to an xTR to notify the xTR of a change in
        # locators, the Map-Server must include the site-ID for the intended
        # recipient xTR, if it has one stored locally.
        if not isinstance(self.site_id, numbers.Integral) \
        or self.site_id < 0 or self.site_id >= 2 ** 64:
            raise ValueError('Invalid site-ID')

        # The fourth bit after the Type field in the Map-Register message is
        # allocated as "R" bit.  R bit indicates that the Map-Register is built
        # for an RTR.  R bit must be set in a Map-Register that a LISP device
        # sends to an RTR.
        if not isinstance(self.for_rtr, bool):
            raise ValueError('For-RTR flag must be a boolean')

        # M: This is the want-map-notify bit, when set to 1 an ETR is
        # requesting for a Map-Notify message to be returned in response to
        # sending a Map-Register message.  The Map-Notify message sent by a
        # Map-Server is used to an acknowledge receipt of a Map-Register
        # message.
        if not isinstance(self.want_map_notify, bool):
            raise ValueError('Want Map Notify flag must be a boolean')

        # Nonce:  This 8-octet Nonce field is set to 0 in Map-Register
        # messages.  Since the Map-Register message is authenticated, the
        # nonce field is not currently used for any security function but
        # may be in the future as part of an anti-replay solution.
        if self.nonce != '\x00\x00\x00\x00\x00\x00\x00\x00':
            # Cisco devices seems to fill it in even if it should be 0
            pass
            # raise ValueError('Invalid nonce (must be 0 for Map-Register): {0}'.format(self.nonce.encode('hex')))

        # Key ID:  A configured ID to find the configured Message
        # Authentication Code (MAC) algorithm and key value used for the
        # authentication function.  See Section 14.4 for codepoint
        # assignments.
        if self.key_id not in (KEY_ID_NONE, KEY_ID_HMAC_SHA_1_96,
                               KEY_ID_HMAC_SHA_256_128):
            raise ValueError('Invalid Key ID')

        # Authentication Data:  The message digest used from the output of the
        # Message Authentication Code (MAC) algorithm.  The entire Map-
        # Register payload is authenticated with this field preset to 0.
        # After the MAC is computed, it is placed in this field.
        # Implementations of this specification MUST include support for
        # HMAC-SHA-1-96 [RFC2404] and support for HMAC-SHA-256-128 [RFC6234]
        # is RECOMMENDED.
        if not isinstance(self.authentication_data, bytes):
            raise ValueError('Invalid authentication data')

        # Map-Reply Record:  When the M bit is set, this field is the size of a
        # single "Record" in the Map-Reply format.  This Map-Reply record
        # contains the EID-to-RLOC mapping entry associated with the Source
        # EID.  This allows the ETR which will receive this Map-Request to
        # cache the data if it chooses to do so.
        for record in self.records:
            if not isinstance(record, MapRegisterRecord):
                raise ValueError('Invalid record')

            record.sanitize()