summaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-11-16 10:06:47 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-11-16 12:23:18 +0900
commitc1bca2555919f9f2a7dd9d13dc3e14a4bf6a589a (patch)
tree3a19cc12f27f146df079e03a487acea492e8d595 /cmd
parent893dbd5c074c097f0c9921d3131a072011fb7e6a (diff)
use google/protobuf/timestamp.proto
use google/protobuf/timestamp.proto instead of our own way to represent time. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gobgp/common.go3
-rw-r--r--cmd/gobgp/neighbor.go19
-rw-r--r--cmd/gobgp/rpki.go5
3 files changed, 15 insertions, 12 deletions
diff --git a/cmd/gobgp/common.go b/cmd/gobgp/common.go
index 709c4efb..8fa31fc8 100644
--- a/cmd/gobgp/common.go
+++ b/cmd/gobgp/common.go
@@ -108,7 +108,8 @@ var bmpOpts struct {
StatisticsTimeout int `short:"s" long:"statistics-timeout" description:"Interval for Statistics Report"`
}
-func formatTimedelta(d int64) string {
+func formatTimedelta(t time.Time) string {
+ d := time.Now().Unix() - t.Unix()
u := uint64(d)
neg := d < 0
if neg {
diff --git a/cmd/gobgp/neighbor.go b/cmd/gobgp/neighbor.go
index d0499950..c7400f50 100644
--- a/cmd/gobgp/neighbor.go
+++ b/cmd/gobgp/neighbor.go
@@ -26,6 +26,7 @@ import (
"strings"
"time"
+ "github.com/golang/protobuf/ptypes"
"github.com/spf13/cobra"
api "github.com/osrg/gobgp/api"
@@ -133,7 +134,6 @@ func showNeighbors(vrf string) error {
return strings.Less(0, 1)
})
- now := time.Now()
for _, n := range m {
if i := len(n.Conf.NeighborInterface); i > maxaddrlen {
maxaddrlen = i
@@ -144,12 +144,12 @@ func showNeighbors(vrf string) error {
maxaslen = l
}
timeStr := "never"
- if n.Timers.State.Uptime != 0 {
- t := int64(n.Timers.State.Downtime)
+ if n.Timers.State.Uptime != nil {
+ t, _ := ptypes.Timestamp(n.Timers.State.Downtime)
if n.State.SessionState == api.PeerState_ESTABLISHED {
- t = int64(n.Timers.State.Uptime)
+ t, _ = ptypes.Timestamp(n.Timers.State.Uptime)
}
- timeStr = formatTimedelta(int64(now.Sub(time.Unix(int64(t), 0)).Seconds()))
+ timeStr = formatTimedelta(t)
}
if len(timeStr) > maxtimelen {
maxtimelen = len(timeStr)
@@ -236,8 +236,9 @@ func showNeighbor(args []string) error {
}
fmt.Printf(" BGP version 4, remote router ID %s\n", id)
fmt.Printf(" BGP state = %s", p.State.SessionState)
- if p.Timers.State.Uptime > 0 {
- fmt.Printf(", up for %s\n", formatTimedelta(int64(p.Timers.State.Uptime)-time.Now().Unix()))
+ if p.Timers.State.Uptime != nil {
+ t, _ := ptypes.Timestamp(p.Timers.State.Uptime)
+ fmt.Printf(", up for %s\n", formatTimedelta(t))
} else {
fmt.Print("\n")
}
@@ -564,8 +565,8 @@ func makeShowRouteArgs(p *api.Path, idx int, now time.Time, showAge, showBest, s
// Age
if showAge {
- t := time.Unix(p.Age, 0)
- args = append(args, formatTimedelta(int64(now.Sub(t).Seconds())))
+ t, _ := ptypes.Timestamp(p.Age)
+ args = append(args, formatTimedelta(t))
}
// Path Attributes
diff --git a/cmd/gobgp/rpki.go b/cmd/gobgp/rpki.go
index a2caf72a..c5da682f 100644
--- a/cmd/gobgp/rpki.go
+++ b/cmd/gobgp/rpki.go
@@ -20,8 +20,8 @@ import (
"io"
"net"
"strconv"
- "time"
+ "github.com/golang/protobuf/ptypes"
api "github.com/osrg/gobgp/api"
"github.com/spf13/cobra"
)
@@ -50,7 +50,8 @@ func showRPKIServer(args []string) error {
uptime := "never"
if r.State.Up {
s = "Up"
- uptime = fmt.Sprint(formatTimedelta(int64(time.Since(time.Unix(r.State.Uptime, 0)).Seconds())))
+ t, _ := ptypes.Timestamp(r.State.Uptime)
+ uptime = fmt.Sprint(formatTimedelta(t))
}
fmt.Printf(format, net.JoinHostPort(r.Conf.Address, fmt.Sprintf("%d", r.Conf.RemotePort)), s, uptime, fmt.Sprintf("%d/%d", r.State.RecordIpv4, r.State.RecordIpv6))