From 31f525e7560ad13e32cfc5e0b5f1862c0efcb991 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Mon, 14 May 2018 18:14:15 +0200 Subject: large refactoring: use FSMs for lchans; add inter-BSC HO Add FSMs: - timeslot_fsm: handle dynamic timeslots and OML+RSL availability. - lchan_fsm: handle an individual lchan activation, RTP stream and release, signal the appropriate calling FSMs on success, failure, release. - mgw_endpoint_fsm: handle one entire endpoint with several CI. - assignment_fsm: BSSMAP Assignment Request. - handover_fsm: all of intra, inter-MO and inter-MT handover. Above FSMs absorb large parts of the gscon FSM. The gscon FSM was surpassing the maximum amount events (32), and it is more logical to treat assignment, handover and MGW procedures in separate FSMs. - Add logging macros for each FSM type: - LOG_TS() - LOG_LCHAN() - LOG_MGWEP(), LOG_CI() - LOG_ASSIGNMENT() - LOG_HO() These log with the osmo_fsm_inst where present. New style decision: logging without a final newline char is awkward, especially for gsmtap logging and when other logs interleave LOGPC() calls; we have various cases where the final \n goes missing, and also this invokes the log category checking N times instead of once. So I decided to make these macros *always* append a newline, but only if there is no final newline yet. I hope that the compiler optimizes the strlen() of the constant format strings away. Thus I can log with or without typing "\n" and always get an \n termination anyway. General: - replace osmo_timers, state enums and program-wide osmo_signal_dispatch() with dedicated FSM timeouts, states and events. - introduce a common way to handle Tnnn timers: gsm_timers.h/.c: struct T_def. These can be used (with some macro magic) to define a state's timeout once, and not make mistakes for each osmo_fsm_inst_state_chg(). Details: bsc_subscr_conn_fsm.c: - move most states of this FSM to lchan_fsm, assignment_fsm, handover_fsm and mgw_endpoint_fsm. - There is exactly one state for an ongoing Assignment, with all details handled in conn->assignment.fi. The state relies on the assignment_fsm's timeout. - There is one state for an ongoing Handover; except for an incoming Handover from a remote BSS, the gscon remains in ST_INIT until the new lchan and conn are both established. - move bssmap_add_lcls_status() to osmo_bsc_lcls.c abis_rsl.c: - move all dynamic timeslot logic away into timeslot_fsm. Only keep plain send/receive functions in abis_rsl.c - reduce some rsl functions to merely send a message, rename to "_tx_". - rsl_ipacc_mdcx(): add '_tx_' in the name; move parts that change the lchan state out into the lchan_fsm, the lchan->abis_ip.* are now set there prior to invoking this function. - move all timers and error/release handling away into various FSMs. - tweak ipa_smod_s_for_lchan() and ipa_rtp_pt_for_lchan() to not require an lchan passed, but just mode,type that they require. Rename to ipacc_speech_mode*() and ipacc_payload_type(). - add rsl_forward_layer3_info, used for inter-BSC HO MO, to just send the RR message received during BSSMAP Handover Command. - move various logging to LOG_LCHAN() in order to log with the lchan FSM instance. One drawback is that the lchan FSM is limited to one logging category, i.e. this moves some logging from DRR to DRSL. It might actually make sense to combine those categories. - lose LOGP...LOGPC logging cascades: they are bad for gsmtap logging and for performance. - handle_classmark_chg(): change logging, move cm2 len check out of the cm3 condition (I hope that's correct). - gsm48_send_ho_cmd(): split off gsm48_make_ho_cmd() which doesn't send right away, so that during inter-bsc HO we can make an RR Handover Command to send via the MSC to the remote BSS. assignment_fsm.c: - the Chan Mode Modify in case of re-using the same lchan is not implemented yet, because this was also missing in the previous implementation (OS#3357). osmo_bsc_api.c: - simplify bsc_mr_config() and move to lchan_fsm.c, the only caller; rename to lchan_mr_config(). (bsc_mr_config() used to copy the values to mr_bts_lv twice, once by member assignment and then again with a memcpy.) - During handover, we used to copy the MR config from the old lchan. Since we may handover between FR and HR, rather set the MR Config anew every time, so that FR rates are always available on FR lchans, and never on HR lchans. Depends: I03ee7ce840ecfa0b6a33358e7385528aabd4873f (libosmocore), I1f2918418c38918c5ac70acaa51a47adfca12b5e (libosmocore) Change-Id: I82e3f918295daa83274a4cf803f046979f284366 --- src/osmo-bsc/osmo_bsc_lcls.c | 84 +++++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 21 deletions(-) (limited to 'src/osmo-bsc/osmo_bsc_lcls.c') diff --git a/src/osmo-bsc/osmo_bsc_lcls.c b/src/osmo-bsc/osmo_bsc_lcls.c index b197e6607..04826615b 100644 --- a/src/osmo-bsc/osmo_bsc_lcls.c +++ b/src/osmo-bsc/osmo_bsc_lcls.c @@ -28,6 +28,7 @@ #include #include #include +#include #include struct value_string lcls_event_names[] = { @@ -228,24 +229,24 @@ void lcls_apply_config(struct gsm_subscriber_connection *conn) static void lcls_break_local_switching(struct gsm_subscriber_connection *conn) { - struct mgcp_conn_peer peer; - struct sockaddr_in *sin; + struct mgcp_conn_peer mdcx_info; LOGPFSM(conn->lcls.fi, "=== HERE IS WHERE WE DISABLE LCLS\n"); - if (!conn->user_plane.fi_msc) { + if (!conn->user_plane.mgw_endpoint_ci_msc) { /* the MGCP FSM has died, e.g. due to some MGCP/SDP parsing error */ LOGPFSML(conn->lcls.fi, LOGL_NOTICE, "Cannot disable LCLS without MSC-side MGCP FSM\n"); return; } - sin = (struct sockaddr_in *)&conn->user_plane.aoip_rtp_addr_remote; - OSMO_ASSERT(sin->sin_family == AF_INET); + mdcx_info = (struct mgcp_conn_peer){ + .port = conn->user_plane.msc_assigned_rtp_port, + }; + osmo_strlcpy(mdcx_info.addr, conn->user_plane.msc_assigned_rtp_addr, sizeof(mdcx_info.addr)); + mgcp_pick_codec(&mdcx_info, conn->lchan); - memset(&peer, 0, sizeof(peer)); - peer.port = htons(sin->sin_port); - osmo_strlcpy(peer.addr, inet_ntoa(sin->sin_addr), sizeof(peer.addr)); - bsc_subscr_pick_codec(&peer, conn); - mgcp_conn_modify(conn->user_plane.fi_msc, 0, &peer); + mgw_endpoint_ci_request(conn->user_plane.mgw_endpoint_ci_msc, + MGCP_VERB_MDCX, &mdcx_info, + NULL, 0, 0, NULL); } static bool lcls_enable_possible(struct gsm_subscriber_connection *conn) @@ -547,26 +548,35 @@ static void lcls_locally_switched_onenter(struct osmo_fsm_inst *fi, uint32_t pre { struct gsm_subscriber_connection *conn = fi->priv; struct gsm_subscriber_connection *conn_other = conn->lcls.other; - struct mgcp_conn_peer peer; - struct sockaddr_in *sin; + const struct mgcp_conn_peer *other_mgw_info; + struct mgcp_conn_peer mdcx_info; OSMO_ASSERT(conn_other); LOGPFSM(fi, "=== HERE IS WHERE WE ENABLE LCLS\n"); - if (!conn->user_plane.fi_msc) { + if (!conn->user_plane.mgw_endpoint_ci_msc) { + LOGPFSML(fi, LOGL_ERROR, "Cannot enable LCLS without MSC-side MGCP FSM. FIXME\n"); + return; + } + if (!conn_other->user_plane.mgw_endpoint_ci_msc) { LOGPFSML(fi, LOGL_ERROR, "Cannot enable LCLS without MSC-side MGCP FSM. FIXME\n"); return; } - sin = (struct sockaddr_in *)&conn_other->user_plane.aoip_rtp_addr_local; - OSMO_ASSERT(sin->sin_family == AF_INET); - - memset(&peer, 0, sizeof(peer)); - peer.port = htons(sin->sin_port); - osmo_strlcpy(peer.addr, inet_ntoa(sin->sin_addr), sizeof(peer.addr)); - bsc_subscr_pick_codec(&peer, conn); - mgcp_conn_modify(conn->user_plane.fi_msc, 0, &peer); + other_mgw_info = mgwep_ci_get_rtp_info(conn_other->user_plane.mgw_endpoint_ci_msc); + if (!other_mgw_info) { + LOGPFSML(fi, LOGL_ERROR, "Cannot enable LCLS without RTP port info of MSC-side" + " -- missing CRCX?\n"); + return; + } + mdcx_info = *other_mgw_info; + /* Make sure the request doesn't want to use the other side's endpoint string. */ + mdcx_info.endpoint[0] = 0; + mgcp_pick_codec(&mdcx_info, conn->lchan); + mgw_endpoint_ci_request(conn->user_plane.mgw_endpoint_ci_msc, + MGCP_VERB_MDCX, &mdcx_info, + NULL, 0, 0, NULL); } static void lcls_locally_switched_wait_break_fn(struct osmo_fsm_inst *fi, uint32_t event, void *data) @@ -766,3 +776,35 @@ struct osmo_fsm lcls_fsm = { .log_subsys = DLCLS, .event_names = lcls_event_names, }; + +/* Add the LCLS BSS Status IE to a BSSMAP message. We assume this is + * called on a msgb that was returned by gsm0808_create_ass_compl() */ +static void bssmap_add_lcls_status(struct msgb *msg, enum gsm0808_lcls_status status) +{ + OSMO_ASSERT(msg->l3h[0] == BSSAP_MSG_BSS_MANAGEMENT); + OSMO_ASSERT(msg->l3h[2] == BSS_MAP_MSG_ASSIGMENT_COMPLETE || + msg->l3h[2] == BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE || + msg->l3h[2] == BSS_MAP_MSG_HANDOVER_COMPLETE || + msg->l3h[2] == BSS_MAP_MSG_HANDOVER_PERFORMED); + OSMO_ASSERT(msgb_tailroom(msg) >= 2); + + /* append IE to end of message */ + msgb_tv_put(msg, GSM0808_IE_LCLS_BSS_STATUS, status); + /* increment the "length" byte in the BSSAP header */ + msg->l3h[1] += 2; +} + +/* Add (append) the LCLS BSS Status IE to a BSSMAP message, if there is any LCLS + * active on the given \a conn */ +void bssmap_add_lcls_status_if_needed(struct gsm_subscriber_connection *conn, struct msgb *msg) +{ + enum gsm0808_lcls_status status = lcls_get_status(conn); + if (status != 0xff) { + LOGPFSM(conn->fi, "Adding LCLS BSS-Status (%s) to %s\n", + gsm0808_lcls_status_name(status), + gsm0808_bssmap_name(msg->l3h[2])); + bssmap_add_lcls_status(msg, status); + } +} + + -- cgit v1.2.3