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
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
DAG=
ifeq ($(WITH_DAG),1)
DAG=mapidagdrv.so dagflib.so
DAGAPI=$(DAG_API_DIR)/dagopts.o $(DAG_API_DIR)/dagapi.o
DAGAPI=-ldag
endif
COMBOSIX=
......@@ -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
$(CC) $(CFLAGS) -shared -o $@ $^ -lpcap -lfl -lrt
mapinicdrv_buf.o: mapinicdrv_buf.c mapi.h mapidrv.h mapidlib.h mapid.h mapi_errors.h
$(CC) $(CFLAGS) -fPIC -c $<
#mapinicdrv_buf.o: mapinicdrv_buf.c mapi.h mapidrv.h mapidlib.h mapid.h mapi_errors.h
# $(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
$(CC) $(CFLAGS) -shared -o $@ $^ -lpcap -lfl -lrt
......
......@@ -10,28 +10,27 @@ LIB_DIR=-L/usr/local/lib
DEBUG=1
#DAG cards
WITH_DAG=0
WITH_DAG=1
#COMBO6 cards
WITH_COMBO6=0
#Distributed MAPI functionality
WITH_DIMAPI=1
WITH_DIMAPI=0
#MAPI function statistics
#With this pkt counters for each function is enabled
WITH_FUNCT_STATS=0
WITH_FUNCT_STATS=1
#Support for flow priorities
WITH_PRIORITIES=0
WITH_PRIORITIES=1
PRIORITIES=3
#Support for functions that modifies packets
WITH_MODIFY_PKTS=1
#Support for anonymization
WITH_ANONYMIZATION=1
WITH_ANONYMIZATION=0
#Ipfix flow record generation
WITH_IPFIX=0
......
......@@ -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,
flist_t *flow_flist,
mapidflib_flow_mod_t *flow_mod,function_manipulation_t* manip)
mapidflib_flow_mod_t *flow_mod)
{
mapiFunctArg* args=instance->args;
int protocol, field_description, anonymization_function;
......@@ -328,24 +328,10 @@ static int anonymize_instance(mapidflib_function_instance_t *instance,
return MFUNCT_INVALID_ARGUMENT_4;
}
flist_node_t *n;
struct mapidlibflow *flow=NULL;
mapidlib_instance_t *i;
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->protocol=protocol;
......@@ -1020,6 +1006,7 @@ static mapidflib_function_def_t finfo={
MAPIRES_NONE, //Method for returning results
0, //shm size
0, //modifies_pkts
MAPIFUNC_OPT_AUTO, //Optimization
anonymize_instance, //instance
anonymize_init, //init
anonymize_process, //process
......
......@@ -58,6 +58,7 @@ static mapidflib_function_def_t anonprintfinfo={
MAPIRES_NONE, //Method for returning results
0, //shm size
0, //modifies_pkts
MAPIFUNC_OPT_AUTO, //Optimization
anonprint_instance, //instance
anonprint_init, //init
anonprint_process, //process
......
......@@ -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;
struct mapidlibflow *flow=NULL;
mapidlib_instance_t *i;
......@@ -196,18 +196,6 @@ static int uncook_instance(mapidflib_function_instance_t *instance, flist_t *flo
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 uncook_data *)malloc(sizeof(struct uncook_data));
data->flow=flow;
instance->internal_data=(void *)data;
......@@ -248,6 +236,7 @@ static mapidflib_function_def_t uncookfinfo={
MAPIRES_NONE, //Method for returning results
0, //shm size
0, //modifies_pkts
MAPIFUNC_OPT_AUTO, //Optimization
uncook_instance, //instance
uncook_init, //init
uncook_process, //process
......
......@@ -19,7 +19,6 @@
#include <sys/wait.h>
#include "../../mapi.h"
#include "../../mapid.h"
// usefull vars
......
......@@ -15,8 +15,8 @@ typedef struct interface_instance_type {
} interface_instance_t;
static int interface_instance(mapidflib_function_instance_t *instance,
MAPI_UNUSED flist_t *flist,
MAPI_UNUSED mapidflib_flow_mod_t *flow_mod, MAPI_UNUSED function_manipulation_t* manip)
MAPI_UNUSED int fd,
MAPI_UNUSED mapidflib_flow_mod_t *flow_mod)
{
mapiFunctArg* a=instance->args;
int ifindex = getargint(&a);
......@@ -28,7 +28,7 @@ static int interface_instance(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
{
interface_instance_t *i=malloc(sizeof(interface_instance_t));
......@@ -63,6 +63,8 @@ static mapidflib_function_def_t finfo={
MAPIRES_NONE, //Method for returning results
0, //shm size
0, //modifies_pkts
1, //filters packets
MAPIOPT_AUTO,
interface_instance, //instance
interface_init, //init
interface_process, //process
......
......@@ -24,8 +24,8 @@ typedef struct erf_instance {
} erf_instance_t;
static int to_erf_instance(mapidflib_function_instance_t *instance,
MAPI_UNUSED flist_t *flist,
MAPI_UNUSED mapidflib_flow_mod_t *flow_mod, MAPI_UNUSED function_manipulation_t* manip)
MAPI_UNUSED int fd,
MAPI_UNUSED mapidflib_flow_mod_t *flow_mod)
{
mapiFunctArg* a=instance->args;
int type = getargint(&a);
......@@ -37,7 +37,7 @@ static int to_erf_instance(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
{
int *res;
......@@ -100,6 +100,8 @@ static mapidflib_function_def_t finfo={
MAPIRES_SHM,
sizeof(int), //shm size
0, //modifies_pkts
0, //filters packets
MAPIOPT_AUTO,
to_erf_instance,
to_erf_init,
to_erf_process,
......
......@@ -8,35 +8,27 @@
#include <sys/stat.h>
#include <sys/sem.h>
#include <fcntl.h>
#include "fhelp.h"
#include "mapid.h"
#include "mapidevices.h"
#include "debug.h"
#include "mapidflib.h"
#define TIME_M 257698037760ULL
#define TIME_S 4294967296ULL
#define TIME_MS 4294967
#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)
//return fid of first function with the name fname
{
flist_node_t *n;
mapidflib_function_instance_t *funct;
mapidflib_function_t *funct;
n = flist_head(flist);
while(n) {
funct=flist_data(n);
if(strcmp(funct->def->name,fname)==0)
if(strcmp(funct->instance->def->name,fname)==0)
return funct->fid;
n=flist_next(n);
}
......@@ -64,9 +56,17 @@ int fhlp_check_software_funct(flist_t *flist, mapidflib_function_instance_t *fro
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)
......@@ -83,7 +83,7 @@ int fhlp_create_semaphore(fhlp_sem_t *sem, int num)
argument.val = 0;
strncpy(pathname,FUNCTION_SEM_TEMPLATE,MAPI_STR_LENGTH);
if(mkstemp(pathname)==NULL)
if(mkstemp(pathname)==-1)
return MDLIB_SEM_ERR;
umask(017);
......@@ -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)
//Converts a string to an unsigned long long value
{
......@@ -180,3 +162,4 @@ int fhlp_ull2sec(unsigned long long l, char *str, int length)
return snprintf(str,length,"%f",sec);
}
......@@ -18,15 +18,12 @@ typedef struct fhlp_sem {
char fname[MAPI_STR_LENGTH];
} 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_funct(flist_t *flist, char *fname);
int fhlp_create_semaphore(fhlp_sem_t *sem,int num);
void fhlp_free_semaphore(fhlp_sem_t *sem);
extern inline mapidflib_result_t* fhlp_get_res(mapidflib_function_instance_t *instance);
void* fhlp_get_function_instance(int fd, int fid, int pid);
void fhlp_init_manipulation(function_manipulation_t* manip);
mapidflib_result_t* fhlp_new_get_res(int fd, int fid, int pid);
mapidflib_function_instance_t* fhlp_get_function_instance(global_function_list_t *glf,int fd, int fid);
//Convert a string to an unsigned long long value
unsigned long long fhlp_str2ull(char *str);
......
......@@ -3,7 +3,6 @@
Based on slist in adm_ctrl
*/
#include <pthread.h>
#include "stdlib.h"
#include "flist.h"
......@@ -24,14 +23,13 @@ flist_append(flist_t *list,int id,void *data)
node->data = data;
node->next = NULL;
pthread_mutex_lock(&list->lock);
if ( flist_head(list) == NULL )
flist_head(list) = node;
else
flist_next(flist_tail(list)) = node;
flist_tail(list) = node;
++flist_size(list);
pthread_mutex_unlock(&list->lock);
return 0;
}
......@@ -49,34 +47,38 @@ int flist_insert_before(flist_t *list, int before, int id, void *data)
//Find before node
pthread_mutex_lock(&list->lock);
node=flist_head(list);
if (node == NULL) {
flist_head(list) = newnode;
flist_tail(list) = newnode;
} else {
while(node!=NULL) {
if(node->id!=before) {
prev=node;
node=flist_next(node);
} else
break;
if ( node == NULL )
{
flist_append(list,id,data);
free(newnode);
}
else
{
while(node!=NULL)
{
if(node->id!=before)
{
prev=node;
node=flist_next(node);
}
else
break;
}
if(prev==NULL) {
newnode->next = flist_head(list);
flist_head(list) = newnode;
if (flist_tail(list)==NULL)
flist_tail(list) = newnode;
} else {
free(newnode);
flist_prepend(list,id,data);
}
else {
prev->next=newnode;
newnode->next=node;
if(node==NULL)
flist_tail(list)=newnode;
flist_tail(list)=newnode;
++flist_size(list);
}
}
++flist_size(list);
pthread_mutex_unlock(&list->lock);
return 0;
}
......@@ -96,15 +98,12 @@ flist_prepend(flist_t *list,int id,void *data)
node->id=id;
flist_data(node) = data;
pthread_mutex_lock(&list->lock);
flist_next(node) = flist_head(list);
flist_head(list) = node;
if ( flist_tail(list) == NULL )
flist_tail(list) = node;
++flist_size(list);
pthread_mutex_unlock(&list->lock);
return 0;
}
......@@ -119,17 +118,14 @@ flist_pop_first(flist_t *list)
void *d;
flist_node_t *node;
pthread_mutex_lock(&list->lock);
if ( flist_head(list) == NULL ) {
pthread_mutex_unlock(&list->lock);
if ( flist_head(list) == NULL )
return NULL;
}
d = flist_data((node = flist_head(list)));
flist_head(list) = flist_next(node);
free(node);
if ( --flist_size(list) == 0 )
flist_tail(list) = NULL;
pthread_mutex_unlock(&list->lock);
return d;
}
......@@ -141,7 +137,6 @@ flist_init(flist_t *list)
{
flist_head(list) = flist_tail(list) = NULL;
flist_size(list) = 0;
pthread_mutex_init(&list->lock, NULL);
}
/** \brief Destroy and de-allocate the memory hold by a list
......@@ -153,7 +148,6 @@ flist_destroy(flist_t *list,flist_destroy_t dealloc)
{
flist_node_t *node;
pthread_mutex_lock(&list->lock);
while( (node = flist_head(list)) )
{
flist_head(list) = flist_next(node);
......@@ -163,52 +157,37 @@ flist_destroy(flist_t *list,flist_destroy_t dealloc)
}
flist_tail(list) = NULL;
flist_size(list) = 0;
pthread_mutex_unlock(&list->lock);
}
void* flist_get(flist_t *list, int id)
{
flist_node_t *node;
void* dataCopy;
flist_node_t *node=flist_head(list);
pthread_mutex_lock(&list->lock);
node=flist_head(list);
while(node!=NULL) {
if(node->id==id) {
dataCopy = node->data;
pthread_mutex_unlock(&list->lock);
return dataCopy;
}
if(node->id==id)
return node->data;
else
node=flist_next(node);
}
pthread_mutex_unlock(&list->lock);
return NULL;
}
int flist_get_next_id(flist_t *list, int id)
{
flist_node_t *node;
int idCopy;
flist_node_t *node=flist_head(list);
pthread_mutex_lock(&list->lock);
node=flist_head(list);
while(node!=NULL) {
if(node->id==id) {
node=flist_next(node);
idCopy = node->id; // a copy for thread safety
pthread_mutex_unlock(&list->lock);
if(node==NULL)
return 0;
return 0;
else
return idCopy;
return node->id;
}
else
node=flist_next(node);
}
pthread_mutex_unlock(&list->lock);
return 0;
}
......@@ -220,33 +199,30 @@ void flist_move_before(flist_t *list,int before,int id) {
void* flist_remove(flist_t *list,int id,flist_destroy_t dealloc)
{
flist_node_t *node;
flist_node_t *node=flist_head(list);
flist_node_t *p=NULL;
void *data;
pthread_mutex_lock(&list->lock);
node=flist_head(list);
while(node!=NULL) {
if(node->id==id) {
--flist_size(list);
data=node->data;
if(p==NULL)
flist_head(list)=node->next;
flist_head(list)=node->next;
else
p->next=node->next;
p->next=node->next;
if(flist_tail(list)==node)
flist_tail(list)=p;
flist_tail(list)=p;
if(dealloc==FLIST_FREE_DATA)
free(flist_data(node));
free(flist_data(node));
free(node);
pthread_mutex_unlock(&list->lock);
return data;
} else {
}
else {
p=node;
node=flist_next(node);
}
}
pthread_mutex_unlock(&list->lock);
return NULL;
}
......@@ -255,7 +231,7 @@ int
flist_insert(flist_t *list, int id, void* data, int index)
{
int i;
flist_node_t* head;
flist_node_t* head = flist_head(list);
flist_node_t* prev=NULL;
flist_node_t* node;
......@@ -270,8 +246,6 @@ flist_insert(flist_t *list, int id, void* data, int index)
node->id = id;
node->data = data;
pthread_mutex_lock(&list->lock);
head = flist_head(list);
for (i=0; head != NULL; head = flist_next(head), i++)
{
if (i == index)
......@@ -282,7 +256,6 @@ flist_insert(flist_t *list, int id, void* data, int index)
prev = head;
}
flist_size(list)++;
pthread_mutex_unlock(&list->lock);
return 0;
}
......@@ -293,14 +266,9 @@ void flist_reverse(flist_t* list)
flist_node_t* prev=NULL;
flist_node_t* next=NULL;
pthread_mutex_lock(&list->lock);
node = flist_head(list);
pthread_mutex_unlock(&list->lock);
if (node == NULL)
if (flist_head(list) == NULL)
return;
pthread_mutex_lock(&list->lock);
for (node=flist_head(list); node != NULL; node = next)
{
next = flist_next(node);
......@@ -311,35 +279,6 @@ void flist_reverse(flist_t* list)
node = flist_head(list);
flist_head(list) = flist_tail(list);
flist_tail(list) = node;
pthread_mutex_unlock(&list->lock);
return;
}
/** \brief Searches for a mathcing node and returns it
Returns only the first matching node.
\param list a pointer to an existing list
\param comp function reference to be used for comparison of nodes
\param cdata 2nd argument to be passed to comparison function
\return Reference to the matching node's data, or NULL if no node
was matched
*/
void *flist_search(flist_t *list, int (*comp)(void *, void *), void *user)
{
flist_node_t *n;
void *dataCopy;
pthread_mutex_lock(&list->lock);
for(n = flist_head(list) ; n != NULL ; n = flist_next(n)) {
if ( comp(flist_data(n),</