-
Notifications
You must be signed in to change notification settings - Fork 171
/
README.txt
225 lines (173 loc) · 5.63 KB
/
README.txt
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
The xml file specification
-------------------------
<?xml version="1.0"?>
<test>
<test_name>Interface test</test_name>
<message>
<vif>
<m_op>Add</m_op>
<vif_type>Virtual</vif_type>
<vif_index>4</vif_index>
<vif_vrf>0</vif_vrf>
<vif_mac>00:01:02:03:04:05</vif_mac>
<vif_mtu>1514</vif_mtu>
</vif>
<message_return>0</message_return>
</message>
<test_result>
<message>
<vif>
<m_op>Get</m_op>
<vif_index>4</vif_index>
</vif>
</message>
<message_return>0</message_return>
<message_expect>
<vif>
<vif_type>Virtual</vif_type>
<vif_index>4</vif_index>
<vif_vrf>0</vif_vrf>
<vif_mac>00:01:02:03:04:05</vif_mac>
<vif_mtu>1514</vif_mtu>
</vif>
</message_expect>
</test_result>
</test>
The generated code from sandesh file processing
-----------------------------------------------
There is a sandesh compiler that parses the sandesh file and autogenerates
code to read values from specification file and assign it to corresponding
variables of the sandesh structure. It takes care of all known data types
of sandesh message (including list<type> and string). As of now, the compiler
generates 'vt_gen_sandesh.c' (that contains the above described functionality)
, 'vt_gen_message_modules.c' (that contains the list of nodes under the message
module of vtest), 'vt_gen_message_modules.h' (a header file that contains all
the required declarations) and 'vt_gen_expect.c' that sanitizes the received
message with expected values from the specification file.
The generator is still evolving. More functionality will be added to generator
on need basis.
Snap of code generated in 'vt_gen_sandesh.c'
-------------------------------------------
....
void *
vr_nexthop_req_node(xmlNodePtr node, struct vtest *test)
{
unsigned int list_size;
vr_nexthop_req *req;
req = calloc(sizeof(*req), 1);
if (!req)
return NULL;
node = node->xmlChildrenNode;
while (node) {
if (!node->content || !strlen(node->content)) {
return NULL;
}
if (!strncmp(node->name, "h_op", strlen(node->content))) {
req->h_op = vt_gen_op(node->content);
} else if (!strncmp(node->name, "nhr_type", strlen(node->content))) {
req->nhr_type = strtoul(node->content, NULL, 0);
} else if (!strncmp(node->name, "nhr_family", strlen(node->content))) {
....
} else if (!strncmp(node->name, "nhr_label_list", strlen(node->content))) {
req->nhr_label_list = vt_gen_list(node->content, GEN_TYPE_U32, &list_size);
req->nhr_label_list_size = list_size;
}
node = node->next;
}
return (void *)req;
}
Snap of code generated in 'vt_gen_message_modules.c'
----------------------------------------------------
/*
* Auto generated file
*/
#include <string.h>
#include <stdbool.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <vr_types.h>
#include <vt_gen_lib.h>
#include <vtest.h>
#include <vt_gen_message_modules.h>
struct vt_message_module vt_message_modules[] = {
{
.vmm_name = "vr_nexthop_req",
.vmm_node = vr_nexthop_req_node,
.vmm_expect = vr_nexthop_req_expect,
.vmm_size = sizeof(vr_nexthop_req),
},
{
.vmm_name = "vr_interface_req",
.vmm_node = vr_interface_req_node,
....
....
{
.vmm_name = "expect",
.vmm_node = vt_expect_node,
.vmm_size = 0,
},
};
unsigned int vt_message_modules_num =
sizeof(vt_message_modules) / sizeof(vt_message_modules[0]);
Snap of code generated in 'vt_gen_message_modules.h'
---------------------------------------------------
/*
* Auto generated file
*/
#ifndef __VT_GEN_MESSAGE_MODULES_H__
#define __VT_GEN_MESSAGE_MODULES_H__
#include <string.h>
#include <stdbool.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <vr_types.h>
#include <vt_gen_lib.h>
#include <vtest.h>
struct vt_message_module {
char *vmm_name;
void *(*vmm_node)(xmlNodePtr, struct vtest *);
bool (*vmm_expect)(xmlNodePtr, struct vtest *, void *);
unsigned int vmm_size;
};
extern void *vr_nexthop_req_node(xmlNodePtr, struct vtest *);
extern bool vr_nexthop_req_expect(xmlNodePtr, struct vtest *, void *);
....
....
extern void *vt_return_node(xmlNodePtr, struct vtest *);
extern void *vt_expect_node(xmlNodePtr, struct vtest *);
#endif
Snap of code generated in 'vt_gen_sandesh_expect.c'
--------------------------------------------------
/*
* Auto generated file
*/
#include <string.h>
#include <stdbool.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <vr_types.h>
#include <vt_gen_lib.h>
#include <vtest.h>
bool
vr_nexthop_req_expect(xmlNodePtr node, struct vtest *test, void *buf)
{
bool result = true;
unsigned int list_size;
vr_nexthop_req *req = (vr_nexthop_req *)buf;
node = node->xmlChildrenNode;
while (node) {
if (!node->content || !strlen(node->content)) {
return NULL;
}
....
....
} else if (!strncmp(node->name, "nhr_label_list", strlen(node->content))) {
result = vt_gen_list_compare(req->nhr_label_list,
req->nhr_label_list_size, node->content, GEN_TYPE_U32);
}
if (!result)
return result;
node = node->next;
}
return result;
}