pespin submitted this change.

View Change

Approvals: Jenkins Builder: Verified fixeria: Looks good to me, approved laforge: Looks good to me, but someone else must approve
vty: Define peer proto during 'peer' node cmd

This way we lock the type (proto) of each peer at creation time.
Otherwise, having the possibility of changing the protocol of the peer
makes all the code too complex and there's no good way to prevent the
protocol from being changed at any time creating unexpected issues.
If the user wants to change the protocol, she can do so by removing the
peer and re-adding it through the VTY with the desired protocol.

Change-Id: I47756dddd8f9b8450ba14c914614fd2391d5486e
---
M doc/examples/osmo-cbc/osmo-cbc.cfg
M src/cbc_vty.c
2 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/doc/examples/osmo-cbc/osmo-cbc.cfg b/doc/examples/osmo-cbc/osmo-cbc.cfg
index dc33b09..cc4272f 100644
--- a/doc/examples/osmo-cbc/osmo-cbc.cfg
+++ b/doc/examples/osmo-cbc/osmo-cbc.cfg
@@ -14,12 +14,10 @@
local-ip 127.0.0.1
local-ip ::1
local-port 29168
- peer example-bsc
- protocol cbsp
+ peer cbsp example-bsc
remote-ip 127.0.0.2
remote-port 48049
- peer example-mme
- protocol sbcap
+ peer sbcap example-mme
remote-ip 127.0.0.2
remote-ip ::2
remote-port 29168
diff --git a/src/cbc_vty.c b/src/cbc_vty.c
index 36d646d..7e5a9db 100644
--- a/src/cbc_vty.c
+++ b/src/cbc_vty.c
@@ -44,6 +44,10 @@
{ 0, NULL }
};

+#define CBC_PEER_PROTO_NAME_VTY_CMD "(cbsp|sbcap)"
+#define CBC_PEER_PROTO_NAME_VTY_STR "Cell Broadcast Service Protocol (GSM)\n" \
+ "SBc Application Part (LTE)\n"
+
static void dump_one_cbc_peer(struct vty *vty, const struct cbc_peer *peer)
{
const char *state = "<disconnected>";
@@ -519,13 +523,17 @@

/* PEER */

-DEFUN(cfg_cbc_peer, cfg_cbc_peer_cmd,
+DEFUN_DEPRECATED(cfg_cbc_peer_old, cfg_cbc_peer_old_cmd,
"peer NAME",
"Remote Peer\n"
"Name identifying the peer\n")
{
struct cbc_peer *peer;

+ vty_out(vty, "%% This function is deprecated, use "
+ "'peer " CBC_PEER_PROTO_NAME_VTY_CMD " NAME' instead. "
+ "Assuming 'cbsp' for peers being created%s", VTY_NEWLINE);
+
peer = cbc_peer_by_name(argv[0]);
if (!peer)
peer = cbc_peer_create(argv[0], CBC_PEER_PROTO_CBSP);
@@ -537,6 +545,27 @@
return CMD_SUCCESS;
}

+DEFUN(cfg_cbc_peer, cfg_cbc_peer_cmd,
+ "peer " CBC_PEER_PROTO_NAME_VTY_CMD " NAME",
+ "Remote Peer\n"
+ CBC_PEER_PROTO_NAME_VTY_STR
+ "Name identifying the peer\n")
+{
+ struct cbc_peer *peer;
+ enum cbc_peer_protocol proto;
+
+ proto = get_string_value(cbc_peer_proto_name_vty, argv[0]);
+ peer = cbc_peer_by_name(argv[1]);
+ if (!peer)
+ peer = cbc_peer_create(argv[1], proto);
+ if (!peer)
+ return CMD_WARNING;
+
+ vty->node = PEER_NODE;
+ vty->index = peer;
+ return CMD_SUCCESS;
+}
+
DEFUN(cfg_cbc_no_peer, cfg_cbc_no_peer_cmd,
"no peer NAME",
NO_STR "Remote Peer\n"
@@ -554,13 +583,13 @@
}


-DEFUN(cfg_peer_proto, cfg_peer_proto_cmd,
- "protocol (cbsp|sbcap)",
+DEFUN_DEPRECATED(cfg_peer_proto, cfg_peer_proto_cmd,
+ "protocol " CBC_PEER_PROTO_NAME_VTY_CMD,
"Configure Protocol of Peer\n"
- "Cell Broadcast Service Protocol (GSM)\n")
+ CBC_PEER_PROTO_NAME_VTY_STR)
{
- struct cbc_peer *peer = (struct cbc_peer *) vty->index;
- peer->proto = get_string_value(cbc_peer_proto_name_vty, argv[0]);
+ vty_out(vty, "%% This function is deprecated and does nothing, use "
+ "'peer " CBC_PEER_PROTO_NAME_VTY_CMD " NAME' instead%s", VTY_NEWLINE);
return CMD_SUCCESS;
}

@@ -646,9 +675,8 @@
static void write_one_peer(struct vty *vty, struct cbc_peer *peer)
{
unsigned int i;
- vty_out(vty, " peer %s%s", peer->name, VTY_NEWLINE);
- vty_out(vty, " protocol %s%s",
- get_value_string(cbc_peer_proto_name_vty, peer->proto), VTY_NEWLINE);
+ vty_out(vty, " peer %s %s%s", get_value_string(cbc_peer_proto_name_vty, peer->proto),
+ peer->name, VTY_NEWLINE);
if (peer->remote_port == -1)
vty_out(vty, " no remote-port%s", VTY_NEWLINE);
else
@@ -696,6 +724,7 @@
install_element(SBcAP_NODE, &cfg_sbcap_no_local_ip_cmd);
install_element(SBcAP_NODE, &cfg_sbcap_local_port_cmd);

+ install_element(CBC_NODE, &cfg_cbc_peer_old_cmd);
install_element(CBC_NODE, &cfg_cbc_peer_cmd);
install_element(CBC_NODE, &cfg_cbc_no_peer_cmd);
install_node(&peer_node, NULL);

To view, visit change 28718. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: osmo-cbc
Gerrit-Branch: master
Gerrit-Change-Id: I47756dddd8f9b8450ba14c914614fd2391d5486e
Gerrit-Change-Number: 28718
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>
Gerrit-MessageType: merged