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