Commit 90d7ac0b authored by 's avatar

EXPIRED_FLOWS protocol changed to give packet statistics at host too.


git-svn-id: file:///home/svn/mapi/trunk@1443 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 0d4ec436
......@@ -28,6 +28,13 @@ typedef struct flows_stat {
unsigned int expired;
unsigned int ignored;
unsigned int dropped;
struct {
unsigned int sent;
unsigned int received;
unsigned int expired;
unsigned int ignored;
unsigned int dropped;
} packets;
} flows_stat;
struct exfl_list_node {
......
......@@ -47,19 +47,12 @@ void shift_node(struct exfl_data *data, struct exfl_list_node *node);
void poll_expired_flows(mapidflib_function_instance_t *instance);
void print_flow(eflow_data *data);
inline unsigned int hash_function(eflow_data record) {
ip_addr saddr = record.saddr;
ip_addr daddr = record.daddr;
ip_addr saddr = record.saddr, daddr = record.daddr;
if( (record.ptcl == IPPROTO_TCP) || (record.ptcl == IPPROTO_UDP) ) {
return(((unsigned int)((saddr.byte1 + saddr.byte2 + saddr.byte3 + saddr.byte4)*record.sport +
(daddr.byte1 + daddr.byte2 + daddr.byte3 + daddr.byte4 + 1)*record.dport))/137);
}
else {
return(((unsigned int)((saddr.byte1 + saddr.byte2 + saddr.byte3 + saddr.byte4) +
(daddr.byte1 + daddr.byte2 + daddr.byte3 + daddr.byte4+1)))/137);
}
return ((unsigned int)((saddr.byte1 + saddr.byte2 + saddr.byte3 + saddr.byte4) * (record.sport + 1) +
(daddr.byte1 + daddr.byte2 + daddr.byte3 + daddr.byte4) * (record.dport + 2))) / 137;
}
void add_toflow(struct exfl_data *data, eflow_data record, flows_stat *stats) {
......@@ -84,6 +77,7 @@ void add_toflow(struct exfl_data *data, eflow_data record, flows_stat *stats) {
shift_node(data, lookup->node);
pthread_mutex_unlock( &(data->mutex) );
}
stats->packets.received++;
}
void shift_node(struct exfl_data *data, struct exfl_list_node *node) {
......@@ -259,6 +253,7 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) {
if(tmp) { //if list is not empty
while( data->epoch - tmp->flow.epoch > TIMEOUT) {
stats->expired++;
stats->packets.expired += tmp->flow.packets_count;
previous = tmp->previous;
value = tmp->value;
tmpeflow_data = tmp->flow;
......@@ -335,11 +330,13 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) {
else {
// else drop
stats->dropped++;
stats->packets.dropped += tmp->flow.packets_count;
free(tmp);
}
}
else {
stats->ignored++;
stats->packets.ignored += tmp->flow.packets_count;
free(tmp);
}
......@@ -351,10 +348,12 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) {
pthread_mutex_lock( shm_struct.smmutex );
memcpy(&(shm_struct.Table[*(shm_struct.size)]), &(tmp->flow), sizeof(struct flow_data));
(*(shm_struct.size))++;
stats->packets.sent += tmp->flow.packets_count;
pthread_mutex_unlock( shm_struct.smmutex );
}
else {
stats->ignored++;
stats->packets.ignored += tmp->flow.packets_count;
}
free(tmp);
}
......@@ -437,6 +436,12 @@ static int exprflow_init(mapidflib_function_instance_t *instance, MAPI_UNUSED in
stats->ignored = 0;
stats->dropped = 0;
stats->packets.received = 0;
stats->packets.expired = 0;
stats->packets.sent = 0;
stats->packets.ignored = 0;
stats->packets.dropped = 0;
//mutex initialization
*(shm_struct.smmutex) = tmpmutex;
......@@ -657,6 +662,11 @@ static int exprflow_client_read_result(mapidflib_function_instance_t *instance,m
*(shm_struct.size) = 0; //stats->sent = 0;
stats->ignored = 0;
stats->dropped = 0;
stats->packets.received = 0;
stats->packets.expired = 0;
stats->packets.sent = 0;
stats->packets.ignored = 0;
stats->packets.dropped = 0;
pthread_mutex_unlock( shm_struct.smmutex );
return(0);
......
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