From: <et...@us...> - 2003-11-10 13:42:33
|
Update of /cvsroot/jungerl/jungerl/lib/eradius/test In directory sc8-pr-cvs1:/tmp/cvs-serv16008/test Modified Files: et.erl Log Message: Fixed up the Radius accounting Index: et.erl =================================================================== RCS file: /cvsroot/jungerl/jungerl/lib/eradius/test/et.erl,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- et.erl 5 Nov 2003 20:39:26 -0000 1.3 +++ et.erl 10 Nov 2003 13:42:29 -0000 1.4 @@ -5,17 +5,43 @@ %%% Purpose : eradius test code %%% Created : 25 Sep 2003 by Torbjorn Tornkvist <to...@bl...> %%%---------------------------------------------------------------------- --export([local/0, duva/1]). +-export([local/0, duva/1, acc/0]). +-export([go/5]). +-include_lib("kernel/include/inet.hrl"). -include("eradius.hrl"). +-include("eradius_lib.hrl"). -include("eradius_dict.hrl"). +-include("dictionary_alteon.hrl"). +-import(eradius_acc, + [set_user/2, set_nas_ip_address/1, set_nas_ip_address/2, + set_login_time/1, set_logout_time/1, set_session_id/2, new/0, + set_radacct/1, set_attr/3, set_vend_attrs/2, acc_update/1, + set_servers/2, set_timeout/2, set_login_time/2, set_vendor_id/2, + set_logout_time/2, set_tc_ureq/1, set_tc_itimeout/1, + set_tc_areset/1, set_tc_areboot/1, set_tc_nasreboot/1]). + + +%%% Radius shortcuts local() -> go({127,0,0,1}, "tobbe", "qwe123", "qwe123", {127,0,0,1}). duva(Passwd) -> go({192,168,128,1}, "support", Passwd, Passwd, {192,168,128,32}). +%%% Server for Radius accounting +radacct_servers() -> + %% + %% list_of( [IP, Port, SharedSecret] ) + %% + [[{192,168,128,51}, 1813, "mortuta42"]]. + + +%%% -------------------------------- +%%% Radius authentication test case. +%%% -------------------------------- + go(IP, User, Passwd, Shared, NasIP) -> TraceFun = fun(_E,Str,Args) -> io:format(Str,Args), @@ -52,6 +78,114 @@ pa(As); pa([]) -> true. + + +%%% -------------------------------- +%%% Radius accounting test case. +%%% -------------------------------- + +%%% Reasons for session termination +-define(REASON_LOGOUT, 1). +-define(REASON_TIMEOUT, 2). +-define(REASON_RESET, 3). +-define(REASON_REBOOT, 4). +-define(REASON_TERMINATE, 5). + + +acc() -> + eradius:start(), + eradius_acc:start(), + eradius:load_tables(["dictionary", + "dictionary_alteon"]), + User = "tobbe", + SessionId = 42, + R = acc_start(User, SessionId), + Login = R#rad_accreq.login_time, + sleep(10), + VendAttrs = [{?Alteon, [{?Alteon_ASA_Audit_Trail, "This is a test!"}]}], + acc_update(User, SessionId, VendAttrs), + sleep(10), + acc_stop(User, SessionId, Login, ?REASON_LOGOUT). + + +acc_start(User, SessId) -> + Srvs = radacct_servers(), + NasIP = nas_ip_address(), + A = eradius_acc:new(), + R = set_session_id( + set_user( + set_servers( + set_nas_ip_address( + set_login_time(A), + NasIP), + Srvs), + User), + SessId), + eradius_acc:acc_start(R), + R. + + +acc_stop(User, SessId, Login, Reason) -> + Srvs = radacct_servers(), + NasIP = nas_ip_address(), + Logout = erlang:now(), + A = eradius_acc:new(), + R = set_stop_reason( + set_logout_time( + set_login_time( + set_session_id( + set_user( + set_servers( + set_nas_ip_address(A, NasIP), + Srvs), + User), + SessId), + Login), + Logout), + Reason), + eradius_acc:acc_stop(R), + R. + +acc_update(User, SessId, VendAttrs) -> + Srvs = radacct_servers(), + NasIP = nas_ip_address(), + A = eradius_acc:new(), + R = set_vend_attrs( + set_session_id( + set_user( + set_servers( + set_nas_ip_address(A, NasIP), + Srvs), + User), + SessId), + VendAttrs), + eradius_acc:acc_update(R), + R. + + +set_stop_reason(R, ?REASON_LOGOUT) -> set_tc_ureq(R); +set_stop_reason(R, ?REASON_TIMEOUT) -> set_tc_itimeout(R); +set_stop_reason(R, ?REASON_RESET) -> set_tc_areset(R); +set_stop_reason(R, ?REASON_REBOOT) -> set_tc_areboot(R); +set_stop_reason(R, ?REASON_TERMINATE) -> set_tc_nasreboot(R). + +%%% ----------------- +%%% Misc. stuff +%%% ----------------- + +%%% Our own IP address +nas_ip_address() -> + case catch inet:gethostbyname(element(2,inet:gethostname())) of + {ok,H} when record(H,hostent) -> + hd(H#hostent.h_addr_list); + _ -> + io:format("WARNING: failed to get local IP address!~n",[]), + "192.168.42.42" + end. + +sleep(Sec) -> + receive after Sec*1000 -> true end. + to_list(B, string) -> binary_to_list(B); to_list(B, octets) -> B; |