Commit c6fe1d34 authored by 's avatar

Expired flow works now with epochs and doesn't require the timestamp of...

Expired flow works now with epochs and doesn't require the timestamp of packets to be synchronised with the host clock anymore.


git-svn-id: file:///home/svn/mapi/trunk@1265 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent b8f4cecc
......@@ -17,13 +17,16 @@
#define EXPIRED_FLOWS "EXPIRED_FLOWS"
#define SEND_SIZE 64 //Number of expired flows send per mapi_read_results.
#define TIMEOUT 30
#define TIMEOUT 30 //in epochs
#define EPOCHDURATION 1
#define SHM_FLOWS 1000 //shm flows count
#define ETHERTYPE_8021Q 0x8100
#define MPLS_MASK 0x8847
#define ETHERTYPE_IP 0x0800 /* IP protocol */
unsigned long long epoch;
struct vlan_802q_header {
u_int16_t priority_cfi_vid;
u_int16_t ether_type;
......@@ -76,7 +79,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 = record.timestamp;
lookup->node->flow.timestamp = epoch;
shift_node(data, lookup->node);
pthread_mutex_unlock( &(data->mutex) );
......@@ -241,12 +244,10 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) {
struct exfl_list_node *tmp, *previous;
struct exfl_hash_node *lookup_hash;
flow_data tmpflow_data;
unsigned long long current_ts = 0;
unsigned int value;
pthread_mutex_t *mutex = &(data->mutex);
int check;
shm shm_struct;
struct timeval tp; // need in poll_expired_flows
shm_struct.size = (unsigned int *)instance->result.data;
shm_struct.Table = (flow_data *)((char *)instance->result.data+sizeof(unsigned int));
......@@ -259,11 +260,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
if(gettimeofday(&tp, NULL) ==0) {
// calculate the current timestamp
current_ts = ((unsigned long long)tp.tv_sec);
while( current_ts - ((tmp->flow.timestamp)>>32) > TIMEOUT) {
while( epoch - tmp->flow.timestamp > TIMEOUT) {
previous = tmp->previous;
value = tmp->value;
tmpflow_data = tmp->flow;
......@@ -350,10 +347,10 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) {
if(tmp == NULL)
break;
}
}
}
pthread_mutex_unlock( mutex );
sleep(1);
sleep(EPOCHDURATION);
epoch++;
}
pthread_exit(NULL);
}
......@@ -366,6 +363,9 @@ 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) {
fprintf(stderr, "Malloc failed in exprflow.c for size %d\n", sizeof(struct exfl_data));
......@@ -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 = pkt_head->ts;
record.timestamp = 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 = pkt_head->ts;
record.timestamp = 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 = pkt_head->ts;
record.timestamp = 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