diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-20 02:52:59 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-20 02:52:59 +0900 |
commit | b6e606a99480cffd47e73e7b74aa3a10df5ad47d (patch) | |
tree | ad34613d89ea3316271ff6c2f82caff804ff9c81 /server/peer.go | |
parent | 49e45d4e0c0a81dc8f9ec4b3a39433b22af04f16 (diff) |
remove gRPC dependency from peer.go
move gRPC dependency from peer.go to grpc_server.go
Preparation for the removal of gRPC dependency from packages except
for api package.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/peer.go')
-rw-r--r-- | server/peer.go | 138 |
1 files changed, 21 insertions, 117 deletions
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) { |