diff options
author | Harald Welte <laforge@gnumonks.org> | 2010-05-01 11:28:43 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2010-05-04 07:20:42 +0200 |
commit | b77c697c0b86a17870da5dda8f0f17007f5e35b4 (patch) | |
tree | def9f69143d11d6241895f037b63bd2dea70e9c6 /openbsc | |
parent | 799e0c92c640db7e0418cc90eff6326898c1e147 (diff) |
[gprs] fully integrate VTY configuration into Gb proxy
The Gb-proxy is now fully configured by config file / VTY
Diffstat (limited to 'openbsc')
-rw-r--r-- | openbsc/include/openbsc/gb_proxy.h | 37 | ||||
-rw-r--r-- | openbsc/include/openbsc/gprs_ns.h | 49 | ||||
-rw-r--r-- | openbsc/src/gb_proxy_main.c | 21 | ||||
-rw-r--r-- | openbsc/src/gb_proxy_vty.c | 30 | ||||
-rw-r--r-- | openbsc/src/gprs_ns.c | 29 |
5 files changed, 112 insertions, 54 deletions
diff --git a/openbsc/include/openbsc/gb_proxy.h b/openbsc/include/openbsc/gb_proxy.h new file mode 100644 index 000000000..8194d2a8b --- /dev/null +++ b/openbsc/include/openbsc/gb_proxy.h @@ -0,0 +1,37 @@ +#ifndef _GB_PROXY_H +#define _GB_PROXY_H + +#include <sys/types.h> + +#include <osmocore/msgb.h> + +#include <openbsc/gprs_ns.h> + +struct gbproxy_config { + /* parsed from config file */ + u_int32_t nsip_listen_ip; + u_int16_t nsip_listen_port; + + u_int32_t nsip_sgsn_ip; + u_int16_t nsip_sgsn_port; + + u_int16_t nsip_sgsn_nsei; + u_int16_t nsip_sgsn_nsvci; + + /* misc */ + struct gprs_ns_inst *nsi; +}; + + +/* gb_proxy_vty .c */ + +int gbproxy_vty_init(void); +int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg); + + +/* gb_proxy.c */ + +/* Main input function for Gb proxy */ +int gbprox_rcvmsg(struct msgb *msg, struct gprs_nsvc *nsvc, uint16_t ns_bvci); + +#endif diff --git a/openbsc/include/openbsc/gprs_ns.h b/openbsc/include/openbsc/gprs_ns.h index dd10d3339..ca02c4b5d 100644 --- a/openbsc/include/openbsc/gprs_ns.h +++ b/openbsc/include/openbsc/gprs_ns.h @@ -76,10 +76,46 @@ enum ns_cause { /* Our Implementation */ #include <netinet/in.h> +#include <osmocore/linuxlist.h> +#include <osmocore/msgb.h> +#include <osmocore/timer.h> +#include <osmocore/select.h> #define NSE_S_BLOCKED 0x0001 #define NSE_S_ALIVE 0x0002 +enum gprs_ns_ll { + GPRS_NS_LL_UDP, + GPRS_NS_LL_E1, +}; + +enum gprs_ns_evt { + GPRS_NS_EVT_UNIT_DATA, +}; + +struct gprs_nsvc; +typedef int gprs_ns_cb_t(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, + struct msgb *msg, u_int16_t bvci); + +/* An instance of the NS protocol stack */ +struct gprs_ns_inst { + /* callback to the user for incoming UNIT DATA IND */ + gprs_ns_cb_t *cb; + + /* linked lists of all NSVC in this instance */ + struct llist_head gprs_nsvcs; + + /* which link-layer are we based on? */ + enum gprs_ns_ll ll; + + union { + /* NS-over-IP specific bits */ + struct { + struct bsc_fd fd; + } nsip; + }; +}; + struct gprs_nsvc { struct llist_head list; struct gprs_ns_inst *nsi; @@ -103,16 +139,6 @@ struct gprs_nsvc { }; }; - -struct gprs_ns_inst; - -enum gprs_ns_evt { - GPRS_NS_EVT_UNIT_DATA, -}; - -typedef int gprs_ns_cb_t(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, - struct msgb *msg, u_int16_t bvci); - /* Create a new NS protocol instance */ struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb); @@ -137,5 +163,6 @@ int nsip_listen(struct gprs_ns_inst *nsi, uint16_t udp_port); /* Establish a connection (from the BSS) to the SGSN */ struct gprs_nsvc *nsip_connect(struct gprs_ns_inst *nsi, - struct sockaddr_in *dest, uint16_t nsvci); + struct sockaddr_in *dest, uint16_t nsei, + uint16_t nsvci); #endif diff --git a/openbsc/src/gb_proxy_main.c b/openbsc/src/gb_proxy_main.c index 1793757fb..8f0306091 100644 --- a/openbsc/src/gb_proxy_main.c +++ b/openbsc/src/gb_proxy_main.c @@ -41,6 +41,7 @@ #include <openbsc/gprs_ns.h> #include <openbsc/telnet_interface.h> #include <openbsc/vty.h> +#include <openbsc/gb_proxy.h> #include "../bscconfig.h" @@ -53,7 +54,6 @@ void subscr_put() { abort(); } void *tall_bsc_ctx; struct gprs_ns_inst *gbprox_nsi; -static u_int16_t nsip_listen_port = 23000; const char *openbsc_version = "Osmocom NSIP Proxy " PACKAGE_VERSION; const char *openbsc_copyright = @@ -64,7 +64,8 @@ const char *openbsc_copyright = "This is free software: you are free to change and redistribute it.\n" "There is NO WARRANTY, to the extent permitted by law.\n"; -static char *config_file = "nsip_proxy.cfg"; +static char *config_file = "gb_proxy.cfg"; +static struct gbproxy_config gbcfg; /* Pointer to the SGSN peer */ extern struct gbprox_peer *gbprox_peer_sgsn; @@ -105,19 +106,27 @@ int main(int argc, char **argv) log_set_all_filter(stderr_target, 1); telnet_init(&dummy_network, 4244); + rc = gbproxy_parse_config(config_file, &gbcfg); + if (rc < 0) { + LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file\n"); + exit(2); + } gbprox_nsi = gprs_ns_instantiate(&proxy_ns_cb); if (!gbprox_nsi) { LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n"); exit(1); } - nsip_listen(gbprox_nsi, nsip_listen_port); + gbcfg.nsi = gbprox_nsi; + nsip_listen(gbprox_nsi, gbcfg.nsip_listen_port); /* 'establish' the outgoing connection to the SGSN */ sin.sin_family = AF_INET; - sin.sin_port = ntohs(23000); - inet_aton("192.168.100.239", &sin.sin_addr); - gbprox_peer_sgsn = nsip_connect(gbprox_nsi, &sin, 2342); + sin.sin_port = htons(gbcfg.nsip_sgsn_port); + sin.sin_addr.s_addr = htonl(gbcfg.nsip_sgsn_ip); + gbprox_peer_sgsn = nsip_connect(gbprox_nsi, &sin, + gbcfg.nsip_sgsn_nsei, + gbcfg.nsip_sgsn_nsvci); while (1) { rc = bsc_select_main(0); diff --git a/openbsc/src/gb_proxy_vty.c b/openbsc/src/gb_proxy_vty.c index ae6be5e4b..16f6a1e0e 100644 --- a/openbsc/src/gb_proxy_vty.c +++ b/openbsc/src/gb_proxy_vty.c @@ -27,27 +27,18 @@ #include <osmocore/talloc.h> #include <openbsc/debug.h> +#include <openbsc/gb_proxy.h> +#include <openbsc/gprs_ns.h> #include <vty/command.h> #include <vty/vty.h> -struct gbproxy_config { - u_int32_t nsip_listen_ip; - u_int16_t nsip_listen_port; - - u_int32_t nsip_sgsn_ip; - u_int16_t nsip_sgsn_port; - - u_int16_t nsip_sgsn_nsei; - u_int16_t nsip_sgsn_nsvci; -}; - static struct gbproxy_config *g_cfg = NULL; /* * vty code for mgcp below */ -struct cmd_node gbproxy_node = { +static struct cmd_node gbproxy_node = { GBPROXY_NODE, "%s(gbproxy)#", 1, @@ -83,6 +74,21 @@ DEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy", SHOW_STR "Display information about the Gb proxy") { /* FIXME: iterate over list of NS-VC's and display their state */ + struct gprs_ns_inst *nsi = g_cfg->nsi; + struct gprs_nsvc *nsvc; + + llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { + vty_out(vty, "NSEI %5u, NS-VC %5u, %s-mode, %s %s%s", + nsvc->nsei, nsvc->nsvci, + nsvc->remote_end_is_sgsn ? "BSS" : "SGSN", + nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD", + nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED", + VTY_NEWLINE); + if (nsvc->nsi->ll == GPRS_NS_LL_UDP) + vty_out(vty, " remote peer %s:%u%s", + inet_ntoa(nsvc->ip.bts_addr.sin_addr), + ntohs(nsvc->ip.bts_addr.sin_port), VTY_NEWLINE); + } return CMD_SUCCESS; } diff --git a/openbsc/src/gprs_ns.c b/openbsc/src/gprs_ns.c index 3bb0bf94d..18d189f5a 100644 --- a/openbsc/src/gprs_ns.c +++ b/openbsc/src/gprs_ns.c @@ -72,30 +72,6 @@ static const struct tlv_definition ns_att_tlvdef = { }, }; -enum gprs_ns_ll { - GPRS_NS_LL_UDP, - GPRS_NS_LL_E1, -}; - -/* An instance of the NS protocol stack */ -struct gprs_ns_inst { - /* callback to the user for incoming UNIT DATA IND */ - gprs_ns_cb_t *cb; - - /* linked lists of all NSVC in this instance */ - struct llist_head gprs_nsvcs; - - /* which link-layer are we based on? */ - enum gprs_ns_ll ll; - - union { - /* NS-over-IP specific bits */ - struct { - struct bsc_fd fd; - } nsip; - }; -}; - /* Lookup struct gprs_nsvc based on NSVCI */ static struct gprs_nsvc *nsvc_by_nsvci(struct gprs_ns_inst *nsi, u_int16_t nsvci) @@ -565,7 +541,8 @@ int nsip_listen(struct gprs_ns_inst *nsi, uint16_t udp_port) /* Establish a connection (from the BSS) to the SGSN */ struct gprs_nsvc *nsip_connect(struct gprs_ns_inst *nsi, - struct sockaddr_in *dest, uint16_t nsvci) + struct sockaddr_in *dest, uint16_t nsei, + uint16_t nsvci) { struct gprs_nsvc *nsvc; @@ -574,6 +551,8 @@ struct gprs_nsvc *nsip_connect(struct gprs_ns_inst *nsi, nsvc = nsvc_create(nsi, nsvci); nsvc->ip.bts_addr = *dest; } + nsvc->nsei = nsei; + nsvc->nsvci = nsvci; nsvc->remote_end_is_sgsn = 1; /* Initiate a RESET procedure */ |