diff options
author | dsp <dsp@2f30.org> | 2015-08-27 12:12:15 -0600 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-28 05:32:32 +0900 |
commit | f1ee03afe3b7bfd49e3f238b08031d2c35c2395f (patch) | |
tree | 2c1116fbfab9dc1837b3ab8e7f5d9d13f123fb7a /packet | |
parent | 8ef1f381b07d04a38597f1fd5587cc1d377433cf (diff) |
mrt: add helper function for timestamp
Commiting helper function on MRTHeader to return a golang time.Time
from the timestamp. Also commiting the relevant test function.
Diffstat (limited to 'packet')
-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 { |