Skip to content

Commit

Permalink
Added logic to show local ASN and local BGP peering address for gobgp…
Browse files Browse the repository at this point in the history
… neighbor command
  • Loading branch information
pavel-odintsov committed Mar 31, 2023
1 parent 43cb0f5 commit 22ffdc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cmd/gobgp/neighbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,22 @@ func getNeighbors(address string, enableAdv bool) ([]*api.Peer, error) {
return l, err
}

func getASN(p *api.Peer) string {
func getRemoteASN(p *api.Peer) string {
asn := "*"
if p.State.PeerAsn > 0 {
asn = fmt.Sprint(p.State.PeerAsn)
}
return asn
}

func getLocalASN(p *api.Peer) string {
asn := "*"
if p.State.LocalAsn > 0 {
asn = fmt.Sprint(p.State.LocalAsn)
}
return asn
}

func counter(p *api.Peer) (uint64, uint64, uint64, error) {
accepted := uint64(0)
received := uint64(0)
Expand Down Expand Up @@ -181,7 +189,7 @@ func showNeighbors(vrf string) error {
} else if j := len(n.State.NeighborAddress); j > maxaddrlen {
maxaddrlen = j
}
if l := len(getASN(n)); l > maxaslen {
if l := len(getRemoteASN(n)); l > maxaslen {
maxaslen = l
}
timeStr := "never"
Expand Down Expand Up @@ -236,7 +244,7 @@ func showNeighbors(vrf string) error {
neigh = n.Conf.NeighborInterface
}
received, accepted, _, _ := counter(n)
fmt.Printf(format, neigh, getASN(n), timedelta[i], formatFsm(n.State.AdminState, n.State.SessionState), fmt.Sprint(received), fmt.Sprint(accepted))
fmt.Printf(format, neigh, getRemoteASN(n), timedelta[i], formatFsm(n.State.AdminState, n.State.SessionState), fmt.Sprint(received), fmt.Sprint(accepted))
}

return nil
Expand All @@ -255,7 +263,7 @@ func showNeighbor(args []string) error {
return nil
}

fmt.Printf("BGP neighbor is %s, remote AS %s", p.State.NeighborAddress, getASN(p))
fmt.Printf("BGP neighbor is %s, remote AS %s", p.State.NeighborAddress, getRemoteASN(p))

if p.RouteReflector.RouteReflectorClient {
fmt.Printf(", route-reflector-client\n")
Expand All @@ -277,6 +285,7 @@ func showNeighbor(args []string) error {
fmt.Print("\n")
}
fmt.Printf(" BGP OutQ = %d, Flops = %d\n", p.State.Queues.Output, p.State.Flops)
fmt.Printf(" Local address is %s, local ASN: %s\n", p.Transport.LocalAddress, getLocalASN(p))
fmt.Printf(" Hold time is %d, keepalive interval is %d seconds\n", int(p.Timers.State.NegotiatedHoldTime), int(p.Timers.State.KeepaliveInterval))
fmt.Printf(" Configured hold time is %d, keepalive interval is %d seconds\n", int(p.Timers.Config.HoldTime), int(p.Timers.Config.KeepaliveInterval))

Expand Down
1 change: 1 addition & 0 deletions internal/pkg/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ func NewPeerFromConfigStruct(pconf *Neighbor) *api.Peer {
},
},
PeerAsn: s.PeerAs,
LocalAsn: s.LocalAs,
Type: api.PeerType(s.PeerType.ToInt()),
NeighborAddress: pconf.State.NeighborAddress,
Queues: &api.Queues{},
Expand Down

0 comments on commit 22ffdc1

Please sign in to comment.