Compare commits

...

3 Commits

Author SHA1 Message Date
Emil Palm
a9b0f37cd6 Fixing a issue with EnabledAdvertised and large datasets. 2019-05-21 07:02:41 +02:00
Emil Palm
50d18afe39 Updates from migration 2019-05-20 07:16:36 +02:00
Emil Palm
a313ef43e0 Better status information from gobgp including version and uptime/reconfigured 2019-05-10 16:55:50 +02:00
3 changed files with 43 additions and 48 deletions

View File

@ -27,25 +27,25 @@ all: $(TARGET)
@echo "Built $(VERSION) @ $(TARGET)"
deps:
GO111MODULE=on go get -v .
GO111MODULE=off go get -v .
osx-dev: deps
GO111MODULE=on go run $(FILES)
GO111MODULE=off go run $(FILES)
osx: deps
GO111MODULE=on GOARCH=$(ARCH) GOOS=darwin go build $(LDFLAGS) -o $(PROG)-osx-$(ARCH)
GO111MODULE=off GOARCH=$(ARCH) GOOS=darwin go build $(LDFLAGS) -o $(PROG)-osx-$(ARCH)
linux: deps
GO111MODULE=on GOARCH=$(ARCH) GOOS=linux go build $(LDFLAGS) -o $(PROG)-linux-$(ARCH)
GO111MODULE=off GOARCH=$(ARCH) GOOS=linux go build $(LDFLAGS) -o $(PROG)-linux-$(ARCH)
bundle:
rice embed-go
test:
GO111MODULE=on go test -v
cd api/ && GO111MODULE=on go test -v
cd caches/ && GO111MODULE=on go test -v
cd sources/birdwatcher && GO111MODULE=on go test -v
GO111MODULE=off go test -v
cd api/ && GO111MODULE=off go test -v
cd caches/ && GO111MODULE=off go test -v
cd sources/birdwatcher && GO111MODULE=off go test -v
dev: clean all

View File

@ -48,10 +48,10 @@ func (gobgp *GoBGP) lookupNeighbour(neighborId string) (*gobgpapi.Peer, error) {
}
func (gobgp *GoBGP) GetNeighbours() ([]*gobgpapi.Peer, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
peerStream, err := gobgp.client.ListPeer(ctx, &gobgpapi.ListPeerRequest{EnableAdvertised: true})
peerStream, err := gobgp.client.ListPeer(ctx, &gobgpapi.ListPeerRequest{EnableAdvertised: false})
if err != nil {
return nil, err
}
@ -63,7 +63,10 @@ func (gobgp *GoBGP) GetNeighbours() ([]*gobgpapi.Peer, error) {
if err == io.EOF {
break
}
peers = append(peers, peer.Peer)
if peer != nil {
peers = append(peers, peer.Peer)
}
}
return peers, nil
}
@ -83,6 +86,7 @@ func (gobgp *GoBGP) parsePathIntoRoute(path *gobgpapi.Path, prefix string) (erro
return err, nil
}
route.Bgp.Communities = make(api.Communities, 0)
route.Bgp.LargeCommunities = make(api.Communities, 0)
route.Bgp.ExtCommunities = make(api.ExtCommunities, 0)
@ -144,7 +148,7 @@ func (gobgp *GoBGP) parsePathIntoRoute(path *gobgpapi.Path, prefix string) (erro
}
func (gobgp *GoBGP) GetRoutes(peer *gobgpapi.Peer, tableType gobgpapi.TableType, response *api.RoutesResponse) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
for _, family := range families {

View File

@ -10,11 +10,12 @@ import (
"context"
"fmt"
"io"
"log"
"time"
)
var contextTimeout time.Duration = time.Second*30
type GoBGP struct {
config Config
client gobgpapi.GobgpApiClient
@ -88,34 +89,28 @@ func (gobgp *GoBGP) ExpireCaches() int {
}
func (gobgp *GoBGP) NeighboursStatus() (*api.NeighboursStatusResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
response := api.NeighboursStatusResponse{}
response.Neighbours = make(api.NeighboursStatus, 0)
resp, err := gobgp.client.ListPeer(ctx, &gobgpapi.ListPeerRequest{})
peers, err := gobgp.GetNeighbours()
if err != nil {
return nil, err
return nil,err
}
for {
_resp, err := resp.Recv()
if err == io.EOF {
break
}
for _, peer := range peers {
ns := api.NeighbourStatus{}
ns.Id = PeerHash(_resp.Peer)
ns.Id = PeerHash(peer)
switch _resp.Peer.State.SessionState {
switch peer.State.SessionState {
case gobgpapi.PeerState_ESTABLISHED:
ns.State = "up"
default:
ns.State = "down"
}
if _resp.Peer.Timers.State.Uptime != nil {
ns.Since = time.Now().Sub(time.Unix(_resp.Peer.Timers.State.Uptime.Seconds, int64(_resp.Peer.Timers.State.Uptime.Nanos)))
if peer.Timers.State.Uptime != nil {
ns.Since = time.Now().Sub(time.Unix(peer.Timers.State.Uptime.Seconds, int64(peer.Timers.State.Uptime.Nanos)))
}
}
@ -123,7 +118,7 @@ func (gobgp *GoBGP) NeighboursStatus() (*api.NeighboursStatusResponse, error) {
}
func (gobgp *GoBGP) Status() (*api.StatusResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), contextTimeout)
defer cancel()
resp, err := gobgp.client.GetBgp(ctx, &gobgpapi.GetBgpRequest{})
@ -133,53 +128,49 @@ func (gobgp *GoBGP) Status() (*api.StatusResponse, error) {
response := api.StatusResponse{}
response.Status.RouterId = resp.Global.RouterId
response.Status.LastReboot = time.Unix(resp.Global.StartedAt.Seconds, int64(resp.Global.StartedAt.Nanos))
response.Status.LastReconfig = time.Unix(resp.Global.ReconfiguredAt.Seconds, int64(resp.Global.ReconfiguredAt.Nanos))
response.Status.Version = resp.Global.Version.Version
response.Status.Message = "Daemon is up and running"
response.Status.Backend = "gobgp"
return &response, nil
}
func (gobgp *GoBGP) Neighbours() (*api.NeighboursResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
response := api.NeighboursResponse{}
response.Neighbours = make(api.Neighbours, 0)
resp, err := gobgp.client.ListPeer(ctx, &gobgpapi.ListPeerRequest{EnableAdvertised: true})
peers, err := gobgp.GetNeighbours()
if err != nil {
return nil, err
}
for {
_resp, err := resp.Recv()
if err == io.EOF {
break
}
for _, peer := range peers {
neigh := api.Neighbour{}
neigh.Address = _resp.Peer.State.NeighborAddress
neigh.Asn = int(_resp.Peer.State.PeerAs)
switch _resp.Peer.State.SessionState {
neigh.Address = peer.State.NeighborAddress
neigh.Asn = int(peer.State.PeerAs)
switch peer.State.SessionState {
case gobgpapi.PeerState_ESTABLISHED:
neigh.State = "up"
default:
neigh.State = "down"
}
neigh.Description = _resp.Peer.Conf.Description
neigh.Description = peer.Conf.Description
neigh.Id = PeerHash(_resp.Peer)
neigh.Id = PeerHash(peer)
response.Neighbours = append(response.Neighbours, &neigh)
for _, afiSafi := range _resp.Peer.AfiSafis {
for _, afiSafi := range peer.AfiSafis {
neigh.RoutesReceived += int(afiSafi.State.Received)
neigh.RoutesExported += int(afiSafi.State.Advertised)
neigh.RoutesAccepted += int(afiSafi.State.Accepted)
neigh.RoutesFiltered += (neigh.RoutesReceived - neigh.RoutesAccepted)
}
if _resp.Peer.Timers.State.Uptime != nil {
neigh.Uptime = time.Now().Sub(time.Unix(_resp.Peer.Timers.State.Uptime.Seconds, int64(_resp.Peer.Timers.State.Uptime.Nanos)))
if peer.Timers.State.Uptime != nil {
neigh.Uptime = time.Now().Sub(time.Unix(peer.Timers.State.Uptime.Seconds, int64(peer.Timers.State.Uptime.Nanos)))
}
response.Neighbours = append(response.Neighbours, &neigh)
}
return &response, nil
@ -298,11 +289,11 @@ func (gobgp *GoBGP) AllRoutes() (*api.RoutesResponse, error) {
if err != nil {
return nil, err
}
for _, peer := range peers {
err = gobgp.GetRoutes(peer, gobgpapi.TableType_ADJ_IN, &routes)
if err != nil {
log.Print(err)
break
}
}