/*
Constructor
*/
WATCHDOG::WATCHDOG(int32_t own_IP) {
port = PORTW; //Port of the GW.
devalue = 0; //Devalue old packets.
readed_packets = 0;
ip_packets = 0;
arp_packets = 0;
interesting_readed_packets = 0;
heartbeat_malicious = HEARTBEAT_MALICIOUS_NODE;
immediate_reaction_duration = IMMEDIATE_REATION_DURATION;
percentile_of_loss = PERCENTAGE_LOSS;
neighbour_timeout = NEIGHBOUR_TIMEOUT; //timeout for neighbours stored.
storing_packet_timeout = STORE_PACKET_TIME;
storing_route_timeout = STORE_ROUTE_TIME;
reduction = WEIGHT_OF_OLD_PACKETS; //Weight of the olds packets when are devaluated.
//IniciateNeighbours(&neigs);
neigs = new NEIGHBOURS();
ownIP = own_IP;
ownMAC=666;
debug=0;
}
/*
New Packet detected!
*/
void
WATCHDOG::newPacket(int32_t source_ip, int32_t destination_ip, int source_mac, int destination_mac, int sourcePort, int destinationPort, packet_t packet_type, char* tmp_data, double tmp_time) {
if(debug>0) printf("Node IP: %d MAC: %d says:\n",ownIP, ownMAC);
readPacket(source_ip, destination_ip, source_mac, destination_mac, sourcePort, destinationPort, packet_type, tmp_data, tmp_time);
neigs->SearchForBlackHole(percentile_of_loss, ownIP, heartbeat_malicious, immediate_reaction_duration, tmp_time);
/* Clean old information */
neigs->DeleteOldNeighbours(neighbour_timeout, debug, tmp_time);
neigs->RemoveOldPackets(storing_packet_timeout, tmp_time);
neigs->RemoveOldFlows(storing_route_timeout, tmp_time);
/* Apply devaluation technique */
if (devalue){
neigs->CompressPacketsAllNeighbours(reduction);
}
}