9
0
Fork 0

vty: Add all mighty new vty interface for osmo-stp

This new interface allows to have multiple linksets, msc
connections and ways to connect those in one instance of
the osmo-stp. Forbid to reset linksets without an app.
This commit is contained in:
Holger Hans Peter Freyther 2011-02-22 20:57:08 +01:00
parent 2917644d50
commit f91e26cc9a
18 changed files with 1314 additions and 332 deletions

View File

@ -53,6 +53,7 @@ struct mtp_udp_link {
int link_index;
int reset_timeout;
char *dest;
struct sockaddr_in remote;
struct mtp_udp_data *data;
@ -69,11 +70,13 @@ struct bsc_data {
/* udp code */
struct mtp_udp_data udp_data;
int src_port;
int udp_src_port;
int udp_port;
char *udp_ip;
int udp_nr_links;
int m2ua_src_port;
/* MTP Links */
struct llist_head linksets;
int num_linksets;
@ -104,7 +107,8 @@ void mtp_linkset_up(struct mtp_link_set *);
/* udp init */
struct mtp_link_set *link_set_create(struct bsc_data *bsc);
int link_global_init(struct mtp_udp_data *data, int src_port);
int link_global_init(struct mtp_udp_data *data);
int link_global_bind(struct mtp_udp_data *data, int src_port);
int link_udp_init(struct mtp_udp_link *data, char *dest_ip, int port);
int link_init(struct bsc_data *bsc, struct mtp_link_set *set);
int link_shutdown_all(struct mtp_link_set *);
@ -120,4 +124,6 @@ int mtp_handle_pcap(struct mtp_link *, int dir, const uint8_t *data, int length)
struct bsc_data *bsc_data_create();
struct mtp_udp_link *mtp_udp_link_init(struct mtp_link *link);
#endif

View File

@ -84,6 +84,7 @@ struct mtp_link_set {
struct rate_ctr_group *ctrg;
/* custom data */
struct bsc_data *bsc;
struct ss7_application *app;
};

View File

@ -57,6 +57,8 @@ struct mtp_m2ua_link {
int link_index;
struct llist_head entry;
struct sctp_m2ua_transport *transport;
char *as;
};
/*
@ -71,8 +73,11 @@ struct sctp_m2ua_conn {
struct sctp_m2ua_transport *trans;
};
struct sctp_m2ua_transport *sctp_m2ua_transp_create(const char *ip, int port);
struct sctp_m2ua_transport *sctp_m2ua_transp_create(struct bsc_data *bsc);
int sctp_m2ua_transport_bind(struct sctp_m2ua_transport *, const char *ip, int port);
struct mtp_m2ua_link *mtp_m2ua_link_create(struct sctp_m2ua_transport *transport,
struct mtp_link_set *);
struct mtp_m2ua_link *mtp_m2ua_link_init(struct mtp_link *link);
#endif

View File

@ -49,7 +49,8 @@ enum {
SNMP_STATUS_TIMEOUT,
};
struct snmp_mtp_session *snmp_mtp_session_create(char *host);
struct snmp_mtp_session *snmp_mtp_session_create(void);
int snmp_mtp_peer_name(struct snmp_mtp_session *, char *name);
void snmp_mtp_deactivate(struct snmp_mtp_session *, int link_id);
void snmp_mtp_activate(struct snmp_mtp_session *, int link_id);
void snmp_mtp_poll();

View File

@ -35,6 +35,7 @@ enum ss7_set_type {
};
enum ss7_app_type {
APP_NONE,
APP_CELLMGR,
APP_RELAY,
APP_STP,
@ -59,6 +60,7 @@ struct ss7_application {
int type;
/* for the routing */
int route_is_set;
struct ss7_application_route route_src;
struct ss7_application_route route_dst;

42
include/ss7_vty.h Normal file
View File

@ -0,0 +1,42 @@
/*
* (C) 2011 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2011 by On-Waves
* All Rights Reserved
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef SS7_VTY_H
#define SS7_VTY_H
#include <osmocom/vty/vty.h>
#include <osmocom/vty/buffer.h>
#include <osmocom/vty/command.h>
enum ss7_vty_node {
MGCP_NODE = _LAST_OSMOVTY_NODE + 1,
CELLMGR_NODE,
SS7_NODE,
LINKSETS_NODE,
LINK_NODE,
MSC_NODE,
APP_NODE,
};
extern struct cmd_element cfg_description_cmd;
extern struct cmd_element cfg_no_description_cmd;
#endif

View File

@ -13,12 +13,13 @@ cellmgr_ng_SOURCES = main.c mtp_layer3.c thread.c input/ipaccess.c pcap.c \
bss_patch.c bssap_sccp.c bsc_sccp.c bsc_ussd.c links.c \
msc_conn.c link_udp.c snmp_mtp.c debug.c isup.c \
mtp_link.c counter.c sccp_state.c bsc.c ss7_application.c \
vty_interface.c vty_interface_cmds.c
vty_interface_legacy.c vty_interface_cmds.c
cellmgr_ng_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) $(NEXUSWARE_C7_LIBS) \
-lpthread -lnetsnmp -lcrypto
osmo_stp_SOURCES = main_stp.c mtp_layer3.c thread.c pcap.c link_udp.c snmp_mtp.c \
debug.c links.c isup.c sctp_m2ua.c \
debug.c links.c isup.c sctp_m2ua.c msc_conn.c sccp_state.c \
bss_patch.c bssap_sccp.c bsc_sccp.c bsc_ussd.c input/ipaccess.c \
mtp_link.c counter.c bsc.c ss7_application.c \
vty_interface.c vty_interface_cmds.c
osmo_stp_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) $(NEXUSWARE_C7_LIBS) \

View File

@ -71,10 +71,13 @@ struct bsc_data *bsc_data_create()
bsc->udp_ip = NULL;
bsc->udp_nr_links = 1;
bsc->src_port = 1313;
bsc->udp_src_port = 1313;
bsc->pcap_fd = -1;
bsc->udp_reset_timeout = 180;
/* m2ua code */
bsc->m2ua_src_port = 2904;
return bsc;
}

View File

@ -231,28 +231,12 @@ static int udp_link_start(struct mtp_link *link)
int link_udp_init(struct mtp_udp_link *link, char *remote, int port)
{
/* setup SNMP first, it is blocking */
link->session = snmp_mtp_session_create(remote);
if (!link->session)
return -1;
link->session->data = link;
/* function table */
link->base->shutdown = udp_link_shutdown;
link->base->clear_queue = udp_link_dummy;
link->base->reset = udp_link_reset;
link->base->start = udp_link_start;
link->base->write = udp_link_write;
/* prepare the remote */
memset(&link->remote, 0, sizeof(link->remote));
link->remote.sin_family = AF_INET;
link->remote.sin_port = htons(port);
inet_aton(remote, &link->remote.sin_addr);
/* add it to the list of udp connections */
llist_add_tail(&link->entry, &link->data->links);
return 0;
}
@ -263,12 +247,8 @@ static void snmp_poll(void *_data)
bsc_schedule_timer(&data->snmp_poll, 0, 5000);
}
int link_global_init(struct mtp_udp_data *data, int src_port)
int link_global_init(struct mtp_udp_data *data)
{
struct sockaddr_in addr;
int fd;
int on;
INIT_LLIST_HEAD(&data->links);
write_queue_init(&data->write_queue, 100);
@ -278,6 +258,15 @@ int link_global_init(struct mtp_udp_data *data, int src_port)
data->write_queue.read_cb = udp_read_cb;
data->write_queue.write_cb = udp_write_cb;
return 0;
}
int link_global_bind(struct mtp_udp_data *data, int src_port)
{
struct sockaddr_in addr;
int fd;
int on;
data->write_queue.bfd.fd = fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
LOGP(DINP, LOGL_ERROR, "Failed to create UDP socket.\n");
@ -359,3 +348,50 @@ void snmp_mtp_callback(struct snmp_mtp_session *session,
area, link->nr, link->name, link->set->nr, link->set->name);
}
}
struct mtp_udp_link *mtp_udp_link_init(struct mtp_link *blnk)
{
struct bsc_data *bsc;
struct mtp_udp_link *lnk;
lnk = talloc_zero(blnk, struct mtp_udp_link);
if (!lnk) {
LOGP(DINP, LOGL_ERROR, "Failed to allocate.\n");
return NULL;
}
/* setup SNMP first, it is blocking */
lnk->session = snmp_mtp_session_create();
if (!lnk->session) {
LOGP(DINP, LOGL_ERROR, "Failed to allocate snmp session.\n");
talloc_free(lnk);
return NULL;
}
lnk->session->data = lnk;
bsc = blnk->set->bsc;
lnk->data = &bsc->udp_data;
lnk->reset_timeout = bsc->udp_reset_timeout;
lnk->base = blnk;
lnk->base->data = lnk;
lnk->base->type = SS7_LTYPE_UDP;
lnk->bsc = bsc;
/* function table */
lnk->base->shutdown = udp_link_shutdown;
lnk->base->clear_queue = udp_link_dummy;
lnk->base->reset = udp_link_reset;
lnk->base->start = udp_link_start;
lnk->base->write = udp_link_write;
/* prepare the remote */
memset(&lnk->remote, 0, sizeof(lnk->remote));
lnk->remote.sin_family = AF_INET;
/* add it to the list of udp connections */
llist_add_tail(&lnk->entry, &lnk->data->links);
return lnk;
}

View File

@ -94,8 +94,6 @@ struct mtp_link_set *link_set_create(struct bsc_data *bsc)
set = mtp_link_set_alloc(bsc);
set->name = talloc_strdup(set, "MTP");
set->sccp_opc = set->isup_opc = -1;
set->pcap_fd = bsc->pcap_fd;
set->ni = MTP_NI_NATION_NET;
set->spare = 0;
@ -116,29 +114,27 @@ int link_init(struct bsc_data *bsc, struct mtp_link_set *set)
struct mtp_link *blnk;
if (!bsc->src_port) {
if (!bsc->udp_src_port) {
LOGP(DINP, LOGL_ERROR, "You need to set a UDP address.\n");
return -1;
}
LOGP(DINP, LOGL_NOTICE, "Using UDP MTP mode.\n");
if (link_global_init(&bsc->udp_data, bsc->src_port) != 0)
if (link_global_init(&bsc->udp_data) != 0)
return -1;
if (link_global_bind(&bsc->udp_data, bsc->udp_src_port) != 0)
return -1;
for (i = 1; i <= bsc->udp_nr_links; ++i) {
blnk = mtp_link_alloc(set);
lnk = talloc_zero(blnk, struct mtp_udp_link);
lnk->base = blnk;
lnk->base->data = lnk;
lnk->base->type = SS7_LTYPE_UDP;
lnk->bsc = bsc;
lnk->data = &bsc->udp_data;
lnk->link_index = i;
lnk->reset_timeout = bsc->udp_reset_timeout;
lnk = mtp_udp_link_init(blnk);
/* now connect to the transport */
if (snmp_mtp_peer_name(lnk->session, bsc->udp_ip) != 0)
return -1;
if (link_udp_init(lnk, bsc->udp_ip, bsc->udp_port) != 0)
return -1;
}

View File

@ -196,9 +196,6 @@ static int inject_init(struct bsc_data *bsc)
int main(int argc, char **argv)
{
int rc;
struct mtp_link_set *set;
struct mtp_link_set *m2ua_set;
struct mtp_m2ua_link *lnk;
struct ss7_application *app;
thread_init();
@ -227,38 +224,7 @@ int main(int argc, char **argv)
srand(time(NULL));
set = link_set_create(bsc);
if (!set) {
LOGP(DINP, LOGL_ERROR, "Failed to allocate the link.\n");
return -1;
}
app = ss7_application_alloc(bsc);
if (!app) {
LOGP(DINP, LOGL_ERROR, "Failed to create the SS7 application.\n");
return -1;
}
m2ua_set = mtp_link_set_alloc(bsc);
m2ua_set->dpc = 92;
m2ua_set->opc = 9;
m2ua_set->sccp_opc = 9;
m2ua_set->isup_opc = 9;
m2ua_set->ni = 3;
m2ua_set->pcap_fd = bsc->pcap_fd;
m2ua_set->name = talloc_strdup(m2ua_set, "M2UA");
m2ua_set->supported_ssn[1] = 1;
m2ua_set->supported_ssn[7] = 1;
m2ua_set->supported_ssn[8] = 1;
m2ua_set->supported_ssn[146] = 1;
m2ua_set->supported_ssn[254] = 1;
cell_vty_init();
if (vty_read_config_file(config, NULL) < 0) {
fprintf(stderr, "Failed to read the VTY config.\n");
return -1;
}
rc = telnet_init(NULL, NULL, 4242);
if (rc < 0)
return rc;
@ -268,23 +234,40 @@ int main(int argc, char **argv)
return -1;
}
if (link_init(bsc, set) != 0)
/* now bind the the UDP and SCTP port */
if (link_global_init(&bsc->udp_data) != 0) {
LOGP(DINP, LOGL_ERROR, "Global UDP input init failed.\n");
return -1;
}
bsc->m2ua_trans = sctp_m2ua_transp_create("0.0.0.0", 2904);
bsc->m2ua_trans = sctp_m2ua_transp_create(bsc);
if (!bsc->m2ua_trans) {
LOGP(DINP, LOGL_ERROR, "Failed to create SCTP transport.\n");
return -1;
}
/* setup things */
lnk = mtp_m2ua_link_create(bsc->m2ua_trans, m2ua_set);
if (vty_read_config_file(config, NULL) < 0) {
fprintf(stderr, "Failed to read the VTY config.\n");
return -1;
}
ss7_application_setup(app, APP_STP,
SS7_SET_LINKSET, 0,
SS7_SET_LINKSET, 1);
if (link_global_bind(&bsc->udp_data, bsc->udp_src_port) != 0) {
LOGP(DINP, LOGL_ERROR, "Global UDP bind failed.\n");
return -1;
}
ss7_application_start(app);
if (sctp_m2ua_transport_bind(bsc->m2ua_trans, "0.0.0.0", bsc->m2ua_src_port) != 0) {
LOGP(DINP, LOGL_ERROR,
"Failed to bind on port %d\n", bsc->m2ua_src_port);
return -1;
}
/* start all apps */
llist_for_each_entry(app, &bsc->apps, entry) {
LOGP(DINP, LOGL_NOTICE,
"Going to start app %d/%s.\n", app->nr, app->name);
ss7_application_start(app);
}
while (1) {
bsc_select_main(0);
@ -293,33 +276,3 @@ int main(int argc, char **argv)
return 0;
}
/* dummy for links */
int msc_connection_start(struct msc_connection *conn)
{
return 0;
}
struct msc_connection *msc_connection_num(struct bsc_data *bsc, int num)
{
return NULL;
}
void msc_mgcp_reset(struct msc_connection *msc)
{
}
void msc_send_reset(struct msc_connection *bsc)
{
}
void msc_close_connection(struct msc_connection *bsc)
{
}
void app_resources_released(struct ss7_application *ss7)
{
}
void app_clear_connections(struct ss7_application *ss7)
{
}
void app_forward_sccp(struct ss7_application *ss7, struct msgb *_msg, int sls)
{
}

View File

@ -609,6 +609,9 @@ struct mtp_link_set *mtp_link_set_alloc(struct bsc_data *bsc)
INIT_LLIST_HEAD(&link->links);
link->nr = bsc->num_linksets++;
link->sccp_opc = link->isup_opc = -1;
link->pcap_fd = bsc->pcap_fd;
link->bsc = bsc;
llist_add_tail(&link->entry, &bsc->linksets);
return link;

View File

@ -711,16 +711,33 @@ static int sctp_m2ua_reset(struct mtp_link *_link)
return 0;
}
struct sctp_m2ua_transport *sctp_m2ua_transp_create(const char *ip, int port)
struct sctp_m2ua_transport *sctp_m2ua_transp_create(struct bsc_data *bsc)
{
struct sctp_m2ua_transport *trans;
trans = talloc_zero(bsc, struct sctp_m2ua_transport);
if (!trans) {
LOGP(DINP, LOGL_ERROR, "Remove the talloc.\n");
return NULL;
}
INIT_LLIST_HEAD(&trans->conns);
INIT_LLIST_HEAD(&trans->links);
return trans;
}
int sctp_m2ua_transport_bind(struct sctp_m2ua_transport *trans,
const char *ip, int port)
{
int sctp;
struct sockaddr_in addr;
struct sctp_m2ua_transport *trans;
sctp = socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP);
if (!sctp) {
LOGP(DINP, LOGL_ERROR, "Failed to create socket.\n");
return NULL;
return -1;
}
memset(&addr, 0, sizeof(addr));
@ -731,25 +748,18 @@ struct sctp_m2ua_transport *sctp_m2ua_transp_create(const char *ip, int port)
if (bind(sctp, (struct sockaddr *) &addr, sizeof(addr)) != 0) {
LOGP(DINP, LOGL_ERROR, "Failed to bind.\n");
close(sctp);
return NULL;
return -2;
}
if (listen(sctp, 1) != 0) {
LOGP(DINP, LOGL_ERROR, "Failed to listen.\n");
close(sctp);
return NULL;
return -3;
}
int on = 1;
setsockopt(sctp, SOL_SCTP, 112, &on, sizeof(on));
trans = talloc_zero(NULL, struct sctp_m2ua_transport);
if (!trans) {
LOGP(DINP, LOGL_ERROR, "Remove the talloc.\n");
close(sctp);
return NULL;
}
trans->bsc.fd = sctp;
trans->bsc.data = trans;
trans->bsc.cb = sctp_trans_accept;
@ -757,33 +767,21 @@ struct sctp_m2ua_transport *sctp_m2ua_transp_create(const char *ip, int port)
if (bsc_register_fd(&trans->bsc) != 0) {
LOGP(DINP, LOGL_ERROR, "Failed to register the fd.\n");
talloc_free(trans);
close(sctp);
return NULL;
return -4;
}
INIT_LLIST_HEAD(&trans->conns);
INIT_LLIST_HEAD(&trans->links);
return trans;
return 0;
}
struct mtp_m2ua_link *mtp_m2ua_link_create(struct sctp_m2ua_transport *trans,
struct mtp_link_set *set)
struct mtp_m2ua_link *mtp_m2ua_link_init(struct mtp_link *blnk)
{
struct mtp_link *blnk;
struct sctp_m2ua_transport *trans;
struct mtp_m2ua_link *lnk;
blnk = mtp_link_alloc(set);
if (!blnk) {
LOGP(DINP, LOGL_ERROR, "Failed to allocate.\n");
return NULL;
}
lnk = talloc_zero(blnk, struct mtp_m2ua_link);
if (!lnk) {
LOGP(DINP, LOGL_ERROR, "Failed to allocate.\n");
talloc_free(blnk);
return NULL;
}
@ -793,6 +791,7 @@ struct mtp_m2ua_link *mtp_m2ua_link_create(struct sctp_m2ua_transport *trans,
blnk->type = SS7_LTYPE_M2UA;
/* remember we have a link here */
trans = blnk->set->bsc->m2ua_trans;
llist_add_tail(&lnk->entry, &trans->links);
lnk->base->shutdown = sctp_m2ua_reset;

View File

@ -18,6 +18,7 @@
*
*/
#include <snmp_mtp.h>
#include <cellmgr_debug.h>
#include <osmocore/talloc.h>
static void add_pdu_var(netsnmp_pdu *pdu, const char *mib_name, int id, const char *value)
@ -120,7 +121,7 @@ static void snmp_mtp_stop_c7_datalink(struct snmp_mtp_session *session, int link
session->last_do_req = status;
}
struct snmp_mtp_session *snmp_mtp_session_create(char *host)
struct snmp_mtp_session *snmp_mtp_session_create()
{
struct snmp_mtp_session *session = talloc_zero(NULL, struct snmp_mtp_session);
if (!session)
@ -128,21 +129,32 @@ struct snmp_mtp_session *snmp_mtp_session_create(char *host)
init_snmp("cellmgr_ng");
snmp_sess_init(&session->session);
session->session.peername = host;
session->session.version = SNMP_VERSION_1;
session->session.community = (unsigned char *) "private";
session->session.community_len = strlen((const char *) session->session.community);
session->session.myvoid = session;
return session;
}
int snmp_mtp_peer_name(struct snmp_mtp_session *session, char *host)
{
if (session->ss) {
snmp_close(session->ss);
session->ss = NULL;
}
session->session.peername = host;
session->ss = snmp_open(&session->session);
if (!session->ss) {
snmp_perror("create failure");
snmp_log(LOG_ERR, "Could not connect to the remote.\n");
talloc_free(session);
return NULL;
LOGP(DINP, LOGL_ERROR, "Failed to open a SNMP session.\n");
return -1;
}
return session;
return 0;
}
void snmp_mtp_deactivate(struct snmp_mtp_session *session, int index)

View File

@ -213,6 +213,7 @@ static int ss7_app_setup_stp(struct ss7_application *app,
app->type = APP_STP;
app->bsc->m2ua_trans->started = 1;
app->route_is_set = 1;
return 0;
}
@ -287,6 +288,7 @@ static int ss7_app_setup_relay(struct ss7_application *app, int type,
app->route_dst.msc = msc;
app->type = type;
app->route_is_set = 1;
return 0;
}
@ -338,6 +340,12 @@ static void start_set(struct ss7_application *app, struct mtp_link_set *set)
int ss7_application_start(struct ss7_application *app)
{
if (!app->route_is_set) {
LOGP(DINP, LOGL_ERROR,
"The routes are not configured on app %d.\n", app->nr);
return -1;
}
start_set(app, app->route_src.set);
start_set(app, app->route_dst.set);

File diff suppressed because it is too large Load Diff

View File

@ -65,13 +65,14 @@ static void dump_state(struct vty *vty, struct mtp_link_set *set)
{
struct mtp_link *link;
if (!set) {
vty_out(vty, "LinkSet for %s is not configured.%s", set->name, VTY_NEWLINE);
if (!set->app) {
vty_out(vty, "LinkSet %d not assigned to an application.%s",
set->nr, VTY_NEWLINE);
return;
}
vty_out(vty, "LinkSet for %s is %s, remote sccp is %s.%s",
set->name,
vty_out(vty, "LinkSet for %d/%s is %s, remote sccp is %s.%s",
set->nr, set->name,
set->available == 0 ? "not available" : "available",
set->sccp_up == 0? "not established" : "established",
VTY_NEWLINE);
@ -200,6 +201,10 @@ DEFUN(pcap_set_stop, pcap_set_stop_cmd,
vty_out(vty, "Unknown Linkset nr %d.%s", set_no, VTY_NEWLINE); \
return CMD_WARNING; \
} \
if (!set->app) { \
vty_out(vty, "Linkset nr %d has no application.%s", \
set_no, VTY_NEWLINE); \
} \
link = mtp_link_num(set, nr); \
if (!link) { \
vty_out(vty, "Can not find link %d.%s", nr, VTY_NEWLINE); \

358
src/vty_interface_legacy.c Normal file
View File

@ -0,0 +1,358 @@
/* VTY code for the Cellmgr */
/*
* (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2010-2011 by On-Waves
* All Rights Reserved
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <bsc_data.h>
#include <mtp_pcap.h>
#include <msc_connection.h>
#include <ss7_application.h>
#include <ss7_vty.h>
#include <osmocore/talloc.h>
#include <osmocore/gsm48.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/logging.h>
#include <osmocom/vty/vty.h>
#include <unistd.h>
#include <netdb.h>
#undef PACKAGE_NAME
#undef PACKAGE_VERSION
#undef PACKAGE_BUGREPORT
#undef PACKAGE_TARNAME
#undef PACKAGE_STRING
#include <cellmgr_config.h>
extern struct bsc_data *bsc;
static struct vty_app_info vty_info = {
.name = "Cellmgr-ng",
.version = VERSION,
.go_parent_cb = NULL,
};
/* vty code */
static struct cmd_node cell_node = {
CELLMGR_NODE,
"%s(cellmgr)#",
1,
};
static int config_write_cell(struct vty *vty)
{
struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
struct msc_connection *msc = msc_connection_num(bsc, 0);
struct ss7_application *app = ss7_application_num(bsc, 0);
vty_out(vty, "cellmgr%s", VTY_NEWLINE);
vty_out(vty, " mtp dpc %d%s", set->dpc, VTY_NEWLINE);
vty_out(vty, " mtp opc %d%s", set->opc, VTY_NEWLINE);
vty_out(vty, " mtp sccp-opc %d%s", set->sccp_opc, VTY_NEWLINE);
vty_out(vty, " mtp ni %d%s", set->ni, VTY_NEWLINE);
vty_out(vty, " mtp spare %d%s", set->spare, VTY_NEWLINE);
vty_out(vty, " mtp sltm once %d%s", set->sltm_once, VTY_NEWLINE);
if (bsc->udp_ip)
vty_out(vty, " udp dest ip %s%s", bsc->udp_ip, VTY_NEWLINE);
vty_out(vty, " udp dest port %d%s", bsc->udp_port, VTY_NEWLINE);
vty_out(vty, " udp src port %d%s", bsc->udp_src_port, VTY_NEWLINE);
vty_out(vty, " udp reset %d%s", bsc->udp_reset_timeout, VTY_NEWLINE);
vty_out(vty, " udp number-links %d%s", bsc->udp_nr_links, VTY_NEWLINE);
vty_out(vty, " isup pass-through %d%s", app->isup_pass, VTY_NEWLINE);
if (msc) {
vty_out(vty, " msc ip %s%s", msc->ip, VTY_NEWLINE);
vty_out(vty, " msc ip-dscp %d%s", msc->dscp, VTY_NEWLINE);
vty_out(vty, " msc token %s%s", msc->token, VTY_NEWLINE);
}
return CMD_SUCCESS;
}
DEFUN(cfg_cell, cfg_cell_cmd,
"cellmgr", "Configure the Cellmgr")
{
vty->node = CELLMGR_NODE;
return CMD_SUCCESS;
}
DEFUN(cfg_net_dpc, cfg_net_dpc_cmd,
"mtp dpc DPC_NR",
"Set the DPC to be used.")
{
struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
set->dpc = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_opc, cfg_net_opc_cmd,
"mtp opc OPC_NR",
"Set the OPC to be used.")
{
struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
set->opc = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_sccp_opc, cfg_net_sccp_opc_cmd,
"mtp sccp-opc OPC_NR",
"Set the SCCP OPC to be used.")
{
struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
set->sccp_opc = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_mtp_ni, cfg_net_mtp_ni_cmd,
"mtp ni NR",
"Set the MTP NI to be used.\n" "NR")
{
struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
set->ni = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_mtp_spare, cfg_net_mtp_spare_cmd,
"mtp spare NR",
"Set the MTP Spare to be used.\n" "NR")
{
struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
set->spare = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd,
"udp dest ip IP",
"Set the IP when UDP mode is supposed to be used.")
{
struct hostent *hosts;
struct in_addr *addr;
hosts = gethostbyname(argv[0]);
if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
addr = (struct in_addr *) hosts->h_addr_list[0];
bsc->udp_ip = talloc_strdup(NULL, inet_ntoa(*addr));
return CMD_SUCCESS;
}
DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd,
"udp dest port PORT_NR",
"If UDP mode is used specify the UDP dest port")
{
bsc->udp_port = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd,
"udp src port PORT_NR",
"Set the UDP source port to be used.")
{
bsc->udp_src_port = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_udp_reset, cfg_udp_reset_cmd,
"udp reset TIMEOUT",
"Set the timeout to take the link down")
{
bsc->udp_reset_timeout = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_udp_nr_links, cfg_udp_nr_links_cmd,
"udp number-links <1-32>",
"Set the number of links to use\n")
{
bsc->udp_nr_links = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_sltm_once, cfg_sltm_once_cmd,
"mtp sltm once (0|1)",
"Send SLTMs until the link is established.")
{
struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
set->sltm_once = !!atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_msc_ip, cfg_msc_ip_cmd,
"msc ip IP",
"Set the MSC IP")
{
struct hostent *hosts;
struct in_addr *addr;
struct msc_connection *msc = msc_connection_num(bsc, 0);
if (!msc) {
vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
return CMD_WARNING;
}
hosts = gethostbyname(argv[0]);
if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
addr = (struct in_addr *) hosts->h_addr_list[0];
if (msc->ip)
talloc_free(msc->ip);
msc->ip = talloc_strdup(msc, inet_ntoa(*addr));
return CMD_SUCCESS;
}
DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd,
"msc ip-dscp <0-255>",
"Set the IP DSCP on the A-link\n"
"Set the DSCP in IP packets to the MSC")
{
struct msc_connection *msc = msc_connection_num(bsc, 0);
if (!msc) {
vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
return CMD_WARNING;
}
msc->dscp = atoi(argv[0]);
return CMD_SUCCESS;
}
ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd,
"msc ip-tos <0-255>",
"Set the IP DSCP on the A-link\n"
"Set the DSCP in IP packets to the MSC")
DEFUN(cfg_msc_token, cfg_msc_token_cmd,
"msc token TOKEN",
"Set the Token to be used for the MSC")
{
struct msc_connection *msc = msc_connection_num(bsc, 0);
if (!msc) {
vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
return CMD_WARNING;
}
if (msc->token)
talloc_free(msc->token);
msc->token = talloc_strdup(msc, argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_ping_time, cfg_ping_time_cmd,
"timeout ping NR",
"Set the PING interval. Negative to disable it")
{
struct msc_connection *msc = msc_connection_num(bsc, 0);
if (!msc) {
vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
return CMD_WARNING;
}
msc->ping_time = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_pong_time, cfg_pong_time_cmd,
"timeout pong NR",
"Set the PING interval. Negative to disable it")
{
struct msc_connection *msc = msc_connection_num(bsc, 0);
if (!msc) {
vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
return CMD_WARNING;
}
msc->pong_time = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_msc_time, cfg_msc_time_cmd,
"timeout msc NR",
"Set the MSC connect timeout")
{
struct msc_connection *msc = msc_connection_num(bsc, 0);
if (!msc) {
vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
return CMD_WARNING;
}
msc->msc_time = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_isup_pass, cfg_isup_pass_cmd,
"isup pass-through (0|1)",
"ISUP related functionality\n"
"Pass through all ISUP messages directly\n"
"Handle some messages locally\n" "Pass through everything\n")
{
struct ss7_application *app = ss7_application_num(bsc, 0);
ss7_application_pass_isup(app, atoi(argv[0]));
return CMD_SUCCESS;
}
extern void cell_vty_init_cmds(void);
void cell_vty_init(void)
{
cmd_init(1);
vty_init(&vty_info);
logging_vty_add_cmds();
install_element(CONFIG_NODE, &cfg_cell_cmd);
install_node(&cell_node, config_write_cell);
install_element(CELLMGR_NODE, &cfg_net_dpc_cmd);
install_element(CELLMGR_NODE, &cfg_net_opc_cmd);
install_element(CELLMGR_NODE, &cfg_net_sccp_opc_cmd);
install_element(CELLMGR_NODE, &cfg_net_mtp_ni_cmd);
install_element(CELLMGR_NODE, &cfg_net_mtp_spare_cmd);
install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd);
install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd);
install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd);
install_element(CELLMGR_NODE, &cfg_udp_reset_cmd);
install_element(CELLMGR_NODE, &cfg_udp_nr_links_cmd);
install_element(CELLMGR_NODE, &cfg_sltm_once_cmd);
install_element(CELLMGR_NODE, &cfg_msc_ip_cmd);
install_element(CELLMGR_NODE, &cfg_msc_token_cmd);
install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd);
install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd);
install_element(CELLMGR_NODE, &cfg_ping_time_cmd);
install_element(CELLMGR_NODE, &cfg_pong_time_cmd);
install_element(CELLMGR_NODE, &cfg_msc_time_cmd);
install_element(CELLMGR_NODE, &cfg_isup_pass_cmd);
cell_vty_init_cmds();
}
const char *openbsc_copyright = "";