1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2010-2020. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20 21-module(redirect). 22 23%% 24%% An example Diameter redirect agent. 25%% 26%% Simplest usage to listen on TCP at 127.0.0.1:3868. 27%% 28%% redirect:start(). 29%% redirect:listen(tcp). 30%% 31 32%% Interface. 33-export([start/1, 34 listen/2, 35 stop/1]). 36 37%% Convenience functions using the default service name. 38-export([start/0, 39 listen/1, 40 stop/0]). 41 42-define(DEF_SVC_NAME, ?MODULE). 43 44%% The service configuration. 45-define(SERVICE(Name), [{'Origin-Host', atom_to_list(Name) ++ ".example.com"}, 46 {'Origin-Realm', "example.com"}, 47 {'Vendor-Id', 193}, 48 {'Product-Name', "RedirectAgent"}, 49 {'Auth-Application-Id', [16#FFFFFFFF]}, 50 {decode_format, map}, 51 {restrict_connections, false}, 52 {strict_mbit, false}, 53 {string_decode, false}, 54 {application, [{alias, redirect}, 55 {dictionary, diameter_gen_relay}, 56 {module, redirect_cb}, 57 {call_mutates_state, false}]}]). 58 59%% start/0 60 61start() -> 62 start(?DEF_SVC_NAME). 63 64%% start/1 65 66start(Name) 67 when is_atom(Name) -> 68 start(Name, []); 69 70start(Opts) 71 when is_list(Opts) -> 72 start(?DEF_SVC_NAME, Opts). 73 74%% start/2 75 76start(Name, Opts) -> 77 Defaults = [T || {K,_} = T <- ?SERVICE(Name), 78 not lists:keymember(K, 1, Opts)], 79 diameter:start_service(Name, Opts ++ Defaults). 80 81%% listen/2 82 83listen(Name, Opts) -> 84 server:listen(Name, Opts). 85 86%% listen/1 87 88listen(Opts) -> 89 listen(?DEF_SVC_NAME, Opts). 90 91%% stop/1 92 93stop(Name) -> 94 diameter:stop_service(Name). 95 96%% stop.0 97 98stop() -> 99 stop(?DEF_SVC_NAME). 100