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

added global optimization and a global flow and function structure. COOKING function does not work

git-svn-id: file:///home/svn/mapi/trunk@326 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent af35579e
...@@ -2,16 +2,19 @@ include Makefile.in ...@@ -2,16 +2,19 @@ include Makefile.in
INCLUDE=-I. -I$(DAG_INCLUDE_DIR) INCLUDE=-I. -I$(DAG_INCLUDE_DIR)
CFLAGS=-g -O2 $(C_WARNINGS) $(C_FEATURES) #CFLAGS=-g -O2 $(C_WARNINGS) $(C_FEATURES)
CFLAGS=-g $(C_WARNINGS) $(C_FEATURES)
TARGETS= mapi.so mapid build_tests build_dimapi_tests build_agent mapinicdrv.so mapidstdflib.so tracklib.so flist.o list.o parseconf.o priorities.o $(ADMCTRLCL_TARGETS)
TARGETS= mapi.so mapid build_tests build_dimapi_tests build_agent mapinicdrv.so mapinicdrv_buf.so mapidstdflib.so tracklib.so flist.o list.o parseconf.o priorities.o $(ADMCTRLCL_TARGETS)
.PHONY: build_stdlib build_anonlib build_tracklib build_combo6lib build_daglib build_ipfixlib build_etherlib .PHONY: build_stdlib build_anonlib build_tracklib build_combo6lib build_daglib build_ipfixlib build_etherlib
DAG= DAG=
ifeq ($(WITH_DAG),1) ifeq ($(WITH_DAG),1)
DAG=mapidagdrv.so dagflib.so DAG=mapidagdrv.so dagflib.so
DAGAPI=$(DAG_API_DIR)/dagopts.o $(DAG_API_DIR)/dagapi.o DAGAPI=-ldag
endif endif
COMBOSIX= COMBOSIX=
...@@ -111,8 +114,8 @@ mapinicdrv.o: mapinicdrv.c mapi.h mapidrv.h mapidlib.h mapid.h mapi_errors.h ...@@ -111,8 +114,8 @@ mapinicdrv.o: mapinicdrv.c mapi.h mapidrv.h mapidlib.h mapid.h mapi_errors.h
mapinicdrv.so: mapinicdrv.o mapidlib.o flist.o mapiipc.o mstring.o mapilibhandler.o parseconf.o cbuf.o priorities.o mapinicdrv.so: mapinicdrv.o mapidlib.o flist.o mapiipc.o mstring.o mapilibhandler.o parseconf.o cbuf.o priorities.o
$(CC) $(CFLAGS) -shared -o $@ $^ -lpcap -lfl -lrt $(CC) $(CFLAGS) -shared -o $@ $^ -lpcap -lfl -lrt
mapinicdrv_buf.o: mapinicdrv_buf.c mapi.h mapidrv.h mapidlib.h mapid.h mapi_errors.h #mapinicdrv_buf.o: mapinicdrv_buf.c mapi.h mapidrv.h mapidlib.h mapid.h mapi_errors.h
$(CC) $(CFLAGS) -fPIC -c $< # $(CC) $(CFLAGS) -fPIC -c $<
mapinicdrv_buf.so: mapinicdrv_buf.o mapidlib.o flist.o mapiipc.o mstring.o mapilibhandler.o parseconf.o cbuf.o priorities.o mapinicdrv_buf.so: mapinicdrv_buf.o mapidlib.o flist.o mapiipc.o mstring.o mapilibhandler.o parseconf.o cbuf.o priorities.o
$(CC) $(CFLAGS) -shared -o $@ $^ -lpcap -lfl -lrt $(CC) $(CFLAGS) -shared -o $@ $^ -lpcap -lfl -lrt
......
...@@ -10,28 +10,27 @@ LIB_DIR=-L/usr/local/lib ...@@ -10,28 +10,27 @@ LIB_DIR=-L/usr/local/lib
DEBUG=1 DEBUG=1
#DAG cards #DAG cards
WITH_DAG=0 WITH_DAG=1
#COMBO6 cards #COMBO6 cards
WITH_COMBO6=0 WITH_COMBO6=0
#Distributed MAPI functionality #Distributed MAPI functionality
WITH_DIMAPI=1 WITH_DIMAPI=0
#MAPI function statistics #MAPI function statistics
#With this pkt counters for each function is enabled #With this pkt counters for each function is enabled
WITH_FUNCT_STATS=0 WITH_FUNCT_STATS=1
#Support for flow priorities #Support for flow priorities
WITH_PRIORITIES=0 WITH_PRIORITIES=1
PRIORITIES=3 PRIORITIES=3
#Support for functions that modifies packets #Support for functions that modifies packets
WITH_MODIFY_PKTS=1 WITH_MODIFY_PKTS=1
#Support for anonymization #Support for anonymization
WITH_ANONYMIZATION=1 WITH_ANONYMIZATION=0
#Ipfix flow record generation #Ipfix flow record generation
WITH_IPFIX=0 WITH_IPFIX=0
......
...@@ -278,7 +278,7 @@ int can_field_be_applied_to_function(int anonymization_function,int field) { ...@@ -278,7 +278,7 @@ int can_field_be_applied_to_function(int anonymization_function,int field) {
static int anonymize_instance(mapidflib_function_instance_t *instance, static int anonymize_instance(mapidflib_function_instance_t *instance,
flist_t *flow_flist, flist_t *flow_flist,
mapidflib_flow_mod_t *flow_mod,function_manipulation_t* manip) mapidflib_flow_mod_t *flow_mod)
{ {
mapiFunctArg* args=instance->args; mapiFunctArg* args=instance->args;
int protocol, field_description, anonymization_function; int protocol, field_description, anonymization_function;
...@@ -328,24 +328,10 @@ static int anonymize_instance(mapidflib_function_instance_t *instance, ...@@ -328,24 +328,10 @@ static int anonymize_instance(mapidflib_function_instance_t *instance,
return MFUNCT_INVALID_ARGUMENT_4; return MFUNCT_INVALID_ARGUMENT_4;
} }
flist_node_t *n;
struct mapidlibflow *flow=NULL; struct mapidlibflow *flow=NULL;
mapidlib_instance_t *i; mapidlib_instance_t *i;
i = flow_mod->mi; i = flow_mod->mi;
n = flist_head(i->flowlist);
while(n)
{
flow = flist_data(n);
if(flow->fd == instance->fd)
{
break;
}
n = flist_next(n);
}
data=(struct anonymize_data *)malloc(sizeof(struct anonymize_data)); data=(struct anonymize_data *)malloc(sizeof(struct anonymize_data));
data->protocol=protocol; data->protocol=protocol;
...@@ -1020,6 +1006,7 @@ static mapidflib_function_def_t finfo={ ...@@ -1020,6 +1006,7 @@ static mapidflib_function_def_t finfo={
MAPIRES_NONE, //Method for returning results MAPIRES_NONE, //Method for returning results
0, //shm size 0, //shm size
0, //modifies_pkts 0, //modifies_pkts
MAPIFUNC_OPT_AUTO, //Optimization
anonymize_instance, //instance anonymize_instance, //instance
anonymize_init, //init anonymize_init, //init
anonymize_process, //process anonymize_process, //process
......
...@@ -58,6 +58,7 @@ static mapidflib_function_def_t anonprintfinfo={ ...@@ -58,6 +58,7 @@ static mapidflib_function_def_t anonprintfinfo={
MAPIRES_NONE, //Method for returning results MAPIRES_NONE, //Method for returning results
0, //shm size 0, //shm size
0, //modifies_pkts 0, //modifies_pkts
MAPIFUNC_OPT_AUTO, //Optimization
anonprint_instance, //instance anonprint_instance, //instance
anonprint_init, //init anonprint_init, //init
anonprint_process, //process anonprint_process, //process
......
...@@ -187,7 +187,7 @@ static int uncook_init(mapidflib_function_instance_t *instance, flist_t *flist) ...@@ -187,7 +187,7 @@ static int uncook_init(mapidflib_function_instance_t *instance, flist_t *flist)
} }
static int uncook_instance(mapidflib_function_instance_t *instance, flist_t *flow_flist, mapidflib_flow_mod_t *flow_mod,function_manipulation_t* manip) { static int uncook_instance(mapidflib_function_instance_t *instance, flist_t *flow_flist, mapidflib_flow_mod_t *flow_mod) {
flist_node_t *n; flist_node_t *n;
struct mapidlibflow *flow=NULL; struct mapidlibflow *flow=NULL;
mapidlib_instance_t *i; mapidlib_instance_t *i;
...@@ -196,18 +196,6 @@ static int uncook_instance(mapidflib_function_instance_t *instance, flist_t *flo ...@@ -196,18 +196,6 @@ static int uncook_instance(mapidflib_function_instance_t *instance, flist_t *flo
i = flow_mod->mi; i = flow_mod->mi;
n = flist_head(i->flowlist); n = flist_head(i->flowlist);
while(n)
{
flow = flist_data(n);
if(flow->fd == instance->fd)
{
break;
}
n = flist_next(n);
}
data=(struct uncook_data *)malloc(sizeof(struct uncook_data)); data=(struct uncook_data *)malloc(sizeof(struct uncook_data));
data->flow=flow; data->flow=flow;
instance->internal_data=(void *)data; instance->internal_data=(void *)data;
...@@ -248,6 +236,7 @@ static mapidflib_function_def_t uncookfinfo={ ...@@ -248,6 +236,7 @@ static mapidflib_function_def_t uncookfinfo={
MAPIRES_NONE, //Method for returning results MAPIRES_NONE, //Method for returning results
0, //shm size 0, //shm size
0, //modifies_pkts 0, //modifies_pkts
MAPIFUNC_OPT_AUTO, //Optimization
uncook_instance, //instance uncook_instance, //instance
uncook_init, //init uncook_init, //init
uncook_process, //process uncook_process, //process
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include <sys/wait.h> #include <sys/wait.h>
#include "../../mapi.h" #include "../../mapi.h"
#include "../../mapid.h"
// usefull vars // usefull vars
......
...@@ -15,8 +15,8 @@ typedef struct interface_instance_type { ...@@ -15,8 +15,8 @@ typedef struct interface_instance_type {
} interface_instance_t; } interface_instance_t;
static int interface_instance(mapidflib_function_instance_t *instance, static int interface_instance(mapidflib_function_instance_t *instance,
MAPI_UNUSED flist_t *flist, MAPI_UNUSED int fd,
MAPI_UNUSED mapidflib_flow_mod_t *flow_mod, MAPI_UNUSED function_manipulation_t* manip) MAPI_UNUSED mapidflib_flow_mod_t *flow_mod)
{ {
mapiFunctArg* a=instance->args; mapiFunctArg* a=instance->args;
int ifindex = getargint(&a); int ifindex = getargint(&a);
...@@ -28,7 +28,7 @@ static int interface_instance(mapidflib_function_instance_t *instance, ...@@ -28,7 +28,7 @@ static int interface_instance(mapidflib_function_instance_t *instance,
} }
static int interface_init(mapidflib_function_instance_t *instance, static int interface_init(mapidflib_function_instance_t *instance,
MAPI_UNUSED flist_t *flist) MAPI_UNUSED int fd)
//Initializes the function //Initializes the function
{ {
interface_instance_t *i=malloc(sizeof(interface_instance_t)); interface_instance_t *i=malloc(sizeof(interface_instance_t));
...@@ -63,6 +63,8 @@ static mapidflib_function_def_t finfo={ ...@@ -63,6 +63,8 @@ static mapidflib_function_def_t finfo={
MAPIRES_NONE, //Method for returning results MAPIRES_NONE, //Method for returning results
0, //shm size 0, //shm size
0, //modifies_pkts 0, //modifies_pkts
1, //filters packets
MAPIOPT_AUTO,
interface_instance, //instance interface_instance, //instance
interface_init, //init interface_init, //init
interface_process, //process interface_process, //process
......
...@@ -24,8 +24,8 @@ typedef struct erf_instance { ...@@ -24,8 +24,8 @@ typedef struct erf_instance {
} erf_instance_t; } erf_instance_t;
static int to_erf_instance(mapidflib_function_instance_t *instance, static int to_erf_instance(mapidflib_function_instance_t *instance,
MAPI_UNUSED flist_t *flist, MAPI_UNUSED int fd,
MAPI_UNUSED mapidflib_flow_mod_t *flow_mod, MAPI_UNUSED function_manipulation_t* manip) MAPI_UNUSED mapidflib_flow_mod_t *flow_mod)
{ {
mapiFunctArg* a=instance->args; mapiFunctArg* a=instance->args;
int type = getargint(&a); int type = getargint(&a);
...@@ -37,7 +37,7 @@ static int to_erf_instance(mapidflib_function_instance_t *instance, ...@@ -37,7 +37,7 @@ static int to_erf_instance(mapidflib_function_instance_t *instance,
} }
static int to_erf_init(mapidflib_function_instance_t *instance, static int to_erf_init(mapidflib_function_instance_t *instance,
MAPI_UNUSED flist_t *flist) MAPI_UNUSED int fd)
//Initializes the function //Initializes the function
{ {
int *res; int *res;
...@@ -100,6 +100,8 @@ static mapidflib_function_def_t finfo={ ...@@ -100,6 +100,8 @@ static mapidflib_function_def_t finfo={
MAPIRES_SHM, MAPIRES_SHM,
sizeof(int), //shm size sizeof(int), //shm size
0, //modifies_pkts 0, //modifies_pkts
0, //filters packets
MAPIOPT_AUTO,
to_erf_instance, to_erf_instance,
to_erf_init, to_erf_init,
to_erf_process, to_erf_process,
......
...@@ -8,35 +8,27 @@ ...@@ -8,35 +8,27 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/sem.h> #include <sys/sem.h>
#include <fcntl.h> #include <fcntl.h>
#include "fhelp.h" #include "fhelp.h"
#include "mapid.h" #include "mapid.h"
#include "mapidevices.h" #include "mapidevices.h"
#include "debug.h" #include "debug.h"
#include "mapidflib.h"
#define TIME_M 257698037760ULL #define TIME_M 257698037760ULL
#define TIME_S 4294967296ULL #define TIME_S 4294967296ULL
#define TIME_MS 4294967 #define TIME_MS 4294967
#define TIME_US 4294 #define TIME_US 4294
function_manipulation_t* manipulation;
void fhlp_init_manipulation(function_manipulation_t* manip)
{
manipulation = manip;
}
int fhlp_check_funct(flist_t *flist, char *fname) int fhlp_check_funct(flist_t *flist, char *fname)
//return fid of first function with the name fname //return fid of first function with the name fname
{ {
flist_node_t *n; flist_node_t *n;
mapidflib_function_instance_t *funct; mapidflib_function_t *funct;
n = flist_head(flist); n = flist_head(flist);
while(n) { while(n) {
funct=flist_data(n); funct=flist_data(n);
if(strcmp(funct->def->name,fname)==0) if(strcmp(funct->instance->def->name,fname)==0)
return funct->fid; return funct->fid;
n=flist_next(n); n=flist_next(n);
} }
...@@ -64,9 +56,17 @@ int fhlp_check_software_funct(flist_t *flist, mapidflib_function_instance_t *fro ...@@ -64,9 +56,17 @@ int fhlp_check_software_funct(flist_t *flist, mapidflib_function_instance_t *fro
return 0; return 0;
} }
void* fhlp_get_function_instance(int fd, int fid, int pid) mapidflib_function_instance_t* fhlp_get_function_instance(global_function_list_t *gfl,int fd, int fid)
{ {
return manipulation->get_function(fd,fid,pid); flist_t *f;
mapidflib_function_t *i;
pthread_spin_lock(&gfl->lock);
f=flist_get(gfl->fflist,fd);
i=flist_get(f,fid);
pthread_spin_unlock(&gfl->lock);
return i->instance;
} }
int fhlp_create_semaphore(fhlp_sem_t *sem, int num) int fhlp_create_semaphore(fhlp_sem_t *sem, int num)
...@@ -83,7 +83,7 @@ int fhlp_create_semaphore(fhlp_sem_t *sem, int num) ...@@ -83,7 +83,7 @@ int fhlp_create_semaphore(fhlp_sem_t *sem, int num)
argument.val = 0; argument.val = 0;
strncpy(pathname,FUNCTION_SEM_TEMPLATE,MAPI_STR_LENGTH); strncpy(pathname,FUNCTION_SEM_TEMPLATE,MAPI_STR_LENGTH);
if(mkstemp(pathname)==NULL) if(mkstemp(pathname)==-1)
return MDLIB_SEM_ERR; return MDLIB_SEM_ERR;
umask(017); umask(017);
...@@ -137,24 +137,6 @@ mapidflib_result_t* fhlp_get_res(mapidflib_function_instance_t *instance) ...@@ -137,24 +137,6 @@ mapidflib_result_t* fhlp_get_res(mapidflib_function_instance_t *instance)
} }
} }
mapidflib_result_t* fhlp_new_get_res(int fd, int fid, int pid)
{
mapidflib_result_t **res = NULL;
mapidflib_function_instance_t *instance = manipulation->get_function(fd, fid, pid);
if(instance==NULL)
return NULL;
if(instance->def->get_result==NULL)
return &instance->result;
else {
instance->def->get_result(instance,res);
return *res;
}
}
unsigned long long fhlp_str2ull(char *str) unsigned long long fhlp_str2ull(char *str)
//Converts a string to an unsigned long long value //Converts a string to an unsigned long long value
{ {
...@@ -180,3 +162,4 @@ int fhlp_ull2sec(unsigned long long l, char *str, int length) ...@@ -180,3 +162,4 @@ int fhlp_ull2sec(unsigned long long l, char *str, int length)
return snprintf(str,length,"%f",sec); return snprintf(str,length,"%f",sec);
} }
...@@ -18,15 +18,12 @@ typedef struct fhlp_sem { ...@@ -18,15 +18,12 @@ typedef struct fhlp_sem {
char fname[MAPI_STR_LENGTH]; char fname[MAPI_STR_LENGTH];
} fhlp_sem_t; } fhlp_sem_t;
void fhelp_init_manipulation(function_manipulation_t*);
int fhlp_check_software_funct(flist_t *flist,mapidflib_function_instance_t *from); int fhlp_check_software_funct(flist_t *flist,mapidflib_function_instance_t *from);
int fhlp_check_funct(flist_t *flist, char *fname); int fhlp_check_funct(flist_t *flist, char *fname);
int fhlp_create_semaphore(fhlp_sem_t *sem,int num); int fhlp_create_semaphore(fhlp_sem_t *sem,int num);
void fhlp_free_semaphore(fhlp_sem_t *sem); void fhlp_free_semaphore(fhlp_sem_t *sem);
extern inline mapidflib_result_t* fhlp_get_res(mapidflib_function_instance_t *instance); extern inline mapidflib_result_t* fhlp_get_res(mapidflib_function_instance_t *instance);
void* fhlp_get_function_instance(int fd, int fid, int pid); mapidflib_function_instance_t* fhlp_get_function_instance(global_function_list_t *glf,int fd, int fid);
void fhlp_init_manipulation(function_manipulation_t* manip);
mapidflib_result_t* fhlp_new_get_res(int fd, int fid, int pid);
//Convert a string to an unsigned long long value //Convert a string to an unsigned long long value
unsigned long long fhlp_str2ull(char *str); unsigned long long fhlp_str2ull(char *str);
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
Based on slist in adm_ctrl Based on slist in adm_ctrl
*/ */
#include <pthread.h>
#include "stdlib.h" #include "stdlib.h"
#include "flist.h" #include "flist.h"
...@@ -24,14 +23,13 @@ flist_append(flist_t *list,int id,void *data) ...@@ -24,14 +23,13 @@ flist_append(flist_t *list,int id,void *data)
node->data = data; node->data = data;
node->next = NULL; node->next = NULL;
pthread_mutex_lock(&list->lock);
if ( flist_head(list) == NULL ) if ( flist_head(list) == NULL )
flist_head(list) = node; flist_head(list) = node;
else else
flist_next(flist_tail(list)) = node; flist_next(flist_tail(list)) = node;
flist_tail(list) = node; flist_tail(list) = node;
++flist_size(list); ++flist_size(list);
pthread_mutex_unlock(&list->lock);
return 0; return 0;
} }
...@@ -49,34 +47,38 @@ int flist_insert_before(flist_t *list, int before, int id, void *data) ...@@ -49,34 +47,38 @@ int flist_insert_before(flist_t *list, int before, int id, void *data)
//Find before node //Find before node
pthread_mutex_lock(&list->lock);
node=flist_head(list); node=flist_head(list);
if (node == NULL) {
flist_head(list) = newnode; if ( node == NULL )
flist_tail(list) = newnode; {
} else { flist_append(list,id,data);
while(node!=NULL) { free(newnode);
if(node->id!=before) { }
prev=node; else
node=flist_next(node); {
} else while(node!=NULL)
break; {
if(node->id!=before)
{
prev=node;
node=flist_next(node);
}
else
break;
} }
if(prev==NULL) { if(prev==NULL) {
newnode->next = flist_head(list); free(newnode);
flist_head(list) = newnode; flist_prepend(list,id,data);
if (flist_tail(list)==NULL) }
flist_tail(list) = newnode; else {
} else {
prev->next=newnode; prev->next=newnode;
newnode->next=node; newnode->next=node;
if(node==NULL) if(node==NULL)
flist_tail(list)=newnode; flist_tail(list)=newnode;
++flist_size(list);
} }
} }
++flist_size(list);
pthread_mutex_unlock(&list->lock);
return 0; return 0;
} }
...@@ -96,15 +98,12 @@ flist_prepend(flist_t *list,int id,void *data) ...@@ -96,15 +98,12 @@ flist_prepend(flist_t *list,int id,void *data)
node->id=id; node->id=id;
flist_data(node) = data; flist_data(node) = data;
pthread_mutex_lock(&list->lock);
flist_next(node) = flist_head(list); flist_next(node) = flist_head(list);
flist_head(list) = node; flist_head(list) = node;
if ( flist_tail(list) == NULL ) if ( flist_tail(list) == NULL )
flist_tail(list) = node; flist_tail(list) = node;
++flist_size(list); ++flist_size(list);
pthread_mutex_unlock(&list->lock);
return 0; return 0;
} }
...@@ -119,17 +118,14 @@ flist_pop_first(flist_t *list) ...@@ -119,17 +118,14 @@ flist_pop_first(flist_t *list)
void *d; void *d;
flist_node_t *node; flist_node_t *node;
pthread_mutex_lock(&list->lock); if ( flist_head(list) == NULL )
if ( flist_head(list) == NULL ) {
pthread_mutex_unlock(&list->lock);
return NULL; return NULL;
}
d = flist_data((node = flist_head(list))); d = flist_data((node = flist_head(list)));
flist_head(list) = flist_next(node); flist_head(list) = flist_next(node);
free(node); free(node);
if ( --flist_size(list) == 0 ) if ( --flist_size(list) == 0 )
flist_tail(list) = NULL;