Skip to content

Commit

Permalink
show the peer-group name in the output of the 'gobgp neighbor' cli co…
Browse files Browse the repository at this point in the history
…mmand
  • Loading branch information
Timur Aitov committed Feb 10, 2025
1 parent 08a001e commit 14e26c8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cmd/gobgp/neighbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func showNeighbors(vrf string) error {
return nil
}
maxaddrlen := 0
maxgrouplen := len("Group")
maxaslen := 2
maxtimelen := len("Up/Down")
timedelta := []string{}
Expand Down Expand Up @@ -189,6 +190,9 @@ func showNeighbors(vrf string) error {
} else if j := len(n.State.NeighborAddress); j > maxaddrlen {
maxaddrlen = j
}
if l := len(n.Conf.PeerGroup); l > maxgrouplen {
maxgrouplen = l
}
if l := len(getRemoteASN(n)); l > maxaslen {
maxaslen = l
}
Expand All @@ -206,9 +210,9 @@ func showNeighbors(vrf string) error {
timedelta = append(timedelta, timeStr)
}

format := "%-" + fmt.Sprint(maxaddrlen) + "s" + " %" + fmt.Sprint(maxaslen) + "s" + " %" + fmt.Sprint(maxtimelen) + "s"
format := "%-" + fmt.Sprint(maxaddrlen) + "s" + " %" + fmt.Sprint(maxgrouplen) + "s" + " %" + fmt.Sprint(maxaslen) + "s" + " %" + fmt.Sprint(maxtimelen) + "s"
format += " %-11s |%9s %9s\n"
fmt.Printf(format, "Peer", "AS", "Up/Down", "State", "#Received", "Accepted")
fmt.Printf(format, "Peer", "Group", "AS", "Up/Down", "State", "#Received", "Accepted")
formatFsm := func(admin api.PeerState_AdminState, fsm api.PeerState_SessionState) string {
switch admin {
case api.PeerState_DOWN:
Expand Down Expand Up @@ -244,7 +248,7 @@ func showNeighbors(vrf string) error {
neigh = n.Conf.NeighborInterface
}
received, accepted, _, _ := counter(n)
fmt.Printf(format, neigh, getRemoteASN(n), timedelta[i], formatFsm(n.State.AdminState, n.State.SessionState), fmt.Sprint(received), fmt.Sprint(accepted))
fmt.Printf(format, neigh, n.Conf.PeerGroup, getRemoteASN(n), timedelta[i], formatFsm(n.State.AdminState, n.State.SessionState), fmt.Sprint(received), fmt.Sprint(accepted))
}

return nil
Expand Down

0 comments on commit 14e26c8

Please sign in to comment.