laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/21400 )

Change subject: gprs_ns2: Give NS-VC FSMs a proper name/identifier
......................................................................

gprs_ns2: Give NS-VC FSMs a proper name/identifier

Log output without a proper identifier is mostly useless.

Change-Id: Id9d5b0684584d03685900c6298fe70246793de14
Closes: OS#4876
---
M src/gb/gprs_ns2.c
M src/gb/gprs_ns2_fr.c
M src/gb/gprs_ns2_internal.h
M src/gb/gprs_ns2_udp.c
M tests/gb/gprs_ns2_test.c
5 files changed, 25 insertions(+), 9 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  daniel: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index 813bd58..7c517aa 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -486,9 +486,10 @@
  * \param[in] bind The 'bind' on which we operate
  * \param[in] nse The NS Entity on which we operate
  * \param[in] initiater - if this is an incoming remote (!initiater) or a 
local outgoing connection (initater)
+ * \param[in] id - human-readable identifier
  * \return newly allocated NS-VC on success; NULL on error */
 struct gprs_ns2_vc *ns2_vc_alloc(struct gprs_ns2_vc_bind *bind, struct 
gprs_ns2_nse *nse, bool initiater,
-                                enum gprs_ns2_vc_mode vc_mode)
+                                enum gprs_ns2_vc_mode vc_mode, const char *id)
 {
        /* Sanity check */
        OSMO_ASSERT(bind->ll == nse->ll);
@@ -511,7 +512,7 @@
        nsvc->statg = osmo_stat_item_group_alloc(nsvc, &nsvc_statg_desc, 
bind->nsi->rate_ctr_idx);
        if (!nsvc->statg)
                goto err_group;
-       if (!gprs_ns2_vc_fsm_alloc(nsvc, NULL, initiater))
+       if (!gprs_ns2_vc_fsm_alloc(nsvc, id, initiater))
                goto err_statg;

        bind->nsi->rate_ctr_idx++;
@@ -791,6 +792,7 @@
        enum gprs_ns2_vc_mode vc_mode;
        uint16_t nsvci;
        uint16_t nsei;
+       char idbuf[32];

        int rc, tlv;

@@ -907,8 +909,11 @@
                return GPRS_NS2_CS_SKIPPED;
        }

+       nsvci = tlvp_val16be(&tp, NS_IE_VCI);
        vc_mode = gprs_ns2_dialect_to_vc_mode(dialect);
-       nsvc = ns2_vc_alloc(bind, nse, false, vc_mode);
+       snprintf(idbuf, sizeof(idbuf), "%s-NSE%05u-NSVC%05u", 
gprs_ns2_lltype_str(nse->ll),
+                nse->nsei, nsvci);
+       nsvc = ns2_vc_alloc(bind, nse, false, vc_mode, idbuf);
        if (!nsvc)
                return GPRS_NS2_CS_SKIPPED;

diff --git a/src/gb/gprs_ns2_fr.c b/src/gb/gprs_ns2_fr.c
index bb55381..c1bed6c 100644
--- a/src/gb/gprs_ns2_fr.c
+++ b/src/gb/gprs_ns2_fr.c
@@ -737,13 +737,17 @@
 {
        struct gprs_ns2_vc *nsvc = NULL;
        struct priv_vc *priv = NULL;
+       struct priv_bind *bpriv = bind->priv;
+       char idbuf[64];

        nsvc = gprs_ns2_fr_nsvc_by_dlci(bind, dlci);
        if (nsvc) {
                goto err;
        }

-       nsvc = ns2_vc_alloc(bind, nse, true, NS2_VC_MODE_BLOCKRESET);
+       snprintf(idbuf, sizeof(idbuf), "%s-%s-DLCI%u-NSE%05u-NSVC%05u", 
gprs_ns2_lltype_str(nse->ll),
+                bpriv->netif, dlci, nse->nsei, nsvci);
+       nsvc = ns2_vc_alloc(bind, nse, true, NS2_VC_MODE_BLOCKRESET, idbuf);
        if (!nsvc)
                goto err;

diff --git a/src/gb/gprs_ns2_internal.h b/src/gb/gprs_ns2_internal.h
index c33f7f8..5dbc349 100644
--- a/src/gb/gprs_ns2_internal.h
+++ b/src/gb/gprs_ns2_internal.h
@@ -233,7 +233,8 @@
 struct gprs_ns2_vc *ns2_vc_alloc(struct gprs_ns2_vc_bind *bind,
                                 struct gprs_ns2_nse *nse,
                                 bool initiater,
-                                enum gprs_ns2_vc_mode vc_mode);
+                                enum gprs_ns2_vc_mode vc_mode,
+                                const char *id);

 struct msgb *gprs_ns2_msgb_alloc(void);

diff --git a/src/gb/gprs_ns2_udp.c b/src/gb/gprs_ns2_udp.c
index 370937f..d93b66d 100644
--- a/src/gb/gprs_ns2_udp.c
+++ b/src/gb/gprs_ns2_udp.c
@@ -394,6 +394,8 @@
        struct gprs_ns2_vc *nsvc;
        struct priv_vc *priv;
        enum gprs_ns2_vc_mode vc_mode;
+       char *sockaddr_str;
+       char idbuf[64];

        vc_mode = gprs_ns2_dialect_to_vc_mode(nse->dialect);
        if ((int) vc_mode == -1) {
@@ -402,7 +404,11 @@
                return NULL;
        }

-       nsvc = ns2_vc_alloc(bind, nse, true, vc_mode);
+       sockaddr_str = (char *)osmo_sockaddr_to_str(remote);
+       osmo_identifier_sanitize_buf(sockaddr_str, NULL, '_');
+       snprintf(idbuf, sizeof(idbuf), "%s-NSE%05u-remote-%s", 
gprs_ns2_lltype_str(nse->ll),
+                nse->nsei, sockaddr_str);
+       nsvc = ns2_vc_alloc(bind, nse, true, vc_mode, idbuf);
        if (!nsvc)
                return NULL;

diff --git a/tests/gb/gprs_ns2_test.c b/tests/gb/gprs_ns2_test.c
index d53dc88..7c28dca 100644
--- a/tests/gb/gprs_ns2_test.c
+++ b/tests/gb/gprs_ns2_test.c
@@ -113,7 +113,7 @@
        OSMO_ASSERT(nse);

        printf("---- Test with NSVC[0]\n");
-       nsvc[0] = ns2_vc_alloc(bind[0], nse, false, NS2_VC_MODE_ALIVE);
+       nsvc[0] = ns2_vc_alloc(bind[0], nse, false, NS2_VC_MODE_ALIVE, NULL);
        OSMO_ASSERT(nsvc[0]);
        OSMO_ASSERT(ns2_count_transfer_cap(nse, 0) == 0);
        nsvc[0]->fi->state = 3; /* HACK: 3 = GPRS_NS2_ST_UNBLOCKED */
@@ -121,7 +121,7 @@
        OSMO_ASSERT(ns2_count_transfer_cap(nse, 0) == 42);

        printf("---- Test with NSVC[1]\n");
-       nsvc[1] = ns2_vc_alloc(bind[0], nse, false, NS2_VC_MODE_ALIVE);
+       nsvc[1] = ns2_vc_alloc(bind[0], nse, false, NS2_VC_MODE_ALIVE, NULL);
        OSMO_ASSERT(nsvc[1]);
        OSMO_ASSERT(ns2_count_transfer_cap(nse, 0) == 42);
        nsvc[1]->fi->state = 3; /* HACK: 3 = GPRS_NS2_ST_UNBLOCKED */
@@ -129,7 +129,7 @@
        OSMO_ASSERT(ns2_count_transfer_cap(nse, 0) == 42);

        printf("---- Test with NSVC[2]\n");
-       nsvc[2] = ns2_vc_alloc(bind[1], nse, false, NS2_VC_MODE_ALIVE);
+       nsvc[2] = ns2_vc_alloc(bind[1], nse, false, NS2_VC_MODE_ALIVE, NULL);
        OSMO_ASSERT(nsvc[2]);
        OSMO_ASSERT(ns2_count_transfer_cap(nse, 0) == 42);
        nsvc[2]->fi->state = 3; /* HACK: 3 = GPRS_NS2_ST_UNBLOCKED */

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id9d5b0684584d03685900c6298fe70246793de14
Gerrit-Change-Number: 21400
Gerrit-PatchSet: 6
Gerrit-Owner: laforge <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: lynxis lazus <[email protected]>
Gerrit-CC: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to