Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package routingtable
import (
"net"
"testing"
bnet "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route"
"github.com/stretchr/testify/assert"
)
func TestShouldPropagateUpdate(t *testing.T) {
tests := []struct {
name string
communities string
neighbor Neighbor
expected bool
}{
{
name: "arbitrary path",
expected: true,
},
{
name: "path was received from this peer before",
communities: "(1,2)",
neighbor: Neighbor{
Type: route.BGPPathType,
Address: bnet.IPv4ToUint32(net.ParseIP("192.168.1.1")),
},
expected: false,
},
{
name: "path with no-export community",
communities: "(1,2) (65535,65281)",
expected: false,
},
{
name: "path with no-export community (iBGP)",
communities: "(1,2) (65535,65281)",
neighbor: Neighbor{
IBGP: true,
},
expected: true,
},
{
name: "path with no-advertise community",
communities: "(1,2) (65535,65282)",
expected: false,
},
{
name: "path with no-advertise community (iBGP)",
communities: "(1,2) (65535,65282)",
neighbor: Neighbor{
IBGP: true,
},
expected: false,
},
}
for _, test := range tests {
t.Run(test.name, func(te *testing.T) {
pfx := bnet.NewPfx(0, 32)
pa := &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
Communities: test.communities,
Source: bnet.IPv4ToUint32(net.ParseIP("192.168.1.1")),
},
}
res := ShouldPropagateUpdate(pfx, pa, &test.neighbor)
assert.Equal(te, test.expected, res)
})
}
}