test: Fix test dependancy
[govpp.git] / adapter / vppapiclient / vppapiclient_wrapper.h
1 // Copyright (c) 2018 Cisco and/or its affiliates.
2 //
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 #ifndef included_vppapiclient_wrapper_h
16 #define included_vppapiclient_wrapper_h
17
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <arpa/inet.h>
22
23 #include <vpp-api/client/vppapiclient.h> // VPP has to be installed!
24
25 // function go_msg_callback is defined in vppapiclient.go
26 extern void go_msg_callback(uint16_t msg_id, void* data, size_t size);
27
28 typedef struct __attribute__((__packed__)) _req_header {
29     uint16_t msg_id;
30     uint32_t client_index;
31     uint32_t context;
32 } req_header_t;
33
34 typedef struct __attribute__((__packed__)) _reply_header {
35     uint16_t msg_id;
36 } reply_header_t;
37
38 static void
39 govpp_msg_callback(unsigned char *data, int size)
40 {
41     reply_header_t *header = ((reply_header_t *)data);
42     go_msg_callback(ntohs(header->msg_id), data, size);
43 }
44
45 static int
46 govpp_send(uint32_t context, void *data, size_t size)
47 {
48         req_header_t *header = ((req_header_t *)data);
49         header->context = htonl(context);
50     return vac_write(data, size);
51 }
52
53 static int
54 govpp_connect(char *shm, int rx_qlen)
55 {
56     return vac_connect("govpp", shm, govpp_msg_callback, rx_qlen);
57 }
58
59 static int
60 govpp_disconnect()
61 {
62     return vac_disconnect();
63 }
64
65 static uint32_t
66 govpp_get_msg_index(char *name_and_crc)
67 {
68     return vac_get_msg_index(name_and_crc);
69 }
70
71 #endif /* included_vppapiclient_wrapper_h */