MSC/SMPP: introduce TC_smpp_mo_sms_rp_error for OS#4351

This test case reproduces the problem described in OS#4351:

  1. MS/UE submits a MO SMS which it getting touted to an ESME;
  2. MSC prematurely responds with RP-ACK to the MS/UE;
  3. ESME responds with DELIVER-SM error;
  4. SMS transaction is already terminated (by RP-ACK).

Expected behaviour:

  1. MS/UE submits a MO SMS which it getting touted to an ESME;
  2. ESME responds with DELIVER-SM error;
  3. MSC terminates the SMS transaction with RP-ERROR.

Change-Id: I33c6ea0ffdf8b8a45f587d690bdceb38fc42c898
Related: OS#4351
diff --git a/msc/MSC_Tests.ttcn b/msc/MSC_Tests.ttcn
index 13cb8f4..94fac74 100644
--- a/msc/MSC_Tests.ttcn
+++ b/msc/MSC_Tests.ttcn
@@ -2160,6 +2160,50 @@
 	f_vty_config2(MSCVTY, { "smpp", "esme msc_tester"}, "no default-route");
 }
 
+/* Test case for OS#4351: make sure that RP-ERROR from ESME is properly sent to the MS/UE */
+friend function f_tc_smpp_mo_sms_rp_error(charstring id, BSC_ConnHdlrPars pars)
+runs on BSC_ConnHdlr {
+	var SmsParameters spars := valueof(t_SmsPars);
+	var SMPP_PDU smpp_pdu;
+	timer T := 3.0;
+
+	f_init_handler(pars);
+
+	/* Perform location update */
+	f_perform_lu();
+
+	/* MS/UE submits a MO SMS */
+	f_establish_fully(EST_TYPE_MO_SMS);
+	f_mo_sms_submit(spars);
+
+	/* ESME responds with an error (Invalid Destination Address) */
+	T.start;
+	alt {
+	[] SMPP.receive(tr_SMPP(c_SMPP_command_id_deliver_sm, ESME_ROK, body := ?)) -> value smpp_pdu {
+		SMPP.send(ts_SMPP_DELIVER_SM_resp(ESME_RINVDSTADR, smpp_pdu.header.seq_num));
+		}
+	[] SMPP.receive(tr_SMPP(c_SMPP_command_id_alert_notification, ESME_ROK)) { repeat; }
+	[] T.timeout {
+		setverdict(fail, "Timeout waiting for SMPP DELIVER-SM");
+		mtc.stop;
+		}
+	}
+
+	/* Expect RP-ERROR on BSSAP interface */
+	spars.exp_rp_err := 1; /* FIXME: GSM411_RP_CAUSE_MO_NUM_UNASSIGNED */
+	f_mo_sms_wait_rp_ack(spars);
+
+	f_expect_clear();
+}
+testcase TC_smpp_mo_sms_rp_error() runs on MTC_CT {
+	var BSC_ConnHdlr vc_conn;
+	f_init();
+	f_vty_config2(MSCVTY, { "smpp", "esme msc_tester"}, "default-route");
+	vc_conn := f_start_handler(refers(f_tc_smpp_mo_sms_rp_error), 45);
+	vc_conn.done;
+	f_vty_config2(MSCVTY, { "smpp", "esme msc_tester"}, "no default-route");
+}
+
 
 /* Test MO-SMS from MS/BTS/BSC towards HLR (via GSUP) */
 friend function f_tc_gsup_mo_sms(charstring id, BSC_ConnHdlrPars pars)
@@ -5904,6 +5948,7 @@
 	execute( TC_lu_and_mt_sms_paging_and_nothing() );
 	execute( TC_lu_and_mt_sms_paging_repeated() );
 	execute( TC_smpp_mo_sms() );
+	execute( TC_smpp_mo_sms_rp_error() );
 	execute( TC_smpp_mt_sms() );
 
 	execute( TC_gsup_mo_sms() );