more fsm wip
Change-Id: I29c7eca5f56061b66e303b952f8f04c71438fe8b
This commit is contained in:
parent
63965b4c25
commit
edf22db326
|
@ -11,7 +11,7 @@ bin_PROGRAMS = osmo-cbc
|
|||
|
||||
osmo_cbc_SOURCES = cbc_main.c cbc_data.c cbc_vty.c cbsp_server.c cbsp_server_fsm.c \
|
||||
rest_api.c charset.c message_handling.c rest_it_op.c \
|
||||
smscb_peer_fsm.c
|
||||
smscb_peer_fsm.c smscb_message_fsm.c
|
||||
osmo_cbc_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) \
|
||||
$(LIBOSMONETIF_LIBS) \
|
||||
$(ULFIUS_LIBS) $(JANSSON_LIBS) $(ORCANIA_LIBS)
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
struct osmo_cbsp_cbc_client;
|
||||
struct osmo_sabp_cbc_client;
|
||||
struct rest_it_op;
|
||||
|
||||
/*********************************************************************************
|
||||
* CBC Peer
|
||||
|
@ -138,10 +139,12 @@ struct cbc_message {
|
|||
/* SMSCB message with id, serial, dcs, pages, ... */
|
||||
struct smscb_message msg;
|
||||
|
||||
struct osmo_fsm_inst *fi; /* FSM instance */
|
||||
struct osmo_fsm_inst *fi; /* FSM instance (smscb_message_fsm) */
|
||||
|
||||
/* CBC peers (BSCs, RNCs, MMEs) to which this message has already been sent */
|
||||
struct llist_head peers;
|
||||
|
||||
struct rest_it_op *it_op; /* inter-thread queue operation currently processing */
|
||||
};
|
||||
|
||||
/*********************************************************************************
|
||||
|
@ -166,9 +169,11 @@ extern struct cbc *g_cbc;
|
|||
|
||||
int cbc_message_del_peer(struct cbc_message *cbcmsg, struct cbc_peer *peer);
|
||||
int cbc_message_add_peer(struct cbc_message *cbcmsg, struct cbc_peer *peer);
|
||||
struct cbc_message_peer *smscb_peer_fsm_alloc(struct cbc_peer *peer, struct cbc_message *cbcmsg);
|
||||
struct cbc_message_peer *cbc_message_peer_get(struct cbc_message *cbcmsg, struct cbc_peer *peer);
|
||||
struct cbc_peer *cbc_peer_by_name(const char *name);
|
||||
struct cbc_peer *cbc_peer_by_addr_proto(const char *remote_host, uint16_t remote_port,
|
||||
enum cbc_peer_protocol proto);
|
||||
struct cbc_peer *cbc_peer_create(const char *name, enum cbc_peer_protocol proto);
|
||||
void cbc_peer_remove(struct cbc_peer *peer);
|
||||
|
||||
|
|
|
@ -31,7 +31,8 @@ void rest_api_fin(void);
|
|||
void cbc_vty_init(void);
|
||||
|
||||
/* message_handling.c */
|
||||
int cbc_message_new(struct cbc_message *cbcmsg);
|
||||
int cbc_message_new(const struct cbc_message *cbcmsg);
|
||||
void cbc_message_delete(struct cbc_message *cbcmsg);
|
||||
struct cbc_message *cbc_message_by_id(uint16_t message_id);
|
||||
|
||||
/* rest_it_op.c */
|
||||
|
@ -62,3 +63,28 @@ enum smscb_fsm_event {
|
|||
SMSCB_E_CBSP_STATUS_ACK,
|
||||
SMSCB_E_CBSP_STATUS_NACK,
|
||||
};
|
||||
|
||||
enum smscb_fsm_state {
|
||||
/* initial state after creation */
|
||||
SMSCB_S_INIT,
|
||||
/* peer (BSC) have been notified of this SMSCB; we're waiting for ACK */
|
||||
SMSCB_S_WAIT_WRITE_ACK,
|
||||
/* peer (BSC) have confirmed it, message is active */
|
||||
SMSCB_S_ACTIVE,
|
||||
/* we have modified the message and sent REPLACE to peer; we're waiting for ACK */
|
||||
SMSCB_S_WAIT_REPLACE_ACK,
|
||||
/* we have modified the message and sent REPLACE to peer; we're waiting for ACK */
|
||||
SMSCB_S_WAIT_STATUS_ACK,
|
||||
/* we have deleted the message and sent KILL to peer; wait for ACK */
|
||||
SMSCB_S_WAIT_DELETE_ACK,
|
||||
SMSCB_S_DELETED,
|
||||
};
|
||||
|
||||
enum smscb_p_fsm_timer {
|
||||
T_WAIT_WRITE_ACK,
|
||||
T_WAIT_REPLACE_ACK,
|
||||
T_WAIT_STATUS_ACK,
|
||||
T_WAIT_DELETE_ACK,
|
||||
};
|
||||
|
||||
extern const struct value_string smscb_fsm_event_names[];
|
||||
|
|
|
@ -104,12 +104,13 @@ static bool is_peer_in_scope(const struct cbc_peer *peer, const struct cbc_messa
|
|||
switch (cbcmsg->scope) {
|
||||
case CBC_MSG_SCOPE_PLMN:
|
||||
return true;
|
||||
/* FIXME: differnt scopes */
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* send given message to given peer */
|
||||
/* send given new message to given peer */
|
||||
int peer_new_cbc_message(struct cbc_peer *peer, struct cbc_message *cbcmsg)
|
||||
{
|
||||
struct osmo_cbsp_decoded *cbsp;
|
||||
|
@ -123,29 +124,43 @@ int peer_new_cbc_message(struct cbc_peer *peer, struct cbc_message *cbcmsg)
|
|||
OSMO_ASSERT(0);
|
||||
}
|
||||
|
||||
/* record that we've sent the message to the peer */
|
||||
//cbc_message_add_peer(cbcmsg, peer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* receive a new CBC message from the user (REST). Allocates new memory,
|
||||
* a FSM, copies data from 'orig', routes to all peers and starts FSMs */
|
||||
int cbc_message_new(const struct cbc_message *orig)
|
||||
{
|
||||
struct cbc_message *cbcmsg = cbc_message_alloc(g_cbc, orig);
|
||||
struct cbc_peer *peer;
|
||||
|
||||
OSMO_ASSERT(llist_empty(&cbcmsg->peers));
|
||||
|
||||
/* iterate over all peers */
|
||||
llist_for_each_entry(peer, &g_cbc->peers, list) {
|
||||
struct cbc_message_peer *mp;
|
||||
|
||||
if (!is_peer_in_scope(peer, cbcmsg))
|
||||
continue;
|
||||
|
||||
/* allocate new cbc_mesage_peer + related FSM */
|
||||
mp = smscb_peer_fsm_alloc(peer, cbcmsg);
|
||||
if (!mp) {
|
||||
LOGP(DCBSP, LOGL_ERROR, "Cannot allocate cbc_message_peer\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* kick off the state machine[s] */
|
||||
osmo_fsm_inst_dispatch(cbcmsg->fi, SMSCB_E_CREATE, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* receive a new CBC message */
|
||||
int cbc_message_new(struct cbc_message *cbcmsg)
|
||||
void cbc_message_delete(struct cbc_message *cbcmsg)
|
||||
{
|
||||
struct cbc_peer *peer;
|
||||
|
||||
/* FIXME: check for duplicate message_id / serial_nr */
|
||||
|
||||
/* add to global list of messages */
|
||||
llist_add_tail(&cbcmsg->list, &g_cbc->messages);
|
||||
|
||||
/* iterate over all peers */
|
||||
llist_for_each_entry(peer, &g_cbc->peers, list) {
|
||||
if (!is_peer_in_scope(peer, cbcmsg))
|
||||
continue;
|
||||
peer_new_cbc_message(peer, cbcmsg);
|
||||
}
|
||||
return 0;
|
||||
osmo_fsm_inst_dispatch(cbcmsg->fi, SMSCB_E_DELETE, NULL);
|
||||
/* TODO: how to handle completion */
|
||||
}
|
||||
|
||||
struct cbc_message *cbc_message_by_id(uint16_t message_id)
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
* HTTP THREAD
|
||||
***********************************************************************/
|
||||
|
||||
/* allocate an inter-thread operation */
|
||||
struct rest_it_op *rest_it_op_alloc(void *ctx)
|
||||
{
|
||||
struct rest_it_op *op = talloc_zero(ctx, struct rest_it_op);
|
||||
|
@ -82,8 +83,10 @@ void rest2main_read_cb(struct osmo_it_q *q, void *item)
|
|||
{
|
||||
struct rest_it_op *op = item;
|
||||
struct cbc_message *cbc_msg;
|
||||
|
||||
/* FIXME: look up related message and dispatch to message FSM,
|
||||
* which will eventually call pthread_cond_signal(&op->cond) */
|
||||
|
||||
switch (op->operation) {
|
||||
case REST_IT_OP_MSG_CREATE:
|
||||
/* FIXME: send to message FSM who can addd it on RAN */
|
||||
|
@ -93,10 +96,13 @@ void rest2main_read_cb(struct osmo_it_q *q, void *item)
|
|||
/* FIXME: send to message FSM who can remove it from RAN */
|
||||
cbc_msg = cbc_message_by_id(op->u.del.msg_id);
|
||||
if (cbc_msg) {
|
||||
llist_del(&cbc_msg->list);
|
||||
talloc_free(cbc_msg);
|
||||
cbc_message_delete(cbc_msg);
|
||||
} else {
|
||||
/* FIXME: immediately wake up? */
|
||||
}
|
||||
break;
|
||||
/* TODO: REPLACE */
|
||||
/* TODO: STATUS */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,365 @@
|
|||
/* SMSCB FSM: Represent master state about one SMSCB message. Parent of smscb_peer_fsm */
|
||||
|
||||
/* (C) 2019-2020 by Harald Welte <laforge@gnumonks.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0+
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/core/talloc.h>
|
||||
#include <osmocom/core/fsm.h>
|
||||
|
||||
#include <osmocom/gsm/gsm23003.h>
|
||||
#include <osmocom/gsm/protocol/gsm_08_08.h>
|
||||
#include <osmocom/gsm/gsm0808_utils.h>
|
||||
#include <osmocom/gsm/cbsp.h>
|
||||
|
||||
#include "cbc_data.h"
|
||||
#include "cbsp_server.h"
|
||||
#include "internal.h"
|
||||
#include "rest_it_op.h"
|
||||
|
||||
#define S(x) (1 << (x))
|
||||
|
||||
static void smscb_fsm_init(struct osmo_fsm_inst *fi, uint32_t event, void *data)
|
||||
{
|
||||
struct cbc_message *cbcmsg = fi->priv;
|
||||
|
||||
switch (event) {
|
||||
case SMSCB_E_CREATE:
|
||||
OSMO_ASSERT(!cbcmsg->it_op);
|
||||
cbcmsg->it_op = data;
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_WAIT_WRITE_ACK, 15, T_WAIT_WRITE_ACK);
|
||||
/* forward this event to all child FSMs (i.e. all smscb_message_peer) */
|
||||
osmo_fsm_inst_broadcast_children(fi, SMSCB_E_CREATE, data);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void smscb_fsm_wait_write_ack(struct osmo_fsm_inst *fi, uint32_t event, void *data)
|
||||
{
|
||||
struct cbc_message *cbcmsg = fi->priv;
|
||||
struct cbc_message_peer *mp = NULL;
|
||||
struct osmo_fsm_inst *peer_fi;
|
||||
|
||||
switch (event) {
|
||||
case SMSCB_E_CBSP_WRITE_ACK:
|
||||
case SMSCB_E_CBSP_WRITE_NACK:
|
||||
mp = data;
|
||||
/* check if any per-peer children have not yet received the ACK or
|
||||
* timed out */
|
||||
llist_for_each_entry(peer_fi, &fi->proc.children, list) {
|
||||
if (peer_fi->state == SMSCB_S_WAIT_WRITE_ACK)
|
||||
break;
|
||||
}
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void smscb_fsm_wait_write_ack_onleave(struct osmo_fsm_inst *fi, uint32_t new_state)
|
||||
{
|
||||
struct cbc_message *cbcmsg = fi->priv;
|
||||
/* release the mutex from the REST interface + respond to user */
|
||||
if (cbcmsg->it_op) {
|
||||
pthread_cond_signal(&cbcmsg->it_op->cond);
|
||||
cbcmsg->it_op = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void smscb_fsm_active(struct osmo_fsm_inst *fi, uint32_t event, void *data)
|
||||
{
|
||||
struct cbc_message *cbcmsg = fi->priv;
|
||||
|
||||
switch (event) {
|
||||
case SMSCB_E_REPLACE:
|
||||
OSMO_ASSERT(!cbcmsg->it_op);
|
||||
cbcmsg->it_op = data;
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_WAIT_REPLACE_ACK, 15, T_WAIT_REPLACE_ACK);
|
||||
/* forward this event to all child FSMs (i.e. all smscb_message_peer) */
|
||||
osmo_fsm_inst_broadcast_children(fi, SMSCB_E_REPLACE, data);
|
||||
break;
|
||||
case SMSCB_E_STATUS:
|
||||
OSMO_ASSERT(!cbcmsg->it_op);
|
||||
cbcmsg->it_op = data;
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_WAIT_STATUS_ACK, 15, T_WAIT_STATUS_ACK);
|
||||
/* forward this event to all child FSMs (i.e. all smscb_message_peer) */
|
||||
osmo_fsm_inst_broadcast_children(fi, SMSCB_E_STATUS, data);
|
||||
break;
|
||||
case SMSCB_E_DELETE:
|
||||
OSMO_ASSERT(!cbcmsg->it_op);
|
||||
cbcmsg->it_op = data;
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_WAIT_DELETE_ACK, 15, T_WAIT_DELETE_ACK);
|
||||
/* forward this event to all child FSMs (i.e. all smscb_message_peer) */
|
||||
osmo_fsm_inst_broadcast_children(fi, SMSCB_E_DELETE, data);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void smscb_fsm_wait_replace_ack(struct osmo_fsm_inst *fi, uint32_t event, void *data)
|
||||
{
|
||||
struct cbc_message_peer *mp = NULL;
|
||||
struct osmo_fsm_inst *peer_fi;
|
||||
|
||||
switch (event) {
|
||||
case SMSCB_E_CBSP_REPLACE_ACK:
|
||||
case SMSCB_E_CBSP_REPLACE_NACK:
|
||||
mp = data;
|
||||
llist_for_each_entry(peer_fi, &fi->proc.children, list) {
|
||||
if (peer_fi->state == SMSCB_S_WAIT_REPLACE_ACK)
|
||||
break;
|
||||
}
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void smscb_fsm_wait_replace_ack_onleave(struct osmo_fsm_inst *fi, uint32_t new_state)
|
||||
{
|
||||
struct cbc_message *cbcmsg = fi->priv;
|
||||
/* release the mutex from the REST interface + respond to user */
|
||||
if (cbcmsg->it_op) {
|
||||
pthread_cond_signal(&cbcmsg->it_op->cond);
|
||||
cbcmsg->it_op = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void smscb_fsm_wait_status_ack(struct osmo_fsm_inst *fi, uint32_t event, void *data)
|
||||
{
|
||||
struct cbc_message_peer *mp = NULL;
|
||||
struct osmo_fsm_inst *peer_fi;
|
||||
|
||||
switch (event) {
|
||||
case SMSCB_E_CBSP_STATUS_ACK:
|
||||
case SMSCB_E_CBSP_STATUS_NACK:
|
||||
mp = data;
|
||||
llist_for_each_entry(peer_fi, &fi->proc.children, list) {
|
||||
if (peer_fi->state == SMSCB_S_WAIT_STATUS_ACK)
|
||||
break;
|
||||
}
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void smscb_fsm_wait_status_ack_onleave(struct osmo_fsm_inst *fi, uint32_t new_state)
|
||||
{
|
||||
struct cbc_message *cbcmsg = fi->priv;
|
||||
/* release the mutex from the REST interface + respond to user */
|
||||
if (cbcmsg->it_op) {
|
||||
pthread_cond_signal(&cbcmsg->it_op->cond);
|
||||
cbcmsg->it_op = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void smscb_fsm_wait_delete_ack(struct osmo_fsm_inst *fi, uint32_t event, void *data)
|
||||
{
|
||||
struct cbc_message_peer *mp = NULL;
|
||||
struct osmo_fsm_inst *peer_fi;
|
||||
|
||||
switch (event) {
|
||||
case SMSCB_E_CBSP_DELETE_ACK:
|
||||
case SMSCB_E_CBSP_DELETE_NACK:
|
||||
mp = data;
|
||||
llist_for_each_entry(peer_fi, &fi->proc.children, list) {
|
||||
if (peer_fi->state == SMSCB_S_WAIT_DELETE_ACK)
|
||||
break;
|
||||
}
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_DELETED, 0, 0);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void smscb_fsm_wait_delete_ack_onleave(struct osmo_fsm_inst *fi, uint32_t new_state)
|
||||
{
|
||||
struct cbc_message *cbcmsg = fi->priv;
|
||||
/* release the mutex from the REST interface + respond to user */
|
||||
if (cbcmsg->it_op) {
|
||||
pthread_cond_signal(&cbcmsg->it_op->cond);
|
||||
cbcmsg->it_op = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void smscb_fsm_deleted_onenter(struct osmo_fsm_inst *fi, uint32_t old_state)
|
||||
{
|
||||
/* release the mutex from the REST interface, then destroy */
|
||||
struct cbc_message *cbcmsg = fi->priv;
|
||||
if (cbcmsg->it_op) {
|
||||
pthread_cond_signal(&cbcmsg->it_op->cond);
|
||||
cbcmsg->it_op = NULL;
|
||||
}
|
||||
osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, NULL);
|
||||
}
|
||||
|
||||
static struct osmo_fsm_state smscb_fsm_states[] = {
|
||||
[SMSCB_S_INIT] = {
|
||||
.in_event_mask = S(SMSCB_E_CREATE),
|
||||
.out_state_mask = S(SMSCB_S_WAIT_WRITE_ACK),
|
||||
.action = smscb_fsm_init,
|
||||
},
|
||||
[SMSCB_S_WAIT_WRITE_ACK] = {
|
||||
.in_event_mask = S(SMSCB_E_CBSP_WRITE_ACK) |
|
||||
S(SMSCB_E_CBSP_WRITE_NACK),
|
||||
.out_state_mask = S(SMSCB_S_ACTIVE),
|
||||
.action = smscb_fsm_wait_write_ack,
|
||||
.onleave = smscb_fsm_wait_write_ack_onleave,
|
||||
},
|
||||
[SMSCB_S_ACTIVE] = {
|
||||
.in_event_mask = S(SMSCB_E_REPLACE) |
|
||||
S(SMSCB_E_STATUS) |
|
||||
S(SMSCB_E_DELETE),
|
||||
.out_state_mask = S(SMSCB_S_ACTIVE) |
|
||||
S(SMSCB_S_WAIT_REPLACE_ACK) |
|
||||
S(SMSCB_S_WAIT_STATUS_ACK) |
|
||||
S(SMSCB_S_WAIT_DELETE_ACK),
|
||||
.action = smscb_fsm_active,
|
||||
},
|
||||
[SMSCB_S_WAIT_REPLACE_ACK] = {
|
||||
.in_event_mask = S(SMSCB_E_CBSP_REPLACE_ACK) |
|
||||
S(SMSCB_E_CBSP_REPLACE_NACK),
|
||||
.out_state_mask = S(SMSCB_S_ACTIVE),
|
||||
.action = smscb_fsm_wait_replace_ack,
|
||||
.onleave = smscb_fsm_wait_replace_ack_onleave,
|
||||
},
|
||||
[SMSCB_S_WAIT_STATUS_ACK] = {
|
||||
.in_event_mask = S(SMSCB_E_CBSP_STATUS_ACK) |
|
||||
S(SMSCB_E_CBSP_STATUS_NACK),
|
||||
.out_state_mask = S(SMSCB_S_ACTIVE),
|
||||
.action = smscb_fsm_wait_status_ack,
|
||||
.onleave = smscb_fsm_wait_status_ack_onleave,
|
||||
},
|
||||
[SMSCB_S_WAIT_DELETE_ACK] = {
|
||||
.in_event_mask = S(SMSCB_E_CBSP_DELETE_ACK) |
|
||||
S(SMSCB_E_CBSP_DELETE_NACK),
|
||||
.out_state_mask = S(SMSCB_S_ACTIVE),
|
||||
.action = smscb_fsm_wait_delete_ack,
|
||||
.onleave = smscb_fsm_wait_delete_ack_onleave,
|
||||
},
|
||||
[SMSCB_S_DELETED] = {
|
||||
.in_event_mask = 0,
|
||||
.out_state_mask = 0,
|
||||
.onenter = smscb_fsm_deleted_onenter,
|
||||
//.action = smscb_fsm_deleted,
|
||||
},
|
||||
};
|
||||
|
||||
static int smscb_fsm_timer_cb(struct osmo_fsm_inst *fi)
|
||||
{
|
||||
switch (fi->T) {
|
||||
case T_WAIT_WRITE_ACK:
|
||||
/* onexit will take care of notifying the user */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
break;
|
||||
case T_WAIT_REPLACE_ACK:
|
||||
/* onexit will take care of notifying the user */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
break;
|
||||
case T_WAIT_STATUS_ACK:
|
||||
/* onexit will take care of notifying the user */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
break;
|
||||
case T_WAIT_DELETE_ACK:
|
||||
/* onexit will take care of notifying the user */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_DELETED, 0, 0);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void smscb_fsm_allstate(struct osmo_fsm_inst *Fi, uint32_t event, void *data)
|
||||
{
|
||||
switch (event) {
|
||||
case SMSCB_E_CHILD_DIED:
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void smscb_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause)
|
||||
{
|
||||
struct cbc_message *cbcmsg = fi->priv;
|
||||
|
||||
OSMO_ASSERT(llist_empty(&cbcmsg->peers));
|
||||
|
||||
llist_del(&cbcmsg->list);
|
||||
/* memory of cbcmsg is child of fi and hence automatically free'd */
|
||||
}
|
||||
|
||||
static struct osmo_fsm smscb_fsm = {
|
||||
.name = "SMSCB",
|
||||
.states = smscb_fsm_states,
|
||||
.num_states = ARRAY_SIZE(smscb_fsm_states),
|
||||
.allstate_event_mask = S(SMSCB_E_CHILD_DIED),
|
||||
.allstate_action = smscb_fsm_allstate,
|
||||
.timer_cb = smscb_fsm_timer_cb,
|
||||
.log_subsys = DCBSP,
|
||||
.event_names = smscb_fsm_event_names,
|
||||
.cleanup= smscb_fsm_cleanup,
|
||||
};
|
||||
|
||||
|
||||
/* allocate a cbc_message, fill it with data from orig_msg, create FSM */
|
||||
struct cbc_message *cbc_message_alloc(void *ctx, const struct cbc_message *orig_msg)
|
||||
{
|
||||
struct cbc_message *smscb;
|
||||
struct osmo_fsm_inst *fi;
|
||||
char idbuf[32];
|
||||
|
||||
if (cbc_message_by_id(orig_msg->msg.message_id)) {
|
||||
LOGP(DCBSP, LOGL_ERROR, "Cannot create message_id %u (already exists)\n",
|
||||
orig_msg->msg.message_id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
snprintf(idbuf, sizeof(idbuf), "%s-%u", orig_msg->cbe_name, orig_msg->msg.message_id);
|
||||
fi = osmo_fsm_inst_alloc(&smscb_fsm, ctx, NULL, LOGL_INFO, idbuf);
|
||||
if (!fi)
|
||||
return NULL;
|
||||
|
||||
/* copy data from original message */
|
||||
smscb = talloc_zero(fi, struct cbc_message);
|
||||
if (!smscb) {
|
||||
osmo_fsm_inst_term(fi, OSMO_FSM_TERM_ERROR, NULL);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(smscb, orig_msg, sizeof(*smscb));
|
||||
INIT_LLIST_HEAD(&smscb->peers);
|
||||
|
||||
fi->priv = smscb;
|
||||
|
||||
/* add to global list of messages */
|
||||
llist_add_tail(&smscb->list, &g_cbc->messages);
|
||||
|
||||
return smscb;
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
/* SMSCB Peer FSM: Represents state of one SMSCB for one peer (BSC) */
|
||||
|
||||
/* This FSM exists per tuple of (message, [bsc/rnc/mme] peer) */
|
||||
|
||||
/* (C) 2019 by Harald Welte <laforge@gnumonks.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
|
@ -36,35 +38,20 @@
|
|||
|
||||
#define S(x) (1 << (x))
|
||||
|
||||
enum smscb_p_state {
|
||||
/* initial state after creation */
|
||||
SMSCB_P_S_INIT,
|
||||
/* peer (BSC) have been notified of this SMSCB; we're waiting for ACK */
|
||||
SMSCB_P_S_WAIT_WRITE_ACK,
|
||||
/* peer (BSC) have confirmed it, message is active */
|
||||
SMSCB_P_S_ACTIVE,
|
||||
/* we have modified the message and sent REPLACE to peer; we're waiting for ACK */
|
||||
SMSCB_P_S_WAIT_REPLACE_ACK,
|
||||
/* we have modified the message and sent REPLACE to peer; we're waiting for ACK */
|
||||
SMSCB_P_S_WAIT_STATUS_ACK,
|
||||
/* we have deleted the message and sent KILL to peer; wait for ACK */
|
||||
SMSCB_P_S_WAIT_DELETE_ACK,
|
||||
SMSCB_P_S_DELETED,
|
||||
};
|
||||
|
||||
enum smscb_p_fsm_timer {
|
||||
T_WAIT_WRITE_ACK,
|
||||
T_WAIT_REPLACE_ACK,
|
||||
T_WAIT_STATUS_ACK,
|
||||
T_WAIT_DELETE_ACK,
|
||||
};
|
||||
|
||||
static const struct value_string smscb_p_fsm_event_names[] = {
|
||||
const struct value_string smscb_fsm_event_names[] = {
|
||||
{ SMSCB_E_CHILD_DIED, "CHILD_DIED" },
|
||||
{ SMSCB_E_CREATE, "CREATE" },
|
||||
{ SMSCB_E_REPLACE, "REPLACE" },
|
||||
{ SMSCB_E_STATUS, "STATUS" },
|
||||
{ SMSCB_E_DELETE, "DELETE" },
|
||||
{ SMSCB_E_CBSP_WRITE_ACK, "WRITE_ACK" },
|
||||
{ SMSCB_E_CBSP_WRITE_NACK, "WRITE_NACK" },
|
||||
{ SMSCB_E_CBSP_REPLACE_ACK, "REPLACE_ACK" },
|
||||
{ SMSCB_E_CBSP_REPLACE_NACK, "REPLACE_NACK" },
|
||||
{ SMSCB_E_CBSP_DELETE_ACK, "DELETE_ACK" },
|
||||
{ SMSCB_E_CBSP_DELETE_NACK, "DELETE_NACK" },
|
||||
{ SMSCB_E_CBSP_STATUS_ACK, "STATUS_ACK" },
|
||||
{ SMSCB_E_CBSP_STATUS_NACK, "STATUS_NACK" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
|
@ -291,7 +278,7 @@ static void smscb_p_fsm_init(struct osmo_fsm_inst *fi, uint32_t event, void *dat
|
|||
/* send it to peer */
|
||||
peer_new_cbc_message(mp->peer, mp->cbcmsg);
|
||||
/* wait for peers' response */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_WAIT_WRITE_ACK, 10, T_WAIT_WRITE_ACK);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_WAIT_WRITE_ACK, 10, T_WAIT_WRITE_ACK);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
|
@ -308,16 +295,18 @@ static void smscb_p_fsm_wait_write_ack(struct osmo_fsm_inst *fi, uint32_t event,
|
|||
dec = data;
|
||||
msg_peer_append_cbsp_compl(mp, &dec->u.write_replace_compl.num_compl_list);
|
||||
msg_peer_append_cbsp_cell(mp, &dec->u.write_replace_compl.cell_list);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_ACTIVE, 0, 0);
|
||||
/* TODO: Signal parent fsm about completion */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
/* Signal parent fsm about completion */
|
||||
osmo_fsm_inst_dispatch(fi->proc.parent, SMSCB_E_CBSP_WRITE_ACK, mp);
|
||||
break;
|
||||
case SMSCB_E_CBSP_WRITE_NACK:
|
||||
dec = data;
|
||||
msg_peer_append_cbsp_compl(mp, &dec->u.write_replace_fail.num_compl_list);
|
||||
msg_peer_append_cbsp_cell(mp, &dec->u.write_replace_fail.cell_list);
|
||||
msg_peer_append_cbsp_fail(mp, &dec->u.write_replace_fail.fail_list);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_ACTIVE, 0, 0);
|
||||
/* TODO: Signal parent fsm about completion */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
/* Signal parent fsm about completion */
|
||||
osmo_fsm_inst_dispatch(fi->proc.parent, SMSCB_E_CBSP_WRITE_NACK, mp);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
|
@ -334,13 +323,13 @@ static void smscb_p_fsm_active(struct osmo_fsm_inst *fi, uint32_t event, void *d
|
|||
cbsp = osmo_cbsp_decoded_alloc(mp->peer, CBSP_MSGT_WRITE_REPLACE);
|
||||
OSMO_ASSERT(cbsp);
|
||||
cbsp->u.write_replace.msg_id = mp->cbcmsg->msg.message_id;
|
||||
cbsp->u.write_replace.old_serial_nr = mp->cbcmsg->msg.serial_nr;
|
||||
cbsp->u.write_replace.old_serial_nr = &mp->cbcmsg->msg.serial_nr;
|
||||
//cbsp->u.write_replace.new_serial_nr
|
||||
/* TODO: we assume that the replace will always affect all original cells */
|
||||
cbsp_append_cell_list(&cbsp->u.write_replace.cell_list, cbsp, mp);
|
||||
// TODO: ALL OTHER DATA
|
||||
cbsp_cbc_client_tx(mp->peer->client.cbsp, cbsp);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_WAIT_REPLACE_ACK, 10, T_WAIT_REPLACE_ACK);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_WAIT_REPLACE_ACK, 10, T_WAIT_REPLACE_ACK);
|
||||
break;
|
||||
case SMSCB_E_STATUS: /* send MSG-STATUS-QUERY to BSC */
|
||||
cbsp = osmo_cbsp_decoded_alloc(mp->peer, CBSP_MSGT_MSG_STATUS_QUERY);
|
||||
|
@ -350,7 +339,7 @@ static void smscb_p_fsm_active(struct osmo_fsm_inst *fi, uint32_t event, void *d
|
|||
cbsp_append_cell_list(&cbsp->u.msg_status_query.cell_list, cbsp, mp);
|
||||
cbsp->u.msg_status_query.channel_ind = CBSP_CHAN_IND_BASIC;
|
||||
cbsp_cbc_client_tx(mp->peer->client.cbsp, cbsp);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_WAIT_STATUS_ACK, 10, T_WAIT_STATUS_ACK);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_WAIT_STATUS_ACK, 10, T_WAIT_STATUS_ACK);
|
||||
break;
|
||||
case SMSCB_E_DELETE: /* send KILL to BSC */
|
||||
cbsp = osmo_cbsp_decoded_alloc(mp->peer, CBSP_MSGT_KILL);
|
||||
|
@ -360,7 +349,7 @@ static void smscb_p_fsm_active(struct osmo_fsm_inst *fi, uint32_t event, void *d
|
|||
/* TODO: we assume that the delete will always affect all original cells */
|
||||
cbsp_append_cell_list(&cbsp->u.kill.cell_list, cbsp, mp);
|
||||
cbsp_cbc_client_tx(mp->peer->client.cbsp, cbsp);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_WAIT_DELETE_ACK, 10, T_WAIT_DELETE_ACK);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_WAIT_DELETE_ACK, 10, T_WAIT_DELETE_ACK);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
|
@ -376,15 +365,17 @@ static void smscb_p_fsm_wait_status_ack(struct osmo_fsm_inst *fi, uint32_t event
|
|||
case SMSCB_E_CBSP_STATUS_ACK:
|
||||
dec = data;
|
||||
msg_peer_append_cbsp_compl(mp, &dec->u.msg_status_query_compl.num_compl_list);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_ACTIVE, 0, 0);
|
||||
/* TODO: Signal parent fsm about completion */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
/* Signal parent fsm about completion */
|
||||
osmo_fsm_inst_dispatch(fi->proc.parent, SMSCB_E_CBSP_STATUS_ACK, mp);
|
||||
break;
|
||||
case SMSCB_E_CBSP_STATUS_NACK:
|
||||
dec = data;
|
||||
msg_peer_append_cbsp_compl(mp, &dec->u.msg_status_query_fail.num_compl_list);
|
||||
msg_peer_append_cbsp_fail(mp, &dec->u.msg_status_query_fail.fail_list);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_ACTIVE, 0, 0);
|
||||
/* TODO: Signal parent fsm about completion */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
/* Signal parent fsm about completion */
|
||||
osmo_fsm_inst_dispatch(fi->proc.parent, SMSCB_E_CBSP_STATUS_NACK, mp);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
|
@ -402,16 +393,18 @@ static void smscb_p_fsm_wait_replace_ack(struct osmo_fsm_inst *fi, uint32_t even
|
|||
dec = data;
|
||||
msg_peer_append_cbsp_compl(mp, &dec->u.write_replace_compl.num_compl_list);
|
||||
msg_peer_append_cbsp_cell(mp, &dec->u.write_replace_compl.cell_list);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_ACTIVE, 0, 0);
|
||||
/* TODO: Signal parent fsm about completion */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
/* Signal parent fsm about completion */
|
||||
osmo_fsm_inst_dispatch(fi->proc.parent, SMSCB_E_CBSP_REPLACE_ACK, mp);
|
||||
break;
|
||||
case SMSCB_E_CBSP_REPLACE_NACK:
|
||||
dec = data;
|
||||
msg_peer_append_cbsp_compl(mp, &dec->u.write_replace_fail.num_compl_list);
|
||||
msg_peer_append_cbsp_cell(mp, &dec->u.write_replace_fail.cell_list);
|
||||
msg_peer_append_cbsp_fail(mp, &dec->u.write_replace_fail.fail_list);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_ACTIVE, 0, 0);
|
||||
/* TODO: Signal parent fsm about completion */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
/* Signal parent fsm about completion */
|
||||
osmo_fsm_inst_dispatch(fi->proc.parent, SMSCB_E_CBSP_REPLACE_NACK, mp);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
|
@ -425,13 +418,15 @@ static void smscb_p_fsm_wait_delete_ack(struct osmo_fsm_inst *fi, uint32_t event
|
|||
switch (event) {
|
||||
case SMSCB_E_CBSP_DELETE_ACK:
|
||||
/* TODO: append results */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_DELETED, 0, 0);
|
||||
/* TODO: Signal parent fsm about completion */
|
||||
/* Signal parent fsm about completion */
|
||||
osmo_fsm_inst_dispatch(fi->proc.parent, SMSCB_E_CBSP_DELETE_ACK, mp);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_DELETED, 0, 0);
|
||||
break;
|
||||
case SMSCB_E_CBSP_DELETE_NACK:
|
||||
/* TODO: append results */
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_DELETED, 0, 0);
|
||||
/* TODO: Signal parent fsm about completion */
|
||||
/* Signal parent fsm about completion */
|
||||
osmo_fsm_inst_dispatch(fi->proc.parent, SMSCB_E_CBSP_DELETE_NACK, mp);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_DELETED, 0, 0);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
|
@ -446,16 +441,16 @@ static int smscb_p_fsm_timer_cb(struct osmo_fsm_inst *fi)
|
|||
|
||||
switch (fi->T) {
|
||||
case T_WAIT_WRITE_ACK:
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_ACTIVE, 0, 0);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
break;
|
||||
case T_WAIT_REPLACE_ACK:
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_ACTIVE, 0, 0);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
break;
|
||||
case T_WAIT_STATUS_ACK:
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_ACTIVE, 0, 0);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_ACTIVE, 0, 0);
|
||||
break;
|
||||
case T_WAIT_DELETE_ACK:
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_P_S_DELETED, 0, 0);
|
||||
osmo_fsm_inst_state_chg(fi, SMSCB_S_DELETED, 0, 0);
|
||||
break;
|
||||
default:
|
||||
OSMO_ASSERT(0);
|
||||
|
@ -464,48 +459,48 @@ static int smscb_p_fsm_timer_cb(struct osmo_fsm_inst *fi)
|
|||
}
|
||||
|
||||
static const struct osmo_fsm_state smscb_p_fsm_states[] = {
|
||||
[SMSCB_P_S_INIT] = {
|
||||
[SMSCB_S_INIT] = {
|
||||
.name = "INIT",
|
||||
.in_event_mask = S(SMSCB_E_CREATE),
|
||||
.out_state_mask = S(SMSCB_P_S_WAIT_WRITE_ACK),
|
||||
.out_state_mask = S(SMSCB_S_WAIT_WRITE_ACK),
|
||||
.action = smscb_p_fsm_init,
|
||||
},
|
||||
[SMSCB_P_S_WAIT_WRITE_ACK] = {
|
||||
[SMSCB_S_WAIT_WRITE_ACK] = {
|
||||
.name = "WAIT_WRITE_ACK",
|
||||
.in_event_mask = S(SMSCB_E_CBSP_WRITE_ACK) |
|
||||
S(SMSCB_E_CBSP_WRITE_NACK),
|
||||
.out_state_mask = S(SMSCB_P_S_ACTIVE),
|
||||
.out_state_mask = S(SMSCB_S_ACTIVE),
|
||||
.action = smscb_p_fsm_wait_write_ack,
|
||||
},
|
||||
[SMSCB_P_S_ACTIVE] = {
|
||||
[SMSCB_S_ACTIVE] = {
|
||||
.name = "ACTIVE",
|
||||
.in_event_mask = S(SMSCB_E_REPLACE) |
|
||||
S(SMSCB_E_STATUS) |
|
||||
S(SMSCB_E_DELETE),
|
||||
.out_state_mask = S(SMSCB_P_S_WAIT_REPLACE_ACK) |
|
||||
S(SMSCB_P_S_WAIT_STATUS_ACK) |
|
||||
S(SMSCB_P_S_WAIT_DELETE_ACK),
|
||||
.out_state_mask = S(SMSCB_S_WAIT_REPLACE_ACK) |
|
||||
S(SMSCB_S_WAIT_STATUS_ACK) |
|
||||
S(SMSCB_S_WAIT_DELETE_ACK),
|
||||
.action = smscb_p_fsm_active,
|
||||
},
|
||||
[SMSCB_P_S_WAIT_STATUS_ACK] = {
|
||||
[SMSCB_S_WAIT_STATUS_ACK] = {
|
||||
.name = "WAIT_STATUS_ACK",
|
||||
.in_event_mask = S(SMSCB_E_CBSP_STATUS_ACK) |
|
||||
S(SMSCB_E_CBSP_STATUS_NACK),
|
||||
.out_state_mask = S(SMSCB_P_S_ACTIVE),
|
||||
.out_state_mask = S(SMSCB_S_ACTIVE),
|
||||
.action = smscb_p_fsm_wait_status_ack,
|
||||
},
|
||||
[SMSCB_P_S_WAIT_REPLACE_ACK] = {
|
||||
[SMSCB_S_WAIT_REPLACE_ACK] = {
|
||||
.name = "WAIT_REPLACE_ACK",
|
||||
.in_event_mask = S(SMSCB_E_CBSP_REPLACE_ACK) |
|
||||
S(SMSCB_E_CBSP_REPLACE_NACK),
|
||||
.out_state_mask = S(SMSCB_P_S_ACTIVE),
|
||||
.out_state_mask = S(SMSCB_S_ACTIVE),
|
||||
.action = smscb_p_fsm_wait_replace_ack,
|
||||
},
|
||||
[SMSCB_P_S_WAIT_DELETE_ACK] = {
|
||||
[SMSCB_S_WAIT_DELETE_ACK] = {
|
||||
.name = "WAIT_DELETE_ACK",
|
||||
.in_event_mask = S(SMSCB_E_CBSP_DELETE_ACK) |
|
||||
S(SMSCB_E_CBSP_DELETE_NACK),
|
||||
.out_state_mask = S(SMSCB_P_S_DELETED),
|
||||
.out_state_mask = S(SMSCB_S_DELETED),
|
||||
.action = smscb_p_fsm_wait_delete_ack,
|
||||
},
|
||||
};
|
||||
|
@ -516,7 +511,7 @@ struct osmo_fsm smscb_p_fsm = {
|
|||
.num_states = ARRAY_SIZE(smscb_p_fsm_states),
|
||||
.timer_cb = smscb_p_fsm_timer_cb,
|
||||
.log_subsys = DCBSP,
|
||||
.event_names = smscb_p_fsm_event_names,
|
||||
.event_names = smscb_fsm_event_names,
|
||||
};
|
||||
|
||||
static __attribute__((constructor)) void on_dso_load_smscb_p_fsm(void)
|
||||
|
|
Loading…
Reference in New Issue