Change in ...libosmo-abis[master]: extend the ipa keepalive fsm

laforge gerrit-no-reply at lists.osmocom.org
Sun Jul 21 19:27:40 UTC 2019


laforge has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/libosmo-abis/+/14742 )

Change subject: extend the ipa keepalive fsm
......................................................................

extend the ipa keepalive fsm

The new and improved fsm supports multipe use cases:
1) plain old ipa server/client operation
2) ipa client/server operation with custom send callback (i.e. to bypass
the tx queue)
3) all of the above + custom timeout callback
4) fully generic operation that will pass opaque data to the callbacks

The current code will always kill the fsm and deallocate it upon
timeout, so the timeout callback will now return a value: 1 means the
fsm will be automatically terminated, 0 means no action, which allows
manually stopping/starting the fsm to reuse it.

Change-Id: Ie453fdee8bfd7fc1a3f1ed67ef0331f0abb1d59b
---
M include/osmocom/abis/ipa.h
M src/input/ipa_keepalive.c
2 files changed, 58 insertions(+), 9 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/abis/ipa.h b/include/osmocom/abis/ipa.h
index 4f6081f..ff00697 100644
--- a/include/osmocom/abis/ipa.h
+++ b/include/osmocom/abis/ipa.h
@@ -113,7 +113,9 @@
 	unsigned int wait_for_resp;
 };
 
-typedef void ipa_keepalive_timeout_cb_t(struct osmo_fsm_inst *fi, void *conn);
+typedef int ipa_keepalive_timeout_cb_t(struct osmo_fsm_inst *fi, void *conn);
+
+typedef void ipa_keepalive_send_cb_t(struct osmo_fsm_inst *fi, void *conn, struct msgb *msg);
 
 struct osmo_fsm_inst *ipa_client_conn_alloc_keepalive_fsm(struct ipa_client_conn *client,
 							  const struct ipa_keepalive_params *params,
@@ -123,12 +125,14 @@
 							  const struct ipa_keepalive_params *params,
 							  const char *id);
 
-struct osmo_fsm_inst *ipa_keepalive_alloc_server(struct ipa_server_conn *server,
-						 const struct ipa_keepalive_params *params,
-						 const char *id);
+struct osmo_fsm_inst *ipa_generic_conn_alloc_keepalive_fsm(void *ctx, void* data,
+							  const struct ipa_keepalive_params *params,
+							  const char *id);
 
 void ipa_keepalive_fsm_set_timeout_cb(struct osmo_fsm_inst *fi, ipa_keepalive_timeout_cb_t *cb);
 
+void ipa_keepalive_fsm_set_send_cb(struct osmo_fsm_inst *fi, ipa_keepalive_send_cb_t *fn);
+
 void ipa_keepalive_fsm_start(struct osmo_fsm_inst *fi);
 
 void ipa_keepalive_fsm_stop(struct osmo_fsm_inst *fi);
diff --git a/src/input/ipa_keepalive.c b/src/input/ipa_keepalive.c
index 81b5a26..d8eec77 100644
--- a/src/input/ipa_keepalive.c
+++ b/src/input/ipa_keepalive.c
@@ -76,7 +76,9 @@
 
 	struct ipa_server_conn *srv_conn;
 	struct ipa_client_conn *client_conn;
+	void *generic;
 	ipa_keepalive_timeout_cb_t *timeout_cb;
+	ipa_keepalive_send_cb_t *send_fn;
 };
 
 static void ipa_ka_init(struct osmo_fsm_inst *fi, uint32_t event, void *data)
@@ -103,11 +105,23 @@
 	msg = gen_ipa_ping();
 	OSMO_ASSERT(msg);
 
-	if (ifp->srv_conn)
-		ipa_server_conn_send(ifp->srv_conn, msg);
+	if (ifp->send_fn && ifp->generic) {
+		ifp->send_fn(fi, ifp->generic, msg);
+		return;
+	}
+
+	if (ifp->srv_conn) {
+		if (ifp->send_fn)
+			ifp->send_fn(fi, ifp->srv_conn, msg);
+		else
+			ipa_server_conn_send(ifp->srv_conn, msg);
+	}
 	else {
 		OSMO_ASSERT(ifp->client_conn);
-		ipa_client_conn_send(ifp->client_conn, msg);
+		if (ifp->send_fn)
+			ifp->send_fn(fi, ifp->client_conn, msg);
+		else
+			ipa_client_conn_send(ifp->client_conn, msg);
 	}
 }
 
@@ -140,10 +154,12 @@
 		/* PONG not received within time */
 		if (ifp->srv_conn)
 			conn = ifp->srv_conn;
-		else
+		else if (ifp->client_conn)
 			conn = ifp->client_conn;
+		else
+			conn = ifp->generic;
 		if (ifp->timeout_cb)
-			ifp->timeout_cb(fi, conn);
+			return ifp->timeout_cb(fi, conn);
 		/* ask fsm core to terminate us */
 		return 1;
 	default:
@@ -261,6 +277,27 @@
 	return fi;
 }
 
+/*! Create a new instance of an IPA keepalive FSM: Periodically transmit PING and expect PONG.
+ *  \param[in] ctx Talloc context.
+ *  \param[in] data Data to pass to write/timeout cb.
+ *  \param[in] params Parameters describing the keepalive FSM time-outs.
+ *  \param[in] id String used as identifier for the FSM.
+ *  \returns pointer to the newly-created FSM instance; NULL in case of error. */
+struct osmo_fsm_inst *ipa_generic_conn_alloc_keepalive_fsm(void *ctx, void* data,
+							   const struct ipa_keepalive_params *params,
+							   const char *id)
+{
+	struct osmo_fsm_inst *fi;
+	struct ipa_fsm_priv *ifp;
+	
+	fi = __ipa_conn_alloc_keepalive_fsm(ctx, params, id);
+	if (!fi)
+		return NULL;
+	ifp = fi->priv;
+	ifp->generic = data;
+	return fi;
+}
+
 /*! Set a timeout call-back which is to be called once the peer doesn't respond anymore */
 void ipa_keepalive_fsm_set_timeout_cb(struct osmo_fsm_inst *fi, ipa_keepalive_timeout_cb_t *cb)
 {
@@ -269,6 +306,14 @@
 	ifp->timeout_cb = cb;
 }
 
+/*! Set a custom send callback for sending pings */
+void ipa_keepalive_fsm_set_send_cb(struct osmo_fsm_inst *fi, ipa_keepalive_send_cb_t *fn)
+{
+	struct ipa_fsm_priv *ifp = fi->priv;
+	OSMO_ASSERT(fi->fsm == &ipa_keepalive_fsm);
+	ifp->send_fn = fn;
+}
+
 /*! Inform IPA Keepalive FSM that a PONG has been received. */
 void ipa_keepalive_fsm_pong_received(struct osmo_fsm_inst *fi)
 {

-- 
To view, visit https://gerrit.osmocom.org/c/libosmo-abis/+/14742
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-abis
Gerrit-Branch: master
Gerrit-Change-Id: Ie453fdee8bfd7fc1a3f1ed67ef0331f0abb1d59b
Gerrit-Change-Number: 14742
Gerrit-PatchSet: 3
Gerrit-Owner: Hoernchen <ewild at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: laforge <laforge at gnumonks.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190721/2258c424/attachment.html>


More information about the gerrit-log mailing list