Пример #1
0
        private void Send()
        {
            // Reset until they are needed
            controlB.Enabled = false;

            ////////////// BUFFER code
            // if we are receiving stuff from the memory, save it to the buffer
            if (memory_receiving)
            {
                int  buffer = buffer_calc.SaveData();
                byte data   = readResultB.Data;
                tempSendRingBuffer.data   = data;
                tempSendRingBuffer.length = buffer_calc.MetadataCurrentSaveSegment().accum_len;
                send_buffer[buffer]       = tempSendRingBuffer;
                Logging.log.Trace($"Got memory. goes to buffer:{buffer} data:0x{data:X2}");
                buffer_calc.FinishFillingCurrentSaveSegment();
                memory_receiving = false;
            }

            // If the last clock had an request, we know that the next clock has
            // to be receiving stuff.
            if (memory_requested)
            {
                memory_receiving = true;
                memory_requested = false;
            }

            // If there are no avaliable next segments, we cannot save data
            if (buffer_calc.NextSegmentReady())
            {
                // Get the address for the current focus element
                int addr = mem_calc.LoadData();

                // If we actually can get the address(If buffer empty etc)
                if (addr != -1)
                {
                    Logging.log.Trace($"Requesting memory from addr: {addr}");
                    // Request the data
                    controlB.Enabled   = true;
                    controlB.IsWriting = false;
                    controlB.Address   = addr;

                    // we now have an request from memory
                    memory_requested = true;

                    tmp_send_ip_info = mem_calc.MetadataCurrentLoadSegment();

                    tmp_send_ip_info.accum_len = (ushort)mem_calc.LoadDataBytesLeft();
                    // test if the total size is missing
                    if (tmp_send_ip_info.total_len == 0)
                    {
                        tmp_send_ip_info.total_len = tmp_send_ip_info.accum_len;
                        mem_calc.MetadataCurrentLoadSegment(tmp_send_ip_info);
                    }
                    if (tmp_send_ip_info.accum_len == 0)
                    {
                        mem_calc.FinishReadingCurrentLoadSegment();
                    }

                    // We save the metadata onto the buffer
                    buffer_calc.NextSegment(tmp_send_ip_info);
                }
            }

            ///////////// Sending code
            // They are ready, we submit stuff

            Logging.log.Info($"The load segment status: {buffer_calc.LoadSegmentReady()} ready: {packetOutBufferConsumerControlBusIn.ready}");


            packetOutBufferProducerControlBusOut.valid = buffer_calc.LoadSegmentReady();

            if (packetOutBufferConsumerControlBusIn.ready)
            {
                send_preload = true;
            }

            if (send_preload && buffer_calc.LoadSegmentReady())
            {
                int  addr       = buffer_calc.LoadData();
                byte data       = send_buffer[addr].data;
                int  bytes_left = send_buffer[addr].length;
                packetOut.data          = data;
                packetOut.ip_dst_addr_0 = buffer_calc.MetadataCurrentLoadSegment().ip_dst_addr_0;
                packetOut.ip_dst_addr_1 = buffer_calc.MetadataCurrentLoadSegment().ip_dst_addr_1;
                packetOut.ip_src_addr_0 = buffer_calc.MetadataCurrentLoadSegment().ip_src_addr_0;
                packetOut.ip_src_addr_1 = buffer_calc.MetadataCurrentLoadSegment().ip_src_addr_1;
                packetOut.frame_number  = buffer_calc.MetadataCurrentLoadSegment().frame_number;
                packetOut.data_length   = buffer_calc.MetadataCurrentLoadSegment().total_len;
                //packetOut.fragment_offset = 0;
                packetOut.ip_id    = buffer_calc.MetadataCurrentLoadSegment().ip_id;
                packetOut.protocol = buffer_calc.MetadataCurrentLoadSegment().protocol;



                packetOutBufferProducerControlBusOut.valid      = true;
                packetOutBufferProducerControlBusOut.bytes_left = (uint)bytes_left;

                buffer_calc.FinishReadingCurrentLoadSegment();

                send_preload = false;

                Logging.log.Info($"Sending: data: 0x{data:X2} " +
                                 $"buffer_addr: {addr} " +
                                 $"bytes left: {bytes_left} " +
                                 $"total length : {buffer_calc.MetadataCurrentLoadSegment().total_len}");
            }
        }
Пример #2
0
        private void Send()
        {
            // Look in the FIFO buffer, and send the next element. If the element is ip segmented,
            // Look through the segments in order, and override the normal fifo order. This way ip segmentation is
            // solved in the buffer. TCP segmentation is solved in the dataout buffer.

            // TODO: If we are at an segment in the ringbuffer where we should submit an segment, but the segment
            // is not done, put it on the top of the FIFO queue, and update the segment pointer, then go to next packet

            // Reset until they are needed
            controlB.Enabled = false;

            ////////////// BUFFER code
            // if we are receiving stuff from the memory, save it to the buffer
            if (memory_receiving)
            {
                int  buffer = buffer_calc.SaveData();
                byte data   = readResultB.Data;
                tempSendRingBuffer.data         = data;
                tempSendRingBuffer.length       = buffer_calc.MetadataCurrentSaveSegment().accum_len;
                tempSendRingBuffer.mem_block_id = buffer_calc.MetadataCurrentSaveSegment().mem_block_id;
                send_buffer[buffer]             = tempSendRingBuffer;
                Logging.log.Trace($"Got memory. goes to buffer:{buffer} data:0x{data:X2}");
                buffer_calc.FinishFillingCurrentSaveSegment();
                memory_receiving = false;
            }

            // If the last clock had an request, we know that the next clock has
            // to be receiving stuff.
            if (memory_requested)
            {
                memory_receiving = true;
                memory_requested = false;
            }

            // If there are no avaliable next segments, we cannot save data
            if (buffer_calc.NextSegmentReady())
            {
                // Get the address for the current focus element
                int focus_segment = mem_calc.FocusSegment();
                Logging.log.Trace($"focus segment: {focus_segment}");
                int addr = mem_calc.LoadData(focus_segment);

                // If we actually can get the address(If buffer empty etc)
                if (addr != -1)
                {
                    Logging.log.Trace($"Requesting memory from addr: {addr} on segment: {focus_segment}");
                    // Request the data
                    controlB.Enabled   = true;
                    controlB.IsWriting = false;
                    controlB.Address   = addr;

                    // we now have an request from memory
                    memory_requested = true;

                    // Get the metadata from the memory calculator, subtract the total by one, and
                    // Push it into the segment. This makes it possible to detect the last byte in the loaded data
                    tmp_send_info              = mem_calc.LoadMetaData(focus_segment);
                    tmp_send_info.accum_len   -= 1;
                    tmp_send_info.mem_block_id = focus_segment;
                    mem_calc.SaveMetaData(focus_segment, tmp_send_info);

                    // We save the metadata onto the buffer
                    buffer_calc.NextSegment(mem_calc.LoadMetaData(focus_segment));
                }
            }

            ///////////// Sending code
            // They are ready, we submit stuff

            Logging.log.Trace($"The load segment status: {buffer_calc.LoadSegmentReady()} ready: {packetOutBufferConsumerControlBusIn.ready}");


            packetOutBufferProducerControlBusOut.valid = buffer_calc.LoadSegmentReady();

            if (packetOutBufferConsumerControlBusIn.ready)
            {
                send_preload = true;
            }

            if (send_preload && buffer_calc.LoadSegmentReady())
            {
                packetOutBus.data_length   = buffer_calc.MetadataCurrentLoadSegment().total_len;
                packetOutBus.ip_dst_addr_0 = buffer_calc.MetadataCurrentLoadSegment().ip_dst_addr_0;
                packetOutBus.ip_dst_addr_1 = buffer_calc.MetadataCurrentLoadSegment().ip_dst_addr_1;
                packetOutBus.ip_src_addr_0 = buffer_calc.MetadataCurrentLoadSegment().ip_src_addr_0;
                packetOutBus.ip_src_addr_1 = buffer_calc.MetadataCurrentLoadSegment().ip_src_addr_1;
                long frame_number = buffer_calc.MetadataCurrentLoadSegment().frame_number;
                packetOutBus.frame_number    = frame_number;
                packetOutBus.fragment_offset = 0;
                uint ip_id = buffer_calc.MetadataCurrentLoadSegment().ip_id;
                packetOutBus.ip_id    = ip_id;
                packetOutBus.protocol = buffer_calc.MetadataCurrentLoadSegment().protocol;
                int  addr = buffer_calc.LoadData();
                byte data = send_buffer[addr].data;
                packetOutBus.data = data;

                packetOutBufferProducerControlBusOut.valid      = true;
                packetOutBufferProducerControlBusOut.bytes_left = send_buffer[addr].length;

                buffer_calc.FinishReadingCurrentLoadSegment();

                send_preload = false;

                Logging.log.Info($"Sending: data: 0x{data:X2} ip_id: 0x{ip_id:X2} buffer_addr: {addr} frame_number: {frame_number} bytes_left: {send_buffer[addr].length}");
            }
        }