Change in osmo-bsc[master]: vty: 'handover any': pick more random chans, use lchan_select_by_type()

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/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Sat Jul 28 10:44:10 UTC 2018


Neels Hofmeyr has submitted this change and it was merged. ( https://gerrit.osmocom.org/10108 )

Change subject: vty: 'handover any': pick more random chans, use lchan_select_by_type()
......................................................................

vty: 'handover any': pick more random chans, use lchan_select_by_type()

The 'handover any' VTY command is only useful for testing. It is even more
useful if it doesn't always pick the first used lchan but produces more random
handovers.

The algorithm takes a random number as input, iterates over used lchans once,
and if the random number is larger, takes modulo of the nr of used lchans
counted. A second iteration will then produce a match.

Instead of figuring out the lchan type logic in bsc_vty.c, just use
lchan_select_by_type();

Change-Id: I50b70e02d665b967e401db65581e110bc83101e7
---
M src/osmo-bsc/bsc_vty.c
1 file changed, 43 insertions(+), 47 deletions(-)

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



diff --git a/src/osmo-bsc/bsc_vty.c b/src/osmo-bsc/bsc_vty.c
index 5940696..e99029a 100644
--- a/src/osmo-bsc/bsc_vty.c
+++ b/src/osmo-bsc/bsc_vty.c
@@ -68,6 +68,7 @@
 #include <osmocom/bsc/gsm_timers.h>
 #include <osmocom/bsc/timeslot_fsm.h>
 #include <osmocom/bsc/lchan_fsm.h>
+#include <osmocom/bsc/lchan_select.h>
 #include <osmocom/bsc/gsm_timers.h>
 #include <osmocom/bsc/mgw_endpoint_fsm.h>
 
@@ -1605,36 +1606,48 @@
 	return ho_or_as(vty, argv, argc);
 }
 
-static struct gsm_lchan *find_used_voice_lchan(struct vty *vty)
+static struct gsm_lchan *find_used_voice_lchan(struct vty *vty, int random_idx)
 {
 	struct gsm_bts *bts;
 	struct gsm_network *network = gsmnet_from_vty(vty);
 
-	llist_for_each_entry(bts, &network->bts_list, list) {
-		struct gsm_bts_trx *trx;
+	while (1) {
+		int count = 0;
+		llist_for_each_entry(bts, &network->bts_list, list) {
+			struct gsm_bts_trx *trx;
 
-		llist_for_each_entry(trx, &bts->trx_list, list) {
-			int i;
-			for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
-				struct gsm_bts_trx_ts *ts = &trx->ts[i];
-				struct gsm_lchan *lchan;
+			llist_for_each_entry(trx, &bts->trx_list, list) {
+				int i;
+				for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
+					struct gsm_bts_trx_ts *ts = &trx->ts[i];
+					struct gsm_lchan *lchan;
 
-				if (ts->fi->state != TS_ST_IN_USE)
-					continue;
+					if (ts->fi->state != TS_ST_IN_USE)
+						continue;
 
-				ts_for_each_lchan(lchan, ts) {
-					if (lchan_state_is(lchan, LCHAN_ST_ESTABLISHED)
-					    && (lchan->type == GSM_LCHAN_TCH_F
-						|| lchan->type == GSM_LCHAN_TCH_H)) {
+					ts_for_each_lchan(lchan, ts) {
+						if (lchan_state_is(lchan, LCHAN_ST_ESTABLISHED)
+						    && (lchan->type == GSM_LCHAN_TCH_F
+							|| lchan->type == GSM_LCHAN_TCH_H)) {
 
-						vty_out(vty, "Found voice call: %s%s",
-							gsm_lchan_name(lchan), VTY_NEWLINE);
-						lchan_dump_full_vty(vty, lchan);
-						return lchan;
+							if (count == random_idx) {
+								vty_out(vty, "Found voice call: %s%s",
+									gsm_lchan_name(lchan),
+									VTY_NEWLINE);
+								lchan_dump_full_vty(vty, lchan);
+								return lchan;
+							}
+							count ++;
+						}
 					}
 				}
 			}
 		}
+
+		if (!count)
+			break;
+		/* there are used lchans, but random_idx is > count. Iterate again. */
+		random_idx %= count;
 	}
 
 	vty_out(vty, "Cannot find any ongoing voice calls%s", VTY_NEWLINE);
@@ -1642,7 +1655,7 @@
 }
 
 static struct gsm_bts *find_other_bts_with_free_slots(struct vty *vty, struct gsm_bts *not_this_bts,
-						      enum gsm_phys_chan_config free_type)
+						      enum gsm_chan_t free_type)
 {
 	struct gsm_bts *bts;
 	struct gsm_network *network = gsmnet_from_vty(vty);
@@ -1654,30 +1667,14 @@
 			continue;
 
 		llist_for_each_entry(trx, &bts->trx_list, list) {
-			int i;
-			/* FIXME: use lchan_select_by_type() instead */
-			for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
-				struct gsm_bts_trx_ts *ts = &trx->ts[i];
-				struct gsm_lchan *lchan;
+			struct gsm_lchan *lchan = lchan_select_by_type(bts, free_type);
+			if (!lchan)
+				continue;
 
-				/* skip administratively deactivated timeslots */
-				if (!nm_is_running(&ts->mo.nm_state))
-					continue;
-
-				if (ts->pchan_is != free_type)
-					continue;
-
-				ts_for_each_lchan(lchan, ts) {
-					if (lchan->fi->state != LCHAN_ST_UNUSED)
-						continue;
-					vty_out(vty, "Found unused %s slot: %s%s",
-						gsm_pchan_name(free_type),
-						gsm_lchan_name(lchan),
-						VTY_NEWLINE);
-					lchan_dump_full_vty(vty, lchan);
-					return bts;
-				}
-			}
+			vty_out(vty, "Found unused %s slot: %s%s",
+				gsm_lchant_name(free_type), gsm_lchan_name(lchan), VTY_NEWLINE);
+			lchan_dump_full_vty(vty, lchan);
+			return bts;
 		}
 	}
 	vty_out(vty, "Cannot find any BTS (other than BTS %u) with free %s lchan%s",
@@ -1694,12 +1691,11 @@
 	struct gsm_lchan *from_lchan;
 	struct gsm_bts *to_bts;
 
-	from_lchan = find_used_voice_lchan(vty);
+	from_lchan = find_used_voice_lchan(vty, random());
 	if (!from_lchan)
 		return CMD_WARNING;
 
-	to_bts = find_other_bts_with_free_slots(vty, from_lchan->ts->trx->bts,
-						from_lchan->ts->pchan_is);
+	to_bts = find_other_bts_with_free_slots(vty, from_lchan->ts->trx->bts, from_lchan->type);
 	if (!to_bts)
 		return CMD_WARNING;
 
@@ -1714,7 +1710,7 @@
 {
 	struct gsm_lchan *from_lchan;
 
-	from_lchan = find_used_voice_lchan(vty);
+	from_lchan = find_used_voice_lchan(vty, random());
 	if (!from_lchan)
 		return CMD_WARNING;
 
@@ -1733,7 +1729,7 @@
 	struct handover_out_req req;
 	struct gsm_lchan *from_lchan;
 
-	from_lchan = find_used_voice_lchan(vty);
+	from_lchan = find_used_voice_lchan(vty, random());
 	if (!from_lchan)
 		return CMD_WARNING;
 

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

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I50b70e02d665b967e401db65581e110bc83101e7
Gerrit-Change-Number: 10108
Gerrit-PatchSet: 9
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180728/d72eb17b/attachment.htm>


More information about the gerrit-log mailing list