//=============================================================================================================
#include <stdint.h>
#include <stdlib.h>
#include <nfp/me.h>
#include <nfp/mem_atomic.h>
#include <pif_common.h>
#include "pif_plugin.h"

//=============================================================================================================

// __export __emem uint32_t pkt_cntrs;
__export __emem uint8_t pkt_cntrs[20];

int pif_plugin_countpacket(EXTRACTED_HEADERS_T *headers, MATCH_DATA_T *match_data) {

    PIF_PLUGIN_map_hdr_T *mapHdr = pif_plugin_hdr_get_map_hdr(headers);
    // uint32_t fid = mapHdr->function_id;
    int fid = mapHdr->function_id;
    // __gpr uint64_t ar[10000];
    // int idx = -1;
    pkt_cntrs[fid%20]++;

    // pkt_cntrs++;
    mapHdr->data = 0;
    mapHdr->function_id = fid+1;
    return PIF_PLUGIN_RETURN_FORWARD; 
}
