summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--config/bgp_configs.go31
-rw-r--r--server/grpc_server.go65
-rw-r--r--server/rpki.go88
-rw-r--r--tools/pyang_plugins/gobgp.yang18
4 files changed, 132 insertions, 70 deletions
diff --git a/config/bgp_configs.go b/config/bgp_configs.go
index 36a51da5..44afcb82 100644
--- a/config/bgp_configs.go
+++ b/config/bgp_configs.go
@@ -1210,6 +1210,19 @@ func (lhs *RpkiMessages) Equal(rhs *RpkiMessages) bool {
//struct for container gobgp:state
type RpkiServerState struct {
+ // original -> gobgp:up
+ //gobgp:up's original type is boolean
+ Up bool `mapstructure:"up"`
+ // original -> gobgp:serial-number
+ SerialNumber uint32 `mapstructure:"serial-number"`
+ // original -> gobgp:records-v4
+ RecordsV4 uint32 `mapstructure:"records-v4"`
+ // original -> gobgp:records-v6
+ RecordsV6 uint32 `mapstructure:"records-v6"`
+ // original -> gobgp:prefixes-v4
+ PrefixesV4 uint32 `mapstructure:"prefixes-v4"`
+ // original -> gobgp:prefixes-v6
+ PrefixesV6 uint32 `mapstructure:"prefixes-v6"`
// original -> gobgp:uptime
Uptime int64 `mapstructure:"uptime"`
// original -> gobgp:downtime
@@ -1224,6 +1237,24 @@ func (lhs *RpkiServerState) Equal(rhs *RpkiServerState) bool {
if lhs == nil || rhs == nil {
return false
}
+ if lhs.Up != rhs.Up {
+ return false
+ }
+ if lhs.SerialNumber != rhs.SerialNumber {
+ return false
+ }
+ if lhs.RecordsV4 != rhs.RecordsV4 {
+ return false
+ }
+ if lhs.RecordsV6 != rhs.RecordsV6 {
+ return false
+ }
+ if lhs.PrefixesV4 != rhs.PrefixesV4 {
+ return false
+ }
+ if lhs.PrefixesV6 != rhs.PrefixesV6 {
+ return false
+ }
if lhs.Uptime != rhs.Uptime {
return false
}
diff --git a/server/grpc_server.go b/server/grpc_server.go
index 64a7f839..69313092 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -485,23 +485,64 @@ func (s *Server) SoftResetRpki(ctx context.Context, arg *api.SoftResetRpkiReques
}
func (s *Server) GetRpki(ctx context.Context, arg *api.GetRpkiRequest) (*api.GetRpkiResponse, error) {
- req := NewGrpcRequest(REQ_GET_RPKI, "", bgp.RouteFamily(arg.Family), nil)
- s.bgpServerCh <- req
- res := <-req.ResponseCh
- if res.Err() != nil {
- return nil, res.Err()
+ d, err := s.get(REQ_GET_RPKI, arg)
+ if err != nil {
+ return nil, err
+ }
+ l := make([]*api.Rpki, 0)
+ for _, s := range d.([]*config.RpkiServer) {
+ received := &s.State.RpkiMessages.RpkiReceived
+ sent := &s.State.RpkiMessages.RpkiSent
+ rpki := &api.Rpki{
+ Conf: &api.RPKIConf{
+ Address: s.Config.Address,
+ RemotePort: strconv.Itoa(int(s.Config.Port)),
+ },
+ State: &api.RPKIState{
+ Uptime: s.State.Uptime,
+ Downtime: s.State.Downtime,
+ Up: s.State.Up,
+ RecordIpv4: s.State.RecordsV4,
+ RecordIpv6: s.State.RecordsV6,
+ PrefixIpv4: s.State.PrefixesV4,
+ PrefixIpv6: s.State.PrefixesV6,
+ Serial: s.State.SerialNumber,
+ ReceivedIpv4: received.Ipv4Prefix,
+ ReceivedIpv6: received.Ipv6Prefix,
+ SerialNotify: received.SerialNotify,
+ CacheReset: received.CacheReset,
+ CacheResponse: received.CacheResponse,
+ EndOfData: received.EndOfData,
+ Error: received.Error,
+ SerialQuery: sent.SerialQuery,
+ ResetQuery: sent.ResetQuery,
+ },
+ }
+ l = append(l, rpki)
}
- return res.Data.(*api.GetRpkiResponse), res.Err()
+ return &api.GetRpkiResponse{Servers: l}, nil
}
func (s *Server) GetRoa(ctx context.Context, arg *api.GetRoaRequest) (*api.GetRoaResponse, error) {
- req := NewGrpcRequest(REQ_ROA, "", bgp.RouteFamily(arg.Family), nil)
- s.bgpServerCh <- req
- res := <-req.ResponseCh
- if res.Err() != nil {
- return nil, res.Err()
+ d, err := s.get(REQ_ROA, arg)
+ if err != nil {
+ return nil, err
+ }
+ l := make([]*api.Roa, 0, len(d.([]*ROA)))
+ for _, r := range d.([]*ROA) {
+ host, port, _ := net.SplitHostPort(r.Src)
+ l = append(l, &api.Roa{
+ As: r.AS,
+ Maxlen: uint32(r.MaxLen),
+ Prefixlen: uint32(r.Prefix.Length),
+ Prefix: r.Prefix.Prefix.String(),
+ Conf: &api.RPKIConf{
+ Address: host,
+ RemotePort: port,
+ },
+ })
}
- return res.Data.(*api.GetRoaResponse), res.Err()
+ return &api.GetRoaResponse{Roas: l}, nil
}
func (s *Server) GetVrf(ctx context.Context, arg *api.GetVrfRequest) (*api.GetVrfResponse, error) {
diff --git a/server/rpki.go b/server/rpki.go
index 1463fd9b..fb675314 100644
--- a/server/rpki.go
+++ b/server/rpki.go
@@ -21,11 +21,11 @@ import (
"io"
"net"
"sort"
+ "strconv"
"time"
log "github.com/Sirupsen/logrus"
"github.com/armon/go-radix"
- api "github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet/bgp"
"github.com/osrg/gobgp/packet/rtr"
@@ -77,21 +77,7 @@ func (r *ROA) Equal(roa *ROA) bool {
return false
}
-func (r *ROA) toApiStruct() *api.Roa {
- host, port, _ := net.SplitHostPort(r.Src)
- return &api.Roa{
- As: r.AS,
- Maxlen: uint32(r.MaxLen),
- Prefixlen: uint32(r.Prefix.Length),
- Prefix: r.Prefix.Prefix.String(),
- Conf: &api.RPKIConf{
- Address: host,
- RemotePort: port,
- },
- }
-}
-
-type roas []*api.Roa
+type roas []*ROA
func (r roas) Len() int {
return len(r)
@@ -105,13 +91,13 @@ func (r roas) Less(i, j int) bool {
r1 := r[i]
r2 := r[j]
- if r1.Maxlen < r1.Maxlen {
+ if r1.MaxLen < r1.MaxLen {
return true
- } else if r1.Maxlen > r1.Maxlen {
+ } else if r1.MaxLen > r1.MaxLen {
return false
}
- if r1.As < r2.As {
+ if r1.AS < r2.AS {
return true
}
return false
@@ -465,57 +451,43 @@ func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) *GrpcResponse {
recordsV4, prefixesV4 := f(c.Roas[bgp.RF_IPv4_UC])
recordsV6, prefixesV6 := f(c.Roas[bgp.RF_IPv6_UC])
- l := make([]*api.Rpki, 0, len(c.clientMap))
+ l := make([]*config.RpkiServer, 0, len(c.clientMap))
for _, client := range c.clientMap {
- state := client.state
+ state := &client.state
+
addr, port, _ := net.SplitHostPort(client.host)
- received := &state.RpkiMessages.RpkiReceived
- sent := client.state.RpkiMessages.RpkiSent
- up := true
+ l = append(l, &config.RpkiServer{
+ Config: config.RpkiServerConfig{
+ Address: addr,
+ Port: func() uint32 { p, _ := strconv.Atoi(port); return uint32(p) }(),
+ },
+ State: client.state,
+ })
+
if client.conn == nil {
- up = false
+ state.Up = false
+ } else {
+ state.Up = true
}
-
f := func(m map[string]uint32, key string) uint32 {
if r, ok := m[key]; ok {
return r
}
return 0
}
-
- rpki := &api.Rpki{
- Conf: &api.RPKIConf{
- Address: addr,
- RemotePort: port,
- },
- State: &api.RPKIState{
- Uptime: state.Uptime,
- Downtime: state.Downtime,
- Up: up,
- RecordIpv4: f(recordsV4, client.host),
- RecordIpv6: f(recordsV6, client.host),
- PrefixIpv4: f(prefixesV4, client.host),
- PrefixIpv6: f(prefixesV6, client.host),
- Serial: client.serialNumber,
- ReceivedIpv4: received.Ipv4Prefix,
- ReceivedIpv6: received.Ipv6Prefix,
- SerialNotify: received.SerialNotify,
- CacheReset: received.CacheReset,
- CacheResponse: received.CacheResponse,
- EndOfData: received.EndOfData,
- Error: received.Error,
- SerialQuery: sent.SerialQuery,
- ResetQuery: sent.ResetQuery,
- },
- }
- l = append(l, rpki)
+ state.RecordsV4 = f(recordsV4, client.host)
+ state.RecordsV6 = f(recordsV6, client.host)
+ state.PrefixesV4 = f(prefixesV4, client.host)
+ state.PrefixesV6 = f(prefixesV6, client.host)
+ state.SerialNumber = client.serialNumber
+ }
+ return &GrpcResponse{
+ Data: l,
}
- return &GrpcResponse{Data: &api.GetRpkiResponse{Servers: l}}
case REQ_ROA:
if len(c.clientMap) == 0 {
return &GrpcResponse{
ResponseErr: fmt.Errorf("RPKI server isn't configured."),
- Data: &api.GetRoaResponse{},
}
}
var rfList []bgp.RouteFamily
@@ -527,14 +499,14 @@ func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) *GrpcResponse {
default:
rfList = []bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC}
}
- l := make([]*api.Roa, 0)
+ l := make([]*ROA, 0)
for _, rf := range rfList {
if tree, ok := c.Roas[rf]; ok {
tree.Walk(func(s string, v interface{}) bool {
b, _ := v.(*roaBucket)
var roaList roas
for _, r := range b.entries {
- roaList = append(roaList, r.toApiStruct())
+ roaList = append(roaList, r)
}
sort.Sort(roaList)
for _, roa := range roaList {
@@ -544,7 +516,7 @@ func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) *GrpcResponse {
})
}
}
- return &GrpcResponse{Data: &api.GetRoaResponse{Roas: l}}
+ return &GrpcResponse{Data: l}
}
return nil
}
diff --git a/tools/pyang_plugins/gobgp.yang b/tools/pyang_plugins/gobgp.yang
index 9ccf1d4f..ee158866 100644
--- a/tools/pyang_plugins/gobgp.yang
+++ b/tools/pyang_plugins/gobgp.yang
@@ -412,6 +412,24 @@ module gobgp {
grouping gobgp-rpki-server-state {
description "additional RPKI state";
+ leaf up {
+ type boolean;
+ }
+ leaf serial-number {
+ type uint32;
+ }
+ leaf records-v4 {
+ type uint32;
+ }
+ leaf records-v6 {
+ type uint32;
+ }
+ leaf prefixes-v4 {
+ type uint32;
+ }
+ leaf prefixes-v6 {
+ type uint32;
+ }
leaf uptime {
type int64;
description