-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
136 lines (127 loc) · 4.8 KB
/
test.cpp
File metadata and controls
136 lines (127 loc) · 4.8 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <iostream>
#include <libyang/libyang.h>
#include <stdlib.h>
using namespace std;
string openconfigInterfacesInterfaces =
"{\n"
" \"openconfig-interfaces:interfaces\": {\n"
" \"interface\": [\n"
" {\n"
" \"config\": {\n"
" \"description\": \"This is ifc 0/2\",\n"
" \"enabled\": true,\n"
" \"mtu\": 1500,\n"
" \"name\": \"0/2\",\n"
" \"type\": \"iana-if-type:ethernetCsmacd\"\n"
" },\n"
" \"name\": \"0/2\",\n"
" \"state\": {\n"
" \"admin-status\": \"UP\",\n"
" \"counters\": {\n"
" \"in-broadcast-pkts\": 2767640,\n"
" \"in-discards\": 0,\n"
" \"in-errors\": 0,\n"
" \"in-multicast-pkts\": 5769311,\n"
" \"in-octets\": 427066814515,\n"
" \"in-unicast-pkts\": 293117,\n"
" \"out-broadcast-pkts\": 7628,\n"
" \"out-discards\": 0,\n"
" \"out-errors\": 0,\n"
" \"out-multicast-pkts\": 325039,\n"
" \"out-octets\": 72669652,\n"
" \"out-unicast-pkts\": 125182\n"
" },\n"
" \"description\": \"Some descr\",\n"
" \"enabled\": true,\n"
" \"mtu\": 1518,\n"
" \"name\": \"0/2\",\n"
" \"oper-status\": \"DOWN\",\n"
" \"type\": \"iana-if-type:ethernetCsmacd\"\n"
" }\n"
" },\n"
" {\n"
" \"config\": {\n"
" \"description\": \"This is ifc 0/3\",\n"
" \"enabled\": true,\n"
" \"mtu\": 1500,\n"
" \"name\": \"0/3\",\n"
" \"type\": \"iana-if-type:ethernetCsmacd\"\n"
" },\n"
" \"name\": \"0/3\",\n"
" \"state\": {\n"
" \"admin-status\": \"UP\",\n"
" \"counters\": {\n"
" \"in-broadcast-pkts\": 2767641,\n"
" \"in-discards\": 0,\n"
" \"in-errors\": 0,\n"
" \"in-multicast-pkts\": 5769311,\n"
" \"in-octets\": 427066814515,\n"
" \"in-unicast-pkts\": 293117,\n"
" \"out-broadcast-pkts\": 7628,\n"
" \"out-discards\": 0,\n"
" \"out-errors\": 0,\n"
" \"out-multicast-pkts\": 325039,\n"
" \"out-octets\": 72669652,\n"
" \"out-unicast-pkts\": 125182\n"
" },\n"
" \"enabled\": true,\n"
" \"mtu\": 1518,\n"
" \"name\": \"0/3\",\n"
" \"oper-status\": \"DOWN\",\n"
" \"type\": \"iana-if-type:ethernetCsmacd\"\n"
" }\n"
" },\n"
" {\n"
" \"config\": {\n"
" \"description\": \"This is ifc 0/4\",\n"
" \"enabled\": true,\n"
" \"mtu\": 1500,\n"
" \"name\": \"0/4\",\n"
" \"type\": \"iana-if-type:ethernetCsmacd\"\n"
" },\n"
" \"name\": \"0/4\",\n"
" \"state\": {\n"
" \"admin-status\": \"UP\",\n"
" \"counters\": {\n"
" \"in-broadcast-pkts\": 2767642,\n"
" \"in-discards\": 0,\n"
" \"in-errors\": 0,\n"
" \"in-multicast-pkts\": 5769311,\n"
" \"in-octets\": 427066814515,\n"
" \"in-unicast-pkts\": 293117,\n"
" \"out-broadcast-pkts\": 7628,\n"
" \"out-discards\": 0,\n"
" \"out-errors\": 0,\n"
" \"out-multicast-pkts\": 325039,\n"
" \"out-octets\": 72669652,\n"
" \"out-unicast-pkts\": 125182\n"
" },\n"
" \"enabled\": true,\n"
" \"mtu\": 1518,\n"
" \"name\": \"0/4\",\n"
" \"oper-status\": \"DOWN\",\n"
" \"type\": \"iana-if-type:ethernetCsmacd\"\n"
" }\n"
" }\n"
" ]\n"
" }\n"
"}";
int main() {
ly_ctx *pLyCtx = ly_ctx_new("./yang", 0);
ly_ctx_load_module(pLyCtx, "iana-if-type", NULL);
const lys_module *pModule =
ly_ctx_load_module(pLyCtx, "openconfig-interfaces", NULL);
lyd_node *pNode = lyd_parse_mem(
pLyCtx, const_cast<char *>(openconfigInterfacesInterfaces.c_str()),
LYD_JSON, LYD_OPT_DATA | LYD_OPT_DATA_NO_YANGLIB);
string path = "/openconfig-interfaces:interfaces/interface[name='0/3']/state";
ly_set *pSet = lyd_find_path(pNode, const_cast<char *>(path.c_str()));
if (pSet->number != 1) {
return 1;
}
char *buff;
lyd_print_mem(&buff, pSet->set.d[0], LYD_JSON, 0);
std::cout << buff << std::endl;
free(buff);
return 0;
}