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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 *------------------------------------------------------------------
17 * udp_ping_api.c - UDP Ping related APIs to create
18 * and maintain ping flows
19 *------------------------------------------------------------------
22 #include <vnet/vnet.h>
23 #include <vnet/ip/ip.h>
24 #include <ioam/udp-ping/udp_ping.h>
26 #include <vlibapi/api.h>
27 #include <vlibmemory/api.h>
30 /* define message IDs */
31 #include <ioam/udp-ping/udp_ping_msg_enum.h>
33 /* define message structures */
35 #include <ioam/udp-ping/udp_ping_all_api_h.h>
38 /* define generated endian-swappers */
40 #include <ioam/udp-ping/udp_ping_all_api_h.h>
43 /* instantiate all the print functions we know about */
44 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
46 #include <ioam/udp-ping/udp_ping_all_api_h.h>
49 /* Get the API version number */
50 #define vl_api_version(n,v) static u32 api_version=(v);
51 #include <ioam/udp-ping/udp_ping_all_api_h.h>
54 #define REPLY_MSG_ID_BASE sm->msg_id_base
55 #include <vlibapi/api_helper_macros.h>
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) \
63 vl_api_udp_ping_add_del_t_handler (vl_api_udp_ping_add_del_t * mp)
65 ip46_address_t dst, src;
67 udp_ping_main_t *sm = &udp_ping_main;
68 vl_api_udp_ping_add_del_reply_t *rmp;
72 rv = -1; //Not supported
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));
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);
90 REPLY_MACRO (VL_API_UDP_PING_ADD_DEL_REPLY);
94 vl_api_udp_ping_export_t_handler (vl_api_udp_ping_export_t * mp)
96 udp_ping_main_t *sm = &udp_ping_main;
98 vl_api_udp_ping_export_reply_t *rmp;
100 (void) udp_ping_flow_create (!mp->enable);
103 REPLY_MACRO (VL_API_UDP_PING_EXPORT_REPLY);
106 /* Set up the API message handling tables */
107 static clib_error_t *
108 udp_ping_api_hookup (vlib_main_t * vm)
110 udp_ping_main_t *sm = &udp_ping_main;
112 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
114 vl_api_##n##_t_handler, \
116 vl_api_##n##_t_endian, \
117 vl_api_##n##_t_print, \
118 sizeof(vl_api_##n##_t), 1);
119 foreach_udp_ping_api_msg;
125 #define vl_msg_name_crc_list
126 #include <ioam/udp-ping/udp_ping_all_api_h.h>
127 #undef vl_msg_name_crc_list
130 setup_message_id_table (udp_ping_main_t * sm, api_main_t * am)
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;
138 static clib_error_t *
139 udp_ping_api_init (vlib_main_t * vm)
141 udp_ping_main_t *sm = &udp_ping_main;
142 clib_error_t *error = 0;
145 name = format (0, "udp_ping_%08x%c", api_version, 0);
147 /* Ask for a correctly-sized block of API message decode slots */
148 sm->msg_id_base = vl_msg_api_get_msg_ids
149 ((char *) name, VL_MSG_FIRST_AVAILABLE);
151 error = udp_ping_api_hookup (vm);
153 /* Add our API messages to the global name_crc hash table */
154 setup_message_id_table (sm, &api_main);
161 VLIB_INIT_FUNCTION (udp_ping_api_init);
164 * fd.io coding-style-patch-verification: ON
167 * eval: (c-set-style "gnu")