FD.io VPP  v17.10-9-gd594711
Vector Packet Processing
vppcom.h
Go to the documentation of this file.
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 
22 /*
23  * VPPCOM Public API Definitions, Enums, and Data Structures
24  */
25 #define INVALID_SESSION_ID (~0)
26 #define VPPCOM_VRF_DEFAULT 0
27 #define VPPCOM_CONF_ENV "VPPCOM_CONF"
28 #define VPPCOM_CONF_DEFAULT "/etc/vpp/vppcom.conf"
29 
30 typedef enum
31 {
35 
36 typedef enum
37 {
41 
42 typedef struct vppcom_endpt_t_
43 {
44  uint32_t vrf;
45  uint8_t is_cut_thru;
46  uint8_t is_ip4;
47  uint8_t *ip;
48  uint16_t port;
50 
51 typedef enum
52 {
53  VPPCOM_OK = 0,
54  VPPCOM_EAGAIN = -EAGAIN,
55  VPPCOM_EINVAL = -EINVAL,
56  VPPCOM_EBADFD = -EBADFD,
57  VPPCOM_EAFNOSUPPORT = -EAFNOSUPPORT,
58  VPPCOM_ECONNRESET = -ECONNRESET,
59  VPPCOM_ECONNREFUSED = -ECONNREFUSED,
60  VPPCOM_ETIMEDOUT = -ETIMEDOUT,
62 
63 /*
64  * VPPCOM Public API Functions
65  */
66 static inline const char *
67 vppcom_retval_str (int retval)
68 {
69  char *st;
70 
71  switch (retval)
72  {
73  case VPPCOM_OK:
74  st = "VPPCOM_OK";
75  break;
76 
77  case VPPCOM_EAGAIN:
78  st = "VPPCOM_EAGAIN";
79  break;
80 
81  case VPPCOM_EINVAL:
82  st = "VPPCOM_EINVAL";
83  break;
84 
85  case VPPCOM_EBADFD:
86  st = "VPPCOM_EBADFD";
87  break;
88 
90  st = "VPPCOM_EAFNOSUPPORT";
91  break;
92 
93  case VPPCOM_ECONNRESET:
94  st = "VPPCOM_ECONNRESET";
95  break;
96 
98  st = "VPPCOM_ECONNREFUSED";
99  break;
100 
101  case VPPCOM_ETIMEDOUT:
102  st = "VPPCOM_ETIMEDOUT";
103  break;
104 
105  default:
106  st = "UNKNOWN_STATE";
107  break;
108  }
109 
110  return st;
111 }
112 
113 static inline int
114 is_vcom_fd (int fd)
115 {
116 #define VPPCOM_FD_OFFSET (1 << 30)
117  return (fd >= VPPCOM_FD_OFFSET);
118 }
119 
120 /* TBD: make these constructor/destructor function */
121 extern int vppcom_app_create (char *app_name);
122 extern void vppcom_app_destroy (void);
123 
124 extern int vppcom_session_create (uint32_t vrf, uint8_t proto,
125  uint8_t is_nonblocking);
126 extern int vppcom_session_close (uint32_t session_index);
127 
128 extern int vppcom_session_bind (uint32_t session_index, vppcom_endpt_t * ep);
129 extern int vppcom_session_listen (uint32_t session_index, uint32_t q_len);
130 extern int vppcom_session_accept (uint32_t session_index,
131  vppcom_endpt_t * client_ep,
132  double wait_for_time);
133 
134 extern int vppcom_session_connect (uint32_t session_index,
135  vppcom_endpt_t * server_ep);
136 extern int vppcom_session_read (uint32_t session_index, void *buf, int n);
137 extern int vppcom_session_write (uint32_t session_index, void *buf, int n);
138 
139 extern int vppcom_select (unsigned long n_bits,
140  unsigned long *read_map,
141  unsigned long *write_map,
142  unsigned long *except_map, double wait_for_time);
143 
144 #endif /* included_vppcom_h */
145 
146 /*
147  * fd.io coding-style-patch-verification: ON
148  *
149  * Local Variables:
150  * eval: (c-set-style "gnu")
151  * End:
152  */
int vppcom_session_connect(uint32_t session_index, vppcom_endpt_t *server_ep)
Definition: vppcom.c:2052
uint8_t * ip
Definition: vppcom.h:47
vppcom_proto_t
Definition: vppcom.h:30
#define VPPCOM_FD_OFFSET
void vppcom_app_destroy(void)
Definition: vppcom.c:1776
vppcom_error_t
Definition: vppcom.h:51
int vppcom_app_create(char *app_name)
Definition: vppcom.c:1690
int vppcom_session_close(uint32_t session_index)
Definition: vppcom.c:1825
static const char * vppcom_retval_str(int retval)
Definition: vppcom.h:67
uint8_t is_ip4
Definition: vppcom.h:46
struct vppcom_endpt_t_ vppcom_endpt_t
int vppcom_session_accept(uint32_t session_index, vppcom_endpt_t *client_ep, double wait_for_time)
Definition: vppcom.c:1972
int vppcom_session_listen(uint32_t session_index, uint32_t q_len)
Definition: vppcom.c:1918
int vppcom_select(unsigned long n_bits, unsigned long *read_map, unsigned long *write_map, unsigned long *except_map, double wait_for_time)
Definition: vppcom.c:2306
int vppcom_session_read(uint32_t session_index, void *buf, int n)
Definition: vppcom.c:2111
vppcom_is_ip4_t
Definition: vppcom.h:36
int vppcom_session_bind(uint32_t session_index, vppcom_endpt_t *ep)
Definition: vppcom.c:1882
int vppcom_session_write(uint32_t session_index, void *buf, int n)
Definition: vppcom.c:2194
uint16_t port
Definition: vppcom.h:48
static int is_vcom_fd(int fd)
Definition: vppcom.h:114
int vppcom_session_create(uint32_t vrf, uint8_t proto, uint8_t is_nonblocking)
uint32_t vrf
Definition: vppcom.h:44
uint8_t is_cut_thru
Definition: vppcom.h:45