ip-neighbor: Replace feature for the ip-neighbor data-base
[vpp.git] / src / vnet / ip-neighbor / ip_neighbor_types.c
1 /*
2  * ip_neighboor.h: ip neighbor generic services
3  *
4  * Copyright (c) 2018 Cisco 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
18 #include <vnet/ip-neighbor/ip_neighbor_types.h>
19
20 u8 *
21 format_ip_neighbor_flags (u8 * s, va_list * args)
22 {
23   ip_neighbor_flags_t flags = va_arg (*args, int);
24
25 #define _(a,b,c,d)                              \
26   if (flags & IP_NEIGHBOR_FLAG_##a)             \
27     s = format (s, "%s", d);
28   foreach_ip_neighbor_flag
29 #undef _
30     return s;
31 }
32
33 u8 *
34 format_ip_neighbor_key (u8 * s, va_list * va)
35 {
36   ip_neighbor_key_t *key = va_arg (*va, ip_neighbor_key_t *);
37
38   return (format (s, "[%U, %U]",
39                   format_vnet_sw_if_index_name, vnet_get_main (),
40                   key->ipnk_sw_if_index,
41                   format_ip46_address, &key->ipnk_ip, key->ipnk_type));
42 }
43
44 u8 *
45 format_ip_neighbor_watcher (u8 * s, va_list * va)
46 {
47   ip_neighbor_watcher_t *watcher = va_arg (*va, ip_neighbor_watcher_t *);
48
49   return (format (s, "[pid:%d, client:%d]",
50                   clib_host_to_net_u32 (watcher->ipw_pid),
51                   clib_host_to_net_u32 (watcher->ipw_client)));
52 }
53
54 u8 *
55 format_ip_neighbor (u8 * s, va_list * va)
56 {
57   index_t ipni = va_arg (*va, index_t);
58   ip_neighbor_t *ipn;
59
60   ipn = ip_neighbor_get (ipni);
61
62   return (format (s, "%=12U%=40U%=6U%=20U%U",
63                   format_vlib_time, vlib_get_main (),
64                   ipn->ipn_time_last_updated,
65                   format_ip46_address, &ipn->ipn_key->ipnk_ip, IP46_TYPE_ANY,
66                   format_ip_neighbor_flags, ipn->ipn_flags,
67                   format_mac_address_t, &ipn->ipn_mac,
68                   format_vnet_sw_if_index_name, vnet_get_main (),
69                   ipn->ipn_key->ipnk_sw_if_index));
70 }
71
72 /*
73  * fd.io coding-style-patch-verification: ON
74  *
75  * Local Variables:
76  * eval: (c-set-style "gnu")
77  * End:
78  */