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