bsc_ctrl_commands: Add GET for bts neighbor-list (local bts numbers)

Related: SYS#6287
Change-Id: I79aeffd93089086f57c66787fe20b439a4d8b6b4
This commit is contained in:
arehbein 2023-01-16 01:31:32 +01:00
parent 2e83847865
commit 97ed3c8d97
3 changed files with 115 additions and 0 deletions

View File

@ -21,6 +21,7 @@
*/
#include <errno.h>
#include <inttypes.h>
#include <time.h>
#include <osmocom/ctrl/control_cmd.h>
@ -94,6 +95,44 @@ static int verify_neighbor_bts_add(struct ctrl_cmd *cmd, const char *value, void
return verify_neighbor_bts(cmd, value, _data);
}
static int get_neighbor_bts_list(struct ctrl_cmd *cmd, void *data)
{
/* Max. 256 BTS neighbors (as of now, any bts can be its own neighbor per cfg) comma-separated ->
* max. 255 commas * + trailing '\0': 256
* 10 of those numbers (0...9) are 1-digit numbers: + 10 = 266
* 90 of those numbers are 2-digit numbers (10...99): + 90 = 356
* 255 - 100 + 1 = 156 are 3-digit numbers (100...255): + 156 = 512 bytes
* Double BTS num entries are not possible (check exists and is being tested against in python tests). */
char log_buf[512];
struct osmo_strbuf reply = { .buf = log_buf,
.len = sizeof(log_buf),
.pos = log_buf
};
struct gsm_bts *neighbor_bts, *bts = (struct gsm_bts *)cmd->node;
if (!bts) {
cmd->reply = "BTS not found";
return CTRL_CMD_ERROR;
}
struct neighbor *n;
llist_for_each_entry(n, &bts->neighbors, entry)
if (resolve_local_neighbor(&neighbor_bts, bts, n) == 0)
OSMO_STRBUF_PRINTF(reply, "%" PRIu8 ",", neighbor_bts->nr);
if (reply.buf == reply.pos)
cmd->reply = "";
else { /* Get rid of trailing comma */
reply.pos[-1] = '\0';
if (!(cmd->reply = talloc_strdup(cmd, reply.buf)))
goto oom;
}
return CTRL_CMD_REPLY;
oom:
cmd->reply = "OOM";
return CTRL_CMD_ERROR;
}
CTRL_CMD_DEFINE_RO(neighbor_bts_list, "neighbor-bts list");
static int set_neighbor_bts_add(struct ctrl_cmd *cmd, void *data)
{
struct gsm_bts *bts = cmd->node;
@ -705,6 +744,7 @@ int neighbor_ident_ctrl_init(void)
rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_lac_ci_del);
rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_cgi_add);
rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_cgi_del);
rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_bts_list);
rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_cgi_ps_add);
rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_cgi_ps_del);
rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_neighbor_clear);

View File

@ -100,6 +100,62 @@ network
gprs mode gprs
gprs routing area 6
neighbor bts 0
neighbor bts 1
neighbor bts 2
neighbor bts 2
trx 0
rf_locked 0
arfcn 880
nominal power 23
! to use full TRX power, set max_power_red 0
max_power_red 20
rsl e1 tei 0
timeslot 0
phys_chan_config CCCH+SDCCH4
hopping enabled 0
timeslot 1
phys_chan_config TCH/F
hopping enabled 0
timeslot 2
phys_chan_config TCH/F
hopping enabled 0
timeslot 3
phys_chan_config TCH/F
hopping enabled 0
timeslot 4
phys_chan_config TCH/F
hopping enabled 0
timeslot 5
phys_chan_config TCH/F
hopping enabled 0
timeslot 6
phys_chan_config TCH/F
hopping enabled 0
timeslot 7
phys_chan_config TCH/F
hopping enabled 0
bts 2
type osmo-bts
band DCS1800
cell_identity 123
location_area_code 0x0001
base_station_id_code 55
ms max power 15
cell reselection hysteresis 4
rxlev access min 0
radio-link-timeout 32
channel allocator mode set-all ascending
rach tx integer 9
rach max transmission 7
channel-description attach 1
channel-description bs-pa-mfrms 5
channel-description bs-ag-blks-res 1
early-classmark-sending forbidden
ipa unit-id 55 0
oml ipa stream-id 255 line 0
codec-support fr
gprs mode gprs
gprs routing area 6
trx 0
rf_locked 0
arfcn 880

View File

@ -616,6 +616,25 @@ class TestCtrlBSCNeighborCell(TestCtrlBase):
def ctrl_app(self):
return (4249, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
def testCtrlListBTS(self):
# Get BTS local neighbors (configured via 'neighbor cgi-ps ...')
r = self.do_get('bts.0.neighbor-bts.list')
self.assertEqual(r['mtype'], 'GET_REPLY')
self.assertEqual(r['var'], 'bts.0.neighbor-bts.list')
self.assertEqual(r['value'], '1')
# Get BTS locally configured neighbors (when none configured)
r = self.do_get('bts.2.neighbor-bts.list')
self.assertEqual(r['mtype'], 'GET_REPLY')
self.assertEqual(r['var'], 'bts.2.neighbor-bts.list')
self.assertEqual(r['value'], None)
# Get BTS locally configured neighbors
r = self.do_get('bts.1.neighbor-bts.list')
self.assertEqual(r['mtype'], 'GET_REPLY')
self.assertEqual(r['var'], 'bts.1.neighbor-bts.list')
self.assertEqual(r['value'], '0,2')
def testCtrlAddDelBTS(self):
r = self.do_set('bts.0.neighbor-bts.add', '1')
print('respose: ' + str(r))