]> git.proxmox.com Git - mirror_frr.git/blame - bfdd/bfdd_nb_state.c
Merge pull request #11765 from lyq140/patch-pimDoc
[mirror_frr.git] / bfdd / bfdd_nb_state.c
CommitLineData
6c574029
RW
1/*
2 * BFD daemon northbound implementation.
3 *
4 * Copyright (C) 2019 Network Device Education Foundation, Inc. ("NetDEF")
5 * Rafael Zalamena
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301 USA.
21 */
22
23#include <zebra.h>
24
25#include "lib/log.h"
26#include "lib/northbound.h"
27
28#include "bfd.h"
29#include "bfdd_nb.h"
30
31/*
32 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop
33 */
60ee8be1
RW
34const void *
35bfdd_bfd_sessions_single_hop_get_next(struct nb_cb_get_next_args *args)
6c574029 36{
60ee8be1 37 return bfd_session_next(args->list_entry, false);
6c574029
RW
38}
39
60ee8be1 40int bfdd_bfd_sessions_single_hop_get_keys(struct nb_cb_get_keys_args *args)
6c574029 41{
60ee8be1 42 const struct bfd_session *bs = args->list_entry;
6c574029
RW
43 char dstbuf[INET6_ADDRSTRLEN];
44
45 inet_ntop(bs->key.family, &bs->key.peer, dstbuf, sizeof(dstbuf));
46
60ee8be1
RW
47 args->keys->num = 3;
48 strlcpy(args->keys->key[0], dstbuf, sizeof(args->keys->key[0]));
49 strlcpy(args->keys->key[1], bs->key.ifname, sizeof(args->keys->key[1]));
50 strlcpy(args->keys->key[2], bs->key.vrfname,
51 sizeof(args->keys->key[2]));
6c574029
RW
52
53 return NB_OK;
54}
55
56const void *
60ee8be1 57bfdd_bfd_sessions_single_hop_lookup_entry(struct nb_cb_lookup_entry_args *args)
6c574029 58{
60ee8be1
RW
59 const char *dest_addr = args->keys->key[0];
60 const char *ifname = args->keys->key[1];
61 const char *vrf = args->keys->key[2];
6c574029
RW
62 struct sockaddr_any psa, lsa;
63 struct bfd_key bk;
64
65 strtosa(dest_addr, &psa);
66 memset(&lsa, 0, sizeof(lsa));
67 gen_bfd_key(&bk, &psa, &lsa, false, ifname, vrf);
68
69 return bfd_key_lookup(bk);
70}
71
72/*
73 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-discriminator
74 */
75struct yang_data *
76bfdd_bfd_sessions_single_hop_stats_local_discriminator_get_elem(
60ee8be1 77 struct nb_cb_get_elem_args *args)
6c574029 78{
60ee8be1 79 const struct bfd_session *bs = args->list_entry;
6c574029 80
60ee8be1 81 return yang_data_new_uint32(args->xpath, bs->discrs.my_discr);
6c574029
RW
82}
83
84/*
85 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-state
86 */
60ee8be1
RW
87struct yang_data *bfdd_bfd_sessions_single_hop_stats_local_state_get_elem(
88 struct nb_cb_get_elem_args *args)
6c574029 89{
60ee8be1 90 const struct bfd_session *bs = args->list_entry;
6c574029 91
60ee8be1 92 return yang_data_new_enum(args->xpath, bs->ses_state);
6c574029
RW
93}
94
95/*
96 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-diagnostic
97 */
98struct yang_data *bfdd_bfd_sessions_single_hop_stats_local_diagnostic_get_elem(
60ee8be1 99 struct nb_cb_get_elem_args *args)
6c574029 100{
60ee8be1 101 const struct bfd_session *bs = args->list_entry;
6c574029 102
60ee8be1 103 return yang_data_new_enum(args->xpath, bs->local_diag);
6c574029
RW
104}
105
106/*
107 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-multiplier
108 */
109struct yang_data *bfdd_bfd_sessions_single_hop_stats_local_multiplier_get_elem(
60ee8be1 110 struct nb_cb_get_elem_args *args)
6c574029 111{
60ee8be1 112 const struct bfd_session *bs = args->list_entry;
6c574029 113
60ee8be1 114 return yang_data_new_int8(args->xpath, bs->detect_mult);
6c574029
RW
115}
116
117/*
118 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-discriminator
119 */
120struct yang_data *
121bfdd_bfd_sessions_single_hop_stats_remote_discriminator_get_elem(
60ee8be1 122 struct nb_cb_get_elem_args *args)
6c574029 123{
60ee8be1 124 const struct bfd_session *bs = args->list_entry;
6c574029
RW
125
126 if (bs->discrs.remote_discr == 0)
127 return NULL;
128
60ee8be1 129 return yang_data_new_uint32(args->xpath, bs->discrs.remote_discr);
6c574029
RW
130}
131
132/*
133 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-state
134 */
60ee8be1
RW
135struct yang_data *bfdd_bfd_sessions_single_hop_stats_remote_state_get_elem(
136 struct nb_cb_get_elem_args *args)
6c574029 137{
60ee8be1 138 const struct bfd_session *bs = args->list_entry;
6c574029 139
60ee8be1 140 return yang_data_new_enum(args->xpath, bs->ses_state);
6c574029
RW
141}
142
143/*
144 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-diagnostic
145 */
146struct yang_data *bfdd_bfd_sessions_single_hop_stats_remote_diagnostic_get_elem(
60ee8be1 147 struct nb_cb_get_elem_args *args)
6c574029 148{
60ee8be1 149 const struct bfd_session *bs = args->list_entry;
6c574029 150
60ee8be1 151 return yang_data_new_enum(args->xpath, bs->remote_diag);
6c574029
RW
152}
153
154/*
155 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-multiplier
156 */
157struct yang_data *bfdd_bfd_sessions_single_hop_stats_remote_multiplier_get_elem(
60ee8be1 158 struct nb_cb_get_elem_args *args)
6c574029 159{
60ee8be1 160 const struct bfd_session *bs = args->list_entry;
6c574029 161
60ee8be1 162 return yang_data_new_int8(args->xpath, bs->remote_detect_mult);
6c574029
RW
163}
164
165/*
166 * XPath:
167 * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/negotiated-transmission-interval
168 */
169struct yang_data *
170bfdd_bfd_sessions_single_hop_stats_negotiated_transmission_interval_get_elem(
60ee8be1 171 struct nb_cb_get_elem_args *args)
6c574029 172{
60ee8be1 173 const struct bfd_session *bs = args->list_entry;
6c574029 174
60ee8be1
RW
175 return yang_data_new_uint32(args->xpath,
176 bs->remote_timers.desired_min_tx);
6c574029
RW
177}
178
179/*
180 * XPath:
181 * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/negotiated-receive-interval
182 */
183struct yang_data *
184bfdd_bfd_sessions_single_hop_stats_negotiated_receive_interval_get_elem(
60ee8be1 185 struct nb_cb_get_elem_args *args)
6c574029 186{
60ee8be1 187 const struct bfd_session *bs = args->list_entry;
6c574029 188
60ee8be1
RW
189 return yang_data_new_uint32(args->xpath,
190 bs->remote_timers.required_min_rx);
6c574029
RW
191}
192
193/*
194 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/detection-mode
195 */
196struct yang_data *bfdd_bfd_sessions_single_hop_stats_detection_mode_get_elem(
60ee8be1 197 struct nb_cb_get_elem_args *args)
6c574029 198{
60ee8be1 199 const struct bfd_session *bs = args->list_entry;
6c574029
RW
200 int detection_mode;
201
202 /*
203 * Detection mode:
204 * 1. Async with echo
205 * 2. Async without echo
206 * 3. Demand with echo
207 * 4. Demand without echo
208 *
209 * TODO: support demand mode.
210 */
b88113ef 211 if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
6c574029
RW
212 detection_mode = 1;
213 else
214 detection_mode = 2;
215
60ee8be1 216 return yang_data_new_enum(args->xpath, detection_mode);
6c574029
RW
217}
218
219/*
220 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/last-down-time
221 */
222struct yang_data *bfdd_bfd_sessions_single_hop_stats_last_down_time_get_elem(
60ee8be1 223 struct nb_cb_get_elem_args *args)
6c574029
RW
224{
225 /*
226 * TODO: implement me.
227 *
228 * No yang support for time elements yet.
229 */
230 return NULL;
231}
232
233/*
234 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/last-up-time
235 */
236struct yang_data *bfdd_bfd_sessions_single_hop_stats_last_up_time_get_elem(
60ee8be1 237 struct nb_cb_get_elem_args *args)
6c574029
RW
238{
239 /*
240 * TODO: implement me.
241 *
242 * No yang support for time elements yet.
243 */
244 return NULL;
245}
246
247/*
248 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/session-down-count
249 */
250struct yang_data *
251bfdd_bfd_sessions_single_hop_stats_session_down_count_get_elem(
60ee8be1 252 struct nb_cb_get_elem_args *args)
6c574029 253{
60ee8be1 254 const struct bfd_session *bs = args->list_entry;
6c574029 255
60ee8be1 256 return yang_data_new_uint64(args->xpath, bs->stats.session_down);
6c574029
RW
257}
258
259/*
260 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/session-up-count
261 */
262struct yang_data *bfdd_bfd_sessions_single_hop_stats_session_up_count_get_elem(
60ee8be1 263 struct nb_cb_get_elem_args *args)
6c574029 264{
60ee8be1 265 const struct bfd_session *bs = args->list_entry;
6c574029 266
60ee8be1 267 return yang_data_new_uint64(args->xpath, bs->stats.session_up);
6c574029
RW
268}
269
270/*
271 * XPath:
272 * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/control-packet-input-count
273 */
274struct yang_data *
275bfdd_bfd_sessions_single_hop_stats_control_packet_input_count_get_elem(
60ee8be1 276 struct nb_cb_get_elem_args *args)
6c574029 277{
60ee8be1 278 const struct bfd_session *bs = args->list_entry;
6c574029 279
60ee8be1 280 return yang_data_new_uint64(args->xpath, bs->stats.rx_ctrl_pkt);
6c574029
RW
281}
282
283/*
284 * XPath:
285 * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/control-packet-output-count
286 */
287struct yang_data *
288bfdd_bfd_sessions_single_hop_stats_control_packet_output_count_get_elem(
60ee8be1 289 struct nb_cb_get_elem_args *args)
6c574029 290{
60ee8be1 291 const struct bfd_session *bs = args->list_entry;
6c574029 292
60ee8be1 293 return yang_data_new_uint64(args->xpath, bs->stats.tx_ctrl_pkt);
6c574029
RW
294}
295
296/*
297 * XPath:
298 * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/negotiated-echo-transmission-interval
299 */
300struct yang_data *
301bfdd_bfd_sessions_single_hop_stats_negotiated_echo_transmission_interval_get_elem(
60ee8be1 302 struct nb_cb_get_elem_args *args)
6c574029 303{
60ee8be1 304 const struct bfd_session *bs = args->list_entry;
6c574029 305
60ee8be1
RW
306 return yang_data_new_uint32(args->xpath,
307 bs->remote_timers.required_min_echo);
6c574029
RW
308}
309
310/*
311 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/echo-packet-input-count
312 */
313struct yang_data *
314bfdd_bfd_sessions_single_hop_stats_echo_packet_input_count_get_elem(
60ee8be1 315 struct nb_cb_get_elem_args *args)
6c574029 316{
60ee8be1 317 const struct bfd_session *bs = args->list_entry;
6c574029 318
60ee8be1 319 return yang_data_new_uint64(args->xpath, bs->stats.rx_echo_pkt);
6c574029
RW
320}
321
322/*
323 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/echo-packet-output-count
324 */
325struct yang_data *
326bfdd_bfd_sessions_single_hop_stats_echo_packet_output_count_get_elem(
60ee8be1 327 struct nb_cb_get_elem_args *args)
6c574029 328{
60ee8be1 329 const struct bfd_session *bs = args->list_entry;
6c574029 330
60ee8be1 331 return yang_data_new_uint64(args->xpath, bs->stats.tx_echo_pkt);
6c574029
RW
332}
333
334/*
335 * XPath: /frr-bfdd:bfdd/bfd/sessions/multi-hop
336 */
60ee8be1
RW
337const void *
338bfdd_bfd_sessions_multi_hop_get_next(struct nb_cb_get_next_args *args)
6c574029 339{
60ee8be1 340 return bfd_session_next(args->list_entry, true);
6c574029
RW
341}
342
60ee8be1 343int bfdd_bfd_sessions_multi_hop_get_keys(struct nb_cb_get_keys_args *args)
6c574029 344{
60ee8be1 345 const struct bfd_session *bs = args->list_entry;
6c574029
RW
346 char dstbuf[INET6_ADDRSTRLEN], srcbuf[INET6_ADDRSTRLEN];
347
348 inet_ntop(bs->key.family, &bs->key.peer, dstbuf, sizeof(dstbuf));
349 inet_ntop(bs->key.family, &bs->key.local, srcbuf, sizeof(srcbuf));
350
60ee8be1
RW
351 args->keys->num = 4;
352 strlcpy(args->keys->key[0], srcbuf, sizeof(args->keys->key[0]));
353 strlcpy(args->keys->key[1], dstbuf, sizeof(args->keys->key[1]));
874ca769
IR
354 strlcpy(args->keys->key[2], bs->key.vrfname,
355 sizeof(args->keys->key[2]));
6c574029
RW
356
357 return NB_OK;
358}
359
360const void *
60ee8be1 361bfdd_bfd_sessions_multi_hop_lookup_entry(struct nb_cb_lookup_entry_args *args)
6c574029 362{
60ee8be1
RW
363 const char *source_addr = args->keys->key[0];
364 const char *dest_addr = args->keys->key[1];
874ca769 365 const char *vrf = args->keys->key[2];
6c574029
RW
366 struct sockaddr_any psa, lsa;
367 struct bfd_key bk;
368
369 strtosa(dest_addr, &psa);
370 strtosa(source_addr, &lsa);
874ca769 371 gen_bfd_key(&bk, &psa, &lsa, true, NULL, vrf);
6c574029
RW
372
373 return bfd_key_lookup(bk);
374}