private void Write() { // We need to buffer the incoming packets, and save them in order. // This is done with the Multi memory segments. // When segmented packets are received, their respective multi memory segments are saved, // and the id is saved in an dict with <(packet_ident),[segment_pointer]> // Disable the write bus, enable if there is stuff in the packet controlA.Enabled = false; // If the data is valid, we write it if (packetInComputeProducerControlBusIn.valid) { // This is a new packet if (write_next_packet) { // Fill in the temporary data tmp_write_info.ip_dst_addr_0 = packetInBus.ip_dst_addr_0; tmp_write_info.ip_dst_addr_1 = packetInBus.ip_dst_addr_1; tmp_write_info.ip_src_addr_0 = packetInBus.ip_src_addr_0; tmp_write_info.ip_src_addr_1 = packetInBus.ip_src_addr_1; tmp_write_info.protocol = packetInBus.protocol; tmp_write_info.ip_id = packetInBus.ip_id; tmp_write_info.frame_number = packetInBus.frame_number; tmp_write_info.total_len = (ushort)packetInBus.data_length; // Set the accumulator length to the same as the total length, since this is a new "pristine" packet tmp_write_info.accum_len = (ushort)(packetInBus.data_length); // Get the new block we write to, and save the metadata cur_write_block_id = mem_calc.AllocateSegment(packetInBus.data_length); mem_calc.SaveMetaData(cur_write_block_id, tmp_write_info); // XXX: Fix fragmentation // We have made the new packet, set the flag to false write_next_packet = false; Logging.log.Info($"New packet! frame_number: {packetInBus.frame_number} " + $"write_mem_id: {cur_write_block_id} " + $"ip_id: 0x{tmp_write_info.ip_id:X2} " + $"segment_length: {packetInBus.data_length} "); } // Submit the data controlA.Enabled = true; controlA.IsWriting = true; int addr = mem_calc.SaveData(cur_write_block_id); controlA.Address = addr; Logging.log.Info($"Receiving: data: 0x{packetInBus.data:X2} " + $"addr: {addr} " + $"in memory block: {cur_write_block_id} " + $"data left: {packetInComputeProducerControlBusIn.bytes_left} " + $"frame_number: {packetInBus.frame_number}"); controlA.Data = packetInBus.data; } // Test if we are at the last byte in this segment, and mark it for next clock, where we get a the next packet if (packetInComputeProducerControlBusIn.bytes_left == 0) { write_next_packet = true; } }
private void Write() { // Disable the write bus, enable if there is stuff in the packet controlA.Enabled = false; // XXX datain ready should be stopped when there is no more good data dataInComputeConsumerControlBusOut.ready = true; // Data on the bus is currently valid if (dataInComputeProducerControlBusIn.valid) { // This is a new packet if (dataIn.socket != cur_write_socket || dataIn.sequence != cur_write_sequence) { // Set the current socket, sequence and packet number cur_write_socket = dataIn.socket; cur_write_sequence = dataIn.sequence; // get the new write id cur_write_block_id = mem_calc.AllocateSegment(dataIn.data_length); // Fist we test and fill the socket dict // Check if we need to create key in the socket, if so make it if (!this.sequence_dict.ContainsKey((int)cur_write_socket)) { if (!this.sequence_dict.New((int)cur_write_socket)) { Logging.log.Fatal($"Could not create new key for socket_dict key:{cur_write_socket}"); throw new Exception($"Could not create new key for socket_dict key:{cur_write_socket}"); } // Set the sequence to zero tmp_sequenceinfo.maximum_sequence = 0; this.sequence_dict.SaveMetaData(cur_write_socket, tmp_sequenceinfo); } // We save information about the newly seen segment for that socket int test = this.sequence_dict.Insert(cur_write_socket, (int)cur_write_sequence); memory_lookup[test] = cur_write_block_id; Logging.log.Info($"Adding memory_segment " + $"socket: {cur_write_socket} " + $"segment size: {dataIn.data_length} " + $"sequence: {cur_write_sequence} " + $"mem look addr: {test} " + $"write block id: {cur_write_block_id}"); // Test if we have gotten a new sequence that is higher tmp_sequenceinfo = this.sequence_dict.LoadMetaData(cur_write_socket); if (tmp_sequenceinfo.maximum_sequence < dataIn.highest_sequence_ready) { tmp_sequenceinfo.maximum_sequence = (int)dataIn.highest_sequence_ready; this.sequence_dict.SaveMetaData(cur_write_socket, tmp_sequenceinfo); } // We create the struct for the address block tmp_write_inputdata.total_length = dataIn.data_length; tmp_write_inputdata.invalidate = dataIn.invalidate; tmp_write_inputdata.socket = dataIn.socket; tmp_write_inputdata.sequence = dataIn.sequence; tmp_write_inputdata.accum_len = dataIn.data_length; mem_calc.SaveMetaData(cur_write_block_id, tmp_write_inputdata); } // Submit the data controlA.Enabled = true; controlA.IsWriting = true; // We save information about the newly seen segment for that socket int saveaddress = this.sequence_dict.Observe(cur_write_socket, (int)cur_write_sequence); Logging.log.Info($"Received data 0x{dataIn.data:X2} " + $"Socket: {dataIn.socket} " + $"Sequence number: {dataIn.sequence} " + $"sequence dict addr: {saveaddress} " + $"frame number: {dataIn.frame_number} " + $"memory lookup: {memory_lookup[saveaddress]}"); controlA.Address = mem_calc.SaveData(memory_lookup[saveaddress]); controlA.Data = dataIn.data; } }