[PATCH 3/3] Decompress the CRBB bitmap using tree based approach

sangamesh sajjan sangamesh.sajjan at radisys.com
Wed Mar 30 13:50:45 UTC 2016


This patch includes the changes for compression algorithm which
decompress the received CRBB bitmap and corresponding modification
of EPDAN handling
---
 src/decoding.cpp              |   30 ++++---------
 src/decoding.h                |   10 ++++-
 src/egprs_rlc_compression.cpp |   96 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+), 23 deletions(-)

diff --git a/src/decoding.cpp b/src/decoding.cpp
index f2b548c..4535d1b 100644
--- a/src/decoding.cpp
+++ b/src/decoding.cpp
@@ -536,7 +536,6 @@ int Decoding::decode_egprs_acknack_bits(const EGPRS_AckNack_Desc_t *desc,
 	bool have_bitmap;
 	int implicitly_acked_blocks;
 	int ssn = desc->STARTING_SEQUENCE_NUMBER;
-	int rc;
 
 	if (desc->FINAL_ACK_INDICATION)
 		return handle_final_ack(bits, bsn_begin, bsn_end, window);
@@ -576,26 +575,15 @@ int Decoding::decode_egprs_acknack_bits(const EGPRS_AckNack_Desc_t *desc,
 
 	if (crbb_len > 0) {
 		int old_len = bits->cur_bit;
-		struct bitvec crbb;
-
-		crbb.data = (uint8_t *)desc->CRBB;
-		crbb.data_len = sizeof(desc->CRBB);
-		crbb.cur_bit = desc->CRBB_LENGTH;
-
-		rc = osmo_t4_decode(&crbb, desc->CRBB_STARTING_COLOR_CODE,
-			bits);
-
-		if (rc < 0) {
-			LOGP(DRLCMACUL, LOGL_NOTICE,
-				"Failed to decode CRBB: "
-				"length %d, data '%s'\n",
-				desc->CRBB_LENGTH,
-				osmo_hexdump(crbb.data, crbb.data_len));
-			/* We don't know the SSN offset for the URBB,
-			 * return what we have so far and assume the
-			 * bitmap has stopped here */
-			goto aborted;
-		}
+
+		LOGP(DRLCMACDL, LOGL_DEBUG, "Compress bitmap exist,"
+			"CRBB LEN =%d and Starting color code =%d",
+			desc->CRBB_LENGTH, desc->CRBB_STARTING_COLOR_CODE);
+
+		decompress_crbb(desc->CRBB_LENGTH,
+				desc->CRBB_STARTING_COLOR_CODE,
+				desc->CRBB,
+				bits);
 
 		LOGP(DRLCMACDL, LOGL_DEBUG,
 			"CRBB len: %d, decoded len: %d, cc: %d, crbb: '%s'\n",
diff --git a/src/decoding.h b/src/decoding.h
index 58ecd18..5989907 100644
--- a/src/decoding.h
+++ b/src/decoding.h
@@ -60,6 +60,12 @@ public:
 		struct gprs_rlc_dl_window *window);
 	static int decode_gprs_acknack_bits(
 		const Ack_Nack_Description_t *desc,
-		bitvec *bits, int *bsn_begin, int *bsn_end,
-		gprs_rlc_dl_window *window);
+		bitvec * bits, int *bsn_begin, int *bsn_end,
+		gprs_rlc_dl_window * window);
+	static void decompress_crbb(
+			int8_t compress_bmap_len,
+			uint8_t clr_code_bit,
+			const uint8_t *orig_buf,
+			bitvec * dest
+			);
 };
diff --git a/src/egprs_rlc_compression.cpp b/src/egprs_rlc_compression.cpp
index 4c17a17..2e4dc05 100644
--- a/src/egprs_rlc_compression.cpp
+++ b/src/egprs_rlc_compression.cpp
@@ -218,3 +218,99 @@ const char *zero_run_len_code_list[MAX_CDWDTBL_LEN] = {
 	"0000001110010",
 	"0000001110011"
 };
+
+int search_runlen(
+		Node    *root,		/* root of Ones or Zeros tree */
+		const uint8_t *bmbuf,	/* Received compressed bitmap buf */
+		uint8_t bit_pos,	/* the start bit pos to read codeword */
+		uint8_t *len_codewd,	/* length of codeword */
+		uint16_t *rlen           /* run length of Ones or Zeros */
+		)
+{
+	Node *iter;
+	uint8_t dir;
+
+	iter = root;
+	*len_codewd = 0;
+
+	while (iter->run_length == 0) {
+		if ((iter->left == NULL) && (iter->right == NULL))
+			return -1;
+
+	/* get the bit value at the bitpos and put it in right most of dir */
+		dir = ((bmbuf[BITS_TO_BYTES(bit_pos)-1]
+				>>(7-(MOD8(bit_pos)))) & 0x01);
+		(bit_pos)++;
+		(*len_codewd)++;
+
+		if (((dir&0x01) == 0) && (iter->left != NULL))
+			iter = iter->left;
+
+		else if (((dir&0x01) == 1) && (iter->right != NULL))
+			iter = iter->right;
+		else
+			return -1;
+	}
+	(*rlen) = *(iter->run_length);
+
+	return 1;
+} /* search_runlen */
+
+void Decoding::decompress_crbb(
+		int8_t compress_bmap_len, /* compressed bitmap length */
+		uint8_t clr_code_bit, /* run length of Ones or Zeros */
+		const uint8_t *orig_crbb_buf, /* received block crbb bitmap */
+		bitvec * dest
+		)
+{
+
+	uint8_t bit_pos = 0;
+	uint8_t nbits = 0; /* number of bits of codeword */
+	uint16_t run_length = 0;
+	uint16_t cbmaplen = 0; /* compressed bitmap part after decompression */
+	unsigned wp = 0;
+
+	egprs_compress *compress = egprs_compress::instance();
+
+	while (compress_bmap_len >= 0) {
+		if (clr_code_bit == 1) {
+			search_runlen(compress->ones_list, orig_crbb_buf,
+					bit_pos, &nbits, &run_length);
+		       /*If run length > 64, need makeup and terminating code*/
+			if (run_length < 64)
+				clr_code_bit = 0;
+			cbmaplen = cbmaplen + run_length;
+			/* put run length of Ones in uncompressed bitmap */
+			while (run_length != 0) {
+				if (run_length > 8) {
+					bitvec_write_field(dest, wp, 0xff, 8);
+					run_length = run_length - 8;
+				} else {
+					bitvec_write_field(dest, wp, 0xff,
+								run_length);
+					run_length = 0;
+				}
+			}
+		} else {
+			search_runlen(compress->zeros_list, orig_crbb_buf,
+					 bit_pos, &nbits, &run_length);
+			/*If run length > 64, need makeup and terminating code*/
+			if (run_length < 64)
+				clr_code_bit = 1;
+			cbmaplen = cbmaplen + run_length;
+			/* put run length of Zeros in uncompressed bitmap */
+			while (run_length != 0) {
+				if (run_length > 8) {
+					bitvec_write_field(dest, wp, 0x00, 8);
+					run_length = run_length - 8;
+				} else {
+					bitvec_write_field(dest, wp, 0x00,
+								 run_length);
+					run_length = 0;
+				}
+			}
+		}
+		bit_pos = bit_pos + nbits;
+		compress_bmap_len = compress_bmap_len - nbits;
+	}
+} /* Decompress_CRBB */
-- 
1.7.9.5




More information about the osmocom-net-gprs mailing list