MCPcopy
hub / github.com/osrg/gobgp / Test_importLookupBody

Function Test_importLookupBody

pkg/zebra/zapi_test.go:902–946  ·  view source on GitHub ↗

ImportLookup exists in only quagga (zebra API version 2 and 3)

(t *testing.T)

Source from the content-addressed store, hash-verified

900
901// ImportLookup exists in only quagga (zebra API version 2 and 3)
902func Test_importLookupBody(t *testing.T) {
903 assert := assert.New(t)
904
905 // decodeFromBytes
906 pos := 0
907 buf := make([]byte, 18)
908 ip := net.ParseIP("192.168.50.0").To4()
909 copy(buf[:4], []byte(ip))
910 pos += 4
911 binary.BigEndian.PutUint32(buf[pos:], 10)
912 pos += 4
913 buf[pos] = byte(1)
914 pos++
915 buf[pos] = byte(4)
916 pos++
917 ip = net.ParseIP("172.16.1.101").To4()
918 copy(buf[pos:pos+4], []byte(ip))
919 pos += 4
920 binary.BigEndian.PutUint32(buf[pos:], 3)
921
922 b := &lookupBody{api: zapi3IPv4ImportLookup}
923 v := uint8(2)
924 software := NewSoftware(v, "")
925 err := b.decodeFromBytes(buf, v, software)
926 assert.NoError(err)
927 assert.Equal("192.168.50.0", b.addr.String())
928 assert.Equal(uint32(10), b.metric)
929 assert.Equal(uint32(3), b.nexthops[0].Ifindex)
930 assert.Equal(nexthopType(4), b.nexthops[0].Type)
931 assert.Equal("172.16.1.101", b.nexthops[0].Gate.String())
932
933 // serialize
934 b.prefixLength = uint8(24)
935 buf, err = b.serialize(v, software)
936 ip = net.ParseIP("192.168.50.0").To4()
937 assert.NoError(err)
938 assert.Equal(uint8(24), buf[0])
939 assert.Equal([]byte(ip)[:4], buf[1:5])
940
941 // length invalid
942 buf = make([]byte, 3)
943 b = &lookupBody{api: zapi3IPv4ImportLookup}
944 err = b.decodeFromBytes(buf, v, software)
945 assert.NotNil(err)
946}
947
948func Test_NexthopRegisterBody(t *testing.T) {
949 assert := assert.New(t)

Callers

nothing calls this directly

Calls 6

decodeFromBytesMethod · 0.95
serializeMethod · 0.95
NewSoftwareFunction · 0.85
nexthopTypeTypeAlias · 0.85
StringMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…