blob: 5511f0465159c7b70db0587f25c6251f48f554c1 [file] [log] [blame]
Dave Wallace543852a2017-08-03 02:11:34 -04001/*
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>
Dave Wallacef7f809c2017-10-03 01:48:42 -040021#include <sys/epoll.h>
Dave Wallace543852a2017-08-03 02:11:34 -040022
23/*
24 * VPPCOM Public API Definitions, Enums, and Data Structures
25 */
Dave Wallace774169b2017-11-01 20:07:40 -040026#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"
Dave Wallace498b3a52017-11-09 13:00:34 -050030#define VPPCOM_ENV_DEBUG "VCL_DEBUG"
Dave Wallace774169b2017-11-01 20:07:40 -040031#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"
Dave Wallace543852a2017-08-03 02:11:34 -040037
38typedef enum
39{
40 VPPCOM_PROTO_TCP = 0,
41 VPPCOM_PROTO_UDP,
42} vppcom_proto_t;
43
44typedef enum
45{
46 VPPCOM_IS_IP6 = 0,
47 VPPCOM_IS_IP4,
48} vppcom_is_ip4_t;
49
50typedef 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
59typedef enum
60{
61 VPPCOM_OK = 0,
62 VPPCOM_EAGAIN = -EAGAIN,
Dave Wallace60caa062017-11-10 17:07:13 -050063 VPPCOM_ENOMEM = -ENOMEM,
Dave Wallace543852a2017-08-03 02:11:34 -040064 VPPCOM_EINVAL = -EINVAL,
65 VPPCOM_EBADFD = -EBADFD,
66 VPPCOM_EAFNOSUPPORT = -EAFNOSUPPORT,
Dave Wallaceee45d412017-11-24 21:44:06 -050067 VPPCOM_ECONNABORTED = -ECONNABORTED,
Dave Wallace543852a2017-08-03 02:11:34 -040068 VPPCOM_ECONNRESET = -ECONNRESET,
Dave Wallace4878cbe2017-11-21 03:45:09 -050069 VPPCOM_ENOTCONN = -ENOTCONN,
Dave Wallace543852a2017-08-03 02:11:34 -040070 VPPCOM_ECONNREFUSED = -ECONNREFUSED,
71 VPPCOM_ETIMEDOUT = -ETIMEDOUT,
72} vppcom_error_t;
73
Dave Wallace35830af2017-10-09 01:43:42 -040074typedef enum
75{
76 VPPCOM_ATTR_GET_NREAD,
Dave Wallace227867f2017-11-13 21:21:53 -050077 VPPCOM_ATTR_GET_NWRITE,
Dave Wallace35830af2017-10-09 01:43:42 -040078 VPPCOM_ATTR_GET_FLAGS,
79 VPPCOM_ATTR_SET_FLAGS,
80 VPPCOM_ATTR_GET_LCL_ADDR,
81 VPPCOM_ATTR_GET_PEER_ADDR,
Stevenb5a11602017-10-11 09:59:30 -070082 VPPCOM_ATTR_SET_REUSEADDR,
83 VPPCOM_ATTR_SET_BROADCAST,
84 VPPCOM_ATTR_SET_V6ONLY,
Stevenbccd3392017-10-12 20:42:21 -070085 VPPCOM_ATTR_SET_KEEPALIVE,
86 VPPCOM_ATTR_SET_TCP_KEEPIDLE,
87 VPPCOM_ATTR_SET_TCP_KEEPINTVL,
Dave Wallace35830af2017-10-09 01:43:42 -040088} vppcom_attr_op_t;
89
Dave Wallace543852a2017-08-03 02:11:34 -040090/*
91 * VPPCOM Public API Functions
92 */
93static inline const char *
94vppcom_retval_str (int retval)
95{
96 char *st;
97
98 switch (retval)
99 {
100 case VPPCOM_OK:
101 st = "VPPCOM_OK";
102 break;
103
104 case VPPCOM_EAGAIN:
105 st = "VPPCOM_EAGAIN";
106 break;
107
Dave Wallacee376f932017-11-19 11:20:02 -0500108 case VPPCOM_ENOMEM:
109 st = "VPPCOM_ENOMEM";
110 break;
111
Dave Wallace543852a2017-08-03 02:11:34 -0400112 case VPPCOM_EINVAL:
113 st = "VPPCOM_EINVAL";
114 break;
115
116 case VPPCOM_EBADFD:
117 st = "VPPCOM_EBADFD";
118 break;
119
120 case VPPCOM_EAFNOSUPPORT:
121 st = "VPPCOM_EAFNOSUPPORT";
122 break;
123
Dave Wallaceee45d412017-11-24 21:44:06 -0500124 case VPPCOM_ECONNABORTED:
125 st = "VPPCOM_ECONNABORTED";
126 break;
127
Dave Wallace543852a2017-08-03 02:11:34 -0400128 case VPPCOM_ECONNRESET:
129 st = "VPPCOM_ECONNRESET";
130 break;
131
Dave Wallace4878cbe2017-11-21 03:45:09 -0500132 case VPPCOM_ENOTCONN:
133 st = "VPPCOM_ENOTCONN";
134 break;
135
Dave Wallace543852a2017-08-03 02:11:34 -0400136 case VPPCOM_ECONNREFUSED:
137 st = "VPPCOM_ECONNREFUSED";
138 break;
139
140 case VPPCOM_ETIMEDOUT:
141 st = "VPPCOM_ETIMEDOUT";
142 break;
143
144 default:
145 st = "UNKNOWN_STATE";
146 break;
147 }
148
149 return st;
150}
151
Dave Wallace543852a2017-08-03 02:11:34 -0400152/* TBD: make these constructor/destructor function */
153extern int vppcom_app_create (char *app_name);
154extern void vppcom_app_destroy (void);
155
156extern int vppcom_session_create (uint32_t vrf, uint8_t proto,
157 uint8_t is_nonblocking);
158extern int vppcom_session_close (uint32_t session_index);
159
160extern int vppcom_session_bind (uint32_t session_index, vppcom_endpt_t * ep);
161extern int vppcom_session_listen (uint32_t session_index, uint32_t q_len);
162extern int vppcom_session_accept (uint32_t session_index,
163 vppcom_endpt_t * client_ep,
Dave Wallace227867f2017-11-13 21:21:53 -0500164 uint32_t flags, double wait_for_time);
Dave Wallace543852a2017-08-03 02:11:34 -0400165
166extern int vppcom_session_connect (uint32_t session_index,
167 vppcom_endpt_t * server_ep);
168extern int vppcom_session_read (uint32_t session_index, void *buf, int n);
169extern int vppcom_session_write (uint32_t session_index, void *buf, int n);
170
171extern int vppcom_select (unsigned long n_bits,
172 unsigned long *read_map,
173 unsigned long *write_map,
174 unsigned long *except_map, double wait_for_time);
175
Dave Wallacef7f809c2017-10-03 01:48:42 -0400176extern int vppcom_epoll_create (void);
177extern int vppcom_epoll_ctl (uint32_t vep_idx, int op,
178 uint32_t session_index,
179 struct epoll_event *event);
180extern int vppcom_epoll_wait (uint32_t vep_idx, struct epoll_event *events,
181 int maxevents, double wait_for_time);
Dave Wallace35830af2017-10-09 01:43:42 -0400182extern int vppcom_session_attr (uint32_t session_index, uint32_t op,
183 void *buffer, uint32_t * buflen);
Stevenac1f96d2017-10-24 16:03:58 -0700184extern int vppcom_session_recvfrom (uint32_t session_index, void *buffer,
185 uint32_t buflen, int flags,
186 vppcom_endpt_t * ep);
187extern int vppcom_session_sendto (uint32_t session_index, void *buffer,
188 uint32_t buflen, int flags,
189 vppcom_endpt_t * ep);
Dave Wallacef7f809c2017-10-03 01:48:42 -0400190
Dave Wallace543852a2017-08-03 02:11:34 -0400191#endif /* included_vppcom_h */
192
193/*
194 * fd.io coding-style-patch-verification: ON
195 *
196 * Local Variables:
197 * eval: (c-set-style "gnu")
198 * End:
199 */