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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
#include <rte_debug.h>
#include <rte_ethdev.h>
#include <rte_ether.h>
#include <rte_graph.h>
#include <rte_graph_worker.h>
#include <rte_mbuf.h>
#include <mrb_define.h>
#include <sc_node.h>
#include <sc_node_common.h>
#include <sc_vdev.h>
struct dev_node_elem
{
TAILQ_ENTRY(dev_node_elem) entries;
rte_node_t nid;
struct dev_node_ctx ctx;
};
struct dev_node_main
{
TAILQ_HEAD(dev_node_elem_head, dev_node_elem) elems_head;
struct sc_main * sc;
};
static struct dev_node_main st_dev_node_main;
static struct dev_node_main * p_dev_node_main = &st_dev_node_main;
static_assert(sizeof(struct dev_node_ctx) <= RTE_NODE_CTX_SZ, "dev_node_ctx size must smaller than RTE_NODE_CTX_SZ");
static __rte_always_inline uint16_t dpdk_dev_rx_node_process(struct rte_graph * graph, struct rte_node * node,
void ** objs, uint16_t cnt)
{
struct dev_node_ctx * ctx = (struct dev_node_ctx *)node->ctx;
struct sc_main * sc = p_dev_node_main->sc;
assert(ctx != NULL && sc != NULL);
RTE_SET_USED(objs);
RTE_SET_USED(cnt);
unsigned int rx_nr_mbufs =
rte_eth_rx_burst(ctx->dev_desc->port_id, graph->id, (struct rte_mbuf **)node->objs, RTE_GRAPH_BURST_SIZE);
if (rx_nr_mbufs == 0)
{
return 0;
}
/* hash caculate */
node->idx = rx_nr_mbufs;
distributer_caculate(sc->dist_object, (struct rte_mbuf **)node->objs, node->idx);
/* shared ctx */
for (unsigned int i = 0; i < node->idx; i++)
{
struct rte_mbuf * mbuf = (struct rte_mbuf *)node->objs[i];
struct mrb_metadata * private_ctrlzone = mrbuf_cz_data(mbuf, MR_NODE_CTRLZONE_ID);
memset(private_ctrlzone, 0, sizeof(struct mrb_metadata));
private_ctrlzone->port_ingress = ctx->dev_desc->port_id;
private_ctrlzone->port_egress = UINT16_MAX;
/* Parser Pkt */
struct pkt_parser pkt_parser;
pkt_parser_init(&pkt_parser, LAYER_TYPE_ALL, MR_PKT_PARSER_LAYERS_MAX);
complex_parser_ether(&pkt_parser, rte_pktmbuf_mtod(mbuf, const char *));
/* copy the result to private zone */
private_ctrlzone->pkt_parser_result = pkt_parser.result;
}
/* move to next node */
rte_node_next_stream_move(graph, node, 0);
return rx_nr_mbufs;
}
static __rte_always_inline uint16_t dpdk_dev_tx_node_process(struct rte_graph * graph, struct rte_node * node,
void ** objs, uint16_t cnt)
{
struct dev_node_ctx * ctx = (struct dev_node_ctx *)node->ctx;
unsigned int tx_nr_mbufs = rte_eth_tx_burst(ctx->dev_desc->port_id, graph->id, (struct rte_mbuf **)objs, cnt);
if (unlikely(tx_nr_mbufs != cnt))
{
/* redirect unsent pkts to drop node */
rte_node_enqueue(graph, node, 0, &objs[tx_nr_mbufs], cnt - tx_nr_mbufs);
}
return cnt;
}
static int dev_node_init(const struct rte_graph * graph, struct rte_node * node)
{
struct dev_node_ctx * ctx = (struct dev_node_ctx *)node->ctx;
struct dev_node_elem * elem_iter = NULL;
TAILQ_FOREACH(elem_iter, &p_dev_node_main->elems_head, entries)
{
if (elem_iter->nid != node->id)
continue;
*ctx = (elem_iter->ctx);
}
return 0;
}
static struct rte_node_register dpdk_dev_rx_node_base = {
.process = dpdk_dev_rx_node_process,
.flags = RTE_NODE_SOURCE_F,
.name = "dpdk_dev_rx_node",
.init = dev_node_init,
.nb_edges = 2,
.next_nodes =
{
[0] = "eth_ingress",
[1] = "pkt_drop",
},
};
static struct rte_node_register dpdk_dev_tx_node_base = {
.process = dpdk_dev_tx_node_process,
.name = "dpdk_dev_tx_node",
.init = dev_node_init,
.nb_edges = 1,
.next_nodes =
{
[0] = "pkt_drop",
},
};
/* TODO: move these functions to here */
extern uint16_t shmdev_rx_node_process(struct rte_graph * graph, struct rte_node * node, void ** objs, uint16_t cnt);
extern uint16_t shmdev_tx_node_process(struct rte_graph * graph, struct rte_node * node, void ** objs, uint16_t cnt);
static struct rte_node_register shm_dev_rx_node_base = {
.process = shmdev_rx_node_process,
.flags = RTE_NODE_SOURCE_F,
.name = "shm_dev_rx_node",
.init = dev_node_init,
.nb_edges = 2,
.next_nodes =
{
[0] = "eth_ingress",
[1] = "pkt_drop",
},
};
static struct rte_node_register shm_dev_tx_node_base = {
.process = shmdev_tx_node_process,
.name = "shm_dev_tx_node",
.init = dev_node_init,
.nb_edges = 1,
.next_nodes =
{
[0] = "pkt_drop",
},
};
RTE_NODE_REGISTER(dpdk_dev_rx_node_base);
RTE_NODE_REGISTER(dpdk_dev_tx_node_base);
RTE_NODE_REGISTER(shm_dev_rx_node_base);
RTE_NODE_REGISTER(shm_dev_tx_node_base);
int node_manager_dev_init(struct sc_main * sc, struct node_manager_main * node_mgr_main)
{
TAILQ_INIT(&p_dev_node_main->elems_head);
/* reference to sc_main */
p_dev_node_main->sc = sc;
unsigned int dev_desc_iterator = 0;
struct mr_dev_desc * dev_desc = NULL;
unsigned int nr_dpdk_devs = 0;
unsigned int nr_shm_devs = 0;
while ((dev_desc = mr_dev_desc_iterate(sc->devmgr_main, &dev_desc_iterator)) != NULL)
{
/* the bond's slave should not be rx/tx by itself */
if (dev_desc->is_bond_slave)
continue;
struct dev_node_elem * rx_node_elem = ZMALLOC(sizeof(struct dev_node_elem));
MR_VERIFY_MALLOC(rx_node_elem);
struct rte_node_register * rx_node_base = NULL;
struct rte_node_register * tx_node_base = NULL;
/* DPDK devices */
if (dev_desc->dpdk_dev_desc != NULL)
{
rx_node_base = &dpdk_dev_rx_node_base;
tx_node_base = &dpdk_dev_tx_node_base;
nr_dpdk_devs++;
}
/* shm devices */
else if (dev_desc->shm_dev_desc != NULL)
{
rx_node_base = &shm_dev_rx_node_base;
tx_node_base = &shm_dev_tx_node_base;
nr_shm_devs++;
}
assert(rx_node_base != NULL);
assert(tx_node_base != NULL);
rte_node_t rx_node_id = rte_node_clone(rx_node_base->id, dev_desc->symbol);
MR_VERIFY(rx_node_id != RTE_NODE_ID_INVALID);
rx_node_elem->nid = rx_node_id;
rx_node_elem->ctx.dev_desc = dev_desc;
TAILQ_INSERT_TAIL(&p_dev_node_main->elems_head, rx_node_elem, entries);
/* tx nodes */
struct dev_node_elem * tx_node_elem = ZMALLOC(sizeof(struct dev_node_elem));
MR_VERIFY_MALLOC(tx_node_elem);
rte_node_t tx_node_id = rte_node_clone(tx_node_base->id, dev_desc->symbol);
MR_VERIFY(tx_node_id != RTE_NODE_ID_INVALID);
tx_node_elem->nid = tx_node_id;
tx_node_elem->ctx.dev_desc = dev_desc;
TAILQ_INSERT_TAIL(&p_dev_node_main->elems_head, tx_node_elem, entries);
dev_desc->rx_node_id = rx_node_id;
dev_desc->tx_node_id = tx_node_id;
}
if (nr_dpdk_devs > 0)
{
node_setup_desc_add_for_all_workers(node_mgr_main, "dpdk_dev_rx_node-*");
node_setup_desc_add_for_all_workers(node_mgr_main, "dpdk_dev_tx_node-*");
}
if (nr_shm_devs > 0)
{
node_setup_desc_add_for_all_workers(node_mgr_main, "shm_dev_rx_node-*");
node_setup_desc_add_for_all_workers(node_mgr_main, "shm_dev_tx_node-*");
}
return 0;
}
int node_manager_phydev_deinit(struct node_manager_main * node_mgr_main)
{
return 0;
}
|