Line data Source code
1 : #include <stdio.h>
2 : #include <stdlib.h>
3 : #include <stdbool.h>
4 :
5 : #include <libxml/xmlmemory.h>
6 :
7 : #include <vtest.h>
8 : #include <vr_types.h>
9 : #include <vt_gen_lib.h>
10 :
11 : #include <nl_util.h>
12 :
13 : struct received_vrouter received_msg;
14 : struct return_vrouter return_msg;
15 :
16 : static void
17 152 : interface_req_process(void *s) {
18 152 : void *buf = calloc(1, sizeof(vr_interface_req));
19 152 : if (!buf) {
20 0 : fprintf(stderr, "Cannot alloc memory \n");
21 0 : exit(ENOMEM);
22 : }
23 :
24 152 : received_msg.ptr_num++;
25 152 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_interface_req_free;
26 152 : received_msg.mem_handles[received_msg.ptr_num].mem =
27 152 : (memcpy(buf, s, sizeof(vr_interface_req)));
28 152 : memset(s, 0, sizeof(vr_interface_req));
29 152 : }
30 :
31 : static void
32 6 : nexthop_req_process(void *s) {
33 6 : void *buf = calloc(1, sizeof(vr_nexthop_req));
34 6 : if (!buf) {
35 0 : fprintf(stderr, "Cannot alloc memory \n");
36 0 : exit(ENOMEM);
37 : }
38 :
39 6 : received_msg.ptr_num++;
40 6 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_nexthop_req_free;
41 6 : received_msg.mem_handles[received_msg.ptr_num].mem =
42 6 : (memcpy(buf, s, sizeof(vr_nexthop_req)));
43 6 : memset(s, 0, sizeof(vr_nexthop_req));
44 6 : }
45 :
46 : static void
47 321 : route_req_process(void *s) {
48 321 : void *buf = calloc(1, sizeof(vr_route_req));
49 321 : if (!buf) {
50 0 : fprintf(stderr, "Cannot alloc memory \n");
51 0 : exit(ENOMEM);
52 : }
53 :
54 321 : received_msg.ptr_num++;
55 321 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_route_req_free;
56 321 : received_msg.mem_handles[received_msg.ptr_num].mem =
57 321 : (memcpy(buf, s, sizeof(vr_route_req)));
58 321 : memset(s, 0, sizeof(vr_route_req));
59 321 : }
60 :
61 : static void
62 2794 : response_process(void *s) {
63 2794 : vr_response *buf = (vr_response *)s;
64 :
65 2794 : return_msg.ptr_num++;
66 2794 : return_msg.return_val[return_msg.ptr_num] = buf->resp_code;
67 2794 : return_msg.has_returned = true;
68 2794 : }
69 :
70 : static void
71 0 : vrf_stats_req_process(void *s) {
72 0 : void *buf = calloc(1, sizeof(vr_vrf_stats_req));
73 0 : if (!buf) {
74 0 : fprintf(stderr, "Cannot alloc memory \n");
75 0 : exit(ENOMEM);
76 : }
77 :
78 0 : received_msg.ptr_num++;
79 0 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_vrf_stats_req_free;
80 0 : received_msg.mem_handles[received_msg.ptr_num].mem =
81 0 : (memcpy(buf, s, sizeof(vr_vrf_stats_req)));
82 0 : memset(s, 0, sizeof(vr_vrf_stats_req));
83 0 : }
84 :
85 : static void
86 0 : vt_vrouter_ops_process(void *s) {
87 0 : void *buf = calloc(1, sizeof(vrouter_ops));
88 0 : if (!buf) {
89 0 : fprintf(stderr, "Cannot alloc memory \n");
90 0 : exit(ENOMEM);
91 : }
92 :
93 0 : received_msg.ptr_num++;
94 0 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vrouter_ops_free;
95 0 : received_msg.mem_handles[received_msg.ptr_num].mem =
96 0 : (memcpy(buf, s, sizeof(vrouter_ops)));
97 0 : memset(s, 0, sizeof(vrouter_ops));
98 0 : }
99 :
100 : static void
101 0 : vrf_assign_req_process(void *s) {
102 0 : void *buf = calloc(1, sizeof(vr_vrf_assign_req));
103 0 : if (!buf) {
104 0 : fprintf(stderr, "Cannot alloc memory \n");
105 0 : exit(ENOMEM);
106 : }
107 :
108 0 : received_msg.ptr_num++;
109 0 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_vrf_assign_req_free;
110 0 : received_msg.mem_handles[received_msg.ptr_num].mem =
111 0 : (memcpy(buf, s, sizeof(vr_vrf_assign_req)));
112 0 : memset(s, 0, sizeof(vr_vrf_assign_req));
113 0 : }
114 :
115 : static void
116 0 : flow_req_process(void *s) {
117 0 : void *buf = calloc(1, sizeof(vr_flow_req));
118 0 : if (!buf) {
119 0 : fprintf(stderr, "Cannot alloc memory \n");
120 0 : exit(ENOMEM);
121 : }
122 :
123 0 : received_msg.ptr_num++;
124 0 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_flow_req_free;
125 0 : received_msg.mem_handles[received_msg.ptr_num].mem =
126 0 : (memcpy(buf, s, sizeof(vr_flow_req)));
127 0 : memset(s, 0, sizeof(vr_flow_req));
128 0 : }
129 :
130 : static void
131 322 : flow_response_process(void *s) {
132 322 : void *buf = calloc(1, sizeof(vr_flow_response));
133 322 : if (!buf) {
134 0 : fprintf(stderr, "Cannot alloc memory \n");
135 0 : exit(ENOMEM);
136 : }
137 :
138 322 : received_msg.ptr_num++;
139 322 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_flow_response_free;
140 322 : received_msg.mem_handles[received_msg.ptr_num].mem =
141 322 : (memcpy(buf, s, sizeof(vr_flow_response)));
142 322 : memset(s, 0, sizeof(vr_flow_response));
143 322 : }
144 :
145 : static void
146 1 : vxlan_req_process(void *s) {
147 1 : void *buf = calloc(1, sizeof(vr_vxlan_req));
148 1 : if (!buf) {
149 0 : fprintf(stderr, "Cannot alloc memory \n");
150 0 : exit(ENOMEM);
151 : }
152 :
153 1 : received_msg.ptr_num++;
154 1 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_vxlan_req_free;
155 1 : received_msg.mem_handles[received_msg.ptr_num].mem =
156 1 : (memcpy(buf, s, sizeof(vr_vxlan_req)));
157 1 : memset(s, 0, sizeof(vr_vxlan_req));
158 1 : }
159 :
160 : static void
161 5 : drop_stats_req_process(void *s) {
162 5 : void *buf = calloc(1, sizeof(vr_drop_stats_req));
163 5 : if (!buf) {
164 0 : fprintf(stderr, "Cannot alloc memory \n");
165 0 : exit(ENOMEM);
166 : }
167 :
168 5 : received_msg.ptr_num++;
169 5 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_drop_stats_req_free;
170 5 : received_msg.mem_handles[received_msg.ptr_num].mem =
171 5 : (memcpy(buf, s, sizeof(vr_drop_stats_req)));
172 5 : memset(s, 0, sizeof(vr_drop_stats_req));
173 5 : }
174 :
175 : static void
176 1 : mpls_req_process(void *s) {
177 1 : void *buf = calloc(1, sizeof(vr_mpls_req));
178 1 : if (!buf) {
179 0 : fprintf(stderr, "Cannot alloc memory \n");
180 0 : exit(ENOMEM);
181 : }
182 :
183 1 : received_msg.ptr_num++;
184 1 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_mpls_req_free;
185 1 : received_msg.mem_handles[received_msg.ptr_num].mem =
186 1 : (memcpy(buf, s, sizeof(vr_mpls_req)));
187 1 : memset(s, 0, sizeof(vr_mpls_req));
188 1 : }
189 :
190 : static void
191 1 : mirror_req_process(void *s) {
192 1 : void *buf = calloc(1, sizeof(vr_mirror_req));
193 1 : if (!buf) {
194 0 : fprintf(stderr, "Cannot alloc memory \n");
195 0 : exit(ENOMEM);
196 : }
197 :
198 1 : received_msg.ptr_num++;
199 1 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_mirror_req_free;
200 1 : received_msg.mem_handles[received_msg.ptr_num].mem =
201 1 : (memcpy(buf, s, sizeof(vr_mirror_req)));
202 1 : memset(s, 0, sizeof(vr_mirror_req));
203 1 : }
204 :
205 : static void
206 0 : mem_stats_req_process(void *s) {
207 0 : void *buf = calloc(1, sizeof(vr_mem_stats_req));
208 0 : if (!buf) {
209 0 : fprintf(stderr, "Cannot alloc memory \n");
210 0 : exit(ENOMEM);
211 : }
212 :
213 0 : received_msg.ptr_num++;
214 0 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_mem_stats_req_free;
215 0 : received_msg.mem_handles[received_msg.ptr_num].mem =
216 0 : (memcpy(buf, s, sizeof(vr_mem_stats_req)));
217 0 : memset(s, 0, sizeof(vr_mem_stats_req));
218 0 : }
219 :
220 : static void
221 0 : hugepage_config_process(void *s) {
222 0 : void *buf = calloc(1, sizeof(vr_hugepage_config));
223 0 : if (!buf) {
224 0 : fprintf(stderr, "Cannot alloc memory \n");
225 0 : exit(ENOMEM);
226 : }
227 :
228 0 : received_msg.ptr_num++;
229 0 : received_msg.mem_handles[received_msg.ptr_num].free_mem = vr_hugepage_config_free;
230 0 : received_msg.mem_handles[received_msg.ptr_num].mem =
231 0 : (memcpy(buf, s, sizeof(vr_hugepage_config)));
232 0 : memset(s, 0, sizeof(vr_hugepage_config));
233 0 : }
234 :
235 : void
236 2920 : vt_fill_nl_callbacks()
237 : {
238 2920 : nl_cb.vr_interface_req_process = interface_req_process;
239 2920 : nl_cb.vr_nexthop_req_process = nexthop_req_process;
240 2920 : nl_cb.vr_route_req_process = route_req_process;
241 2920 : nl_cb.vr_response_process = response_process;
242 2920 : nl_cb.vr_vrf_stats_req_process = vrf_stats_req_process;
243 2920 : nl_cb.vrouter_ops_process = vt_vrouter_ops_process;
244 2920 : nl_cb.vr_vrf_assign_req_process = vrf_assign_req_process;
245 2920 : nl_cb.vr_flow_req_process = flow_req_process;
246 2920 : nl_cb.vr_flow_response_process = flow_response_process;
247 2920 : nl_cb.vr_vxlan_req_process = vxlan_req_process;
248 2920 : nl_cb.vr_drop_stats_req_process = drop_stats_req_process;
249 2920 : nl_cb.vr_mpls_req_process = mpls_req_process;
250 2920 : nl_cb.vr_mirror_req_process = mirror_req_process;
251 2920 : nl_cb.vr_mem_stats_req_process = mem_stats_req_process;
252 2920 : nl_cb.vr_hugepage_config_process = hugepage_config_process;
253 2920 : }
|