osmith has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-bsc-nat/+/27474 )
Change subject: msc_fsm: send RESET to MSC on start up
......................................................................
msc_fsm: send RESET to MSC on start up
Automatically send RESET to the MSC as the BSCNAT starts up. Try it
again if it fails, in case the MSC was not started yet or if the SCCP
connection was not up yet (right now it does not seem possible to get
notified when the SCCP connection is up).
Related: SYS#5560
Related:
https://osmocom.org/projects/osmo-bscnat/wiki/AoIP_OsmoBSCNAT#RESET
Change-Id: Icfec3ec0168c7040e88a536fa48da339349fb6cf
---
M include/osmocom/bsc_nat/bssap.h
M include/osmocom/bsc_nat/msc_fsm.h
M src/osmo-bsc-nat/bsc_nat.c
M src/osmo-bsc-nat/bsc_nat_fsm.c
M src/osmo-bsc-nat/bssap.c
M src/osmo-bsc-nat/msc_fsm.c
6 files changed, 143 insertions(+), 19 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-bsc-nat refs/changes/74/27474/1
diff --git a/include/osmocom/bsc_nat/bssap.h b/include/osmocom/bsc_nat/bssap.h
index 1a9324a..e535d5a 100644
--- a/include/osmocom/bsc_nat/bssap.h
+++ b/include/osmocom/bsc_nat/bssap.h
@@ -22,3 +22,5 @@
int bssap_handle_udt(struct bsc_nat_sccp_inst *sccp_inst, struct osmo_sccp_addr *addr,
struct msgb *msgb,
unsigned int length);
+
+int bssap_tx_reset(struct bsc_nat_sccp_inst *sccp_inst, struct osmo_sccp_addr *addr);
diff --git a/include/osmocom/bsc_nat/msc_fsm.h b/include/osmocom/bsc_nat/msc_fsm.h
index 0ea3024..3133a7c 100644
--- a/include/osmocom/bsc_nat/msc_fsm.h
+++ b/include/osmocom/bsc_nat/msc_fsm.h
@@ -19,3 +19,5 @@
#pragma once
void msc_fsm_alloc(struct msc *msc);
+void msc_fsm_connect(struct msc *msc);
+void msc_fsm_rx_reset_ack(struct msc *msc);
diff --git a/src/osmo-bsc-nat/bsc_nat.c b/src/osmo-bsc-nat/bsc_nat.c
index b8c87dd..0a42c96 100644
--- a/src/osmo-bsc-nat/bsc_nat.c
+++ b/src/osmo-bsc-nat/bsc_nat.c
@@ -63,6 +63,7 @@
llist_add(&msc->list, &bsc_nat->mscs);
msc_fsm_alloc(msc);
+ msc_fsm_connect(msc);
return msc;
}
diff --git a/src/osmo-bsc-nat/bsc_nat_fsm.c b/src/osmo-bsc-nat/bsc_nat_fsm.c
index b35376d..f198eca 100644
--- a/src/osmo-bsc-nat/bsc_nat_fsm.c
+++ b/src/osmo-bsc-nat/bsc_nat_fsm.c
@@ -286,24 +286,6 @@
case OSMO_PRIM(OSMO_SCU_PRIM_N_UNITDATA, PRIM_OP_INDICATION):
/* connection-less data received */
rc = bssap_handle_udt(sccp_inst, &prim->u.unitdata.calling_addr, oph->msg,
msgb_l2len(oph->msg));
-
- /* FIXME: don't forward this to the MSC anymore, as soon as the
- * BSCNAT is able to do the RESET to MSC by itself. */
- addr = &prim->u.unitdata.calling_addr;
-
- if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) < 0)
- goto error;
-
- LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr(g_bsc_nat->cn,
&peer_addr_out));
-
- /* oph->msg stores oph and unitdata msg. Move oph->msg->data to
- * unitdata msg and send it again. */
- msgb_pull_to_l2(oph->msg);
- osmo_sccp_tx_unitdata(g_bsc_nat->cn->scu,
- &g_bsc_nat->cn->addr,
- &peer_addr_out,
- oph->msg->data,
- msgb_length(oph->msg));
break;
default:
diff --git a/src/osmo-bsc-nat/bssap.c b/src/osmo-bsc-nat/bssap.c
index ef12192..72fd751 100644
--- a/src/osmo-bsc-nat/bssap.c
+++ b/src/osmo-bsc-nat/bssap.c
@@ -35,6 +35,47 @@
return osmo_sccp_tx_unitdata_msg(sccp_inst->scu, &sccp_inst->addr, addr,
msg);
}
+int bssap_tx_reset(struct bsc_nat_sccp_inst *sccp_inst, struct osmo_sccp_addr *addr)
+{
+ LOGP(DMAIN, LOGL_NOTICE, "Tx RESET to %s\n", bsc_nat_print_addr(sccp_inst,
addr));
+
+ struct msgb *msg = gsm0808_create_reset();
+
+ return osmo_sccp_tx_unitdata_msg(sccp_inst->scu, &sccp_inst->addr, addr,
msg);
+}
+
+static int bssap_cn_handle_reset_ack(struct osmo_sccp_addr *addr, struct msgb *msg,
unsigned int length)
+{
+ struct msc *msc = bsc_nat_msc_get(g_bsc_nat);
+
+ if (msc->addr.pc != addr->pc) {
+ LOGP(DMAIN, LOGL_ERROR, "Unexpected Rx RESET ACK in CN from %s, which is not
%s\n",
+ osmo_ss7_pointcode_print(NULL, addr->pc), talloc_get_name(msc));
+ return -1;
+ }
+
+ LOGP(DMAIN, LOGL_NOTICE, "Rx RESET ACK from %s\n", talloc_get_name(msc));
+ msc_fsm_rx_reset_ack(msc);
+
+ return 0;
+}
+
+static int bssap_cn_rcvmsg_udt(struct osmo_sccp_addr *addr, struct msgb *msg, unsigned
int length)
+{
+ int ret = 0;
+
+ switch (msg->l3h[0]) {
+ case BSS_MAP_MSG_RESET_ACKNOWLEDGE:
+ ret = bssap_cn_handle_reset_ack(addr, msg, length);
+ break;
+ default:
+ LOGP(DMAIN, LOGL_NOTICE, "Unimplemented BSSMAP UDT %s\n",
gsm0808_bssap_name(msg->l3h[0]));
+ break;
+ }
+
+ return ret;
+}
+
static int bssap_ran_handle_reset(struct osmo_sccp_addr *addr, struct msgb *msg, unsigned
int length)
{
struct bsc *bsc;
@@ -74,7 +115,8 @@
LOGP(DMAIN, LOGL_NOTICE, "Rx UDT BSSMAP %s\n",
gsm0808_bssap_name(msg->l3h[0]));
- /* NOTE: bssap_cn_rcvmsg_udt() will be added in a future patch */
+ if (sccp_inst == g_bsc_nat->cn)
+ return bssap_cn_rcvmsg_udt(addr, msg, length - sizeof(struct bssmap_header));
return bssap_ran_rcvmsg_udt(addr, msg, length - sizeof(struct bssmap_header));
}
diff --git a/src/osmo-bsc-nat/msc_fsm.c b/src/osmo-bsc-nat/msc_fsm.c
index 30434f4..2b1ae44 100644
--- a/src/osmo-bsc-nat/msc_fsm.c
+++ b/src/osmo-bsc-nat/msc_fsm.c
@@ -28,19 +28,103 @@
enum msc_fsm_states {
MSC_FSM_ST_DISCONNECTED,
+ MSC_FSM_ST_CONNECTING,
+ MSC_FSM_ST_CONNECTED,
};
+enum msc_fsm_events {
+ MSC_FSM_EV_TX_RESET,
+ MSC_FSM_EV_RX_RESET_ACK,
+ MSC_FSM_EV_DISCONNECT
+};
+
+static void st_connecting(struct osmo_fsm_inst *fi, uint32_t event, void *data)
+{
+ switch (event) {
+ case MSC_FSM_EV_RX_RESET_ACK:
+ osmo_fsm_inst_state_chg(fi, MSC_FSM_ST_CONNECTED, 0, 0);
+ break;
+ default:
+ OSMO_ASSERT(false);
+ }
+}
+
+static void st_disconnected_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_stat)
+{
+ osmo_fsm_inst_dispatch(fi, MSC_FSM_EV_TX_RESET, NULL);
+}
+
+static void st_disconnected(struct osmo_fsm_inst *fi, uint32_t event, void *data)
+{
+ struct msc *msc = fi->priv;
+
+ switch (event) {
+ case MSC_FSM_EV_TX_RESET:
+ LOGP(DMAIN, LOGL_DEBUG, "Tx RESET to %s\n", talloc_get_name(msc));
+
+ if (bssap_tx_reset(g_bsc_nat->cn, &msc->addr) < 0) {
+ LOGP(DMAIN, LOGL_ERROR, "Could not send RESET to MSC (SCCP not up
yet?)\n");
+ }
+
+ /* Retry in 3s if RESET ACK was not received from MSC */
+ osmo_fsm_inst_state_chg(fi, MSC_FSM_ST_CONNECTING, 3, 0);
+
+ break;
+ default:
+ OSMO_ASSERT(false);
+ }
+}
+
+int msc_fsm_timer_cb(struct osmo_fsm_inst *fi)
+{
+ switch (fi->state) {
+ case MSC_FSM_ST_CONNECTING:
+ osmo_fsm_inst_state_chg(fi, MSC_FSM_ST_DISCONNECTED, 0, 0);
+ break;
+ default:
+ OSMO_ASSERT(false);
+ }
+ return 0;
+}
+
static struct osmo_fsm_state msc_fsm_states[] = {
[MSC_FSM_ST_DISCONNECTED] = {
.name = "DISCONNECTED",
.in_event_mask = 0
+ | X(MSC_FSM_EV_TX_RESET)
,
.out_state_mask = 0
+ | X(MSC_FSM_ST_CONNECTING)
+ ,
+ .action = st_disconnected,
+ .onenter = st_disconnected_on_enter,
+ },
+ [MSC_FSM_ST_CONNECTING] = {
+ .name = "CONNECTING",
+ .in_event_mask = 0
+ | X(MSC_FSM_EV_RX_RESET_ACK)
+ ,
+ .out_state_mask = 0
+ | X(MSC_FSM_ST_CONNECTED)
+ | X(MSC_FSM_ST_DISCONNECTED)
+ ,
+ .action = st_connecting,
+ },
+ [MSC_FSM_ST_CONNECTED] = {
+ .name = "CONNECTED",
+ .in_event_mask = 0
+ | X(MSC_FSM_EV_DISCONNECT)
+ ,
+ .out_state_mask = 0
+ | X(MSC_FSM_ST_DISCONNECTED)
,
},
};
const struct value_string msc_fsm_event_names[] = {
+ OSMO_VALUE_STRING(MSC_FSM_EV_TX_RESET),
+ OSMO_VALUE_STRING(MSC_FSM_EV_RX_RESET_ACK),
+ OSMO_VALUE_STRING(MSC_FSM_EV_DISCONNECT),
{ 0, NULL }
};
@@ -50,6 +134,7 @@
.num_states = ARRAY_SIZE(msc_fsm_states),
.log_subsys = DMAIN,
.event_names = msc_fsm_event_names,
+ .timer_cb = msc_fsm_timer_cb,
};
static __attribute__((constructor)) void msc_fsm_init(void)
@@ -62,3 +147,13 @@
msc->fi = osmo_fsm_inst_alloc(&msc_fsm, msc, msc, LOGL_INFO, NULL);
OSMO_ASSERT(msc->fi);
}
+
+void msc_fsm_connect(struct msc *msc)
+{
+ osmo_fsm_inst_dispatch(msc->fi, MSC_FSM_EV_TX_RESET, NULL);
+}
+
+void msc_fsm_rx_reset_ack(struct msc *msc)
+{
+ osmo_fsm_inst_dispatch(msc->fi, MSC_FSM_EV_RX_RESET_ACK, NULL);
+}
--
To view, visit
https://gerrit.osmocom.org/c/osmo-bsc-nat/+/27474
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc-nat
Gerrit-Branch: master
Gerrit-Change-Id: Icfec3ec0168c7040e88a536fa48da339349fb6cf
Gerrit-Change-Number: 27474
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-MessageType: newchange