Commit fad04307 authored by 's avatar

Reverted previous "fix". Pebkac.


git-svn-id: file:///home/svn/mapi/trunk@1373 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 810d25d7
......@@ -21,7 +21,7 @@
#define WITH_NCURSES 0 // set to 1 if you want ncurses, 0 otherwise
#define REFRESH_TIME 10 // 10 seconds base interval with which data will be fed into the RRD
#define SHM_FLOWS_DEVICE_MAX 49999 // (DIMAPI_DATA_SIZE - sizeof(flows_stat) - sizeof(unsigned int)) / sizeof(struct flow_data))
#define SHM_FLOWS_DEVICE_MAX 49998 // (DIMAPI_DATA_SIZE - sizeof(flows_stat) - cca24) / sizeof(struct flow_data))
#define SHM_FLOWS_TOTAL_MAX 250000
#define TIMESTAMP_TOLERANCE 430000000 // NTP 0.1
#define MIN(x, y) ((x) < (y) ? (x) : (y))
......@@ -337,7 +337,7 @@ int main(int argc, char *argv[])
unsigned int *results; // number of results/flowdata = (unsigned int *) ...
struct flows_stat *flowsstats;
struct flow_data *flowdata; // result/flowdata = (struct flow_data *)((char *) ... + sizeof(flows_stat) + sizeof(unsigned int));
struct flow_data *flowdata; // result/flowdata = (struct flow_data *)((char *) ... ) + sizeof(flows_stat);
unsigned long long pkloss = 0;
......@@ -710,7 +710,7 @@ int main(int argc, char *argv[])
}
results = (unsigned int *) host[h].results_dev[d].res; // number of results/flows at host h, dev d
flowsstats = (struct flows_stat *) host[h].results_dev[d].res;
flowdata = (struct flow_data *)((char *) host[h].results_dev[d].res + sizeof(flows_stat) + sizeof(unsigned int)); // results/flows array
flowdata = (struct flow_data *)((char *) host[h].results_dev[d].res + sizeof(flows_stat)); // results/flows array
fprintf(stdout, "packetloss: storing and matching results from %s:%d: %d\n", host[h].name, d, *results); fflush(stdout);
// store flowstats_dev
......@@ -763,7 +763,7 @@ int main(int argc, char *argv[])
// }}}
results = (unsigned int *) host[h].results_dev[d].res; // number of results/flows
flowdata = (struct flow_data *) ((char *) host[h].results_dev[d].res + sizeof(flows_stat) + sizeof(unsigned int)); // results/flows array
flowdata = (struct flow_data *) ((char *) host[h].results_dev[d].res + sizeof(flows_stat)); // results/flows array
for (count = *results; count > 0; count--) {
if (LOGFILE) {
......
#define EXFL_HASH_SIZE 262144 //4096
#define EXFL_HASH_SIZE 262144 //4128
#include "protocols.h"
......
......@@ -35,7 +35,6 @@ pthread_t pthread;
typedef struct shm {
unsigned int *size;
unsigned int *shm_flows;
flow_data *Table;
pthread_mutex_t *smmutex;
}shm;
......@@ -252,8 +251,8 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) {
stats = (flows_stat *) instance->result.data;
shm_struct.size = (unsigned int *)instance->result.data;
shm_struct.Table = (flow_data *)((char *)instance->result.data+sizeof(flows_stat)+sizeof(unsigned int));
shm_struct.smmutex = (pthread_mutex_t *)(((char *)instance->result.data) + sizeof(flows_stat) + sizeof(unsigned int) + sizeof(struct flow_data)*data->shm_flows);
shm_struct.Table = (flow_data *)((char *)instance->result.data+sizeof(flows_stat));
shm_struct.smmutex = (pthread_mutex_t *)(((char *)instance->result.data) + sizeof(flows_stat) + sizeof(struct flow_data)*data->shm_flows);
*(shm_struct.size) = 0;
while(data->run) {
......@@ -383,12 +382,12 @@ static int exprflow_instance(mapidflib_function_instance_t *instance,
MAPI_UNUSED int fd,
MAPI_UNUSED mapidflib_flow_mod_t *flow_mod) {
mapiFunctArg* fargs;
int shm_flows; // max: (DIMAPI_DATA_SIZE - sizeof(flows_stat) - sizeof(unsigned int)) / sizeof(struct flow_data))
int shm_flows; // max: (DIMAPI_DATA_SIZE - sizeof(flows_stat) - cca24) / sizeof(struct flow_data))
fargs = instance->args;
shm_flows = getargint(&fargs);
instance->def->shm_size = sizeof(flows_stat) + sizeof(unsigned int) + sizeof(struct flow_data) * shm_flows + sizeof(unsigned int) + sizeof(pthread_mutex_t);
instance->def->shm_size = sizeof(flows_stat) + sizeof(struct flow_data) * shm_flows + sizeof(pthread_mutex_t);
return 0;
}
......@@ -424,23 +423,21 @@ static int exprflow_init(mapidflib_function_instance_t *instance, MAPI_UNUSED in
data->epoch=0;
// function arguments
data->shm_flows = getargint(&fargs); // max: (DIMAPI_DATA_SIZE - sizeof(flows_stat) - sizeof(unsigned int)) / sizeof(struct flow_data))
data->shm_flows = getargint(&fargs); // max: (DIMAPI_DATA_SIZE - sizeof(flows_stat) - cca24) / sizeof(struct flow_data))
data->expired_flows_list_size_max = getargint(&fargs);
data->packets_count_min = getargint(&fargs);
// Shared Memory Initialization
stats = (flows_stat *)instance->result.data;
shm_struct.size = (unsigned int *)instance->result.data;
shm_struct.shm_flows = (unsigned int*)((char *)instance->result.data+sizeof(flows_stat));
shm_struct.Table = (flow_data *)((char *)instance->result.data+sizeof(flows_stat)+sizeof(unsigned int));
shm_struct.smmutex = (pthread_mutex_t *)(((char *)instance->result.data) + sizeof(flows_stat) + sizeof(unsigned int) + sizeof(struct flow_data)*data->shm_flows);
shm_struct.Table = (flow_data *)((char *)instance->result.data+sizeof(flows_stat));
shm_struct.smmutex = (pthread_mutex_t *)(((char *)instance->result.data) + sizeof(flows_stat) + sizeof(struct flow_data) * data->shm_flows);
stats->received = 0;
stats->expired = 0;
*(shm_struct.size) = 0; //stats->sent = 0;
stats->ignored = 0;
stats->dropped = 0;
*(shm_struct.shm_flows) = data->shm_flows;
//mutex initialization
*(shm_struct.smmutex) = tmpmutex;
......@@ -609,27 +606,22 @@ void print_flow(eflow_data *data) {
}
static int exprflow_client_read_result(mapidflib_function_instance_t *instance,mapi_result_t *res) {
unsigned int size;
shm shm_struct;
eflow_data *data;
flows_stat *stats;
mapiFunctArg* fargs;
int shm_flows; // max: (DIMAPI_DATA_SIZE - sizeof(flows_stat) - sizeof(unsigned int)) / sizeof(struct flow_data))
int shm_flows; // max: (DIMAPI_DATA_SIZE - sizeof(flows_stat) - cca24) / sizeof(struct flow_data))
fargs = instance->args;
shm_flows = getargint(&fargs);
stats = (flows_stat *)instance->result.data;
shm_struct.size = (unsigned int *)instance->result.data;
shm_struct.shm_flows = (unsigned int *)((char *)instance->result.data+sizeof(flows_stat));
shm_struct.Table = (flow_data *)((char *)instance->result.data+sizeof(flows_stat)+sizeof(unsigned int));
fprintf(stdout, "shm_flows: %u", *(shm_struct.shm_flows)); fflush(stdout);
shm_struct.smmutex = (pthread_mutex_t *)(((char *)instance->result.data) + sizeof(flows_stat) + sizeof(unsigned int) + sizeof(struct flow_data)*(*shm_struct.shm_flows));
shm_struct.Table = (flow_data *)((char *)instance->result.data+sizeof(flows_stat));
shm_struct.smmutex = (pthread_mutex_t *)(((char *)instance->result.data) + sizeof(flows_stat) + sizeof(struct flow_data) * shm_flows);
res->res = instance->internal_data;
res->size = sizeof(flows_stat) + sizeof(unsigned int) + sizeof(flow_data)*(*(shm_struct.size));
size = *shm_struct.size;
res->size = sizeof(flows_stat) + sizeof(flow_data) * (*(shm_struct.size));
pthread_mutex_lock( shm_struct.smmutex );
memcpy(instance->internal_data, instance->result.data, res->size);
......@@ -640,25 +632,24 @@ fprintf(stdout, "shm_flows: %u", *(shm_struct.shm_flows)); fflush(stdout);
stats->dropped = 0;
pthread_mutex_unlock( shm_struct.smmutex );
data = (flow_data *)((char *)instance->internal_data+sizeof(flows_stat)+sizeof(unsigned int));
return(0);
}
static int exprflow_client_init( mapidflib_function_instance_t *instance, void *data) {
mapiFunctArg* fargs;
int shm_flows; // max: (DIMAPI_DATA_SIZE - sizeof(flows_stat) - sizeof(unsigned int)) / sizeof(struct flow_data))
int shm_flows; // max: (DIMAPI_DATA_SIZE - sizeof(flows_stat) - cca24) / sizeof(struct flow_data))
fargs = instance->args;
shm_flows = getargint(&fargs);
if(shm_flows > (DIMAPI_DATA_SIZE - sizeof(flows_stat) - sizeof(unsigned int)) / sizeof(struct flow_data)) {
printf("Cannot process %d flows. Maximum is %d.\n", shm_flows, (DIMAPI_DATA_SIZE - sizeof(flows_stat)) / sizeof(struct flow_data));
if(shm_flows > (DIMAPI_DATA_SIZE - sizeof(flows_stat) - 24) / sizeof(struct flow_data)) {
printf("Cannot process %d flows. Maximum is %d.\n", shm_flows, (DIMAPI_DATA_SIZE - sizeof(flows_stat) - 24) / sizeof(struct flow_data));
return(-1);
}
if((instance->internal_data = malloc(sizeof(flows_stat)+sizeof(unsigned int)+sizeof(struct flow_data)*shm_flows)) == NULL) {
printf("Malloc failed for size %d [%s:%d]\n", sizeof(flows_stat)+sizeof(unsigned int)+sizeof(struct flow_data)*shm_flows, __FILE__, __LINE__);
if((instance->internal_data = malloc(sizeof(flows_stat)+sizeof(struct flow_data)*shm_flows)) == NULL) {
printf("Malloc failed for size %d [%s:%d]\n", sizeof(flows_stat)+sizeof(struct flow_data)*shm_flows, __FILE__, __LINE__);
return(-1);
}
data = instance->internal_data;
......
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