/* Try to increment stats for all vswitch counters, which should * succeed */ static void test_stats_vswitch_increment(int argc, char *argv[]) { stats_init(); stats_vswitch_clear(); stats_vswitch_rx_drop_increment(23); stats_vswitch_tx_drop_increment(23); stats_vswitch_rx_drop_increment(19); stats_vswitch_tx_drop_increment(19); }
/* * Function sends unmatched packets to vswitchd. */ void send_packet_to_vswitchd(struct rte_mbuf *mbuf, struct dpdk_upcall *info) { int rslt = 0; void *mbuf_ptr = NULL; const uint64_t dpif_send_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * DPIF_SEND_US; uint64_t cur_tsc = 0; uint64_t diff_tsc = 0; static uint64_t prev_tsc = 0; /* send one packet, delete information about segments */ rte_pktmbuf_pkt_len(mbuf) = rte_pktmbuf_data_len(mbuf); /* allocate space before the packet for the upcall info */ mbuf_ptr = rte_pktmbuf_prepend(mbuf, sizeof(*info)); if (mbuf_ptr == NULL) { printf("Cannot prepend upcall info\n"); rte_pktmbuf_free(mbuf); stats_vswitch_tx_drop_increment(INC_BY_1); stats_vport_tx_drop_increment(VSWITCHD, INC_BY_1); return; } rte_memcpy(mbuf_ptr, info, sizeof(*info)); /* send the packet and the upcall info to the daemon */ rslt = rte_ring_mp_enqueue(vswitchd_packet_ring, mbuf); if (rslt < 0) { if (rslt == -ENOBUFS) { rte_pktmbuf_free(mbuf); stats_vswitch_tx_drop_increment(INC_BY_1); stats_vport_tx_drop_increment(VSWITCHD, INC_BY_1); return; } else { stats_vport_overrun_increment(VSWITCHD, INC_BY_1); } } stats_vport_tx_increment(VSWITCHD, INC_BY_1); cur_tsc = rte_rdtsc(); diff_tsc = cur_tsc - prev_tsc; prev_tsc = cur_tsc; /* Only signal the daemon after 100 milliseconds */ if (unlikely(diff_tsc > dpif_send_tsc)) send_signal_to_dpif(); }
/* Try to get stats for all vswitch, which should succeed */ static void test_stats_vswitch_get(int argc, char *argv[]) { stats_init(); stats_vswitch_clear(); /* increment stats so there's something to check */ stats_vswitch_rx_drop_increment(23); stats_vswitch_tx_drop_increment(23); stats_vswitch_rx_drop_increment(19); stats_vswitch_tx_drop_increment(19); assert(stats_vswitch_rx_drop_get() == 42); assert(stats_vswitch_tx_drop_get() == 42); }
/* * Send a reply message to the vswitchd */ static void send_reply_to_vswitchd(struct dpdk_message *reply) { struct rte_mbuf *mbuf = NULL; void *pktmbuf_data = NULL; int rslt = 0; /* Preparing the buffer to send */ mbuf = rte_pktmbuf_alloc(pktmbuf_pool); if (!mbuf) { RTE_LOG(WARNING, APP, "Error : Unable to allocate an mbuf " ": %s : %d", __FUNCTION__, __LINE__); stats_vswitch_tx_drop_increment(INC_BY_1); stats_vport_rx_drop_increment(VSWITCHD, INC_BY_1); return; } pktmbuf_data = rte_pktmbuf_mtod(mbuf, void *); rte_memcpy(pktmbuf_data, reply, sizeof(*reply)); rte_pktmbuf_data_len(mbuf) = sizeof(*reply); /* Sending the buffer to vswitchd */ rslt = rte_ring_mp_enqueue(vswitchd_reply_ring, (void *)mbuf); if (rslt < 0) { if (rslt == -ENOBUFS) { rte_pktmbuf_free(mbuf); stats_vswitch_tx_drop_increment(INC_BY_1); stats_vport_rx_drop_increment(VSWITCHD, INC_BY_1); } else { stats_vport_overrun_increment(VSWITCHD, INC_BY_1); stats_vport_rx_increment(VSWITCHD, INC_BY_1); } } else { stats_vport_rx_increment(VSWITCHD, INC_BY_1); } }