common: Adding common library for sample vnf
[samplevnf.git] / common / VIL / pipeline_txrx / pipeline_txrx.c
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 #include <cmdline_parse.h>
18 #include <cmdline_parse_num.h>
19 #include <cmdline_parse_string.h>
20 #include <cmdline_parse_ipaddr.h>
21 #include <cmdline_parse_etheraddr.h>
22
23 #include "app.h"
24 #include "pipeline_common_fe.h"
25 #include "pipeline_txrx.h"
26 #include "vnf_common.h"
27 //#include "lib_arp.h"
28 #include "pipeline_arpicmp_be.h"
29
30 static int
31 app_pipeline_txrx_entry_dbg(struct app_params *app,
32                                         uint32_t pipeline_id, uint8_t *msg)
33 {
34         struct pipeline_txrx_entry_dbg_msg_req *req;
35         struct pipeline_txrx_entry_dbg_msg_rsp *rsp;
36
37         /* Check input arguments */
38         if (app == NULL)
39                 return -1;
40
41         /* Allocate and write request */
42         req = app_msg_alloc(app);
43         if (req == NULL)
44                 return -1;
45
46         req->type = PIPELINE_MSG_REQ_CUSTOM;
47         req->subtype = PIPELINE_TXRX_MSG_REQ_ENTRY_DBG;
48         req->data[0] = msg[0];
49         req->data[1] = msg[1];
50
51         rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
52         if (rsp == NULL)
53                 return -1;
54
55         /* Read response */
56         if (rsp->status) {
57                 app_msg_free(app, rsp);
58                 printf("Error rsp->status %d\n", rsp->status);
59                 return -1;
60         }
61
62         /* Free response */
63         app_msg_free(app, rsp);
64
65         return 0;
66 }
67
68 /*
69  * entry dbg
70  */
71
72
73 struct cmd_entry_dbg_result {
74         cmdline_fixed_string_t p_string;
75         uint32_t p;
76         cmdline_fixed_string_t entry_string;
77         cmdline_fixed_string_t dbg_string;
78         uint8_t cmd;
79         uint8_t d1;
80 };
81
82 static void
83 cmd_entry_dbg_parsed(void *parsed_result,
84                                  __rte_unused struct cmdline *cl, void *data)
85 {
86         struct cmd_entry_dbg_result *params = parsed_result;
87         struct app_params *app = data;
88         uint8_t msg[2];
89         int status;
90
91         msg[0] = params->cmd;
92         msg[1] = params->d1;
93         status = app_pipeline_txrx_entry_dbg(app, params->p, msg);
94
95         if (status != 0) {
96                 printf("Dbg Command failed\n");
97                 return;
98         }
99 }
100
101 static cmdline_parse_token_string_t lb_cmd_entry_dbg_p_string =
102 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, p_string, "p");
103
104 static cmdline_parse_token_num_t lb_cmd_entry_dbg_p =
105 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, p, UINT32);
106
107 static cmdline_parse_token_string_t lb_cmd_entry_dbg_entry_string =
108 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result,
109                          entry_string, "txrx");
110
111 static cmdline_parse_token_string_t lb_cmd_entry_dbg_dbg_string =
112 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, dbg_string,
113                          "dbg");
114
115 static cmdline_parse_token_num_t lb_cmd_entry_dbg_cmd =
116 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, cmd, UINT8);
117
118 static cmdline_parse_token_num_t lb_cmd_entry_dbg_d1 =
119 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d1, UINT8);
120
121 static cmdline_parse_inst_t lb_cmd_entry_dbg = {
122         .f = cmd_entry_dbg_parsed,
123         .data = NULL,
124         .help_str = "TXRX dbg cmd",
125         .tokens = {
126                          (void *)&lb_cmd_entry_dbg_p_string,
127                          (void *)&lb_cmd_entry_dbg_p,
128                          (void *)&lb_cmd_entry_dbg_entry_string,
129                          (void *)&lb_cmd_entry_dbg_dbg_string,
130                          (void *)&lb_cmd_entry_dbg_cmd,
131                          (void *)&lb_cmd_entry_dbg_d1,
132                          NULL,
133                          },
134 };
135
136 static cmdline_parse_ctx_t pipeline_cmds[] = {
137         (cmdline_parse_inst_t *) &lb_cmd_entry_dbg,
138         NULL,
139 };
140
141 static struct pipeline_fe_ops pipeline_txrx_fe_ops = {
142         .f_init = NULL,
143         .f_free = NULL,
144         .cmds = pipeline_cmds,
145 };
146
147 struct pipeline_type pipeline_txrx = {
148         .name = "TXRX",
149         .be_ops = &pipeline_txrx_be_ops,
150         .fe_ops = &pipeline_txrx_fe_ops,
151 };