示例#1
0
        private void Forward(IxgbeDevice rxDev, int rxQueue, IxgbeDevice txDev, int txQueue, Span <PacketBuffer> buffers)
        {
            var rxBuffCount = rxDev.RxBatch(rxQueue, buffers);

            if (rxBuffCount > 0)
            {
                var rxBuffers = buffers.Slice(0, rxBuffCount);
                //Touch all buffers to simulate a realistic scenario
                foreach (var buffer in rxBuffers)
                {
                    buffer.Touch();
                }

                var txBuffCount = txDev.TxBatch(txQueue, rxBuffers);
                _mempool = (_mempool == null) ? Mempool.FindPool(rxBuffers[0].MempoolId) : _mempool;

                //Drop unsent packets
                foreach (var buffer in rxBuffers.Slice(txBuffCount))
                {
                    _mempool.FreeBuffer(buffer);
                }
            }
        }
示例#2
0
        private void InitMempool()
        {
            _mempool = MemoryHelper.AllocateMempool(BuffersCount);

            //Pre-fill all our packet buffers with some templates that can be modified later
            var buffers = new PacketBuffer[BuffersCount];

            for (int i = 0; i < BuffersCount; i++)
            {
                var buffer = _mempool.GetPacketBuffer();
                buffer.Size = (uint)PacketData.Length;
                buffer.WriteData(0, PacketData);
                var ipData = buffer.CopyData(14, 20);
                buffer.WriteData(24, (short)CalcIpChecksum(ipData));
                buffers[i] = buffer;
            }

            //Return them all to the mempool, all future allocations will return buffers with the data set above
            foreach (var buffer in buffers)
            {
                _mempool.FreeBuffer(buffer);
            }
        }