mgcp_client: add function to generate e1-endpoint names

mgcp_client.h offers functions to generate endpoint names for wildcarded
request. This is used in osmo-bsc, lets now also add a function that can
generate e1-endpoint names.

Change-Id: Iec35b5bae8a7b07ddb3559f7114a24dcd10e8f14
Related: OS#2547
diff --git a/tests/mgcp_client/mgcp_client_test.c b/tests/mgcp_client/mgcp_client_test.c
index d2e34a6..db9f4f8 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -547,6 +547,57 @@
 	printf("\n");
 }
 
+void test_mgcp_client_e1_epname(void)
+{
+	char *epname;
+
+	if (mgcp)
+		talloc_free(mgcp);
+	mgcp = mgcp_client_init(ctx, &conf);
+
+	/* Valid endpoint names */
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 1, 15, 64, 0);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 2, 14, 32, 0);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 3, 13, 32, 4);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 4, 12, 16, 0);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 5, 11, 16, 2);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 6, 10, 16, 4);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 7, 9, 16, 6);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 8, 8, 8, 0);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 9, 7, 8, 1);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 10, 6, 8, 2);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 11, 5, 8, 3);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 12, 4, 8, 4);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 13, 3, 8, 5);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 14, 2, 8, 6);
+	printf("%s\n", epname);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 15, 1, 8, 7);
+	printf("%s\n", epname);
+
+	/* A few invalid enpoint names */
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 15, 1, 128, 0);
+	OSMO_ASSERT(epname == NULL);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 15, 1, 8, 16);
+	OSMO_ASSERT(epname == NULL);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 15, 0, 8, 2);
+	OSMO_ASSERT(epname == NULL);
+	epname = (char *)mgcp_client_e1_epname(ctx, mgcp, 15, 64, 8, 2);
+	OSMO_ASSERT(epname == NULL);
+}
+
 static const struct log_info_cat log_categories[] = {
 };
 
@@ -575,6 +626,7 @@
 	test_sdp_section_start();
 	test_map_codec_to_pt_and_map_pt_to_codec();
 	test_map_pt_to_codec();
+	test_mgcp_client_e1_epname();
 
 	printf("Done\n");
 	fprintf(stderr, "Done\n");
diff --git a/tests/mgcp_client/mgcp_client_test.err b/tests/mgcp_client/mgcp_client_test.err
index fbcf8f6..e114f79 100644
--- a/tests/mgcp_client/mgcp_client_test.err
+++ b/tests/mgcp_client/mgcp_client_test.err
@@ -72,4 +72,9 @@
 DLMGCP ptmap contains illegal mapping: codec=0 maps to pt=100
 DLMGCP ptmap contains illegal mapping: codec=113 maps to pt=2
 DLMGCP ptmap contains illegal mapping: codec=0 maps to pt=100
+DLMGCP MGCP client: using endpoint domain '@mgw'
+DLMGCP Cannot compose MGCP e1-endpoint name (ds/e1-15/s-1/su128-0@mgw), rate(128)/offset(0) combination is invalid!
+DLMGCP Cannot compose MGCP e1-endpoint name (ds/e1-15/s-1/su8-16@mgw), rate(8)/offset(16) combination is invalid!
+DLMGCP Cannot compose MGCP e1-endpoint name (ds/e1-15/s-0/su8-2@mgw), E1-timeslot number (0) is invalid!
+DLMGCP Cannot compose MGCP e1-endpoint name (ds/e1-15/s-64/su8-2@mgw), E1-timeslot number (64) is invalid!
 Done
diff --git a/tests/mgcp_client/mgcp_client_test.ok b/tests/mgcp_client/mgcp_client_test.ok
index 8b3e15b..2b03ba1 100644
--- a/tests/mgcp_client/mgcp_client_test.ok
+++ b/tests/mgcp_client/mgcp_client_test.ok
@@ -178,4 +178,19 @@
  2 <= 2
  100 <= 100
 
+ds/e1-1/s-15/su64-0@mgw
+ds/e1-2/s-14/su32-0@mgw
+ds/e1-3/s-13/su32-4@mgw
+ds/e1-4/s-12/su16-0@mgw
+ds/e1-5/s-11/su16-2@mgw
+ds/e1-6/s-10/su16-4@mgw
+ds/e1-7/s-9/su16-6@mgw
+ds/e1-8/s-8/su8-0@mgw
+ds/e1-9/s-7/su8-1@mgw
+ds/e1-10/s-6/su8-2@mgw
+ds/e1-11/s-5/su8-3@mgw
+ds/e1-12/s-4/su8-4@mgw
+ds/e1-13/s-3/su8-5@mgw
+ds/e1-14/s-2/su8-6@mgw
+ds/e1-15/s-1/su8-7@mgw
 Done