Commit 216204d8 authored by Arne Øslebø's avatar Arne Øslebø
Browse files

added SYNC function. Modified global function list

git-svn-id: file:///home/svn/mapi/trunk@793 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 9fd252f5
......@@ -62,11 +62,11 @@ int fhlp_check_software_funct(flist_t *flist, mapidflib_function_instance_t *fro
mapidflib_function_instance_t* fhlp_get_function_instance(global_function_list_t *gfl,int fd, int fid)
{
flist_t *f;
mapid_flow_info_t *f;
mapidflib_function_t *i;
f=flist_get(gfl->fflist,fd);
i=flist_get(f,fid);
i=flist_get(f->flist,fid);
if(!i)
......@@ -77,13 +77,13 @@ mapidflib_function_instance_t* fhlp_get_function_instance(global_function_list_t
mapidflib_function_instance_t* fhlp_get_function_instance_byname(global_function_list_t *gfl, int fd, const char *name)
{
flist_t *f = NULL;
mapid_flow_info_t *f = NULL;
mapidflib_function_t *i = NULL;
flist_node_t *node = NULL;
pthread_spin_lock(&gfl->lock);
f = flist_get(gfl->fflist,fd);
node=flist_head(f);
node=flist_head(f->flist);
while(node!=NULL) {
i=node->data;
if(strcmp(i->instance->def->name, name)==0) {
......
......@@ -76,13 +76,6 @@ typedef struct mapidflib_result {
unsigned long data_size; ///< Size of data that contains the result
} mapidflib_result_t;
/**
* \brief Enum showing if a MAPI function is initialized
*/
typedef enum { MAPIFUNC_UNINIT, ///< Enum value indicating that the function is uninitialized
MAPIFUNC_INIT ///< Enum value indicating that the function is initialized
} mapidflib_status_t;
/**
* \brief Enum used for deciding how global anonymization should be handled for a function
*/
......@@ -91,6 +84,14 @@ typedef enum { MAPIOPT_NONE, ///< Enum value indicating that no global optimizat
MAPIOPT_MANUAL ///< Enum value indicating that manual global optimization should be used. Function using this method should use the identical field in the mapiflib_flow_mod structure for global optimization
} mapidflib_optimize_t;
/**
* \brief Enum showing if a MAPI function is initialized
*/
typedef enum { MAPIFUNC_UNINIT, ///< Enum value indicating that the function is uninitialized
MAPIFUNC_INIT ///< Enum value indicating that the function is initialized
} mapidflib_status_t;
/**
* \brief Structure containing information related to the actual instance of a MAPI function
*/
......
......@@ -214,7 +214,7 @@ static void fix_funct_ref(global_function_list_t *gflist,mapidflib_function_t *i
//Loop through all flows
for(flow=flist_head(gflist->fflist);flow!=NULL;flow=flist_next(flow)) {
functions=(flist_t*)flist_data(flow);
functions=((mapid_flow_info_t*)flist_data(flow))->flist;
if(functions==NULL)
continue;
......@@ -249,7 +249,7 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
//global optimization
functions=flist_get(flow->hwinfo->gflist->fflist,flow->fd);
functions=((mapid_flow_info_t*)flist_get(flow->hwinfo->gflist->fflist,flow->fd))->flist;
if(functions!=NULL)
for(funct_node=flist_head(functions);funct_node!=NULL;funct_node=flist_next(funct_node)) {
funct=(mapidflib_function_t*)flist_data(funct_node);
......@@ -437,6 +437,11 @@ mapid_connect(mapidlib_instance_t *i,int fd)
#endif
flow->status = FLOW_ACTIVE;
//Update global function list
((mapid_flow_info_t*)flist_get(flow->hwinfo->gflist->fflist,flow->fd))->status=FLOW_ACTIVE;
time(&flow->start);
return 0;
......@@ -452,6 +457,7 @@ mapid_add_flow(mapidlib_instance_t *i,
//info = adapter specific info
{
struct mapidlibflow* fl;
mapid_flow_info_t *flow=malloc(sizeof(mapid_flow_info_t));
fl=malloc(sizeof (struct mapidlibflow));
......@@ -470,7 +476,10 @@ mapid_add_flow(mapidlib_instance_t *i,
fl->functionlist=malloc(sizeof(flist_t));
flist_init(fl->functionlist);
pthread_spin_lock(&hwinfo->gflist->lock);
flist_append(hwinfo->gflist->fflist,fd,fl->functionlist);
flow->status=FLOW_INIT;
flow->flist=fl->functionlist;
flist_append(hwinfo->gflist->fflist,fd,flow);
pthread_spin_unlock(&hwinfo->gflist->lock);
fl->procfunctionlist=malloc(sizeof(flist_t));
......@@ -588,6 +597,9 @@ mapid_close_flow(mapidlib_instance_t *i,int fd)
f->status=FLOW_CLOSED;
//Update global function list
((mapid_flow_info_t*)flist_get(f->hwinfo->gflist->fflist,f->fd))->status=FLOW_CLOSED;
time(&f->end);
......@@ -631,7 +643,7 @@ mapid_read_results(mapidlib_instance_t *i,
struct mapidlibflow *flow=flist_get(i->flowlist,fd);
#endif
functs=flist_get(flow->hwinfo->gflist->fflist,fd);
functs=((mapid_flow_info_t*)flist_get(flow->hwinfo->gflist->fflist,fd))->flist;
if(functs==NULL)
return MDLIB_INVALID_FLID;
......@@ -689,7 +701,7 @@ static mapidflib_function_instance_t *find_identical_function(MAPI_UNUSED mapidl
mapidflib_function_t *funct,*funct2;
//Get flow functions already applied
flist_t *functs=flist_get(gflist->fflist,fd);
flist_t *functs=((mapid_flow_info_t*)flist_get(gflist->fflist,fd))->flist;
#ifdef WITH_PRIORITIES
mapidlibflow_t *iflow;
......@@ -960,6 +972,9 @@ int mapid_finished(mapidlib_instance_t *i)
{
flow=flist_data(n);
flow->status=FLOW_FINISHED;
//Update global function list
((mapid_flow_info_t*)flist_get(flow->hwinfo->gflist->fflist,flow->fd))->status=FLOW_FINISHED;
n = flist_next(n);
}
}
......@@ -969,6 +984,9 @@ int mapid_finished(mapidlib_instance_t *i)
{
flow=flist_data(n);
flow->status=FLOW_FINISHED;
//Update global function list
((mapid_flow_info_t*)flist_get(flow->hwinfo->gflist->fflist,flow->fd))->status=FLOW_FINISHED;
n = flist_next(n);
}
#endif
......
......@@ -13,6 +13,12 @@
#define FUNCTION_SEM_PROJECT_ID 'S'
#define FUNCTION_SEM_PERMS 0666 //Not secure. Should find better method
typedef struct mapid_flow_info {
enum mapi_flow_status status;
flist_t *flist; //List of all functions applied to the flow
} mapid_flow_info_t;
typedef struct mapid_funct_info {
int fid;
char* name; //Name of function
......
......@@ -30,6 +30,7 @@ sample.c \
startstop.c \
stats.c \
strsearch.c \
sync.c \
threshold.c threshold.h \
tobuffer_all.c \
to_tcpdump.c
......
......@@ -67,8 +67,8 @@ static int res2file_instance(mapidflib_function_instance_t *instance,
return(MFUNCT_INVALID_ARGUMENT_4);
else
{
struct stat buf;
if(fstat(file, &buf) == -1)
struct stat sbuf;
if(fstat(file, &sbuf) == -1)
{
fprintf(stderr, "Cannot fstat() file descriptor %d.\n", file);
return(MFUNCT_INVALID_ARGUMENT_4);
......
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
//Wed Feb 22 14:21:33 2006
//Fri Jul 28 14:51:18 2006
//This file was created automatically by createlib.pl
#include <stdio.h>
......@@ -13,15 +10,15 @@
__attribute__ ((constructor)) void init ();
__attribute__ ((destructor)) void fini ();
mapidflib_functionlist_t functions[18];
mapidflib_functionlist_t functions[19];
extern mapidflib_function_def_t * hash_get_funct_info();
extern mapidflib_function_def_t * binop_get_funct_info();
extern mapidflib_function_def_t * bpf_get_funct_info();
extern mapidflib_function_def_t * bucket_get_funct_info();
extern mapidflib_function_def_t * bytec_get_funct_info();
extern mapidflib_function_def_t * dist_get_funct_info();
extern mapidflib_function_def_t * gap_get_funct_info();
extern mapidflib_function_def_t * hash_get_funct_info();
extern mapidflib_function_def_t * hashsamp_get_funct_info();
extern mapidflib_function_def_t * pktc_get_funct_info();
extern mapidflib_function_def_t * pktinfo_get_funct_info();
......@@ -30,37 +27,38 @@ extern mapidflib_function_def_t * sample_get_funct_info();
extern mapidflib_function_def_t * startstop_get_funct_info();
extern mapidflib_function_def_t * stats_get_funct_info();
extern mapidflib_function_def_t * strsearch_get_funct_info();
extern mapidflib_function_def_t * sync_get_funct_info();
extern mapidflib_function_def_t * threshold_get_funct_info();
extern mapidflib_function_def_t * to_tcpdump_get_funct_info();
extern mapidflib_function_def_t * toba_get_funct_info();
mapidflib_functionlist_t* mapidflib_get_function_list()
{
functions[0].def=binop_get_funct_info();
functions[0].def=hash_get_funct_info();
functions[0].def->libname=libname;
functions[0].next=&functions[1];
functions[1].def=bpf_get_funct_info();
functions[1].def=binop_get_funct_info();
functions[1].def->libname=libname;
functions[1].next=&functions[2];
functions[2].def=bucket_get_funct_info();
functions[2].def=bpf_get_funct_info();
functions[2].def->libname=libname;
functions[2].next=&functions[3];
functions[3].def=bytec_get_funct_info();
functions[3].def=bucket_get_funct_info();
functions[3].def->libname=libname;
functions[3].next=&functions[4];
functions[4].def=dist_get_funct_info();
functions[4].def=bytec_get_funct_info();
functions[4].def->libname=libname;
functions[4].next=&functions[5];
functions[5].def=gap_get_funct_info();
functions[5].def=dist_get_funct_info();
functions[5].def->libname=libname;
functions[5].next=&functions[6];
functions[6].def=hash_get_funct_info();
functions[6].def=gap_get_funct_info();
functions[6].def->libname=libname;
functions[6].next=&functions[7];
......@@ -96,18 +94,21 @@ mapidflib_functionlist_t* mapidflib_get_function_list()
functions[14].def->libname=libname;
functions[14].next=&functions[15];
functions[15].def=threshold_get_funct_info();
functions[15].def=sync_get_funct_info();
functions[15].def->libname=libname;
functions[15].next=&functions[16];
functions[16].def=to_tcpdump_get_funct_info();
functions[16].def=threshold_get_funct_info();
functions[16].def->libname=libname;
functions[16].next=&functions[17];
functions[17].def=toba_get_funct_info();
functions[17].def=to_tcpdump_get_funct_info();
functions[17].def->libname=libname;
functions[17].next=NULL;
functions[17].next=&functions[18];
functions[18].def=toba_get_funct_info();
functions[18].def->libname=libname;
functions[18].next=NULL;
return &functions[0];
}
......
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <sys/shm.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "mapidflib.h"
#include "mapidlib.h"
#include "mapidevices.h"
#include "mapi_errors.h"
#include "mapid.h"
#include "fhelp.h"
#include "debug.h"
typedef struct sync_inst {
mapid_flow_info_t **flow_info;
int numfuncts;
} sync_inst_t;
static int sync_instance(mapidflib_function_instance_t *instance,
MAPI_UNUSED int flow_descr,
MAPI_UNUSED mapidflib_flow_mod_t *flow_mod)
{
char *fids,*s;
int fd;
char buf[DATA_SIZE],*cfids;
char *t,*t2;
mapiFunctArg* fargs=instance->args;
if(!(fids = getargstr(&fargs)))
return(MFUNCT_INVALID_ARGUMENT_2);
//Loop through fids amd types and verify
strncpy(buf,fids,DATA_SIZE);
cfids=buf;
while((s=strchr(cfids,','))!=NULL) {
*s='\0';
if((t2=strchr(t,','))==NULL)
return MFUNCT_INVALID_ARGUMENT_1;
*t2='\0';
sscanf(cfids,"%d",&fd);
if(flist_get(instance->hwinfo->gflist->fflist,fd)==NULL)
return MFUNCT_INVALID_ARGUMENT_2;
cfids=s+1;
}
sscanf(fids,"%d",&fd);
if(flist_get(instance->hwinfo->gflist->fflist,fd)==NULL)
return MFUNCT_INVALID_ARGUMENT_2;
return 0;
};
static int sync_init(mapidflib_function_instance_t *instance,
MAPI_UNUSED int flow_descr)
{
sync_inst_t *i;
char *fids,*s,*f;
int fd,c;
char buf[DATA_SIZE],*cfids;
mapiFunctArg* fargs=instance->args;
i=instance->internal_data=malloc(sizeof(sync_inst_t));
fids=getargstr(&fargs);
//Count number of fids
c=0;
f=fids;
while((s=strchr(f,','))!=NULL) {
f=s+1;
c++;
}
c++;
i->flow_info=malloc(sizeof(mapid_flow_info_t*)*c);
i->numfuncts=c;
//Loop through fids and verify
strncpy(buf,fids,DATA_SIZE);
cfids=buf;
c=0;
while((s=strchr(cfids,','))!=NULL) {
*s='\0';
sscanf(cfids,"%d",&fd);
i->flow_info[c]=flist_get(instance->hwinfo->gflist->fflist,fd);
if(i->flow_info[c]==NULL)
return MFUNCT_INVALID_ARGUMENT_2;
c++;
cfids=s+1;
}
sscanf(cfids,"%d",&fd);
i->flow_info[c]=flist_get(instance->hwinfo->gflist->fflist,fd);
return 0;
}
static int sync_process_true(MAPI_UNUSED mapidflib_function_instance_t *instance,
MAPI_UNUSED unsigned char* dev_pkt,
MAPI_UNUSED unsigned char* link_pkt,
MAPI_UNUSED mapid_pkthdr_t* pkt_head)
{
return 1;
}
static int sync_process(mapidflib_function_instance_t *instance,
MAPI_UNUSED unsigned char* dev_pkt,
MAPI_UNUSED unsigned char* link_pkt,
MAPI_UNUSED mapid_pkthdr_t* pkt_head)
{
int c;
sync_inst_t *i=instance->internal_data;
for(c=0;c<i->numfuncts;c++)
if(i->flow_info[c]->status==FLOW_INIT)
return 0;
instance->def->process=sync_process_true;
return 1;
}
static int sync_cleanup(mapidflib_function_instance_t *instance)
{
sync_inst_t *i=instance->internal_data;
free(i->flow_info);
free(i);
return 0;
}
static mapidflib_function_def_t finfo={
"", //libname
"SYNC", //name
"Syncronizes multiple flows on the same device", //descr
"s", //argdescr
MAPI_DEVICE_ALL, //devoid
MAPIRES_NONE, //Method for returning results
0, //shm size
0, //modifies_pkts
0, //filters packets
MAPIOPT_NONE, //Optimization
sync_instance, //instance
sync_init, //init
sync_process, //process
NULL, //get_result,
NULL, //reset
sync_cleanup, //cleanup
NULL, //client_init
NULL, //client_read_result
NULL //client_cleanup
};
mapidflib_function_def_t* sync_get_funct_info();
mapidflib_function_def_t* sync_get_funct_info() {
return &finfo;
};
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