Commit 495d16a2 authored by 's avatar
Browse files

Fix in exprflow regarding epochs


git-svn-id: file:///home/svn/mapi/trunk@1283 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent fc49d868
......@@ -40,4 +40,5 @@ struct exfl_data {
pthread_mutex_t mutex;
pthread_t pthread;
unsigned int run;
unsigned long long epoch;
};
......@@ -25,7 +25,6 @@
#define MPLS_MASK 0x8847
#define ETHERTYPE_IP 0x0800 /* IP protocol */
unsigned long long epoch;
struct vlan_802q_header {
u_int16_t priority_cfi_vid;
......@@ -59,7 +58,7 @@ inline unsigned int hash_function(flow_data record) {
}
else {
return(((unsigned int)((saddr.byte1 + saddr.byte2 + saddr.byte3 + saddr.byte4) +
(daddr.byte1 + daddr.byte2 + daddr.byte3 + daddr.byte4)))/137);
(daddr.byte1 + daddr.byte2 + daddr.byte3 + daddr.byte4+1)))/137);
}
}
......@@ -79,7 +78,7 @@ void add_toflow(struct exfl_data *data, flow_data record) {
else {
lookup->node->flow.packets_count++;
lookup->node->flow.bytes_count += record.bytes_count;
lookup->node->flow.timestamp = epoch;
lookup->node->flow.timestamp = data->epoch;
shift_node(data, lookup->node);
pthread_mutex_unlock( &(data->mutex) );
......@@ -260,7 +259,7 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) {
tmp = data->list_tail;
check_expired_flows(data,shm_struct );
if(tmp) { //if list is not empty
while( epoch - tmp->flow.timestamp > TIMEOUT) {
while( data->epoch - tmp->flow.timestamp > TIMEOUT) {
previous = tmp->previous;
value = tmp->value;
tmpflow_data = tmp->flow;
......@@ -350,7 +349,7 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) {
}
pthread_mutex_unlock( mutex );
sleep(EPOCHDURATION);
epoch++;
data->epoch++;
}
pthread_exit(NULL);
}
......@@ -363,8 +362,6 @@ static int exprflow_init(mapidflib_function_instance_t *instance, MAPI_UNUSED in
shm shm_struct;
struct exfl_data *data;
// Epoch initialization
epoch=0;
// HashTable initialization
if( (instance->internal_data = malloc(sizeof(struct exfl_data))) == NULL) {
......@@ -380,6 +377,8 @@ static int exprflow_init(mapidflib_function_instance_t *instance, MAPI_UNUSED in
data->mutex = tmpmutex;
data->run = 1;
data->list_size = 0;
// Epoch initialization
data->epoch=0;
// Shared Memory Initialization
shm_struct.size = (unsigned int *)instance->result.data;
......@@ -411,6 +410,7 @@ static int exprflow_process(mapidflib_function_instance_t *instance, MAPI_UNUSED
unsigned int len = pkt_head->caplen;
int headerlenoverplus = 0;
struct vlan_802q_header *vlan_header;
p = link_pkt;
......@@ -450,7 +450,7 @@ static int exprflow_process(mapidflib_function_instance_t *instance, MAPI_UNUSED
record.daddr = ip->daddr;
record.sport = ntohs(tcp->sport);
record.dport = ntohs(tcp->dport);
record.timestamp = epoch;
record.timestamp = data->epoch;
record.ptcl = ip->ptcl;
record.bytes_count = pkt_head->wlen - headerlenoverplus;
add_toflow(data, record);
......@@ -462,7 +462,7 @@ static int exprflow_process(mapidflib_function_instance_t *instance, MAPI_UNUSED
record.daddr = ip->daddr;
record.sport = ntohs(udp->sport);
record.dport = ntohs(udp->dport);
record.timestamp = epoch;
record.timestamp = data->epoch;
record.ptcl = ip->ptcl;
record.bytes_count = pkt_head->wlen - headerlenoverplus;
add_toflow(data,record);
......@@ -472,7 +472,7 @@ static int exprflow_process(mapidflib_function_instance_t *instance, MAPI_UNUSED
record.saddr = ip->saddr;
record.daddr = ip->daddr;
record.sport = record.dport = ntohs(0);
record.timestamp = epoch;
record.timestamp = data->epoch;
record.ptcl = ip->ptcl;
record.bytes_count = pkt_head->wlen - headerlenoverplus;
add_toflow(data, record);
......
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