nat: Look at the assignment command and remember on which timeslot the data is

This information will be needed when we are trying to forward
MGCP connections to and from the BSC through the IPA protocol.
diff --git a/openbsc/tests/bsc-nat/Makefile.am b/openbsc/tests/bsc-nat/Makefile.am
index d26bbeb..bcd9f18 100644
--- a/openbsc/tests/bsc-nat/Makefile.am
+++ b/openbsc/tests/bsc-nat/Makefile.am
@@ -9,5 +9,6 @@
 			$(top_srcdir)/src/nat/bsc_filter.c \
 			$(top_srcdir)/src/nat/bsc_sccp.c \
 			$(top_srcdir)/src/nat/bsc_nat_utils.c \
+			$(top_srcdir)/src/nat/bsc_mgcp_utils.c \
 			$(top_srcdir)/src/bssap.c
 bsc_nat_test_LDADD = $(top_builddir)/src/libbsc.a $(top_builddir)/src/libsccp.a $(LIBOSMOCORE_LIBS)
diff --git a/openbsc/tests/bsc-nat/bsc_data.c b/openbsc/tests/bsc-nat/bsc_data.c
index b73aff1..ca170e2 100644
--- a/openbsc/tests/bsc-nat/bsc_data.c
+++ b/openbsc/tests/bsc-nat/bsc_data.c
@@ -80,3 +80,10 @@
 0x10, 0x52, 0x08, 0x08, 0x29, 0x47, 0x10, 0x02,
 0x01, 0x50, 0x02, 0x30, 0x1a, 0x03, 0x05, 0x20,
 0x15 };
+
+/* an assignment command */
+static const u_int8_t ass_cmd[] = {
+0x00, 0x12, 0xfd, 0x06,
+0x00, 0x00, 0x49, 0x00, 0x01, 0x0b, 0x00, 0x09,
+0x01, 0x0b, 0x03, 0x01, 0x0a, 0x11, 0x01, 0x00,
+0x15 };
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index 3a10960..70e98d7 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -335,6 +335,41 @@
 	talloc_free(parsed);
 }
 
+static void test_mgcp(void)
+{
+	struct sccp_connections con;
+	struct bsc_nat_parsed *parsed;
+	struct msgb *msg;
+
+	fprintf(stderr, "Testing MGCP.\n");
+	memset(&con, 0, sizeof(con));
+
+	msg = msgb_alloc(4096, "foo");
+	copy_to_msg(msg, ass_cmd, sizeof(ass_cmd));
+	parsed = bsc_nat_parse(msg);
+	if (bsc_mgcp_assign(&con, msg) != 0) {
+		fprintf(stderr, "Failed to handle assignment.\n");
+		abort();
+	}
+
+	if (con.msc_timeslot != 21) {
+		fprintf(stderr, "Timeslot should be 21.\n");
+		abort();
+	}
+
+	if (con.bsc_timeslot != 21) {
+		fprintf(stderr, "Assigned timeslot should have been 21.\n");
+		abort();
+	}
+	talloc_free(parsed);
+
+	bsc_mgcp_clear(&con);
+	if (con.bsc_timeslot != -1 || con.msc_timeslot != -1) {
+		fprintf(stderr, "Clearing should remove the mapping.\n");
+		abort();
+	}
+}
+
 int main(int argc, char **argv)
 {
 	struct debug_target *stderr_target;
@@ -345,9 +380,8 @@
 
 	test_filter();
 	test_contrack();
-
-	debug_set_log_level(stderr_target, 1);
 	test_paging();
+	test_mgcp();
 	return 0;
 }