2 * collectd - src/ovs_stats.c
4 * Copyright(c) 2016 Intel Corporation. All rights reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is furnished to
13 * so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
17 * copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * Taras Chornyi <tarasx.chornyi@intel.com>
33 #include "utils_ovs.h" /* OvS helpers */
36 static const char plugin_name[] = "ovs_stats";
38 typedef enum iface_counter {
54 rx_128_to_255_packets,
55 rx_256_to_511_packets,
56 rx_512_to_1023_packets,
57 rx_1024_to_1522_packets,
58 rx_1523_to_max_packets,
61 tx_128_to_255_packets,
62 tx_256_to_511_packets,
63 tx_512_to_1023_packets,
64 tx_1024_to_1522_packets,
65 tx_1523_to_max_packets,
76 rx_management_dropped,
77 rx_mbuf_allocation_errors,
79 rx_total_missed_packets,
81 rx_management_packets,
82 tx_management_packets,
92 #define IFACE_COUNTER_MAX (__iface_counter_max - 1)
93 #define IFACE_COUNTER_COUNT (__iface_counter_max)
94 #define PORT_NAME_SIZE_MAX 255
97 typedef struct interface_s {
98 char name[PORT_NAME_SIZE_MAX]; /* Interface name */
99 char iface_uuid[UUID_SIZE]; /* Interface table uuid */
100 char ex_iface_id[UUID_SIZE]; /* External iface id */
101 char ex_vm_id[UUID_SIZE]; /* External vm id */
102 int64_t stats[IFACE_COUNTER_COUNT]; /* Statistics for interface */
103 struct interface_s *next; /* Next interface for associated port */
106 typedef struct port_s {
107 char name[PORT_NAME_SIZE_MAX]; /* Port name */
108 char port_uuid[UUID_SIZE]; /* Port table _uuid */
109 struct bridge_list_s *br; /* Pointer to bridge */
110 struct interface_s *iface; /* Pointer to first interface */
111 struct port_s *next; /* Next port */
114 typedef struct bridge_list_s {
115 char *name; /* Bridge name */
116 struct bridge_list_s *next; /* Next bridge*/
119 #define cnt_str(x) [x] = #x
121 static const char *const iface_counter_table[IFACE_COUNTER_COUNT] = {
127 cnt_str(rx_frame_err),
128 cnt_str(rx_over_err),
134 cnt_str(rx_1_to_64_packets),
135 cnt_str(rx_65_to_127_packets),
136 cnt_str(rx_128_to_255_packets),
137 cnt_str(rx_256_to_511_packets),
138 cnt_str(rx_512_to_1023_packets),
139 cnt_str(rx_1024_to_1522_packets),
140 cnt_str(rx_1523_to_max_packets),
141 cnt_str(tx_1_to_64_packets),
142 cnt_str(tx_65_to_127_packets),
143 cnt_str(tx_128_to_255_packets),
144 cnt_str(tx_256_to_511_packets),
145 cnt_str(tx_512_to_1023_packets),
146 cnt_str(tx_1024_to_1522_packets),
147 cnt_str(tx_1523_to_max_packets),
148 cnt_str(rx_multicast_packets),
149 cnt_str(tx_multicast_packets),
150 cnt_str(rx_broadcast_packets),
151 cnt_str(tx_broadcast_packets),
152 cnt_str(rx_undersized_errors),
153 cnt_str(rx_oversize_errors),
154 cnt_str(rx_fragmented_errors),
155 cnt_str(rx_jabber_errors),
156 cnt_str(rx_error_bytes),
157 cnt_str(rx_l3_l4_xsum_error),
158 cnt_str(rx_management_dropped),
159 cnt_str(rx_mbuf_allocation_errors),
160 cnt_str(rx_total_bytes),
161 cnt_str(rx_total_missed_packets),
162 cnt_str(rx_undersize_errors),
163 cnt_str(rx_management_packets),
164 cnt_str(tx_management_packets),
165 cnt_str(rx_good_bytes),
166 cnt_str(tx_good_bytes),
167 cnt_str(rx_good_packets),
168 cnt_str(tx_good_packets),
169 cnt_str(rx_total_packets),
170 cnt_str(tx_total_packets),
175 /* Entry into the list of network bridges */
176 static bridge_list_t *g_bridge_list_head;
178 /* Entry into the list of monitored network bridges */
179 static bridge_list_t *g_monitored_bridge_list_head;
181 /* entry into the list of network bridges */
182 static port_list_t *g_port_list_head;
184 /* lock for statistics cache */
185 static pthread_mutex_t g_stats_lock;
188 static ovs_db_t *g_ovs_db;
190 /* OVS stats configuration data */
191 struct ovs_stats_config_s {
192 char ovs_db_node[OVS_DB_ADDR_NODE_SIZE]; /* OVS DB node */
193 char ovs_db_serv[OVS_DB_ADDR_SERVICE_SIZE]; /* OVS DB service */
194 char ovs_db_unix[OVS_DB_ADDR_UNIX_SIZE]; /* OVS DB unix socket path */
196 typedef struct ovs_stats_config_s ovs_stats_config_t;
198 static ovs_stats_config_t ovs_stats_cfg = {
199 .ovs_db_node = "localhost", /* use default OVS DB node */
200 .ovs_db_serv = "6640", /* use default OVS DB service */
203 /* flag indicating whether or not to publish individual interface statistics */
204 static bool interface_stats = false;
206 static iface_counter ovs_stats_counter_name_to_type(const char *counter) {
207 iface_counter index = not_supported;
210 return not_supported;
212 for (int i = 0; i < IFACE_COUNTER_COUNT; i++) {
213 if (strncmp(iface_counter_table[i], counter,
214 strlen(iface_counter_table[i])) == 0) {
222 static void ovs_stats_submit_one(const char *dev, const char *type,
223 const char *type_instance, derive_t value,
225 /* if counter is less than 0 - skip it*/
228 value_list_t vl = VALUE_LIST_INIT;
230 vl.values = &(value_t){.derive = value};
234 sstrncpy(vl.plugin, plugin_name, sizeof(vl.plugin));
235 sstrncpy(vl.plugin_instance, dev, sizeof(vl.plugin_instance));
236 sstrncpy(vl.type, type, sizeof(vl.type));
238 if (type_instance != NULL)
239 sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
241 plugin_dispatch_values(&vl);
244 static void ovs_stats_submit_two(const char *dev, const char *type,
245 const char *type_instance, derive_t rx,
246 derive_t tx, meta_data_t *meta) {
247 /* if counter is less than 0 - skip it*/
248 if (rx < 0 || tx < 0)
250 value_list_t vl = VALUE_LIST_INIT;
251 value_t values[] = {{.derive = rx}, {.derive = tx}};
254 vl.values_len = STATIC_ARRAY_SIZE(values);
257 sstrncpy(vl.plugin, plugin_name, sizeof(vl.plugin));
258 sstrncpy(vl.plugin_instance, dev, sizeof(vl.plugin_instance));
259 sstrncpy(vl.type, type, sizeof(vl.type));
261 if (type_instance != NULL)
262 sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
264 plugin_dispatch_values(&vl);
267 static void ovs_stats_submit_interfaces(port_list_t *port) {
268 char devname[PORT_NAME_SIZE_MAX * 2];
270 bridge_list_t *bridge = port->br;
271 for (interface_list_t *iface = port->iface; iface != NULL;
272 iface = iface->next) {
273 meta_data_t *meta = meta_data_create();
275 meta_data_add_string(meta, "uuid", iface->iface_uuid);
277 if (strlen(iface->ex_vm_id))
278 meta_data_add_string(meta, "vm-uuid", iface->ex_vm_id);
280 if (strlen(iface->ex_iface_id))
281 meta_data_add_string(meta, "iface-id", iface->ex_iface_id);
283 snprintf(devname, sizeof(devname), "%s.%s.%s", bridge->name, port->name,
285 ovs_stats_submit_one(devname, "if_collisions", NULL,
286 iface->stats[collisions], meta);
287 ovs_stats_submit_two(devname, "if_dropped", NULL, iface->stats[rx_dropped],
288 iface->stats[tx_dropped], meta);
289 ovs_stats_submit_two(devname, "if_errors", NULL, iface->stats[rx_errors],
290 iface->stats[tx_errors], meta);
291 ovs_stats_submit_two(devname, "if_packets", NULL, iface->stats[rx_packets],
292 iface->stats[tx_packets], meta);
293 ovs_stats_submit_one(devname, "if_rx_errors", "crc",
294 iface->stats[rx_crc_err], meta);
295 ovs_stats_submit_one(devname, "if_rx_errors", "frame",
296 iface->stats[rx_frame_err], meta);
297 ovs_stats_submit_one(devname, "if_rx_errors", "over",
298 iface->stats[rx_over_err], meta);
299 ovs_stats_submit_one(devname, "if_rx_octets", NULL, iface->stats[rx_bytes],
301 ovs_stats_submit_one(devname, "if_tx_octets", NULL, iface->stats[tx_bytes],
303 ovs_stats_submit_two(devname, "if_packets", "1_to_64_packets",
304 iface->stats[rx_1_to_64_packets],
305 iface->stats[tx_1_to_64_packets], meta);
306 ovs_stats_submit_two(devname, "if_packets", "65_to_127_packets",
307 iface->stats[rx_65_to_127_packets],
308 iface->stats[tx_65_to_127_packets], meta);
309 ovs_stats_submit_two(devname, "if_packets", "128_to_255_packets",
310 iface->stats[rx_128_to_255_packets],
311 iface->stats[tx_128_to_255_packets], meta);
312 ovs_stats_submit_two(devname, "if_packets", "256_to_511_packets",
313 iface->stats[rx_256_to_511_packets],
314 iface->stats[tx_256_to_511_packets], meta);
315 ovs_stats_submit_two(devname, "if_packets", "512_to_1023_packets",
316 iface->stats[rx_512_to_1023_packets],
317 iface->stats[tx_512_to_1023_packets], meta);
318 ovs_stats_submit_two(devname, "if_packets", "1024_to_1522_packets",
319 iface->stats[rx_1024_to_1522_packets],
320 iface->stats[tx_1024_to_1522_packets], meta);
321 ovs_stats_submit_two(devname, "if_packets", "1523_to_max_packets",
322 iface->stats[rx_1523_to_max_packets],
323 iface->stats[tx_1523_to_max_packets], meta);
324 ovs_stats_submit_two(devname, "if_packets", "broadcast_packets",
325 iface->stats[rx_broadcast_packets],
326 iface->stats[tx_broadcast_packets], meta);
327 ovs_stats_submit_one(devname, "if_rx_errors", "rx_undersized_errors",
328 iface->stats[rx_undersized_errors], meta);
329 ovs_stats_submit_one(devname, "if_rx_errors", "rx_oversize_errors",
330 iface->stats[rx_oversize_errors], meta);
331 ovs_stats_submit_one(devname, "if_rx_errors", "rx_fragmented_errors",
332 iface->stats[rx_fragmented_errors], meta);
333 ovs_stats_submit_one(devname, "if_rx_errors", "rx_jabber_errors",
334 iface->stats[rx_jabber_errors], meta);
335 ovs_stats_submit_one(devname, "if_rx_octets", "rx_error_bytes",
336 iface->stats[rx_error_bytes], meta);
337 ovs_stats_submit_one(devname, "if_errors", "rx_l3_l4_xsum_error",
338 iface->stats[rx_l3_l4_xsum_error], meta);
339 ovs_stats_submit_one(devname, "if_dropped", "rx_management_dropped",
340 iface->stats[rx_management_dropped], meta);
341 ovs_stats_submit_one(devname, "if_errors", "rx_mbuf_allocation_errors",
342 iface->stats[rx_mbuf_allocation_errors], meta);
343 ovs_stats_submit_one(devname, "if_octets", "rx_total_bytes",
344 iface->stats[rx_total_bytes], meta);
345 ovs_stats_submit_one(devname, "if_packets", "rx_total_missed_packets",
346 iface->stats[rx_total_missed_packets], meta);
347 ovs_stats_submit_one(devname, "if_rx_errors", "rx_undersize_errors",
348 iface->stats[rx_undersize_errors], meta);
349 ovs_stats_submit_two(devname, "if_packets", "management_packets",
350 iface->stats[rx_management_packets],
351 iface->stats[tx_management_packets], meta);
352 ovs_stats_submit_two(devname, "if_packets", "multicast_packets",
353 iface->stats[rx_multicast_packets],
354 iface->stats[tx_multicast_packets], meta);
355 ovs_stats_submit_two(devname, "if_octets", "good_bytes",
356 iface->stats[rx_good_bytes],
357 iface->stats[tx_good_bytes], meta);
358 ovs_stats_submit_two(devname, "if_packets", "good_packets",
359 iface->stats[rx_good_packets],
360 iface->stats[tx_good_packets], meta);
361 ovs_stats_submit_two(devname, "if_packets", "total_packets",
362 iface->stats[rx_total_packets],
363 iface->stats[tx_total_packets], meta);
365 meta_data_destroy(meta);
369 static int ovs_stats_get_port_stat_value(port_list_t *port,
370 iface_counter index) {
376 for (interface_list_t *iface = port->iface; iface != NULL;
377 iface = iface->next) {
378 value = value + iface->stats[index];
384 static void ovs_stats_submit_port(port_list_t *port) {
385 char devname[PORT_NAME_SIZE_MAX * 2];
387 meta_data_t *meta = meta_data_create();
389 char key_str[DATA_MAX_NAME_LEN];
392 for (interface_list_t *iface = port->iface; iface != NULL;
393 iface = iface->next) {
394 snprintf(key_str, sizeof(key_str), "uuid%d", i);
395 meta_data_add_string(meta, key_str, iface->iface_uuid);
397 if (strlen(iface->ex_vm_id)) {
398 snprintf(key_str, sizeof(key_str), "vm-uuid%d", i);
399 meta_data_add_string(meta, key_str, iface->ex_vm_id);
402 if (strlen(iface->ex_iface_id)) {
403 snprintf(key_str, sizeof(key_str), "iface-id%d", i);
404 meta_data_add_string(meta, key_str, iface->ex_iface_id);
410 bridge_list_t *bridge = port->br;
411 snprintf(devname, sizeof(devname), "%s.%s", bridge->name, port->name);
412 ovs_stats_submit_one(devname, "if_collisions", NULL,
413 ovs_stats_get_port_stat_value(port, collisions), meta);
414 ovs_stats_submit_two(devname, "if_dropped", NULL,
415 ovs_stats_get_port_stat_value(port, rx_dropped),
416 ovs_stats_get_port_stat_value(port, tx_dropped), meta);
417 ovs_stats_submit_two(devname, "if_errors", NULL,
418 ovs_stats_get_port_stat_value(port, rx_errors),
419 ovs_stats_get_port_stat_value(port, tx_errors), meta);
420 ovs_stats_submit_two(devname, "if_packets", NULL,
421 ovs_stats_get_port_stat_value(port, rx_packets),
422 ovs_stats_get_port_stat_value(port, tx_packets), meta);
423 ovs_stats_submit_one(devname, "if_rx_errors", "crc",
424 ovs_stats_get_port_stat_value(port, rx_crc_err), meta);
425 ovs_stats_submit_one(devname, "if_rx_errors", "frame",
426 ovs_stats_get_port_stat_value(port, rx_frame_err), meta);
427 ovs_stats_submit_one(devname, "if_rx_errors", "over",
428 ovs_stats_get_port_stat_value(port, rx_over_err), meta);
429 ovs_stats_submit_one(devname, "if_rx_octets", NULL,
430 ovs_stats_get_port_stat_value(port, rx_bytes), meta);
431 ovs_stats_submit_one(devname, "if_tx_octets", NULL,
432 ovs_stats_get_port_stat_value(port, tx_bytes), meta);
433 ovs_stats_submit_two(devname, "if_packets", "1_to_64_packets",
434 ovs_stats_get_port_stat_value(port, rx_1_to_64_packets),
435 ovs_stats_get_port_stat_value(port, tx_1_to_64_packets),
437 ovs_stats_submit_two(
438 devname, "if_packets", "65_to_127_packets",
439 ovs_stats_get_port_stat_value(port, rx_65_to_127_packets),
440 ovs_stats_get_port_stat_value(port, tx_65_to_127_packets), meta);
441 ovs_stats_submit_two(
442 devname, "if_packets", "128_to_255_packets",
443 ovs_stats_get_port_stat_value(port, rx_128_to_255_packets),
444 ovs_stats_get_port_stat_value(port, tx_128_to_255_packets), meta);
445 ovs_stats_submit_two(
446 devname, "if_packets", "256_to_511_packets",
447 ovs_stats_get_port_stat_value(port, rx_256_to_511_packets),
448 ovs_stats_get_port_stat_value(port, tx_256_to_511_packets), meta);
449 ovs_stats_submit_two(
450 devname, "if_packets", "512_to_1023_packets",
451 ovs_stats_get_port_stat_value(port, rx_512_to_1023_packets),
452 ovs_stats_get_port_stat_value(port, tx_512_to_1023_packets), meta);
453 ovs_stats_submit_two(
454 devname, "if_packets", "1024_to_1522_packets",
455 ovs_stats_get_port_stat_value(port, rx_1024_to_1522_packets),
456 ovs_stats_get_port_stat_value(port, tx_1024_to_1522_packets), meta);
457 ovs_stats_submit_two(
458 devname, "if_packets", "1523_to_max_packets",
459 ovs_stats_get_port_stat_value(port, rx_1523_to_max_packets),
460 ovs_stats_get_port_stat_value(port, tx_1523_to_max_packets), meta);
461 ovs_stats_submit_two(
462 devname, "if_packets", "broadcast_packets",
463 ovs_stats_get_port_stat_value(port, rx_broadcast_packets),
464 ovs_stats_get_port_stat_value(port, tx_broadcast_packets), meta);
465 ovs_stats_submit_one(
466 devname, "if_rx_errors", "rx_undersized_errors",
467 ovs_stats_get_port_stat_value(port, rx_undersized_errors), meta);
468 ovs_stats_submit_one(devname, "if_rx_errors", "rx_oversize_errors",
469 ovs_stats_get_port_stat_value(port, rx_oversize_errors),
471 ovs_stats_submit_one(
472 devname, "if_rx_errors", "rx_fragmented_errors",
473 ovs_stats_get_port_stat_value(port, rx_fragmented_errors), meta);
474 ovs_stats_submit_one(devname, "if_rx_errors", "rx_jabber_errors",
475 ovs_stats_get_port_stat_value(port, rx_jabber_errors),
477 ovs_stats_submit_one(devname, "if_rx_octets", "rx_error_bytes",
478 ovs_stats_get_port_stat_value(port, rx_error_bytes),
480 ovs_stats_submit_one(devname, "if_errors", "rx_l3_l4_xsum_error",
481 ovs_stats_get_port_stat_value(port, rx_l3_l4_xsum_error),
483 ovs_stats_submit_one(
484 devname, "if_dropped", "rx_management_dropped",
485 ovs_stats_get_port_stat_value(port, rx_management_dropped), meta);
486 ovs_stats_submit_one(
487 devname, "if_errors", "rx_mbuf_allocation_errors",
488 ovs_stats_get_port_stat_value(port, rx_mbuf_allocation_errors), meta);
489 ovs_stats_submit_one(devname, "if_octets", "rx_total_bytes",
490 ovs_stats_get_port_stat_value(port, rx_total_bytes),
492 ovs_stats_submit_one(
493 devname, "if_packets", "rx_total_missed_packets",
494 ovs_stats_get_port_stat_value(port, rx_total_missed_packets), meta);
495 ovs_stats_submit_one(devname, "if_rx_errors", "rx_undersize_errors",
496 ovs_stats_get_port_stat_value(port, rx_undersize_errors),
498 ovs_stats_submit_two(
499 devname, "if_packets", "management_packets",
500 ovs_stats_get_port_stat_value(port, rx_management_packets),
501 ovs_stats_get_port_stat_value(port, tx_management_packets), meta);
502 ovs_stats_submit_two(
503 devname, "if_packets", "multicast_packets",
504 ovs_stats_get_port_stat_value(port, rx_multicast_packets),
505 ovs_stats_get_port_stat_value(port, tx_multicast_packets), meta);
506 ovs_stats_submit_two(devname, "if_octets", "good_bytes",
507 ovs_stats_get_port_stat_value(port, rx_good_bytes),
508 ovs_stats_get_port_stat_value(port, tx_good_bytes),
510 ovs_stats_submit_two(devname, "if_packets", "good_packets",
511 ovs_stats_get_port_stat_value(port, rx_good_packets),
512 ovs_stats_get_port_stat_value(port, tx_good_packets),
514 ovs_stats_submit_two(devname, "if_packets", "total_packets",
515 ovs_stats_get_port_stat_value(port, rx_total_packets),
516 ovs_stats_get_port_stat_value(port, tx_total_packets),
519 meta_data_destroy(meta);
522 static port_list_t *ovs_stats_get_port(const char *uuid) {
526 for (port_list_t *port = g_port_list_head; port != NULL; port = port->next) {
527 if (strncmp(port->port_uuid, uuid, strlen(port->port_uuid)) == 0)
533 static port_list_t *ovs_stats_get_port_by_interface_uuid(const char *uuid) {
537 for (port_list_t *port = g_port_list_head; port != NULL; port = port->next) {
538 for (interface_list_t *iface = port->iface; iface != NULL;
539 iface = iface->next) {
540 if (strncmp(iface->iface_uuid, uuid, strlen(uuid)) == 0)
547 static interface_list_t *ovs_stats_get_port_interface(port_list_t *port,
549 if (port == NULL || uuid == NULL)
552 for (interface_list_t *iface = port->iface; iface != NULL;
553 iface = iface->next) {
554 if (strncmp(iface->iface_uuid, uuid, strlen(uuid)) == 0)
560 static interface_list_t *ovs_stats_get_interface(const char *uuid) {
564 for (port_list_t *port = g_port_list_head; port != NULL; port = port->next) {
565 for (interface_list_t *iface = port->iface; iface != NULL;
566 iface = iface->next) {
567 if (strncmp(iface->iface_uuid, uuid, strlen(uuid)) == 0)
574 static interface_list_t *ovs_stats_new_port_interface(port_list_t *port,
579 interface_list_t *iface = ovs_stats_get_port_interface(port, uuid);
582 iface = calloc(1, sizeof(*iface));
584 ERROR("%s: Error allocating interface", plugin_name);
587 memset(iface->stats, -1, sizeof(int64_t[IFACE_COUNTER_COUNT]));
588 sstrncpy(iface->iface_uuid, uuid, sizeof(iface->iface_uuid));
589 interface_list_t *iface_head = port->iface;
590 iface->next = iface_head;
596 /* Create or get port by port uuid */
597 static port_list_t *ovs_stats_new_port(bridge_list_t *bridge,
602 port_list_t *port = ovs_stats_get_port(uuid);
605 port = calloc(1, sizeof(*port));
607 ERROR("%s: Error allocating port", plugin_name);
610 sstrncpy(port->port_uuid, uuid, sizeof(port->port_uuid));
611 port->next = g_port_list_head;
612 g_port_list_head = port;
614 if (bridge != NULL) {
620 /* Get bridge by name*/
621 static bridge_list_t *ovs_stats_get_bridge(bridge_list_t *head,
626 for (bridge_list_t *bridge = head; bridge != NULL; bridge = bridge->next) {
627 if ((strncmp(bridge->name, name, strlen(bridge->name)) == 0) &&
628 strlen(name) == strlen(bridge->name))
634 /* Check if bridge is configured to be monitored in config file */
635 static int ovs_stats_is_monitored_bridge(const char *br_name) {
636 /* if no bridges are configured, return true */
637 if (g_monitored_bridge_list_head == NULL)
640 /* check if given bridge exists */
641 if (ovs_stats_get_bridge(g_monitored_bridge_list_head, br_name) != NULL)
648 static int ovs_stats_del_bridge(yajl_val bridge) {
649 const char *old[] = {"old", NULL};
650 const char *name[] = {"name", NULL};
652 if (!bridge || !YAJL_IS_OBJECT(bridge)) {
653 WARNING("%s: Incorrect data for deleting bridge", plugin_name);
657 yajl_val row = yajl_tree_get(bridge, old, yajl_t_object);
658 if (!row || !YAJL_IS_OBJECT(row))
661 yajl_val br_name = yajl_tree_get(row, name, yajl_t_string);
662 if (!br_name || !YAJL_IS_STRING(br_name))
665 bridge_list_t *prev_br = g_bridge_list_head;
666 for (bridge_list_t *br = g_bridge_list_head; br != NULL;
667 prev_br = br, br = br->next) {
668 if ((strncmp(br->name, br_name->u.string, strlen(br->name)) == 0) &&
669 strlen(br->name) == strlen(br_name->u.string)) {
670 if (br == g_bridge_list_head)
671 g_bridge_list_head = br->next;
673 prev_br->next = br->next;
682 /* Update Bridge. Create bridge ports*/
683 static int ovs_stats_update_bridge(yajl_val bridge) {
684 const char *new[] = {"new", NULL};
685 const char *name[] = {"name", NULL};
686 const char *ports[] = {"ports", NULL};
688 if (!bridge || !YAJL_IS_OBJECT(bridge))
691 yajl_val row = yajl_tree_get(bridge, new, yajl_t_object);
692 if (!row || !YAJL_IS_OBJECT(row))
695 yajl_val br_name = yajl_tree_get(row, name, yajl_t_string);
696 if (!br_name || !YAJL_IS_STRING(br_name))
699 if (!ovs_stats_is_monitored_bridge(YAJL_GET_STRING(br_name)))
703 ovs_stats_get_bridge(g_bridge_list_head, YAJL_GET_STRING(br_name));
705 br = calloc(1, sizeof(*br));
707 ERROR("%s: calloc(%zu) failed.", plugin_name, sizeof(*br));
711 char *tmp = YAJL_GET_STRING(br_name);
713 br->name = strdup(tmp);
715 if (br->name == NULL) {
717 ERROR("%s: strdup failed.", plugin_name);
721 br->next = g_bridge_list_head;
722 g_bridge_list_head = br;
725 yajl_val br_ports = yajl_tree_get(row, ports, yajl_t_array);
726 if (!br_ports || !YAJL_IS_ARRAY(br_ports))
729 char *tmp = YAJL_GET_STRING(br_ports->u.array.values[0]);
730 if (tmp != NULL && strcmp("set", tmp) == 0) {
731 yajl_val *array = YAJL_GET_ARRAY(br_ports)->values;
732 size_t array_len = YAJL_GET_ARRAY(br_ports)->len;
733 if (array != NULL && array_len > 0 && YAJL_IS_ARRAY(array[1])) {
734 if (YAJL_GET_ARRAY(array[1]) == NULL)
737 yajl_val *ports_arr = YAJL_GET_ARRAY(array[1])->values;
738 size_t ports_num = YAJL_GET_ARRAY(array[1])->len;
739 for (size_t i = 0; i < ports_num && ports_arr != NULL; i++) {
740 tmp = YAJL_GET_STRING(ports_arr[i]->u.array.values[1]);
742 ovs_stats_new_port(br, tmp);
748 ovs_stats_new_port(br, YAJL_GET_STRING(br_ports->u.array.values[1]));
754 ERROR("Incorrect JSON Bridge data");
758 /* Handle JSON with Bridge Table change event */
759 static void ovs_stats_bridge_table_change_cb(yajl_val jupdates) {
760 /* Bridge Table update example JSON data
763 "bb1f8965-5775-46d9-b820-236ca8edbedc": {
771 "117f1a07-7ef0-458a-865c-ec7fbb85bc01"
775 "12fd8bdc-e950-4281-aaa9-46e185658f79"
784 const char *path[] = {"Bridge", NULL};
785 yajl_val bridges = yajl_tree_get(jupdates, path, yajl_t_object);
787 if (!bridges || !YAJL_IS_OBJECT(bridges))
790 pthread_mutex_lock(&g_stats_lock);
791 for (size_t i = 0; i < YAJL_GET_OBJECT(bridges)->len; i++) {
792 yajl_val bridge = YAJL_GET_OBJECT(bridges)->values[i];
793 ovs_stats_update_bridge(bridge);
795 pthread_mutex_unlock(&g_stats_lock);
798 /* Handle Bridge Table delete event */
799 static void ovs_stats_bridge_table_delete_cb(yajl_val jupdates) {
800 const char *path[] = {"Bridge", NULL};
801 yajl_val bridges = yajl_tree_get(jupdates, path, yajl_t_object);
802 if (!bridges || !YAJL_IS_OBJECT(bridges))
805 pthread_mutex_lock(&g_stats_lock);
806 for (size_t i = 0; i < YAJL_GET_OBJECT(bridges)->len; i++) {
807 yajl_val bridge = YAJL_GET_OBJECT(bridges)->values[i];
808 ovs_stats_del_bridge(bridge);
810 pthread_mutex_unlock(&g_stats_lock);
813 /* Handle JSON with Bridge table initial values */
814 static void ovs_stats_bridge_table_result_cb(yajl_val jresult,
816 if (YAJL_IS_NULL(jerror))
817 ovs_stats_bridge_table_change_cb(jresult);
819 ERROR("%s: Error received from OvSDB. Table: Bridge", plugin_name);
823 /* Update port name and interface UUID(s)*/
824 static int ovs_stats_update_port(const char *uuid, yajl_val port) {
825 const char *new[] = {"new", NULL};
826 const char *name[] = {"name", NULL};
828 if (!port || !YAJL_IS_OBJECT(port)) {
829 ERROR("Incorrect JSON Port data");
833 yajl_val row = yajl_tree_get(port, new, yajl_t_object);
834 if (!row || !YAJL_IS_OBJECT(row))
837 yajl_val port_name = yajl_tree_get(row, name, yajl_t_string);
838 if (!port_name || !YAJL_IS_STRING(port_name))
841 /* Create or get port by port uuid */
842 port_list_t *portentry = ovs_stats_new_port(NULL, uuid);
846 sstrncpy(portentry->name, YAJL_GET_STRING(port_name),
847 sizeof(portentry->name));
849 yajl_val ifaces_root = ovs_utils_get_value_by_key(row, "interfaces");
850 char *ifaces_root_key =
851 YAJL_GET_STRING(YAJL_GET_ARRAY(ifaces_root)->values[0]);
853 if (strcmp("set", ifaces_root_key) == 0) {
854 // ifaces_root is ["set", [[ "uuid", "<some_uuid>" ], [ "uuid",
855 // "<another_uuid>" ], ... ]]
856 yajl_val ifaces_list = YAJL_GET_ARRAY(ifaces_root)->values[1];
858 // ifaces_list is [[ "uuid", "<some_uuid>" ], [ "uuid",
859 // "<another_uuid>" ], ... ]]
860 for (int i = 0; i < YAJL_GET_ARRAY(ifaces_list)->len; i++) {
861 yajl_val iface_tuple = YAJL_GET_ARRAY(ifaces_list)->values[i];
863 // iface_tuple is [ "uuid", "<some_uuid>" ]
864 char *iface_uuid_str =
865 YAJL_GET_STRING(YAJL_GET_ARRAY(iface_tuple)->values[1]);
867 // Also checks if interface already registered
868 ovs_stats_new_port_interface(portentry, iface_uuid_str);
871 // ifaces_root is [ "uuid", "<some_uuid>" ]
872 char *iface_uuid_str =
873 YAJL_GET_STRING(YAJL_GET_ARRAY(ifaces_root)->values[1]);
875 // Also checks if interface already registered
876 ovs_stats_new_port_interface(portentry, iface_uuid_str);
882 /* Delete port from global port list */
883 static int ovs_stats_del_port(const char *uuid) {
884 port_list_t *prev_port = g_port_list_head;
885 for (port_list_t *port = g_port_list_head; port != NULL;
886 prev_port = port, port = port->next) {
887 if (strncmp(port->port_uuid, uuid, strlen(port->port_uuid)) == 0) {
888 if (port == g_port_list_head)
889 g_port_list_head = port->next;
891 prev_port->next = port->next;
893 for (interface_list_t *iface = port->iface; iface != NULL;
894 iface = port->iface) {
895 interface_list_t *del = iface;
896 port->iface = iface->next;
907 /* Handle JSON with Port Table change event */
908 static void ovs_stats_port_table_change_cb(yajl_val jupdates) {
909 /* Port Table update example JSON data
912 "ab107d6f-28a1-4257-b1cc-5b742821db8a": {
917 "33a289a0-1d34-4e46-a3c2-3e4066fbecc6"
924 const char *path[] = {"Port", NULL};
925 yajl_val ports = yajl_tree_get(jupdates, path, yajl_t_object);
926 if (!ports || !YAJL_IS_OBJECT(ports))
929 pthread_mutex_lock(&g_stats_lock);
930 for (size_t i = 0; i < YAJL_GET_OBJECT(ports)->len; i++) {
931 yajl_val port = YAJL_GET_OBJECT(ports)->values[i];
932 ovs_stats_update_port(YAJL_GET_OBJECT(ports)->keys[i], port);
934 pthread_mutex_unlock(&g_stats_lock);
938 /* Handle JSON with Port table initial values */
939 static void ovs_stats_port_table_result_cb(yajl_val jresult, yajl_val jerror) {
940 if (YAJL_IS_NULL(jerror))
941 ovs_stats_port_table_change_cb(jresult);
943 ERROR("%s: Error received from OvSDB. Table: Port", plugin_name);
947 /* Handle Port Table delete event */
948 static void ovs_stats_port_table_delete_cb(yajl_val jupdates) {
949 const char *path[] = {"Port", NULL};
950 yajl_val ports = yajl_tree_get(jupdates, path, yajl_t_object);
951 if (!ports || !YAJL_IS_OBJECT(ports))
954 pthread_mutex_lock(&g_stats_lock);
955 for (size_t i = 0; i < YAJL_GET_OBJECT(ports)->len; i++) {
956 ovs_stats_del_port(YAJL_GET_OBJECT(ports)->keys[i]);
958 pthread_mutex_unlock(&g_stats_lock);
962 /* Update interface statistics */
963 static int ovs_stats_update_iface_stats(interface_list_t *iface,
966 if (!stats || !YAJL_IS_ARRAY(stats))
969 for (size_t i = 0; i < YAJL_GET_ARRAY(stats)->len; i++) {
970 yajl_val stat = YAJL_GET_ARRAY(stats)->values[i];
971 if (!YAJL_IS_ARRAY(stat))
974 char *counter_name = YAJL_GET_STRING(YAJL_GET_ARRAY(stat)->values[0]);
975 iface_counter counter_index = ovs_stats_counter_name_to_type(counter_name);
976 int64_t counter_value = YAJL_GET_INTEGER(YAJL_GET_ARRAY(stat)->values[1]);
977 if (counter_index == not_supported)
980 iface->stats[counter_index] = counter_value;
986 /* Update interface external_ids */
987 static int ovs_stats_update_iface_ext_ids(interface_list_t *iface,
990 if (!ext_ids || !YAJL_IS_ARRAY(ext_ids))
993 for (size_t i = 0; i < YAJL_GET_ARRAY(ext_ids)->len; i++) {
994 yajl_val ext_id = YAJL_GET_ARRAY(ext_ids)->values[i];
995 if (!YAJL_IS_ARRAY(ext_id))
998 char *key = YAJL_GET_STRING(YAJL_GET_ARRAY(ext_id)->values[0]);
999 char *value = YAJL_GET_STRING(YAJL_GET_ARRAY(ext_id)->values[1]);
1001 if (strncmp(key, "iface-id", strlen(key)) == 0) {
1002 sstrncpy(iface->ex_iface_id, value, sizeof(iface->ex_iface_id));
1003 } else if (strncmp(key, "vm-uuid", strlen(key)) == 0) {
1004 sstrncpy(iface->ex_vm_id, value, sizeof(iface->ex_vm_id));
1012 /* Get interface statistic and external_ids */
1013 static int ovs_stats_update_iface(yajl_val iface_obj) {
1014 if (!iface_obj || !YAJL_IS_OBJECT(iface_obj)) {
1015 ERROR("ovs_stats plugin: incorrect JSON interface data");
1019 yajl_val row = ovs_utils_get_value_by_key(iface_obj, "new");
1020 if (!row || !YAJL_IS_OBJECT(row))
1023 yajl_val iface_name = ovs_utils_get_value_by_key(row, "name");
1024 if (!iface_name || !YAJL_IS_STRING(iface_name))
1027 yajl_val iface_uuid = ovs_utils_get_value_by_key(row, "_uuid");
1028 if (!iface_uuid || !YAJL_IS_ARRAY(iface_uuid) ||
1029 YAJL_GET_ARRAY(iface_uuid)->len != 2)
1032 char *iface_uuid_str = YAJL_GET_STRING(YAJL_GET_ARRAY(iface_uuid)->values[1]);
1033 if (iface_uuid_str == NULL) {
1034 ERROR("ovs_stats plugin: incorrect JSON interface data");
1038 interface_list_t *iface = ovs_stats_get_interface(iface_uuid_str);
1042 sstrncpy(iface->name, YAJL_GET_STRING(iface_name), sizeof(iface->name));
1044 yajl_val iface_stats = ovs_utils_get_value_by_key(row, "statistics");
1045 yajl_val iface_ext_ids = ovs_utils_get_value_by_key(row, "external_ids");
1064 Check that statistics is an array with 2 elements
1067 if (iface_stats && YAJL_IS_ARRAY(iface_stats) &&
1068 YAJL_GET_ARRAY(iface_stats)->len == 2)
1069 ovs_stats_update_iface_stats(iface, YAJL_GET_ARRAY(iface_stats)->values[1]);
1071 if (iface_ext_ids && YAJL_IS_ARRAY(iface_ext_ids))
1072 ovs_stats_update_iface_ext_ids(iface,
1073 YAJL_GET_ARRAY(iface_ext_ids)->values[1]);
1078 /* Delete interface */
1079 static int ovs_stats_del_interface(const char *uuid) {
1080 port_list_t *port = ovs_stats_get_port_by_interface_uuid(uuid);
1085 interface_list_t *prev_iface = NULL;
1087 for (interface_list_t *iface = port->iface; iface != NULL;
1088 iface = port->iface) {
1089 if (strncmp(iface->iface_uuid, uuid, strlen(iface->iface_uuid))) {
1091 interface_list_t *del = iface;
1093 if (prev_iface == NULL)
1094 port->iface = iface->next;
1096 prev_iface->next = iface->next;
1108 /* Handle JSON with Interface Table change event */
1109 static void ovs_stats_interface_table_change_cb(yajl_val jupdates) {
1110 /* Interface Table update example JSON data
1113 "33a289a0-1d34-4e46-a3c2-3e4066fbecc6": {
1136 "33a289a0-1d34-4e46-a3c2-3e4066fbecc6"
1147 "a61b7e2b-6951-488a-b4c6-6e91343960b2"
1160 const char *path[] = {"Interface", NULL};
1161 yajl_val interfaces = yajl_tree_get(jupdates, path, yajl_t_object);
1162 if (!interfaces || !YAJL_IS_OBJECT(interfaces))
1165 pthread_mutex_lock(&g_stats_lock);
1166 for (size_t i = 0; i < YAJL_GET_OBJECT(interfaces)->len; i++) {
1167 ovs_stats_update_iface(YAJL_GET_OBJECT(interfaces)->values[i]);
1169 pthread_mutex_unlock(&g_stats_lock);
1174 /* Handle JSON with Interface table initial values */
1175 static void ovs_stats_interface_table_result_cb(yajl_val jresult,
1177 if (YAJL_IS_NULL(jerror))
1178 ovs_stats_interface_table_change_cb(jresult);
1180 ERROR("%s: Error received from OvSDB. Table: Interface", plugin_name);
1184 /* Handle Interface Table delete event */
1185 static void ovs_stats_interface_table_delete_cb(yajl_val jupdates) {
1186 const char *path[] = {"Interface", NULL};
1187 yajl_val interfaces = yajl_tree_get(jupdates, path, yajl_t_object);
1188 if (!interfaces || !YAJL_IS_OBJECT(interfaces))
1191 pthread_mutex_lock(&g_stats_lock);
1192 for (size_t i = 0; i < YAJL_GET_OBJECT(interfaces)->len; i++) {
1193 ovs_stats_del_interface(YAJL_GET_OBJECT(interfaces)->keys[i]);
1195 pthread_mutex_unlock(&g_stats_lock);
1200 /* Setup OVS DB table callbacks */
1201 static void ovs_stats_initialize(ovs_db_t *pdb) {
1202 const char *bridge_columns[] = {"name", "ports", NULL};
1203 const char *port_columns[] = {"name", "interfaces", NULL};
1204 const char *interface_columns[] = {"name", "statistics", "_uuid",
1205 "external_ids", NULL};
1207 /* subscribe to a tables */
1208 ovs_db_table_cb_register(
1209 pdb, "Bridge", bridge_columns, ovs_stats_bridge_table_change_cb,
1210 ovs_stats_bridge_table_result_cb,
1211 OVS_DB_TABLE_CB_FLAG_INITIAL | OVS_DB_TABLE_CB_FLAG_INSERT |
1212 OVS_DB_TABLE_CB_FLAG_MODIFY);
1214 ovs_db_table_cb_register(pdb, "Bridge", bridge_columns,
1215 ovs_stats_bridge_table_delete_cb, NULL,
1216 OVS_DB_TABLE_CB_FLAG_DELETE);
1218 ovs_db_table_cb_register(
1219 pdb, "Port", port_columns, ovs_stats_port_table_change_cb,
1220 ovs_stats_port_table_result_cb,
1221 OVS_DB_TABLE_CB_FLAG_INITIAL | OVS_DB_TABLE_CB_FLAG_INSERT |
1222 OVS_DB_TABLE_CB_FLAG_MODIFY);
1224 ovs_db_table_cb_register(pdb, "Port", port_columns,
1225 ovs_stats_port_table_delete_cb, NULL,
1226 OVS_DB_TABLE_CB_FLAG_DELETE);
1228 ovs_db_table_cb_register(
1229 pdb, "Interface", interface_columns, ovs_stats_interface_table_change_cb,
1230 ovs_stats_interface_table_result_cb,
1231 OVS_DB_TABLE_CB_FLAG_INITIAL | OVS_DB_TABLE_CB_FLAG_INSERT |
1232 OVS_DB_TABLE_CB_FLAG_MODIFY);
1234 ovs_db_table_cb_register(pdb, "Interface", interface_columns,
1235 ovs_stats_interface_table_delete_cb, NULL,
1236 OVS_DB_TABLE_CB_FLAG_DELETE);
1239 /* Delete all ports from port list */
1240 static void ovs_stats_free_port_list(port_list_t *head) {
1241 for (port_list_t *i = head; i != NULL;) {
1242 port_list_t *del = i;
1244 for (interface_list_t *iface = i->iface; iface != NULL; iface = i->iface) {
1245 interface_list_t *del2 = iface;
1246 i->iface = iface->next;
1255 /* Delete all bridges from bridge list */
1256 static void ovs_stats_free_bridge_list(bridge_list_t *head) {
1257 for (bridge_list_t *i = head; i != NULL;) {
1258 bridge_list_t *del = i;
1265 /* Handle OVSDB lost connection callback */
1266 static void ovs_stats_conn_terminate() {
1267 WARNING("Lost connection to OVSDB server");
1268 pthread_mutex_lock(&g_stats_lock);
1269 ovs_stats_free_bridge_list(g_bridge_list_head);
1270 g_bridge_list_head = NULL;
1271 ovs_stats_free_port_list(g_port_list_head);
1272 g_port_list_head = NULL;
1273 pthread_mutex_unlock(&g_stats_lock);
1276 /* Parse plugin configuration file and store the config
1277 * in allocated memory. Returns negative value in case of error.
1279 static int ovs_stats_plugin_config(oconfig_item_t *ci) {
1280 bridge_list_t *bridge;
1282 for (int i = 0; i < ci->children_num; i++) {
1283 oconfig_item_t *child = ci->children + i;
1284 if (strcasecmp("Address", child->key) == 0) {
1285 if (cf_util_get_string_buffer(child, ovs_stats_cfg.ovs_db_node,
1286 OVS_DB_ADDR_NODE_SIZE) != 0) {
1287 ERROR("%s: parse '%s' option failed", plugin_name, child->key);
1290 } else if (strcasecmp("Port", child->key) == 0) {
1291 if (cf_util_get_string_buffer(child, ovs_stats_cfg.ovs_db_serv,
1292 OVS_DB_ADDR_SERVICE_SIZE) != 0) {
1293 ERROR("%s: parse '%s' option failed", plugin_name, child->key);
1296 } else if (strcasecmp("Socket", child->key) == 0) {
1297 if (cf_util_get_string_buffer(child, ovs_stats_cfg.ovs_db_unix,
1298 OVS_DB_ADDR_UNIX_SIZE) != 0) {
1299 ERROR("%s: parse '%s' option failed", plugin_name, child->key);
1302 } else if (strcasecmp("Bridges", child->key) == 0) {
1303 for (int j = 0; j < child->values_num; j++) {
1304 /* check value type */
1305 if (child->values[j].type != OCONFIG_TYPE_STRING) {
1306 ERROR("%s: Wrong bridge name [idx=%d]. "
1307 "Bridge name should be string",
1312 char const *br_name = child->values[j].value.string;
1313 if ((bridge = ovs_stats_get_bridge(g_monitored_bridge_list_head,
1314 br_name)) == NULL) {
1315 if ((bridge = calloc(1, sizeof(*bridge))) == NULL) {
1316 ERROR("%s: Error allocating memory for bridge", plugin_name);
1319 char *br_name_dup = strdup(br_name);
1320 if (br_name_dup == NULL) {
1321 ERROR("%s: strdup() copy bridge name fail", plugin_name);
1326 pthread_mutex_lock(&g_stats_lock);
1327 /* store bridge name */
1328 bridge->name = br_name_dup;
1329 bridge->next = g_monitored_bridge_list_head;
1330 g_monitored_bridge_list_head = bridge;
1331 pthread_mutex_unlock(&g_stats_lock);
1332 DEBUG("%s: found monitored interface \"%s\"", plugin_name, br_name);
1336 } else if (strcasecmp("InterfaceStats", child->key) == 0) {
1337 if (cf_util_get_boolean(child, &interface_stats) != 0) {
1338 ERROR("%s: parse '%s' option failed", plugin_name, child->key);
1342 WARNING("%s: option '%s' not allowed here", plugin_name, child->key);
1349 ovs_stats_free_bridge_list(g_monitored_bridge_list_head);
1353 /* Initialize OvS Stats plugin*/
1354 static int ovs_stats_plugin_init(void) {
1355 ovs_db_callback_t cb = {.post_conn_init = ovs_stats_initialize,
1356 .post_conn_terminate = ovs_stats_conn_terminate};
1358 INFO("%s: Connecting to OVS DB using address=%s, service=%s, unix=%s",
1359 plugin_name, ovs_stats_cfg.ovs_db_node, ovs_stats_cfg.ovs_db_serv,
1360 ovs_stats_cfg.ovs_db_unix);
1361 /* connect to OvS DB */
1363 ovs_db_init(ovs_stats_cfg.ovs_db_node, ovs_stats_cfg.ovs_db_serv,
1364 ovs_stats_cfg.ovs_db_unix, &cb)) == NULL) {
1365 ERROR("%s: plugin: failed to connect to OvS DB server", plugin_name);
1368 int err = pthread_mutex_init(&g_stats_lock, NULL);
1370 ERROR("%s: plugin: failed to initialize cache lock", plugin_name);
1371 ovs_db_destroy(g_ovs_db);
1377 /* OvS stats read callback. Read bridge/port information and submit it*/
1378 static int ovs_stats_plugin_read(__attribute__((unused)) user_data_t *ud) {
1379 pthread_mutex_lock(&g_stats_lock);
1380 for (port_list_t *port = g_port_list_head; port != NULL; port = port->next) {
1381 if (strlen(port->name) == 0)
1382 /* Skip port w/o name. This is possible when read callback
1383 * is called after Interface Table update callback but before
1384 * Port table Update callback. Will add this port on next read */
1387 /* Skip port if it has no bridge */
1391 ovs_stats_submit_port(port);
1393 if (interface_stats)
1394 ovs_stats_submit_interfaces(port);
1396 pthread_mutex_unlock(&g_stats_lock);
1400 /* Shutdown OvS Stats plugin */
1401 static int ovs_stats_plugin_shutdown(void) {
1402 DEBUG("OvS Statistics plugin shutting down");
1403 ovs_db_destroy(g_ovs_db);
1404 pthread_mutex_lock(&g_stats_lock);
1405 ovs_stats_free_bridge_list(g_bridge_list_head);
1406 ovs_stats_free_bridge_list(g_monitored_bridge_list_head);
1407 ovs_stats_free_port_list(g_port_list_head);
1408 pthread_mutex_unlock(&g_stats_lock);
1409 pthread_mutex_destroy(&g_stats_lock);
1413 /* Register OvS Stats plugin callbacks */
1414 void module_register(void) {
1415 plugin_register_complex_config(plugin_name, ovs_stats_plugin_config);
1416 plugin_register_init(plugin_name, ovs_stats_plugin_init);
1417 plugin_register_complex_read(NULL, plugin_name, ovs_stats_plugin_read, 0,
1419 plugin_register_shutdown(plugin_name, ovs_stats_plugin_shutdown);