diff --git a/iPDC/Attack_detect.c b/iPDC/Attack_detect.c new file mode 100644 index 0000000..e6ca3db --- /dev/null +++ b/iPDC/Attack_detect.c @@ -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 */ \ No newline at end of file diff --git a/iPDC/Attack_detect.h b/iPDC/Attack_detect.h new file mode 100644 index 0000000..b5b9f1b --- /dev/null +++ b/iPDC/Attack_detect.h @@ -0,0 +1,14 @@ +/* pavan changes */ +#include + +/* 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 */ \ No newline at end of file diff --git a/iPDC/parser.c b/iPDC/parser.c index a28d22f..711792f 100755 --- a/iPDC/parser.c +++ b/iPDC/parser.c @@ -54,6 +54,7 @@ #include #include #include +#include #include "parser.h" #include "global.h" #include "dallocate.h" @@ -61,6 +62,7 @@ #include "connections.h" #include "recreate.h" #include "utility_tools.h" +#include "Attack_detect.h" /* ---------------------------------------------------------------------------- */ /* FUNCTION cfgparser(): */ @@ -1269,8 +1271,15 @@ int dataparser(unsigned char data[]) { //No match for configuration frame 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 + /* karthik changes*/ int freq = to_intconvertor(df->dpmu[0]->freq); if(util_map != 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)); } + /* karthik changes */ if((config_change == 14) ||(config_change == 10)) return config_change;