test parse ext. communities form openbgpd
This commit is contained in:
parent
11e1508a16
commit
8b4b14b7a9
@ -243,11 +243,13 @@ func decodeExtendedCommunities(c interface{}) api.ExtCommunities {
|
|||||||
for _, com := range details {
|
for _, com := range details {
|
||||||
tokens := strings.SplitN(com, " ", 2)
|
tokens := strings.SplitN(com, " ", 2)
|
||||||
if len(tokens) != 2 {
|
if len(tokens) != 2 {
|
||||||
|
log.Println("can not decode ext. community:", com)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
nums := decoders.IntListFromStrings(
|
nums := decoders.IntListFromStrings(
|
||||||
strings.SplitN(tokens[1], ":", 2))
|
strings.SplitN(tokens[1], ":", 2))
|
||||||
if len(nums) != 2 {
|
if len(nums) != 2 {
|
||||||
|
log.Println("can not decode ext. community:", com)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
comms = append(comms, []interface{}{tokens[0], nums[0], nums[1]})
|
comms = append(comms, []interface{}{tokens[0], nums[0], nums[1]})
|
||||||
|
@ -76,6 +76,7 @@ func TestDecodeRoutes(t *testing.T) {
|
|||||||
if r.BGP.ExtCommunities[1][2] != 11000 {
|
if r.BGP.ExtCommunities[1][2] != 11000 {
|
||||||
t.Error("unexpected community:", r.BGP.ExtCommunities[0])
|
t.Error("unexpected community:", r.BGP.ExtCommunities[0])
|
||||||
}
|
}
|
||||||
|
t.Log(r.BGP.ExtCommunities)
|
||||||
|
|
||||||
if r.BGP.AsPath[0] != 1111 {
|
if r.BGP.AsPath[0] != 1111 {
|
||||||
t.Error("unexpected as_path:", r.BGP.AsPath)
|
t.Error("unexpected as_path:", r.BGP.AsPath)
|
||||||
@ -93,3 +94,26 @@ func TestDecodeExtendedCommunities(t *testing.T) {
|
|||||||
t.Fatal("unexpected result:", comms[0])
|
t.Fatal("unexpected result:", comms[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDecodeMalformedExtendedCommunities(t *testing.T) {
|
||||||
|
data := []interface{}{
|
||||||
|
"0x8000000000000000",
|
||||||
|
"8000000000000000",
|
||||||
|
"rt 1239", "generic :123", "generic ro-23:123",
|
||||||
|
"generic 123123192399281398193489:asd",
|
||||||
|
"[0] 0x8000000000000000",
|
||||||
|
"[0] 0x800000000:0000000",
|
||||||
|
"foo bar:23:42",
|
||||||
|
"foo 2342:bar",
|
||||||
|
"foo 23:bar:42",
|
||||||
|
"foo",
|
||||||
|
"b 9223372036854775808",
|
||||||
|
922337203685477580,
|
||||||
|
"ro 2::42",
|
||||||
|
"generic rt a:b"}
|
||||||
|
comms := decodeExtendedCommunities(data)
|
||||||
|
t.Log(comms)
|
||||||
|
if len(comms) > 0 {
|
||||||
|
t.Error("expected empty communities")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
3
pkg/sources/openbgpd/testdata/rib.json
vendored
3
pkg/sources/openbgpd/testdata/rib.json
vendored
@ -25,7 +25,8 @@
|
|||||||
],
|
],
|
||||||
"extended_communities": [
|
"extended_communities": [
|
||||||
"[0] 11000:0",
|
"[0] 11000:0",
|
||||||
"rt 65000:11000"
|
"rt 65000:11000",
|
||||||
|
"[0] 0x8000000000000000"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user