REST_API: rest api client implementation
[samplevnf.git] / common / VIL / pipeline_common / pipeline_common_fe.h
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #ifndef __INCLUDE_PIPELINE_COMMON_FE_H__
18 #define __INCLUDE_PIPELINE_COMMON_FE_H__
19
20 #include <rte_common.h>
21 #include <rte_cycles.h>
22 #include <rte_malloc.h>
23 #include <cmdline_parse.h>
24
25 #include "pipeline_common_be.h"
26 #include "pipeline.h"
27 #include "app.h"
28
29 #ifndef MSG_TIMEOUT_DEFAULT
30 #define MSG_TIMEOUT_DEFAULT                      1000
31 #endif
32 struct app_link_params mylink[APP_MAX_LINKS];
33 static inline struct app_pipeline_data *
34 app_pipeline_data(struct app_params *app, uint32_t id)
35 {
36         struct app_pipeline_params *params;
37
38         APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", id, params);
39         if (params == NULL)
40                 return NULL;
41
42         return &app->pipeline_data[params - app->pipeline_params];
43 }
44
45 static inline void *
46 app_pipeline_data_fe(struct app_params *app, uint32_t id, struct pipeline_type *ptype)
47 {
48         struct app_pipeline_data *pipeline_data;
49
50         pipeline_data = app_pipeline_data(app, id);
51         if (pipeline_data == NULL)
52                 return NULL;
53
54         if (strcmp(pipeline_data->ptype->name, ptype->name) != 0)
55                 return NULL;
56
57         if (pipeline_data->enabled == 0)
58                 return NULL;
59
60         return pipeline_data->fe;
61 }
62
63 static inline struct rte_ring *
64 app_pipeline_msgq_in_get(struct app_params *app,
65         uint32_t pipeline_id)
66 {
67         struct app_msgq_params *p;
68
69         APP_PARAM_FIND_BY_ID(app->msgq_params,
70                 "MSGQ-REQ-PIPELINE",
71                 pipeline_id,
72                 p);
73         if (p == NULL)
74                 return NULL;
75
76         return app->msgq[p - app->msgq_params];
77 }
78
79 static inline struct rte_ring *
80 app_pipeline_msgq_out_get(struct app_params *app,
81         uint32_t pipeline_id)
82 {
83         struct app_msgq_params *p;
84
85         APP_PARAM_FIND_BY_ID(app->msgq_params,
86                 "MSGQ-RSP-PIPELINE",
87                 pipeline_id,
88                 p);
89         if (p == NULL)
90                 return NULL;
91
92         return app->msgq[p - app->msgq_params];
93 }
94
95 static inline void *
96 app_msg_alloc(__rte_unused struct app_params *app)
97 {
98         return rte_malloc(NULL, 2048, RTE_CACHE_LINE_SIZE);
99 }
100
101 static inline void
102 app_msg_free(__rte_unused struct app_params *app,
103         void *msg)
104 {
105         rte_free(msg);
106 }
107
108 static inline void
109 app_msg_send(struct app_params *app,
110         uint32_t pipeline_id,
111         void *msg)
112 {
113         struct rte_ring *r = app_pipeline_msgq_in_get(app, pipeline_id);
114         int status;
115
116         do {
117                 status = rte_ring_sp_enqueue(r, msg);
118         } while (status == -ENOBUFS);
119 }
120
121 static inline void *
122 app_msg_recv(struct app_params *app,
123         uint32_t pipeline_id)
124 {
125         struct rte_ring *r = app_pipeline_msgq_out_get(app, pipeline_id);
126         void *msg;
127         int status = rte_ring_sc_dequeue(r, &msg);
128
129         if (status != 0)
130                 return NULL;
131
132         return msg;
133 }
134
135 static inline void *
136 app_msg_send_recv(struct app_params *app,
137         uint32_t pipeline_id,
138         void *msg,
139         uint32_t timeout_ms)
140 {
141         struct rte_ring *r_req = app_pipeline_msgq_in_get(app, pipeline_id);
142         struct rte_ring *r_rsp = app_pipeline_msgq_out_get(app, pipeline_id);
143         uint64_t hz = rte_get_tsc_hz();
144         void *msg_recv = NULL;
145         uint64_t deadline;
146         int status = 0;
147
148         /* send */
149         do {
150                 if(r_req)
151                 status = rte_ring_sp_enqueue(r_req, (void *) msg);
152         } while (status == -ENOBUFS);
153
154         /* recv */
155         deadline = (timeout_ms) ?
156                 (rte_rdtsc() + ((hz * timeout_ms) / 1000)) :
157                 UINT64_MAX;
158
159         do {
160                 if (rte_rdtsc() > deadline)
161                         return NULL;
162                  if (r_rsp)
163                 status = rte_ring_sc_dequeue(r_rsp, &msg_recv);
164         } while (status != 0);
165
166         return msg_recv;
167 }
168
169 int
170 app_pipeline_ping(struct app_params *app,
171         uint32_t pipeline_id);
172
173 int
174 app_pipeline_stats_port_in(struct app_params *app,
175         uint32_t pipeline_id,
176         uint32_t port_id,
177         struct rte_pipeline_port_in_stats *stats);
178
179 int
180 app_pipeline_stats_port_out(struct app_params *app,
181         uint32_t pipeline_id,
182         uint32_t port_id,
183         struct rte_pipeline_port_out_stats *stats);
184
185 int
186 app_pipeline_stats_table(struct app_params *app,
187         uint32_t pipeline_id,
188         uint32_t table_id,
189         struct rte_pipeline_table_stats *stats);
190
191 int
192 app_pipeline_port_in_enable(struct app_params *app,
193         uint32_t pipeline_id,
194         uint32_t port_id);
195
196 int
197 app_pipeline_port_in_disable(struct app_params *app,
198         uint32_t pipeline_id,
199         uint32_t port_id);
200
201 int
202 app_link_config(struct app_params *app,
203         uint32_t link_id,
204         uint32_t ip,
205         uint32_t depth);
206
207 int
208 app_link_up(struct app_params *app,
209         uint32_t link_id);
210
211 int
212 app_link_down(struct app_params *app,
213         uint32_t link_id);
214
215 int
216 app_pipeline_common_cmd_push(struct app_params *app);
217
218
219 void convert_prefixlen_to_netmask_ipv6(uint32_t depth, uint8_t netmask_ipv6[]);
220
221 void
222 get_host_portion_ipv6(uint8_t ipv6[], uint8_t netmask[], uint8_t host_ipv6[]);
223
224 void
225 get_bcast_portion_ipv6(uint8_t host[], uint8_t netmask[], uint8_t bcast_ipv6[]);
226
227 int
228 app_link_config_ipv6(struct app_params *app,
229                                  uint32_t link_id, uint8_t ipv6[], uint32_t depth);
230
231 int app_routeadd_config_ipv4( __attribute__((unused)) struct app_params *app,
232         uint32_t port_id, uint32_t ip, uint32_t mask);
233
234 int app_routeadd_config_ipv6( __attribute__((unused)) struct app_params *app,
235         uint32_t port_id, uint8_t ipv6[], uint32_t depth);
236
237 #endif