Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :- dynamic time/2.
- :- dynamic attacks/2.
- :- dynamic attack_prob/2.
- elem(zero,0).
- elem(low,20).
- elem(below_medium,40).
- elem(above_medium,60).
- elem(high,80).
- elem(definite,100).
- timeFuzzification(DurationTime):-
- DurationTime =< 10, Rang is (10 - DurationTime) / 10 ,assert(time(tiny,Rang)),fail;
- DurationTime =< 10, Rang is DurationTime / 10 ,assert(time(small,Rang)),fail;
- DurationTime > 10, DurationTime =< 40, Rang is (40 - DurationTime) / (40 - 10) ,assert(time(small,Rang)),fail;
- DurationTime > 10, DurationTime =< 40, Rang is (DurationTime - 10) / (40 - 10) ,assert(time(medium,Rang)),fail;
- DurationTime > 40, DurationTime =< 150, Rang is (40- - DurationTime) / (150 - 40) ,assert(time(medium,Rang)),fail;
- DurationTime > 40, DurationTime =< 150, Rang is (DurationTime - 40) / (150 - 40) ,assert(time(large,Rang)),fail;
- DurationTime > 150, Rang is 1 , assert(time(large,Rang)),fail;
- true.
- packetsFuzzification(PacketsNumber):-
- PacketsNumber =< 10, Rang is (10 - PacketsNumber) / 10 ,assert(attacks(few,Rang)),fail;
- PacketsNumber =< 10, Rang is PacketsNumber / 10 ,assert(attacks(medium,Rang)),fail;
- PacketsNumber > 10, PacketsNumber =< 300, Rang is (300 - PacketsNumber) / (300 - 10) ,assert(attacks(medium,Rang)),fail;
- PacketsNumber > 10, PacketsNumber =< 300, Rang is (PacketsNumber - 10) / (300 - 10) ,assert(attacks(many,Rang)),fail;
- PacketsNumber > 300, PacketsNumber =< 1000, Rang is (1000 - PacketsNumber) / (1000 - 300) ,assert(attacks(many,Rang)),fail;
- PacketsNumber > 300, PacketsNumber =< 1000, Rang is (PacketsNumber - 300) / (1000 - 300) ,assert(attacks(enormous,Rang)),fail;
- PacketsNumber > 10000, Rang is 1 , assert(attacks(enormous,Rang)),fail;
- true.
- control_block_impl(DurationTime,Rt,PacketsNumber,Ra):-
- DurationTime == tiny,(
- PacketsNumber == few, Rang is min(Rt,Ra),assert(attack_prob(zero,Rang));
- PacketsNumber == medium, Rang is min(Rt,Ra),assert(attack_prob(below_medium,Rang));
- PacketsNumber == many, Rang is min(Rt,Ra),assert(attack_prob(above_medium,Rang));
- PacketsNumber == enormous, Rang is min(Rt,Ra),assert(attack_prob(definite,Rang))
- );
- DurationTime == small,(
- PacketsNumber == few, Rang is min(Rt,Ra),assert(attack_prob(zero,Rang));
- PacketsNumber == medium, Rang is min(Rt,Ra),assert(attack_prob(low,Rang));
- PacketsNumber == many, Rang is min(Rt,Ra),assert(attack_prob(above_medium,Rang));
- PacketsNumber == enormous, Rang is min(Rt,Ra),assert(attack_prob(definite,Rang))
- );
- DurationTime == medium,(
- PacketsNumber == few, Rang is min(Rt,Ra),assert(attack_prob(zero,Rang));
- PacketsNumber == medium, Rang is min(Rt,Ra),assert(attack_prob(low,Rang));
- PacketsNumber == many, Rang is min(Rt,Ra),assert(attack_prob(below_medium,Rang));
- PacketsNumber == enormous, Rang is min(Rt,Ra),assert(attack_prob(above_medium,Rang))
- );
- DurationTime == large,(
- PacketsNumber == few, Rang is min(Rt,Ra),assert(attack_prob(zero,Rang));
- PacketsNumber == medium, Rang is min(Rt,Ra),assert(attack_prob(zero,Rang));
- PacketsNumber == many, Rang is min(Rt,Ra),assert(attack_prob(low,Rang));
- PacketsNumber == enormous, Rang is min(Rt,Ra),assert(attack_prob(below_medium,Rang))
- ).
- control_block():-
- time(T,Rt), attacks(A,Ra), control_block_impl(T,Rt,A,Ra), fail;
- true.
- sum_res(Nominator, Denominator, Nres, Dres) :-
- attack_prob(Fuzzy_set,Rang),
- elem(Fuzzy_set,A),
- Area is 10 * (2 * Rang - Rang * Rang),
- NextNominator is Nominator + A * Area,
- NextDenominator is Denominator + Area,
- retract(attack_prob(Fuzzy_set,Rang)),
- sum_res(NextNominator, NextDenominator, Nres, Dres).
- sum_res(N,D,N,D).
- defuzzification(Result):-
- sum_res(0,0,N,D), Result is N / D.
- syn_flood():-
- write("Response time = "), read(Time),
- write("SYN = "), read(SYN),
- write("ACK = "), read(ACK),
- retractall(time(_,_)),retractall(attacks(_,_)),
- timeFuzzification(Time),
- Packets is SYN - ACK,
- packetsFuzzification(Packets),
- control_block(),
- defuzzification(Result),
- format("SYN-flood probability is ~f.\n", Result).
Add Comment
Please, Sign In to add comment