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