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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef included_vppcom_h
17 #define included_vppcom_h
21 #include <sys/epoll.h>
24 * VPPCOM Public API Definitions, Enums, and Data Structures
26 #define INVALID_SESSION_ID (~0)
27 #define VPPCOM_VRF_DEFAULT 0
28 #define VPPCOM_CONF_ENV "VPPCOM_CONF"
29 #define VPPCOM_CONF_DEFAULT "/etc/vpp/vppcom.conf"
43 typedef struct vppcom_endpt_t_
55 VPPCOM_EAGAIN = -EAGAIN,
56 VPPCOM_EINVAL = -EINVAL,
57 VPPCOM_EBADFD = -EBADFD,
58 VPPCOM_EAFNOSUPPORT = -EAFNOSUPPORT,
59 VPPCOM_ECONNRESET = -ECONNRESET,
60 VPPCOM_ECONNREFUSED = -ECONNREFUSED,
61 VPPCOM_ETIMEDOUT = -ETIMEDOUT,
66 VPPCOM_ATTR_GET_NREAD,
67 VPPCOM_ATTR_PEEK_NREAD,
68 VPPCOM_ATTR_GET_FLAGS,
69 VPPCOM_ATTR_SET_FLAGS,
70 VPPCOM_ATTR_GET_LCL_ADDR,
71 VPPCOM_ATTR_GET_PEER_ADDR,
75 * VPPCOM Public API Functions
77 static inline const char *
78 vppcom_retval_str (int retval)
100 case VPPCOM_EAFNOSUPPORT:
101 st = "VPPCOM_EAFNOSUPPORT";
104 case VPPCOM_ECONNRESET:
105 st = "VPPCOM_ECONNRESET";
108 case VPPCOM_ECONNREFUSED:
109 st = "VPPCOM_ECONNREFUSED";
112 case VPPCOM_ETIMEDOUT:
113 st = "VPPCOM_ETIMEDOUT";
117 st = "UNKNOWN_STATE";
127 #define VPPCOM_FD_OFFSET (1 << 30)
128 return (fd >= VPPCOM_FD_OFFSET);
131 /* TBD: make these constructor/destructor function */
132 extern int vppcom_app_create (char *app_name);
133 extern void vppcom_app_destroy (void);
135 extern int vppcom_session_create (uint32_t vrf, uint8_t proto,
136 uint8_t is_nonblocking);
137 extern int vppcom_session_close (uint32_t session_index);
139 extern int vppcom_session_bind (uint32_t session_index, vppcom_endpt_t * ep);
140 extern int vppcom_session_listen (uint32_t session_index, uint32_t q_len);
141 extern int vppcom_session_accept (uint32_t session_index,
142 vppcom_endpt_t * client_ep,
143 double wait_for_time);
145 extern int vppcom_session_connect (uint32_t session_index,
146 vppcom_endpt_t * server_ep);
147 extern int vppcom_session_read (uint32_t session_index, void *buf, int n);
148 extern int vppcom_session_write (uint32_t session_index, void *buf, int n);
150 extern int vppcom_select (unsigned long n_bits,
151 unsigned long *read_map,
152 unsigned long *write_map,
153 unsigned long *except_map, double wait_for_time);
155 extern int vppcom_epoll_create (void);
156 extern int vppcom_epoll_ctl (uint32_t vep_idx, int op,
157 uint32_t session_index,
158 struct epoll_event *event);
159 extern int vppcom_epoll_wait (uint32_t vep_idx, struct epoll_event *events,
160 int maxevents, double wait_for_time);
161 extern int vppcom_session_attr (uint32_t session_index, uint32_t op,
162 void *buffer, uint32_t * buflen);
164 #endif /* included_vppcom_h */
167 * fd.io coding-style-patch-verification: ON
170 * eval: (c-set-style "gnu")