blob: 7e8d2035c56de87a4b2ad0469f9c59dc1c12b9d1 [file] [log] [blame]
Gabriel Oginski4e88e042022-06-29 12:54:30 +00001#ifndef KERNEL_VPP_SHARED_H_
2#define KERNEL_VPP_SHARED_H_
3/*
4 * Copyright (c) 2022 Intel and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Gabriel Oginski0e1fe7b2023-07-14 07:22:12 +000018/**
19 * Every 2 seconds, the thread responsible for collecting the available
20 * interfaces will be executed.
21 * Retrying 5 times every 1 second ensures that there is enough time to check
22 * if the interface will be available.
23 */
24#define N_RETRY_GET_IF 5
25
Gabriel Oginski4e88e042022-06-29 12:54:30 +000026typedef struct vac_t vac_t;
27
28/**
29 * Callback function invoked for received event messages.
30 *
31 * @param data associated event message, destroyed by VPP API wrapper
32 * @param data_len length of the event message
33 * @param ctx user data, as passed to register_event
34 */
35typedef void (*event_cb_t) (char *data, int data_len, void *ctx);
36
37/**
38 * Wrapper around VPP binary API client.
39 */
40struct vac_t
41{
42
43 /**
44 * Destroy the VPP API client.
45 */
46 void (*destroy) (vac_t *this);
47
48 /**
49 * Send VPP API message and wait for a reply
50 *
51 * @param in VPP API message to send
52 * @param in_len length of the message to send
53 * @param out received VPP API message
54 * @param out_len length of the received message
55 */
56 status_t (*send) (vac_t *this, char *in, int in_len, char **out,
57 int *out_len);
58
59 /**
60 * Send VPP API dump message and wait for a reply.
61 *
62 * @param in VPP API message to send
63 * @param in_len length of the message to send
64 * @param out received VPP API message
65 * @param out_len length of the received message
66 */
67 status_t (*send_dump) (vac_t *this, char *in, int in_len, char **out,
68 int *out_len);
69
70 /**
71 * Register for VPP API event of a given kind.
72 *
73 * @param in VPP API event message to register
74 * @param in_len length of the event message to register
75 * @param cb callback function to register
76 * @param event_id event ID
77 * @param ctx user data passed to callback invocations
78 */
79 status_t (*register_event) (vac_t *this, char *in, int in_len, event_cb_t cb,
80 uint16_t event_id, void *ctx);
81};
82
83extern vac_t *vac;
84
85/**
86 * Establishing a binary API connection to VPP.
87 *
88 * @param name client name
89 * @return vac_t instance
90 */
91vac_t *vac_create (char *name);
92
93#endif /* KERNEL_VPP_SHARED_H_ */