blob: 72637ecac57f47dc3f00f1a00f9a7b01eef5b75c [file] [log] [blame]
Harald Weltec6e466e2011-10-10 14:03:50 +02001% OTP Supervisor for Osmocom SCCP
2
3% (C) 2011 by Harald Welte <laforge@gnumonks.org>
4%
5% All Rights Reserved
6%
7% This program is free software; you can redistribute it and/or modify
8% it under the terms of the GNU Affero General Public License as
9% published by the Free Software Foundation; either version 3 of the
10% License, or (at your option) any later version.
11%
12% This program is distributed in the hope that it will be useful,
13% but WITHOUT ANY WARRANTY; without even the implied warranty of
14% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15% GNU General Public License for more details.
16%
17% You should have received a copy of the GNU Affero General Public License
18% along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Weltef8bf0322012-04-16 13:10:47 +020019%
20% Additional Permission under GNU AGPL version 3 section 7:
21%
22% If you modify this Program, or any covered work, by linking or
23% combining it with runtime libraries of Erlang/OTP as released by
24% Ericsson on http://www.erlang.org (or a modified version of these
25% libraries), containing parts covered by the terms of the Erlang Public
26% License (http://www.erlang.org/EPLICENSE), the licensors of this
27% Program grant you additional permission to convey the resulting work
28% without the need to license the runtime libraries of Erlang/OTP under
29% the GNU Affero General Public License. Corresponding Source for a
30% non-source form of such a combination shall include the source code
31% for the parts of the runtime libraries of Erlang/OTP used as well as
32% that of the covered work.
Harald Weltec6e466e2011-10-10 14:03:50 +020033
34-module(osmo_ss7_sup).
35-behavior(supervisor).
36
37-export([start_link/0, add_mtp_link/1]).
38-export([init/1]).
39
40-include_lib("osmo_ss7/include/osmo_ss7.hrl").
41
42start_link() ->
43 supervisor:start_link({local, ?MODULE}, ?MODULE, [{debug, [trace]}]).
44
45init(Args) ->
46 LinksChild = {ss7_links, {ss7_links, start_link, []},
47 permanent, 2000, worker, [ss7_links]},
Harald Welteb8bfc4e2011-10-11 18:49:59 +020048 RouteChild = {ss7_routes, {ss7_routes, start_link, []},
49 permanent, 2000, worker, [ss7_routes]},
50 {ok,{{one_for_one,60,600}, [LinksChild, RouteChild]}}.
Harald Weltec6e466e2011-10-10 14:03:50 +020051
52% Add a m3ua link to this supervisor
53add_mtp_link(L=#sigtran_link{type = m3ua, name = Name,
54 local = Local, remote = Remote}) ->
55 ChildName = list_to_atom("ss7_link_m3ua_" ++ Name),
56 ChildSpec = {ChildName, {ss7_link_m3ua, start_link, [L]},
Harald Welte8fa297d2011-10-10 19:32:13 +020057 permanent, 2000, worker, [ss7_link_m3ua]},
Harald Weltec6e466e2011-10-10 14:03:50 +020058 supervisor:start_child(?MODULE, ChildSpec);
Harald Welte5c9f3b52013-07-26 22:40:25 +080059add_mtp_link(L=#sigtran_link{type = m2ua, name = Name,
60 local = Local, remote = Remote}) ->
61 ChildName = list_to_atom("ss7_link_m2ua_" ++ Name),
62 ChildSpec = {ChildName, {ss7_link_m2ua, start_link, [L]},
63 permanent, 2000, worker, [ss7_link_m2ua]},
64 supervisor:start_child(?MODULE, ChildSpec);
Harald Welte5cde7622012-01-23 23:18:28 +010065add_mtp_link(L=#sigtran_link{type = ipa_client, name = Name}) ->
66 ChildName = list_to_atom("ss7_link_ipa_client_" ++ Name),
67 ChildSpec = {ChildName, {ss7_link_ipa_client, start_link, [L]},
68 permanent, 2000, worker, [ss7_link_ipa_client]},
69 supervisor:start_child(?MODULE, ChildSpec);
Harald Weltec6e466e2011-10-10 14:03:50 +020070add_mtp_link([]) ->
71 ok;
72add_mtp_link([Head|Tail]) ->
73 add_mtp_link(Head, Tail).
74add_mtp_link(Head, Tail) ->
75 {ok, _Child} = add_mtp_link(Head),
76 add_mtp_link(Tail).