/**
* Search for a black hole node.
*/
void
NEIGHBOURS::SearchForBlackHole(int percentile_of_loss, int32_t ownIP, int heartbeat_malicious, int immediate_reaction_duration, double pktime) {
int j;
char text[200];
char protocol_name[MAX_PROTOCOL_NAME];
neighbour *n;
double percentage;

n = neigs->group;

while (n != NULL) {
/* Porcentaje dividido por protocolos y puertos */
for (j = 0; j < NUMBER_PROTOCOLS; j++) {
if (n->pckts->received_packets(j) > MIN_SIGNIFICANT_PACKETS) {
percentage = ((1 - ((n->pckts->forwarded_packets(j) + n->pckts->stored_packets_protocol(j)) / (n->pckts->received_packets(j)))) * 100);
} else {
percentage = -1;
}
if (percentage > max_percentage) {
max_percentage = percentage;
}

if ((percentage > percentile_of_loss && (pktime > n->malicious_node + heartbeat_malicious))) {
obtainNameProtocol(protocol_name, j);
sprintf(text, "\nAlarm! Alarm! node %d (mac %d) not forward more than %d%% packets: %.2f%% loss for %s, %.2f secs of execution and %.2f secs from neighbour detection\n",
n->ip, n->mac, percentile_of_loss, percentage, protocol_name, pktime - start_time, pktime - n->starting_time);
n->malicious_node = pktime;
//SendAnAlarm(text, n, ownIP, gw_ip, port, finish);
printf("%s", text);

if (finish) {
exit(0);
}
}
if ((percentage > percentile_of_loss && (immediate_reaction_duration > 0) && (pktime > n->malicious_node + immediate_reaction_duration))) {
//immediateReaction(n->mac, immediate_reaction_duration);
}
}
n = n->next;
}
}
 posted on 2012-03-08 15:20  Fuzzy Joke  阅读(295)  评论(0编辑  收藏  举报