AI attack_detect function

This commit is contained in:
pavanvpatil 2022-09-24 16:45:28 +05:30
parent c6926c8baa
commit 1edf6729e2
3 changed files with 55 additions and 1 deletions

30
iPDC/Attack_detect.c Normal file
View File

@ -0,0 +1,30 @@
#include "Attack_detect.h"
#include "parser.h"
/* pavan changes */
void attack_detect(struct data_frame *df,clock_t START)
{
float CURR_FREQ=to_intconvertor(df->dpmu[0]->freq);
SUM_OF_FREQUENCY+=CURR_FREQ;
COUNT=0;
float FREQ_AVG=SUM_OF_FREQUENCY/(COUNT*1.0f);
float DETECT_PERCENT=(abs(FREQ_AVG-CURR_FREQ)/(FREQ_AVG*1.0f))*100;
double END = clock();
printf("Detect_percent: %f\n",DETECT_PERCENT);
if(DETECT_PERCENT>THRESHOLD)
printf("ATTACK DETECTED\n");
else
printf("NO PROBLEM\n");
cpu_time_used = ((double) (END - START)) / CLOCKS_PER_SEC;
if(cpu_time_used > 10)
{
START = 0;
SUM_OF_FREQUENCY=CURR_FREQ;
COUNT=1;
}
}
/* pavan changes */

14
iPDC/Attack_detect.h Normal file
View File

@ -0,0 +1,14 @@
/* pavan changes */
#include <time.h>
/* variables declared */
float SUM_OF_FREQUENCY=0;
float COUNT=0;
float THRESHOLD=25;
double cpu_time_used;
/* functions declared */
void attack_detect(struct data_frame *df,clock_t START);
/* pavan changes */

View File

@ -54,6 +54,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h> #include <pthread.h>
#include <stdint.h> #include <stdint.h>
#include <time.h>
#include "parser.h" #include "parser.h"
#include "global.h" #include "global.h"
#include "dallocate.h" #include "dallocate.h"
@ -61,6 +62,7 @@
#include "connections.h" #include "connections.h"
#include "recreate.h" #include "recreate.h"
#include "utility_tools.h" #include "utility_tools.h"
#include "Attack_detect.h"
/* ---------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------- */
/* FUNCTION cfgparser(): */ /* FUNCTION cfgparser(): */
@ -1269,8 +1271,15 @@ int dataparser(unsigned char data[]) {
//No match for configuration frame //No match for configuration frame
printf("Configuration is not fresent for received data frame!\n"); printf("Configuration is not fresent for received data frame!\n");
} }
printf("freq = %d\n",to_intconvertor(df->dpmu[0]->freq));
/*pavan changes*/
//#include "Attack_detect.h"
//clock_t START = clock();
//attack_detect(df,START);
/*pavan changes*/
// temp code // temp code
/* karthik changes*/
int freq = to_intconvertor(df->dpmu[0]->freq); int freq = to_intconvertor(df->dpmu[0]->freq);
if(util_map != NULL){ if(util_map != NULL){
g_red_image = gdk_pixbuf_new_from_file_at_size ("red.png", 24,24,NULL); g_red_image = gdk_pixbuf_new_from_file_at_size ("red.png", 24,24,NULL);
@ -1286,6 +1295,7 @@ int dataparser(unsigned char data[]) {
gtk_widget_show_all(GTK_WIDGET(util_map)); gtk_widget_show_all(GTK_WIDGET(util_map));
} }
/* karthik changes */
if((config_change == 14) ||(config_change == 10)) if((config_change == 14) ||(config_change == 10))
return config_change; return config_change;