示例#1
0
static int
rte_port_fd_reader_rx(void *port, struct rte_mbuf **pkts, uint32_t n_pkts)
{
	struct rte_port_fd_reader *p = port;
	uint32_t i, j;

	if (rte_pktmbuf_alloc_bulk(p->mempool, pkts, n_pkts) != 0)
		return 0;

	for (i = 0; i < n_pkts; i++) {
		struct rte_mbuf *pkt = pkts[i];
		void *pkt_data = rte_pktmbuf_mtod(pkt, void *);
		ssize_t n_bytes;

		n_bytes = read(p->fd, pkt_data, (size_t) p->mtu);
		if (n_bytes <= 0)
			break;

		pkt->data_len = n_bytes;
		pkt->pkt_len = n_bytes;
	}

	for (j = i; j < n_pkts; j++)
		rte_pktmbuf_free(pkts[j]);

	RTE_PORT_FD_READER_STATS_PKTS_IN_ADD(p, i);

	return i;
}
static int
rte_port_source_rx(void *port, struct rte_mbuf **pkts, uint32_t n_pkts)
{
	struct rte_port_source *p = port;
	uint32_t i;

	if (rte_pktmbuf_alloc_bulk(p->mempool, pkts, n_pkts) != 0)
		return 0;

	if (p->pkt_buff != NULL) {
		for (i = 0; i < n_pkts; i++) {
			uint8_t *pkt_data = rte_pktmbuf_mtod(pkts[i],
				uint8_t *);

			rte_memcpy(pkt_data, p->pkts[p->pkt_index],
					p->pkt_len[p->pkt_index]);
			pkts[i]->data_len = p->pkt_len[p->pkt_index];
			pkts[i]->pkt_len = pkts[i]->data_len;

			p->pkt_index++;
			if (p->pkt_index >= p->n_pkts)
				p->pkt_index = 0;
		}
	}

	RTE_PORT_SOURCE_STATS_PKTS_IN_ADD(p, n_pkts);

	return n_pkts;
}