diff options
-rw-r--r-- | api/grpc_server.go | 13 | ||||
-rw-r--r-- | config/bgp_configs.go | 48 | ||||
-rw-r--r-- | server/peer.go | 23 | ||||
-rw-r--r-- | tools/pyang_plugins/bgpyang2golang.py | 9 | ||||
-rw-r--r-- | tools/pyang_plugins/gobgp.yang | 21 |
5 files changed, 50 insertions, 64 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go index af16dccf..3ccfa4cc 100644 --- a/api/grpc_server.go +++ b/api/grpc_server.go @@ -107,6 +107,15 @@ func (s *Server) GetNeighbor(ctx context.Context, arg *GetNeighborRequest) (*Get if pconf.Transport.State.LocalAddress != "" { localAddress = pconf.Transport.State.LocalAddress } + var remoteCap, localCap [][]byte + for _, cap := range pconf.State.RemoteCapabilityList { + c, _ := cap.Serialize() + remoteCap = append(remoteCap, c) + } + for _, cap := range pconf.State.LocalCapabilityList { + c, _ := cap.Serialize() + localCap = append(localCap, c) + } return &Peer{ Conf: &PeerConf{ NeighborAddress: pconf.Config.NeighborAddress, @@ -120,8 +129,8 @@ func (s *Server) GetNeighbor(ctx context.Context, arg *GetNeighborRequest) (*Get SendCommunity: uint32(pconf.Config.SendCommunity.ToInt()), Description: pconf.Config.Description, PeerGroup: pconf.Config.PeerGroup, - RemoteCap: s.Capabilities.RemoteList, - LocalCap: s.Capabilities.LocalList, + RemoteCap: remoteCap, + LocalCap: localCap, PrefixLimits: prefixLimits, LocalAddress: localAddress, NeighborInterface: pconf.Config.NeighborInterface, diff --git a/config/bgp_configs.go b/config/bgp_configs.go index c9e2a9c0..ea0e6549 100644 --- a/config/bgp_configs.go +++ b/config/bgp_configs.go @@ -19,8 +19,9 @@ package config import ( - "bytes" "fmt" + + "github.com/osrg/gobgp/packet/bgp" ) func mapkey(index int, name string) string { @@ -1996,39 +1997,6 @@ func (lhs *Timers) Equal(rhs *Timers) bool { return true } -//struct for container gobgp:Capabilities -type Capabilities struct { - // original -> gobgp:remote - // original type is list of binary - RemoteList [][]byte `mapstructure:"remote-list"` - // original -> gobgp:local - // original type is list of binary - LocalList [][]byte `mapstructure:"local-list"` -} - -func (lhs *Capabilities) Equal(rhs *Capabilities) bool { - if lhs == nil || rhs == nil { - return false - } - if len(lhs.RemoteList) != len(rhs.RemoteList) { - return false - } - for idx, l := range lhs.RemoteList { - if bytes.Compare(l, rhs.RemoteList[idx]) != 0 { - return false - } - } - if len(lhs.LocalList) != len(rhs.LocalList) { - return false - } - for idx, l := range lhs.LocalList { - if bytes.Compare(l, rhs.LocalList[idx]) != 0 { - return false - } - } - return true -} - //struct for container gobgp:adj-table type AdjTable struct { // original -> gobgp:ADVERTISED @@ -2235,11 +2203,15 @@ type NeighborState struct { Queues Queues `mapstructure:"queues"` // original -> gobgp:adj-table AdjTable AdjTable `mapstructure:"adj-table"` - // original -> gobgp:Capabilities - Capabilities Capabilities `mapstructure:"capabilities"` + // original -> gobgp:remote-capability + // original type is list of bgp-capability + RemoteCapabilityList []bgp.ParameterCapabilityInterface `mapstructure:"remote-capability-list"` + // original -> gobgp:local-capability + // original type is list of bgp-capability + LocalCapabilityList []bgp.ParameterCapabilityInterface `mapstructure:"local-capability-list"` // original -> gobgp:received-open-message - //gobgp:received-open-message's original type is binary - ReceivedOpenMessage []byte `mapstructure:"received-open-message"` + //gobgp:received-open-message's original type is bgp-open-message + ReceivedOpenMessage *bgp.BGPMessage `mapstructure:"received-open-message"` // original -> gobgp:admin-down //gobgp:admin-down's original type is boolean AdminDown bool `mapstructure:"admin-down"` diff --git a/server/peer.go b/server/peer.go index eaf1e4ac..e7fa290b 100644 --- a/server/peer.go +++ b/server/peer.go @@ -511,22 +511,17 @@ func (peer *Peer) ToConfig() *config.Neighbor { conf.AfiSafis[i] = peer.fsm.pConf.AfiSafis[i] } - remoteCap := make([][]byte, 0, len(peer.fsm.capMap)) + remoteCap := make([]bgp.ParameterCapabilityInterface, 0, len(peer.fsm.capMap)) for _, c := range peer.fsm.capMap { for _, m := range c { + // need to copy all values here buf, _ := m.Serialize() - remoteCap = append(remoteCap, buf) + cap, _ := bgp.DecodeCapability(buf) + remoteCap = append(remoteCap, cap) } } - conf.State.Capabilities.RemoteList = remoteCap - - caps := capabilitiesFromConfig(peer.fsm.pConf) - localCap := make([][]byte, 0, len(caps)) - for _, c := range caps { - buf, _ := c.Serialize() - localCap = append(localCap, buf) - } - conf.State.Capabilities.LocalList = localCap + conf.State.RemoteCapabilityList = remoteCap + conf.State.LocalCapabilityList = capabilitiesFromConfig(peer.fsm.pConf) conf.State.RemoteRouterId = peer.fsm.peerInfo.ID.To4().String() conf.State.SessionState = config.IntToSessionStateMap[int(peer.fsm.state)] @@ -541,9 +536,9 @@ func (peer *Peer) ToConfig() *config.Neighbor { conf.Transport.State.LocalAddress, conf.Transport.State.LocalPort = peer.fsm.LocalHostPort() _, conf.Transport.State.RemotePort = peer.fsm.RemoteHostPort() - - conf.State.ReceivedOpenMessage, _ = peer.fsm.recvOpen.Serialize() - + buf, _ := peer.fsm.recvOpen.Serialize() + // need to copy all values here + conf.State.ReceivedOpenMessage, _ = bgp.ParseBGPMessage(buf) } return &conf } diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py index 9f131df0..5be6569f 100644 --- a/tools/pyang_plugins/bgpyang2golang.py +++ b/tools/pyang_plugins/bgpyang2golang.py @@ -665,6 +665,8 @@ _type_translation_map = { 'yang:timeticks': 'int64', 'ptypes:install-protocol-type': 'string', 'binary': '[]byte', + 'bgp-capability': 'bgp.ParameterCapabilityInterface', + 'bgp-open-message': '*bgp.BGPMessage', } @@ -690,7 +692,9 @@ _path_exclude = ["/rpol:routing-policy/rpol:defined-sets/rpol:neighbor-sets/rpol "/rpol:routing-policy/rpol:defined-sets/bgp-pol:bgp-defined-sets/bgp-pol:ext-community-sets/bgp-pol:ext-community-set/bgp-pol:ext-community-member", "/rpol:routing-policy/rpol:defined-sets/bgp-pol:bgp-defined-sets/bgp-pol:as-path-sets/bgp-pol:as-path-set/bgp-pol:as-path-set-member"] -_typedef_exclude =[] +_typedef_exclude =["/gobgp:bgp-capability", + "/gobgp:bgp-open-message"] + def generate_header(ctx): print _COPYRIGHT_NOTICE @@ -698,7 +702,8 @@ def generate_header(ctx): print '' print 'import (' print '"fmt"' - print '"bytes"' + print '' + print '"github.com/osrg/gobgp/packet/bgp"' print ')' print '' diff --git a/tools/pyang_plugins/gobgp.yang b/tools/pyang_plugins/gobgp.yang index 6729349d..06b545af 100644 --- a/tools/pyang_plugins/gobgp.yang +++ b/tools/pyang_plugins/gobgp.yang @@ -631,19 +631,24 @@ module gobgp { uses gobgp-adjacent-table; } + typedef bgp-capability { + type uint8; + } + + typedef bgp-open-message { + type uint8; + } augment "/bgp:bgp/bgp:neighbors/bgp:neighbor/bgp:state" { - container Capabilities { - leaf-list remote { - type binary; - } - leaf-list local { - type binary; - } + leaf-list remote-capability { + type bgp-capability; + } + leaf-list local-capability { + type bgp-capability; } leaf received-open-message { - type binary; + type bgp-open-message; } } |