aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openbsc/include/openbsc/db.h3
-rw-r--r--openbsc/include/openbsc/gprs_ns.h6
-rw-r--r--openbsc/src/Makefile.am2
-rw-r--r--openbsc/src/db.c56
-rw-r--r--openbsc/src/gprs/Makefile.am4
-rw-r--r--openbsc/src/gprs/gb_proxy_main.c2
-rw-r--r--openbsc/src/gprs/gprs_ns.c282
-rw-r--r--openbsc/src/gprs/gprs_ns_vty.c275
8 files changed, 377 insertions, 253 deletions
diff --git a/openbsc/include/openbsc/db.h b/openbsc/include/openbsc/db.h
index d0a1278ef..1782efb50 100644
--- a/openbsc/include/openbsc/db.h
+++ b/openbsc/include/openbsc/db.h
@@ -66,6 +66,9 @@ int db_apdu_blob_store(struct gsm_subscriber *subscr,
u_int8_t *apdu);
/* Statistics counter storage */
+struct counter;
int db_store_counter(struct counter *ctr);
+struct rate_ctr_group;
+int db_store_rate_ctr_group(struct rate_ctr_group *ctrg);
#endif /* _DB_H */
diff --git a/openbsc/include/openbsc/gprs_ns.h b/openbsc/include/openbsc/gprs_ns.h
index 847e8f9cc..34b1b62d2 100644
--- a/openbsc/include/openbsc/gprs_ns.h
+++ b/openbsc/include/openbsc/gprs_ns.h
@@ -163,6 +163,8 @@ struct gprs_nsvc {
unsigned int remote_end_is_sgsn:1;
unsigned int persistent:1;
+ struct rate_ctr_group *ctrg;
+
union {
struct {
struct sockaddr_in bts_addr;
@@ -200,6 +202,10 @@ struct gprs_nsvc *nsip_connect(struct gprs_ns_inst *nsi,
struct sockaddr_in *dest, uint16_t nsei,
uint16_t nsvci);
+struct gprs_nsvc *nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci);
+void nsvc_delete(struct gprs_nsvc *nsvc);
+struct gprs_nsvc *nsvc_by_nsei(struct gprs_ns_inst *nsi, uint16_t nsei);
+
/* Add NS-specific VTY stuff */
int gprs_ns_vty_init(struct gprs_ns_inst *nsi);
diff --git a/openbsc/src/Makefile.am b/openbsc/src/Makefile.am
index 9dc02575c..177c410ad 100644
--- a/openbsc/src/Makefile.am
+++ b/openbsc/src/Makefile.am
@@ -27,7 +27,7 @@ libmsc_a_SOURCES = gsm_subscriber.c db.c \
handover_logic.c handover_decision.c meas_rep.c
libvty_a_SOURCES = vty/buffer.c vty/command.c vty/vector.c vty/vty.c \
- telnet_interface.c vty_interface_cmds.c
+ telnet_interface.c vty_interface_cmds.c vty/utils.c
libsccp_a_SOURCES = sccp/sccp.c
diff --git a/openbsc/src/db.c b/openbsc/src/db.c
index 8bf47ab38..f7fb3b457 100644
--- a/openbsc/src/db.c
+++ b/openbsc/src/db.c
@@ -20,13 +20,8 @@
*
*/
-#include <openbsc/gsm_data.h>
-#include <openbsc/gsm_04_11.h>
-#include <openbsc/db.h>
-#include <osmocore/talloc.h>
-#include <openbsc/debug.h>
-#include <osmocore/statistics.h>
-
+#include <stdint.h>
+#include <inttypes.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
@@ -34,6 +29,14 @@
#include <errno.h>
#include <dbi/dbi.h>
+#include <openbsc/gsm_data.h>
+#include <openbsc/gsm_04_11.h>
+#include <openbsc/db.h>
+#include <osmocore/talloc.h>
+#include <openbsc/debug.h>
+#include <osmocore/statistics.h>
+#include <osmocore/rate_ctr.h>
+
static char *db_basename = NULL;
static char *db_dirname = NULL;
static dbi_conn conn;
@@ -1180,3 +1183,42 @@ int db_store_counter(struct counter *ctr)
dbi_result_free(result);
return 0;
}
+
+static int db_store_rate_ctr(struct rate_ctr_group *ctrg, unsigned int num,
+ char *q_prefix)
+{
+ dbi_result result;
+ char *q_name;
+
+ dbi_conn_quote_string_copy(conn, ctrg->desc->ctr_desc[num].name,
+ &q_name);
+
+ result = dbi_conn_queryf(conn,
+ "Insert INTO Counters "
+ "(timestamp,name,value) VALUES "
+ "(datetime('now'),%s.%s,%"PRIu64")",
+ q_prefix, q_name, ctrg->ctr[num].current);
+
+ free(q_name);
+
+ if (!result)
+ return -EIO;
+
+ dbi_result_free(result);
+ return 0;
+}
+
+int db_store_rate_ctr_group(struct rate_ctr_group *ctrg)
+{
+ unsigned int i;
+ char *q_prefix;
+
+ dbi_conn_quote_string_copy(conn, ctrg->name_prefix, &q_prefix);
+
+ for (i = 0; i < ctrg->desc->num_ctr; i++)
+ db_store_rate_ctr(ctrg, i, q_prefix);
+
+ free(q_prefix);
+
+ return 0;
+}
diff --git a/openbsc/src/gprs/Makefile.am b/openbsc/src/gprs/Makefile.am
index 7cb7ba66a..88c358a1b 100644
--- a/openbsc/src/gprs/Makefile.am
+++ b/openbsc/src/gprs/Makefile.am
@@ -9,10 +9,10 @@ libsgsn_a_SOURCES = gprs_ns.c gprs_bssgp.c gprs_llc.c gsm_04_08_gprs.c \
crc24.c gprs_sgsn.c gprs_bssgp_util.c
osmo_gbproxy_SOURCES = gb_proxy.c gb_proxy_main.c gb_proxy_vty.c \
- gprs_ns.c gprs_bssgp_util.c \
+ gprs_ns.c gprs_ns_vty.c gprs_bssgp_util.c \
$(top_srcdir)/src/socket.c $(top_srcdir)/src/debug.c
osmo_gbproxy_LDADD = $(top_builddir)/src/libvty.a
-osmo_sgsn_SOURCES = sgsn_main.c sgsn_vty.c \
+osmo_sgsn_SOURCES = sgsn_main.c sgsn_vty.c gprs_ns_vty.c \
$(top_srcdir)/src/socket.c $(top_srcdir)/src/debug.c
osmo_sgsn_LDADD = $(top_builddir)/src/libvty.a libsgsn.a
diff --git a/openbsc/src/gprs/gb_proxy_main.c b/openbsc/src/gprs/gb_proxy_main.c
index d1024f101..fc8f1648d 100644
--- a/openbsc/src/gprs/gb_proxy_main.c
+++ b/openbsc/src/gprs/gb_proxy_main.c
@@ -36,6 +36,7 @@
#include <osmocore/talloc.h>
#include <osmocore/select.h>
+#include <osmocore/rate_ctr.h>
#include <openbsc/signal.h>
#include <openbsc/debug.h>
@@ -138,6 +139,7 @@ int main(int argc, char **argv)
log_add_target(stderr_target);
log_set_all_filter(stderr_target, 1);
+ rate_ctr_init(tall_bsc_ctx);
telnet_init(&dummy_network, 4246);
bssgp_nsi = gprs_ns_instantiate(&proxy_ns_cb);
diff --git a/openbsc/src/gprs/gprs_ns.c b/openbsc/src/gprs/gprs_ns.c
index 11637f7fa..e83aee8e6 100644
--- a/openbsc/src/gprs/gprs_ns.c
+++ b/openbsc/src/gprs/gprs_ns.c
@@ -56,6 +56,7 @@
#include <osmocore/tlv.h>
#include <osmocore/talloc.h>
#include <osmocore/select.h>
+#include <osmocore/rate_ctr.h>
#include <openbsc/debug.h>
#include <openbsc/signal.h>
#include <openbsc/gprs_ns.h>
@@ -63,19 +64,6 @@
#define NS_ALLOC_SIZE 1024
-/* FIXME: this should go to some common file as it is copied
- * in vty_interface.c of the BSC */
-static const struct value_string gprs_ns_timer_strs[] = {
- { 0, "tns-block" },
- { 1, "tns-block-retries" },
- { 2, "tns-reset" },
- { 3, "tns-reset-retries" },
- { 4, "tns-test" },
- { 5, "tns-alive" },
- { 6, "tns-alive-retries" },
- { 0, NULL }
-};
-
static const struct tlv_definition ns_att_tlvdef = {
.def = {
[NS_IE_CAUSE] = { TLV_TYPE_TvLV, 0 },
@@ -86,6 +74,20 @@ static const struct tlv_definition ns_att_tlvdef = {
},
};
+static const struct rate_ctr_desc nsvc_ctr_description[] = {
+ { "packets.in", "Packets at NS Level ( In)" },
+ { "packets.out", "Packets at NS Level (Out)" },
+ { "bytes.in", "Bytes at NS Level ( In)" },
+ { "bytes.out", "Bytes at NS Level (Out)" },
+};
+
+static const struct rate_ctr_group_desc nsvc_ctrg_desc = {
+ .group_prefix_fmt = "ns.nsvc%u",
+ .group_description = "NSVC Peer Statistics",
+ .num_ctr = ARRAY_SIZE(nsvc_ctr_description),
+ .ctr_desc = nsvc_ctr_description,
+};
+
/* Lookup struct gprs_nsvc based on NSVCI */
static struct gprs_nsvc *nsvc_by_nsvci(struct gprs_ns_inst *nsi,
uint16_t nsvci)
@@ -99,8 +101,7 @@ static struct gprs_nsvc *nsvc_by_nsvci(struct gprs_ns_inst *nsi,
}
/* Lookup struct gprs_nsvc based on NSVCI */
-static struct gprs_nsvc *nsvc_by_nsei(struct gprs_ns_inst *nsi,
- uint16_t nsei)
+struct gprs_nsvc *nsvc_by_nsei(struct gprs_ns_inst *nsi, uint16_t nsei)
{
struct gprs_nsvc *nsvc;
llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
@@ -110,7 +111,6 @@ static struct gprs_nsvc *nsvc_by_nsei(struct gprs_ns_inst *nsi,
return NULL;
}
-
/* Lookup struct gprs_nsvc based on remote peer socket addr */
static struct gprs_nsvc *nsvc_by_rem_addr(struct gprs_ns_inst *nsi,
struct sockaddr_in *sin)
@@ -127,7 +127,7 @@ static struct gprs_nsvc *nsvc_by_rem_addr(struct gprs_ns_inst *nsi,
static void gprs_ns_timer_cb(void *data);
-static struct gprs_nsvc *nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci)
+struct gprs_nsvc *nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci)
{
struct gprs_nsvc *nsvc;
@@ -138,13 +138,14 @@ static struct gprs_nsvc *nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci)
nsvc->nsi = nsi;
nsvc->timer.cb = gprs_ns_timer_cb;
nsvc->timer.data = nsvc;
+ nsvc->ctrg = rate_ctr_group_alloc(nsvc, &nsvc_ctrg_desc, nsvci);
llist_add(&nsvc->list, &nsi->gprs_nsvcs);
return nsvc;
}
-static void nsvc_delete(struct gprs_nsvc *nsvc)
+void nsvc_delete(struct gprs_nsvc *nsvc)
{
if (bsc_timer_pending(&nsvc->timer))
bsc_del_timer(&nsvc->timer);
@@ -190,6 +191,10 @@ static int gprs_ns_tx(struct gprs_nsvc *nsvc, struct msgb *msg)
{
int ret;
+ /* Increment number of Uplink bytes */
+ rate_ctr_inc(&nsvc->ctrg->ctr[1]);
+ rate_ctr_add(&nsvc->ctrg->ctr[3], msgb_l2len(msg));
+
switch (nsvc->nsi->ll) {
case GPRS_NS_LL_UDP:
ret = nsip_sendmsg(nsvc, msg);
@@ -211,7 +216,8 @@ static int gprs_ns_tx_simple(struct gprs_nsvc *nsvc, uint8_t pdu_type)
if (!msg)
return -ENOMEM;
- nsh = (struct gprs_ns_hdr *) msgb_put(msg, sizeof(*nsh));
+ msg->l2h = msgb_put(msg, sizeof(*nsh));
+ nsh = (struct gprs_ns_hdr *) msg->l2h;
nsh->pdu_type = pdu_type;
@@ -231,7 +237,8 @@ int gprs_ns_tx_reset(struct gprs_nsvc *nsvc, uint8_t cause)
LOGP(DNS, LOGL_INFO, "NSEI=%u Tx NS RESET (NSVCI=%u, cause=%s)\n",
nsvc->nsei, nsvc->nsvci, gprs_ns_cause_str(cause));
- nsh = (struct gprs_ns_hdr *) msgb_put(msg, sizeof(*nsh));
+ msg->l2h = msgb_put(msg, sizeof(*nsh));
+ nsh = (struct gprs_ns_hdr *) msg->l2h;
nsh->pdu_type = NS_PDUT_RESET;
msgb_tvlv_put(msg, NS_IE_CAUSE, 1, &cause);
@@ -257,7 +264,8 @@ int gprs_ns_tx_status(struct gprs_nsvc *nsvc, uint8_t cause,
LOGP(DNS, LOGL_INFO, "NSEI=%u Tx NS STATUS (NSVCI=%u, cause=%s)\n",
nsvc->nsei, nsvc->nsvci, gprs_ns_cause_str(cause));
- nsh = (struct gprs_ns_hdr *) msgb_put(msg, sizeof(*nsh));
+ msg->l2h = msgb_put(msg, sizeof(*nsh));
+ nsh = (struct gprs_ns_hdr *) msg->l2h;
nsh->pdu_type = NS_PDUT_STATUS;
msgb_tvlv_put(msg, NS_IE_CAUSE, 1, &cause);
@@ -303,7 +311,8 @@ int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause)
/* be conservative and mark it as blocked even now! */
nsvc->state |= NSE_S_BLOCKED;
- nsh = (struct gprs_ns_hdr *) msgb_put(msg, sizeof(*nsh));
+ msg->l2h = msgb_put(msg, sizeof(*nsh));
+ nsh = (struct gprs_ns_hdr *) msg->l2h;
nsh->pdu_type = NS_PDUT_BLOCK;
msgb_tvlv_put(msg, NS_IE_CAUSE, 1, &cause);
@@ -428,7 +437,8 @@ static int gprs_ns_tx_reset_ack(struct gprs_nsvc *nsvc)
nsvci = htons(nsvc->nsvci);
nsei = htons(nsvc->nsei);
- nsh = (struct gprs_ns_hdr *) msgb_put(msg, sizeof(*nsh));
+ msg->l2h = msgb_put(msg, sizeof(*nsh));
+ nsh = (struct gprs_ns_hdr *) msg->l2h;
nsh->pdu_type = NS_PDUT_RESET_ACK;
@@ -600,6 +610,8 @@ int gprs_ns_rcvmsg(struct gprs_ns_inst *nsi, struct msgb *msg,
struct gprs_nsvc *nsvc;
int rc = 0;
+ DEBUGP(DNS, "gprs_ns_rcvmsg(%d)\n", msgb_l2len(msg));
+
/* look up the NSVC based on source address */
nsvc = nsvc_by_rem_addr(nsi, saddr);
if (!nsvc) {
@@ -645,6 +657,10 @@ int gprs_ns_rcvmsg(struct gprs_ns_inst *nsi, struct msgb *msg,
} else
msgb_nsei(msg) = nsvc->nsei;
+ /* Increment number of Incoming bytes */
+ rate_ctr_inc(&nsvc->ctrg->ctr[2]);
+ rate_ctr_add(&nsvc->ctrg->ctr[0], msgb_l2len(msg));
+
switch (nsh->pdu_type) {
case NS_PDUT_ALIVE:
/* If we're dead and blocked and suddenly receive a
@@ -880,224 +896,4 @@ struct gprs_nsvc *nsip_connect(struct gprs_ns_inst *nsi,
return nsvc;
}
-#include <vty/vty.h>
-#include <vty/command.h>
-
-static struct gprs_ns_inst *vty_nsi = NULL;
-
-static struct cmd_node ns_node = {
- NS_NODE,
- "%s(ns)#",
- 1,
-};
-
-static int config_write_ns(struct vty *vty)
-{
- struct gprs_nsvc *nsvc;
- unsigned int i;
-
- vty_out(vty, "ns%s", VTY_NEWLINE);
-
- llist_for_each_entry(nsvc, &vty_nsi->gprs_nsvcs, list) {
- if (!nsvc->persistent)
- continue;
- vty_out(vty, " nse %u nsvci %u%s",
- nsvc->nsei, nsvc->nsvci, VTY_NEWLINE);
- vty_out(vty, " nse %u remote-role %s%s",
- nsvc->nsei, nsvc->remote_end_is_sgsn ? "sgsn" : "bss",
- VTY_NEWLINE);
- if (nsvc->nsi->ll == GPRS_NS_LL_UDP) {
- vty_out(vty, " nse %u remote-ip %s%s",
- nsvc->nsei,
- inet_ntoa(nsvc->ip.bts_addr.sin_addr),
- VTY_NEWLINE);
- vty_out(vty, " nse %u remote-port %u%s",
- nsvc->nsei, ntohs(nsvc->ip.bts_addr.sin_port),
- VTY_NEWLINE);
- }
- }
-
- for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++)
- vty_out(vty, " timer %s %u%s",
- get_value_string(gprs_ns_timer_strs, i),
- vty_nsi->timeout[i], VTY_NEWLINE);
-
- return CMD_SUCCESS;
-}
-
-DEFUN(cfg_ns, cfg_ns_cmd,
- "ns",
- "Configure the GPRS Network Service")
-{
- vty->node = NS_NODE;
- return CMD_SUCCESS;
-}
-
-DEFUN(show_ns, show_ns_cmd, "show ns",
- SHOW_STR "Display information about the NS protocol")
-{
- struct gprs_ns_inst *nsi = vty_nsi;
- struct gprs_nsvc *nsvc;
-
- llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
- vty_out(vty, "NSEI %5u, NS-VC %5u, Remote: %-4s, %5s %9s",
- nsvc->nsei, nsvc->nsvci,
- nsvc->remote_end_is_sgsn ? "SGSN" : "BSS",
- nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
- nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED");
- if (nsvc->nsi->ll == GPRS_NS_LL_UDP)
- vty_out(vty, ", %15s:%u",
- inet_ntoa(nsvc->ip.bts_addr.sin_addr),
- ntohs(nsvc->ip.bts_addr.sin_port));
- vty_out(vty, "%s", VTY_NEWLINE);
- }
-
- return CMD_SUCCESS;
-}
-
-
-#define NSE_CMD_STR "NS Entity\n" "NS Entity ID (NSEI)\n"
-
-DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
- "nse <0-65535> nsvci <0-65534>",
- NSE_CMD_STR
- "NS Virtual Connection\n"
- "NS Virtual Connection ID (NSVCI)\n"
- )
-{
- uint16_t nsei = atoi(argv[0]);
- uint16_t nsvci = atoi(argv[1]);
- struct gprs_nsvc *nsvc;
-
- nsvc = nsvc_by_nsei(vty_nsi, nsei);
- if (!nsvc) {
- nsvc = nsvc_create(vty_nsi, nsvci);
- nsvc->nsei = nsei;
- }
- nsvc->nsvci = nsvci;
- /* All NSVCs that are explicitly configured by VTY are
- * marked as persistent so we can write them to the config
- * file at some later point */
- nsvc->persistent = 1;
-
- return CMD_SUCCESS;
-}
-
-DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd,
- "nse <0-65535> remote-ip A.B.C.D",
- NSE_CMD_STR
- "Remote IP Address\n"
- "Remote IP Address\n")
-{
- uint16_t nsei = atoi(argv[0]);
- struct gprs_nsvc *nsvc;
- nsvc = nsvc_by_nsei(vty_nsi, nsei);
- if (!nsvc) {
- vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
- return CMD_WARNING;
- }
- inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr);
-
- return CMD_SUCCESS;
-
-}
-
-DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd,
- "nse <0-65535> remote-port <0-65535>",
- NSE_CMD_STR
- "Remote UDP Port\n"
- "Remote UDP Port Number\n")
-{
- uint16_t nsei = atoi(argv[0]);
- uint16_t port = atoi(argv[1]);
- struct gprs_nsvc *nsvc;
-
- nsvc = nsvc_by_nsei(vty_nsi, nsei);
- if (!nsvc) {
- vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- nsvc->ip.bts_addr.sin_port = htons(port);
-
- return CMD_SUCCESS;
-}
-
-DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd,
- "nse <0-65535> remote-role (sgsn|bss)",
- NSE_CMD_STR
- "Remote NSE Role\n"
- "Remote Peer is SGSN\n"
- "Remote Peer is BSS\n")
-{
- uint16_t nsei = atoi(argv[0]);
- struct gprs_nsvc *nsvc;
-
- nsvc = nsvc_by_nsei(vty_nsi, nsei);
- if (!nsvc) {
- vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- if (!strcmp(argv[1], "sgsn"))
- nsvc->remote_end_is_sgsn = 1;
- else
- nsvc->remote_end_is_sgsn = 0;
-
- return CMD_SUCCESS;
-}
-
-DEFUN(cfg_no_nse, cfg_no_nse_cmd,
- "no nse <0-65535>",
- "Delete NS Entity\n"
- "Delete " NSE_CMD_STR)
-{
- uint16_t nsei = atoi(argv[0]);
- struct gprs_nsvc *nsvc;
-
- nsvc = nsvc_by_nsei(vty_nsi, nsei);
- if (!nsvc) {
- vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- nsvc_delete(nsvc);
-
- return CMD_SUCCESS;
-}
-
-DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
- "timer " NS_TIMERS " <0-65535>",
- "Network Service Timer\n"
- NS_TIMERS_HELP "Timer Value\n")
-{
- int idx = get_string_value(gprs_ns_timer_strs, argv[0]);
- int val = atoi(argv[1]);
-
- if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout))
- return CMD_WARNING;
-
- vty_nsi->timeout[idx] = val;
-
- return CMD_SUCCESS;
-}
-
-int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
-{
- vty_nsi = nsi;
-
- install_element_ve(&show_ns_cmd);
-
- install_element(CONFIG_NODE, &cfg_ns_cmd);
- install_node(&ns_node, config_write_ns);
- install_default(NS_NODE);
- install_element(NS_NODE, &cfg_nse_nsvci_cmd);
- install_element(NS_NODE, &cfg_nse_remoteip_cmd);
- install_element(NS_NODE, &cfg_nse_remoteport_cmd);
- install_element(NS_NODE, &cfg_nse_remoterole_cmd);
- install_element(NS_NODE, &cfg_no_nse_cmd);
- install_element(NS_NODE, &cfg_ns_timer_cmd);
-
- return 0;
-}
diff --git a/openbsc/src/gprs/gprs_ns_vty.c b/openbsc/src/gprs/gprs_ns_vty.c
new file mode 100644
index 000000000..6e98e44d6
--- /dev/null
+++ b/openbsc/src/gprs/gprs_ns_vty.c
@@ -0,0 +1,275 @@
+/* VTY interface for our GPRS Networks Service (NS) implementation */
+
+/* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdint.h>
+
+#include <arpa/inet.h>
+
+#include <openbsc/gsm_data.h>
+#include <osmocore/msgb.h>
+#include <osmocore/tlv.h>
+#include <osmocore/talloc.h>
+#include <osmocore/select.h>
+#include <osmocore/rate_ctr.h>
+#include <openbsc/debug.h>
+#include <openbsc/signal.h>
+#include <openbsc/gprs_ns.h>
+#include <openbsc/gprs_bssgp.h>
+
+#include <vty/vty.h>
+#include <vty/command.h>
+
+static struct gprs_ns_inst *vty_nsi = NULL;
+
+/* FIXME: this should go to some common file as it is copied
+ * in vty_interface.c of the BSC */
+static const struct value_string gprs_ns_timer_strs[] = {
+ { 0, "tns-block" },
+ { 1, "tns-block-retries" },
+ { 2, "tns-reset" },
+ { 3, "tns-reset-retries" },
+ { 4, "tns-test" },
+ { 5, "tns-alive" },
+ { 6, "tns-alive-retries" },
+ { 0, NULL }
+};
+
+static struct cmd_node ns_node = {
+ NS_NODE,
+ "%s(ns)#",
+ 1,
+};
+
+static int config_write_ns(struct vty *vty)
+{
+ struct gprs_nsvc *nsvc;
+ unsigned int i;
+
+ vty_out(vty, "ns%s", VTY_NEWLINE);
+
+ llist_for_each_entry(nsvc, &vty_nsi->gprs_nsvcs, list) {
+ if (!nsvc->persistent)
+ continue;
+ vty_out(vty, " nse %u nsvci %u%s",
+ nsvc->nsei, nsvc->nsvci, VTY_NEWLINE);
+ vty_out(vty, " nse %u remote-role %s%s",
+ nsvc->nsei, nsvc->remote_end_is_sgsn ? "sgsn" : "bss",
+ VTY_NEWLINE);
+ if (nsvc->nsi->ll == GPRS_NS_LL_UDP) {
+ vty_out(vty, " nse %u remote-ip %s%s",
+ nsvc->nsei,
+ inet_ntoa(nsvc->ip.bts_addr.sin_addr),
+ VTY_NEWLINE);
+ vty_out(vty, " nse %u remote-port %u%s",
+ nsvc->nsei, ntohs(nsvc->ip.bts_addr.sin_port),
+ VTY_NEWLINE);
+ }
+ }
+
+ for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++)
+ vty_out(vty, " timer %s %u%s",
+ get_value_string(gprs_ns_timer_strs, i),
+ vty_nsi->timeout[i], VTY_NEWLINE);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ns, cfg_ns_cmd,
+ "ns",
+ "Configure the GPRS Network Service")
+{
+ vty->node = NS_NODE;
+ return CMD_SUCCESS;
+}
+
+DEFUN(show_ns, show_ns_cmd, "show ns",
+ SHOW_STR "Display information about the NS protocol")
+{
+ struct gprs_ns_inst *nsi = vty_nsi;
+ struct gprs_nsvc *nsvc;
+
+ llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
+ vty_out(vty, "NSEI %5u, NS-VC %5u, Remote: %-4s, %5s %9s",
+ nsvc->nsei, nsvc->nsvci,
+ nsvc->remote_end_is_sgsn ? "SGSN" : "BSS",
+ nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
+ nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED");
+ if (nsvc->nsi->ll == GPRS_NS_LL_UDP)
+ vty_out(vty, ", %15s:%u",
+ inet_ntoa(nsvc->ip.bts_addr.sin_addr),
+ ntohs(nsvc->ip.bts_addr.sin_port));
+ vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out_rate_ctr_group(vty, " ", nsvc->ctrg);
+ }
+
+ return CMD_SUCCESS;
+}
+
+
+#define NSE_CMD_STR "NS Entity\n" "NS Entity ID (NSEI)\n"
+
+DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
+ "nse <0-65535> nsvci <0-65534>",
+ NSE_CMD_STR
+ "NS Virtual Connection\n"
+ "NS Virtual Connection ID (NSVCI)\n"
+ )
+{
+ uint16_t nsei = atoi(argv[0]);
+ uint16_t nsvci = atoi(argv[1]);
+ struct gprs_nsvc *nsvc;
+
+ nsvc = nsvc_by_nsei(vty_nsi, nsei);
+ if (!nsvc) {
+ nsvc = nsvc_create(vty_nsi, nsvci);
+ nsvc->nsei = nsei;
+ }
+ nsvc->nsvci = nsvci;
+ /* All NSVCs that are explicitly configured by VTY are
+ * marked as persistent so we can write them to the config
+ * file at some later point */
+ nsvc->persistent = 1;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd,
+ "nse <0-65535> remote-ip A.B.C.D",
+ NSE_CMD_STR
+ "Remote IP Address\n"
+ "Remote IP Address\n")
+{
+ uint16_t nsei = atoi(argv[0]);
+ struct gprs_nsvc *nsvc;
+
+ nsvc = nsvc_by_nsei(vty_nsi, nsei);
+ if (!nsvc) {
+ vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr);
+
+ return CMD_SUCCESS;
+
+}
+
+DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd,
+ "nse <0-65535> remote-port <0-65535>",
+ NSE_CMD_STR
+ "Remote UDP Port\n"
+ "Remote UDP Port Number\n")
+{
+ uint16_t nsei = atoi(argv[0]);
+ uint16_t port = atoi(argv[1]);
+ struct gprs_nsvc *nsvc;
+
+ nsvc = nsvc_by_nsei(vty_nsi, nsei);
+ if (!nsvc) {
+ vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ nsvc->ip.bts_addr.sin_port = htons(port);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd,
+ "nse <0-65535> remote-role (sgsn|bss)",
+ NSE_CMD_STR
+ "Remote NSE Role\n"
+ "Remote Peer is SGSN\n"
+ "Remote Peer is BSS\n")
+{
+ uint16_t nsei = atoi(argv[0]);
+ struct gprs_nsvc *nsvc;
+
+ nsvc = nsvc_by_nsei(vty_nsi, nsei);
+ if (!nsvc) {
+ vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (!strcmp(argv[1], "sgsn"))
+ nsvc->remote_end_is_sgsn = 1;
+ else
+ nsvc->remote_end_is_sgsn = 0;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_no_nse, cfg_no_nse_cmd,
+ "no nse <0-65535>",
+ "Delete NS Entity\n"
+ "Delete " NSE_CMD_STR)
+{
+ uint16_t nsei = atoi(argv[0]);
+ struct gprs_nsvc *nsvc;
+
+ nsvc = nsvc_by_nsei(vty_nsi, nsei);
+ if (!nsvc) {
+ vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ nsvc_delete(nsvc);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
+ "timer " NS_TIMERS " <0-65535>",
+ "Network Service Timer\n"
+ NS_TIMERS_HELP "Timer Value\n")
+{
+ int idx = get_string_value(gprs_ns_timer_strs, argv[0]);
+ int val = atoi(argv[1]);
+
+ if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout))
+ return CMD_WARNING;
+
+ vty_nsi->timeout[idx] = val;
+
+ return CMD_SUCCESS;
+}
+
+int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
+{
+ vty_nsi = nsi;
+
+ install_element_ve(&show_ns_cmd);
+
+ install_element(CONFIG_NODE, &cfg_ns_cmd);
+ install_node(&ns_node, config_write_ns);
+ install_default(NS_NODE);
+ install_element(NS_NODE, &cfg_nse_nsvci_cmd);
+ install_element(NS_NODE, &cfg_nse_remoteip_cmd);
+ install_element(NS_NODE, &cfg_nse_remoteport_cmd);
+ install_element(NS_NODE, &cfg_nse_remoterole_cmd);
+ install_element(NS_NODE, &cfg_no_nse_cmd);
+ install_element(NS_NODE, &cfg_ns_timer_cmd);
+
+ return 0;
+}