def from_bytes(cls, bitstream): """ Parse the given record and update properties accordingly """ record = cls() # Convert to ConstBitStream (if not already provided) if not isinstance(bitstream, ConstBitStream): if isinstance(bitstream, Bits): bitstream = ConstBitStream(auto=bitstream) else: bitstream = ConstBitStream(bytes=bitstream) # Read the record TTL record.ttl = bitstream.read("uint:32") # Store the locator record count until we need it referral_count = bitstream.read("uint:8") # Store the EID prefix mask length until we need it eid_prefix_len = bitstream.read("uint:8") # Read the Negative Map_Reply action record.action = bitstream.read("uint:3") # Read the flags (record.authoritative, record.incomplete) = bitstream.readlist("2*bool") # Read reserved bits record._reserved1 = bitstream.read(11) # Read the signature count sig_count = bitstream.read("uint:4") # Read the map version record.map_version = bitstream.read("uint:12") # Read the EID prefix record.eid_prefix = read_afi_address_from_bitstream(bitstream, eid_prefix_len) # Read the locator records for dummy in range(referral_count): locator_record = LocatorRecord.from_bytes(bitstream) record.locator_records.append(locator_record) # TODO: Can't handle signatures yet! [LISP-Security] if sig_count: raise NotImplementedError("Cannot handle signatures yet") # Verify that the properties make sense record.sanitize() return record
def from_bytes(cls, bitstream): ''' Parse the given record and update properties accordingly ''' record = cls() # Convert to ConstBitStream (if not already provided) if not isinstance(bitstream, ConstBitStream): if isinstance(bitstream, Bits): bitstream = ConstBitStream(auto=bitstream) else: bitstream = ConstBitStream(bytes=bitstream) # Read the record TTL record.ttl = bitstream.read('uint:32') # Store the locator record count until we need it locator_record_count = bitstream.read('uint:8') # Store the EID prefix mask length until we need it eid_prefix_len = bitstream.read('uint:8') # Read the Negative Map_Reply action record.action = bitstream.read('uint:3') # Read the flag record.authoritative = bitstream.read('bool') # Read reserved bits record._reserved1 = bitstream.read(12 + 4) # Read the map version record.map_version = bitstream.read('uint:12') # Read the EID prefix record.eid_prefix = read_afi_address_from_bitstream(bitstream, eid_prefix_len) # Read the locator records for dummy in range(locator_record_count): locator_record = LocatorRecord.from_bytes(bitstream) record.locator_records.append(locator_record) # Verify that the properties make sense record.sanitize() return record