Done with atteck detect function

This commit is contained in:
pavanvpatil 2022-09-25 00:16:42 +05:30
parent 50dc610c43
commit 3e87203535
4 changed files with 54 additions and 41 deletions

View File

@ -1 +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 */

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

@ -74,47 +74,10 @@
/* pavan changes */ /* pavan changes */
/* variables declared */ /* variables declared of attack_detect function */
float SUM_OF_FREQUENCY=0; float SUM_OF_FREQUENCY=0;
float COUNT=0; float COUNT=0;
float THRESHOLD=25;
double time_used;
time_t START; time_t START;
void attack_detect(struct data_frame *df)
{
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);
if(DETECT_PERCENT>THRESHOLD)
printf("ATTACK DETECTED\n");
else
printf("NO PROBLEM\n");
if(COUNT==1)
time(&START);
time_t END;
time(&END);
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 */ /* pavan changes */
@ -1319,7 +1282,7 @@ int dataparser(unsigned char data[]) {
} }
/*pavan changes*/ /*pavan changes*/
attack_detect(df); attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
/*pavan changes*/ /*pavan changes*/
// temp code // temp code