fix paging: add timeout to discard unsuccessful paging

Currently, if there is no reply from the BSS / RNC, a subscriber will remain as
"already paged" forever, and is never going to be paged again. Even on IMSI
Detach, the pending request will keep a ref count on the vlr_subscr.

Add a paging timeout, as gsm_network->paging_timeout and in the VTY on the
'msc' node as 'paging timeout (default|<1-65535>'. (There is a 'network' /
'T3113' in OsmoBSC, but to not confuse the two, give this a different name.)

Add test_ms_timeout_paging() test to verify the timeout works.

I hit this while testing Paging across multiple hNodeB, when a UE lost
connection to the hNodeB. I noticed that no matter how long I wait, no Paging
is sent out anymore, and found this embarrassing issue. Good grief...

The choice of 10 seconds is taken from https://osmocom.org/issues/2756

Change-Id: I2db6f1e2ad341cf9c2cc7a21ec2fca0bae5b2db5
diff --git a/src/libmsc/msc_vty.c b/src/libmsc/msc_vty.c
index 14ad19e..c1c9f6b 100644
--- a/src/libmsc/msc_vty.c
+++ b/src/libmsc/msc_vty.c
@@ -109,6 +109,22 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_msc_paging_response_timer, cfg_msc_paging_response_timer_cmd,
+      "paging response-timer (default|<1-65535>)",
+      "Configure Paging\n"
+      "Set Paging timeout, the minimum time to pass between (unsuccessful) Pagings sent towards"
+      " BSS or RNC\n"
+      "Set to default timeout (" OSMO_STRINGIFY_VAL(MSC_PAGING_RESPONSE_TIMER_DEFAULT) " seconds)\n"
+      "Set paging timeout in seconds\n")
+{
+	struct gsm_network *gsmnet = gsmnet_from_vty(vty);
+	if (!strcmp(argv[1], "default"))
+		gsmnet->paging_response_timer = MSC_PAGING_RESPONSE_TIMER_DEFAULT;
+	else
+		gsmnet->paging_response_timer = atoi(argv[0]);
+	return CMD_SUCCESS;
+}
+
 static int config_write_msc(struct vty *vty)
 {
 	struct gsm_network *gsmnet = gsmnet_from_vty(vty);
@@ -130,6 +146,9 @@
 		vty_out(vty, " auth-tuple-reuse-on-error 1%s",
 			VTY_NEWLINE);
 
+	if (gsmnet->paging_response_timer != MSC_PAGING_RESPONSE_TIMER_DEFAULT)
+		vty_out(vty, " paging response-timer %u%s", gsmnet->paging_response_timer, VTY_NEWLINE);
+
 	mgcp_client_config_write(vty, " ");
 #ifdef BUILD_IU
 	ranap_iu_vty_config_write(vty, " ");
@@ -186,6 +205,7 @@
 	install_element(MSC_NODE, &cfg_msc_auth_tuple_reuse_on_error_cmd);
 	install_element(MSC_NODE, &cfg_msc_cs7_instance_a_cmd);
 	install_element(MSC_NODE, &cfg_msc_cs7_instance_iu_cmd);
+	install_element(MSC_NODE, &cfg_msc_paging_response_timer_cmd);
 
 	mgcp_client_vty_init(msc_network, MSC_NODE, &msc_network->mgw.conf);
 #ifdef BUILD_IU