]>
git.proxmox.com Git - mirror_frr.git/blob - lib/command_graph.h
2 * Graph data structure and companion routines for CLI backend.
5 * Copyright (C) 2016 Cumulus Networks, Inc.
7 * This file is part of GNU Zebra.
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Zebra; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 #ifndef _ZEBRA_COMMAND_GRAPH_H
26 #define _ZEBRA_COMMAND_GRAPH_H
31 * Types for graph nodes.
33 * The node type determines what kind of data the node can match (in the
34 * matching use case) or hold (in the argv use case).
38 IPV4_GN
, // IPV4 addresses
39 IPV4_PREFIX_GN
, // IPV4 network prefixes
40 IPV6_GN
, // IPV6 prefixes
41 IPV6_PREFIX_GN
, // IPV6 network prefixes
43 RANGE_GN
, // integer ranges
45 VARIABLE_GN
, // almost anything
47 SELECTOR_GN
, // marks beginning of selector subgraph
48 OPTION_GN
, // marks beginning of option subgraph
49 NUL_GN
, // transparent node with various uses
50 START_GN
, // first node in the graph (has no parents)
51 END_GN
// leaf node in the graph, has pointer to cmd_element
56 * Used for matching and passing arguments to vtysh commands.
60 enum graph_node_type type
; // data type this node matches or holds
61 vector children
; // this node's children
63 char *text
; // original format text
64 char *doc
; // docstring for this node
65 long long value
; // for NUMBER_GN
66 long long min
, max
; // for RANGE_GN
68 /* cmd_element struct pointer, only valid for END_GN */
69 struct cmd_element
*element
;
71 /* used for passing arguments to command functions */
74 /* refcount for node parents */
79 * Adds a node as a child of another node.
81 * @param[in] parent node
82 * @param[in] child node
86 graphnode_add_child (struct graph_node
*parent
, struct graph_node
*child
);
89 * Creates a new node, initializes all fields to default values and sets the
92 * @param[in] type node type
93 * @return pointer to the created node
96 graphnode_new (enum graph_node_type type
);
99 * Deletes a graph node without deleting its children.
101 * @param[out] node pointer to node to delete
104 graphnode_delete (struct graph_node
*node
);
107 * Deletes a graph node and recursively deletes all its direct and indirect
110 * @param[out] node start node of graph to free
113 graphnode_delete_graph (struct graph_node
*node
);
115 #endif /* _ZEBRA_COMMAND_GRAPH_H */