Skip to content

Commit

Permalink
Add Routing Areas
Browse files Browse the repository at this point in the history
Add a routing area layer which tracks routing area and
cells within a routing area.

Change-Id: I2474b19a7471a1dea3c863ddf8372b16180211aa
  • Loading branch information
lynxis committed Oct 21, 2024
1 parent 6213201 commit e8c82d9
Show file tree
Hide file tree
Showing 17 changed files with 987 additions and 0 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ AC_OUTPUT(
tests/Makefile
tests/atlocal
tests/gprs/Makefile
tests/gprs_routing_area/Makefile
tests/sgsn/Makefile
tests/gtphub/Makefile
tests/xid/Makefile
Expand Down
1 change: 1 addition & 0 deletions include/osmocom/sgsn/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ noinst_HEADERS = \
gprs_llc.h \
gprs_llc_xid.h \
gprs_ranap.h \
gprs_routing_area.h \
gprs_sm.h \
gprs_sndcp_comp.h \
gprs_sndcp_dcomp.h \
Expand Down
1 change: 1 addition & 0 deletions include/osmocom/sgsn/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum {
DGTP,
DOBJ,
DRIM,
DRA, /* Routing Area handling */
Debug_LastEntry,
};

Expand Down
88 changes: 88 additions & 0 deletions include/osmocom/sgsn/gprs_routing_area.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*! \file gprs_routing_area.h */

#pragma once

#include <stdbool.h>
#include <stdint.h>

#include <osmocom/core/linuxlist.h>
#include <osmocom/gsm/gsm23003.h>

struct sgsn_instance;

struct sgsn_ra_global {
/* list of struct sgsn_ra */
struct llist_head ra_list;
};

struct sgsn_ra {
/* Entry in sgsn_ra_global->ra_list */
struct llist_head list;

struct osmo_routing_area_id rai;
/* cells contains a list of sgsn_ra_cells which are alive */
struct llist_head cells;
};

enum sgsn_ra_ran_type {
RA_TYPE_GERAN_Gb,
RA_TYPE_UTRAN_Iu,
};

struct sgsn_ra_cell {
/* Entry in sgsn_ra->cells */
struct llist_head list;

/*! link back to the parent */
struct sgsn_ra *ra;

enum sgsn_ra_ran_type ran_type;

uint16_t cell_id;
union {
struct {
uint16_t nsei;
uint16_t bvci;
} geran;
struct {
/* TODO: unused */
uint16_t rncid;
uint16_t sac;
} utran;
} u;
};

void sgsn_ra_init(struct sgsn_instance *inst);

struct sgsn_ra *sgsn_ra_alloc(const struct osmo_routing_area_id *rai);
void sgsn_ra_free(struct sgsn_ra *ra);
struct sgsn_ra_cell *sgsn_ra_cell_alloc_geran(struct sgsn_ra *ra, uint16_t cell_id, uint16_t nsei, uint16_t bvci);
void sgsn_ra_cell_free(struct sgsn_ra_cell *cell);

/* Called by BSSGP layer to inform about a reset on a BVCI */
int sgsn_ra_bvc_reset_ind(uint16_t nsei, uint16_t bvci, struct osmo_cell_global_id_ps *cgi_ps);
/* FIXME: handle BVC BLOCK/UNBLOCK/UNAVAILABLE */
/* Called by NS-VC layer to inform about an unavailable NSEI (and all BVCI on them) */
int sgsn_ra_nsei_failure_ind(uint16_t nsei);

struct sgsn_ra_cell *sgsn_ra_get_cell_by_cgi_ps(const struct osmo_cell_global_id_ps *cgi_ps);
struct sgsn_ra_cell *sgsn_ra_get_cell_by_lai(const struct osmo_location_area_id *lai, uint16_t cell_id);
struct sgsn_ra_cell *sgsn_ra_get_cell_by_cgi(const struct osmo_cell_global_id *cgi);
struct sgsn_ra_cell *sgsn_ra_get_cell_by_ra(const struct sgsn_ra *ra, uint16_t cell_id);
struct sgsn_ra_cell *sgsn_ra_get_cell_by_gb(uint16_t nsei, uint16_t bvci);
struct sgsn_ra *sgsn_ra_get_ra(const struct osmo_routing_area_id *ra_id);


/*
* return value for callbacks.
* STOP: stop calling the callback for the remaining cells, sgsn_ra_foreach_ra() returns 0
* CONT: continue to call the callback for remaining cells
* ABORT: stop calling the callback for the remaining cells, sgsn_ra_foreach_ra() returns -1
*/
#define SGSN_RA_CB_STOP 1
#define SGSN_RA_CB_CONT 0
#define SGSN_RA_CB_ERROR -1

typedef int (sgsn_ra_cb_t)(struct sgsn_ra_cell *ra_cell, void *cb_data);
int sgsn_ra_foreach_cell(struct sgsn_ra *ra, sgsn_ra_cb_t *cb, void *cb_data);
int sgsn_ra_foreach_cell2(struct osmo_routing_area_id *rai, sgsn_ra_cb_t *cb, void *cb_data);
3 changes: 3 additions & 0 deletions include/osmocom/sgsn/sgsn.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ struct sgsn_instance {
ares_channel ares_channel;
struct ares_addr_node *ares_servers;

/* Routing areas */
struct sgsn_ra_global *routing_area;

struct rate_ctr_group *rate_ctrs;

struct llist_head apn_list; /* list of struct sgsn_apn_ctx */
Expand Down
1 change: 1 addition & 0 deletions src/sgsn/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ osmo_sgsn_SOURCES = \
gprs_gmm_fsm.c \
gprs_mm_state_gb_fsm.c \
gprs_ns.c \
gprs_routing_area.c \
gprs_sm.c \
gprs_sndcp.c \
gprs_sndcp_comp.c \
Expand Down
30 changes: 30 additions & 0 deletions src/sgsn/gprs_bssgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include <osmocom/core/prim.h>
#include <osmocom/core/rate_ctr.h>

Expand All @@ -30,9 +31,26 @@

#include <osmocom/sgsn/gprs_llc.h>
#include <osmocom/sgsn/gprs_gmm.h>
#include <osmocom/sgsn/gprs_routing_area.h>
#include <osmocom/sgsn/sgsn_rim.h>
#include <osmocom/sgsn/mmctx.h>

#include <osmocom/sgsn/debug.h>

static int bssgp_nm_bvc_reset_ind(struct osmo_bssgp_prim *bp)
{
struct osmo_cell_global_id_ps cgi_ps = {};

if (!bp->tp)
return -EINVAL;

if (!TLVP_PRES_LEN(bp->tp, BSSGP_IE_CELL_ID, 8))
return -EINVAL;

bssgp_parse_cell_id2(&cgi_ps.rai, &cgi_ps.cell_identity, TLVP_VAL(bp->tp, BSSGP_IE_CELL_ID), 8);
return sgsn_ra_bvc_reset_ind(bp->nsei, bp->bvci, &cgi_ps);
}

/* call-back function for the BSSGP protocol */
int sgsn_bssgp_rx_prim(struct osmo_prim_hdr *oph)
{
Expand All @@ -58,6 +76,18 @@ int sgsn_bssgp_rx_prim(struct osmo_prim_hdr *oph)
}
break;
case SAP_BSSGP_NM:
switch (oph->primitive) {
case PRIM_NM_BVC_RESET:
if (oph->operation == PRIM_OP_INDICATION)
bssgp_nm_bvc_reset_ind(bp);
break;
case PRIM_NM_BVC_BLOCK:
case PRIM_NM_BVC_UNBLOCK:
case PRIM_NM_STATUS:
case PRIM_NM_LLC_DISCARDED:
break;
}

break;
case SAP_BSSGP_RIM:
return sgsn_rim_rx_from_gb(bp, oph->msg);
Expand Down
2 changes: 2 additions & 0 deletions src/sgsn/gprs_ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <osmocom/gprs/gprs_ns2.h>
#include <osmocom/gprs/gprs_bssgp_bss.h>
#include <osmocom/sgsn/gprs_llc.h>
#include <osmocom/sgsn/gprs_routing_area.h>

#include "config.h"

Expand All @@ -52,6 +53,7 @@ void gprs_ns_prim_status_cb(struct osmo_gprs_ns2_prim *nsp)
break;
case GPRS_NS2_AFF_CAUSE_FAILURE:
LOGP(DGPRS, LOGL_NOTICE, "NS-E %d became unavailable\n", nsp->nsei);
sgsn_ra_nsei_failure_ind(nsp->nsei);
break;
default:
LOGP(DGPRS, LOGL_NOTICE, "NS: %s Unknown prim %d from NS\n",
Expand Down
Loading

0 comments on commit e8c82d9

Please sign in to comment.