Create NS instance at startup time and open/close it at BTS start/stop

The NS instance must be created at startup time before the config is
parsed, so the NS VTY elements will exist at this point. The NS instance
must persist.

Then during BTS start, the NS instance is opened/bound/connected to the
socket that is specified by BTS.

Then during BTS stop, the NS instance is closed, but the NS instance sill
exists.

At PCU stop, the NS instance is completely destroyed.
This commit is contained in:
Andreas Eversberg 2013-06-30 10:12:01 +02:00
parent 65d589bb24
commit 2a2ea42fca
3 changed files with 20 additions and 17 deletions

View File

@ -468,7 +468,7 @@ int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
return 0;
}
static int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, struct msgb *msg, uint16_t bvci)
int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, struct msgb *msg, uint16_t bvci)
{
int rc = 0;
switch (event) {
@ -590,18 +590,11 @@ int gprs_bssgp_create(uint16_t local_port, uint32_t sgsn_ip,
if (bctx)
return 0; /* if already created, must return 0: no error */
bssgp_nsi = gprs_ns_instantiate(&sgsn_ns_cb, tall_pcu_ctx);
if (!bssgp_nsi) {
LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
return -EINVAL;
}
gprs_ns_vty_init(bssgp_nsi);
bssgp_nsi->nsip.local_port = local_port;
rc = gprs_ns_nsip_listen(bssgp_nsi);
if (rc < 0) {
LOGP(DBSSGP, LOGL_ERROR, "Failed to create socket\n");
gprs_ns_destroy(bssgp_nsi);
bssgp_nsi = NULL;
gprs_ns_close(bssgp_nsi);
return -EINVAL;
}
@ -612,17 +605,16 @@ int gprs_bssgp_create(uint16_t local_port, uint32_t sgsn_ip,
nsvc = gprs_ns_nsip_connect(bssgp_nsi, &dest, nsei, nsvci);
if (!nsvc) {
LOGP(DBSSGP, LOGL_ERROR, "Failed to create NSVCt\n");
gprs_ns_destroy(bssgp_nsi);
bssgp_nsi = NULL;
gprs_ns_close(bssgp_nsi);
return -EINVAL;
}
bctx = btsctx_alloc(bvci, nsei);
if (!bctx) {
LOGP(DBSSGP, LOGL_ERROR, "Failed to create BSSGP context\n");
gprs_nsvc_delete(nsvc);
nsvc = NULL;
gprs_ns_destroy(bssgp_nsi);
bssgp_nsi = NULL;
gprs_ns_close(bssgp_nsi);
return -EINVAL;
}
bctx->ra_id.mcc = spoof_mcc ? : mcc;
@ -637,13 +629,12 @@ int gprs_bssgp_create(uint16_t local_port, uint32_t sgsn_ip,
bvc_timer.cb = bvc_timeout;
return 0;
}
void gprs_bssgp_destroy(void)
{
if (!bssgp_nsi)
if (!bctx)
return;
if (osmo_timer_pending(&bvc_timer))
@ -651,6 +642,7 @@ void gprs_bssgp_destroy(void)
osmo_signal_unregister_handler(SS_L_NS, nsvc_signal_cb, NULL);
gprs_nsvc_delete(nsvc);
nsvc = NULL;
/* FIXME: move this to libgb: btsctx_free() */
@ -660,7 +652,6 @@ void gprs_bssgp_destroy(void)
/* FIXME: blocking... */
gprs_ns_destroy(bssgp_nsi);
bssgp_nsi = NULL;
gprs_ns_close(bssgp_nsi);
}

View File

@ -51,6 +51,8 @@ int gprs_bssgp_pcu_rx_sign(struct msgb *msg, struct tlv_parsed *tp, struct bssgp
int gprs_bssgp_pcu_rcvmsg(struct msgb *msg);
int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, struct msgb *msg, uint16_t bvci);
int gprs_bssgp_create(uint16_t local_port, uint32_t sgsn_ip, uint16_t
sgsn_port, uint16_t nsei, uint16_t nsvci, uint16_t bvci,
uint16_t mcc, uint16_t mnc, uint16_t lac, uint16_t rac,

View File

@ -184,6 +184,13 @@ int main(int argc, char *argv[])
vty_init(&pcu_vty_info);
pcu_vty_init(&gprs_log_info);
bssgp_nsi = gprs_ns_instantiate(&sgsn_ns_cb, tall_pcu_ctx);
if (!bssgp_nsi) {
LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
return -EINVAL;
}
gprs_ns_vty_init(bssgp_nsi);
handle_options(argc, argv);
if ((!!spoof_mcc) + (!!spoof_mnc) == 1) {
fprintf(stderr, "--mcc and --mnc must be specified "
@ -250,6 +257,9 @@ int main(int argc, char *argv[])
pcu_l1if_close();
gprs_ns_destroy(bssgp_nsi);
bssgp_nsi = NULL;
flush_timing_advance();
talloc_free(gprs_rlcmac_bts);