1%%----------------------------------------------------------------------
2%%
3%% %CopyrightBegin%
4%%
5%% Copyright Ericsson AB 1999-2016. All Rights Reserved.
6%%
7%% Licensed under the Apache License, Version 2.0 (the "License");
8%% you may not use this file except in compliance with the License.
9%% You may obtain a copy of the License at
10%%
11%%     http://www.apache.org/licenses/LICENSE-2.0
12%%
13%% Unless required by applicable law or agreed to in writing, software
14%% distributed under the License is distributed on an "AS IS" BASIS,
15%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16%% See the License for the specific language governing permissions and
17%% limitations under the License.
18%%
19%% %CopyrightEnd%
20%%
21%%----------------------------------------------------------------------
22%% File    : ip_v4v6_interop_SUITE.erl
23%% Description :
24%%
25%%----------------------------------------------------------------------
26-module(ip_v4v6_interop_SUITE).
27
28-compile(export_all).
29%%----------------------------------------------------------------------
30%% External exports
31%%----------------------------------------------------------------------
32-export([
33	 all/0,
34	 init_per_suite/1,
35	 end_per_suite/1,
36         init_per_testcase/2,
37	 end_per_testcase/2,
38	 groups/0,
39	 init_per_group/2,
40	 end_per_group/2
41	]).
42%%-----------------------------------------------------------------
43%% Internal exports
44%%-----------------------------------------------------------------
45-export([]).
46
47%%----------------------------------------------------------------------
48%% Include files
49%%----------------------------------------------------------------------
50-include_lib("common_test/include/ct.hrl").
51-include_lib("orber/include/corba.hrl").
52-include_lib("orber/COSS/CosNaming/CosNaming.hrl").
53-include_lib("orber/src/orber_iiop.hrl").
54-include_lib("orber/src/ifr_objects.hrl").
55-include("idl_output/orber_test_server.hrl").
56-include_lib("orber/COSS/CosNaming/CosNaming_NamingContextExt.hrl").
57-include_lib("orber/COSS/CosNaming/CosNaming_NamingContext.hrl").
58
59%%----------------------------------------------------------------------
60%% Macros
61%%----------------------------------------------------------------------
62-define(default_timeout, test_server:minutes(15)).
63
64-define(match(ExpectedRes,Expr),
65	fun() ->
66	       AcTuAlReS = (catch (Expr)),
67	       case AcTuAlReS of
68		   ExpectedRes ->
69		       io:format("------ CORRECT RESULT ------~n~p~n",
70				 [AcTuAlReS]),
71		       AcTuAlReS;
72		   _ ->
73		       io:format("###### ERROR ERROR ######~nRESULT:  ~p~n",
74				 [AcTuAlReS]),
75		       exit(AcTuAlReS)
76	       end
77       end()).
78%%----------------------------------------------------------------------
79%% Records
80%%----------------------------------------------------------------------
81
82%%======================================================================
83%% Initialization functions.
84%%======================================================================
85
86init_per_testcase(_Case, Config) ->
87    %% Starting dual configured ORB
88    orber:jump_start([{iiop_port, 10001}, {flags, 16#1000}]),
89    orber:info(),
90    Dog=test_server:timetrap(?default_timeout),
91    [{watchdog, Dog}|Config].
92
93
94end_per_testcase(_Case, Config) ->
95    orber:jump_stop(),
96    Dog = proplists:get_value(watchdog, Config),
97    test_server:timetrap_cancel(Dog),
98    ok.
99
100init_per_suite(Config) ->
101    Config.
102
103end_per_suite(Config) ->
104    Config.
105
106%%====================================================================
107%% SUITE specification
108%%====================================================================
109all() ->
110    [
111     dual_ipv4v6
112    ].
113
114suite() -> [{ct_hooks,[ts_install_cth]}].
115
116
117groups() ->
118    [].
119
120init_per_group(_GroupName, Config) ->
121    Config.
122
123end_per_group(_GroupName, Config) ->
124    Config.
125
126%%====================================================================
127%% Test Cases
128%%====================================================================
129%% ORB configured for supporting both IPv4 and IPv6
130dual_ipv4v6(_Config) ->
131
132    %% Starting slave node with ipv4 configured ORB
133    {ok, Ipv4Node, _Ipv4Host} =
134	?match({ok,_,_}, orber_test_lib:js_node([{iiop_port, 4001}])),
135    Ipv4NS = orber_test_lib:remote_apply(Ipv4Node, corba, resolve_initial_references, ["NameService"]),
136
137    %% Starting slave node with ipv6 configured ORB
138    {ok, Ipv6Node, _Ipv6Host} =
139	?match({ok,_,_}, orber_test_lib:js_node([{iiop_port, 6001}, {flags, 16#0100}])),
140    Ipv6NS = orber_test_lib:remote_apply(Ipv6Node, corba, resolve_initial_references, ["NameService"]),
141
142    %% Add the ipv6 interface in the dual configured ORB
143    ?match({ok, _}, orber:add_listen_interface("::1", normal,
144					       [{ip_family, inet6}, {iiop_port, 10002}])),
145    DualNS = corba:resolve_initial_references("NameService"),
146
147    %% Bind IPv4 NameServer to a name in the dual stack orbs NameServer
148    NSDual4 = orber_test_lib:remote_apply(Ipv4Node, corba, resolve_initial_references_remote,
149					  ["NameService", ["iiop://127.0.0.1:10001"]]),
150    ?match(ok, orber_test_lib:remote_apply(Ipv4Node, 'CosNaming_NamingContext', bind,
151					   [NSDual4, lname:new(["ns4"]), Ipv4NS])),
152    'CosNaming_NamingContext':resolve(DualNS, lname:new(["ns4"])),
153
154    %% Bind IPv6 NameServer to a name in the dual stack orbs NameServer
155    NSDual6 = orber_test_lib:remote_apply(Ipv6Node, corba, resolve_initial_references_remote,
156					  ["NameService", ["iiop://[::1]:10002"]]),
157    ?match(ok, orber_test_lib:remote_apply(Ipv6Node, 'CosNaming_NamingContext', bind,
158				     [NSDual6, lname:new(["ns6"]), Ipv6NS])),
159    'CosNaming_NamingContext':resolve(DualNS, lname:new(["ns6"])),
160
161    %% IPv4: Fetch IPv6 NS reference from dual stack orber and register own NameServer in that
162    Ipv4NSO = orber_test_lib:remote_apply(Ipv4Node, 'CosNaming_NamingContext', resolve,
163					  [NSDual4, lname:new(["ns6"])]),
164    ?match(ok, orber_test_lib:remote_apply(Ipv4Node, 'CosNaming_NamingContext', bind,
165				     [Ipv4NSO, lname:new(["nso"]), Ipv4NS])),
166
167    %% IPv6: Fetch IPv4 NS reference from dual stack orber and register own NameServer in that
168    Ipv6NSO = orber_test_lib:remote_apply(Ipv6Node, 'CosNaming_NamingContext', resolve,
169					  [NSDual6, lname:new(["ns4"])]),
170    ?match(ok, orber_test_lib:remote_apply(Ipv6Node, 'CosNaming_NamingContext', bind,
171				     [Ipv6NSO, lname:new(["nso"]), Ipv6NS])),
172
173
174    %% IPv4: Fetch own NS reference from IPv6 NameServer and add a context then check that everything went well
175    Ipv4NSFromIpv6 = orber_test_lib:remote_apply(Ipv6Node, 'CosNaming_NamingContext', resolve,
176				       [Ipv6NS, lname:new(["nso"])]),
177    _Ipv4NC = orber_test_lib:remote_apply(Ipv4Node, 'CosNaming_NamingContext', bind_new_context,
178					 [Ipv4NSFromIpv6, lname:new(["test_context4"])]),
179
180    %% IPv6: Fetch own NS reference from IPv4 NameServer and add a context then check that everything went well
181    Ipv6NSFromIpv4 = orber_test_lib:remote_apply(Ipv4Node, 'CosNaming_NamingContext', resolve,
182				       [Ipv4NS, lname:new(["nso"])]),
183    _Ipv6NC = orber_test_lib:remote_apply(Ipv6Node, 'CosNaming_NamingContext', bind_new_context,
184					 [Ipv6NSFromIpv4, lname:new(["test_context6"])]),
185
186    %% Check that all the names are register correctly
187    {ok,DualNames,_} = 'CosNaming_NamingContext':list(DualNS, 100),
188    {ok,Ipv4Names,_} = orber_test_lib:remote_apply(Ipv4Node, 'CosNaming_NamingContext', list, [Ipv4NS, 100]),
189    {ok,Ipv6Names,_} = orber_test_lib:remote_apply(Ipv6Node, 'CosNaming_NamingContext', list, [Ipv6NS, 100]),
190
191    io:format("\nNames in Dual NS: ~p\n", [DualNames]),
192    ?match(2, length(DualNames)),
193    io:format("\nNames in IPv4 NS: ~p\n", [Ipv4Names]),
194    ?match(2, length(Ipv4Names)),
195    io:format("\nNames in IPv6 NS: ~p\n", [Ipv6Names]),
196    ?match(2, length(Ipv6Names)),
197
198    ok.
199
200