[PATCH] gbproxy/vty: Enhance delete-gbproxy-peer command

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Jacob Erlbeck jerlbeck at sysmocom.de
Thu Oct 24 10:48:23 UTC 2013


This adds the option to delete all BVC peers and/or NS_VC with a
given NSEI with a single command. Static (configured) NS-VC are not
affected. In addition, all connections for this NSEI that can be
deleted by this command can be listed without deleting them by
appending 'dry-run' to the command.

Sponsored-by: On-Waves ehf
---
 openbsc/include/openbsc/gb_proxy.h |    3 +-
 openbsc/src/gprs/gb_proxy.c        |  135 ++++++++++++++++++++++++++++++------
 openbsc/src/gprs/gb_proxy_vty.c    |    3 +-
 openbsc/tests/vty_test_runner.py   |   16 +++++
 4 files changed, 133 insertions(+), 24 deletions(-)

diff --git a/openbsc/include/openbsc/gb_proxy.h b/openbsc/include/openbsc/gb_proxy.h
index e51dd47..c2c9092 100644
--- a/openbsc/include/openbsc/gb_proxy.h
+++ b/openbsc/include/openbsc/gb_proxy.h
@@ -17,7 +17,8 @@ struct gbproxy_config {
 
 extern struct gbproxy_config gbcfg;
 extern struct cmd_element show_gbproxy_cmd;
-extern struct cmd_element delete_gb_cmd;
+extern struct cmd_element delete_gb_bvci_cmd;
+extern struct cmd_element delete_gb_nsei_cmd;
 
 /* gb_proxy_vty .c */
 
diff --git a/openbsc/src/gprs/gb_proxy.c b/openbsc/src/gprs/gb_proxy.c
index a7640f0..6f7d1c3 100644
--- a/openbsc/src/gprs/gb_proxy.c
+++ b/openbsc/src/gprs/gb_proxy.c
@@ -881,8 +881,41 @@ int gbprox_dump_peers(FILE *stream, int indent, int verbose)
 	return 0;
 }
 
+static int gbprox_cleanup_peers(uint16_t nsei, uint16_t bvci)
+{
+	int counter = 0;
+	struct gbprox_peer *peer, *tmp;
+
+	llist_for_each_entry_safe(peer, tmp, &gbprox_bts_peers, list) {
+		if (peer->nsei != nsei)
+			continue;
+		if (bvci && peer->bvci != bvci)
+			continue;
+
+		peer_free(peer);
+		counter += 1;
+	}
+
+	return counter;
+}
+
 #include <osmocom/vty/command.h>
 
+static void gbprox_vty_print_peer(struct vty *vty, struct gbprox_peer *peer)
+{
+	struct gprs_ra_id raid;
+	gsm48_parse_ra(&raid, peer->ra);
+
+	vty_out(vty, "NSEI %5u, PTP-BVCI %5u, "
+		"RAC %u-%u-%u-%u",
+		peer->nsei, peer->bvci,
+		raid.mcc, raid.mnc, raid.lac, raid.rac);
+	if (peer->blocked)
+		vty_out(vty, " [BVC-BLOCKED]");
+
+	vty_out(vty, "%s", VTY_NEWLINE);
+}
+
 gDEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy [stats]",
        SHOW_STR "Display information about the Gb proxy")
 {
@@ -893,17 +926,7 @@ gDEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy [stats]",
 		vty_out_rate_ctr_group(vty, "", get_global_ctrg());
 
 	llist_for_each_entry(peer, &gbprox_bts_peers, list) {
-		struct gprs_ra_id raid;
-		gsm48_parse_ra(&raid, peer->ra);
-
-		vty_out(vty, "NSEI %5u, PTP-BVCI %5u, "
-			"RAC %u-%u-%u-%u",
-			peer->nsei, peer->bvci,
-			raid.mcc, raid.mnc, raid.lac, raid.rac);
-		if (peer->blocked)
-			vty_out(vty, " [BVC-BLOCKED]");
-
-		vty_out(vty, "%s", VTY_NEWLINE);
+		gbprox_vty_print_peer(vty, peer);
 
 		if (show_stats)
 			vty_out_rate_ctr_group(vty, "  ", peer->ctrg);
@@ -911,24 +934,92 @@ gDEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy [stats]",
 	return CMD_SUCCESS;
 }
 
-gDEFUN(delete_gb, delete_gb_cmd,
-	"delete-gbproxy-peer <0-65534> bvci <0-65534>",
-	"Delete a GBProxy peer by NSEI and BVCI\n"
+gDEFUN(delete_gb_bvci, delete_gb_bvci_cmd,
+	"delete-gbproxy-peer <0-65534> bvci <2-65534>",
+	"Delete a GBProxy peer by NSEI and optionally BVCI\n"
 	"NSEI number\n"
-	"BVCI\n"
+	"Only delete peer with a matching BVCI\n"
 	"BVCI number\n")
 {
-	struct gbprox_peer *peer, *tmp;
 	const uint16_t nsei = atoi(argv[0]);
 	const uint16_t bvci = atoi(argv[1]);
+	int counter;
 
-	llist_for_each_entry_safe(peer, tmp, &gbprox_bts_peers, list) {
-		if (peer->bvci != bvci)
-			continue;
-		if (peer->nsei != nsei)
-			continue;
+	counter = gbprox_cleanup_peers(nsei, bvci);
 
-		peer_free(peer);
+	if (counter == 0) {
+		vty_out(vty, "BVC not found%s", VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	return CMD_SUCCESS;
+}
+
+gDEFUN(delete_gb_nsei, delete_gb_nsei_cmd,
+	"delete-gbproxy-peer <0-65534> (only-bvc|only-nsvc|all) [dry-run]",
+	"Delete a GBProxy peer by NSEI and optionally BVCI\n"
+	"NSEI number\n"
+	"Only delete BSSGP connections (BVC)\n"
+	"Only delete dynamic NS connections (NS-VC)\n"
+	"Delete BVC and dynamic NS connections\n"
+	"Show what would be deleted instead of actually deleting\n"
+	)
+{
+	const uint16_t nsei = atoi(argv[0]);
+	const char *mode = argv[1];
+	int dry_run = argc > 2;
+	int delete_bvc = 0;
+	int delete_nsvc = 0;
+	int counter;
+
+	if (strcmp(mode, "only-bvc") == 0)
+		delete_bvc = 1;
+	else if (strcmp(mode, "only-nsvc") == 0)
+		delete_nsvc = 1;
+	else
+		delete_bvc = delete_nsvc = 1;
+
+	if (delete_bvc) {
+		if (!dry_run)
+			counter = gbprox_cleanup_peers(nsei, 0);
+		else {
+			struct gbprox_peer *peer;
+			counter = 0;
+			llist_for_each_entry(peer, &gbprox_bts_peers, list) {
+				if (peer->nsei != nsei)
+					continue;
+
+				vty_out(vty, "BVC: ");
+				gbprox_vty_print_peer(vty, peer);
+				counter += 1;
+			}
+		}
+		vty_out(vty, "%sDeleted %d BVC%s",
+			dry_run ? "Not " : "", counter, VTY_NEWLINE);
+	}
+
+	if (delete_nsvc) {
+		struct gprs_ns_inst *nsi = gbcfg.nsi;
+		struct gprs_nsvc *nsvc, *nsvc2;
+
+		counter = 0;
+		llist_for_each_entry_safe(nsvc, nsvc2, &nsi->gprs_nsvcs, list) {
+			if (nsvc->nsei != nsei)
+				continue;
+			if (nsvc->persistent)
+				continue;
+
+			if (!dry_run)
+				gprs_nsvc_delete(nsvc);
+			else
+				vty_out(vty, "NS-VC: NSEI %5u, NS-VCI %5u, "
+					"remote %s%s",
+					nsvc->nsei, nsvc->nsvci,
+					gprs_ns_ll_str(nsvc), VTY_NEWLINE);
+			counter += 1;
+		}
+		vty_out(vty, "%sDeleted %d NS-VC%s",
+			dry_run ? "Not " : "", counter, VTY_NEWLINE);
 	}
 
 	return CMD_SUCCESS;
diff --git a/openbsc/src/gprs/gb_proxy_vty.c b/openbsc/src/gprs/gb_proxy_vty.c
index 176ea65..82d49ca 100644
--- a/openbsc/src/gprs/gb_proxy_vty.c
+++ b/openbsc/src/gprs/gb_proxy_vty.c
@@ -80,7 +80,8 @@ int gbproxy_vty_init(void)
 {
 	install_element_ve(&show_gbproxy_cmd);
 
-	install_element(ENABLE_NODE, &delete_gb_cmd);
+	install_element(ENABLE_NODE, &delete_gb_bvci_cmd);
+	install_element(ENABLE_NODE, &delete_gb_nsei_cmd);
 
 	install_element(CONFIG_NODE, &cfg_gbproxy_cmd);
 	install_node(&gbproxy_node, config_write_gbproxy);
diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py
index e040cac..18cf688 100644
--- a/openbsc/tests/vty_test_runner.py
+++ b/openbsc/tests/vty_test_runner.py
@@ -527,6 +527,22 @@ class TestVTYGbproxy(TestVTYGenericBSC):
         res = self.vty.command("show gbproxy stats")
         self.assert_(res.find('GBProxy Global Statistics') >= 0)
 
+    def testVtyDeletePeer(self):
+        self.vty.enable()
+        self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
+        res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
+        self.assert_(res.find('Not Deleted 0 BVC') >= 0)
+        self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
+        res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
+        self.assert_(res.find('Not Deleted 0 BVC') >= 0)
+        self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
+        res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
+        self.assert_(res.find('Not Deleted 0 BVC') < 0)
+        self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
+        res = self.vty.command("delete-gbproxy-peer 9999 all")
+        self.assert_(res.find('Deleted 0 BVC') >= 0)
+        self.assert_(res.find('Deleted 0 NS-VC') >= 0)
+
 def add_nat_test(suite, workdir):
     if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
         print("Skipping the NAT test")
-- 
1.7.9.5





More information about the OpenBSC mailing list