summaryrefslogtreecommitdiffhomepage
path: root/zebra/zapi_test.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-02-10 14:34:24 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-02-15 00:11:29 +0900
commit087ea7585069481bc0cf45f658698cc3ef9f5a3e (patch)
tree58dc04b7559c295655491a6cf47b804cf355ee5d /zebra/zapi_test.go
parent0e53acd88f3389d4dbade900abe783ae68faf292 (diff)
zebra/zapi: Support NEXTHOP_UPDATE message
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'zebra/zapi_test.go')
-rw-r--r--zebra/zapi_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/zebra/zapi_test.go b/zebra/zapi_test.go
index ac4862f0..7d0fe29b 100644
--- a/zebra/zapi_test.go
+++ b/zebra/zapi_test.go
@@ -19,6 +19,7 @@ import (
"encoding/binary"
"github.com/stretchr/testify/assert"
"net"
+ "syscall"
"testing"
)
@@ -450,3 +451,35 @@ func Test_ImportLookupBody(t *testing.T) {
err = b.DecodeFromBytes(buf, 2)
assert.NotEqual(nil, err)
}
+
+func Test_NexthopUpdateBody(t *testing.T) {
+ assert := assert.New(t)
+
+ // Input binary
+ bufIn := []byte{
+ 0x00, 0x02, 0x20, // afi(2 bytes)=AF_INET, prefix_len(1 byte)=32
+ 0xc0, 0xa8, 0x01, 0x01, // prefix(4 bytes)="192.168.1.1"
+ 0x00, 0x00, 0x00, 0x01, // metric(4 bytes)=1
+ 0x01, // nexthops(1 byte)=1
+ 0x04, // nexthop_type(1 byte)=NEXTHOP_IPV4_IFINDEX
+ 0xc0, 0xa8, 0x01, 0x01, // nexthop_ip(4 bytes)="192.168.0.1"
+ 0x00, 0x00, 0x00, 0x02, // nexthop_ifindex(4 byte)=2
+ }
+
+ // Test DecodeFromBytes()
+ b := &NexthopUpdateBody{Api: NEXTHOP_UPDATE}
+ err := b.DecodeFromBytes(bufIn, 2)
+ assert.Nil(err)
+
+ // Test decoded values
+ assert.Equal(uint16(syscall.AF_INET), b.Family)
+ assert.Equal(net.ParseIP("192.168.1.1").To4(), b.Prefix)
+ assert.Equal(uint32(1), b.Metric)
+ nexthop := &Nexthop{
+ Type: NEXTHOP_FLAG(NEXTHOP_IPV4_IFINDEX),
+ Addr: net.ParseIP("192.168.1.1").To4(),
+ Ifindex: uint32(2),
+ }
+ assert.Equal(1, len(b.Nexthops))
+ assert.Equal(nexthop, b.Nexthops[0])
+}