aboutsummaryrefslogtreecommitdiffstats
path: root/remsim/RemsimClient_Tests.ttcn
blob: d9501524f5afdccdd0e5e909d95093108a3ced5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
module RemsimClient_Tests {

/* Integration Tests for osmo-remsim-client
 * (C) 2019 by Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * This test suite tests osmo-remsim-client by attaching to the external interfaces.
 */

import from Osmocom_Types all;
import from IPA_Emulation all;

import from RSPRO all;
import from RSPRO_Types all;
import from RSPRO_Server all;
import from REMSIM_Tests all;

type component client_test_CT extends rspro_server_CT {
	var ComponentIdentity g_srv_comp_id, g_bankd_comp_id;
};

private function f_init() runs on client_test_CT {
	g_srv_comp_id := valueof(ts_CompId(remsimServer, "ttcn-server"));
	g_bankd_comp_id := valueof(ts_CompId(remsimBankd, "ttcn-bankd"));

	f_rspro_srv_init(0, mp_server_ip, mp_server_port, g_srv_comp_id);
	f_rspro_srv_init(1, mp_bankd_ip, mp_bankd_port, g_bankd_comp_id, exp_connect := false);
}


/* ConnectClientReq from client to remsim-server */
testcase TC_srv_connectClient() runs on client_test_CT {
	f_init();
	/* expect inbound connectClientReq */
	as_connectClientReq();
	setverdict(pass);
	f_sleep(1.0);
}

/* ConnectClientReq from client to remsim-server */
testcase TC_srv_connectClient_reject() runs on client_test_CT {
	f_init();
	/* expect inbound connectClientReq */
	as_connectClientReq(res := illegalClientId);
	/* expect disconnect by client */
	RSPRO_SRV[0].receive(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_DOWN));
	setverdict(pass);
	f_sleep(1.0);
}

/* ConnectClientReq from client to remsim-server */
testcase TC_srv_connectClient_configClientBank() runs on client_test_CT {
	var BankSlot bslot := { 1, 0 };
	f_init();
	/* expect inbound connectClientReq */
	as_connectClientReq();
	/* configure client to connect to [simulated] bankd */
	f_rspro_config_client_bank(bslot, ts_IpPort(ts_IPv4(mp_bankd_ip), mp_bankd_port));
	/* expect inbound connect on simulated bankd */
	f_rspro_srv_exp_connect(1);
	/* expect inbound connectClientReq on simulated bankd */
	as_connectClientReq(i := 1);
	setverdict(pass);
	f_sleep(1.0);
}

/* Test if client re-connects to server after connection is lost */
testcase TC_srv_reconnect() runs on client_test_CT {
	var BankSlot bslot := { 1, 0 };
	f_init();
	/* expect inbound connectClientReq */
	as_connectClientReq();

	/* disconnect the client from server and expect re-establish + re-connect */
	f_rspro_srv_fini(0);
	f_rspro_srv_init(0, mp_server_ip, mp_server_port, g_srv_comp_id, exp_connect := true);
	/* expect inbound connectClientReq */
	as_connectClientReq(i := 0);

	setverdict(pass);
	f_sleep(1.0);
}

/* Test if client re-connects to bank after connection is lost */
testcase TC_bank_reconnect() runs on client_test_CT {
	var BankSlot bslot := { 1, 0 };
	f_init();
	/* expect inbound connectClientReq */
	as_connectClientReq();
	/* configure client to connect to [simulated] bankd */
	f_rspro_config_client_bank(bslot, ts_IpPort(ts_IPv4(mp_bankd_ip), mp_bankd_port));
	/* expect inbound connect on simulated bankd */
	f_rspro_srv_exp_connect(1);
	/* expect inbound connectClientReq on simulated bankd */
	as_connectClientReq(i := 1);

	/* disconnect the client from bankd and expect re-establish + re-connect */
	f_rspro_srv_fini(1);
	f_rspro_srv_init(1, mp_bankd_ip, mp_bankd_port, g_bankd_comp_id, exp_connect := true);
	/* expect inbound connectClientReq on simulated bankd */
	as_connectClientReq(i := 1);

	setverdict(pass);
	f_sleep(1.0);
}

/* Test if client disconnects from bankd after slotmap delete on server */
testcase TC_bank_disconnect() runs on client_test_CT {
	var BankSlot bslot := { 1, 0 };
	f_init();
	/* expect inbound connectClientReq */
	as_connectClientReq();
	/* configure client to connect to [simulated] bankd */
	f_rspro_config_client_bank(bslot, ts_IpPort(ts_IPv4(mp_bankd_ip), mp_bankd_port));
	/* expect inbound connect on simulated bankd */
	f_rspro_srv_exp_connect(1);
	/* expect inbound connectClientReq on simulated bankd */
	as_connectClientReq(i := 1);

	f_sleep(1.0);

	/* configure client to disconnect from [simulated] bankd */
	f_rspro_config_client_bank(bslot, ts_IpPort(ts_IPv4("0.0.0.0"), 0));

	/* expect disconnect of client on simulated bankd side */
	RSPRO_SRV[1].receive(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_DOWN));
	setverdict(pass);
}

/* Test if client connects to bankd after disconnects from bankd after slotmap delete on server */
testcase TC_bank_disconnect_reconnect() runs on client_test_CT {
	var BankSlot bslot := { 1, 0 };
	f_init();
	/* expect inbound connectClientReq */
	as_connectClientReq();
	/* configure client to connect to [simulated] bankd */
	f_rspro_config_client_bank(bslot, ts_IpPort(ts_IPv4(mp_bankd_ip), mp_bankd_port));
	/* expect inbound connect on simulated bankd */
	f_rspro_srv_exp_connect(1);
	/* expect inbound connectClientReq on simulated bankd */
	as_connectClientReq(i := 1);

	f_sleep(1.0);

	/* configure client to disconnect from [simulated] bankd */
	f_rspro_config_client_bank(bslot, ts_IpPort(ts_IPv4("0.0.0.0"), 0));

	/* expect disconnect of client on simulated bankd side */
	RSPRO_SRV[1].receive(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_DOWN));

	/* re-start the IPA emulation (which terminated itself on the TCP disconnect */
	f_rspro_srv_init(1, mp_bankd_ip, mp_bankd_port, g_bankd_comp_id, exp_connect := false);

	/* configure client to connect to [simulated] bankd */
	f_rspro_config_client_bank(bslot, ts_IpPort(ts_IPv4(mp_bankd_ip), mp_bankd_port));

	/* expect inbound connect on simulated bankd */
	f_rspro_srv_exp_connect(1);

	/* expect inbound connect on simulated bankd */
	as_connectClientReq(i := 1);

	setverdict(pass);
}


/* TODO:
   * send a configClientBankIpReq and change the bank of an active client
   * send a configClientBankSlotReq and chagne the bank slot of an active client
   * test keepalive mechanism: do we get IPA PING?
   * test keepalive mechanism: do we see disconnect+reconnect if we don't respond to IPA PING?
   * test actual APDU transfers
   * test messages in invalid state, e.g. APDUs before we're connected to a bank
   * test messages on server connection which are only permitted on bankd connection
 */

control {
	execute( TC_srv_connectClient() );
	execute( TC_srv_connectClient_reject() );
	execute( TC_srv_connectClient_configClientBank() );
	execute( TC_srv_reconnect() );
	execute( TC_bank_reconnect() );
	execute( TC_bank_disconnect() );
	execute( TC_bank_disconnect_reconnect() );
}


}