Commit e82629a8 authored by 's avatar

test application for PKTBYTECOUNTERFILTER


git-svn-id: file:///home/svn/mapi/trunk@1606 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 5d843deb
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <mapi.h>
#include "test.h"
#define RULES_MAX 2048LLU
typedef struct pktbytecounterrules_rules {
// unsigned int rules;
unsigned long long packets[RULES_MAX];
unsigned long long bytes[RULES_MAX];
} pktbytecounterrules_rules_t;
int main(int argc, char *argv[])
{
int fd;
int fid;
mapi_results_t* res;
int err_no=0 , flag=0;
char error[512];
mapi_flow_info_t info;
pktbytecounterrules_rules_t *pktbytecounterrules_rules;
if (argc != 2) {
fprintf(stderr, "\nWrong arguments\n");
// return -1;
}
if ((fd = mapi_create_flow("/dev/szedataII0")) < 0) {
fprintf(stderr, "Could not create flow using '%s'\n", argv[1]);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode :%d description: %s \n" ,err_no, error);
return -1;
}
if ((fid = mapi_apply_function(fd, "PKTBYTECOUNTERFILTER")) == -1) {
fprintf(stderr, "Count not apply function PKTBYTECOUNTERFILTER to flow %d\n", fd);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode :%d description: %s \n" ,err_no, error);
return -1;
}
;
if (mapi_connect(fd) < 0) {
fprintf(stderr, "Could not connect to flow %d\n", fd);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode :%d description: %s \n" ,err_no, error);
return -1;
}
while (1) {
res = mapi_read_results(fd, fid);
if(res != NULL) {
pktbytecounterrules_rules = res->res;
unsigned int i;
for (i = 0; i < RULES_MAX; i++) {
if(pktbytecounterrules_rules->packets[i])
printf("packets[%u] %llu\n", i, pktbytecounterrules_rules->packets[i]);
if(pktbytecounterrules_rules->bytes[i])
printf("bytes[%u] %llu\n", i, pktbytecounterrules_rules->bytes[i]);
}
printf("---\n");
}
sleep(1);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment