diff options
-rw-r--r-- | packet/mrt.go | 6 | ||||
-rw-r--r-- | packet/mrt_test.go | 11 |
2 files changed, 17 insertions, 0 deletions
diff --git a/packet/mrt.go b/packet/mrt.go index 369e8063..b259be7f 100644 --- a/packet/mrt.go +++ b/packet/mrt.go @@ -21,6 +21,7 @@ import ( "fmt" "math" "net" + "time" ) const ( @@ -139,6 +140,11 @@ func NewMRTHeader(timestamp uint32, t MRTType, subtype MRTSubTyper, l uint32) (* }, nil } +func (h *MRTHeader) GetTime() time.Time { + t := int64(h.Timestamp) + return time.Unix(t, 0) +} + type MRTMessage struct { Header MRTHeader Body Body diff --git a/packet/mrt_test.go b/packet/mrt_test.go index c43d45e0..11a233ec 100644 --- a/packet/mrt_test.go +++ b/packet/mrt_test.go @@ -41,6 +41,17 @@ func TestMrtHdr(t *testing.T) { assert.Equal(t, reflect.DeepEqual(h1, h2), true) } +func TestMrtHdrTime(t *testing.T) { + h1, err := NewMRTHeader(10, TABLE_DUMPv2, RIB_IPV4_MULTICAST, 20) + if err != nil { + t.Fatal(err) + } + ttime := time.Unix(10, 0) + htime := h1.GetTime() + t.Logf("this timestamp should be 10s after epoch:%v", htime) + assert.Equal(t, h1.GetTime(), ttime) +} + func testPeer(t *testing.T, p1 *Peer) { b1, err := p1.Serialize() if err != nil { |