FD.io VPP  v18.04-17-g3a0d853
Vector Packet Processing
udp_ping_api.c
Go to the documentation of this file.
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  *------------------------------------------------------------------
17  * udp_ping_api.c - UDP Ping related APIs to create
18  * and maintain ping flows
19  *------------------------------------------------------------------
20  */
21 
22 #include <vnet/vnet.h>
23 #include <vnet/ip/ip.h>
24 #include <ioam/udp-ping/udp_ping.h>
25 
26 #include <vlibapi/api.h>
27 #include <vlibmemory/api.h>
28 
29 
30 /* define message IDs */
32 
33 /* define message structures */
34 #define vl_typedefs
36 #undef vl_typedefs
37 
38 /* define generated endian-swappers */
39 #define vl_endianfun
41 #undef vl_endianfun
42 
43 /* instantiate all the print functions we know about */
44 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
45 #define vl_printfun
47 #undef vl_printfun
48 
49 /* Get the API version number */
50 #define vl_api_version(n,v) static u32 api_version=(v);
52 #undef vl_api_version
53 
54 #define REPLY_MSG_ID_BASE sm->msg_id_base
56 
57 /* List of message types that this module understands */
58 #define foreach_udp_ping_api_msg \
59  _(UDP_PING_ADD_DEL, udp_ping_add_del) \
60  _(UDP_PING_EXPORT, udp_ping_export) \
61 
62 static void
64 {
65  ip46_address_t dst, src;
66  int rv = 0;
68  vl_api_udp_ping_add_del_reply_t *rmp;
69 
70  if (mp->is_ipv4)
71  {
72  rv = -1; //Not supported
73  goto ERROROUT;
74  }
75 
76  clib_memcpy ((void *) &src.ip6, (void *) mp->src_ip_address,
77  sizeof (ip6_address_t));
78  clib_memcpy ((void *) &dst.ip6, (void *) mp->dst_ip_address,
79  sizeof (ip6_address_t));
80 
81  ip46_udp_ping_set_flow (src, dst,
82  ntohs (mp->start_src_port),
83  ntohs (mp->end_src_port),
84  ntohs (mp->start_dst_port),
85  ntohs (mp->end_dst_port),
86  ntohs (mp->interval), mp->fault_det, mp->dis);
87  rv = 0; //FIXME
88 
89 ERROROUT:
90  REPLY_MACRO (VL_API_UDP_PING_ADD_DEL_REPLY);
91 }
92 
93 static void
95 {
97  int rv = 0;
98  vl_api_udp_ping_export_reply_t *rmp;
99 
100  (void) udp_ping_flow_create (!mp->enable);
101  rv = 0; //FIXME
102 
103  REPLY_MACRO (VL_API_UDP_PING_EXPORT_REPLY);
104 }
105 
106 /* Set up the API message handling tables */
107 static clib_error_t *
109 {
111 #define _(N,n) \
112  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
113  #n, \
114  vl_api_##n##_t_handler, \
115  vl_noop_handler, \
116  vl_api_##n##_t_endian, \
117  vl_api_##n##_t_print, \
118  sizeof(vl_api_##n##_t), 1);
120 #undef _
121 
122  return 0;
123 }
124 
125 #define vl_msg_name_crc_list
127 #undef vl_msg_name_crc_list
128 
129 static void
131 {
132 #define _(id,n,crc) \
133  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
134  foreach_vl_msg_name_crc_udp_ping;
135 #undef _
136 }
137 
138 static clib_error_t *
140 {
142  clib_error_t *error = 0;
143  u8 *name;
144 
145  name = format (0, "udp_ping_%08x%c", api_version, 0);
146 
147  /* Ask for a correctly-sized block of API message decode slots */
149  ((char *) name, VL_MSG_FIRST_AVAILABLE);
150 
151  error = udp_ping_api_hookup (vm);
152 
153  /* Add our API messages to the global name_crc hash table */
155 
156  vec_free (name);
157 
158  return error;
159 }
160 
162 
163 /*
164  * fd.io coding-style-patch-verification: ON
165  *
166  * Local Variables:
167  * eval: (c-set-style "gnu")
168  * End:
169  */
static void vl_api_udp_ping_export_t_handler(vl_api_udp_ping_export_t *mp)
Definition: udp_ping_api.c:94
static void vl_api_udp_ping_add_del_t_handler(vl_api_udp_ping_add_del_t *mp)
Definition: udp_ping_api.c:63
udp-ping main data-structure.
Definition: udp_ping.h:105
clib_error_t * udp_ping_flow_create(u8 del)
static void setup_message_id_table(udp_ping_main_t *sm, api_main_t *am)
Definition: udp_ping_api.c:130
#define foreach_udp_ping_api_msg
Definition: udp_ping_api.c:58
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
static clib_error_t * udp_ping_api_hookup(vlib_main_t *vm)
Definition: udp_ping_api.c:108
Udp-probe export add/del request.
Definition: udp_ping.api:51
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
u16 msg_id_base
API message ID base.
Definition: udp_ping.h:120
udp_ping_main_t udp_ping_main
Definition: udp_ping_node.c:41
#define REPLY_MACRO(t)
static clib_error_t * udp_ping_api_init(vlib_main_t *vm)
Definition: udp_ping_api.c:139
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:199
vlib_main_t * vm
Definition: buffer.c:294
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
#define clib_memcpy(a, b, c)
Definition: string.h:75
void ip46_udp_ping_set_flow(ip46_address_t src, ip46_address_t dst, u16 start_src_port, u16 end_src_port, u16 start_dst_port, u16 end_dst_port, u16 interval, u8 fault_det, u8 is_disable)
UDP-Probe Add/Delete request.
Definition: udp_ping.api:30
unsigned char u8
Definition: types.h:56
api_main_t api_main
Definition: api_shared.c:35
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:872