osmith has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-bsc/+/38753?usp=email )
Change subject: Add osmo_ss7 APIs
......................................................................
Add osmo_ss7 APIs
Prepare OsmoBSC to work with newer versions of libosmo-sigtran, where
struct osmo_ss7_instance was made private. Ensure the APIs are always
present even if building with older libosmo-sigtran, so we can apply
patches that switches over to using these APIs instead of accessing the
struct directly.
Related: OS#6617
Change-Id: I327664775e94cf1bae203e98f3324d9ab63ee6d0
---
M configure.ac
M include/osmocom/bsc/Makefile.am
A include/osmocom/bsc/sigtran_compat.h
M src/osmo-bsc/Makefile.am
M src/osmo-bsc/bsc_ctrl.c
M src/osmo-bsc/bsc_vty.c
M src/osmo-bsc/lb.c
M src/osmo-bsc/osmo_bsc_sigtran.c
A src/osmo-bsc/sigtran_compat.c
9 files changed, 157 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/53/38753/1
diff --git a/configure.ac b/configure.ac
index ef43aa6..601134d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -224,6 +224,18 @@
AC_MSG_RESULT([CFLAGS="$CFLAGS"])
AC_MSG_RESULT([CPPFLAGS="$CPPFLAGS"])
+# OS#6617: check if libosmo-sigtran has private structs
+# We need to use grep here, can't set the includedir with AC_CHECK_DECL.
+m="OS#6617: checking whether libosmo-sigtran has private structs..."
+h="$($PKG_CONFIG --variable=includedir
libosmo-sigtran)/osmocom/sigtran/osmo_ss7.h"
+f=osmo_ss7_as_select_asp
+if grep -q "$f" "$h"; then
+ echo "$m yes ($f in $h)"
+ AC_DEFINE(SIGTRAN_PRIVATE_STRUCTS, [1], ["OS#6617"])
+else
+ echo "$m no ($f not in $h)"
+fi
+
dnl Generate the output
AM_CONFIG_HEADER(bscconfig.h)
diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index a560f23..d0f7c52 100644
--- a/include/osmocom/bsc/Makefile.am
+++ b/include/osmocom/bsc/Makefile.am
@@ -67,4 +67,5 @@
smscb.h \
power_control.h \
vgcs_fsm.h \
+ sigtran_compat.h \
$(NULL)
diff --git a/include/osmocom/bsc/sigtran_compat.h b/include/osmocom/bsc/sigtran_compat.h
new file mode 100644
index 0000000..59b40d6
--- /dev/null
+++ b/include/osmocom/bsc/sigtran_compat.h
@@ -0,0 +1,35 @@
+#pragma once
+#include "../../bscconfig.h"
+
+#include <osmocom/sigtran/osmo_ss7.h>
+
+#ifndef SIGTRAN_PRIVATE_STRUCTS
+
+static inline struct osmo_ss7_as *osmo_ss7_route_get_dest_as(struct osmo_ss7_route *rt)
+{
+ return rt->dest.as;
+}
+
+static inline uint32_t osmo_ss7_instance_get_id(const struct osmo_ss7_instance *inst)
+{
+ return inst->cfg.id;
+}
+
+static inline struct osmo_ss7_instance *osmo_ss7_instances_llist_entry(struct llist_head
*list)
+{
+ struct osmo_ss7_instance *pos;
+ pos = llist_entry(list, struct osmo_ss7_instance, list);
+ return pos;
+}
+
+static inline enum osmo_ss7_asp_protocol osmo_ss7_as_get_asp_protocol(const struct
osmo_ss7_as *as)
+{
+ return as->cfg.proto;
+}
+
+struct osmo_ss7_asp *ss7_as_select_asp_override(struct osmo_ss7_as *as);
+struct osmo_ss7_asp *ss7_as_select_asp_roundrobin(struct osmo_ss7_as *as);
+struct osmo_ss7_asp *ss7_as_select_asp_broadcast(struct osmo_ss7_as *as);
+struct osmo_ss7_asp *osmo_ss7_as_select_asp(struct osmo_ss7_as *as);
+
+#endif
diff --git a/src/osmo-bsc/Makefile.am b/src/osmo-bsc/Makefile.am
index 1026523..2ac133f 100644
--- a/src/osmo-bsc/Makefile.am
+++ b/src/osmo-bsc/Makefile.am
@@ -117,6 +117,7 @@
cbch_scheduler.c \
cbsp_link.c \
power_control.c \
+ sigtran_compat.c \
$(NULL)
libbsc_la_LIBADD = \
diff --git a/src/osmo-bsc/bsc_ctrl.c b/src/osmo-bsc/bsc_ctrl.c
index aff1d83..caef66e 100644
--- a/src/osmo-bsc/bsc_ctrl.c
+++ b/src/osmo-bsc/bsc_ctrl.c
@@ -44,6 +44,7 @@
#include <osmocom/bsc/ctrl.h>
#include <osmocom/bsc/handover_ctrl.h>
#include <osmocom/bsc/neighbor_ident.h>
+#include <osmocom/bsc/sigtran_compat.h>
static int verify_net_apply_config_file(struct ctrl_cmd *cmd, const char *value, void
*_data)
{
diff --git a/src/osmo-bsc/bsc_vty.c b/src/osmo-bsc/bsc_vty.c
index 8690a47..9558330 100644
--- a/src/osmo-bsc/bsc_vty.c
+++ b/src/osmo-bsc/bsc_vty.c
@@ -68,6 +68,7 @@
#include <osmocom/bsc/bsc_msc_data.h>
#include <osmocom/bsc/lchan.h>
#include <osmocom/bsc/pcu_if.h>
+#include <osmocom/bsc/sigtran_compat.h>
#include <inttypes.h>
diff --git a/src/osmo-bsc/lb.c b/src/osmo-bsc/lb.c
index 511a545..9d5f78e 100644
--- a/src/osmo-bsc/lb.c
+++ b/src/osmo-bsc/lb.c
@@ -32,6 +32,7 @@
#include <osmocom/bsc/lcs_loc_req.h>
#include <osmocom/bsc/bssmap_reset.h>
#include <osmocom/bsc/gsm_data.h>
+#include <osmocom/bsc/sigtran_compat.h>
/* Send reset to SMLC */
int bssmap_le_tx_reset(void)
diff --git a/src/osmo-bsc/osmo_bsc_sigtran.c b/src/osmo-bsc/osmo_bsc_sigtran.c
index cdc5785..d1d4d18 100644
--- a/src/osmo-bsc/osmo_bsc_sigtran.c
+++ b/src/osmo-bsc/osmo_bsc_sigtran.c
@@ -37,6 +37,7 @@
#include <osmocom/bsc/bts.h>
#include <osmocom/bsc/paging.h>
#include <osmocom/bsc/bssmap_reset.h>
+#include <osmocom/bsc/sigtran_compat.h>
#include <osmocom/mgcp_client/mgcp_common.h>
#include <osmocom/netif/ipa.h>
diff --git a/src/osmo-bsc/sigtran_compat.c b/src/osmo-bsc/sigtran_compat.c
new file mode 100644
index 0000000..30f0d5b
--- /dev/null
+++ b/src/osmo-bsc/sigtran_compat.c
@@ -0,0 +1,104 @@
+/* (C) 2024 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de>
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#include "../../bscconfig.h"
+
+#include <osmocom/bsc/sigtran_compat.h>
+
+#ifndef SIGTRAN_PRIVATE_STRUCTS
+
+struct osmo_ss7_asp *ss7_as_select_asp_override(struct osmo_ss7_as *as)
+{
+ struct osmo_ss7_asp *asp;
+ unsigned int i;
+
+ /* FIXME: proper selection of the ASP based on the SLS! */
+ for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) {
+ asp = as->cfg.asps[i];
+ if (asp && osmo_ss7_asp_active(asp))
+ break;
+ }
+ return asp;
+}
+
+struct osmo_ss7_asp *ss7_as_select_asp_roundrobin(struct osmo_ss7_as *as)
+{
+ struct osmo_ss7_asp *asp;
+ unsigned int i;
+ unsigned int first_idx;
+
+ first_idx = (as->cfg.last_asp_idx_sent + 1) % ARRAY_SIZE(as->cfg.asps);
+ i = first_idx;
+ do {
+ asp = as->cfg.asps[i];
+ if (asp && osmo_ss7_asp_active(asp))
+ break;
+ i = (i + 1) % ARRAY_SIZE(as->cfg.asps);
+ } while (i != first_idx);
+ as->cfg.last_asp_idx_sent = i;
+
+ return asp;
+}
+
+/* returns NULL if multiple ASPs would need to be selected. */
+struct osmo_ss7_asp *ss7_as_select_asp_broadcast(struct osmo_ss7_as *as)
+{
+ struct osmo_ss7_asp *asp;
+ struct osmo_ss7_asp *asp_found = NULL;
+
+ for (unsigned int i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) {
+ asp = as->cfg.asps[i];
+ if (!asp || !osmo_ss7_asp_active(asp))
+ continue;
+ if (asp_found) /* >1 ASPs selected, early return */
+ return NULL;
+ asp_found = asp;
+ }
+ return asp_found;
+}
+
+struct osmo_ss7_asp *osmo_ss7_as_select_asp(struct osmo_ss7_as *as)
+{
+ struct osmo_ss7_asp *asp = NULL;
+
+ switch (as->cfg.mode) {
+ case OSMO_SS7_AS_TMOD_OVERRIDE:
+ asp = ss7_as_select_asp_override(as);
+ break;
+ case OSMO_SS7_AS_TMOD_LOADSHARE:
+ /* TODO: actually use the SLS value to ensure same SLS goes
+ * through same ASP. Not strictly required by M3UA RFC, but
+ * would fit the overall principle. */
+ case OSMO_SS7_AS_TMOD_ROUNDROBIN:
+ asp = ss7_as_select_asp_roundrobin(as);
+ break;
+ case OSMO_SS7_AS_TMOD_BCAST:
+ return ss7_as_select_asp_broadcast(as);
+ case _NUM_OSMO_SS7_ASP_TMOD:
+ OSMO_ASSERT(false);
+ }
+
+ if (!asp) {
+ LOGPFSM(as->fi, "No selectable ASP in AS\n");
+ return NULL;
+ }
+ return asp;
+}
+
+#endif
--
To view, visit
https://gerrit.osmocom.org/c/osmo-bsc/+/38753?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-bsc
Gerrit-Branch: osmith/1.12.2
Gerrit-Change-Id: I327664775e94cf1bae203e98f3324d9ab63ee6d0
Gerrit-Change-Number: 38753
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith(a)sysmocom.de>