nsim: basic reorder support
[vpp.git] / src / plugins / nsim / nsim.h
1
2 /*
3  * nsim.h - skeleton vpp engine plug-in header file
4  *
5  * Copyright (c) <current-year> <your-organization>
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #ifndef __included_nsim_h__
19 #define __included_nsim_h__
20
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/ethernet/ethernet.h>
24
25 #include <vppinfra/hash.h>
26 #include <vppinfra/error.h>
27
28 typedef struct
29 {
30   f64 tx_time;
31   u32 rx_sw_if_index;
32   u32 tx_sw_if_index;
33   u32 output_next_index;
34   u32 buffer_index;
35   u32 pad;                      /* pad to 32-bytes */
36 } nsim_wheel_entry_t;
37
38 typedef struct
39 {
40   u32 wheel_size;
41   u32 cursize;
42   u32 head;
43   u32 tail;
44   nsim_wheel_entry_t *entries;
45     CLIB_CACHE_LINE_ALIGN_MARK (pad);
46 } nsim_wheel_t;
47
48 typedef struct nsim_node_ctx
49 {
50   vnet_feature_config_main_t *fcm;
51   f64 expires;
52   u32 *drop;
53   u32 *reord;
54   u16 *reord_nexts;
55   u8 *action;
56   u64 n_buffered;
57   u64 n_loss;
58 } nsim_node_ctx_t;
59
60 #define foreach_nsm_action                      \
61   _(DROP, "Packet loss")                        \
62   _(REORDER, "Packet reorder")
63
64 enum nsm_action_bit
65 {
66 #define _(sym, str) NSIM_ACTION_##sym##_BIT,
67   foreach_nsm_action
68 #undef _
69 };
70
71 typedef enum nsm_action
72 {
73 #define _(sym, str) NSIM_ACTION_##sym = 1 << NSIM_ACTION_##sym##_BIT,
74   foreach_nsm_action
75 #undef _
76 } nsm_action_e;
77
78 typedef struct
79 {
80   /* API message ID base */
81   u16 msg_id_base;
82
83   /* output feature arc index */
84   u16 arc_index;
85
86   /* Two interfaces, cross-connected with delay */
87   u32 sw_if_index0, sw_if_index1;
88   u32 output_next_index0, output_next_index1;
89
90   /* N interfaces, using the output feature */
91   u32 *output_next_index_by_sw_if_index;
92
93   /* Random seed for loss-rate simulation */
94   u32 seed;
95
96   /* Per-thread scheduler wheels */
97   nsim_wheel_t **wheel_by_thread;
98
99   /* Config parameters */
100   f64 delay;
101   f64 bandwidth;
102   f64 packet_size;
103   f64 drop_fraction;
104   f64 reorder_fraction;
105   u32 poll_main_thread;
106
107   u64 mmap_size;
108
109   /* Wheels are configured */
110   int is_configured;
111
112   /* convenience */
113   vlib_main_t *vlib_main;
114   vnet_main_t *vnet_main;
115 } nsim_main_t;
116
117 extern nsim_main_t nsim_main;
118
119 extern vlib_node_registration_t nsim_node;
120 extern vlib_node_registration_t nsim_input_node;
121
122 #endif /* __included_nsim_h__ */
123
124 /*
125  * fd.io coding-style-patch-verification: ON
126  *
127  * Local Variables:
128  * eval: (c-set-style "gnu")
129  * End:
130  */