gb_proxy: simplify raid data storage

Instead of storing the raw ra_id in its unparsed binary form, store it
as a parsed struct. Also store the cell-id on cell allocation for later
use.

Change-Id: Ib58b9188e3ce4bd3fdadb03f158d56b29778387c
Related: OS#4894
This commit is contained in:
Philipp Maier 2021-02-04 21:54:09 +01:00
parent 55a22b8bc0
commit da3af94bf8
4 changed files with 26 additions and 20 deletions

View File

@ -8,6 +8,7 @@
#include <osmocom/core/hashtable.h>
#include <osmocom/gsm/gsm23003.h>
#include <osmocom/gsm/gsm23236.h>
#include <osmocom/gsm/gsm48.h>
#include <osmocom/gsm/protocol/gsm_23_003.h>
#include <osmocom/gprs/gprs_ns2.h>
@ -110,8 +111,13 @@ struct gbproxy_cell {
/* BVCI of PTP BVCs associated to this cell */
uint16_t bvci;
/* Routing Area that this BVC is part of (raw 04.08 encoding) */
uint8_t ra[6];
struct {
/* Routing Area that this cell is part of */
struct gprs_ra_id raid;
/* Cell ID of this cell */
uint16_t cid;
} id;
/* pointer to the BSS-side BVC */
struct gbproxy_bvc *bss_bvc;
@ -131,8 +137,8 @@ struct gbproxy_bvc {
/* PTP BVCI of this BVC */
uint16_t bvci;
/* Routing Area that this BVC is part of (raw 04.08 encoding) */
uint8_t ra[6];
/* Routing Area that this BVC is part of */
struct gprs_ra_id raid;
/* Counter */
struct rate_ctr_group *ctrg;

View File

@ -671,7 +671,8 @@ static void bss_ptp_bvc_reset_notif(uint16_t nsei, uint16_t bvci, const struct g
bvc->cell = gbproxy_cell_alloc(cfg, bvci);
OSMO_ASSERT(bvc->cell);
memcpy(bvc->cell->ra, bvc->ra, sizeof(bvc->cell->ra));
memcpy(&bvc->cell->id.raid, &bvc->raid, sizeof(bvc->cell->id.raid));
bvc->cell->id.cid = cell_id;
/* link us to the cell and vice-versa */
bvc->cell->bss_bvc = bvc;
@ -688,7 +689,7 @@ static void bss_ptp_bvc_reset_notif(uint16_t nsei, uint16_t bvci, const struct g
OSMO_ASSERT(sgsn_bvc);
sgsn_bvc->cell = bvc->cell;
memcpy(sgsn_bvc->ra, bvc->cell->ra, sizeof(sgsn_bvc->ra));
memcpy(&sgsn_bvc->raid, &bvc->cell->id.raid, sizeof(sgsn_bvc->raid));
sgsn_bvc->fi = bssgp_bvc_fsm_alloc_ptp_bss(sgsn_bvc, cfg->nsi, sgsn_nse->nsei,
bvci, ra_id, cell_id);
OSMO_ASSERT(sgsn_bvc->fi);
@ -878,8 +879,8 @@ static int rx_bvc_reset_from_bss(struct gbproxy_nse *nse, struct msgb *msg, stru
* PDU, this means we can extend our local
* state information about this particular cell
* */
memcpy(from_bvc->ra, TLVP_VAL(tp, BSSGP_IE_CELL_ID), sizeof(from_bvc->ra));
gsm48_parse_ra(&raid, from_bvc->ra);
gsm48_parse_ra(&raid, TLVP_VAL(tp, BSSGP_IE_CELL_ID));
memcpy(&from_bvc->raid, &raid, sizeof(from_bvc->raid));
LOGPBVC(from_bvc, LOGL_INFO, "Cell ID %s\n", osmo_rai_name(&raid));
}
}
@ -1053,11 +1054,13 @@ static int gbprox_rx_paging(struct gbproxy_nse *sgsn_nse, struct msgb *msg, cons
LOGPBVC(sgsn_bvc, LOGL_INFO, "Rx %s: routing by BVCI\n", pdut_name);
return gbprox_relay2peer(msg, sgsn_bvc->cell->bss_bvc, ns_bvci);
} else if (TLVP_PRES_LEN(tp, BSSGP_IE_ROUTEING_AREA, 6)) {
struct gprs_ra_id raid;
errctr = GBPROX_GLOB_CTR_INV_RAI;
gsm48_parse_ra(&raid, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA));
/* iterate over all bvcs and dispatch the paging to each matching one */
hash_for_each(cfg->bss_nses, i, nse, list) {
hash_for_each(nse->bvcs, j, bss_bvc, list) {
if (!memcmp(bss_bvc->ra, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA), 6)) {
if (gsm48_ra_equal(&bss_bvc->raid, &raid)) {
LOGPNSE(nse, LOGL_INFO, "Rx %s: routing to NSE (RAI match)\n",
pdut_name);
gbprox_relay2peer(msg, bss_bvc, ns_bvci);
@ -1068,11 +1071,13 @@ static int gbprox_rx_paging(struct gbproxy_nse *sgsn_nse, struct msgb *msg, cons
}
}
} else if (TLVP_PRES_LEN(tp, BSSGP_IE_LOCATION_AREA, 5)) {
struct gsm48_ra_id lac;
errctr = GBPROX_GLOB_CTR_INV_LAI;
/* iterate over all bvcs and dispatch the paging to each matching one */
hash_for_each(cfg->bss_nses, i, nse, list) {
hash_for_each(nse->bvcs, j, bss_bvc, list) {
if (!memcmp(bss_bvc->ra, TLVP_VAL(tp, BSSGP_IE_LOCATION_AREA), 5)) {
gsm48_encode_ra(&lac, &bss_bvc->raid);
if (!memcmp(&lac, TLVP_VAL(tp, BSSGP_IE_LOCATION_AREA), 5)) {
LOGPNSE(nse, LOGL_INFO, "Rx %s: routing to NSE (LAI match)\n",
pdut_name);
gbprox_relay2peer(msg, bss_bvc, ns_bvci);

View File

@ -91,13 +91,12 @@ static int get_gbproxy_state(struct ctrl_cmd *cmd, void *data)
hash_for_each(cfg->bss_nses, i, nse_peer, list) {
struct gbproxy_bvc *bvc;
hash_for_each(nse_peer->bvcs, j, bvc, list) {
struct gprs_ra_id raid;
gsm48_parse_ra(&raid, bvc->ra);
struct gprs_ra_id *raid = &bvc->cell->id.raid;
cmd->reply = talloc_asprintf_append(cmd->reply, "%u,%u,%u-%u-%u-%u,%s\n",
nse_peer->nsei, bvc->bvci,
raid.mcc, raid.mnc,
raid.lac, raid.rac,
raid->mcc, raid->mnc,
raid->lac, raid->rac,
osmo_fsm_inst_state_name(bvc->fi));
}
}

View File

@ -78,10 +78,8 @@ static void gbprox_vty_print_bvc(struct vty *vty, struct gbproxy_bvc *bvc)
vty_out(vty, "NSEI %5u, SIG-BVCI %5u [%s]%s", bvc->nse->nsei, bvc->bvci,
osmo_fsm_inst_state_name(bvc->fi), VTY_NEWLINE);
} else {
struct gprs_ra_id raid;
gsm48_parse_ra(&raid, bvc->ra);
vty_out(vty, "NSEI %5u, PTP-BVCI %5u, RAI %s [%s]%s", bvc->nse->nsei, bvc->bvci,
osmo_rai_name(&raid), osmo_fsm_inst_state_name(bvc->fi), VTY_NEWLINE);
osmo_rai_name(&bvc->cell->id.raid), osmo_fsm_inst_state_name(bvc->fi), VTY_NEWLINE);
}
}
@ -100,12 +98,10 @@ static void gbproxy_vty_print_nse(struct vty *vty, struct gbproxy_nse *nse, bool
static void gbproxy_vty_print_cell(struct vty *vty, struct gbproxy_cell *cell, bool show_stats)
{
struct gprs_ra_id raid;
gsm48_parse_ra(&raid, cell->ra);
unsigned int num_sgsn_bvc = 0;
unsigned int i;
vty_out(vty, "BVCI %5u RAI %s: ", cell->bvci, osmo_rai_name(&raid));
vty_out(vty, "BVCI %5u RAI %s CID %05u: ", cell->bvci, osmo_rai_name(&cell->id.raid), cell->id.cid);
if (cell->bss_bvc)
vty_out(vty, "BSS NSEI %5u, SGSN NSEI ", cell->bss_bvc->nse->nsei);
else