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 { ...@@ -28,6 +28,13 @@ typedef struct flows_stat {
unsigned int expired; unsigned int expired;
unsigned int ignored; unsigned int ignored;
unsigned int dropped; unsigned int dropped;
struct {
unsigned int sent;
unsigned int received;
unsigned int expired;
unsigned int ignored;
unsigned int dropped;
} packets;
} flows_stat; } flows_stat;
struct exfl_list_node { struct exfl_list_node {
......
...@@ -47,19 +47,12 @@ void shift_node(struct exfl_data *data, struct exfl_list_node *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 poll_expired_flows(mapidflib_function_instance_t *instance);
void print_flow(eflow_data *data); void print_flow(eflow_data *data);
inline unsigned int hash_function(eflow_data record) { 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; 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;
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);
}
} }
void add_toflow(struct exfl_data *data, eflow_data record, flows_stat *stats) { 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) { ...@@ -84,6 +77,7 @@ void add_toflow(struct exfl_data *data, eflow_data record, flows_stat *stats) {
shift_node(data, lookup->node); shift_node(data, lookup->node);
pthread_mutex_unlock( &(data->mutex) ); pthread_mutex_unlock( &(data->mutex) );
} }
stats->packets.received++;
} }
void shift_node(struct exfl_data *data, struct exfl_list_node *node) { 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) { ...@@ -259,6 +253,7 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) {
if(tmp) { //if list is not empty if(tmp) { //if list is not empty
while( data->epoch - tmp->flow.epoch > TIMEOUT) { while( data->epoch - tmp->flow.epoch > TIMEOUT) {
stats->expired++; stats->expired++;
stats->packets.expired += tmp->flow.packets_count;
previous = tmp->previous; previous = tmp->previous;
value = tmp->value; value = tmp->value;
tmpeflow_data = tmp->flow; tmpeflow_data = tmp->flow;
...@@ -335,11 +330,13 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) { ...@@ -335,11 +330,13 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) {
else { else {
// else drop // else drop
stats->dropped++; stats->dropped++;
stats->packets.dropped += tmp->flow.packets_count;
free(tmp); free(tmp);
} }
} }
else { else {
stats->ignored++; stats->ignored++;
stats->packets.ignored += tmp->flow.packets_count;
free(tmp); free(tmp);
} }
...@@ -351,10 +348,12 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) { ...@@ -351,10 +348,12 @@ void poll_expired_flows(mapidflib_function_instance_t *instance) {
pthread_mutex_lock( shm_struct.smmutex ); pthread_mutex_lock( shm_struct.smmutex );
memcpy(&(shm_struct.Table[*(shm_struct.size)]), &(tmp->flow), sizeof(struct flow_data)); memcpy(&(shm_struct.Table[*(shm_struct.size)]), &(tmp->flow), sizeof(struct flow_data));
(*(shm_struct.size))++; (*(shm_struct.size))++;
stats->packets.sent += tmp->flow.packets_count;
pthread_mutex_unlock( shm_struct.smmutex ); pthread_mutex_unlock( shm_struct.smmutex );
} }
else { else {
stats->ignored++; stats->ignored++;
stats->packets.ignored += tmp->flow.packets_count;
} }
free(tmp); free(tmp);
} }
...@@ -437,6 +436,12 @@ static int exprflow_init(mapidflib_function_instance_t *instance, MAPI_UNUSED in ...@@ -437,6 +436,12 @@ static int exprflow_init(mapidflib_function_instance_t *instance, MAPI_UNUSED in
stats->ignored = 0; stats->ignored = 0;
stats->dropped = 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 //mutex initialization
*(shm_struct.smmutex) = tmpmutex; *(shm_struct.smmutex) = tmpmutex;
...@@ -657,6 +662,11 @@ static int exprflow_client_read_result(mapidflib_function_instance_t *instance,m ...@@ -657,6 +662,11 @@ static int exprflow_client_read_result(mapidflib_function_instance_t *instance,m
*(shm_struct.size) = 0; //stats->sent = 0; *(shm_struct.size) = 0; //stats->sent = 0;
stats->ignored = 0; stats->ignored = 0;
stats->dropped = 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 ); pthread_mutex_unlock( shm_struct.smmutex );
return(0); 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