aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/test
diff options
context:
space:
mode:
Diffstat (limited to 'lib/diameter/test')
-rw-r--r--lib/diameter/test/diameter_examples_SUITE.erl8
-rw-r--r--lib/diameter/test/diameter_transport_SUITE.erl46
-rw-r--r--lib/diameter/test/diameter_util.erl50
3 files changed, 66 insertions, 38 deletions
diff --git a/lib/diameter/test/diameter_examples_SUITE.erl b/lib/diameter/test/diameter_examples_SUITE.erl
index e4ed2b227d..680ce4f366 100644
--- a/lib/diameter/test/diameter_examples_SUITE.erl
+++ b/lib/diameter/test/diameter_examples_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2013-2015. All Rights Reserved.
+%% Copyright Ericsson AB 2013-2017. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -70,6 +70,8 @@
%% Transport protocols over which the example Diameter nodes are run.
-define(PROTS, [tcp, sctp]).
+-define(ADDR, diameter_util:ip4()).
+
%% ===========================================================================
suite() ->
@@ -346,7 +348,7 @@ top(Dir, LibDir) ->
start({server, Prot}) ->
ok = diameter:start(),
ok = server:start(),
- {ok, Ref} = server:listen(Prot),
+ {ok, Ref} = server:listen({Prot, ?ADDR, 3868}),
[_] = ?util:lport(Prot, Ref),
ok;
@@ -354,7 +356,7 @@ start({client = Svc, Prot}) ->
ok = diameter:start(),
true = diameter:subscribe(Svc),
ok = client:start(),
- {ok, Ref} = client:connect(Prot),
+ {ok, Ref} = client:connect({Prot, ?ADDR, ?ADDR, 3868}),
receive #diameter_event{info = {up, Ref, _, _, _}} -> ok end;
start(Config) ->
diff --git a/lib/diameter/test/diameter_transport_SUITE.erl b/lib/diameter/test/diameter_transport_SUITE.erl
index c94f46b7a5..ac65cbe618 100644
--- a/lib/diameter/test/diameter_transport_SUITE.erl
+++ b/lib/diameter/test/diameter_transport_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2016. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2017. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -56,8 +56,10 @@
-define(RECV(Pat, Ret), receive Pat -> Ret end).
-define(RECV(Pat), ?RECV(Pat, diameter_lib:now())).
-%% Sockets are opened on the loopback address.
--define(ADDR, {127,0,0,1}).
+%% Address to open sockets on.
+-define(ADDR(Prot), if sctp == Prot -> diameter_util:ip4();
+ true -> {127,0,0,1}
+ end).
%% diameter_tcp doesn't use anything but host_ip_address, and that
%% only is a local address isn't configured as at transport start.
@@ -351,13 +353,14 @@ rand_bytes(N, Bin) ->
%% start_connect/3
start_connect(Prot, PortNr, Ref) ->
- {ok, TPid, [?ADDR]} = start_connect(Prot,
- {connect, Ref},
- ?SVC([]),
- [{raddr, ?ADDR},
- {rport, PortNr},
- {ip, ?ADDR},
- {port, 0}]),
+ Addr = ?ADDR(Prot),
+ {ok, TPid, [_]} = start_connect(Prot,
+ {connect, Ref},
+ ?SVC([]),
+ [{raddr, Addr},
+ {rport, PortNr},
+ {ip, Addr},
+ {port, 0}]),
?RECV(?TMSG({TPid, connected, _})),
TPid.
@@ -370,9 +373,9 @@ start_connect(tcp, T, Svc, Opts) ->
start_accept(Prot, Ref) ->
{Mod, Opts} = tmod(Prot),
- {ok, TPid, [?ADDR]} = Mod:start({accept, Ref},
- ?SVC([?ADDR]),
- [{port, 0} | Opts]),
+ {ok, TPid, [_]} = Mod:start({accept, Ref},
+ ?SVC([?ADDR(Prot)]),
+ [{port, 0} | Opts]),
?RECV(?TMSG({TPid, connected})),
TPid.
@@ -386,19 +389,20 @@ tmod(tcp) ->
%% gen_connect/2
gen_connect(sctp = P, PortNr) ->
- {ok, Sock} = Ok = gen_sctp:open([{ip, ?ADDR}, {port, 0} | ?SCTP_OPTS]),
- ok = gen_sctp:connect_init(Sock, ?ADDR, PortNr, []),
+ Addr = ?ADDR(P),
+ {ok, Sock} = Ok = gen_sctp:open([{ip, Addr}, {port, 0} | ?SCTP_OPTS]),
+ ok = gen_sctp:connect_init(Sock, Addr, PortNr, []),
Ok = gen_accept(P, Sock);
-gen_connect(tcp, PortNr) ->
- gen_tcp:connect(?ADDR, PortNr, ?TCP_OPTS).
+gen_connect(tcp = P, PortNr) ->
+ gen_tcp:connect(?ADDR(P), PortNr, ?TCP_OPTS).
%% gen_listen/1
-gen_listen(sctp) ->
- {ok, Sock} = gen_sctp:open([{ip, ?ADDR}, {port, 0} | ?SCTP_OPTS]),
+gen_listen(sctp = P) ->
+ {ok, Sock} = gen_sctp:open([{ip, ?ADDR(P)}, {port, 0} | ?SCTP_OPTS]),
{gen_sctp:listen(Sock, true), Sock};
-gen_listen(tcp) ->
- gen_tcp:listen(0, [{ip, ?ADDR} | ?TCP_OPTS]).
+gen_listen(tcp = P) ->
+ gen_tcp:listen(0, [{ip, ?ADDR(P)} | ?TCP_OPTS]).
%% gen_accept/2
diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl
index 37fcbbc267..8df5c907d0 100644
--- a/lib/diameter/test/diameter_util.erl
+++ b/lib/diameter/test/diameter_util.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2016. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2017. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -32,7 +32,8 @@
foldl/3,
scramble/1,
unique_string/0,
- have_sctp/0]).
+ have_sctp/0,
+ ip4/0]).
%% diameter-specific
-export([lport/2,
@@ -197,8 +198,11 @@ unique_string() ->
have_sctp() ->
case gen_sctp:open() of
{ok, Sock} ->
+ RC = gen_sctp:connect(Sock, ip4(), 3868, []),
gen_sctp:close(Sock),
- true;
+ %% Connect has been seen to return eafnosupport on at least
+ %% one SunOS 10 Sparc host, for reasons unknown.
+ RC /= {error, eafnosupport};
{error, E} when E == eprotonosupport;
E == esocktnosupport -> %% fail on any other reason
false
@@ -361,7 +365,8 @@ tmod(any) ->
opts(Prot, T) ->
tmo(T, lists:append([[{transport_module, M}, {transport_config, C}]
|| M <- tmod(Prot),
- C <- [cfg(M,T) ++ cfg(M) ++ cfg(T)]])).
+ C <- [buf(M,T) ++ [{ip, addr(M)}, {port, 0}]
+ ++ remote(M,T)]])).
tmo(listen, Opts) ->
Opts;
@@ -377,21 +382,38 @@ tmo([M, C | Opts]) ->
%% Listening SCTP socket need larger-than-default buffers to avoid
%% resends on some platforms (eg. SLES 11).
-cfg(diameter_sctp, listen) ->
+buf(diameter_sctp, listen) ->
[{recbuf, 1 bsl 16}, {sndbuf, 1 bsl 16}];
-
-cfg(_, _) ->
+buf(_, _) ->
[].
-cfg(M)
- when M == diameter_tcp;
- M == diameter_sctp ->
- [{ip, ?ADDR}, {port, 0}];
+addr(diameter_tcp) ->
+ {127,0,0,1};
+addr(diameter_sctp) ->
+ ip4().
-cfg(listen) ->
+remote(_, listen) ->
[{accept, M} || M <- [{256,0,0,1}, ["256.0.0.1", ["^.+$"]]]];
-cfg(PortNr) ->
- [{raddr, ?ADDR}, {rport, PortNr}].
+remote(Mod, PortNr) ->
+ [{raddr, addr(Mod)}, {rport, PortNr}].
+
+%% Try to use something other than the loopback address where this
+%% address is known to be problematic for gen_sctp.
+ip4() ->
+ try
+ "sparc-sun-solaris2.10" = erlang:system_info(system_architecture),
+ {ok, List} = inet:getifaddrs(),
+ hd(lists:flatmap(fun ip4/1, List))
+ catch
+ error:_ ->
+ ?ADDR
+ end.
+
+ip4({_, Opts}) ->
+ {flags, Flags} = lists:keyfind(flags, 1, Opts),
+ [A || lists:member(up, Flags),
+ not lists:member(loopback, Flags),
+ {addr, {_,_,_,_} = A} <- Opts].
%% ---------------------------------------------------------------------------
%% info/0