misc: api move continued
[vpp.git] / src / plugins / stn / stn_test.c
1 /*
2  * Copyright (c) 2018 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 #include <vat/vat.h>
16 #include <vlibapi/api.h>
17 #include <vlibmemory/api.h>
18 #include <vppinfra/error.h>
19 #include <vnet/format_fns.h>
20 #include <stn/stn.h>
21
22 #define __plugin_msg_base stn_test_main.msg_id_base
23 #include <vlibapi/vat_helper_macros.h>
24
25 /* Declare message IDs */
26 #include <stn/stn.api_enum.h>
27 #include <stn/stn.api_types.h>
28 #include <vlibmemory/vlib.api_types.h>
29
30 typedef struct
31 {
32   /* API message ID base */
33   u16 msg_id_base;
34   u32 ping_id;
35   vat_main_t *vat_main;
36 } stn_test_main_t;
37
38 stn_test_main_t stn_test_main;
39
40 static int
41 api_stn_add_del_rule (vat_main_t * vam)
42 {
43   // Not yet implemented
44   return -99;
45 }
46
47 static int
48 api_stn_rules_dump (vat_main_t * vam)
49 {
50   stn_test_main_t *sm = &stn_test_main;
51   vl_api_stn_rules_dump_t *mp;
52   vl_api_control_ping_t *mp_ping;
53   int ret;
54
55   if (!vam->json_output)
56     {
57       print (vam->ofp, "%=20s", "STN Rules");
58     }
59
60   M (STN_RULES_DUMP, mp);
61   /* send it... */
62   S (mp);
63
64   /* Use a control ping for synchronization */
65   mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
66   mp_ping->_vl_msg_id = htons (sm->ping_id);
67   mp_ping->client_index = vam->my_client_index;
68
69   fformat (vam->ofp, "Sending ping id=%d\n", sm->ping_id);
70
71   vam->result_ready = 0;
72   S (mp_ping);
73
74   /* Wait for a reply... */
75   W (ret);
76   return ret;
77 }
78
79 static void
80 vl_api_stn_rules_details_t_handler (vl_api_stn_rules_details_t * mp)
81 {
82   vat_main_t *vam = stn_test_main.vat_main;
83   fformat (vam->ofp, "addr: %U sw_if_index: %u\n",
84            format_ip46_address,
85            mp->ip_address, clib_net_to_host_u32 (mp->sw_if_index));
86 }
87
88 #include <stn/stn.api_test.c>
89
90 /*
91  * fd.io coding-style-patch-verification: ON
92  *
93  * Local Variables:
94  * eval: (c-set-style "gnu")
95  * End:
96  */