VCL: Set debug output level from env var
[vpp.git] / src / vcl / vppcom.h
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef included_vppcom_h
17 #define included_vppcom_h
18
19 #include <netdb.h>
20 #include <errno.h>
21 #include <sys/epoll.h>
22
23 /*
24  * VPPCOM Public API Definitions, Enums, and Data Structures
25  */
26 #define INVALID_SESSION_ID                   (~0)
27 #define VPPCOM_VRF_DEFAULT                   0
28 #define VPPCOM_CONF_DEFAULT                  "/etc/vpp/vcl.conf"
29 #define VPPCOM_ENV_CONF                      "VCL_CONFIG"
30 #define VPPCOM_ENV_DEBUG                     "VCL_DEBUG"
31 #define VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP   "VCL_APP_PROXY_TRANSPORT_TCP"
32 #define VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP   "VCL_APP_PROXY_TRANSPORT_UDP"
33 #define VPPCOM_ENV_APP_NAMESPACE_ID          "VCL_APP_NAMESPACE_ID"
34 #define VPPCOM_ENV_APP_NAMESPACE_SECRET      "VCL_APP_NAMESPACE_SECRET"
35 #define VPPCOM_ENV_APP_SCOPE_LOCAL           "VCL_APP_SCOPE_LOCAL"
36 #define VPPCOM_ENV_APP_SCOPE_GLOBAL          "VCL_APP_SCOPE_GLOBAL"
37
38 typedef enum
39 {
40   VPPCOM_PROTO_TCP = 0,
41   VPPCOM_PROTO_UDP,
42 } vppcom_proto_t;
43
44 typedef enum
45 {
46   VPPCOM_IS_IP6 = 0,
47   VPPCOM_IS_IP4,
48 } vppcom_is_ip4_t;
49
50 typedef struct vppcom_endpt_t_
51 {
52   uint32_t vrf;
53   uint8_t is_cut_thru;
54   uint8_t is_ip4;
55   uint8_t *ip;
56   uint16_t port;
57 } vppcom_endpt_t;
58
59 typedef enum
60 {
61   VPPCOM_OK = 0,
62   VPPCOM_EAGAIN = -EAGAIN,
63   VPPCOM_EINVAL = -EINVAL,
64   VPPCOM_EBADFD = -EBADFD,
65   VPPCOM_EAFNOSUPPORT = -EAFNOSUPPORT,
66   VPPCOM_ECONNRESET = -ECONNRESET,
67   VPPCOM_ECONNREFUSED = -ECONNREFUSED,
68   VPPCOM_ETIMEDOUT = -ETIMEDOUT,
69 } vppcom_error_t;
70
71 typedef enum
72 {
73   VPPCOM_ATTR_GET_NREAD,
74   VPPCOM_ATTR_PEEK_NREAD,
75   VPPCOM_ATTR_GET_FLAGS,
76   VPPCOM_ATTR_SET_FLAGS,
77   VPPCOM_ATTR_GET_LCL_ADDR,
78   VPPCOM_ATTR_GET_PEER_ADDR,
79   VPPCOM_ATTR_SET_REUSEADDR,
80   VPPCOM_ATTR_SET_BROADCAST,
81   VPPCOM_ATTR_SET_V6ONLY,
82   VPPCOM_ATTR_SET_KEEPALIVE,
83   VPPCOM_ATTR_SET_TCP_KEEPIDLE,
84   VPPCOM_ATTR_SET_TCP_KEEPINTVL,
85 } vppcom_attr_op_t;
86
87 /*
88  * VPPCOM Public API Functions
89  */
90 static inline const char *
91 vppcom_retval_str (int retval)
92 {
93   char *st;
94
95   switch (retval)
96     {
97     case VPPCOM_OK:
98       st = "VPPCOM_OK";
99       break;
100
101     case VPPCOM_EAGAIN:
102       st = "VPPCOM_EAGAIN";
103       break;
104
105     case VPPCOM_EINVAL:
106       st = "VPPCOM_EINVAL";
107       break;
108
109     case VPPCOM_EBADFD:
110       st = "VPPCOM_EBADFD";
111       break;
112
113     case VPPCOM_EAFNOSUPPORT:
114       st = "VPPCOM_EAFNOSUPPORT";
115       break;
116
117     case VPPCOM_ECONNRESET:
118       st = "VPPCOM_ECONNRESET";
119       break;
120
121     case VPPCOM_ECONNREFUSED:
122       st = "VPPCOM_ECONNREFUSED";
123       break;
124
125     case VPPCOM_ETIMEDOUT:
126       st = "VPPCOM_ETIMEDOUT";
127       break;
128
129     default:
130       st = "UNKNOWN_STATE";
131       break;
132     }
133
134   return st;
135 }
136
137 /* TBD: make these constructor/destructor function */
138 extern int vppcom_app_create (char *app_name);
139 extern void vppcom_app_destroy (void);
140
141 extern int vppcom_session_create (uint32_t vrf, uint8_t proto,
142                                   uint8_t is_nonblocking);
143 extern int vppcom_session_close (uint32_t session_index);
144
145 extern int vppcom_session_bind (uint32_t session_index, vppcom_endpt_t * ep);
146 extern int vppcom_session_listen (uint32_t session_index, uint32_t q_len);
147 extern int vppcom_session_accept (uint32_t session_index,
148                                   vppcom_endpt_t * client_ep,
149                                   double wait_for_time);
150
151 extern int vppcom_session_connect (uint32_t session_index,
152                                    vppcom_endpt_t * server_ep);
153 extern int vppcom_session_read (uint32_t session_index, void *buf, int n);
154 extern int vppcom_session_write (uint32_t session_index, void *buf, int n);
155
156 extern int vppcom_select (unsigned long n_bits,
157                           unsigned long *read_map,
158                           unsigned long *write_map,
159                           unsigned long *except_map, double wait_for_time);
160
161 extern int vppcom_epoll_create (void);
162 extern int vppcom_epoll_ctl (uint32_t vep_idx, int op,
163                              uint32_t session_index,
164                              struct epoll_event *event);
165 extern int vppcom_epoll_wait (uint32_t vep_idx, struct epoll_event *events,
166                               int maxevents, double wait_for_time);
167 extern int vppcom_session_attr (uint32_t session_index, uint32_t op,
168                                 void *buffer, uint32_t * buflen);
169 extern int vppcom_session_recvfrom (uint32_t session_index, void *buffer,
170                                     uint32_t buflen, int flags,
171                                     vppcom_endpt_t * ep);
172 extern int vppcom_session_sendto (uint32_t session_index, void *buffer,
173                                   uint32_t buflen, int flags,
174                                   vppcom_endpt_t * ep);
175
176 #endif /* included_vppcom_h */
177
178 /*
179  * fd.io coding-style-patch-verification: ON
180  *
181  * Local Variables:
182  * eval: (c-set-style "gnu")
183  * End:
184  */