Commit 047c01a1 authored by 's avatar

Test file for EXPIRED_FLOWS.


git-svn-id: file:///home/svn/mapi/trunk@1348 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 82b84a61
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <ncurses.h>
#include <rrd.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <netdb.h>
#include <mapi/expiredflowshash.h>
#include <mapi.h>
#include "../test.h"
#define DOTS DOT; DOT; DOT; DOT; DOT; DOT; DOT; DOT; DOT; DOT
#define LOOPS 10
void print_flow(flow_data *data);
int main(int argc, char *argv[]) {
mapi_results_t *result;
unsigned int *results;
struct flow_data *flowdata;
unsigned int i;
char error[512];
int err_no = 0;
int fd;
int fid;
int loops = LOOPS;
if(argc != 2){
printf("Usage: %s <interface> \n", argv[0]);
return -1;
}
if ((fd = mapi_create_flow(argv[1])) < 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);
exit(EXIT_FAILURE);
}
if ((fid = mapi_apply_function(fd, "EXPIRED_FLOWS")) < 0) {
fprintf(stderr, "Count not apply function EXPIRED_FLOWS to flow %d\n", fd);
mapi_read_error(&err_no, error);
fprintf(stderr, "Errorcode: %d description: %s\n", err_no, error);
exit(EXIT_FAILURE);
}
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);
exit(EXIT_FAILURE);
}
// Main loop
while (loops--) { // Infinite Loop. Forever, report the load and packet loss
printf("loop %d/%d\n", LOOPS - loops, LOOPS);
DOTS;
result = (mapi_results_t *) mapi_read_results(fd, fid);
results = (unsigned int *) result->res; // number of results/flows at host h, dev d
flowdata = (struct flow_data *)((char *) result->res + sizeof(unsigned int)); // results/flows array
printf("results: %d (please wait)\n", *results);
for (i = *results; i > 0; i--) {
print_flow(flowdata);
flowdata++;
}
}
if(mapi_close_flow(fd)<0){
fprintf(stderr,"Close flow failed\n");
mapi_read_error(&err_no, error);
fprintf(stderr,"Erorcode :%d description: %s \n" ,err_no, error);
return -1;
}
return 0;
}
void print_flow(flow_data *data) {
switch (data->ptcl) {
case IPPROTO_TCP: fprintf(stdout, "TCP "); break;
case IPPROTO_UDP: fprintf(stdout, "UDP "); break;
default: fprintf(stdout, "IP "); break;
}
fprintf(stdout, "src %d.%d.%d.%d:%d\t", data->saddr.byte1, data->saddr.byte2, data->saddr.byte3, data->saddr.byte4, data->sport);
fprintf(stdout, "dst %d.%d.%d.%d:%d\t", data->daddr.byte1, data->daddr.byte2, data->daddr.byte3, data->daddr.byte4, data->dport);
fprintf(stdout, "packets: %lld, bytes: %lld\n", data->packets_count, data->bytes_count);
}
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