summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/grpc_server.go92
-rw-r--r--server/peer.go138
-rw-r--r--server/server.go8
3 files changed, 114 insertions, 124 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index 5963b780..1ad4735a 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2014,2015 Nippon Telegraph and Telephone Corporation.
+// Copyright (C) 2014-2016 Nippon Telegraph and Telephone Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ import (
"fmt"
log "github.com/Sirupsen/logrus"
api "github.com/osrg/gobgp/api"
+ "github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet/bgp"
"golang.org/x/net/context"
"google.golang.org/grpc"
@@ -147,7 +148,94 @@ func (s *Server) GetNeighbor(ctx context.Context, arg *api.GetNeighborRequest) (
if res.Err() != nil {
return nil, res.Err()
}
- return res.Data.(*api.GetNeighborResponse), nil
+
+ toApi := func(pconf *config.Neighbor) *api.Peer {
+ prefixLimits := make([]*api.PrefixLimit, 0, len(pconf.AfiSafis))
+ for _, family := range pconf.AfiSafis {
+ if c := family.PrefixLimit.Config; c.MaxPrefixes > 0 {
+ k, _ := bgp.GetRouteFamily(string(family.Config.AfiSafiName))
+ prefixLimits = append(prefixLimits, &api.PrefixLimit{
+ Family: uint32(k),
+ MaxPrefixes: c.MaxPrefixes,
+ ShutdownThresholdPct: uint32(c.ShutdownThresholdPct),
+ })
+ }
+ }
+
+ timer := pconf.Timers
+ s := pconf.State
+ return &api.Peer{
+ Conf: &api.PeerConf{
+ NeighborAddress: pconf.Config.NeighborAddress,
+ Id: s.Description,
+ PeerAs: pconf.Config.PeerAs,
+ LocalAs: pconf.Config.LocalAs,
+ PeerType: uint32(pconf.Config.PeerType.ToInt()),
+ AuthPassword: pconf.Config.AuthPassword,
+ RemovePrivateAs: uint32(pconf.Config.RemovePrivateAs.ToInt()),
+ RouteFlapDamping: pconf.Config.RouteFlapDamping,
+ SendCommunity: uint32(pconf.Config.SendCommunity.ToInt()),
+ Description: pconf.Config.Description,
+ PeerGroup: pconf.Config.PeerGroup,
+ RemoteCap: s.Capabilities.RemoteList,
+ LocalCap: s.Capabilities.LocalList,
+ PrefixLimits: prefixLimits,
+ },
+ Info: &api.PeerState{
+ BgpState: bgp.FSMState(s.SessionState.ToInt()).String(),
+ AdminState: s.AdminState,
+ Messages: &api.Messages{
+ Received: &api.Message{
+ NOTIFICATION: s.Messages.Received.Notification,
+ UPDATE: s.Messages.Received.Update,
+ OPEN: s.Messages.Received.Open,
+ KEEPALIVE: s.Messages.Received.Keepalive,
+ REFRESH: s.Messages.Received.Refresh,
+ DISCARDED: s.Messages.Received.Discarded,
+ TOTAL: s.Messages.Received.Total,
+ },
+ Sent: &api.Message{
+ NOTIFICATION: s.Messages.Sent.Notification,
+ UPDATE: s.Messages.Sent.Update,
+ OPEN: s.Messages.Sent.Open,
+ KEEPALIVE: s.Messages.Sent.Keepalive,
+ REFRESH: s.Messages.Sent.Refresh,
+ DISCARDED: s.Messages.Sent.Discarded,
+ TOTAL: s.Messages.Sent.Total,
+ },
+ },
+ Received: s.AdjTable.Received,
+ Accepted: s.AdjTable.Accepted,
+ Advertised: s.AdjTable.Advertised,
+ },
+ Timers: &api.Timers{
+ Config: &api.TimersConfig{
+ ConnectRetry: uint64(timer.Config.ConnectRetry),
+ HoldTime: uint64(timer.Config.HoldTime),
+ KeepaliveInterval: uint64(timer.Config.KeepaliveInterval),
+ },
+ State: &api.TimersState{
+ KeepaliveInterval: uint64(timer.State.KeepaliveInterval),
+ NegotiatedHoldTime: uint64(timer.State.NegotiatedHoldTime),
+ Uptime: uint64(timer.State.Uptime),
+ Downtime: uint64(timer.State.Downtime),
+ },
+ },
+ RouteReflector: &api.RouteReflector{
+ RouteReflectorClient: pconf.RouteReflector.Config.RouteReflectorClient,
+ RouteReflectorClusterId: string(pconf.RouteReflector.Config.RouteReflectorClusterId),
+ },
+ RouteServer: &api.RouteServer{
+ RouteServerClient: pconf.RouteServer.Config.RouteServerClient,
+ },
+ }
+ }
+
+ p := []*api.Peer{}
+ for _, e := range res.Data.([]*config.Neighbor) {
+ p = append(p, toApi(e))
+ }
+ return &api.GetNeighborResponse{Peers: p}, nil
}
func handleMultipleResponses(req *GrpcRequest, f func(*GrpcResponse) error) error {
diff --git a/server/peer.go b/server/peer.go
index 1058f2e9..030044d0 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
+// Copyright (C) 2014-2016 Nippon Telegraph and Telephone Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -16,11 +16,9 @@
package server
import (
- "encoding/json"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/eapache/channels"
- api "github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet/bgp"
"github.com/osrg/gobgp/table"
@@ -384,14 +382,14 @@ func (peer *Peer) PassConn(conn *net.TCPConn) {
}
}
-func (peer *Peer) MarshalJSON() ([]byte, error) {
- return json.Marshal(peer.ToApiStruct())
-}
-
-func (peer *Peer) ToApiStruct() *api.Peer {
+func (peer *Peer) ToConfig() *config.Neighbor {
+ // create copy which can be access to without mutex
+ conf := *peer.fsm.pConf
- f := peer.fsm
- c := f.pConf
+ conf.AfiSafis = make([]config.AfiSafi, len(peer.fsm.pConf.AfiSafis))
+ for i := 0; i < len(peer.fsm.pConf.AfiSafis); i++ {
+ conf.AfiSafis[i] = peer.fsm.pConf.AfiSafis[i]
+ }
remoteCap := make([][]byte, 0, len(peer.fsm.capMap))
for _, c := range peer.fsm.capMap {
@@ -400,6 +398,7 @@ func (peer *Peer) ToApiStruct() *api.Peer {
remoteCap = append(remoteCap, buf)
}
}
+ conf.State.Capabilities.RemoteList = remoteCap
caps := capabilitiesFromConfig(peer.fsm.pConf)
localCap := make([][]byte, 0, len(caps))
@@ -407,120 +406,25 @@ func (peer *Peer) ToApiStruct() *api.Peer {
buf, _ := c.Serialize()
localCap = append(localCap, buf)
}
+ conf.State.Capabilities.LocalList = localCap
- prefixLimits := make([]*api.PrefixLimit, 0, len(peer.fsm.pConf.AfiSafis))
- for _, family := range peer.fsm.pConf.AfiSafis {
- if c := family.PrefixLimit.Config; c.MaxPrefixes > 0 {
- k, _ := bgp.GetRouteFamily(string(family.Config.AfiSafiName))
- prefixLimits = append(prefixLimits, &api.PrefixLimit{
- Family: uint32(k),
- MaxPrefixes: c.MaxPrefixes,
- ShutdownThresholdPct: uint32(c.ShutdownThresholdPct),
- })
- }
- }
-
- conf := &api.PeerConf{
- NeighborAddress: c.Config.NeighborAddress,
- Id: peer.fsm.peerInfo.ID.To4().String(),
- PeerAs: c.Config.PeerAs,
- LocalAs: c.Config.LocalAs,
- PeerType: uint32(c.Config.PeerType.ToInt()),
- AuthPassword: c.Config.AuthPassword,
- RemovePrivateAs: uint32(c.Config.RemovePrivateAs.ToInt()),
- RouteFlapDamping: c.Config.RouteFlapDamping,
- SendCommunity: uint32(c.Config.SendCommunity.ToInt()),
- Description: c.Config.Description,
- PeerGroup: c.Config.PeerGroup,
- RemoteCap: remoteCap,
- LocalCap: localCap,
- PrefixLimits: prefixLimits,
- }
-
- timer := c.Timers
- s := c.State
+ conf.State.Description = peer.fsm.peerInfo.ID.To4().String()
+ conf.State.SessionState = config.IntToSessionStateMap[int(peer.fsm.state)]
+ conf.State.AdminState = peer.fsm.adminState.String()
- advertised := uint32(0)
- received := uint32(0)
- accepted := uint32(0)
- if f.state == bgp.BGP_FSM_ESTABLISHED {
+ if peer.fsm.state == bgp.BGP_FSM_ESTABLISHED {
rfList := peer.configuredRFlist()
- advertised = uint32(peer.adjRibOut.Count(rfList))
- received = uint32(peer.adjRibIn.Count(rfList))
- accepted = uint32(peer.adjRibIn.Accepted(rfList))
- }
+ conf.State.AdjTable.Advertised = uint32(peer.adjRibOut.Count(rfList))
+ conf.State.AdjTable.Received = uint32(peer.adjRibIn.Count(rfList))
+ conf.State.AdjTable.Accepted = uint32(peer.adjRibIn.Accepted(rfList))
- uptime := int64(0)
- if timer.State.Uptime != 0 {
- uptime = timer.State.Uptime
- }
- downtime := int64(0)
- if timer.State.Downtime != 0 {
- downtime = timer.State.Downtime
- }
+ conf.Transport.State.LocalAddress, conf.Transport.State.LocalPort = peer.fsm.LocalHostPort()
+ _, conf.Transport.State.RemotePort = peer.fsm.RemoteHostPort()
- timerconf := &api.TimersConfig{
- ConnectRetry: uint64(timer.Config.ConnectRetry),
- HoldTime: uint64(timer.Config.HoldTime),
- KeepaliveInterval: uint64(timer.Config.KeepaliveInterval),
- }
-
- timerstate := &api.TimersState{
- KeepaliveInterval: uint64(timer.State.KeepaliveInterval),
- NegotiatedHoldTime: uint64(timer.State.NegotiatedHoldTime),
- Uptime: uint64(uptime),
- Downtime: uint64(downtime),
- }
-
- apitimer := &api.Timers{
- Config: timerconf,
- State: timerstate,
- }
- msgrcv := &api.Message{
- NOTIFICATION: s.Messages.Received.Notification,
- UPDATE: s.Messages.Received.Update,
- OPEN: s.Messages.Received.Open,
- KEEPALIVE: s.Messages.Received.Keepalive,
- REFRESH: s.Messages.Received.Refresh,
- DISCARDED: s.Messages.Received.Discarded,
- TOTAL: s.Messages.Received.Total,
- }
- msgsnt := &api.Message{
- NOTIFICATION: s.Messages.Sent.Notification,
- UPDATE: s.Messages.Sent.Update,
- OPEN: s.Messages.Sent.Open,
- KEEPALIVE: s.Messages.Sent.Keepalive,
- REFRESH: s.Messages.Sent.Refresh,
- DISCARDED: s.Messages.Sent.Discarded,
- TOTAL: s.Messages.Sent.Total,
- }
- msg := &api.Messages{
- Received: msgrcv,
- Sent: msgsnt,
- }
- info := &api.PeerState{
- BgpState: f.state.String(),
- AdminState: f.adminState.String(),
- Messages: msg,
- Received: received,
- Accepted: accepted,
- Advertised: advertised,
- }
- rr := &api.RouteReflector{
- RouteReflectorClient: peer.fsm.pConf.RouteReflector.Config.RouteReflectorClient,
- RouteReflectorClusterId: string(peer.fsm.pConf.RouteReflector.Config.RouteReflectorClusterId),
- }
- rs := &api.RouteServer{
- RouteServerClient: peer.fsm.pConf.RouteServer.Config.RouteServerClient,
- }
+ conf.State.ReceivedOpenMessage, _ = peer.fsm.recvOpen.Serialize()
- return &api.Peer{
- Conf: conf,
- Info: info,
- Timers: apitimer,
- RouteReflector: rr,
- RouteServer: rs,
}
+ return &conf
}
func (peer *Peer) DropAll(rfList []bgp.RouteFamily) {
diff --git a/server/server.go b/server/server.go
index 05a1f295..0642619b 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1682,14 +1682,12 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) {
}
close(grpcReq.ResponseCh)
case REQ_NEIGHBOR:
- l := []*api.Peer{}
+ l := make([]*config.Neighbor, 0)
for _, peer := range server.neighborMap {
- l = append(l, peer.ToApiStruct())
+ l = append(l, peer.ToConfig())
}
grpcReq.ResponseCh <- &GrpcResponse{
- Data: &api.GetNeighborResponse{
- Peers: l,
- },
+ Data: l,
}
close(grpcReq.ResponseCh)
case REQ_ADJ_RIB_IN, REQ_ADJ_RIB_OUT: