[PATCH] osmo-msc[master]: mcgp: let the MGW allocate the MGCP endpoint

2018-02-22 Thread dexter
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/6319

to look at the new patch set (#2).

mcgp: let the MGW allocate the MGCP endpoint

osmo-msc still uses endpoints that are allocated locally by the
MGCP-Client. Since osmo-mgw now supports the more comfortable,
dynamic variant we should make use of it.

- Replace the endpoint numer allocation by the client with a
  wildcarded CRCX. Use the endpoint that is assigned by the
  MGW.

Related: OS#2710
Change-Id: Iee3e446b6689626516f01c521abe3d4603cd3e13
---
M include/osmocom/msc/msc_mgcp.h
M src/libmsc/msc_mgcp.c
2 files changed, 35 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/19/6319/2

diff --git a/include/osmocom/msc/msc_mgcp.h b/include/osmocom/msc/msc_mgcp.h
index ac3283c..3c4bc62 100644
--- a/include/osmocom/msc/msc_mgcp.h
+++ b/include/osmocom/msc/msc_mgcp.h
@@ -31,10 +31,15 @@
/* FSM instance, which handles the connection switching procedure */
struct osmo_fsm_inst *fsm;
 
-   /* RTP endpoint number. This number identifies the endpoint
+   /* RTP endpoint string. This string identifies the endpoint
 * on the MGW on which the RAN and CN connection is created. This
-* endpoint number is assigned and released automatically. */
-   uint16_t rtp_endpoint;
+* endpoint number is assigned by the MGW. */
+   char rtp_endpoint[MGCP_ENDPOINT_MAXLEN];
+
+   /* Call id of the current call. Will be derived from the callref
+* of the transaction that is valid during the first CRCX. (The
+* callref may change throughout the call) */
+   unsigned int call_id;
 
/* Set to true, when the context information is no longer needed */
bool free_ctx;
diff --git a/src/libmsc/msc_mgcp.c b/src/libmsc/msc_mgcp.c
index 2bc186e..f5e40d2 100644
--- a/src/libmsc/msc_mgcp.c
+++ b/src/libmsc/msc_mgcp.c
@@ -51,7 +51,7 @@
 #define MGCP_ASS_TIMEOUT 10/* in seconds */
 #define MGCP_ASS_TIMEOUT_TIMER_NR 4
 
-#define MGCP_ENDPOINT_FORMAT "%x@mgw"
+#define ENDPOINT_ID "rtpbridge/*@mgw"
 
 /* Some internal cause codes to indicate fault condition inside the FSM */
 enum msc_mgcp_cause_code {
@@ -187,9 +187,6 @@
 * there is no meaningful action we can take now other than
 * giving up. */
 
-   /* At least release the occupied endpoint ID */
-   mgcp_client_release_endpoint(mgcp_ctx->rtp_endpoint, mgcp);
-
/* Cancel the transaction that timed out */
mgcp_client_cancel(mgcp, mgcp_ctx->mgw_pending_trans);
 
@@ -241,8 +238,6 @@
mgcp = mgcp_ctx->mgcp;
OSMO_ASSERT(mgcp);
 
-   mgcp_ctx->rtp_endpoint = mgcp_client_next_endpoint(mgcp);
-
LOGPFSML(fi, LOGL_DEBUG,
 "CRCX/RAN: creating connection for the RAN side on MGW 
endpoint:0x%x...\n", mgcp_ctx->rtp_endpoint);
 
@@ -250,14 +245,15 @@
mgcp_msg = (struct mgcp_msg) {
.verb = MGCP_VERB_CRCX,
.presence = (MGCP_MSG_PRESENCE_ENDPOINT | 
MGCP_MSG_PRESENCE_CALL_ID | MGCP_MSG_PRESENCE_CONN_MODE),
-   .call_id = mgcp_ctx->rtp_endpoint,
+   .call_id = mgcp_ctx->call_id,
.conn_mode = MGCP_CONN_LOOPBACK
};
-   if (snprintf(mgcp_msg.endpoint, MGCP_ENDPOINT_MAXLEN, 
MGCP_ENDPOINT_FORMAT, mgcp_ctx->rtp_endpoint) >=
+   if (osmo_strlcpy(mgcp_msg.endpoint, mgcp_ctx->rtp_endpoint, 
sizeof(mgcp_msg.endpoint)) >=
MGCP_ENDPOINT_MAXLEN) {
handle_error(mgcp_ctx, MGCP_ERR_NOMEM);
return;
}
+
msg = mgcp_msg_gen(mgcp, &mgcp_msg);
OSMO_ASSERT(msg);
 
@@ -293,9 +289,11 @@
return;
}
 
-   /* memorize connection identifier */
+   /* memorize connection identifier and specific endpoint id */
osmo_strlcpy(mgcp_ctx->conn_id_ran, r->head.conn_id, 
sizeof(mgcp_ctx->conn_id_ran));
LOGPFSML(mgcp_ctx->fsm, LOGL_DEBUG, "CRCX/RAN: MGW responded with CI: 
%s\n", mgcp_ctx->conn_id_ran);
+   osmo_strlcpy(mgcp_ctx->rtp_endpoint, r->head.endpoint, 
sizeof(mgcp_ctx->rtp_endpoint));
+   LOGPFSML(mgcp_ctx->fsm, LOGL_DEBUG, "CRCX/RAN: MGW assigned endpoint: 
%s\n", mgcp_ctx->rtp_endpoint);
 
rc = mgcp_response_parse_params(r);
if (rc) {
@@ -343,14 +341,15 @@
mgcp_msg = (struct mgcp_msg) {
.verb = MGCP_VERB_CRCX,
.presence = (MGCP_MSG_PRESENCE_ENDPOINT | 
MGCP_MSG_PRESENCE_CALL_ID | MGCP_MSG_PRESENCE_CONN_MODE),
-   .call_id = mgcp_ctx->rtp_endpoint,
+   .call_id = mgcp_ctx->call_id,
.conn_mode = MGCP_CONN_LOOPBACK
};
-   if (snprintf(mgcp_msg.endpoint, MGCP_ENDPOINT_MAXLEN, 
MGCP_ENDPOINT_FORMAT, mgcp_ctx->rtp_endpoint) >=
+   if (osmo_strlcpy(mgcp_msg.endpoint, mgcp_ctx->rtp_endpoint, 
sizeof(mgcp_msg.endpoint)) >=
MGCP_ENDPOIN

[PATCH] osmo-msc[master]: mcgp: let the MGW allocate the MGCP endpoint

2018-02-08 Thread dexter

Review at  https://gerrit.osmocom.org/6319

mcgp: let the MGW allocate the MGCP endpoint

osmo-msc still uses endpoints that are allocated locally by the
MGCP-Client. Since osmo-mgw now supports the more comfortable,
dynamic variant we should make use of it.

- Replace the endpoint numer allocation by the client with a
  wildcarded CRCX. Use the endpoint that is assigned by the
  MGW.

Related:
OS#2710

Change-Id: Iee3e446b6689626516f01c521abe3d4603cd3e13
---
M include/osmocom/msc/msc_mgcp.h
M src/libmsc/msc_mgcp.c
2 files changed, 23 insertions(+), 44 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/19/6319/1

diff --git a/include/osmocom/msc/msc_mgcp.h b/include/osmocom/msc/msc_mgcp.h
index ac3283c..05f2fd9 100644
--- a/include/osmocom/msc/msc_mgcp.h
+++ b/include/osmocom/msc/msc_mgcp.h
@@ -31,10 +31,10 @@
/* FSM instance, which handles the connection switching procedure */
struct osmo_fsm_inst *fsm;
 
-   /* RTP endpoint number. This number identifies the endpoint
+   /* RTP endpoint string. This string identifies the endpoint
 * on the MGW on which the RAN and CN connection is created. This
-* endpoint number is assigned and released automatically. */
-   uint16_t rtp_endpoint;
+* endpoint number is assigned by the MGW. */
+   char rtp_endpoint[MGCP_ENDPOINT_MAXLEN];
 
/* Set to true, when the context information is no longer needed */
bool free_ctx;
diff --git a/src/libmsc/msc_mgcp.c b/src/libmsc/msc_mgcp.c
index bd60c13..85e9d2e 100644
--- a/src/libmsc/msc_mgcp.c
+++ b/src/libmsc/msc_mgcp.c
@@ -51,7 +51,7 @@
 #define MGCP_ASS_TIMEOUT 10/* in seconds */
 #define MGCP_ASS_TIMEOUT_TIMER_NR 4
 
-#define MGCP_ENDPOINT_FORMAT "%x@mgw"
+#define ENDPOINT_ID "rtpbridge/*@mgw"
 
 /* Some internal cause codes to indicate fault condition inside the FSM */
 enum msc_mgcp_cause_code {
@@ -176,9 +176,6 @@
 * there is no meaningful action we can take now other than
 * giving up. */
 
-   /* At least release the occupied endpoint ID */
-   mgcp_client_release_endpoint(mgcp_ctx->rtp_endpoint, mgcp);
-
/* Cancel the transaction that timed out */
mgcp_client_cancel(mgcp, mgcp_ctx->mgw_pending_trans);
 
@@ -230,8 +227,6 @@
mgcp = mgcp_ctx->mgcp;
OSMO_ASSERT(mgcp);
 
-   mgcp_ctx->rtp_endpoint = mgcp_client_next_endpoint(mgcp);
-
LOGPFSML(fi, LOGL_DEBUG,
 "CRCX/RAN: creating connection for the RAN side on MGW 
endpoint:0x%x...\n", mgcp_ctx->rtp_endpoint);
 
@@ -239,14 +234,11 @@
mgcp_msg = (struct mgcp_msg) {
.verb = MGCP_VERB_CRCX,
.presence = (MGCP_MSG_PRESENCE_ENDPOINT | 
MGCP_MSG_PRESENCE_CALL_ID | MGCP_MSG_PRESENCE_CONN_MODE),
-   .call_id = mgcp_ctx->rtp_endpoint,
+   .call_id = 12345,
.conn_mode = MGCP_CONN_LOOPBACK
};
-   if (snprintf(mgcp_msg.endpoint, MGCP_ENDPOINT_MAXLEN, 
MGCP_ENDPOINT_FORMAT, mgcp_ctx->rtp_endpoint) >=
-   MGCP_ENDPOINT_MAXLEN) {
-   handle_error(mgcp_ctx, MGCP_ERR_NOMEM);
-   return;
-   }
+   osmo_strlcpy(mgcp_msg.endpoint, mgcp_ctx->rtp_endpoint, 
sizeof(mgcp_msg.endpoint));
+
msg = mgcp_msg_gen(mgcp, &mgcp_msg);
OSMO_ASSERT(msg);
 
@@ -282,9 +274,11 @@
return;
}
 
-   /* memorize connection identifier */
+   /* memorize connection identifier and specific endpoint id */
osmo_strlcpy(mgcp_ctx->conn_id_ran, r->head.conn_id, 
sizeof(mgcp_ctx->conn_id_ran));
LOGPFSML(mgcp_ctx->fsm, LOGL_DEBUG, "CRCX/RAN: MGW responded with CI: 
%s\n", mgcp_ctx->conn_id_ran);
+   osmo_strlcpy(mgcp_ctx->rtp_endpoint, r->head.endpoint, 
sizeof(mgcp_ctx->rtp_endpoint));
+   LOGPFSML(mgcp_ctx->fsm, LOGL_DEBUG, "CRCX/RAN: MGW assigned endpoint: 
%s\n", mgcp_ctx->rtp_endpoint);
 
rc = mgcp_response_parse_params(r);
if (rc) {
@@ -332,14 +326,11 @@
mgcp_msg = (struct mgcp_msg) {
.verb = MGCP_VERB_CRCX,
.presence = (MGCP_MSG_PRESENCE_ENDPOINT | 
MGCP_MSG_PRESENCE_CALL_ID | MGCP_MSG_PRESENCE_CONN_MODE),
-   .call_id = mgcp_ctx->rtp_endpoint,
+   .call_id = 12345,
.conn_mode = MGCP_CONN_LOOPBACK
};
-   if (snprintf(mgcp_msg.endpoint, MGCP_ENDPOINT_MAXLEN, 
MGCP_ENDPOINT_FORMAT, mgcp_ctx->rtp_endpoint) >=
-   MGCP_ENDPOINT_MAXLEN) {
-   handle_error(mgcp_ctx, MGCP_ERR_NOMEM);
-   return;
-   }
+   osmo_strlcpy(mgcp_msg.endpoint, mgcp_ctx->rtp_endpoint, 
sizeof(mgcp_msg.endpoint));
+
msg = mgcp_msg_gen(mgcp, &mgcp_msg);
OSMO_ASSERT(msg);
 
@@ -493,17 +484,14 @@
.presence = (MGCP_MSG_PRESENCE_ENDPOINT | 
MGCP_MSG_PRESENCE_CALL_ID | MGCP_MSG_PRESENCE_CONN_ID |
 MGCP_MSG_PRESENCE_CONN_MOD