Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ergw_sbi_client #411

Merged
merged 11 commits into from
Jul 26, 2021
Merged
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ rebar3
ergw.config
data.ergw*
log.ergw*
apps/ergw_core/priv/*.so
apps/ergw_core/priv*
18 changes: 18 additions & 0 deletions apps/ergw/priv/schemas/ergw_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ components:
- "*"
ipv6_ue_interface_id:
$ref: TS29571_CommonData.yaml#/components/schemas/Ipv6Addr
upf_selection:
type: array
items:
type: string
prefered_bearer_type:
type: string
enum:
Expand Down Expand Up @@ -530,6 +534,20 @@ properties:
prefix:
type: integer
default: 0

sbi_client:
type: object
properties:
upf_selection:
type: object
properties:
endpoint:
$ref: 'TS29571_CommonData.yaml#/components/schemas/Uri'
timeout:
$ref: "#/components/schemas/TimeoutInf"
default:
type: string
required: ['endpoint', 'timeout', 'default']

accept_new:
default: true
Expand Down
2 changes: 1 addition & 1 deletion apps/ergw/src/ergw.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
prometheus_diameter_collector,
jsx, compiler, os_mon, jobs, ra,
riak_core, riak_core_lite_util,
ergw_cluster, ergw_core, ergw_aaa]},
ergw_cluster, ergw_core, ergw_aaa, ergw_sbi_client]},
{included_applications, [k8s_dist]},
{mod, {ergw_app, []}},
{registered, []}
Expand Down
19 changes: 17 additions & 2 deletions apps/ergw/src/ergw_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,21 @@ ergw_aaa_init(apps, #{apps := Apps0}) ->
ergw_aaa_init(_, _) ->
ok.

ergw_sbi_client_init(Opts) ->
ergw_sbi_client_config:validate_options(fun ergw_sbi_client_config:validate_option/2, Opts).

ergw_core_init(Config) ->
Init = [node, aaa, wait_till_running, path_management, node_selection,
sockets, upf_nodes, handlers, ip_pools, apns, charging, proxy_map,
http_api],
http_api, sbi_client],
lists:foreach(ergw_core_init(_, Config), Init).

ergw_core_init(node, #{node := Node}) ->
ergw_core:start_node(Node);
ergw_core_init(aaa, #{aaa := AAA}) ->
ergw_aaa_init(AAA);
ergw_core_init(sbi_client, #{sbi_client := SbiClient}) ->
ergw_sbi_client_init(SbiClient);
ergw_core_init(wait_till_running, _) ->
ergw_core:wait_till_running();
ergw_core_init(path_management, #{path_management := NodeSel}) ->
Expand Down Expand Up @@ -208,7 +213,8 @@ config_raw_meta() ->
proxy_map => config_meta_proxy_map(),
sockets => config_meta_socket(),
teid => config_meta_tei_mngr(),
aaa => config_meta_aaa()}.
aaa => config_meta_aaa(),
sbi_client => config_meta_sbi_client()}.

config_meta() ->
load_typespecs(),
Expand All @@ -229,6 +235,7 @@ config_meta_apns() ->
prefered_bearer_type => atom,
ipv6_ue_interface_id => ip6_ifid,
inactivity_timeout => timeout,
upf_selection => {list, atom},
'MS-Primary-DNS-Server' => ip4_address,
'MS-Secondary-DNS-Server' => ip4_address,
'MS-Primary-NBNS-Server' => ip4_address,
Expand Down Expand Up @@ -543,6 +550,14 @@ config_meta_tei_mngr() ->
#{prefix => integer,
len => integer}.

config_meta_sbi_client() ->
#{upf_selection => config_meta_sbi_client_upf_selection()}.

config_meta_sbi_client_upf_selection() ->
#{endpoint => string,
timeout => timeout,
default => string}.

config_meta_aaa() ->
#{product_name => config_meta_aaa_product_name(),
rate_limits => config_meta_aaa_rate_limits(),
Expand Down
10 changes: 10 additions & 0 deletions apps/ergw/test/config_SUITE_data/ggsn.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,15 @@
"teid": {
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
}
}
10 changes: 10 additions & 0 deletions apps/ergw/test/config_SUITE_data/ggsn_proxy.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,5 +392,15 @@
"teid": {
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
}
}
10 changes: 10 additions & 0 deletions apps/ergw/test/config_SUITE_data/pgw.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,5 +360,15 @@
"teid": {
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
}
}
10 changes: 10 additions & 0 deletions apps/ergw/test/config_SUITE_data/pgw_proxy.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,5 +439,15 @@
"teid": {
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
}
}
10 changes: 10 additions & 0 deletions apps/ergw/test/config_SUITE_data/saegw_s11.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,15 @@
"teid": {
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
}
}
10 changes: 10 additions & 0 deletions apps/ergw/test/config_SUITE_data/tdf.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,5 +303,15 @@
"teid": {
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
}
}
10 changes: 10 additions & 0 deletions apps/ergw/test/ergw_http_api_SUITE_data/ggsn.json
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,16 @@
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
},
"aaa": {
"apps": [
{
Expand Down
10 changes: 10 additions & 0 deletions apps/ergw/test/sbi_nbsf_SUITE_data/ipv4.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,16 @@
"len":0,
"prefix":0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
},
"upf_nodes":{
"default":{
"heartbeat":{
Expand Down
10 changes: 10 additions & 0 deletions apps/ergw/test/sbi_nbsf_SUITE_data/ipv6.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,16 @@
"len":0,
"prefix":0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
},
"upf_nodes":{
"default":{
"heartbeat":{
Expand Down
10 changes: 10 additions & 0 deletions apps/ergw/test/smc_SUITE_data/ggsn.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,16 @@
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
},
"aaa": {
"apps": [
{
Expand Down
10 changes: 10 additions & 0 deletions apps/ergw/test/smc_SUITE_data/ggsn_proxy.json
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,16 @@
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
},
"aaa": {
"apps": [
{
Expand Down
10 changes: 10 additions & 0 deletions apps/ergw/test/smc_SUITE_data/pgw.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,16 @@
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
},
"aaa": {
"apps": [
{
Expand Down
10 changes: 10 additions & 0 deletions apps/ergw/test/smc_SUITE_data/pgw_proxy.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,16 @@
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
},
"aaa": {
"apps": [
{
Expand Down
10 changes: 10 additions & 0 deletions apps/ergw/test/smc_SUITE_data/saegw_s11.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
},
"aaa": {
"apps": [
{
Expand Down
10 changes: 10 additions & 0 deletions apps/ergw/test/smc_SUITE_data/tdf.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,16 @@
"len": 0,
"prefix": 0
},
"sbi_client": {
"upf_selection": {
"endpoint": "https://example.com/nf-selection-api/v1",
"timeout": {
"timeout": 500,
"unit": "millisecond"
},
"default": "fallback"
}
},
"aaa": {
"apps": [
{
Expand Down
24 changes: 23 additions & 1 deletion apps/ergw_core/src/ergw_apn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ get(_, _) ->
{bearer_type, 'IPv4v6'},
{prefered_bearer_type, 'IPv6'},
{ipv6_ue_interface_id, default},
{inactivity_timeout, 48 * 3600 * 1000} %% 48hrs timer in msecs
{inactivity_timeout, 48 * 3600 * 1000}, %% 48hrs timer in msecs
{upf_selection, ['3gpp']}
]).

validate_options({APN0, Value}) when ?is_opts(Value) ->
Expand Down Expand Up @@ -113,6 +114,9 @@ validate_apn_option({ipv6_ue_interface_id, {0,0,0,0,E,F,G,H}} = Opt)
G >= 0, G < 65536, H >= 0, H < 65536,
(E + F + G + H) =/= 0 ->
Opt;
validate_apn_option({upf_selection, List} = Opt) ->
lists:foreach(fun validate_upf_selection/1, List),
Opt;
validate_apn_option({Opt, Value})
when Opt == 'MS-Primary-DNS-Server'; Opt == 'MS-Secondary-DNS-Server';
Opt == 'MS-Primary-NBNS-Server'; Opt == 'MS-Secondary-NBNS-Server';
Expand All @@ -124,3 +128,21 @@ validate_apn_option({Opt = inactivity_timeout, Timer})
{Opt, Timer};
validate_apn_option({Opt, Value}) ->
erlang:error(badarg, [Opt, Value]).

validate_upf_selection('3gpp') ->
ok;
validate_upf_selection(M) when is_atom(M) ->
case code:ensure_loaded(M) of
{module, _} ->
ok;
_ ->
erlang:error(badarg, [apn, upf_selection, M])
end,
case erlang:function_exported(M, upf_selection, 1) of
true ->
ok;
false ->
erlang:error(badarg, [apn, upf_selection, M])
end;
validate_upf_selection(Opt) ->
erlang:error(badarg, [apn, upf_selection, Opt]).
Loading