[cmaster-next] [PATCH 2/7] vtysh: vty adaptations for new bgp vrf node

Philippe Guibert philippe.guibert at 6wind.com
Tue Dec 20 09:46:22 EST 2016


This commit includes changes related to introduce new subnode under bgp
called vrf <>. This node permits configuring route distinguishers and
route target under the subnode, by using vtysh command tool.

Signed-off-by: Philippe Guibert <philippe.guibert at 6wind.com>
---
 vtysh/extract.pl.in  |  2 ++
 vtysh/vtysh.c        | 42 ++++++++++++++++++++++++++++++++++++++++++
 vtysh/vtysh_config.c |  6 +++++-
 3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in
index fc5a5147f1d0..5d8b21ef135d 100755
--- a/vtysh/extract.pl.in
+++ b/vtysh/extract.pl.in
@@ -69,6 +69,8 @@ $ignore{'"exit-link-params"'} = "ignore";
 $ignore{'"vnc defaults"'} = "ignore";
 $ignore{'"vnc nve-group NAME"'} = "ignore";
 $ignore{'"exit-vnc"'} = "ignore";
+$ignore{'"vrf WORD"'} = "ignore";
+$ignore{'"exit-bgp-vrf"'} = "ignore";
 $ignore{'"key chain WORD"'} = "ignore";
 $ignore{'"key (0-2147483647)"'} = "ignore";
 $ignore{'"route-map WORD <deny|permit> (1-65535)"'} = "ignore";
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index f67fc1f31d6b..e6b32791cd33 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -317,6 +317,10 @@ vtysh_execute_func (const char *line, int pager)
            || saved_node == BGP_VNC_L2_GROUP_NODE) && (tried == 1))
 	{
 	  vtysh_execute("exit-vnc");
+        }
+      else if ((saved_node == BGP_VRF_NODE) && (tried == 1))
+	{
+	  vtysh_execute("exit-bgp-vrf");
 	}
       else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
 	{
@@ -969,6 +973,13 @@ static struct cmd_node bgp_vnc_l2_group_node =
   "%s(config-router-vnc-l2-group)# "
 };
 
+/* VRF node. */
+static struct cmd_node bgp_vrf_node =
+{
+  BGP_VRF_NODE,
+  "%s(bgp-vrf)# "
+};
+
 static struct cmd_node ospf_node =
 {
   OSPF_NODE,
@@ -1222,6 +1233,18 @@ DEFUNSH (VTYSH_BGPD,
 }
 #endif
 
+DEFUNSH (VTYSH_BGPD,
+         bgp_vrf,
+         bgp_vrf_cmd,
+       "vrf WORD",
+       "BGP VRF\n"
+       "VRF Name\n"
+)
+{
+  vty->node = BGP_VRF_NODE;
+  return CMD_SUCCESS;
+}
+
 DEFUNSH (VTYSH_RIPD,
 	 key_chain,
 	 key_chain_cmd,
@@ -1484,6 +1507,7 @@ vtysh_exit (struct vty *vty)
     case BGP_VNC_DEFAULTS_NODE:
     case BGP_VNC_NVE_GROUP_NODE:
     case BGP_VNC_L2_GROUP_NODE:
+    case BGP_VRF_NODE:
       vty->node = BGP_NODE;
       break;
     case LDP_IPV4_NODE:
@@ -1560,6 +1584,17 @@ DEFUNSH (VTYSH_BGPD,
   return CMD_SUCCESS;
 }
 
+DEFUNSH (VTYSH_BGPD,
+         exit_bgp_vrf,
+         exit_bgp_vrf_cmd,
+         "exit-bgp-vrf",
+         "Exit from BGP vrf configuration mode\n")
+{
+  if (vty->node == BGP_VRF_NODE)
+    vty->node = BGP_NODE;
+  return CMD_SUCCESS;
+}
+
 DEFUNSH (VTYSH_RIPD,
 	 vtysh_exit_ripd,
 	 vtysh_exit_ripd_cmd,
@@ -3044,6 +3079,7 @@ vtysh_init_vty (void)
   install_node (&bgp_vnc_defaults_node, NULL);
   install_node (&bgp_vnc_nve_group_node, NULL);
   install_node (&bgp_vnc_l2_group_node, NULL);
+  install_node (&bgp_vrf_node, NULL);
   install_node (&ospf_node, NULL);
   install_node (&ripng_node, NULL);
   install_node (&ospf6_node, NULL);
@@ -3082,6 +3118,7 @@ vtysh_init_vty (void)
   vtysh_install_default (BGP_VNC_NVE_GROUP_NODE);
   vtysh_install_default (BGP_VNC_L2_GROUP_NODE);
 #endif
+  vtysh_install_default (BGP_VRF_NODE);
   vtysh_install_default (OSPF_NODE);
   vtysh_install_default (RIPNG_NODE);
   vtysh_install_default (OSPF6_NODE);
@@ -3156,6 +3193,8 @@ vtysh_init_vty (void)
   install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_exit_bgpd_cmd);
   install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_quit_bgpd_cmd);
 #endif
+  install_element (BGP_VRF_NODE, &vtysh_exit_bgpd_cmd);
+  install_element (BGP_VRF_NODE, &vtysh_quit_bgpd_cmd);
   install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
   install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
   install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
@@ -3193,6 +3232,7 @@ vtysh_init_vty (void)
   install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_end_all_cmd);
   install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_end_all_cmd);
   install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_end_all_cmd);
+  install_element (BGP_VRF_NODE, &vtysh_end_all_cmd);
   install_element (ISIS_NODE, &vtysh_end_all_cmd);
   install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
   install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
@@ -3246,6 +3286,7 @@ vtysh_init_vty (void)
   install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
   install_element (BGP_NODE, &address_family_ipv6_cmd);
   install_element (BGP_NODE, &address_family_ipv6_multicast_cmd);
+  install_element (BGP_NODE, &bgp_vrf_cmd);
   install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
   install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
   install_element (BGP_ENCAP_NODE, &exit_address_family_cmd);
@@ -3259,6 +3300,7 @@ vtysh_init_vty (void)
   install_element (BGP_VNC_NVE_GROUP_NODE, &exit_vnc_config_cmd);
   install_element (BGP_VNC_L2_GROUP_NODE, &exit_vnc_config_cmd);
 
+  install_element (BGP_VRF_NODE, &exit_bgp_vrf_cmd);
   install_element (CONFIG_NODE, &key_chain_cmd);
   install_element (CONFIG_NODE, &vtysh_route_map_cmd);
   install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c
index e60e9c091fdf..b4afd56d9298 100644
--- a/vtysh/vtysh_config.c
+++ b/vtysh/vtysh_config.c
@@ -187,7 +187,11 @@ vtysh_config_parse_line (const char *line)
 	      config->index == NS_NODE ||
 	      config->index == VTY_NODE)
 	    config_add_line_uniq (config->line, line);
-	  else
+	  else if (config->index == BGP_VRF_NODE)
+            {
+              config = config_get (BGP_VRF_NODE, line);
+            }
+          else
 	    config_add_line (config->line, line);
 	}
       else
-- 
2.1.4





More information about the dev mailing list