FINAL Attack detect 25 sept pavan

This commit is contained in:
pavanvpatil 2022-09-25 16:24:02 +05:30
parent 3e87203535
commit 57d08a0516
3 changed files with 28 additions and 20 deletions

View File

@ -6,36 +6,45 @@
void attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_OF_FREQUENCY) void attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_OF_FREQUENCY)
{ {
// printf("freq: %d\n",to_intconvertor(&(df->dpmu[0]->fmt->freq)));
// printf("analog: %d\n",to_intconvertor(&(df->dpmu[0]->fmt->analog)));
// printf("phasor %d\n",to_intconvertor(&(df->dpmu[0]->fmt->phasor)));
// printf("polar: %d\n",to_intconvertor(&(df->dpmu[0]->fmt->polar)));
*COUNT = *COUNT+1; *COUNT = *COUNT+1;
printf("count: %f\n",*COUNT);
float CURR_FREQ=to_intconvertor(df->dpmu[0]->freq); float CURR_FREQ=to_intconvertor(df->dpmu[0]->freq);
*SUM_OF_FREQUENCY+=CURR_FREQ; *SUM_OF_FREQUENCY+=CURR_FREQ;
float FREQ_AVG=*SUM_OF_FREQUENCY/(*COUNT*1.0f); float FREQ_AVG=*SUM_OF_FREQUENCY/(*COUNT*1.0f);
float DETECT_PERCENT=(abs(FREQ_AVG-CURR_FREQ)/(FREQ_AVG*1.0f))*100; float DETECT_PERCENT=(abs(FREQ_AVG-CURR_FREQ)/(FREQ_AVG*1.0f))*100;
printf("Detect_percent: %f\n",DETECT_PERCENT); /* detecting based on thershold */
printf("frequency average: %f\n",FREQ_AVG); float THRESHOLD=70;
float THRESHOLD=25;
if(DETECT_PERCENT>THRESHOLD) if(DETECT_PERCENT>THRESHOLD)
printf("ATTACK DETECTED\n"); {
printf("\033[0;31m");
printf("ATTACK DETECTED!");
printf("\033[0m");
printf(" Detect_percent: %f\n",DETECT_PERCENT);
}
else else
printf("NO PROBLEM\n"); {
printf("\033[0;32m");
printf("NO PROBLEM :)\n");
printf("\033[0m");
}
/* calcculating time */
if(*COUNT==1) if(*COUNT==1)
{ {
time(START); time(START);
printf("entered\n"); printf("entered\n");
} }
time_t END; time_t END;
time(&END); time(&END);
double time_used = difftime(END,*START); double time_used = difftime(END,*START);
printf("time used %lf\n",time_used); printf("time used %lf\n",time_used);
/* resetting after i minute */
if(time_used > 60) if(time_used > 60)
{ {
time(START); time(START);

View File

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

View File

@ -73,14 +73,6 @@
/* ---------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------- */
/* 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;