fix
This commit is contained in:
parent
fef8247944
commit
9f39cf4852
42
apps/sdlan/include/policy.hrl
Normal file
42
apps/sdlan/include/policy.hrl
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @author anlicheng
|
||||||
|
%%% @copyright (C) 2026, <COMPANY>
|
||||||
|
%%% @doc
|
||||||
|
%%%
|
||||||
|
%%% @end
|
||||||
|
%%% Created : 28. 2月 2026 15:25
|
||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
-author("anlicheng").
|
||||||
|
|
||||||
|
-record(identity, {
|
||||||
|
identity_id :: integer(),
|
||||||
|
network_id :: integer(),
|
||||||
|
subject_type,
|
||||||
|
created_at :: integer(),
|
||||||
|
expired_at :: integer()
|
||||||
|
}).
|
||||||
|
|
||||||
|
-record(identity_policy, {
|
||||||
|
identity_id :: integer(),
|
||||||
|
policy_id :: integer()
|
||||||
|
}).
|
||||||
|
|
||||||
|
-record(policy, {
|
||||||
|
policy_id :: integer(),
|
||||||
|
network_id :: integer(),
|
||||||
|
name :: binary(),
|
||||||
|
created_at = 0 :: integer()
|
||||||
|
}).
|
||||||
|
|
||||||
|
-record(rule, {
|
||||||
|
rule_id :: integer(),
|
||||||
|
policy_id :: integer(),
|
||||||
|
network_id :: integer(),
|
||||||
|
access_rule_id :: integer(),
|
||||||
|
src_policy_id :: integer(),
|
||||||
|
dst_policy_id :: integer(),
|
||||||
|
proto :: integer(),
|
||||||
|
port :: integer(),
|
||||||
|
action,
|
||||||
|
created_at = 0 :: integer()
|
||||||
|
}).
|
||||||
21
apps/sdlan/src/policy/identity_ets.erl
Normal file
21
apps/sdlan/src/policy/identity_ets.erl
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
-module(identity_ets).
|
||||||
|
-include("policy.hrl").
|
||||||
|
|
||||||
|
-export([init/0]).
|
||||||
|
-export([lookup/1, insert/1]).
|
||||||
|
|
||||||
|
-define(TABLE, identity_ets_table).
|
||||||
|
|
||||||
|
init() ->
|
||||||
|
ets:new(?TABLE, [named_table, ordered_set, public, {keypos, 2}, {read_concurrency, true}]).
|
||||||
|
|
||||||
|
lookup(IdentityId) when is_integer(IdentityId) ->
|
||||||
|
case ets:lookup(?TABLE, IdentityId) of
|
||||||
|
[Identity] ->
|
||||||
|
{ok, Identity};
|
||||||
|
[] ->
|
||||||
|
error
|
||||||
|
end.
|
||||||
|
|
||||||
|
insert(Identity = #identity{}) ->
|
||||||
|
true = ets:insert(?TABLE, Identity).
|
||||||
17
apps/sdlan/src/policy/identity_policy_ets.erl
Normal file
17
apps/sdlan/src/policy/identity_policy_ets.erl
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
-module(identity_policy_ets).
|
||||||
|
-include("policy.hrl").
|
||||||
|
|
||||||
|
-export([init/0]).
|
||||||
|
-export([lookup/1, insert/1]).
|
||||||
|
|
||||||
|
-define(TABLE, identity_policy_ets_table).
|
||||||
|
|
||||||
|
init() ->
|
||||||
|
ets:new(?TABLE, [named_table, bag, public, {keypos, 2}, {read_concurrency, true}]).
|
||||||
|
|
||||||
|
lookup(IdentityId) when is_integer(IdentityId) ->
|
||||||
|
Records = ets:lookup(?TABLE, IdentityId),
|
||||||
|
lists:map(fun(#identity_policy{policy_id = PolicyId}) -> PolicyId end, Records).
|
||||||
|
|
||||||
|
insert(IdentityPolicy = #identity_policy{}) ->
|
||||||
|
true = ets:insert(?TABLE, IdentityPolicy).
|
||||||
16
apps/sdlan/src/policy/policy_ets.erl
Normal file
16
apps/sdlan/src/policy/policy_ets.erl
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
-module(policy_ets).
|
||||||
|
-include("policy.hrl").
|
||||||
|
|
||||||
|
-export([init/0]).
|
||||||
|
-export([lookup/1, insert/1]).
|
||||||
|
|
||||||
|
-define(TABLE, policy_ets_table).
|
||||||
|
|
||||||
|
init() ->
|
||||||
|
ets:new(?TABLE, [named_table, ordered_set, public, {keypos, 2}, {read_concurrency, true}]).
|
||||||
|
|
||||||
|
lookup(PolicyId) when is_integer(PolicyId) ->
|
||||||
|
Records = ets:lookup(?TABLE, PolicyId).
|
||||||
|
|
||||||
|
insert(Policy = #policy{}) ->
|
||||||
|
true = ets:insert(?TABLE, Policy).
|
||||||
16
apps/sdlan/src/policy/rule_ets.erl
Normal file
16
apps/sdlan/src/policy/rule_ets.erl
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
-module(rule_ets).
|
||||||
|
-include("policy.hrl").
|
||||||
|
|
||||||
|
-export([init/0]).
|
||||||
|
-export([lookup/1, insert/1]).
|
||||||
|
|
||||||
|
-define(TABLE, policy_ets_table).
|
||||||
|
|
||||||
|
init() ->
|
||||||
|
ets:new(?TABLE, [named_table, ordered_set, public, {keypos, 2}, {read_concurrency, true}]).
|
||||||
|
|
||||||
|
lookup(PolicyId) when is_integer(PolicyId) ->
|
||||||
|
Records = ets:lookup(?TABLE, PolicyId).
|
||||||
|
|
||||||
|
insert(Rule = #rule{}) ->
|
||||||
|
true = ets:insert(?TABLE, Rule).
|
||||||
Loading…
x
Reference in New Issue
Block a user