int main(int argc, char **argv) { struct sockaddr_in bss_peer= {0}; osmo_init_logging(&info); log_set_use_color(osmo_stderr_target, 0); log_set_print_filename(osmo_stderr_target, 0); bssgp_nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); bss_peer.sin_family = AF_INET; bss_peer.sin_port = htons(32000); bss_peer.sin_addr.s_addr = htonl(0x7f0000ff); gprs_ns_nsip_connect(bssgp_nsi, &bss_peer, BSS_NSEI, BSS_NSEI+1); printf("===== BSSGP test START\n"); test_bssgp_suspend_resume(); printf("===== BSSGP test END\n\n"); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { struct gsm_network dummy_network; int rc; tall_bsc_ctx = talloc_named_const(NULL, 0, "osmo_sgsn"); tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 0, "msgb"); signal(SIGINT, &signal_handler); signal(SIGABRT, &signal_handler); signal(SIGUSR1, &signal_handler); signal(SIGUSR2, &signal_handler); osmo_init_ignore_signals(); osmo_init_logging(&gprs_log_info); vty_info.copyright = openbsc_copyright; vty_init(&vty_info); logging_vty_add_cmds(&gprs_log_info); sgsn_vty_init(); handle_options(argc, argv); rate_ctr_init(tall_bsc_ctx); rc = telnet_init(tall_bsc_ctx, &dummy_network, 4245); if (rc < 0) exit(1); gprs_ns_set_log_ss(DNS); bssgp_set_log_ss(DBSSGP); sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb, tall_bsc_ctx); if (!sgsn_nsi) { LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n"); exit(1); } bssgp_nsi = sgsn_inst.cfg.nsi = sgsn_nsi; gprs_llc_init("/usr/local/lib/osmocom/crypt/"); gprs_ns_vty_init(bssgp_nsi); bssgp_vty_init(); gprs_llc_vty_init(); gprs_sndcp_vty_init(); /* FIXME: register signal handler for SS_L_NS */ rc = sgsn_parse_config(sgsn_inst.config_file, &sgsn_inst.cfg); if (rc < 0) { LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file\n"); exit(2); } rc = sgsn_gtp_init(&sgsn_inst); if (rc) { LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on GTP socket\n"); exit(2); } rc = gprs_ns_nsip_listen(sgsn_nsi); if (rc < 0) { LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on NSIP socket\n"); exit(2); } rc = gprs_ns_frgre_listen(sgsn_nsi); if (rc < 0) { LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen GRE " "socket. Do you have CAP_NET_RAW?\n"); exit(2); } if (daemonize) { rc = osmo_daemonize(); if (rc < 0) { perror("Error during daemonize"); exit(1); } } while (1) { rc = osmo_select_main(0); if (rc < 0) exit(3); } /* not reached */ exit(0); }
static void test_bssgp_flow_control_bvc(void) { struct bssgp_bvc_ctx bctx = { .nsei = 0x1234, .bvci = 0x5678, }; const uint8_t tag = 42; const uint32_t bmax = 0x1022 * 100; const uint32_t rate = 0xc040 / 8 * 100; const uint32_t bmax_ms = bmax / 2; const uint32_t rate_ms = rate / 2; uint8_t ratio = 0x78; uint32_t qdelay = 0x1144 * 10; int rc; static uint8_t expected_simple_msg[] = { 0x26, 0x1e, 0x81, 0x2a, /* tag */ 0x05, 0x82, 0x10, 0x22, /* Bmax */ 0x03, 0x82, 0xc0, 0x40, /* R */ 0x01, 0x82, 0x08, 0x11, /* Bmax_MS */ 0x1c, 0x82, 0x60, 0x20, /* R_MS */ }; static uint8_t expected_ext_msg[] = { 0x26, 0x1e, 0x81, 0x2a, /* tag */ 0x05, 0x82, 0x10, 0x22, /* Bmax */ 0x03, 0x82, 0xc0, 0x40, /* R */ 0x01, 0x82, 0x08, 0x11, /* Bmax_MS */ 0x1c, 0x82, 0x60, 0x20, /* R_MS */ 0x3c, 0x81, 0x78, /* ratio */ 0x06, 0x82, 0x11, 0x44, /* Qdelay */ }; printf("----- %s START\n", __func__); rc = bssgp_tx_fc_bvc(&bctx, tag, bmax, rate, bmax_ms, rate_ms, NULL, NULL); OSMO_ASSERT(rc >= 0); OSMO_ASSERT(last_ns_tx_msg != NULL); printf("Got message: %s\n", msgb_hexdump(last_ns_tx_msg)); OSMO_ASSERT(msgb_length(last_ns_tx_msg) == sizeof(expected_simple_msg)); OSMO_ASSERT(0 == memcmp(msgb_data(last_ns_tx_msg), expected_simple_msg, sizeof(expected_simple_msg))); rc = bssgp_tx_fc_bvc(&bctx, tag, bmax, rate, bmax_ms, rate_ms, &ratio, &qdelay); OSMO_ASSERT(rc >= 0); OSMO_ASSERT(last_ns_tx_msg != NULL); printf("Got message: %s\n", msgb_hexdump(last_ns_tx_msg)); OSMO_ASSERT(msgb_length(last_ns_tx_msg) == sizeof(expected_ext_msg)); OSMO_ASSERT(0 == memcmp(msgb_data(last_ns_tx_msg), expected_ext_msg, sizeof(expected_ext_msg))); msgb_free(last_ns_tx_msg); last_ns_tx_msg = NULL; printf("----- %s END\n", __func__); } static struct log_info info = {}; int main(int argc, char **argv) { struct sockaddr_in bss_peer= {0}; osmo_init_logging(&info); log_set_use_color(osmo_stderr_target, 0); log_set_print_filename(osmo_stderr_target, 0); bssgp_nsi = gprs_ns_instantiate(gprs_ns_callback, NULL); bss_peer.sin_family = AF_INET; bss_peer.sin_port = htons(32000); bss_peer.sin_addr.s_addr = htonl(0x7f0000ff); gprs_ns_nsip_connect(bssgp_nsi, &bss_peer, BSS_NSEI, BSS_NSEI+1); printf("===== BSSGP test START\n"); test_bssgp_suspend_resume(); test_bssgp_status(); test_bssgp_bad_reset(); test_bssgp_flow_control_bvc(); printf("===== BSSGP test END\n\n"); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { struct ctrl_handle *ctrl; struct gsm_network dummy_network; int rc; tall_bsc_ctx = talloc_named_const(NULL, 0, "osmo_sgsn"); tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 0, "msgb"); signal(SIGINT, &signal_handler); signal(SIGABRT, &signal_handler); signal(SIGUSR1, &signal_handler); signal(SIGUSR2, &signal_handler); osmo_init_ignore_signals(); osmo_init_logging(&gprs_log_info); vty_info.copyright = openbsc_copyright; vty_init(&vty_info); logging_vty_add_cmds(&gprs_log_info); sgsn_vty_init(); handle_options(argc, argv); rate_ctr_init(tall_bsc_ctx); rc = telnet_init(tall_bsc_ctx, &dummy_network, OSMO_VTY_PORT_SGSN); if (rc < 0) exit(1); ctrl = sgsn_controlif_setup(NULL, OSMO_CTRL_PORT_SGSN); if (!ctrl) { LOGP(DGPRS, LOGL_ERROR, "Failed to create CTRL interface.\n"); exit(1); } if (sgsn_ctrl_cmds_install() != 0) { LOGP(DGPRS, LOGL_ERROR, "Failed to install CTRL commands.\n"); exit(1); } gprs_ns_set_log_ss(DNS); bssgp_set_log_ss(DBSSGP); sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb, tall_bsc_ctx); if (!sgsn_nsi) { LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n"); exit(1); } bssgp_nsi = sgsn_inst.cfg.nsi = sgsn_nsi; gprs_llc_init("/usr/local/lib/osmocom/crypt/"); sgsn_inst_init(); gprs_ns_vty_init(bssgp_nsi); bssgp_vty_init(); gprs_llc_vty_init(); gprs_sndcp_vty_init(); sgsn_auth_init(); sgsn_cdr_init(&sgsn_inst); /* FIXME: register signal handler for SS_L_NS */ rc = sgsn_parse_config(sgsn_inst.config_file, &sgsn_inst.cfg); if (rc < 0) { LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file\n"); exit(2); } rc = sgsn_gtp_init(&sgsn_inst); if (rc) { LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on GTP socket\n"); exit(2); } rc = gprs_subscr_init(&sgsn_inst); if (rc < 0) { LOGP(DGPRS, LOGL_FATAL, "Cannot set up subscriber management\n"); exit(2); } rc = gprs_ns_nsip_listen(sgsn_nsi); if (rc < 0) { LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on NSIP socket\n"); exit(2); } rc = gprs_ns_frgre_listen(sgsn_nsi); if (rc < 0) { LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen GRE " "socket. Do you have CAP_NET_RAW?\n"); exit(2); } if (sgsn->cfg.dynamic_lookup) { if (sgsn_ares_init(sgsn) != 0) { LOGP(DGPRS, LOGL_FATAL, "Failed to initialize c-ares(%d)\n", rc); exit(4); } } if (daemonize) { rc = osmo_daemonize(); if (rc < 0) { perror("Error during daemonize"); exit(1); } } while (1) { rc = osmo_select_main(0); if (rc < 0) exit(3); } /* not reached */ exit(0); }
int main(int argc, char **argv) { struct gsm_network dummy_network; int rc; tall_bsc_ctx = talloc_named_const(NULL, 0, "nsip_proxy"); tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 0, "msgb"); signal(SIGINT, &signal_handler); signal(SIGABRT, &signal_handler); signal(SIGUSR1, &signal_handler); signal(SIGUSR2, &signal_handler); osmo_init_ignore_signals(); osmo_init_logging(&gprs_log_info); vty_info.copyright = openbsc_copyright; vty_init(&vty_info); logging_vty_add_cmds(&gprs_log_info); gbproxy_vty_init(); handle_options(argc, argv); rate_ctr_init(tall_bsc_ctx); rc = telnet_init(tall_bsc_ctx, &dummy_network, 4246); if (rc < 0) exit(1); bssgp_nsi = gprs_ns_instantiate(&proxy_ns_cb, tall_bsc_ctx); if (!bssgp_nsi) { LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n"); exit(1); } gbcfg.nsi = bssgp_nsi; gprs_ns_vty_init(bssgp_nsi); gprs_ns_set_log_ss(DNS); bssgp_set_log_ss(DBSSGP); osmo_signal_register_handler(SS_L_NS, &gbprox_signal, NULL); rc = gbproxy_parse_config(config_file, &gbcfg); if (rc < 0) { LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file\n"); exit(2); } if (!gprs_nsvc_by_nsei(gbcfg.nsi, gbcfg.nsip_sgsn_nsei)) { LOGP(DGPRS, LOGL_FATAL, "You cannot proxy to NSEI %u " "without creating that NSEI before\n", gbcfg.nsip_sgsn_nsei); exit(2); } rc = gprs_ns_nsip_listen(bssgp_nsi); if (rc < 0) { LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on NSIP socket\n"); exit(2); } rc = gprs_ns_frgre_listen(bssgp_nsi); if (rc < 0) { LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen GRE " "socket. Do you have CAP_NET_RAW?\n"); exit(2); } if (daemonize) { rc = osmo_daemonize(); if (rc < 0) { perror("Error during daemonize"); exit(1); } } /* Reset all the persistent NS-VCs that we've read from the config */ gbprox_reset_persistent_nsvcs(bssgp_nsi); while (1) { rc = osmo_select_main(0); if (rc < 0) exit(3); } exit(0); }