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 global node_id config setting and use it in PFCP #278

Merged
merged 1 commit into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ Then fill just created **ergw.config** file with content like described below pr
{ip, {0,0,0,0}}
]},

{node_id, <<"pgw.$ORIGIN">>},
{sockets,
[{cp, [{type, 'gtp-u'},
{vrf, cp},
Expand All @@ -314,9 +315,7 @@ Then fill just created **ergw.config** file with content like described below pr
{ip, {127,0,0,1}},
{reuseaddr, true}
]},
{sx, [{node, 'ergw'},
{name, 'ergw'},
{type, 'pfcp'},
{sx, [{type, 'pfcp'},
{socket, cp},
{ip, {172,21,16,2}}
]}
Expand Down
1 change: 1 addition & 0 deletions config/ergw-c-node.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[{"ORIGIN", {value, "epc.mnc001.mcc001.3gppnetwork.org"}}]},

{plmn_id, {<<"001">>, <<"01">>}},
{node_id, <<"pgw.$ORIGIN">>},

{sockets,
[{cp, [{type, 'gtp-u'},
Expand Down
5 changes: 2 additions & 3 deletions doc/walkthrough-saegw.config
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{ip, {0,0,0,0}}
]},

{node_id, <<"saegw">>},
{sockets,
[{cp, [{type, 'gtp-u'},
{vrf, cp},
Expand All @@ -34,9 +35,7 @@
{ip, {172,20,16,1}},
{netdev, "vrf-irx"}
]},
{sx, [{node, 'ergw'},
{name, 'ergw'},
{type, 'pfcp'},
{sx, [{type, 'pfcp'},
{socket, cp},
{ip, {172,21,16,2}}
]}
Expand Down
5 changes: 2 additions & 3 deletions doc/walkthrough-saegw.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ erGW Installation
{ip, {0,0,0,0}}
]},

{node_id, <<"saegw">>},
{sockets,
[{cp, [{type, 'gtp-u'},
{vrf, cp},
Expand All @@ -136,9 +137,7 @@ erGW Installation
{ip, {172,20,16,1}},
{netdev, "vrf-irx"}
]},
{sx, [{node, 'ergw'},
{name, 'ergw'},
{type, 'pfcp'},
{sx, [{type, 'pfcp'},
{socket, cp},
{ip, {172,21,16,2}}
]}
Expand Down
3 changes: 1 addition & 2 deletions priv/dev.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
[{port, 8080},
{ip, {0,0,0,0}}
]},
{node_id, <<"pgw.$ORIGIN">>},
{sockets,
[{cp, [{type, 'gtp-u'},
{ip, {127,0,0,1}},
Expand All @@ -39,8 +40,6 @@
{reuseaddr, true}
]},
{sx, [
{node, 'ergw'},
{name, 'ergw'},
{type, 'pfcp'},
{socket, cp},
{ip, {0,0,0,0}},
Expand Down
6 changes: 6 additions & 0 deletions priv/static/specs/http_api_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ definitions:
acceptNewRequests:
type: "boolean"
default: true
nodeId:
$ref:
"#/definitions/Fqdn"
plmnId:
$ref:
"#/definitions/PLMN"
Expand All @@ -107,3 +110,6 @@ definitions:
properties:
version:
type: "string"
Fqdn:
description: Fully Qualified Domain Name
type: "string"
12 changes: 9 additions & 3 deletions src/ergw.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
attach_tdf/2, attach_protocol/5]).
-export([handler/2]).
-export([load_config/1]).
-export([get_plmn_id/0, get_accept_new/0]).
-export([get_plmn_id/0, get_node_id/0, get_accept_new/0]).
-export([system_info/0, system_info/1, system_info/2]).
-export([i/0, i/1, i/2]).

Expand Down Expand Up @@ -45,15 +45,20 @@ start_link() ->
get_plmn_id() ->
[{config, plmn_id, MCC, MNC}] = ets:lookup(?SERVER, plmn_id),
{MCC, MNC}.
get_node_id() ->
{ok, Id} = application:get_env(ergw, node_id),
Id.
get_accept_new() ->
[{config, accept_new, Value}] = ets:lookup(?SERVER, accept_new),
Value.

system_info() ->
[{K,system_info(K)} || K <- [plmn_id, accept_new]].
[{K,system_info(K)} || K <- [plmn_id, node_id, accept_new]].

system_info(accept_new) ->
get_accept_new();
system_info(node_id) ->
get_node_id();
system_info(plmn_id) ->
get_plmn_id();
system_info(Arg) ->
Expand Down Expand Up @@ -82,7 +87,8 @@ load_config([{Key, Value} | T])
Key =:= apns;
Key =:= charging;
Key =:= proxy_map;
Key =:= teid ->
Key =:= teid;
Key =:= node_id ->
ok = application:set_env(ergw, Key, Value),
load_config(T);
load_config([_ | T]) ->
Expand Down
6 changes: 6 additions & 0 deletions src/ergw_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
-endif.

-define(DefaultOptions, [{plmn_id, {<<"001">>, <<"01">>}},
{node_id, undefined},
vkatsuba marked this conversation as resolved.
Show resolved Hide resolved
{teid, {0, 0}},
{accept_new, true},
{sockets, []},
Expand Down Expand Up @@ -204,6 +205,10 @@ validate_option(plmn_id, {MCC, MNC} = Value) ->
ok -> Value;
_ -> throw({error, {options, {plmn_id, Value}}})
end;
validate_option(node_id, Value) when is_binary(Value) ->
Value;
validate_option(node_id, Value) when is_list(Value) ->
iolist_to_binary(Value);
validate_option(accept_new, Value) when is_boolean(Value) ->
Value;
validate_option(sockets, Value) when ?is_opts(Value) ->
Expand Down Expand Up @@ -241,6 +246,7 @@ validate_option(teid, Value) ->
ergw_tei_mngr:validate_option(Value);
validate_option(Opt, Value)
when Opt == plmn_id;
Opt == node_id;
Opt == accept_new;
Opt == sockets;
Opt == handlers;
Expand Down
2 changes: 1 addition & 1 deletion src/ergw_sx_node.erl
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ put_ie(IE, _IEs) ->
[IE].

put_node_id(R = #pfcp{ie = IEs}, #data{cp = #node{node = Node}}) ->
NodeId = #node_id{id = string:split(atom_to_binary(Node, utf8), ".", all)},
NodeId = #node_id{id = string:split(Node, ".", all)},
R#pfcp{ie = put_ie(NodeId, IEs)}.

put_build_id(R = #pfcp{ie = IEs}) ->
Expand Down
13 changes: 6 additions & 7 deletions src/ergw_sx_socket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

-record(state, {
name,
node,
node :: binary(),
send_socket :: socket:socket(),
recv_socket :: socket:socket(),
burst_size = 1 :: non_neg_integer(),
Expand Down Expand Up @@ -105,8 +105,7 @@ seid() ->
%%%===================================================================

-define(SOCKET_OPTS, [netdev, netns, freebind, reuseaddr, rcvbuf]).
-define(SocketDefaults, [{node, "invalid"},
{socket, "invalid"},
-define(SocketDefaults, [{socket, "invalid"},
{ip, invalid},
{burst_size, 10}]).

Expand All @@ -116,7 +115,8 @@ validate_options(Name, Values) ->

validate_option(type, pfcp = Value) ->
Value;
validate_option(node, Value) when is_atom(Value) ->
validate_option(node, Value) ->
?LOG(warning, "depreciated config key 'node' in Sx socket configuration"),
Value;
validate_option(name, Value) when is_atom(Value) ->
Value;
Expand Down Expand Up @@ -152,8 +152,7 @@ validate_option(Opt, Value) ->
%%% gen_server callbacks
%%%===================================================================

init(#{name := Name, node := Node, ip := IP,
socket := GtpSocketName, burst_size := BurstSize} = Opts) ->
init(#{name := Name, ip := IP, socket := GtpSocketName, burst_size := BurstSize} = Opts) ->
process_flag(trap_exit, true),

SocketOpts = maps:with(?SOCKET_OPTS, Opts),
Expand All @@ -171,7 +170,7 @@ init(#{name := Name, node := Node, ip := IP,
send_socket = SendSocket,
recv_socket = RecvSocket,
name = Name,
node = Node,
node = ergw:get_node_id(),
burst_size = BurstSize,
gtp_socket = GtpSocket,
gtp_info = GtpSockInfo,
Expand Down
29 changes: 13 additions & 16 deletions src/http_api_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
%% cowboy handler methods, used in routes
-ignore_xref([handle_request_json/2, handle_request_text/2]).

-define(FIELDS_MAPPING, [{accept_new, 'acceptNewRequests'},
{plmn_id, 'plmnId'}]).

init(Req, Opts) ->
{cowboy_rest, Req, Opts}.

Expand Down Expand Up @@ -55,19 +52,19 @@ handle_request(<<"GET">>, <<"/api/v1/version">>, json, Req, State) ->
{Response, Req, State};

handle_request(<<"GET">>, <<"/api/v1/status">>, json, Req, State) ->
Response = ergw:system_info(),
MappedResponse = lists:map(fun({Key, Value}) ->
{_, K} = lists:keyfind(Key, 1, ?FIELDS_MAPPING),
{K, Value}
end, Response),
ResponseMap = maps:from_list(MappedResponse),
Result = case maps:find('plmnId', ResponseMap) of
{ok, {Mcc, Mnc}} ->
maps:update('plmnId', [{mcc, Mcc}, {mnc, Mnc}], ResponseMap);
_ ->
ResponseMap
end,
{jsx:encode(Result), Req, State};
FieldMap = #{accept_new => 'acceptNewRequests',
node_id => 'nodeId'},
vkatsuba marked this conversation as resolved.
Show resolved Hide resolved
Response =
lists:foldl(
fun({plmn_id, {MCC, MNC}}, M) ->
M#{'plmnId' => [{mcc, MCC}, {mnc, MNC}]};
({Key, Value}, M)
when is_map_key(Key, FieldMap) ->
M#{maps:get(Key, FieldMap) => Value};
(_, M) ->
M
end, #{}, ergw:system_info()),
{jsx:encode(Response), Req, State};

handle_request(<<"GET">>, <<"/api/v1/status/accept-new">>, json, Req, State) ->
AcceptNew = ergw:system_info(accept_new),
Expand Down
3 changes: 1 addition & 2 deletions test/bench_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

{ergw, [{'$setup_vars',
[{"ORIGIN", {value, "epc.mnc001.mcc001.3gppnetwork.org"}}]},
{node_id, <<"PGW">>},
{sockets,
[{'cp-socket',
[{type, 'gtp-u'},
Expand All @@ -86,8 +87,6 @@
]},

{sx, [{type, 'pfcp'},
{node, 'ergw'},
{name, 'ergw'},
{socket, cp},
{ip, ?MUST_BE_UPDATED},
{reuseaddr, true}
Expand Down
Loading