]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_nb_state.c
Merge pull request #6692 from mjstapp/fix_sharp_gcc10
[mirror_frr.git] / isisd / isis_nb_state.c
CommitLineData
2a1c520e
RW
1/*
2 * Copyright (C) 2018 Volta Networks
3 * Emanuele Di Pascale
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <zebra.h>
21
22#include "northbound.h"
23#include "linklist.h"
24
25#include "isisd/isisd.h"
26#include "isisd/isis_nb.h"
27#include "isisd/isis_circuit.h"
28#include "isisd/isis_adjacency.h"
29#include "isisd/isis_misc.h"
30
31/*
27171928 32 * XPath: /frr-interface:lib/interface/state/frr-isisd:isis
2a1c520e 33 */
27171928
RW
34struct yang_data *
35lib_interface_state_isis_get_elem(struct nb_cb_get_elem_args *args)
36{
37 struct interface *ifp;
38 struct isis_circuit *circuit;
39
40 ifp = (struct interface *)args->list_entry;
41 if (!ifp)
42 return NULL;
43
44 circuit = circuit_scan_by_ifp(ifp);
45 if (!circuit || !circuit->area)
46 return NULL;
47
48 return yang_data_new(args->xpath, NULL);
49}
50
51/*
52 * XPath:
53 * /frr-interface:lib/interface/state/frr-isisd:isis/adjacencies/adjacency
54 */
55const void *lib_interface_state_isis_adjacencies_adjacency_get_next(
60ee8be1 56 struct nb_cb_get_next_args *args)
2a1c520e
RW
57{
58 struct interface *ifp;
59 struct isis_circuit *circuit;
e3c19b81 60 struct isis_adjacency *adj = NULL, *adj_next = NULL;
2a1c520e
RW
61 struct list *list;
62 struct listnode *node, *node_next;
63
64 /* Get first adjacency. */
60ee8be1
RW
65 if (args->list_entry == NULL) {
66 ifp = (struct interface *)args->parent_list_entry;
2a1c520e
RW
67 if (!ifp)
68 return NULL;
69
70 circuit = circuit_scan_by_ifp(ifp);
71 if (!circuit)
72 return NULL;
73
74 switch (circuit->circ_type) {
75 case CIRCUIT_T_BROADCAST:
76 for (int level = ISIS_LEVEL1; level <= ISIS_LEVELS;
77 level++) {
e3c19b81
RW
78 struct list *adjdb;
79
80 adjdb = circuit->u.bc.adjdb[level - 1];
81 if (adjdb) {
82 adj = listnode_head(adjdb);
83 if (adj)
84 break;
85 }
2a1c520e
RW
86 }
87 break;
88 case CIRCUIT_T_P2P:
89 adj = circuit->u.p2p.neighbor;
90 break;
91 default:
2a1c520e
RW
92 break;
93 }
94
95 return adj;
96 }
97
98 /* Get next adjacency. */
60ee8be1 99 adj = (struct isis_adjacency *)args->list_entry;
2a1c520e
RW
100 circuit = adj->circuit;
101 switch (circuit->circ_type) {
102 case CIRCUIT_T_BROADCAST:
103 list = circuit->u.bc.adjdb[adj->level - 1];
104 node = listnode_lookup(list, adj);
105 node_next = listnextnode(node);
106 if (node_next)
107 adj_next = listgetdata(node_next);
108 else if (adj->level == ISIS_LEVEL1) {
109 /*
110 * Once we finish the L1 adjacencies, move to the L2
111 * adjacencies list.
112 */
113 list = circuit->u.bc.adjdb[ISIS_LEVEL2 - 1];
114 adj_next = listnode_head(list);
115 }
116 break;
117 case CIRCUIT_T_P2P:
118 /* P2P circuits have at most one adjacency. */
119 default:
120 break;
121 }
122
123 return adj_next;
124}
125
126/*
127 * XPath:
27171928 128 * /frr-interface:lib/interface/state/frr-isisd:isis/adjacencies/adjacency/neighbor-sys-type
2a1c520e
RW
129 */
130struct yang_data *
27171928 131lib_interface_state_isis_adjacencies_adjacency_neighbor_sys_type_get_elem(
60ee8be1 132 struct nb_cb_get_elem_args *args)
2a1c520e 133{
60ee8be1 134 const struct isis_adjacency *adj = args->list_entry;
2a1c520e 135
60ee8be1 136 return yang_data_new_enum(args->xpath, adj->level);
2a1c520e
RW
137}
138
139/*
140 * XPath:
27171928 141 * /frr-interface:lib/interface/state/frr-isisd:isis/adjacencies/adjacency/neighbor-sysid
2a1c520e
RW
142 */
143struct yang_data *
27171928 144lib_interface_state_isis_adjacencies_adjacency_neighbor_sysid_get_elem(
60ee8be1 145 struct nb_cb_get_elem_args *args)
2a1c520e 146{
60ee8be1 147 const struct isis_adjacency *adj = args->list_entry;
2a1c520e 148
60ee8be1 149 return yang_data_new_string(args->xpath, sysid_print(adj->sysid));
2a1c520e
RW
150}
151
152/*
153 * XPath:
27171928 154 * /frr-interface:lib/interface/state/frr-isisd:isis/adjacencies/adjacency/neighbor-extended-circuit-id
2a1c520e
RW
155 */
156struct yang_data *
27171928 157lib_interface_state_isis_adjacencies_adjacency_neighbor_extended_circuit_id_get_elem(
60ee8be1 158 struct nb_cb_get_elem_args *args)
2a1c520e 159{
60ee8be1 160 const struct isis_adjacency *adj = args->list_entry;
2a1c520e 161
60ee8be1 162 return yang_data_new_uint32(args->xpath, adj->circuit->circuit_id);
2a1c520e
RW
163}
164
165/*
166 * XPath:
27171928 167 * /frr-interface:lib/interface/state/frr-isisd:isis/adjacencies/adjacency/neighbor-snpa
2a1c520e
RW
168 */
169struct yang_data *
27171928 170lib_interface_state_isis_adjacencies_adjacency_neighbor_snpa_get_elem(
60ee8be1 171 struct nb_cb_get_elem_args *args)
2a1c520e 172{
60ee8be1 173 const struct isis_adjacency *adj = args->list_entry;
2a1c520e 174
60ee8be1 175 return yang_data_new_string(args->xpath, snpa_print(adj->snpa));
2a1c520e
RW
176}
177
178/*
179 * XPath:
27171928 180 * /frr-interface:lib/interface/state/frr-isisd:isis/adjacencies/adjacency/hold-timer
2a1c520e 181 */
27171928
RW
182struct yang_data *
183lib_interface_state_isis_adjacencies_adjacency_hold_timer_get_elem(
60ee8be1 184 struct nb_cb_get_elem_args *args)
2a1c520e 185{
60ee8be1 186 const struct isis_adjacency *adj = args->list_entry;
2a1c520e 187
60ee8be1 188 return yang_data_new_uint16(args->xpath, adj->hold_time);
2a1c520e
RW
189}
190
191/*
192 * XPath:
27171928 193 * /frr-interface:lib/interface/state/frr-isisd:isis/adjacencies/adjacency/neighbor-priority
2a1c520e
RW
194 */
195struct yang_data *
27171928 196lib_interface_state_isis_adjacencies_adjacency_neighbor_priority_get_elem(
60ee8be1 197 struct nb_cb_get_elem_args *args)
2a1c520e 198{
60ee8be1 199 const struct isis_adjacency *adj = args->list_entry;
2a1c520e 200
60ee8be1 201 return yang_data_new_uint8(args->xpath, adj->prio[adj->level - 1]);
2a1c520e
RW
202}
203
204/*
205 * XPath:
27171928 206 * /frr-interface:lib/interface/state/frr-isisd:isis/adjacencies/adjacency/state
2a1c520e 207 */
27171928 208struct yang_data *lib_interface_state_isis_adjacencies_adjacency_state_get_elem(
60ee8be1 209 struct nb_cb_get_elem_args *args)
2a1c520e 210{
60ee8be1 211 const struct isis_adjacency *adj = args->list_entry;
2a1c520e 212
60ee8be1
RW
213 return yang_data_new_string(args->xpath,
214 isis_adj_yang_state(adj->adj_state));
2a1c520e
RW
215}
216
217/*
218 * XPath:
27171928 219 * /frr-interface:lib/interface/state/frr-isisd:isis/event-counters/adjacency-changes
2a1c520e 220 */
27171928
RW
221struct yang_data *
222lib_interface_state_isis_event_counters_adjacency_changes_get_elem(
60ee8be1 223 struct nb_cb_get_elem_args *args)
2a1c520e
RW
224{
225 struct interface *ifp;
226 struct isis_circuit *circuit;
227
60ee8be1 228 ifp = (struct interface *)args->list_entry;
2a1c520e
RW
229 if (!ifp)
230 return NULL;
231
232 circuit = circuit_scan_by_ifp(ifp);
233 if (!circuit)
234 return NULL;
235
60ee8be1 236 return yang_data_new_uint32(args->xpath, circuit->adj_state_changes);
2a1c520e
RW
237}
238
239/*
240 * XPath:
27171928 241 * /frr-interface:lib/interface/state/frr-isisd:isis/event-counters/adjacency-number
2a1c520e 242 */
27171928
RW
243struct yang_data *
244lib_interface_state_isis_event_counters_adjacency_number_get_elem(
60ee8be1 245 struct nb_cb_get_elem_args *args)
2a1c520e
RW
246{
247 struct interface *ifp;
248 struct isis_circuit *circuit;
249 struct isis_adjacency *adj;
250 struct listnode *node;
251 uint32_t total = 0;
252
60ee8be1 253 ifp = (struct interface *)args->list_entry;
2a1c520e
RW
254 if (!ifp)
255 return NULL;
256
257 circuit = circuit_scan_by_ifp(ifp);
258 if (!circuit)
259 return NULL;
260
261 /*
262 * TODO: keep track of the number of adjacencies instead of calculating
263 * it on demand.
264 */
265 switch (circuit->circ_type) {
266 case CIRCUIT_T_BROADCAST:
267 for (int level = ISIS_LEVEL1; level <= ISIS_LEVELS; level++) {
268 for (ALL_LIST_ELEMENTS_RO(
269 circuit->u.bc.adjdb[level - 1], node, adj))
270 total++;
271 }
272 break;
273 case CIRCUIT_T_P2P:
274 adj = circuit->u.p2p.neighbor;
275 if (adj)
276 total = 1;
277 break;
278 default:
279 break;
280 }
281
60ee8be1 282 return yang_data_new_uint32(args->xpath, total);
2a1c520e
RW
283}
284
285/*
27171928
RW
286 * XPath:
287 * /frr-interface:lib/interface/state/frr-isisd:isis/event-counters/init-fails
2a1c520e 288 */
27171928 289struct yang_data *lib_interface_state_isis_event_counters_init_fails_get_elem(
60ee8be1 290 struct nb_cb_get_elem_args *args)
2a1c520e
RW
291{
292 struct interface *ifp;
293 struct isis_circuit *circuit;
294
60ee8be1 295 ifp = (struct interface *)args->list_entry;
2a1c520e
RW
296 if (!ifp)
297 return NULL;
298
299 circuit = circuit_scan_by_ifp(ifp);
300 if (!circuit)
301 return NULL;
302
60ee8be1 303 return yang_data_new_uint32(args->xpath, circuit->init_failures);
2a1c520e
RW
304}
305
306/*
307 * XPath:
27171928 308 * /frr-interface:lib/interface/state/frr-isisd:isis/event-counters/adjacency-rejects
2a1c520e 309 */
27171928
RW
310struct yang_data *
311lib_interface_state_isis_event_counters_adjacency_rejects_get_elem(
60ee8be1 312 struct nb_cb_get_elem_args *args)
2a1c520e
RW
313{
314 struct interface *ifp;
315 struct isis_circuit *circuit;
316
60ee8be1 317 ifp = (struct interface *)args->list_entry;
2a1c520e
RW
318 if (!ifp)
319 return NULL;
320
321 circuit = circuit_scan_by_ifp(ifp);
322 if (!circuit)
323 return NULL;
324
60ee8be1 325 return yang_data_new_uint32(args->xpath, circuit->rej_adjacencies);
2a1c520e
RW
326}
327
328/*
329 * XPath:
27171928 330 * /frr-interface:lib/interface/state/frr-isisd:isis/event-counters/id-len-mismatch
2a1c520e 331 */
27171928
RW
332struct yang_data *
333lib_interface_state_isis_event_counters_id_len_mismatch_get_elem(
60ee8be1 334 struct nb_cb_get_elem_args *args)
2a1c520e
RW
335{
336 struct interface *ifp;
337 struct isis_circuit *circuit;
338
60ee8be1 339 ifp = (struct interface *)args->list_entry;
2a1c520e
RW
340 if (!ifp)
341 return NULL;
342
343 circuit = circuit_scan_by_ifp(ifp);
344 if (!circuit)
345 return NULL;
346
60ee8be1 347 return yang_data_new_uint32(args->xpath, circuit->id_len_mismatches);
2a1c520e
RW
348}
349
350/*
351 * XPath:
27171928 352 * /frr-interface:lib/interface/state/frr-isisd:isis/event-counters/max-area-addresses-mismatch
2a1c520e
RW
353 */
354struct yang_data *
27171928 355lib_interface_state_isis_event_counters_max_area_addresses_mismatch_get_elem(
60ee8be1 356 struct nb_cb_get_elem_args *args)
2a1c520e
RW
357{
358 struct interface *ifp;
359 struct isis_circuit *circuit;
360
60ee8be1 361 ifp = (struct interface *)args->list_entry;
2a1c520e
RW
362 if (!ifp)
363 return NULL;
364
365 circuit = circuit_scan_by_ifp(ifp);
366 if (!circuit)
367 return NULL;
368
60ee8be1
RW
369 return yang_data_new_uint32(args->xpath,
370 circuit->max_area_addr_mismatches);
2a1c520e
RW
371}
372
373/*
374 * XPath:
27171928 375 * /frr-interface:lib/interface/state/frr-isisd:isis/event-counters/authentication-type-fails
2a1c520e
RW
376 */
377struct yang_data *
27171928 378lib_interface_state_isis_event_counters_authentication_type_fails_get_elem(
60ee8be1 379 struct nb_cb_get_elem_args *args)
2a1c520e
RW
380{
381 struct interface *ifp;
382 struct isis_circuit *circuit;
383
60ee8be1 384 ifp = (struct interface *)args->list_entry;
2a1c520e
RW
385 if (!ifp)
386 return NULL;
387
388 circuit = circuit_scan_by_ifp(ifp);
389 if (!circuit)
390 return NULL;
391
60ee8be1 392 return yang_data_new_uint32(args->xpath, circuit->auth_type_failures);
2a1c520e
RW
393}
394
395/*
396 * XPath:
27171928 397 * /frr-interface:lib/interface/state/frr-isisd:isis/event-counters/authentication-fails
2a1c520e
RW
398 */
399struct yang_data *
27171928 400lib_interface_state_isis_event_counters_authentication_fails_get_elem(
60ee8be1 401 struct nb_cb_get_elem_args *args)
2a1c520e
RW
402{
403 struct interface *ifp;
404 struct isis_circuit *circuit;
405
60ee8be1 406 ifp = (struct interface *)args->list_entry;
2a1c520e
RW
407 if (!ifp)
408 return NULL;
409
410 circuit = circuit_scan_by_ifp(ifp);
411 if (!circuit)
412 return NULL;
413
60ee8be1 414 return yang_data_new_uint32(args->xpath, circuit->auth_failures);
2a1c520e 415}