UPDATED attack detect function
This commit is contained in:
parent
1edf6729e2
commit
50dc610c43
|
@ -1,30 +1 @@
|
|||
#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 */
|
|
@ -1,14 +0,0 @@
|
|||
/* 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 */
|
|
@ -72,6 +72,52 @@
|
|||
/* also in the file `cfg.bin` by calling */
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
/* pavan changes */
|
||||
/* variables declared */
|
||||
float SUM_OF_FREQUENCY=0;
|
||||
float COUNT=0;
|
||||
float THRESHOLD=25;
|
||||
double time_used;
|
||||
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 */
|
||||
|
||||
|
||||
void cfgparser(unsigned char st[]){
|
||||
|
||||
unsigned char *s;
|
||||
|
@ -1273,9 +1319,7 @@ int dataparser(unsigned char data[]) {
|
|||
}
|
||||
|
||||
/*pavan changes*/
|
||||
//#include "Attack_detect.h"
|
||||
//clock_t START = clock();
|
||||
//attack_detect(df,START);
|
||||
attack_detect(df);
|
||||
/*pavan changes*/
|
||||
|
||||
// temp code
|
||||
|
|
Loading…
Reference in New Issue