Commit a0609b50 authored by 's avatar
Browse files

Added BURST into man page and test_burst.c into tests directory.


git-svn-id: file:///home/svn/mapi/trunk@1304 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent e4933d10
......@@ -27,6 +27,7 @@ MAPI stdflib \- Standard MAPI Function Library
\fBRES2FILE\fP Stores results from other MAPI functions to a file
\fBSTARTSTOP\fP Starts and/or stops measurements at a specific time
\fBSTATS\fP Returns statistical information about results from other MAPI functions
\fBBURST\fP Returns the histogram of bursts
.fi
.SH DESCRIPTION
......@@ -317,6 +318,24 @@ struct stats {
};
.fi
.\"--------------------------------------------------------
.IP "\fBBURST\fP (int \fImin\fP, int \fImax\fP, int \fIstep\fP, int \fIiftime\fP, int \fIlate\fP, int \fIearly\fP, int \fIlink_speed\fP)"
Returns the histogram of bursts. Bursts are categorized according to their total size in bytes, the result is an array of total sizes of these bursts. Catogory 0 always holds bursts of lower size than the minimum size specified (\fImin\fP [B]). The last category always holds bursts of greater size than the maximum size specified (\fImax\fP [B]). \fIstep\fP [B] specifies the precission of the histogram.
.nf
Category Burst size in bytes
0 <0, min)
1 <min, min + step)
...
N-1 <max - step, max)
N >= max
.fi
\fIiftime\fP [ns] specifies the inter-frame time (an expected time from last bit of one packet to first bit of the following packet in burst), \fIlate\fP [ns] and \fIearly\fP [ns] specifies the tolerance (packet can arrive \fIlate\fP ns later or \fIearly\fP ns earlier than expected). \fIlink_speed\fP [mbps] specifies the speed of the link associated with the flow.
Number of categories returned: (\fImax\fP - \fImin\fP) / \fIstep\fP + 2
Type of results: \fBunsigned long[]\fP.
.\"--------------------------------------------------------
.SH "EXAMPLES"
The example below reports periodically
......
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <mapi.h>
#include <string.h>
int main(int argc, char *argv[]) {
int fd;
int fid;
mapi_flow_info_t info;
mapi_device_info_t dinfo;
mapi_results_t* res;
int err_no = 0;
char error[512];
void *oldres;
unsigned int oldres_size;
unsigned int i;
unsigned int loop = 0;
unsigned int loops = 3;
unsigned int mtime = 3;
unsigned int min = 0;
unsigned int max = 10000;
unsigned int step = 1000;
unsigned int categories = (max - min) / step + 2;
unsigned int link_speed;
unsigned int iftime;
unsigned int late;
unsigned int early;
if (argc == 1) { // no device specified
fprintf(stderr, "\nWrong arguments\n");
exit(EXIT_FAILURE);
}
// create flow
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);
}
// get link_speed
if((mapi_get_flow_info(fd, &info)) < 0){
fprintf(stderr, "Getting flow info failed on fd:%d\n", fd);
mapi_read_error(&err_no, error);
fprintf(stderr,"Errorcode: %d description: %s.\n", err_no, error);
exit(EXIT_FAILURE);
}
if((mapi_get_device_info(info.devid, &dinfo)) < 0){
fprintf(stderr, "Getting device info failed on fd:%d\n", fd);
mapi_read_error(&err_no, error);
fprintf(stderr,"Errorcode: %d description: %s.\n", err_no, error);
exit(EXIT_FAILURE);
}
if(dinfo.link_speed == 0) {
fprintf(stderr, "Getting device info failed on fd:%d. Please configure link_speed for device %s in [driver] section of mapi.conf.\n", fd, dinfo.device);
exit(EXIT_FAILURE);
}
link_speed = dinfo.link_speed;
// calculate iftime
iftime = (int) 160000 / link_speed; // (12 + 8) * 8
// set up tolerance
late = 12304000 / link_speed; // == 1000000000*1538*8/(l_s * 1000000)
early = 12304000 / link_speed; // == 1000000000*1538*8/(l_s * 1000000)
// allocate memory to store results in
if((oldres = malloc(oldres_size = categories * sizeof(unsigned long))) == NULL) {
fprintf(stderr, "Could not allocate internal data.\n");
exit(EXIT_FAILURE);
}
memset(oldres, 0, oldres_size);
// apply function
if ((fid = mapi_apply_function(fd, "BURST", min, max, step, iftime, late, early, link_speed)) == -1) {
fprintf(stderr, "Count not apply function BURST 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);
}
while(loop < loops) {
printf("Loop: %d / %d (%d seconds per loop)\n", loop, loops, mtime);
sleep(mtime);
res = mapi_read_results(fd, fid);
for(i = 0; i < categories; i++) {
printf("%d: burst[%d]: %lu\n", loop, i, ((unsigned long*)res->res)[i] - ((unsigned long*)oldres)[i]);
((unsigned long*)oldres)[i] = ((unsigned long*)res->res)[i];
}
printf("\n");
fflush(stdout);
loop++;
}
free(oldres);
printf("Brust finished.\n");
return 0;
}
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