blob: a20ff14a32eabb56df8ed175915f9fd674b03012 [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"
30#define VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP "VCL_APP_PROXY_TRANSPORT_TCP"
31#define VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP "VCL_APP_PROXY_TRANSPORT_UDP"
32#define VPPCOM_ENV_APP_NAMESPACE_ID "VCL_APP_NAMESPACE_ID"
33#define VPPCOM_ENV_APP_NAMESPACE_SECRET "VCL_APP_NAMESPACE_SECRET"
34#define VPPCOM_ENV_APP_SCOPE_LOCAL "VCL_APP_SCOPE_LOCAL"
35#define VPPCOM_ENV_APP_SCOPE_GLOBAL "VCL_APP_SCOPE_GLOBAL"
Dave Wallace543852a2017-08-03 02:11:34 -040036
37typedef enum
38{
39 VPPCOM_PROTO_TCP = 0,
40 VPPCOM_PROTO_UDP,
41} vppcom_proto_t;
42
43typedef enum
44{
45 VPPCOM_IS_IP6 = 0,
46 VPPCOM_IS_IP4,
47} vppcom_is_ip4_t;
48
49typedef struct vppcom_endpt_t_
50{
51 uint32_t vrf;
52 uint8_t is_cut_thru;
53 uint8_t is_ip4;
54 uint8_t *ip;
55 uint16_t port;
56} vppcom_endpt_t;
57
58typedef enum
59{
60 VPPCOM_OK = 0,
61 VPPCOM_EAGAIN = -EAGAIN,
62 VPPCOM_EINVAL = -EINVAL,
63 VPPCOM_EBADFD = -EBADFD,
64 VPPCOM_EAFNOSUPPORT = -EAFNOSUPPORT,
65 VPPCOM_ECONNRESET = -ECONNRESET,
66 VPPCOM_ECONNREFUSED = -ECONNREFUSED,
67 VPPCOM_ETIMEDOUT = -ETIMEDOUT,
68} vppcom_error_t;
69
Dave Wallace35830af2017-10-09 01:43:42 -040070typedef enum
71{
72 VPPCOM_ATTR_GET_NREAD,
73 VPPCOM_ATTR_PEEK_NREAD,
74 VPPCOM_ATTR_GET_FLAGS,
75 VPPCOM_ATTR_SET_FLAGS,
76 VPPCOM_ATTR_GET_LCL_ADDR,
77 VPPCOM_ATTR_GET_PEER_ADDR,
Stevenb5a11602017-10-11 09:59:30 -070078 VPPCOM_ATTR_SET_REUSEADDR,
79 VPPCOM_ATTR_SET_BROADCAST,
80 VPPCOM_ATTR_SET_V6ONLY,
Stevenbccd3392017-10-12 20:42:21 -070081 VPPCOM_ATTR_SET_KEEPALIVE,
82 VPPCOM_ATTR_SET_TCP_KEEPIDLE,
83 VPPCOM_ATTR_SET_TCP_KEEPINTVL,
Dave Wallace35830af2017-10-09 01:43:42 -040084} vppcom_attr_op_t;
85
Dave Wallace543852a2017-08-03 02:11:34 -040086/*
87 * VPPCOM Public API Functions
88 */
89static inline const char *
90vppcom_retval_str (int retval)
91{
92 char *st;
93
94 switch (retval)
95 {
96 case VPPCOM_OK:
97 st = "VPPCOM_OK";
98 break;
99
100 case VPPCOM_EAGAIN:
101 st = "VPPCOM_EAGAIN";
102 break;
103
104 case VPPCOM_EINVAL:
105 st = "VPPCOM_EINVAL";
106 break;
107
108 case VPPCOM_EBADFD:
109 st = "VPPCOM_EBADFD";
110 break;
111
112 case VPPCOM_EAFNOSUPPORT:
113 st = "VPPCOM_EAFNOSUPPORT";
114 break;
115
116 case VPPCOM_ECONNRESET:
117 st = "VPPCOM_ECONNRESET";
118 break;
119
120 case VPPCOM_ECONNREFUSED:
121 st = "VPPCOM_ECONNREFUSED";
122 break;
123
124 case VPPCOM_ETIMEDOUT:
125 st = "VPPCOM_ETIMEDOUT";
126 break;
127
128 default:
129 st = "UNKNOWN_STATE";
130 break;
131 }
132
133 return st;
134}
135
Dave Wallace543852a2017-08-03 02:11:34 -0400136/* TBD: make these constructor/destructor function */
137extern int vppcom_app_create (char *app_name);
138extern void vppcom_app_destroy (void);
139
140extern int vppcom_session_create (uint32_t vrf, uint8_t proto,
141 uint8_t is_nonblocking);
142extern int vppcom_session_close (uint32_t session_index);
143
144extern int vppcom_session_bind (uint32_t session_index, vppcom_endpt_t * ep);
145extern int vppcom_session_listen (uint32_t session_index, uint32_t q_len);
146extern int vppcom_session_accept (uint32_t session_index,
147 vppcom_endpt_t * client_ep,
148 double wait_for_time);
149
150extern int vppcom_session_connect (uint32_t session_index,
151 vppcom_endpt_t * server_ep);
152extern int vppcom_session_read (uint32_t session_index, void *buf, int n);
153extern int vppcom_session_write (uint32_t session_index, void *buf, int n);
154
155extern int vppcom_select (unsigned long n_bits,
156 unsigned long *read_map,
157 unsigned long *write_map,
158 unsigned long *except_map, double wait_for_time);
159
Dave Wallacef7f809c2017-10-03 01:48:42 -0400160extern int vppcom_epoll_create (void);
161extern int vppcom_epoll_ctl (uint32_t vep_idx, int op,
162 uint32_t session_index,
163 struct epoll_event *event);
164extern int vppcom_epoll_wait (uint32_t vep_idx, struct epoll_event *events,
165 int maxevents, double wait_for_time);
Dave Wallace35830af2017-10-09 01:43:42 -0400166extern int vppcom_session_attr (uint32_t session_index, uint32_t op,
167 void *buffer, uint32_t * buflen);
Stevenac1f96d2017-10-24 16:03:58 -0700168extern int vppcom_session_recvfrom (uint32_t session_index, void *buffer,
169 uint32_t buflen, int flags,
170 vppcom_endpt_t * ep);
171extern int vppcom_session_sendto (uint32_t session_index, void *buffer,
172 uint32_t buflen, int flags,
173 vppcom_endpt_t * ep);
Dave Wallacef7f809c2017-10-03 01:48:42 -0400174
Dave Wallace543852a2017-08-03 02:11:34 -0400175#endif /* included_vppcom_h */
176
177/*
178 * fd.io coding-style-patch-verification: ON
179 *
180 * Local Variables:
181 * eval: (c-set-style "gnu")
182 * End:
183 */