bgpd: show peer group information for bgp peer

Currently peer group name is not displayed in show bgp
vty output and also in json output. This fix adds those
information in show bgp command

test:

BGP routing table entry for 192.168.251.0/30, version 1
Paths: (1 available, best #1, table default)
  Advertised to peers:
  192.168.255.3 192.168.251.2 192.168.252.2 r1-eth0
  Local
    0.0.0.0 from 0.0.0.0 (192.168.255.1)
      Origin incomplete, metric 0, weight 32768, valid, sourced, best (First path received)
      Last update: Tue Apr 29 17:28:02 2025

BGP advertisement output json:
{
  "prefix":"192.168.251.0/30",
  "version":1,
  "advertisedTo":{
    "192.168.255.3":{
      "hostname":"r3",
      "peerGroup":"PG"
    },
    "192.168.251.2":{
      "hostname":"r2",
      "peerGroup":"PG2"
    },
    "192.168.252.2":{
      "hostname":"r4",
      "peerGroup":"PG2"
    },
    "r1-eth0":{
      "hostname":"r2"
    }
  },
  "paths":[
    {
      "aspath":{
        "string":"Local",
        "segments":[
        ],
        "length":0
      },
      "origin":"incomplete",
      "metric":0,
      "weight":32768,
      "valid":true,
      "version":1,
      "sourced":true,
      "bestpath":{
        "overall":true,
        "selectionReason":"First path received"
      },
      "lastUpdate":{
        "epoch":1744926043,
        "string":"Thu Apr 17 21:40:43 2025"
      },
      "fibInstalled":true,
      "nexthops":[
        {
          "ip":"0.0.0.0",
          "hostname":"r1",
          "afi":"ipv4",
          "metric":0,
          "accessible":true,
          "used":true
        }
      ],
      "peer":{
        "peerId":"0.0.0.0",
        "routerId":"192.168.255.1"
      }
    }
  ]
}

Signed-off-by: Soumya Roy <souroy@nvidia.com>
This commit is contained in:
Soumya Roy 2025-04-17 21:57:00 +00:00
parent 70530c70cf
commit ca73707b59

View file

@ -11135,6 +11135,10 @@ static void route_vty_out_advertised_to(struct vty *vty, struct peer *peer, int
json_object_string_add(json_peer, "hostname",
peer->hostname);
/* Add peerGroup information when the peer belongs to a group */
if (peer->group)
json_object_string_add(json_peer, "peerGroup", peer->group->name);
if (peer->conf_if)
json_object_object_add(json_adv_to, peer->conf_if,
json_peer);