Change in osmo-e1d[master]: Evaluate received E and A bits in TS0

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Wed Jan 6 10:51:45 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-e1d/+/21808 )

Change subject: Evaluate received E and A bits in TS0
......................................................................

Evaluate received E and A bits in TS0

Related: OS#4917
Change-Id: I7e1c919518b3418e973b7ae5bedd5a6dd1c2adec
---
M src/e1d.h
M src/intf_line.c
M src/mux_demux.c
M src/usb.c
M src/vpair.c
M src/vty.c
6 files changed, 85 insertions(+), 7 deletions(-)

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



diff --git a/src/e1d.h b/src/e1d.h
index 9848df4..7cb5335 100644
--- a/src/e1d.h
+++ b/src/e1d.h
@@ -27,6 +27,7 @@
 #include <osmocom/core/isdnhdlc.h>
 #include <osmocom/core/linuxlist.h>
 #include <osmocom/core/rate_ctr.h>
+#include <osmocom/core/timer.h>
 #include <osmocom/vty/command.h>
 
 enum e1d_vty_node {
@@ -42,6 +43,8 @@
 	LINE_CTR_CRC_ERR,
 	LINE_CTR_RX_OVFL,
 	LINE_CTR_TX_UNFL,
+	LINE_CTR_RX_REMOTE_E,
+	LINE_CTR_RX_REMOTE_A,
 };
 
 enum e1_ts_mode {
@@ -88,6 +91,9 @@
 	E1_LINE_MODE_SUPERCHANNEL,
 };
 
+#define E1L_TS0_RX_CRC4_ERR	0x01
+#define E1L_TS0_RX_ALARM	0x02
+
 struct e1_line {
 	struct llist_head list;
 
@@ -103,6 +109,17 @@
 	struct e1_ts ts[32];
 	/* superchannel */
 	struct e1_ts superchan;
+
+	struct {
+		/*! buffer where we aggregate the E bits each multi-frame */
+		uint8_t e_bits;
+		/*! did we receive CRC4 / ALARM error reports this second (timer tick) */
+		uint8_t cur_errmask;
+		/*! did we receive CRC4 / ALARM error reports previous second (timer tick) */
+		uint8_t prev_errmask;
+		/*! timer to re-set the rx_crc4_err and rx_alarm above */
+		struct osmo_timer_list timer;
+	} ts0;
 };
 
 enum e1_driver {
@@ -160,7 +177,7 @@
 e1_line_mux_out(struct e1_line *line, uint8_t *buf, int fts);
 
 int
-e1_line_demux_in(struct e1_line *line, const uint8_t *buf, int size);
+e1_line_demux_in(struct e1_line *line, const uint8_t *buf, int size, int frame_base);
 
 void
 e1_ts_stop(struct e1_ts *ts);
diff --git a/src/intf_line.c b/src/intf_line.c
index ccd7645..5143e45 100644
--- a/src/intf_line.c
+++ b/src/intf_line.c
@@ -52,6 +52,8 @@
 	[LINE_CTR_CRC_ERR] =	{ "rx:crc_errors",		"E1 Rx CRC Errors" },
 	[LINE_CTR_RX_OVFL] =	{ "rx:overflow",		"E1 Rx Overflow" },
 	[LINE_CTR_TX_UNFL] =	{ "tx:underflow",		"E1 Tx Underflow" },
+	[LINE_CTR_RX_REMOTE_E] ={ "rx:remote_crc_errors",	"Rx Frames Reporting Remote CRC Error"},
+	[LINE_CTR_RX_REMOTE_A] ={ "rx:remote_alarm",		"Rx Frames Reporting Remote Alarm"},
 };
 
 static const struct rate_ctr_group_desc line_ctrg_desc = {
@@ -134,6 +136,28 @@
 }
 
 static void
+_ts0_tmr_cb(void *_line)
+{
+	struct e1_line *line = (struct e1_line *) _line;
+
+	if ((line->ts0.cur_errmask & E1L_TS0_RX_CRC4_ERR) !=
+	    (line->ts0.prev_errmask & E1L_TS0_RX_CRC4_ERR)) {
+		LOGPLI(line, DE1D, LOGL_NOTICE, "Remote CRC4 Error report %s\n",
+			line->ts0.cur_errmask & E1L_TS0_RX_CRC4_ERR ? "STARTED" : "CEASED");
+	}
+
+	if ((line->ts0.cur_errmask & E1L_TS0_RX_ALARM) !=
+	    (line->ts0.prev_errmask & E1L_TS0_RX_ALARM)) {
+		LOGPLI(line, DE1D, LOGL_NOTICE, "Remote ALARM condition %s\n",
+			line->ts0.cur_errmask & E1L_TS0_RX_ALARM ? "STARTED" : "CEASED");
+	}
+
+	line->ts0.prev_errmask = line->ts0.cur_errmask;
+	line->ts0.cur_errmask = 0;
+	osmo_timer_schedule(&line->ts0.timer, 1, 0);
+}
+
+static void
 _ts_init(struct e1_ts *ts, struct e1_line *line, int id)
 {
 	ts->line = line;
@@ -167,6 +191,9 @@
 	line->ctrs = rate_ctr_group_alloc(line, &line_ctrg_desc, line->id);
 	OSMO_ASSERT(line->ctrs);
 
+	osmo_timer_setup(&line->ts0.timer, _ts0_tmr_cb, line);
+	osmo_timer_schedule(&line->ts0.timer, 1, 0);
+
 	llist_add_tail(&line->list, &intf->lines);
 
 	LOGPLI(line, DE1D, LOGL_NOTICE, "Created\n");
diff --git a/src/mux_demux.c b/src/mux_demux.c
index ed7bf3b..dffc798 100644
--- a/src/mux_demux.c
+++ b/src/mux_demux.c
@@ -348,13 +348,41 @@
 	return 0;
 }
 
+static void
+_e1_line_demux_in_ts0(struct e1_line *line, const uint8_t *buf, int ftr, uint8_t frame_base)
+{
+	int i;
+
+	for (i = 0; i < ftr; i++) {
+		const uint8_t *frame = buf + i*32;
+		uint8_t frame_nr = (frame_base + i) & 0xf;
+
+		/* A bit is present in each odd frame */
+		if (frame_nr % 2) {
+			if (frame[0] & 0x20)
+				line->ts0.cur_errmask |= E1L_TS0_RX_ALARM;
+		}
+
+		/* E bits are present in frame 13 + 15 */
+		if (frame_nr == 13)
+			line->ts0.e_bits = frame[0] & 0x80 ? 2 : 0;
+		if (frame_nr == 15) {
+			line->ts0.e_bits |= frame[0] & 0x80 ? 1 : 0;
+			if (line->ts0.e_bits != 3)
+				line->ts0.cur_errmask |= E1L_TS0_RX_CRC4_ERR;
+		}
+		/* cur_errmask is being cleared once per second via line->ts0.timer */
+	}
+}
+
 /*! de-multiplex E1 line data to the individual timeslots.
  *  \param[in] line E1 line on which we operate.
  *  \param[in] buf buffer containing multiplexed frame-aligned E1 data.
  *  \param[in] size size of 'buf' in octets; assumed to be multiple of E1 frame size (32).
+ *  \param[in] frame_base frame number (in multiframe) of first frame in 'buf'. -1 to disable TS0.
  *  \returns 0 on success; negative on error */
 int
-e1_line_demux_in(struct e1_line *line, const uint8_t *buf, int size)
+e1_line_demux_in(struct e1_line *line, const uint8_t *buf, int size, int frame_base)
 {
 	int ftr;
 
@@ -366,6 +394,9 @@
 	ftr = size / 32;
 	OSMO_ASSERT(size % 32 == 0);
 
+	if (frame_base >= 0)
+		_e1_line_demux_in_ts0(line, buf, ftr, frame_base);
+
 	switch (line->mode) {
 	case E1_LINE_MODE_CHANNELIZED:
 		return _e1_line_demux_in_channelized(line, buf, ftr);
diff --git a/src/usb.c b/src/usb.c
index 326a2b2..3ec793f 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -118,7 +118,7 @@
 {
 	if (size == 0)
 		return 0;
-	return e1_line_demux_in(flow->line, buf + 4, size - 4);
+	return e1_line_demux_in(flow->line, buf + 4, size - 4, buf[3] & 0xf);
 }
 
 static int
diff --git a/src/vpair.c b/src/vpair.c
index df14026..8484be0 100644
--- a/src/vpair.c
+++ b/src/vpair.c
@@ -132,14 +132,14 @@
 		rc = e1_line_mux_out(line, buf, frames_expired);
 		OSMO_ASSERT(rc >= 0);
 		/* write data to peer */
-		rc = e1_line_demux_in(peer, buf, rc);
+		rc = e1_line_demux_in(peer, buf, rc, 0);
 		OSMO_ASSERT(rc >= 0);
 
 		/* generate data on peer line */
 		rc = e1_line_mux_out(peer, buf, frames_expired);
 		OSMO_ASSERT(rc >= 0);
 		/* write data to current line */
-		rc = e1_line_demux_in(line, buf, rc);
+		rc = e1_line_demux_in(line, buf, rc, 0);
 		OSMO_ASSERT(rc >= 0);
 	}
 
diff --git a/src/vty.c b/src/vty.c
index da3d005..0d8ab2b 100644
--- a/src/vty.c
+++ b/src/vty.c
@@ -109,8 +109,11 @@
 {
 	int tn;
 
-	vty_out(vty, "Interface #%u, Line #%u, Mode %s:%s", line->intf->id, line->id,
-		get_value_string(e1_line_mode_names, line->mode), VTY_NEWLINE);
+	vty_out(vty, "Interface #%u, Line #%u, Mode %s%s%s:%s", line->intf->id, line->id,
+		get_value_string(e1_line_mode_names, line->mode),
+		line->ts0.cur_errmask & E1L_TS0_RX_ALARM ? " [REMOTE-ALARM]" : "",
+		line->ts0.cur_errmask & E1L_TS0_RX_CRC4_ERR ? " [REMOTE-CRC-ERROR]" : "",
+		VTY_NEWLINE);
 
 	for (tn = 0; tn < ARRAY_SIZE(line->ts); tn++) {
 		const struct e1_ts *ts = &line->ts[tn];

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

Gerrit-Project: osmo-e1d
Gerrit-Branch: master
Gerrit-Change-Id: I7e1c919518b3418e973b7ae5bedd5a6dd1c2adec
Gerrit-Change-Number: 21808
Gerrit-PatchSet: 4
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: tnt <tnt at 246tNt.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210106/eaefe017/attachment.htm>


More information about the gerrit-log mailing list