#include <stdint.h>
#include "main.h"
#define SUBPORT_OFFSET  7
#define PIPE_OFFSET     9
#define TC_OFFSET       20
#define QUEUE_OFFSET    20
#define COLOR_OFFSET    19
static inline int
get_pkt_sched(
struct rte_mbuf *m, uint32_t *subport, uint32_t *pipe,
            uint32_t *traffic_class, uint32_t *queue, uint32_t *color)
{
            (port_params.n_subports_per_port - 1); 
            (port_params.n_pipes_per_subport - 1); 
    *traffic_class = (pdata[QUEUE_OFFSET] & 0x0F) &
    *queue = ((pdata[QUEUE_OFFSET] >> 8) & 0x0F) &
    *color = pdata[COLOR_OFFSET] & 0x03;    
    return 0;
}
void
app_rx_thread(struct thread_conf **confs)
{
    uint32_t i, nb_rx;
    struct thread_conf *conf;
    int conf_idx = 0;
    uint32_t subport;
    uint32_t pipe;
    uint32_t traffic_class;
    uint32_t queue;
    uint32_t color;
    while ((conf = confs[conf_idx])) {
                burst_conf.rx_burst);
            APP_STATS_ADD(conf->stat.nb_rx, nb_rx);
            for(i = 0; i < nb_rx; i++) {
                get_pkt_sched(rx_mbufs[i],
                        &subport, &pipe, &traffic_class, &queue, &color);
            }
                    (void **)rx_mbufs, nb_rx, NULL) == 0)) {
                for(i = 0; i < nb_rx; i++) {
                    APP_STATS_ADD(conf->stat.nb_drop, 1);
                }
            }
        }
        conf_idx++;
        if (confs[conf_idx] == NULL)
            conf_idx = 0;
    }
}
static inline void
app_send_burst(struct thread_conf *qconf)
{
    uint32_t n, ret;
    mbufs = (
struct rte_mbuf **)qconf->m_table;
    n = qconf->n_mbufs;
    do {
        
        
        n -= ret;
        mbufs = (
struct rte_mbuf **)&mbufs[ret];
    } while (n);
}
static void
app_send_packets(
struct thread_conf *qconf, 
struct rte_mbuf **mbufs, uint32_t nb_pkt)
{
    uint32_t i, len;
    len = qconf->n_mbufs;
    for(i = 0; i < nb_pkt; i++) {
        qconf->m_table[len] = mbufs[i];
        len++;
        
        if (
unlikely(len == burst_conf.tx_burst)) {
 
            qconf->n_mbufs = len;
            app_send_burst(qconf);
            len = 0;
        }
    }
    qconf->n_mbufs = len;
}
void
app_tx_thread(struct thread_conf **confs)
{
    struct rte_mbuf *mbufs[burst_conf.qos_dequeue];
 
    struct thread_conf *conf;
    int conf_idx = 0;
    int retval;
    const uint64_t drain_tsc = (
rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US;
 
    while ((conf = confs[conf_idx])) {
                    burst_conf.qos_dequeue, NULL);
            app_send_packets(conf, mbufs, burst_conf.qos_dequeue);
            conf->counter = 0; 
        }
        conf->counter++;
        
        if (
unlikely(conf->counter > drain_tsc)) {
 
            
            if (conf->n_mbufs != 0) {
                app_send_burst(conf);
                conf->n_mbufs = 0;
            }
            conf->counter = 0;
        }
        conf_idx++;
        if (confs[conf_idx] == NULL)
            conf_idx = 0;
    }
}
void
app_worker_thread(struct thread_conf **confs)
{
    struct rte_mbuf *mbufs[burst_conf.ring_burst];
 
    struct thread_conf *conf;
    int conf_idx = 0;
    while ((conf = confs[conf_idx])) {
        uint32_t nb_pkt;
        
                    burst_conf.ring_burst, NULL);
                    nb_pkt);
            APP_STATS_ADD(conf->stat.nb_drop, nb_pkt - nb_sent);
            APP_STATS_ADD(conf->stat.nb_rx, nb_pkt);
        }
                    burst_conf.qos_dequeue);
                    (void **)mbufs, nb_pkt, NULL) == 0)
                ; 
        conf_idx++;
        if (confs[conf_idx] == NULL)
            conf_idx = 0;
    }
}
void
app_mixed_thread(struct thread_conf **confs)
{
    struct rte_mbuf *mbufs[burst_conf.ring_burst];
 
    struct thread_conf *conf;
    int conf_idx = 0;
    const uint64_t drain_tsc = (
rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US;
 
    while ((conf = confs[conf_idx])) {
        uint32_t nb_pkt;
        
                    burst_conf.ring_burst, NULL);
                    nb_pkt);
            APP_STATS_ADD(conf->stat.nb_drop, nb_pkt - nb_sent);
            APP_STATS_ADD(conf->stat.nb_rx, nb_pkt);
        }
                    burst_conf.qos_dequeue);
            app_send_packets(conf, mbufs, nb_pkt);
            conf->counter = 0; 
        }
        conf->counter++;
        
        if (
unlikely(conf->counter > drain_tsc)) {
 
            
            if (conf->n_mbufs != 0) {
                app_send_burst(conf);
                conf->n_mbufs = 0;
            }
            conf->counter = 0;
        }
        conf_idx++;
        if (confs[conf_idx] == NULL)
            conf_idx = 0;
    }
}