+static void ovs_stats_submit_interfaces(port_list_t *port) {
+ char devname[PORT_NAME_SIZE_MAX * 2];
+
+ bridge_list_t *bridge = port->br;
+ for (interface_list_t *iface = port->iface; iface != NULL;
+ iface = iface->next) {
+ meta_data_t *meta = meta_data_create();
+ if (meta != NULL) {
+ meta_data_add_string(meta, "uuid", iface->iface_uuid);
+
+ if (strlen(iface->ex_vm_id))
+ meta_data_add_string(meta, "vm-uuid", iface->ex_vm_id);
+
+ if (strlen(iface->ex_iface_id))
+ meta_data_add_string(meta, "iface-id", iface->ex_iface_id);
+ }
+ strjoin(devname, sizeof(devname),
+ (char *[]){
+ bridge->name, port->name, iface->name,
+ },
+ 3, ".");
+ ovs_stats_submit_one(devname, "if_collisions", NULL,
+ iface->stats[collisions], meta);
+ ovs_stats_submit_two(devname, "if_dropped", NULL, iface->stats[rx_dropped],
+ iface->stats[tx_dropped], meta);
+ ovs_stats_submit_two(devname, "if_errors", NULL, iface->stats[rx_errors],
+ iface->stats[tx_errors], meta);
+ ovs_stats_submit_two(devname, "if_packets", NULL, iface->stats[rx_packets],
+ iface->stats[tx_packets], meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "crc",
+ iface->stats[rx_crc_err], meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "frame",
+ iface->stats[rx_frame_err], meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "over",
+ iface->stats[rx_over_err], meta);
+ ovs_stats_submit_one(devname, "if_rx_octets", NULL, iface->stats[rx_bytes],
+ meta);
+ ovs_stats_submit_one(devname, "if_tx_octets", NULL, iface->stats[tx_bytes],
+ meta);
+ ovs_stats_submit_two(devname, "if_packets", "1_to_64_packets",
+ iface->stats[rx_1_to_64_packets],
+ iface->stats[tx_1_to_64_packets], meta);
+ ovs_stats_submit_two(devname, "if_packets", "65_to_127_packets",
+ iface->stats[rx_65_to_127_packets],
+ iface->stats[tx_65_to_127_packets], meta);
+ ovs_stats_submit_two(devname, "if_packets", "128_to_255_packets",
+ iface->stats[rx_128_to_255_packets],
+ iface->stats[tx_128_to_255_packets], meta);
+ ovs_stats_submit_two(devname, "if_packets", "256_to_511_packets",
+ iface->stats[rx_256_to_511_packets],
+ iface->stats[tx_256_to_511_packets], meta);
+ ovs_stats_submit_two(devname, "if_packets", "512_to_1023_packets",
+ iface->stats[rx_512_to_1023_packets],
+ iface->stats[tx_512_to_1023_packets], meta);
+ ovs_stats_submit_two(devname, "if_packets", "1024_to_1522_packets",
+ iface->stats[rx_1024_to_1522_packets],
+ iface->stats[tx_1024_to_1522_packets], meta);
+ ovs_stats_submit_two(devname, "if_packets", "1523_to_max_packets",
+ iface->stats[rx_1523_to_max_packets],
+ iface->stats[tx_1523_to_max_packets], meta);
+ ovs_stats_submit_two(devname, "if_packets", "broadcast_packets",
+ iface->stats[rx_broadcast_packets],
+ iface->stats[tx_broadcast_packets], meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "rx_undersized_errors",
+ iface->stats[rx_undersized_errors], meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "rx_oversize_errors",
+ iface->stats[rx_oversize_errors], meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "rx_fragmented_errors",
+ iface->stats[rx_fragmented_errors], meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "rx_jabber_errors",
+ iface->stats[rx_jabber_errors], meta);
+ ovs_stats_submit_one(devname, "if_rx_octets", "rx_error_bytes",
+ iface->stats[rx_error_bytes], meta);
+ ovs_stats_submit_one(devname, "if_errors", "rx_l3_l4_xsum_error",
+ iface->stats[rx_l3_l4_xsum_error], meta);
+ ovs_stats_submit_one(devname, "if_dropped", "rx_management_dropped",
+ iface->stats[rx_management_dropped], meta);
+ ovs_stats_submit_one(devname, "if_errors", "rx_mbuf_allocation_errors",
+ iface->stats[rx_mbuf_allocation_errors], meta);
+ ovs_stats_submit_one(devname, "if_octets", "rx_total_bytes",
+ iface->stats[rx_total_bytes], meta);
+ ovs_stats_submit_one(devname, "if_packets", "rx_total_missed_packets",
+ iface->stats[rx_total_missed_packets], meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "rx_undersize_errors",
+ iface->stats[rx_undersize_errors], meta);
+ ovs_stats_submit_two(devname, "if_packets", "management_packets",
+ iface->stats[rx_management_packets],
+ iface->stats[tx_management_packets], meta);
+ ovs_stats_submit_two(devname, "if_packets", "multicast_packets",
+ iface->stats[rx_multicast_packets],
+ iface->stats[tx_multicast_packets], meta);
+ ovs_stats_submit_two(devname, "if_octets", "good_bytes",
+ iface->stats[rx_good_bytes],
+ iface->stats[tx_good_bytes], meta);
+ ovs_stats_submit_two(devname, "if_packets", "good_packets",
+ iface->stats[rx_good_packets],
+ iface->stats[tx_good_packets], meta);
+ ovs_stats_submit_two(devname, "if_packets", "total_packets",
+ iface->stats[rx_total_packets],
+ iface->stats[tx_total_packets], meta);
+
+ meta_data_destroy(meta);
+ }
+}
+
+static int ovs_stats_get_port_stat_value(port_list_t *port,
+ iface_counter index) {
+ if (port == NULL)
+ return 0;
+
+ int value = 0;
+
+ for (interface_list_t *iface = port->iface; iface != NULL;
+ iface = iface->next) {
+ value = value + iface->stats[index];
+ }
+
+ return value;
+}
+
+static void ovs_stats_submit_port(port_list_t *port) {
+ char devname[PORT_NAME_SIZE_MAX * 2];
+
+ meta_data_t *meta = meta_data_create();
+ if (meta != NULL) {
+ char key_str[DATA_MAX_NAME_LEN];
+ int i = 0;
+
+ for (interface_list_t *iface = port->iface; iface != NULL;
+ iface = iface->next) {
+ ssnprintf(key_str, sizeof(key_str), "uuid%d", i);
+ meta_data_add_string(meta, key_str, iface->iface_uuid);
+
+ if (strlen(iface->ex_vm_id)) {
+ ssnprintf(key_str, sizeof(key_str), "vm-uuid%d", i);
+ meta_data_add_string(meta, key_str, iface->ex_vm_id);
+ }
+
+ if (strlen(iface->ex_iface_id)) {
+ ssnprintf(key_str, sizeof(key_str), "iface-id%d", i);
+ meta_data_add_string(meta, key_str, iface->ex_iface_id);
+ }
+
+ i++;
+ }
+ }
+ bridge_list_t *bridge = port->br;
+ ssnprintf(devname, sizeof(devname), "%s.%s", bridge->name, port->name);
+ ovs_stats_submit_one(devname, "if_collisions", NULL,
+ ovs_stats_get_port_stat_value(port, collisions), meta);
+ ovs_stats_submit_two(devname, "if_dropped", NULL,
+ ovs_stats_get_port_stat_value(port, rx_dropped),
+ ovs_stats_get_port_stat_value(port, tx_dropped), meta);
+ ovs_stats_submit_two(devname, "if_errors", NULL,
+ ovs_stats_get_port_stat_value(port, rx_errors),
+ ovs_stats_get_port_stat_value(port, tx_errors), meta);
+ ovs_stats_submit_two(devname, "if_packets", NULL,
+ ovs_stats_get_port_stat_value(port, rx_packets),
+ ovs_stats_get_port_stat_value(port, tx_packets), meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "crc",
+ ovs_stats_get_port_stat_value(port, rx_crc_err), meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "frame",
+ ovs_stats_get_port_stat_value(port, rx_frame_err), meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "over",
+ ovs_stats_get_port_stat_value(port, rx_over_err), meta);
+ ovs_stats_submit_one(devname, "if_rx_octets", NULL,
+ ovs_stats_get_port_stat_value(port, rx_bytes), meta);
+ ovs_stats_submit_one(devname, "if_tx_octets", NULL,
+ ovs_stats_get_port_stat_value(port, tx_bytes), meta);
+ ovs_stats_submit_two(devname, "if_packets", "1_to_64_packets",
+ ovs_stats_get_port_stat_value(port, rx_1_to_64_packets),
+ ovs_stats_get_port_stat_value(port, tx_1_to_64_packets),
+ meta);
+ ovs_stats_submit_two(
+ devname, "if_packets", "65_to_127_packets",
+ ovs_stats_get_port_stat_value(port, rx_65_to_127_packets),
+ ovs_stats_get_port_stat_value(port, tx_65_to_127_packets), meta);
+ ovs_stats_submit_two(
+ devname, "if_packets", "128_to_255_packets",
+ ovs_stats_get_port_stat_value(port, rx_128_to_255_packets),
+ ovs_stats_get_port_stat_value(port, tx_128_to_255_packets), meta);
+ ovs_stats_submit_two(
+ devname, "if_packets", "256_to_511_packets",
+ ovs_stats_get_port_stat_value(port, rx_256_to_511_packets),
+ ovs_stats_get_port_stat_value(port, tx_256_to_511_packets), meta);
+ ovs_stats_submit_two(
+ devname, "if_packets", "512_to_1023_packets",
+ ovs_stats_get_port_stat_value(port, rx_512_to_1023_packets),
+ ovs_stats_get_port_stat_value(port, tx_512_to_1023_packets), meta);
+ ovs_stats_submit_two(
+ devname, "if_packets", "1024_to_1522_packets",
+ ovs_stats_get_port_stat_value(port, rx_1024_to_1522_packets),
+ ovs_stats_get_port_stat_value(port, tx_1024_to_1522_packets), meta);
+ ovs_stats_submit_two(
+ devname, "if_packets", "1523_to_max_packets",
+ ovs_stats_get_port_stat_value(port, rx_1523_to_max_packets),
+ ovs_stats_get_port_stat_value(port, tx_1523_to_max_packets), meta);
+ ovs_stats_submit_two(
+ devname, "if_packets", "broadcast_packets",
+ ovs_stats_get_port_stat_value(port, rx_broadcast_packets),
+ ovs_stats_get_port_stat_value(port, tx_broadcast_packets), meta);
+ ovs_stats_submit_one(
+ devname, "if_rx_errors", "rx_undersized_errors",
+ ovs_stats_get_port_stat_value(port, rx_undersized_errors), meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "rx_oversize_errors",
+ ovs_stats_get_port_stat_value(port, rx_oversize_errors),
+ meta);
+ ovs_stats_submit_one(
+ devname, "if_rx_errors", "rx_fragmented_errors",
+ ovs_stats_get_port_stat_value(port, rx_fragmented_errors), meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "rx_jabber_errors",
+ ovs_stats_get_port_stat_value(port, rx_jabber_errors),
+ meta);
+ ovs_stats_submit_one(devname, "if_rx_octets", "rx_error_bytes",
+ ovs_stats_get_port_stat_value(port, rx_error_bytes),
+ meta);
+ ovs_stats_submit_one(devname, "if_errors", "rx_l3_l4_xsum_error",
+ ovs_stats_get_port_stat_value(port, rx_l3_l4_xsum_error),
+ meta);
+ ovs_stats_submit_one(
+ devname, "if_dropped", "rx_management_dropped",
+ ovs_stats_get_port_stat_value(port, rx_management_dropped), meta);
+ ovs_stats_submit_one(
+ devname, "if_errors", "rx_mbuf_allocation_errors",
+ ovs_stats_get_port_stat_value(port, rx_mbuf_allocation_errors), meta);
+ ovs_stats_submit_one(devname, "if_octets", "rx_total_bytes",
+ ovs_stats_get_port_stat_value(port, rx_total_bytes),
+ meta);
+ ovs_stats_submit_one(
+ devname, "if_packets", "rx_total_missed_packets",
+ ovs_stats_get_port_stat_value(port, rx_total_missed_packets), meta);
+ ovs_stats_submit_one(devname, "if_rx_errors", "rx_undersize_errors",
+ ovs_stats_get_port_stat_value(port, rx_undersize_errors),
+ meta);
+ ovs_stats_submit_two(
+ devname, "if_packets", "management_packets",
+ ovs_stats_get_port_stat_value(port, rx_management_packets),
+ ovs_stats_get_port_stat_value(port, tx_management_packets), meta);
+ ovs_stats_submit_two(
+ devname, "if_packets", "multicast_packets",
+ ovs_stats_get_port_stat_value(port, rx_multicast_packets),
+ ovs_stats_get_port_stat_value(port, tx_multicast_packets), meta);
+ ovs_stats_submit_two(devname, "if_octets", "good_bytes",
+ ovs_stats_get_port_stat_value(port, rx_good_bytes),
+ ovs_stats_get_port_stat_value(port, tx_good_bytes),
+ meta);
+ ovs_stats_submit_two(devname, "if_packets", "good_packets",
+ ovs_stats_get_port_stat_value(port, rx_good_packets),
+ ovs_stats_get_port_stat_value(port, tx_good_packets),
+ meta);
+ ovs_stats_submit_two(devname, "if_packets", "total_packets",
+ ovs_stats_get_port_stat_value(port, rx_total_packets),
+ ovs_stats_get_port_stat_value(port, tx_total_packets),
+ meta);
+
+ meta_data_destroy(meta);
+}
+