]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: Implement "sh bgp l2vpn evpn community|large-community X" 5119/head
authorLakshman Krishnamoorthy <lkrishnamoor@vmware.com>
Mon, 7 Oct 2019 21:58:39 +0000 (14:58 -0700)
committerLakshman Krishnamoorthy <lkrishnamoor@vmware.com>
Tue, 15 Oct 2019 07:43:41 +0000 (00:43 -0700)
Full output here: https://github.com/FRRouting/frr/pull/5119

Signed-off-by: Lakshman Krishnamoorthy <lkrishnamoor@vmware.com>
bgpd/bgp_evpn_vty.c

index 66681db5203179189fa31673ccbaadcadeffde8e..2344db2e8d394ad5a8a0ecc1430b40e1e0fa9cdf 100644 (file)
@@ -37,6 +37,8 @@
 #include "bgpd/bgp_vty.h"
 #include "bgpd/bgp_errors.h"
 #include "bgpd/bgp_ecommunity.h"
+#include "bgpd/bgp_lcommunity.h"
+#include "bgpd/bgp_community.h"
 
 #define SHOW_DISPLAY_STANDARD 0
 #define SHOW_DISPLAY_TAGS 1
@@ -1079,6 +1081,38 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd,
                                        if (peer_cmp(peer, pi->peer) != 0)
                                                continue;
                                }
+                               if (type == bgp_show_type_lcommunity_exact) {
+                                       struct lcommunity *lcom = output_arg;
+
+                                       if (!pi->attr->lcommunity ||
+                                               !lcommunity_cmp(
+                                               pi->attr->lcommunity, lcom))
+                                               continue;
+                               }
+                               if (type == bgp_show_type_lcommunity) {
+                                       struct lcommunity *lcom = output_arg;
+
+                                       if (!pi->attr->lcommunity ||
+                                               !lcommunity_match(
+                                               pi->attr->lcommunity, lcom))
+                                               continue;
+                               }
+                               if (type == bgp_show_type_community) {
+                                       struct community *com = output_arg;
+
+                                       if (!pi->attr->community ||
+                                               !community_match(
+                                               pi->attr->community, com))
+                                               continue;
+                               }
+                               if (type == bgp_show_type_community_exact) {
+                                       struct community *com = output_arg;
+
+                                       if (!pi->attr->community ||
+                                               !community_cmp(
+                                               pi->attr->community, com))
+                                               continue;
+                               }
                                if (header) {
                                        if (use_json) {
                                                json_object_int_add(
@@ -1654,6 +1688,71 @@ DEFUN(show_ip_bgp_evpn_rd_overlay,
                                     use_json(argc, argv));
 }
 
+DEFUN(show_bgp_l2vpn_evpn_com,
+      show_bgp_l2vpn_evpn_com_cmd,
+      "show bgp l2vpn evpn \
+      <community AA:NN|large-community AA:BB:CC> \
+      [exact-match] [json]",
+      SHOW_STR
+      BGP_STR
+      L2VPN_HELP_STR
+      EVPN_HELP_STR
+      "Display routes matching the community\n"
+      "Community number where AA and NN are (0-65535)\n"
+      "Display routes matching the large-community\n"
+      "List of large-community numbers\n"
+      "Exact match of the communities\n"
+      JSON_STR)
+{
+       int idx = 0;
+       int ret = 0;
+       const char *clist_number_or_name;
+       int show_type = bgp_show_type_normal;
+       struct community *com;
+       struct lcommunity *lcom;
+
+       if (argv_find(argv, argc, "large-community", &idx)) {
+               clist_number_or_name = argv[++idx]->arg;
+               show_type = bgp_show_type_lcommunity;
+
+               if (++idx < argc && strmatch(argv[idx]->text, "exact-match"))
+                       show_type = bgp_show_type_lcommunity_exact;
+
+               lcom = lcommunity_str2com(clist_number_or_name);
+               if (!lcom) {
+                       vty_out(vty, "%% Large-community malformed\n");
+                       return CMD_WARNING;
+               }
+
+               ret = bgp_show_ethernet_vpn(vty, NULL, show_type, lcom,
+                                           SHOW_DISPLAY_STANDARD,
+                                           use_json(argc, argv));
+
+               lcommunity_free(&lcom);
+       } else if (argv_find(argv, argc, "community", &idx)) {
+               clist_number_or_name = argv[++idx]->arg;
+               show_type = bgp_show_type_community;
+
+               if (++idx < argc && strmatch(argv[idx]->text, "exact-match"))
+                       show_type = bgp_show_type_community_exact;
+
+               com = community_str2com(clist_number_or_name);
+
+               if (!com) {
+                       vty_out(vty, "%% Community malformed: %s\n",
+                               clist_number_or_name);
+                       return CMD_WARNING;
+               }
+
+               ret = bgp_show_ethernet_vpn(vty, NULL, show_type, com,
+                                           SHOW_DISPLAY_STANDARD,
+                                           use_json(argc, argv));
+               community_free(&com);
+       }
+
+       return ret;
+}
+
 /* For testing purpose, static route of EVPN RT-5. */
 DEFUN(evpnrt5_network,
       evpnrt5_network_cmd,
@@ -5444,6 +5543,7 @@ void bgp_ethernetvpn_init(void)
        install_element(VIEW_NODE, &show_bgp_evpn_route_vni_all_cmd);
        install_element(VIEW_NODE, &show_bgp_evpn_import_rt_cmd);
        install_element(VIEW_NODE, &show_bgp_vrf_l3vni_info_cmd);
+       install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_com_cmd);
 
        install_element(BGP_EVPN_NODE, &bgp_evpn_vni_cmd);
        install_element(BGP_EVPN_NODE, &no_bgp_evpn_vni_cmd);