You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

288 lines
10 KiB

  1. From 2939f712d152f7e3ae438cc0f1d96dd9485e7487 Mon Sep 17 00:00:00 2001
  2. From: Donatas Abraitis <donatas.abraitis@gmail.com>
  3. Date: Thu, 9 Jul 2020 16:00:27 +0300
  4. Subject: [PATCH 1/2] bgpd: Add command to show only established sessions
  5. ```
  6. exit1-debian-9# show bgp summary
  7. IPv4 Unicast Summary:
  8. BGP router identifier 192.168.0.1, local AS number 100 vrf-id 0
  9. BGP table version 8
  10. RIB entries 15, using 2880 bytes of memory
  11. Peers 2, using 43 KiB of memory
  12. Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt
  13. 192.168.0.2 4 200 10 6 0 0 0 00:00:35 8 8
  14. 2a02:4780::2 4 0 0 1 0 0 0 never Active 0
  15. Total number of neighbors 2
  16. exit1-debian-9# show bgp summary established
  17. IPv4 Unicast Summary:
  18. BGP router identifier 192.168.0.1, local AS number 100 vrf-id 0
  19. BGP table version 8
  20. RIB entries 15, using 2880 bytes of memory
  21. Peers 2, using 43 KiB of memory
  22. Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt
  23. 192.168.0.2 4 200 10 6 0 0 0 00:00:39 8 8
  24. Total number of neighbors 2
  25. exit1-debian-9# show bgp summary failed
  26. IPv4 Unicast Summary:
  27. BGP router identifier 192.168.0.1, local AS number 100 vrf-id 0
  28. BGP table version 8
  29. RIB entries 15, using 2880 bytes of memory
  30. Peers 2, using 43 KiB of memory
  31. Neighbor EstdCnt DropCnt ResetTime Reason
  32. 2a02:4780::2 0 0 never Waiting for peer OPEN
  33. Total number of neighbors 2
  34. exit1-debian-9#
  35. ```
  36. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
  37. ---
  38. bgpd/bgp_evpn_vty.c | 11 ++++++++---
  39. bgpd/bgp_vty.c | 43 +++++++++++++++++++++++++++++++------------
  40. bgpd/bgp_vty.h | 3 ++-
  41. 3 files changed, 41 insertions(+), 16 deletions(-)
  42. diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c
  43. index 85604d856d..42987117d4 100644
  44. --- a/bgpd/bgp_evpn_vty.c
  45. +++ b/bgpd/bgp_evpn_vty.c
  46. @@ -4077,7 +4077,7 @@ DEFUN(show_bgp_l2vpn_evpn_es,
  47. */
  48. DEFUN(show_bgp_l2vpn_evpn_summary,
  49. show_bgp_l2vpn_evpn_summary_cmd,
  50. - "show bgp [vrf VRFNAME] l2vpn evpn summary [failed] [json]",
  51. + "show bgp [vrf VRFNAME] l2vpn evpn summary [established|failed] [json]",
  52. SHOW_STR
  53. BGP_STR
  54. "bgp vrf\n"
  55. @@ -4085,6 +4085,7 @@ DEFUN(show_bgp_l2vpn_evpn_summary,
  56. L2VPN_HELP_STR
  57. EVPN_HELP_STR
  58. "Summary of BGP neighbor status\n"
  59. + "Show only sessions in Established state\n"
  60. "Show only sessions not in Established state\n"
  61. JSON_STR)
  62. {
  63. @@ -4092,13 +4093,17 @@ DEFUN(show_bgp_l2vpn_evpn_summary,
  64. bool uj = use_json(argc, argv);
  65. char *vrf = NULL;
  66. bool show_failed = false;
  67. + bool show_established = false;
  68. if (argv_find(argv, argc, "vrf", &idx_vrf))
  69. vrf = argv[++idx_vrf]->arg;
  70. if (argv_find(argv, argc, "failed", &idx_vrf))
  71. show_failed = true;
  72. - return bgp_show_summary_vty(vty, vrf, AFI_L2VPN, SAFI_EVPN,
  73. - show_failed, uj);
  74. + if (argv_find(argv, argc, "established", &idx_vrf))
  75. + show_established = true;
  76. +
  77. + return bgp_show_summary_vty(vty, vrf, AFI_L2VPN, SAFI_EVPN, show_failed,
  78. + show_established, uj);
  79. }
  80. /*
  81. diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
  82. index 67ff31df8f..78521457fd 100644
  83. --- a/bgpd/bgp_vty.c
  84. +++ b/bgpd/bgp_vty.c
  85. @@ -8772,7 +8772,8 @@ static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
  86. /* Show BGP peer's summary information. */
  87. static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
  88. - bool show_failed, bool use_json)
  89. + bool show_failed, bool show_established,
  90. + bool use_json)
  91. {
  92. struct peer *peer;
  93. struct listnode *node, *nnode;
  94. @@ -9104,6 +9105,10 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
  95. bgp_show_failed_summary(vty, bgp, peer,
  96. json_peer, 0, use_json);
  97. } else if (!show_failed) {
  98. + if (show_established
  99. + && bgp_has_peer_failed(peer, afi, safi))
  100. + continue;
  101. +
  102. json_peer = json_object_new_object();
  103. if (peer_dynamic_neighbor(peer)) {
  104. json_object_boolean_true_add(json_peer,
  105. @@ -9193,6 +9198,10 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
  106. max_neighbor_width,
  107. use_json);
  108. } else if (!show_failed) {
  109. + if (show_established
  110. + && bgp_has_peer_failed(peer, afi, safi))
  111. + continue;
  112. +
  113. memset(dn_flag, '\0', sizeof(dn_flag));
  114. if (peer_dynamic_neighbor(peer)) {
  115. dn_flag[0] = '*';
  116. @@ -9315,7 +9324,8 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
  117. }
  118. static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
  119. - int safi, bool show_failed, bool use_json)
  120. + int safi, bool show_failed,
  121. + bool show_established, bool use_json)
  122. {
  123. int is_first = 1;
  124. int afi_wildcard = (afi == AFI_MAX);
  125. @@ -9358,7 +9368,8 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
  126. false));
  127. }
  128. }
  129. - bgp_show_summary(vty, bgp, afi, safi, show_failed,
  130. + bgp_show_summary(vty, bgp, afi, safi,
  131. + show_failed, show_established,
  132. use_json);
  133. }
  134. safi++;
  135. @@ -9382,6 +9393,7 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
  136. static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
  137. safi_t safi, bool show_failed,
  138. + bool show_established,
  139. bool use_json)
  140. {
  141. struct listnode *node, *nnode;
  142. @@ -9411,7 +9423,7 @@ static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
  143. : bgp->name);
  144. }
  145. bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
  146. - use_json);
  147. + show_established, use_json);
  148. }
  149. if (use_json)
  150. @@ -9421,15 +9433,16 @@ static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
  151. }
  152. int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
  153. - safi_t safi, bool show_failed, bool use_json)
  154. + safi_t safi, bool show_failed, bool show_established,
  155. + bool use_json)
  156. {
  157. struct bgp *bgp;
  158. if (name) {
  159. if (strmatch(name, "all")) {
  160. - bgp_show_all_instances_summary_vty(vty, afi, safi,
  161. - show_failed,
  162. - use_json);
  163. + bgp_show_all_instances_summary_vty(
  164. + vty, afi, safi, show_failed, show_established,
  165. + use_json);
  166. return CMD_SUCCESS;
  167. } else {
  168. bgp = bgp_lookup_by_name(name);
  169. @@ -9444,7 +9457,8 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
  170. }
  171. bgp_show_summary_afi_safi(vty, bgp, afi, safi,
  172. - show_failed, use_json);
  173. + show_failed, show_established,
  174. + use_json);
  175. return CMD_SUCCESS;
  176. }
  177. }
  178. @@ -9453,7 +9467,7 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
  179. if (bgp)
  180. bgp_show_summary_afi_safi(vty, bgp, afi, safi, show_failed,
  181. - use_json);
  182. + show_established, use_json);
  183. else {
  184. if (use_json)
  185. vty_out(vty, "{}\n");
  186. @@ -9468,7 +9482,7 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
  187. /* `show [ip] bgp summary' commands. */
  188. DEFUN (show_ip_bgp_summary,
  189. show_ip_bgp_summary_cmd,
  190. - "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [failed] [json]",
  191. + "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [established|failed] [json]",
  192. SHOW_STR
  193. IP_STR
  194. BGP_STR
  195. @@ -9476,6 +9490,7 @@ DEFUN (show_ip_bgp_summary,
  196. BGP_AFI_HELP_STR
  197. BGP_SAFI_WITH_LABEL_HELP_STR
  198. "Summary of BGP neighbor status\n"
  199. + "Show only sessions in Established state\n"
  200. "Show only sessions not in Established state\n"
  201. JSON_STR)
  202. {
  203. @@ -9483,6 +9498,7 @@ DEFUN (show_ip_bgp_summary,
  204. afi_t afi = AFI_MAX;
  205. safi_t safi = SAFI_MAX;
  206. bool show_failed = false;
  207. + bool show_established = false;
  208. int idx = 0;
  209. @@ -9504,10 +9520,13 @@ DEFUN (show_ip_bgp_summary,
  210. if (argv_find(argv, argc, "failed", &idx))
  211. show_failed = true;
  212. + if (argv_find(argv, argc, "established", &idx))
  213. + show_established = true;
  214. bool uj = use_json(argc, argv);
  215. - return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed, uj);
  216. + return bgp_show_summary_vty(vty, vrf, afi, safi, show_failed,
  217. + show_established, uj);
  218. }
  219. const char *get_afi_safi_str(afi_t afi, safi_t safi, bool for_json)
  220. diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h
  221. index d6ca198d09..95eefbc36f 100644
  222. --- a/bgpd/bgp_vty.h
  223. +++ b/bgpd/bgp_vty.h
  224. @@ -178,6 +178,7 @@ extern int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
  225. int bgp_vty_find_and_parse_bgp(struct vty *vty, struct cmd_token **argv,
  226. int argc, struct bgp **bgp, bool use_json);
  227. extern int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
  228. - safi_t safi, bool show_failed, bool use_json);
  229. + safi_t safi, bool show_failed,
  230. + bool show_established, bool use_json);
  231. #endif /* _QUAGGA_BGP_VTY_H */
  232. From 2600443342d8e21d30df2b6ca095a5f2d0d4de2d Mon Sep 17 00:00:00 2001
  233. From: Donatas Abraitis <donatas.abraitis@gmail.com>
  234. Date: Thu, 9 Jul 2020 16:05:08 +0300
  235. Subject: [PATCH 2/2] doc: Add 'show bgp summary established' command
  236. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
  237. ---
  238. doc/user/bgp.rst | 6 ++++++
  239. 1 file changed, 6 insertions(+)
  240. diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst
  241. index cb343e8dad..36227db604 100644
  242. --- a/doc/user/bgp.rst
  243. +++ b/doc/user/bgp.rst
  244. @@ -2710,6 +2710,12 @@ structure is extended with :clicmd:`show bgp [afi] [safi]`.
  245. Show a bgp peer summary for peers that are not succesfully exchanging routes
  246. for the specified address family, and subsequent address-family.
  247. +.. index:: show bgp [afi] [safi] summary established [json]
  248. +.. clicmd:: show bgp [afi] [safi] summary established [json]
  249. +
  250. + Show a bgp peer summary for peers that are succesfully exchanging routes
  251. + for the specified address family, and subsequent address-family.
  252. +
  253. .. index:: show bgp [afi] [safi] neighbor [PEER]
  254. .. clicmd:: show bgp [afi] [safi] neighbor [PEER]