Compare commits

...

3 Commits

Author SHA1 Message Date
pavanvpatil 3e87203535 Done with atteck detect function 2022-09-25 00:16:42 +05:30
pavanvpatil 50dc610c43 UPDATED attack detect function 2022-09-24 23:36:34 +05:30
pavanvpatil 1edf6729e2 AI attack_detect function 2022-09-24 16:45:28 +05:30
4 changed files with 71 additions and 3 deletions

47
iPDC/Attack_detect.c Normal file
View File

@ -0,0 +1,47 @@
/* pavan changes */
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include "parser.h"
void attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_OF_FREQUENCY)
{
*COUNT = *COUNT+1;
printf("count: %f\n",*COUNT);
float CURR_FREQ=to_intconvertor(df->dpmu[0]->freq);
*SUM_OF_FREQUENCY+=CURR_FREQ;
float FREQ_AVG=*SUM_OF_FREQUENCY/(*COUNT*1.0f);
float DETECT_PERCENT=(abs(FREQ_AVG-CURR_FREQ)/(FREQ_AVG*1.0f))*100;
printf("Detect_percent: %f\n",DETECT_PERCENT);
printf("frequency average: %f\n",FREQ_AVG);
float THRESHOLD=25;
if(DETECT_PERCENT>THRESHOLD)
printf("ATTACK DETECTED\n");
else
printf("NO PROBLEM\n");
if(*COUNT==1)
{
time(START);
printf("entered\n");
}
time_t END;
time(&END);
double time_used = difftime(END,*START);
printf("time used %lf\n",time_used);
if(time_used > 60)
{
time(START);
*SUM_OF_FREQUENCY=CURR_FREQ;
*COUNT=1;
}
}
/* pavan changes */

3
iPDC/Attack_detect.h Normal file
View File

@ -0,0 +1,3 @@
/* pavan changes */
void attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_OF_FREQUENCY);
/* pavan changes */

View File

@ -60,9 +60,10 @@ SOURCES = \
ipdcGui.c ipdcGui.h \ ipdcGui.c ipdcGui.h \
attack_detection.c attack_detection.h \ attack_detection.c attack_detection.h \
data_vis.c data_vis.h \ data_vis.c data_vis.h \
utility_tools.c utility_tools.h utility_tools.c utility_tools.h \
Attack_detect.c Attack_detect.h
OBJECTS = ipdc.c recreate.o connections.o new_pmu_or_pdc.o parser.o dallocate.o align_sort.o ipdcGui.o attack_detection.o data_vis.o utility_tools.o OBJECTS = ipdc.c recreate.o connections.o new_pmu_or_pdc.o parser.o dallocate.o align_sort.o ipdcGui.o attack_detection.o data_vis.o utility_tools.o Attack_detect.o
CLEAN_OBJECTS = recreate.o connections.o new_pmu_or_pdc.o parser.o dallocate.o align_sort.o ipdcGui.o ~iPDC.xml CLEAN_OBJECTS = recreate.o connections.o new_pmu_or_pdc.o parser.o dallocate.o align_sort.o ipdcGui.o ~iPDC.xml

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(): */
@ -70,6 +72,15 @@
/* also in the file `cfg.bin` by calling */ /* also in the file `cfg.bin` by calling */
/* ---------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------- */
/* pavan changes */
/* variables declared of attack_detect function */
float SUM_OF_FREQUENCY=0;
float COUNT=0;
time_t START;
/* pavan changes */
void cfgparser(unsigned char st[]){ void cfgparser(unsigned char st[]){
unsigned char *s; unsigned char *s;
@ -1269,8 +1280,13 @@ 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*/
attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
/*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 +1302,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;