gbproxy/test: Add test cases for IMSI acquisition

If the Attach Request procedure gets restarted e.g. because of a lost
message, all of these messages are stored if IMSI acquisition is in
progress.

This patch adds a test for this case and modifies the dump_peers
function to output the number of stored messages.

Note that the number of stored messages currently increases with each
(repeatedly) received Attach Request which is not the desired behaviour.

Sponsored-by: On-Waves ehf
diff --git a/openbsc/tests/gbproxy/gbproxy_test.c b/openbsc/tests/gbproxy/gbproxy_test.c
index 9d5b849..6fd5485 100644
--- a/openbsc/tests/gbproxy/gbproxy_test.c
+++ b/openbsc/tests/gbproxy/gbproxy_test.c
@@ -121,6 +121,11 @@
 		llist_for_each_entry(tlli_info, &state->enabled_tllis, list) {
 			char mi_buf[200];
 			time_t age = now ? now - tlli_info->timestamp : 0;
+			int stored_msgs = 0;
+			struct llist_head *iter;
+			llist_for_each(iter, &tlli_info->stored_msgs)
+				stored_msgs++;
+
 			if (tlli_info->mi_data_len > 0) {
 				snprintf(mi_buf, sizeof(mi_buf), "(invalid)");
 				gsm48_mi_to_string(mi_buf, sizeof(mi_buf),
@@ -143,15 +148,15 @@
 			fprintf(stream, ", IMSI %s, AGE %d",
 				mi_buf, (int)age);
 
+			if (stored_msgs)
+				fprintf(stream, ", STORED %d", stored_msgs);
+
 			if (cfg->check_imsi && tlli_info->enable_patching)
 				fprintf(stream, ", IMSI matches");
 
 			if (tlli_info->imsi_acq_pending)
 				fprintf(stream, ", IMSI acquisition in progress");
 
-			if (!llist_empty(&tlli_info->stored_msgs))
-				fprintf(stream, ", stored messages");
-
 			rc = fprintf(stream, "\n");
 			if (rc < 0)
 				return rc;
@@ -2036,6 +2041,20 @@
 
 	dump_peers(stdout, 0, 0, &gbcfg);
 
+	/* Special case: Repeated Attach Requests */
+
+	send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002,
+		       foreign_bss_tlli, &rai_unknown, cell_id,
+		       GPRS_SAPI_GMM, bss_nu++,
+		       dtap_attach_req, sizeof(dtap_attach_req));
+
+	send_llc_ul_ui(nsi, "ATTACH REQUEST", &bss_peer[0], 0x1002,
+		       foreign_bss_tlli, &rai_unknown, cell_id,
+		       GPRS_SAPI_GMM, bss_nu++,
+		       dtap_attach_req, sizeof(dtap_attach_req));
+
+	dump_peers(stdout, 0, 0, &gbcfg);
+
 	dump_global(stdout, 0);
 
 	gbprox_reset(&gbcfg);