Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Salience #28

Open
anton-b opened this issue Nov 2, 2017 · 0 comments
Open

Salience #28

anton-b opened this issue Nov 2, 2017 · 0 comments

Comments

@anton-b
Copy link

anton-b commented Nov 2, 2017

Hello, I have a question regarding the usage of Salience of the rules.

-module(rules2).

%% API
-export([init/0, retr_rule/3, connection_blocked/3, add/0, add_rules/0]).
-rules([
    {retr_rule, 3},
    {connection_blocked, 1}
]).

execute() ->
    init(),
    add_rules(),
    add().

init() ->
    application:ensure_all_started(seresye),
    seresye:start(t).

add_rules() ->
    seresye:add_rules(t, rules2).
%%    seresye:add_rule(t, {rules2, retr_rule}, 3),
%%    seresye:add_rule(t, {rules2,connection_blocked}, 1).

add() ->
    seresye:assert(t,
                   [{fact, allow, 1},
                    {fact, block, 2},
                    {fact, block, 3},
                    {fact, allow, 4},
                    {fact, block, 5},
                    {fact, allow, 6},
                    {fact, block, 7},
                    {fact, allow, 8},
                    {fact, block, 9},
                    {fact, allow, 10},
                    {fact, block, 11}]).

connection_blocked(EngineState, {fact, block, Blocking}, {fact, allow, Allowing}) when Blocking < Allowing ->
    seresye_engine:assert(EngineState, {fact_blocked, Blocking}).

retr_rule(EngineState, {fact, Action, A}, {fact, Action, B} = FB) when A < B ->
    seresye_engine:retract(EngineState, FB).

It is model code for evaluating a firewall rules list with some priority numbers. The smaller the number the bigger priority rule has.

retr_rule with salience 3 if i understood correctly from the docs should be executed first and filter out all of the {fact, allow|block, integer()} except of 2 top ones with number 1 and 2.

connection_blocked with smaller salience of 1 should be executed after retr_rule stopped firing.

But as the result i get the following:

1> rules2:execute().
ok
2> seresye:get_kb(t).
[{fact_blocked,2},{fact,block,2},{fact,allow,1}]

Which contradicts to the intended logic. Am I missing something or that is a bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant