-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtx_mp.c
98 lines (94 loc) · 2.41 KB
/
tx_mp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "tx_mp.h"
#include <rte_lcore.h>
#include <stdio.h>
#include <string.h>
#include <rte_eal.h>
#include <rte_common.h>
#include <rte_mempool.h>
#include <rte_memory.h>
#include <rte_mbuf.h>
inline struct rte_mbuf* generate_mbuf(struct packet_model pm, struct rte_mempool *mp, uint32_t pkt_length)
{
struct rte_mbuf *m;
m = rte_pktmbuf_alloc(mp);
if(m == NULL)
{
rte_exit(-1, "mempool is empty!\n");
}
char *data;
if(pm.is_vxlan)
{
data = rte_pktmbuf_append(m, sizeof(pm.vxlan));
if(data == NULL)
{
rte_exit(-1, "mbuf append vxlan hdr failed!\n");
}
rte_memcpy(data, (char*)&(pm.vxlan), sizeof(pm.vxlan));
}
if(pm.is_udp)
{
data = rte_pktmbuf_append(m, sizeof(pm.udp));
if(data == NULL)
{
rte_exit(-1, "mbuf append udp hdr failed!\n");
}
rte_memcpy(data, &(pm.udp), sizeof(pm.udp));
data = rte_pktmbuf_append(m, pkt_length - 46);
if(data == NULL)
{
rte_exit(-1, "mbuf append udp data failed!\n");
}
}
else
{
data = rte_pktmbuf_append(m, sizeof(pm.tcp));
if(data == NULL)
{
rte_exit(-1, "mbuf append tcp hdr failed!\n");
}
rte_memcpy(data, &(pm.tcp), sizeof(pm.tcp));
data = rte_pktmbuf_append(m, pkt_length - 58);
if(data == NULL)
{
rte_exit(-1, "mbuf append tcp data failed!\n");
}
}
return m;
}
struct rte_mempool* tx_mempool_create(int n, int lcore_id)
{
char name[64];
struct rte_mempool *mp;
struct rte_mbuf *m;
int poolsz, i, pmi;
snprintf(name, 64, "tx_mempool_lcore(%d)", lcore_id);
mp = rte_pktmbuf_pool_create(name, n, MAX_TX_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_DATAROOM, rte_lcore_to_socket_id(lcore_id));
if(mp == NULL)
{
rte_exit(EINVAL, "create mempool for lcore %d failed\n", lcore_id);
}
rte_mempool_dump(stdout, mp);
return mp;
}
/*
int tx_mempool_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf *mbuf[], int n)
{
int ret, i;
ret = rte_mempool_get_bulk(mp, (void**)mbuf, n);
if(ret >= 0)
{
for(i = 0; i < n; i++)
{
tx_mbuf_init_noreset(mbuf[i]);
}
}
return ret;
}
void tx_mempool_free_bulk(struct rte_mbuf *mbuf[], int n)
{
int i;
for(i = 0; i < n; i++)
{
rte_pktmbuf_free(mbuf[i]);
}
}*/