Skip to content

Commit

Permalink
rpki: support show the state of RPKI servers
Browse files Browse the repository at this point in the history
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
  • Loading branch information
fujita committed Aug 31, 2015
1 parent 70a8399 commit 955409c
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 67 deletions.
115 changes: 110 additions & 5 deletions api/gobgp.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion api/gobgp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ service Grpc {
rpc MonitorBestChanged(Arguments) returns (stream Destination) {}
rpc MonitorPeerState(Arguments) returns (stream Peer) {}
rpc GetMrt(MrtArguments) returns (stream MrtMessage) {}
rpc GetRPKI(Arguments) returns (stream ROA) {}
rpc GetRPKI(Arguments) returns (stream RPKI) {}
rpc GetROA(Arguments) returns (stream ROA) {}
rpc GetVrfs(Arguments) returns (stream Vrf) {}
rpc ModVrf(ModVrfArguments) returns (Error) {}
}
Expand Down Expand Up @@ -295,6 +296,22 @@ message MrtMessage {
bytes data = 1;
}

message RPKIConf {
string address = 1;
}

message RPKIState {
int64 uptime = 1;
int64 downtime = 2;
int32 received_ipv4 = 3;
int32 received_ipv6 = 4;
}

message RPKI {
RPKIConf conf = 1;
RPKIState state = 2;
}

message ROA {
uint32 as = 1;
uint32 prefixlen = 2;
Expand Down
14 changes: 8 additions & 6 deletions docs/sources/rpki.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,28 @@ and get the ROA (Route Origin Authorization) information in the
following way:

```bash
$ gobgp rpki|head -n4
$ gobgp rpki server
Session State Uptime #IPv4/IPv6 records
210.173.170.254 Up 00:03:06 14823/2168
```

```bash
$ gobgp rpki table 210.173.170.254|head -n4
Network Maxlen AS
2.0.0.0/12 16 3215
2.0.0.0/16 16 3215
2.1.0.0/16 16 3215
$ gobgp rpki |wc -l
14576
```

By default, IPv4's ROA information is shown. You can see IPv6's like:

```bash
$ gobgp rpki -a ipv6|head -n4
$ gobgp rpki -a ipv6 table 210.173.170.254|head -n4
fujita@ubuntu:~$ gobgp rpki -a ipv6|head -n3
Network Maxlen AS
2001:608::/32 32 5539
2001:610::/32 48 1103
2001:610:240::/42 42 3333
$ gobgp rpki -a ipv6|wc -l
2150
```

We configure the peer 10.0.255.1 to send three routes:
Expand Down
2 changes: 2 additions & 0 deletions gobgp/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const (
CMD_DUMP = "dump"
CMD_INJECT = "inject"
CMD_RPKI = "rpki"
CMD_RPKI_TABLE = "table"
CMD_RPKI_SERVER = "server"
CMD_VRF = "vrf"
)

Expand Down
4 changes: 2 additions & 2 deletions gobgp/mrt.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ func injectMrt(r string, filename string, count int) error {
ch <- &api.ModPathArguments{
Resource: resource,
Path: path,
Asn: peers[e.PeerIndex].AS,
Id: peers[e.PeerIndex].BgpId.String(),
Asn: peers[e.PeerIndex].AS,
Id: peers[e.PeerIndex].BgpId.String(),
}
}

Expand Down
51 changes: 48 additions & 3 deletions gobgp/rpki.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,48 @@ import (
"io"
"net"
"os"
"time"
)

func showRPKIServer(args []string) error {
arg := &api.Arguments{}

stream, err := client.GetRPKI(context.Background(), arg)
if err != nil {
fmt.Println(err)
return err
}
format := "%-18s %-6s %-10s %s\n"
fmt.Printf(format, "Session", "State", "Uptime", "#IPv4/IPv6 records")
for {
r, err := stream.Recv()
if err == io.EOF {
break
} else if err != nil {
return err
}
s := "Up"
uptime := int64(time.Now().Sub(time.Unix(r.State.Uptime, 0)).Seconds())

fmt.Printf(format, fmt.Sprintf(r.Conf.Address), s, fmt.Sprint(formatTimedelta(uptime)), fmt.Sprintf("%d/%d", r.State.ReceivedIpv4, r.State.ReceivedIpv6))
}
return nil
}

func showRPKITable(args []string) error {
if len(args) == 0 {
return fmt.Errorf("Needs to specify RPKI server address")
}
rf, err := checkAddressFamily(net.IP{})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
arg := &api.Arguments{
Rf: uint32(rf),
Rf: uint32(rf),
Name: args[0],
}
stream, err := client.GetRPKI(context.Background(), arg)
stream, err := client.GetROA(context.Background(), arg)
if err != nil {
fmt.Println(err)
return err
Expand Down Expand Up @@ -64,10 +94,25 @@ func showRPKITable(args []string) error {
func NewRPKICmd() *cobra.Command {
rpkiCmd := &cobra.Command{
Use: CMD_RPKI,
}

serverCmd := &cobra.Command{
Use: CMD_RPKI_SERVER,
Run: func(cmd *cobra.Command, args []string) {
showRPKIServer(args)
},
}

rpkiCmd.AddCommand(serverCmd)

tableCmd := &cobra.Command{
Use: CMD_RPKI_TABLE,
Run: func(cmd *cobra.Command, args []string) {
showRPKITable(args)
},
}
rpkiCmd.PersistentFlags().StringVarP(&subOpts.AddressFamily, "address-family", "a", "", "address family")
tableCmd.PersistentFlags().StringVarP(&subOpts.AddressFamily, "address-family", "a", "", "address family")

rpkiCmd.AddCommand(tableCmd)
return rpkiCmd
}
10 changes: 10 additions & 0 deletions server/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const (
REQ_MRT_GLOBAL_RIB
REQ_MRT_LOCAL_RIB
REQ_RPKI
REQ_ROA
REQ_VRF
REQ_VRFS
REQ_VRF_MOD
Expand Down Expand Up @@ -512,6 +513,15 @@ func (s *Server) GetRPKI(arg *api.Arguments, stream api.Grpc_GetRPKIServer) erro
req := NewGrpcRequest(REQ_RPKI, "", bgp.RouteFamily(arg.Rf), nil)
s.bgpServerCh <- req

return handleMultipleResponses(req, func(res *GrpcResponse) error {
return stream.Send(res.Data.(*api.RPKI))
})
}

func (s *Server) GetROA(arg *api.Arguments, stream api.Grpc_GetROAServer) error {
req := NewGrpcRequest(REQ_ROA, arg.Name, bgp.RouteFamily(arg.Rf), nil)
s.bgpServerCh <- req

return handleMultipleResponses(req, func(res *GrpcResponse) error {
return stream.Send(res.Data.(*api.ROA))
})
Expand Down
Loading

0 comments on commit 955409c

Please sign in to comment.