summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>2017-10-17 04:32:31 -0700
committerMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>2017-12-14 10:57:06 -0800
commitc0e519d32d69f77bee0d68a45244e1f6ba72f59d (patch)
tree0637fe008d81357da2473572e235bf2f1b00477e
parent9187f600a959fcb5d8ccf380d35a0a3ca4efa8f4 (diff)
zebra: json support for show evpn specific next-hop command
Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
-rw-r--r--zebra/zebra_vty.c9
-rw-r--r--zebra/zebra_vxlan.c72
-rw-r--r--zebra/zebra_vxlan.h2
3 files changed, 62 insertions, 21 deletions
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index 8724f3b1e2..63eab84790 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -2126,18 +2126,19 @@ DEFUN (show_evpn_rmac_l3vni_all,
DEFUN (show_evpn_nh_l3vni_ip,
show_evpn_nh_l3vni_ip_cmd,
- "show evpn next-hops l3vni " CMD_VNI_RANGE " ip WORD",
+ "show evpn next-hops l3vni " CMD_VNI_RANGE " ip WORD [json]",
SHOW_STR
"EVPN\n"
"Remote Vteps\n"
"L3-VNI\n"
"VNI number\n"
"Ip address\n"
- "Host address (ipv4 or ipv6)\n")
+ "Host address (ipv4 or ipv6)\n"
+ JSON_STR)
{
vni_t l3vni;
- u_char uj = use_json(argc, argv);
struct ipaddr ip;
+ u_char uj = use_json(argc, argv);
l3vni = strtoul(argv[4]->arg, NULL, 10);
if (str2ipaddr(argv[6]->arg, &ip) != 0) {
@@ -2145,7 +2146,7 @@ DEFUN (show_evpn_nh_l3vni_ip,
vty_out(vty, "%% Malformed Neighbor address\n");
return CMD_WARNING;
}
- zebra_vxlan_print_specific_nh_l3vni(vty, l3vni, &ip);
+ zebra_vxlan_print_specific_nh_l3vni(vty, l3vni, &ip, uj);
return CMD_SUCCESS;
}
diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c
index 48cf77ed70..9ab2686f85 100644
--- a/zebra/zebra_vxlan.c
+++ b/zebra/zebra_vxlan.c
@@ -63,7 +63,8 @@ static void zvni_print_neigh(zebra_neigh_t *n, void *ctxt, json_object *json);
static void zvni_print_neigh_hash(struct hash_backet *backet, void *ctxt);
static void zvni_print_neigh_hash_all_vni(struct hash_backet *backet,
void **args);
-static void zl3vni_print_nh(zebra_neigh_t *n, struct vty *vty);
+static void zl3vni_print_nh(zebra_neigh_t *n, struct vty *vty,
+ json_object *json);
static void zl3vni_print_rmac(zebra_mac_t *zrmac, struct vty *vty);
static void zvni_print_mac(zebra_mac_t *mac, void *ctxt);
static void zvni_print_mac_hash(struct hash_backet *backet, void *ctxt);
@@ -429,21 +430,39 @@ static void zvni_print_neigh_hash_all_vni(struct hash_backet *backet,
/* print a specific next hop for an l3vni */
static void zl3vni_print_nh(zebra_neigh_t *n,
- struct vty *vty)
+ struct vty *vty,
+ json_object *json)
{
char buf1[ETHER_ADDR_STRLEN];
char buf2[INET6_ADDRSTRLEN];
struct listnode *node = NULL;
struct prefix *p = NULL;
+ json_object *json_hosts = NULL;
- vty_out(vty, "Ip: %s\n",
- ipaddr2str(&n->ip, buf1, sizeof(buf1)));
- vty_out(vty, " RMAC: %s\n",
- prefix_mac2str(&n->emac, buf1, sizeof(buf1)));
- vty_out(vty, " Host-List:\n");
- for (ALL_LIST_ELEMENTS_RO(n->host_list, node, p))
- vty_out(vty, " %s\n",
- prefix2str(p, buf2, sizeof(buf2)));
+ if (!json) {
+ vty_out(vty, "Ip: %s\n",
+ ipaddr2str(&n->ip, buf2, sizeof(buf2)));
+ vty_out(vty, " RMAC: %s\n",
+ prefix_mac2str(&n->emac, buf1, sizeof(buf1)));
+ vty_out(vty, " Host-List:\n");
+ for (ALL_LIST_ELEMENTS_RO(n->host_list, node, p))
+ vty_out(vty, " %s\n",
+ prefix2str(p, buf2, sizeof(buf2)));
+ } else {
+ json_hosts = json_object_new_array();
+ json_object_string_add(json, "ip",
+ ipaddr2str(&(n->ip), buf2,
+ sizeof(buf2)));
+ json_object_string_add(json, "rmac",
+ prefix_mac2str(&n->emac, buf2,
+ sizeof(buf2)));
+ for (ALL_LIST_ELEMENTS_RO(n->host_list, node, p))
+ json_object_array_add(json_hosts,
+ json_object_new_string(
+ prefix2str(p, buf2,
+ sizeof(buf2))));
+ json_object_object_add(json, "hosts", json_hosts);
+ }
}
/* Print a specific RMAC entry */
@@ -3787,28 +3806,49 @@ void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty,
void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty,
vni_t l3vni,
- struct ipaddr *ip)
+ struct ipaddr *ip,
+ u_char use_json)
{
zebra_l3vni_t *zl3vni = NULL;
zebra_neigh_t *n = NULL;
+ json_object *json = NULL;
- if (!is_evpn_enabled())
+ if (!is_evpn_enabled()) {
+ if (use_json)
+ vty_out(vty, "{}\n");
return;
+ }
+
+ if (use_json)
+ json = json_object_new_object();
zl3vni = zl3vni_lookup(l3vni);
if (!zl3vni) {
- vty_out(vty, "%% L3-VNI %u does not exist\n", l3vni);
+ if (use_json)
+ vty_out(vty, "{}\n");
+ else
+ vty_out(vty, "%% L3-VNI %u does not exist\n", l3vni);
return;
}
n = zl3vni_nh_lookup(zl3vni, ip);
if (!n) {
- vty_out(vty, "%% Requested next-hop not present for L3-VNI %u",
- l3vni);
+ if (use_json)
+ vty_out(vty, "{}\n");
+ else
+ vty_out(vty,
+ "%% Requested next-hop not present for L3-VNI %u",
+ l3vni);
return;
}
- zl3vni_print_nh(n, vty);
+ zl3vni_print_nh(n, vty, json);
+
+ if (use_json) {
+ vty_out(vty, "%s\n", json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
+ json_object_free(json);
+ }
}
void zebra_vxlan_print_nh_l3vni(struct vty *vty,
diff --git a/zebra/zebra_vxlan.h b/zebra/zebra_vxlan.h
index 8ec6bb124d..d83d8e973f 100644
--- a/zebra/zebra_vxlan.h
+++ b/zebra/zebra_vxlan.h
@@ -54,7 +54,7 @@ is_evpn_enabled()
extern ifindex_t get_l3vni_svi_ifindex(vrf_id_t vrf_id);
extern int zebra_vxlan_vrf_delete(struct zebra_vrf *);
extern void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni,
- struct ipaddr *ip);
+ struct ipaddr *ip, u_char uj);
extern void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni,
struct ethaddr *rmac);
extern void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf,