test rules

This commit is contained in:
anlicheng 2026-03-04 16:17:27 +08:00
parent 9351cabdee
commit b009a324bd

View File

@ -26,6 +26,7 @@
%% API %% API
-export([start_link/2]). -export([start_link/2]).
-export([send_event/3, stop/2]). -export([send_event/3, stop/2]).
-export([test_rules/2]).
%% gen_statem callbacks %% gen_statem callbacks
-export([init/1, handle_event/4, terminate/3, code_change/4, callback_mode/0]). -export([init/1, handle_event/4, terminate/3, code_change/4, callback_mode/0]).
@ -59,6 +60,12 @@
%%% API %%% API
%%%=================================================================== %%%===================================================================
%%
test_rules(SrcIdentityId, DstIdentityId) when is_integer(SrcIdentityId), is_integer(DstIdentityId) ->
{ok, Rules} = get_rules(SrcIdentityId, DstIdentityId),
logger:debug("[sdlan_channel] policy_request src_identity_id: ~p, dst_identity_id: ~p, rules: ~p", [SrcIdentityId, DstIdentityId, Rules]),
iolist_to_binary(lists:map(fun({Proto, Port}) -> <<Proto:8, Port:16>> end, Rules)).
-spec send_event(Pid :: pid(), EventType :: integer(), Event :: binary()) -> no_return(). -spec send_event(Pid :: pid(), EventType :: integer(), Event :: binary()) -> no_return().
send_event(Pid, EventType, Event) when is_pid(Pid), is_integer(EventType), is_binary(Event) -> send_event(Pid, EventType, Event) when is_pid(Pid), is_integer(EventType), is_binary(Event) ->
gen_statem:cast(Pid, {send_event, EventType, Event}). gen_statem:cast(Pid, {send_event, EventType, Event}).