Commit e4ad2ea3 authored by 's avatar

added a new mapi_is_remote function

git-svn-id: file:///home/svn/mapi/trunk@833 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent b71022a8
......@@ -47,6 +47,8 @@ MAPI \- Monitoring Application Programming Interface
.BI "int mapi_get_next_function_info(int " fd ", int " fid ", mapi_function_info_t *" info ");"
.br
.BI "int mapi_get_scope_size(int " fd ");"
.br
.BI "int mapi_is_remote(int " fd ");"
.SH DESCRIPTION
MAPI builds on the simple and powerful abstraction of the network flow. In
MAPI, a network flow is generally defined as a sequence of packets that
......@@ -404,6 +406,14 @@ that have been declared in
.B mapi_create_flow()
for the network scope denoted by
.IR fd .
If the flow does not exist, it returns -1.
.sp
.BI "int mapi_is_remote(int " fd ");"
.br
Returns 1 if the flow
.IR fd
is associated with a remote sensor, otherwise returns 0.
If the flow does not exist, it returns -1.
.\".B \-<a command line switch>
.\"<description of what that switch does>
.\".TP
......
No preview for this file type
......@@ -3364,12 +3364,29 @@ int mapi_get_scope_size(int fd) {
#ifdef DIMAPI
remote_flowdescr_t* rflow=(remote_flowdescr_t*)flist_get(remote_flowlist, fd);
if (rflow!=NULL) return rflow->scope_size;
if (rflow!=NULL)
return rflow->scope_size;
#endif
if ( flist_get(flowlist, fd)!=NULL ) return 1;
if ( flist_get(flowlist, fd)!=NULL )
return 1;
else {
local_err = MAPI_INVALID_FLOW;
return -1;
}
}
int mapi_is_remote(int fd) {
#ifdef DIMAPI
remote_flowdescr_t* rflow=(remote_flowdescr_t*)flist_get(remote_flowlist, fd);
if (rflow!=NULL) {
return 1;
}
#endif
if (flist_get(flowlist, fd)!=NULL ) {
return 0;
}
else {
local_err = MAPI_INVALID_FLOW;
return -1;
}
}
......@@ -219,6 +219,7 @@ extern int mapi_get_flow_info(int fd, mapi_flow_info_t *info);
extern int mapi_get_next_flow_info(int fd, mapi_flow_info_t *info);
extern int mapi_get_scope_size(int fd);
extern int mapi_is_remote(int fd);
//Get information about a function applied to a flow
extern int mapi_get_function_info(int fd, int fid, mapi_function_info_t *info);
......
......@@ -12,10 +12,10 @@ int main(int argc, char *argv[])
int fid;
unsigned long long limit = 50;
mapi_results_t *run;
int err_no =0 , flag=0;
int err_no=0 , flag=0;
char error[512];
mapi_flow_info_t info;
mapi_flow_info_t info;
if(argc!=2) // Just for uniformity reasons
{
printf("\nWrong Arguments\n");
......@@ -31,33 +31,30 @@ int main(int argc, char *argv[])
DOT;
if((fid = mapi_apply_function(fd, "TO_FILE", MFF_PCAP, "/tmp/MAPI_TESTSUITE_DUMMY_TRACE", limit))<0){
fprintf(stderr, "Could not apply TO_FILE to flow %d\n", fd);
fprintf(stderr, "Could not apply TO_FILE to flow %d\n", fd);
mapi_read_error( &err_no, error);
fprintf(stderr,"Erorcode :%d description: %s \n" ,err_no, error);
return -1;
}
DOT;
DOT;
if(mapi_connect(fd)<0){
fprintf(stderr, "Connecting to flow failed %d\n", fd);
fprintf(stderr, "Connecting to flow failed %d\n", fd);
mapi_read_error( &err_no, error);
fprintf(stderr,"Erorcode :%d description: %s \n" ,err_no, error);
return -1;
}
DOT;
while(12)
{
run = mapi_read_results(fd, fid);
if(*((int*)run->res)==0)
{
DOT;
while (12) {
run = mapi_read_results(fd, fid);
if(*((int*)run->res)==0) {
printf("File written.\n");
break;
}
else
{
else {
usleep(10);
}
}
......@@ -68,56 +65,57 @@ DOT;
fprintf(stderr,"Erorcode :%d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if ((fd = mapi_create_offline_flow("/tmp/MAPI_TESTSUITE_DUMMY_TRACE" , MFF_PCAP))<0){
fprintf(stderr, "Could not create flow using '%s'\n", argv[1]);
mapi_read_error( &err_no, error);
fprintf(stderr,"Erorcode :%d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if (!mapi_is_remote(fd)) {
if ((fd = mapi_create_offline_flow("/tmp/MAPI_TESTSUITE_DUMMY_TRACE" , MFF_PCAP))<0){
fprintf(stderr, "Could not create flow using '%s'\n", argv[1]);
mapi_read_error( &err_no, error);
fprintf(stderr,"Erorcode :%d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if((fid=mapi_apply_function(fd, "PKT_COUNTER"))<0){
fprintf(stderr, "Could not apply PKT_COUNTER to flow %d\n", fd);
mapi_read_error( &err_no, error);
fprintf(stderr,"Erorcode :%d description: %s \n" ,err_no, error);
return -1;
}
if((fid=mapi_apply_function(fd, "PKT_COUNTER"))<0){
fprintf(stderr, "Could not apply PKT_COUNTER to flow %d\n", fd);
mapi_read_error( &err_no, error);
fprintf(stderr,"Erorcode :%d description: %s \n" ,err_no, error);
return -1;
}
DOT;
if(mapi_connect(fd)<0){
fprintf(stderr, "Connecting to flow failed %d\n", fd);
mapi_read_error( &err_no, error);
fprintf(stderr,"Erorcode :%d description: %s \n" ,err_no, error);
return -1;
}
DOT;
do
{
sleep(1);
mapi_get_flow_info(fd,&info);
} while(info.status!=FLOW_FINISHED);
run = mapi_read_results(fd, fid);
if(*((int*)run->res)!=50){
fprintf(stderr,"\nWARNING: TO_FILE failed to log all the requested pkts\n");
}
else
printf("\nTO_FILE OK!!\n");
if(mapi_connect(fd)<0){
fprintf(stderr, "Connecting to flow failed %d\n", fd);
mapi_read_error( &err_no, error);
fprintf(stderr,"Erorcode :%d description: %s \n" ,err_no, error);
return -1;
}
DOT;
do
{
sleep(1);
mapi_get_flow_info(fd,&info);
} while(info.status!=FLOW_FINISHED);
run = mapi_read_results(fd, fid);
if(*((int*)run->res)!=50){
fprintf(stderr,"\nWARNING: TO_FILE failed to log all the requested pkts\n");
}
else
printf("\nTO_FILE OK!!\n");
/*
* Error checking starts
*/
DOT;
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;
/*
* Error checking starts
*/
DOT;
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;
}
DOT;
}
DOT;
if ((fd = mapi_create_flow(argv[1]))<0){
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,"Erorcode :%d description: %s \n" ,err_no, error);
......@@ -125,8 +123,6 @@ if ((fd = mapi_create_flow(argv[1]))<0){
}
DOT;
if((fid = mapi_apply_function(fd, "TO_FILE", 13242312, "/tmp/MAPI_TESTSUTE_ERROR_CASES", limit)) < 0){
mapi_read_error( &err_no, error);
printf("Testing error case1: Erorcode :%d description: %s \n" ,err_no, error);
......@@ -136,7 +132,7 @@ DOT;
}
}
DOT;
DOT;
if((fid = mapi_apply_function(fd, "TO_FILE", MFF_PCAP, NULL, limit))< 0){
mapi_read_error( &err_no, error);
printf("Testing error case2: Erorcode :%d description: %s \n" ,err_no, error);
......@@ -153,7 +149,7 @@ DOT;
fprintf(stderr,"Erorcode :%d description: %s \n" ,err_no, error);
return -1;
}
system("rm -f /tmp/MAPI_TESTSUITE_DUMMY_TRACE* /tmp/MAPI_TESTSUTE_ERROR_CASES*");
system("rm -f /tmp/MAPI_TESTSUITE_DUMMY_TRACE* /tmp/MAPI_TESTSUTE_ERROR_CASES*");
if (!flag) {
printf("\nTO_FILE Error Checking OK\n");
}
......@@ -162,6 +158,6 @@ DOT;
return -1;
}
return 0;
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