-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnwcli.c
88 lines (68 loc) · 2.24 KB
/
nwcli.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "CommandParser/libcli.h"
#include "CommandParser/cmdtlv.h"
#include "cmdcodes.h"
#include "graph.h"
#include <stdio.h>
extern graph_t *topo;
/* node dumping*/
void dump_nw_node(param_t *param, ser_buff_t *tlv_buf) {
node_t *node ;
glthread_t *curr;
ITERATE_GLTHREAD_BEGIN(&topo->node_list,curr) {
node = graph_glue_to_node(curr);
printf("Node Name = %s\n",node->node_name);
} ITERATE_GLTHREAD_END(&topo->node_list,curr);
}
/*General validations and checks */
int valid_node_existence(char *node_name) {
node_t *node = get_node_by_node_name(topo,node_name);
if(node)
return VALIDATION_SUCCESS;
printf("Error : Node %s does not exist\n",node_name);
return VALIDATION_FAILED;
}
/*Generic Topology Commands*/
static int
show_nw_topology_handler(param_t *param, ser_buff_t *tlv_buf, op_mode enable_or_disable){
int CMDCODE = -1;
CMDCODE = EXTRACT_CMD_CODE(tlv_buf);
switch(CMDCODE){
case CMDCODE_SHOW_NW_TOPOLOGY:
dump_nw_graph(topo);
break;
default:
;
}
return 0;
}
void nw_init_cli() {
init_libcli();
param_t *show = libcli_get_show_hook();
param_t *debug = libcli_get_debug_hook();
param_t *config = libcli_get_config_hook();
param_t *run = libcli_get_run_hook();
param_t *debug_show = libcli_get_debug_show_hook();
param_t *root = libcli_get_root();
{
/*show topology*/
static param_t topology;
init_param(&topology, CMD, "topology", show_nw_topology_handler, 0, INVALID, 0, "Dump Complete Network Topology");
libcli_register_param(show, &topology);
set_param_cmd_code(&topology, CMDCODE_SHOW_NW_TOPOLOGY);
}
{
/* run node*/
static param_t node;
init_param(&node, CMD, "node", NULL, 0, INVALID, 0, "\"node\" keyword");
libcli_register_param(run, &node);
libcli_register_display_callback(&node, dump_nw_node);
{
/*run node name*/
static param_t node_name;
init_param(&node_name, LEAF, 0, 0,valid_node_existence, INVALID, 0, "Node Name");
libcli_register_param(&node, &node_name);
{
}
}
}
}