Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 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> |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 21 | #include <sys/epoll.h> |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * VPPCOM Public API Definitions, Enums, and Data Structures |
| 25 | */ |
Dave Wallace | 774169b | 2017-11-01 20:07:40 -0400 | [diff] [blame] | 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" |
Dave Wallace | 498b3a5 | 2017-11-09 13:00:34 -0500 | [diff] [blame] | 30 | #define VPPCOM_ENV_DEBUG "VCL_DEBUG" |
Dave Wallace | 774169b | 2017-11-01 20:07:40 -0400 | [diff] [blame] | 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" |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 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, |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 63 | VPPCOM_ENOMEM = -ENOMEM, |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 64 | VPPCOM_EINVAL = -EINVAL, |
| 65 | VPPCOM_EBADFD = -EBADFD, |
| 66 | VPPCOM_EAFNOSUPPORT = -EAFNOSUPPORT, |
| 67 | VPPCOM_ECONNRESET = -ECONNRESET, |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame^] | 68 | VPPCOM_ENOTCONN = -ENOTCONN, |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 69 | VPPCOM_ECONNREFUSED = -ECONNREFUSED, |
| 70 | VPPCOM_ETIMEDOUT = -ETIMEDOUT, |
| 71 | } vppcom_error_t; |
| 72 | |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 73 | typedef enum |
| 74 | { |
| 75 | VPPCOM_ATTR_GET_NREAD, |
Dave Wallace | 227867f | 2017-11-13 21:21:53 -0500 | [diff] [blame] | 76 | VPPCOM_ATTR_GET_NWRITE, |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 77 | VPPCOM_ATTR_GET_FLAGS, |
| 78 | VPPCOM_ATTR_SET_FLAGS, |
| 79 | VPPCOM_ATTR_GET_LCL_ADDR, |
| 80 | VPPCOM_ATTR_GET_PEER_ADDR, |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 81 | VPPCOM_ATTR_SET_REUSEADDR, |
| 82 | VPPCOM_ATTR_SET_BROADCAST, |
| 83 | VPPCOM_ATTR_SET_V6ONLY, |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 84 | VPPCOM_ATTR_SET_KEEPALIVE, |
| 85 | VPPCOM_ATTR_SET_TCP_KEEPIDLE, |
| 86 | VPPCOM_ATTR_SET_TCP_KEEPINTVL, |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 87 | } vppcom_attr_op_t; |
| 88 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 89 | /* |
| 90 | * VPPCOM Public API Functions |
| 91 | */ |
| 92 | static inline const char * |
| 93 | vppcom_retval_str (int retval) |
| 94 | { |
| 95 | char *st; |
| 96 | |
| 97 | switch (retval) |
| 98 | { |
| 99 | case VPPCOM_OK: |
| 100 | st = "VPPCOM_OK"; |
| 101 | break; |
| 102 | |
| 103 | case VPPCOM_EAGAIN: |
| 104 | st = "VPPCOM_EAGAIN"; |
| 105 | break; |
| 106 | |
Dave Wallace | e376f93 | 2017-11-19 11:20:02 -0500 | [diff] [blame] | 107 | case VPPCOM_ENOMEM: |
| 108 | st = "VPPCOM_ENOMEM"; |
| 109 | break; |
| 110 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 111 | case VPPCOM_EINVAL: |
| 112 | st = "VPPCOM_EINVAL"; |
| 113 | break; |
| 114 | |
| 115 | case VPPCOM_EBADFD: |
| 116 | st = "VPPCOM_EBADFD"; |
| 117 | break; |
| 118 | |
| 119 | case VPPCOM_EAFNOSUPPORT: |
| 120 | st = "VPPCOM_EAFNOSUPPORT"; |
| 121 | break; |
| 122 | |
| 123 | case VPPCOM_ECONNRESET: |
| 124 | st = "VPPCOM_ECONNRESET"; |
| 125 | break; |
| 126 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame^] | 127 | case VPPCOM_ENOTCONN: |
| 128 | st = "VPPCOM_ENOTCONN"; |
| 129 | break; |
| 130 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 131 | case VPPCOM_ECONNREFUSED: |
| 132 | st = "VPPCOM_ECONNREFUSED"; |
| 133 | break; |
| 134 | |
| 135 | case VPPCOM_ETIMEDOUT: |
| 136 | st = "VPPCOM_ETIMEDOUT"; |
| 137 | break; |
| 138 | |
| 139 | default: |
| 140 | st = "UNKNOWN_STATE"; |
| 141 | break; |
| 142 | } |
| 143 | |
| 144 | return st; |
| 145 | } |
| 146 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 147 | /* TBD: make these constructor/destructor function */ |
| 148 | extern int vppcom_app_create (char *app_name); |
| 149 | extern void vppcom_app_destroy (void); |
| 150 | |
| 151 | extern int vppcom_session_create (uint32_t vrf, uint8_t proto, |
| 152 | uint8_t is_nonblocking); |
| 153 | extern int vppcom_session_close (uint32_t session_index); |
| 154 | |
| 155 | extern int vppcom_session_bind (uint32_t session_index, vppcom_endpt_t * ep); |
| 156 | extern int vppcom_session_listen (uint32_t session_index, uint32_t q_len); |
| 157 | extern int vppcom_session_accept (uint32_t session_index, |
| 158 | vppcom_endpt_t * client_ep, |
Dave Wallace | 227867f | 2017-11-13 21:21:53 -0500 | [diff] [blame] | 159 | uint32_t flags, double wait_for_time); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 160 | |
| 161 | extern int vppcom_session_connect (uint32_t session_index, |
| 162 | vppcom_endpt_t * server_ep); |
| 163 | extern int vppcom_session_read (uint32_t session_index, void *buf, int n); |
| 164 | extern int vppcom_session_write (uint32_t session_index, void *buf, int n); |
| 165 | |
| 166 | extern int vppcom_select (unsigned long n_bits, |
| 167 | unsigned long *read_map, |
| 168 | unsigned long *write_map, |
| 169 | unsigned long *except_map, double wait_for_time); |
| 170 | |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 171 | extern int vppcom_epoll_create (void); |
| 172 | extern int vppcom_epoll_ctl (uint32_t vep_idx, int op, |
| 173 | uint32_t session_index, |
| 174 | struct epoll_event *event); |
| 175 | extern int vppcom_epoll_wait (uint32_t vep_idx, struct epoll_event *events, |
| 176 | int maxevents, double wait_for_time); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 177 | extern int vppcom_session_attr (uint32_t session_index, uint32_t op, |
| 178 | void *buffer, uint32_t * buflen); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 179 | extern int vppcom_session_recvfrom (uint32_t session_index, void *buffer, |
| 180 | uint32_t buflen, int flags, |
| 181 | vppcom_endpt_t * ep); |
| 182 | extern int vppcom_session_sendto (uint32_t session_index, void *buffer, |
| 183 | uint32_t buflen, int flags, |
| 184 | vppcom_endpt_t * ep); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 185 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 186 | #endif /* included_vppcom_h */ |
| 187 | |
| 188 | /* |
| 189 | * fd.io coding-style-patch-verification: ON |
| 190 | * |
| 191 | * Local Variables: |
| 192 | * eval: (c-set-style "gnu") |
| 193 | * End: |
| 194 | */ |