Change in osmo-bsc[master]: Re-introduce support for IPA-encapsulated MGCP

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun May 27 16:02:15 UTC 2018


Harald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/9342


Change subject: Re-introduce support for IPA-encapsulated MGCP
......................................................................

Re-introduce support for IPA-encapsulated MGCP

Old osmo-bsc-sccplite already supported this, but in the migration
over to libosmo-sigtran and to real 3GPP AoIP, this functionality
got lost.

We now crate a UDP proxy socket. Any MGCP commands received via IPA
from MSC (or rather: bsc_nat) are retransmitted to the MGW via UDP on
this socket.  Any responses back from the MGW received on the UDP
socket are retransmitted back to MSC/bsc_nat as MGCP inside the IPA
multiplex.

Closes: OS#2536
Change-Id: I38ad8fa645c08900e0e1f1b4b96136bc6d96b3ab
---
M include/osmocom/bsc/bsc_msc_data.h
M include/osmocom/bsc/osmo_bsc_sigtran.h
M src/osmo-bsc/osmo_bsc_audio.c
M src/osmo-bsc/osmo_bsc_ctrl.c
M src/osmo-bsc/osmo_bsc_msc.c
M src/osmo-bsc/osmo_bsc_sigtran.c
M tests/bssap/bssap_test.c
7 files changed, 161 insertions(+), 20 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/42/9342/1

diff --git a/include/osmocom/bsc/bsc_msc_data.h b/include/osmocom/bsc/bsc_msc_data.h
index baa58e7..3918b71 100644
--- a/include/osmocom/bsc/bsc_msc_data.h
+++ b/include/osmocom/bsc/bsc_msc_data.h
@@ -31,6 +31,7 @@
 #include "debug.h"
 
 #include <osmocom/core/timer.h>
+#include <osmocom/core/select.h>
 #include <osmocom/gsm/protocol/gsm_04_08.h>
 
 
@@ -127,6 +128,15 @@
 		 * BSSMAP RESET procedure */
 		struct osmo_fsm_inst *reset_fsm;
 	} a;
+	/* Proxy between IPA/SCCPlite encapsulated MGCP and UDP */
+	struct {
+		/* local (BSC) IP address to be used */
+		char *local_addr;
+		/* local (BSC) UDP port to be usd to talk with MGW */
+		uint16_t local_port;
+		/* UDP socket for proxying MGCP via SCCPlite/IPA */
+		struct osmo_fd ofd;
+	} mgcp_ipa;
 };
 
 /*
diff --git a/include/osmocom/bsc/osmo_bsc_sigtran.h b/include/osmocom/bsc/osmo_bsc_sigtran.h
index bd8b063..b934d51 100644
--- a/include/osmocom/bsc/osmo_bsc_sigtran.h
+++ b/include/osmocom/bsc/osmo_bsc_sigtran.h
@@ -44,3 +44,12 @@
 
 /* receive + process a CTRL command from the piggy-back on the IPA/SCCPlite link */
 int bsc_sccplite_rx_ctrl(struct osmo_ss7_asp *asp, struct msgb *msg);
+
+/* receive + process a MGCP message from the piggy-back on the IPA/SCCPlite link */
+int bsc_sccplite_rx_mgcp(struct osmo_ss7_asp *asp, struct msgb *msg);
+
+/* send a message via SCCPLite to given MSC */
+int bsc_sccplite_msc_send(struct bsc_msc_data *msc, struct msgb *msg);
+
+/* we received some data on the UDP proxy socket from the MGW. Pass it to MSC via IPA */
+int bsc_sccplite_mgcp_proxy_cb(struct osmo_fd *ofd, unsigned int what);
diff --git a/src/osmo-bsc/osmo_bsc_audio.c b/src/osmo-bsc/osmo_bsc_audio.c
index 8eef8d2..ede3939 100644
--- a/src/osmo-bsc/osmo_bsc_audio.c
+++ b/src/osmo-bsc/osmo_bsc_audio.c
@@ -3,6 +3,7 @@
  *
  * (C) 2009-2010 by Holger Hans Peter Freyther <zecke at selfish.org>
  * (C) 2009-2010 by On-Waves
+ * (C) 2018 by Harald Welte <laforge at gnumonks.org>
  * All Rights Reserved
  *
  * This program is free software; you can redistribute it and/or modify
@@ -28,6 +29,8 @@
 #include <osmocom/bsc/signal.h>
 #include <osmocom/gsm/gsm0808.h>
 #include <osmocom/gsm/gsm0808_utils.h>
+#include <osmocom/gsm/ipa.h>
+#include <osmocom/gsm/protocol/ipaccess.h>
 #include <osmocom/bsc/osmo_bsc_sigtran.h>
 #include <osmocom/bsc/bsc_subscr_conn_fsm.h>
 #include <osmocom/bsc/bsc_subscriber.h>
@@ -96,3 +99,64 @@
 	osmo_signal_register_handler(SS_ABISIP, handle_abisip_signal, net);
 	return 0;
 }
+
+/* Determine MSC based on the ASP over which the message was received */
+static struct bsc_msc_data *msc_from_asp(struct osmo_ss7_asp *asp)
+{
+	int msc_nr;
+	/* this is rather ugly, as we of course have MTP-level routing between
+	 * the local SCCP user (BSC) and the AS/ASPs.  However, for the most simple
+	 * SCCPlite case, there is a 1:1 mapping between ASP and AS, and using
+	 * the libosmo-sigtran "simple client", the names are "as[p]-clnt-msc-%u",
+	 * as set in osmo_bsc_sigtran_init() */
+	if (sscanf(asp->cfg.name, "asp-clnt-msc-%u", &msc_nr) != 1) {
+		LOGP(DMSC, LOGL_ERROR, "Cannot find to which MSC the ASP %s belongs\n", asp->cfg.name);
+		return NULL;
+	}
+	return osmo_msc_data_find(bsc_gsmnet, msc_nr);
+}
+
+/* We received an IPA-encapsulated MGCP message from a MSC. Transfers msg ownership. */
+int bsc_sccplite_rx_mgcp(struct osmo_ss7_asp *asp, struct msgb *msg)
+{
+	struct bsc_msc_data *msc;
+	int rc;
+
+	LOGP(DMSC, LOGL_NOTICE, "%s: Received IPA-encapsulated MGCP: %s\n", asp->cfg.name, msg->l2h);
+	msc = msc_from_asp(asp);
+	if (msc) {
+		/* we don't have a write queue here as we simply expect the socket buffers
+		 * to be large enouhg to deal with whatever small/infrequent MGCP messages */
+		rc = send(msc->mgcp_ipa.ofd.fd, msgb_l2(msg), msgb_l2len(msg), 0);
+	} else
+		rc = 0;
+
+	msgb_free(msg);
+	return rc;
+}
+
+/* we received some data on the UDP proxy socket from the MGW. Pass it to MSC via IPA */
+int bsc_sccplite_mgcp_proxy_cb(struct osmo_fd *ofd, unsigned int what)
+{
+	struct bsc_msc_data *msc = ofd->data;
+	struct msgb *msg;
+	int rc;
+
+	if (!(what & BSC_FD_READ))
+		return 0;
+
+	msg = msgb_alloc_headroom(1024, 16, "MGCP->IPA");
+	OSMO_ASSERT(msg);
+	rc = recv(ofd->fd, msg->data, msgb_tailroom(msg), 0);
+	if (rc <= 0) {
+		LOGP(DMSC, LOGL_ERROR, "error receiving data from MGCP<-> IPA proxy UDP socket: "
+			"%s\n", strerror(errno));
+		msgb_free(msg);
+		return rc;
+	}
+	msg->l2h = msgb_put(msg, rc);
+	LOGP(DMSC, LOGL_NOTICE, "Received MGCP on UDP proxy socket: %s\n", msg->l2h);
+
+	ipa_prepend_header(msg, IPAC_PROTO_MGCP_OLD);
+	return bsc_sccplite_msc_send(msc, msg);
+}
diff --git a/src/osmo-bsc/osmo_bsc_ctrl.c b/src/osmo-bsc/osmo_bsc_ctrl.c
index 698a00d..6b7db8d 100644
--- a/src/osmo-bsc/osmo_bsc_ctrl.c
+++ b/src/osmo-bsc/osmo_bsc_ctrl.c
@@ -52,6 +52,39 @@
 	return rt->dest.as;
 }
 
+static int _ss7_as_send(struct osmo_ss7_as *as, struct msgb *msg)
+{
+	struct osmo_ss7_asp *asp;
+	unsigned int i;
+
+	/* FIXME: unify with xua_as_transmit_msg() and perform proper ASP lookup */
+	for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) {
+		asp = as->cfg.asps[i];
+		if (!asp)
+			continue;
+		/* FIXME: deal with multiple ASPs per AS */
+		return osmo_ss7_asp_send(asp, msg);
+	}
+	msgb_free(msg);
+	return -1;
+}
+
+int bsc_sccplite_msc_send(struct bsc_msc_data *msc, struct msgb *msg)
+{
+	struct osmo_ss7_as *as;
+
+	as = msc_get_ss7_as(msc);
+	if (!as) {
+		msgb_free(msg);
+		return -1;
+	}
+
+	/* don't attempt to send CTRL on a non-SCCPlite AS */
+	if (as->cfg.proto != OSMO_SS7_ASP_PROT_IPA)
+		return 0;
+
+	return _ss7_as_send(as, msg);
+}
 
 /* Encode a CTRL command and send it to the given ASP
  * \param[in] asp ASP through which we shall send the encoded message
@@ -83,30 +116,20 @@
  * Caller must hence free 'cmd' itself. */
 static int sccplite_msc_ctrl_cmd_send(struct bsc_msc_data *msc, struct ctrl_cmd *cmd)
 {
-	struct osmo_ss7_as *as;
-	struct osmo_ss7_asp *asp;
-	unsigned int i;
+	struct msgb *msg;
 
-	as = msc_get_ss7_as(msc);
-	if (!as)
+	msg = ctrl_cmd_make(cmd);
+	if (!msg)
 		return -1;
 
-	/* don't attempt to send CTRL on a non-SCCPlite AS */
-	if (as->cfg.proto != OSMO_SS7_ASP_PROT_IPA)
-		return 0;
+	ipa_prepend_header_ext(msg, IPAC_PROTO_EXT_CTRL);
+	ipa_prepend_header(msg, IPAC_PROTO_OSMO);
 
-	/* FIXME: unify with xua_as_transmit_msg() and perform proper ASP lookup */
-	for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) {
-		asp = as->cfg.asps[i];
-		if (!asp)
-			continue;
-		/* FIXME: deal with multiple ASPs per AS */
-		return sccplite_asp_ctrl_cmd_send(asp, cmd);
-	}
-	return -1;
+	return bsc_sccplite_msc_send(msc, msg);
 }
 
-/* receive + process a CTRL command from the piggy-back on the IPA/SCCPlite link */
+/* receive + process a CTRL command from the piggy-back on the IPA/SCCPlite link.
+ * Transfers msg ownership. */
 int bsc_sccplite_rx_ctrl(struct osmo_ss7_asp *asp, struct msgb *msg)
 {
 	struct ctrl_cmd *cmd;
diff --git a/src/osmo-bsc/osmo_bsc_msc.c b/src/osmo-bsc/osmo_bsc_msc.c
index e00c9ef..e20f92c 100644
--- a/src/osmo-bsc/osmo_bsc_msc.c
+++ b/src/osmo-bsc/osmo_bsc_msc.c
@@ -27,26 +27,49 @@
 #include <osmocom/bsc/gsm_data.h>
 #include <osmocom/bsc/ipaccess.h>
 #include <osmocom/bsc/bsc_msc_data.h>
+#include <osmocom/bsc/osmo_bsc_sigtran.h>
 #include <osmocom/bsc/signal.h>
 
 #include <osmocom/core/talloc.h>
+#include <osmocom/core/socket.h>
 
 #include <osmocom/gsm/gsm0808.h>
 
 #include <osmocom/abis/ipa.h>
 
+#include <osmocom/mgcp_client/mgcp_client.h>
+
 #include <sys/socket.h>
 #include <netinet/tcp.h>
 #include <unistd.h>
 
-int osmo_bsc_msc_init(struct bsc_msc_data *data)
+int osmo_bsc_msc_init(struct bsc_msc_data *msc)
 {
+	struct gsm_network *net = msc->network;
+	uint16_t mgw_port;
+	int rc;
+
 	/* FIXME: This is a leftover from the old architecture that used
 	 * sccp-lite with osmocom specific authentication. Since we now
 	 * changed to AoIP the connected status and the authentication
 	 * status is managed differently. However osmo_bsc_filter.c still
 	 * needs the flags to be set to one. See also: OS#3112 */
-	data->is_authenticated = 1;
+	msc->is_authenticated = 1;
+
+	if (net->mgw.conf->remote_port == -1)
+		mgw_port = 2427;
+	else
+		mgw_port = net->mgw.conf->remote_port;
+
+	rc = osmo_sock_init2_ofd(&msc->mgcp_ipa.ofd, AF_INET, SOCK_DGRAM, IPPROTO_UDP,
+				 msc->mgcp_ipa.local_addr, msc->mgcp_ipa.local_port,
+				 net->mgw.conf->remote_addr, mgw_port,
+				 OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT);
+	if (rc < 0) {
+		LOGP(DMSC, LOGL_ERROR, "msc %u: Could not create/connect/bind MGCP proxy socket: %d\n",
+			msc->nr, rc);
+		return rc;
+	}
 
 	return 0;
 }
@@ -94,6 +117,10 @@
 	/* Defaults for the audio setup */
 	msc_data->amr_conf.m5_90 = 1;
 
+	osmo_fd_setup(&msc_data->mgcp_ipa.ofd, -1, BSC_FD_READ, &bsc_sccplite_mgcp_proxy_cb, msc_data, 0);
+	msc_data->mgcp_ipa.local_addr = talloc_strdup(msc_data, "0.0.0.0");
+	msc_data->mgcp_ipa.local_port = 0; /* dynamic */
+
 	return msc_data;
 }
 
diff --git a/src/osmo-bsc/osmo_bsc_sigtran.c b/src/osmo-bsc/osmo_bsc_sigtran.c
index 608c3fb..85bf0f4 100644
--- a/src/osmo-bsc/osmo_bsc_sigtran.c
+++ b/src/osmo-bsc/osmo_bsc_sigtran.c
@@ -538,8 +538,12 @@
 		switch (iph_ext->proto) {
 		case IPAC_PROTO_EXT_CTRL:
 			return bsc_sccplite_rx_ctrl(asp, msg);
+		case IPAC_PROTO_EXT_MGCP:
+			return bsc_sccplite_rx_mgcp(asp, msg);
 		}
 		break;
+	case IPAC_PROTO_MGCP_OLD:
+		return bsc_sccplite_rx_mgcp(asp, msg);
 	default:
 		break;
 	}
diff --git a/tests/bssap/bssap_test.c b/tests/bssap/bssap_test.c
index c9e7075..3754e08 100644
--- a/tests/bssap/bssap_test.c
+++ b/tests/bssap/bssap_test.c
@@ -160,3 +160,7 @@
 int bsc_sccplite_rx_ctrl(struct osmo_ss7_asp *asp, struct msgb *msg) {
 	OSMO_ASSERT(0);
 }
+
+int bsc_sccplite_rx_mgcp(struct osmo_ss7_asp *asp, struct msgb *msg) {
+	OSMO_ASSERT(0);
+}

-- 
To view, visit https://gerrit.osmocom.org/9342
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I38ad8fa645c08900e0e1f1b4b96136bc6d96b3ab
Gerrit-Change-Number: 9342
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180527/57b77d51/attachment.htm>


More information about the gerrit-log mailing list