FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
nsim_input.c
Go to the documentation of this file.
1
/*
2
* nsim.c - skeleton vpp engine plug-in
3
*
4
* Copyright (c) <current-year> <your-organization>
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at:
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*/
17
18
#include <
vlib/vlib.h
>
19
#include <
vnet/vnet.h
>
20
#include <
vppinfra/error.h
>
21
#include <
nsim/nsim.h
>
22
23
typedef
struct
24
{
25
f64
expired
;
26
u32
next_index
;
27
}
nsim_tx_trace_t
;
28
29
#ifndef CLIB_MARCH_VARIANT
30
/* packet trace format function */
31
static
u8
*
32
format_nsim_tx_trace
(
u8
* s, va_list * args)
33
{
34
CLIB_UNUSED
(
vlib_main_t
*
vm
) = va_arg (*args,
vlib_main_t
*);
35
CLIB_UNUSED
(
vlib_node_t
*
node
) = va_arg (*args,
vlib_node_t
*);
36
nsim_tx_trace_t
*t = va_arg (*args,
nsim_tx_trace_t
*);
37
38
s =
format
(s,
"NSIM: tx at %.6f next_index %d"
, t->
expired
, t->
next_index
);
39
return
s;
40
}
41
#endif
/* CLIB_MARCH_VARIANT */
42
43
#define foreach_nsim_tx_error \
44
_(TRANSMITTED, "Packets transmitted")
45
46
typedef
enum
47
{
48
#define _(sym,str) NSIM_TX_ERROR_##sym,
49
foreach_nsim_tx_error
50
#undef _
51
NSIM_TX_N_ERROR
,
52
}
nsim_tx_error_t
;
53
54
#ifndef CLIB_MARCH_VARIANT
55
static
char
*
nsim_tx_error_strings
[] = {
56
#define _(sym,string) string,
57
foreach_nsim_tx_error
58
#undef _
59
};
60
#endif
/* CLIB_MARCH_VARIANT */
61
62
typedef
enum
63
{
64
NSIM_NEXT_DROP
,
65
NSIM_N_NEXT
,
66
}
nsim_next_t
;
67
68
always_inline
uword
69
nsim_input_inline
(
vlib_main_t
*
vm
,
vlib_node_runtime_t
*
node
,
70
vlib_frame_t
*
f
,
int
is_trace)
71
{
72
nsim_main_t
*nsm = &
nsim_main
;
73
nsim_wheel_t
*wp = nsm->
wheel_by_thread
[
vm
->
thread_index
];
74
nsim_wheel_entry_t
*ep;
75
f64
now
;
76
77
/* Nothing on the scheduler wheel? */
78
if
(wp->
cursize
== 0)
79
return
0;
80
81
/* First entry on the wheel isn't expired? */
82
ep = wp->
entries
+ wp->
head
;
83
now
=
vlib_time_now
(
vm
);
84
if
(ep->
tx_time
>
now
)
85
return
0;
86
87
u32
n_burst =
clib_min
(wp->
cursize
,
NSIM_MAX_TX_BURST
), n_tx_packets = 0;
88
u32
froms[
NSIM_MAX_TX_BURST
], *
from
;
89
u16
nexts
[
NSIM_MAX_TX_BURST
], *
next
;
90
91
from
= froms;
92
next
=
nexts
;
93
while
(n_tx_packets < n_burst && ep->tx_time <=
now
)
94
{
95
/* prefetch one line / 2 entries ahead */
96
if
((((
uword
) ep) & (
CLIB_CACHE_LINE_BYTES
- 1)) == 0)
97
CLIB_PREFETCH
((ep + 2),
CLIB_CACHE_LINE_BYTES
, LOAD);
98
99
ep = wp->
entries
+ wp->
head
;
100
from
[0] = ep->buffer_index;
101
next
[0] = ep->output_next_index;
102
103
wp->
head
++;
104
if
(wp->
head
== wp->
wheel_size
)
105
wp->
head
= 0;
106
107
from
+= 1;
108
next
+= 1;
109
n_tx_packets++;
110
}
111
112
wp->
cursize
-= n_tx_packets;
113
vlib_buffer_enqueue_to_next
(
vm
,
node
, froms,
nexts
, n_tx_packets);
114
vlib_node_increment_counter
(
vm
,
node
->node_index,
115
NSIM_TX_ERROR_TRANSMITTED, n_tx_packets);
116
return
n_tx_packets;
117
}
118
119
VLIB_NODE_FN
(
nsim_input_node
) (
vlib_main_t
*
vm
,
vlib_node_runtime_t
*
node
,
120
vlib_frame_t
*
frame
)
121
{
122
if
(
PREDICT_FALSE
(
node
->flags &
VLIB_NODE_FLAG_TRACE
))
123
return
nsim_input_inline
(
vm
,
node
,
frame
, 1
/* is_trace */
);
124
else
125
return
nsim_input_inline
(
vm
,
node
,
frame
, 0
/* is_trace */
);
126
127
}
128
129
/* *INDENT-OFF* */
130
#ifndef CLIB_MARCH_VARIANT
131
VLIB_REGISTER_NODE
(
nsim_input_node
) =
132
{
133
.type =
VLIB_NODE_TYPE_INPUT
,
134
.name =
"nsim-wheel"
,
135
136
/* Will be enabled if/when the feature is configured */
137
.state = VLIB_NODE_STATE_DISABLED,
138
139
.format_trace =
format_nsim_tx_trace
,
140
141
.n_errors =
NSIM_TX_N_ERROR
,
142
.error_strings =
nsim_tx_error_strings
,
143
};
144
#endif
/* CLIB_MARCH_VARIANT */
145
/* *INDENT-ON* */
146
147
/*
148
* fd.io coding-style-patch-verification: ON
149
*
150
* Local Variables:
151
* eval: (c-set-style "gnu")
152
* End:
153
*/
vlib.h
nsim_next_t
nsim_next_t
Definition:
nsim_input.c:62
nsim_tx_error_strings
static char * nsim_tx_error_strings[]
Definition:
nsim_input.c:55
format_nsim_tx_trace
static u8 * format_nsim_tx_trace(u8 *s, va_list *args)
Definition:
nsim_input.c:32
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition:
nat44_ei.c:3048
NSIM_NEXT_DROP
@ NSIM_NEXT_DROP
Definition:
nsim_input.c:64
NSIM_MAX_TX_BURST
#define NSIM_MAX_TX_BURST
max packets in a tx burst
Definition:
nsim.h:28
f
vlib_frame_t * f
Definition:
interface_output.c:1080
nsim_input_inline
static uword nsim_input_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f, int is_trace)
Definition:
nsim_input.c:69
next
u16 * next
Definition:
nat44_ei_out2in.c:718
node
vlib_main_t vlib_node_runtime_t * node
Definition:
nat44_ei.c:3047
nsim_tx_error_t
nsim_tx_error_t
Definition:
nsim_input.c:46
nsim_wheel_entry_t::tx_time
f64 tx_time
Definition:
nsim.h:32
VLIB_NODE_TYPE_INPUT
@ VLIB_NODE_TYPE_INPUT
Definition:
node.h:76
u16
unsigned short u16
Definition:
types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition:
nat44_ei.c:3047
vlib_buffer_enqueue_to_next
vlib_buffer_enqueue_to_next(vm, node, from,(u16 *) nexts, frame->n_vectors)
NSIM_TX_N_ERROR
@ NSIM_TX_N_ERROR
Definition:
nsim_input.c:51
nsim_wheel_t
Definition:
nsim.h:40
vlib_frame_t
Definition:
node.h:372
CLIB_PREFETCH
#define CLIB_PREFETCH(addr, size, type)
Definition:
cache.h:80
error.h
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition:
node.h:202
nsim_wheel_entry_t
Definition:
nsim.h:30
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition:
clib.h:90
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition:
node.h:291
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition:
clib.h:124
uword
u64 uword
Definition:
types.h:112
vlib_main_t::thread_index
u32 thread_index
Definition:
main.h:213
vlib_node_increment_counter
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition:
node_funcs.h:1244
f64
double f64
Definition:
types.h:142
clib_min
#define clib_min(x, y)
Definition:
clib.h:342
nsim_main
nsim_main_t nsim_main
Definition:
nsim.c:39
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition:
cache.h:59
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
nsim_main_t::wheel_by_thread
nsim_wheel_t ** wheel_by_thread
Definition:
nsim.h:99
nsim_tx_trace_t
Definition:
nsim_input.c:23
nsim_wheel_t::head
u32 head
Definition:
nsim.h:44
always_inline
#define always_inline
Definition:
rdma_mlx5dv.h:23
format
description fragment has unexpected format
Definition:
map.api:433
nsim_input_node
vlib_node_registration_t nsim_input_node
(constructor) VLIB_REGISTER_NODE (nsim_input_node)
Definition:
nsim_input.c:131
u32
unsigned int u32
Definition:
types.h:88
NSIM_N_NEXT
@ NSIM_N_NEXT
Definition:
nsim_input.c:65
nsim_wheel_t::cursize
u32 cursize
Definition:
nsim.h:43
nsim_main_t
Definition:
nsim.h:80
nsim_wheel_t::entries
nsim_wheel_entry_t * entries
Definition:
nsim.h:46
nsim_wheel_t::wheel_size
u32 wheel_size
Definition:
nsim.h:42
now
f64 now
Definition:
nat44_ei_out2in.c:710
vlib_main_t
Definition:
main.h:102
vlib_node_t
Definition:
node.h:247
u8
unsigned char u8
Definition:
types.h:56
nsim_tx_trace_t::expired
f64 expired
Definition:
nsim_input.c:25
nsim_tx_trace_t::next_index
u32 next_index
Definition:
nsim_input.c:26
nexts
u16 nexts[VLIB_FRAME_SIZE]
Definition:
nat44_ei_out2in.c:718
vlib_time_now
static f64 vlib_time_now(vlib_main_t *vm)
Definition:
main.h:325
vnet.h
vlib_node_runtime_t
Definition:
node.h:454
from
from
Definition:
nat44_ei_hairpinning.c:415
foreach_nsim_tx_error
#define foreach_nsim_tx_error
Definition:
nsim_input.c:43
nsim.h
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition:
node.h:169
src
plugins
nsim
nsim_input.c
Generated on Sat Jan 8 2022 10:04:19 for FD.io VPP by
1.8.17