Commit db02bb6c authored by 's avatar
Browse files

Section for DiMAPI added

git-svn-id: file:///home/svn/mapi/trunk@321 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 5110f81d
No preview for this file type
...@@ -789,65 +789,67 @@ int fd; ...@@ -789,65 +789,67 @@ int fd;
int main() { int main() {
int fid; int fid;
struct dmapi_results *dres; struct dmapi_results *dres;
unsigned long long *count, *total_count=0; unsigned long long *count, *total_count=0;
int i; int i;
signal(SIGINT, terminate); signal(SIGINT, terminate);
signal(SIGQUIT, terminate); signal(SIGQUIT, terminate);
signal(SIGTERM, terminate); signal(SIGTERM, terminate);
/* create a flow using a scope of three monitoring sensors */ /* create a flow using a scope of three monitoring sensors */
fd = mapi_create_flow("sensor.uninett.no:/dev/dag0, mon1.ics.forth.gr:eth0, 123.45.6.7:eth2"); fd = mapi_create_flow("sensor.uninett.no:/dev/dag0,
if (fd < 0) { mon1.ics.forth.gr:eth0, 123.45.6.7:eth2");
printf("Could not create flow\n"); if (fd < 0) {
exit(EXIT_FAILURE); printf("Could not create flow\n");
} exit(EXIT_FAILURE);
}
/* keep only the web packets */ /* keep only the web packets */
if (mapi_apply_function(fd, "BPF_FILTER", "tcp and port 80") < 0) { if (mapi_apply_function(fd, "BPF_FILTER", "tcp and port 80") < 0) {
printf("Could not apply BPF_FILTER function\n"); printf("Could not apply BPF_FILTER function\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* count them in every monitoring sensor */ /* count them in every monitoring sensor */
fid = mapi_apply_function(fd, "PKT_COUNTER"); fid = mapi_apply_function(fd, "PKT_COUNTER");
if (fid < 0) { if (fid < 0) {
printf("Could not apply PKT_COUNTER function\n"); printf("Could not apply PKT_COUNTER function\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* connect to the flow */ /* connect to the flow */
if(mapi_connect(fd) < 0) { if(mapi_connect(fd) < 0) {
printf("Could not connect to flow %d\n", fd); printf("Could not connect to flow %d\n", fd);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* read the results of the applied PKT_COUNTER function from all hosts every 1 sec */ /* read the results of the applied PKT_COUNTER function from all
while(loop--){ hosts every 1 sec */
sleep(1); while(loop--){
sleep(1);
dres = (struct dmapi_results*) mapi_read_results(fd,fid,MAPI_COPY); dres = (struct dmapi_results*) mapi_read_results(fd, fid, MAPI_COPY);
for (i=0; i<dres->cnt; i++) { for (i=0; i<dres->cnt; i++) {
count=*((unsigned long long*)dres->res[i].result); count = *( (unsigned long long*) dres->res[i].result );
printf("web packets in host %s: %llu\n",dres->res[i].host_dev, count); printf("web packets in host %s: %llu\n",dres->res[i].host_dev, count);
total_count+=count; total_count += count;
}
printf("Total web packets: %llu\n",total_count);
} }
printf("Total web packets: %llu\n",total_count);
}
cnt = (unsigned long long *)mapi_read_results(fd, fid, MAPI_COPY); cnt = (unsigned long long *) mapi_read_results(fd, fid, MAPI_COPY);
printf("pkts:%llu\n", *cnt); printf("pkts:%llu\n", *cnt);
return 0; return 0;
} }
void terminate() { void terminate() {
mapi_close_flow(fd); mapi_close_flow(fd);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
\end{Verbatim} \end{Verbatim}
......
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