[MERGED] osmo-bsc[master]: SI2q: fix generation for multiple UARFCNs

Max gerrit-no-reply at lists.osmocom.org
Tue Oct 10 12:29:49 UTC 2017


Max has submitted this change and it was merged.

Change subject: SI2q: fix generation for multiple UARFCNs
......................................................................


SI2q: fix generation for multiple UARFCNs

* fix insert routine to keep the list sorted by UARFCN
* fix rest octets generator to properly account for offset
* adjust test results accordingly

Change-Id: I443c5c5f937b490578354f3c8a0c5b92629f2794
Related: OS#2357
---
M src/libbsc/rest_octets.c
M src/libbsc/system_information.c
M tests/gsm0408/gsm0408_test.ok
3 files changed, 25 insertions(+), 29 deletions(-)

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



diff --git a/src/libbsc/rest_octets.c b/src/libbsc/rest_octets.c
index b1516ec..a22b8e6 100644
--- a/src/libbsc/rest_octets.c
+++ b/src/libbsc/rest_octets.c
@@ -303,7 +303,7 @@
 static inline void append_uarfcns(struct bitvec *bv, struct gsm_bts *bts, uint8_t budget)
 {
 	const uint16_t *u = bts->si_common.data.uarfcn_list;
-	int i, rem = budget - 7, st = 0; /* account for constant bits right away */
+	int i, rem = budget - 7, st = bts->u_offset; /* account for constant bits right away */
 	uint16_t cu = u[bts->u_offset]; /* caller ensures that length is positive */
 
 	OSMO_ASSERT(budget <= SI2Q_MAX_LEN);
diff --git a/src/libbsc/system_information.c b/src/libbsc/system_information.c
index 761e848..91e993d 100644
--- a/src/libbsc/system_information.c
+++ b/src/libbsc/system_information.c
@@ -280,7 +280,7 @@
 
 int bts_uarfcn_add(struct gsm_bts *bts, uint16_t arfcn, uint16_t scramble, bool diversity)
 {
-	size_t len = bts->si_common.uarfcn_length, i, k = 0;
+	size_t len = bts->si_common.uarfcn_length, i;
 	uint8_t si2q;
 	int pos = uarfcn_sc_pos(bts, arfcn, scramble);
 	uint16_t scr = diversity ? encode_fdd(scramble, true) : encode_fdd(scramble, false),
@@ -297,20 +297,17 @@
 	pos = uarfcn_sc_pos(bts, arfcn, SC_BOUND);
 	i = (pos < 0) ? len : pos;
 
-	for (k = 0; i < len; i++)
-		if (scr > scl[i])
-			k = i + 1;
-
-	/* we keep lists sorted by scramble code of a given UARFCN:
-	   insert into appropriate position and move the tail */
-	if (len - k) {
-		memmove(ual + k + 1, ual + k, (len - k) * 2);
-		memmove(scl + k + 1, scl + k, (len - k) * 2);
+	/* move the tail to make space for inserting if necessary */
+	if (i < len) {
+		memmove(ual + i + 1, ual + i, (len - i) * 2);
+		memmove(scl + i + 1, scl + i, (len - i) * 2);
 	}
 
-	ual[k] = arfcn;
-	scl[k] = scr;
+	/* insert into appropriate position */
+	ual[i] = arfcn;
+	scl[i] = scr;
 	bts->si_common.uarfcn_length++;
+	/* try to generate SI2q */
 	si2q = si2q_num(bts);
 
 	if (si2q <= SI2Q_MAX_NUM) {
@@ -318,6 +315,7 @@
 		return 0;
 	}
 
+	/* rollback after unsuccessful generation */
 	bts_uarfcn_del(bts, arfcn, scramble);
 	return -ENOSPC;
 }
diff --git a/tests/gsm0408/gsm0408_test.ok b/tests/gsm0408/gsm0408_test.ok
index d23cebb..d200539 100644
--- a/tests/gsm0408/gsm0408_test.ok
+++ b/tests/gsm0408/gsm0408_test.ok
@@ -62,9 +62,9 @@
 generating SI2quater for 0 EARFCNs and 1 UARFCNs...
 generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 88 0a 7e 0b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 2 UARFCNs...
-generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 e8 0a 7f 52 88 0a 7e 0b 2b 2b 2b 2b 2b 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 88 0a 7f 52 e8 0a 7e 0b 2b 2b 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 2 UARFCNs...
-generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 e8 0a 7f 52 88 0a 7e 0b 2b 2b 2b 2b 2b 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 88 0a 7f 52 e8 0a 7e 0b 2b 2b 2b 2b 2b 2b 2b 2b 
 Testing SYSINFO_TYPE_2quater EARFCN generation:
 generating SI2quater for 0 EARFCNs and 0 UARFCNs...
 generated invalid SI2quater [00/00]: [23] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
@@ -96,17 +96,17 @@
 generating SI2quater for 0 EARFCNs and 2 UARFCNs...
 generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 14 1a 1f 0b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 3 UARFCNs...
-generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 18 58 12 f0 83 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 1c 7b d0 f7 03 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 4 UARFCNs...
-generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 20 58 2e f0 f2 03 2b 2b 2b 2b 2b 2b 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 24 b3 e4 e9 68 03 2b 2b 2b 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 5 UARFCNs...
-generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 28 58 2e 22 f2 4e 83 2b 2b 2b 2b 2b 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 2c 7a 34 0e 4e e9 83 2b 2b 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 6 UARFCNs...
-generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 34 1a 64 26 5d f2 05 03 2b 2b 2b 2b 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 34 7a 34 0e 4e e9 85 03 2b 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 7 UARFCNs...
-generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 38 58 12 22 fd ce 8e 05 03 2b 2b 2b 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 3c 70 39 02 ce f7 85 0e 03 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 8 UARFCNs...
-generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 40 58 1d 22 fa ce 88 85 7b 0b 2b 2b 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 44 7a 34 05 e4 72 05 08 d5 0b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 9 UARFCNs...
 generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 0f 7c 4c 7a 34 0e 64 77 85 43 55 c8 0b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 10 UARFCNs...
@@ -117,19 +117,17 @@
 generating SI2quater for 0 EARFCNs and 1 UARFCNs...
 generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 88 0a 7c 0b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 2 UARFCNs...
-generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 e8 0a 7f 52 88 0a 7c 0b 2b 2b 2b 2b 2b 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 88 0a 7d 52 e8 0a 7e 0b 2b 2b 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 3 UARFCNs...
-generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 e8 12 7e e0 a9 44 05 3e 0b 2b 2b 2b 2b 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 88 0a 7d 52 e8 12 7e e0 0b 2b 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 4 UARFCNs...
-generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 e8 18 3f f4 90 54 a2 02 9f 03 2b 2b 2b 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 88 0a 7d 52 e8 18 3f f4 90 03 2b 2b 2b 2b 2b 2b 
 generating SI2quater for 0 EARFCNs and 5 UARFCNs...
-generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 ea 08 81 52 e8 18 3f f4 90 54 a2 02 9f 03 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 88 0a 7d 52 e8 18 3f f4 90 54 ba 82 20 03 2b 2b 
 generating SI2quater for 0 EARFCNs and 6 UARFCNs...
-generated valid SI2quater [00/01]: [23] 59 06 07 40 20 25 52 ea 08 81 52 e8 10 3f f4 a9 75 04 a4 0b 2b 2b 2b 
-generated valid SI2quater [01/01]: [23] 59 06 07 42 20 25 52 e8 28 81 df 7f fa 32 d4 a2 02 9f 03 2b 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 88 0a 7d 52 e8 18 3f f4 90 54 ba 84 52 67 03 2b 
 generating SI2quater for 0 EARFCNs and 7 UARFCNs...
-generated valid SI2quater [00/01]: [23] 59 06 07 40 20 25 52 ea 10 81 ce a9 74 08 1f fa 54 ba 82 52 03 2b 2b 
-generated valid SI2quater [01/01]: [23] 59 06 07 42 20 25 52 e8 30 81 d3 7f fd b2 86 54 a2 02 9f 03 2b 2b 2b 
+generated valid SI2quater [00/00]: [23] 59 06 07 40 00 25 52 88 0a 7d 52 e8 18 3f f4 90 54 ba 86 20 73 8c 81 
 Testing SYSINFO_TYPE_2quater combined EARFCN & UARFCN generation:
 generating SI2quater for 17 EARFCNs and 1 UARFCNs...
 generated valid SI2quater [00/04]: [23] 59 06 07 40 80 25 0f 70 0c 1a 10 99 66 0f 04 83 c1 1c bb 2b 03 2b 2b 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I443c5c5f937b490578354f3c8a0c5b92629f2794
Gerrit-PatchSet: 3
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>


More information about the gerrit-log mailing list