Neels Hofmeyr has submitted this change and it was merged.

Change subject: add osmo_ss7_route_name()
......................................................................


add osmo_ss7_route_name()

There is a naming dilemma: though the osmo_ prefix is now reserved for
libosmocore, all surrounding API already has the osmo_ prefix.

This will be used by osmo-hnbgw's VTY 'show cnlink' command.

Change-Id: Ia0d15a2814b08bc3f052a1ed12dbb68bade55309
---
M include/osmocom/sigtran/osmo_ss7.h
M src/osmo_ss7_hmrt.c
2 files changed, 60 insertions(+), 0 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/sigtran/osmo_ss7.h 
b/include/osmocom/sigtran/osmo_ss7.h
index 94d5e8a..fd3f103 100644
--- a/include/osmocom/sigtran/osmo_ss7.h
+++ b/include/osmocom/sigtran/osmo_ss7.h
@@ -234,6 +234,7 @@
 osmo_ss7_route_create(struct osmo_ss7_route_table *rtbl, uint32_t dpc,
                        uint32_t mask, const char *linkset_name);
 void osmo_ss7_route_destroy(struct osmo_ss7_route *rt);
+const char *osmo_ss7_route_name(struct osmo_ss7_route *rt, bool list_asps);
 
 
 /***********************************************************************
diff --git a/src/osmo_ss7_hmrt.c b/src/osmo_ss7_hmrt.c
index 51875b1..a1f9e92 100644
--- a/src/osmo_ss7_hmrt.c
+++ b/src/osmo_ss7_hmrt.c
@@ -139,6 +139,65 @@
        }
 }
 
+/*! Return human readable representation of the route, in a static buffer.
+ * This uses both osmo_ss7_pointcode_print() and osmo_ss7_pointcode_print2(), 
so pairing
+ * osmo_ss7_route_name() with osmo_ss7_pointcode_print() in the same printf 
statement is likely to
+ * conflict.
+ * \param[in] rt  The route information to print, or NULL.
+ * \param[in] list_asps  If true, append info for all ASPs for the route's AS.
+ * \returns A string constant or static buffer. */
+const char *osmo_ss7_route_name(struct osmo_ss7_route *rt, bool list_asps)
+{
+       static char buf[256];
+       char *pos = buf;
+       struct osmo_ss7_instance *inst;
+       size_t l;
+
+       if (!rt)
+               return "no route";
+
+       inst = rt->rtable->inst;
+
+#define APPEND(fmt, args ...) \
+       do { \
+               l = snprintf(pos, sizeof(buf) - (pos - buf), fmt, ## args); \
+               pos += l; \
+               if (pos - buf >= sizeof(buf) ) \
+                       goto out; \
+       } while (0)
+
+       APPEND("pc=%u=%s mask=0x%x=%s",
+              rt->cfg.pc, osmo_ss7_pointcode_print(inst, rt->cfg.pc),
+              rt->cfg.mask, osmo_ss7_pointcode_print2(inst, rt->cfg.mask));
+
+       if (rt->dest.as) {
+               struct osmo_ss7_as *as = rt->dest.as;
+               int i;
+               APPEND(" via AS %s proto=%s", as->cfg.name, 
osmo_ss7_asp_protocol_name(as->cfg.proto));
+
+               if (list_asps) {
+                       for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) {
+                               struct osmo_ss7_asp *asp = as->cfg.asps[i];
+                               if (!asp)
+                                       continue;
+                               APPEND(" ASP");
+                               if (asp->cfg.name)
+                                       APPEND(" %s", asp->cfg.name);
+                               if (asp->sock_name)
+                                       APPEND(" %s", asp->sock_name);
+                       }
+               }
+       } else if (rt->dest.linkset)
+               APPEND(" via linkset %s", rt->dest.linkset->cfg.name);
+       else
+               APPEND(" has no route set");
+#undef APPEND
+
+out:
+       buf[sizeof(buf)-1] = '\0';
+       return buf;
+}
+
 /* HMDC->HMRT Msg For Routing; Figure 26/Q.704 */
 /* local message was receive d from L4, SRM, SLM, STM or SLTC, or
  * remote message received from L2 and HMDC determined msg for routing */

-- 
To view, visit https://gerrit.osmocom.org/5570
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia0d15a2814b08bc3f052a1ed12dbb68bade55309
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <[email protected]>

Reply via email to