Skip to content

Commit

Permalink
E2E: Advertisements with communities
Browse files Browse the repository at this point in the history
Signed-off-by: Ori Braunshtein <[email protected]>
  • Loading branch information
oribon committed Jul 17, 2023
1 parent faae114 commit a1d12c6
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
56 changes: 56 additions & 0 deletions e2etests/tests/advertisement.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,62 @@ var _ = ginkgo.Describe("Advertisement", func() {
}
},
}),
ginkgo.Entry("IPV4 - Advertise with communities", params{
ipFamily: ipfamily.IPv4,
vrf: "",
myAsn: infra.FRRK8sASN,
prefixes: []string{"192.168.0.0/24", "192.168.1.0/24"},
modifyPeers: func(ppV4 []config.Peer, ppV6 []config.Peer) {
for i := range ppV4 {
ppV4[i].Neigh.ToAdvertise.Allowed.Mode = frrk8sv1beta1.AllowAll
ppV4[i].Neigh.ToAdvertise.PrefixesWithCommunity = []frrk8sv1beta1.CommunityPrefixes{
{
Community: "10:100",
Prefixes: []string{"192.168.0.0/24"},
},
{
Community: "10:101",
Prefixes: []string{"192.168.1.0/24"},
},
}
}
},
validate: func(ppV4 []config.Peer, ppV6 []config.Peer, nodes []v1.Node) {
for _, p := range ppV4 {
ValidatePrefixesForNeighbor(p.FRR, nodes, "192.168.0.0/24", "192.168.1.0/24")
ValidateNeighborCommunityPrefixes(p.FRR, "10:100", []string{"192.168.0.0"}, ipfamily.IPv4)
ValidateNeighborCommunityPrefixes(p.FRR, "10:101", []string{"192.168.1.0"}, ipfamily.IPv4)
}
},
}),
ginkgo.Entry("IPV6 - Advertise with communities", params{
ipFamily: ipfamily.IPv6,
vrf: "",
myAsn: infra.FRRK8sASN,
prefixes: []string{"fc00:f853:ccd:e799::/64", "fc00:f853:ccd:e800::/64"},
modifyPeers: func(ppV4 []config.Peer, ppV6 []config.Peer) {
for i := range ppV6 {
ppV6[i].Neigh.ToAdvertise.Allowed.Mode = frrk8sv1beta1.AllowAll
ppV6[i].Neigh.ToAdvertise.PrefixesWithCommunity = []frrk8sv1beta1.CommunityPrefixes{
{
Community: "10:100",
Prefixes: []string{"fc00:f853:ccd:e799::/64"},
},
{
Community: "10:101",
Prefixes: []string{"fc00:f853:ccd:e800::/64"},
},
}
}
},
validate: func(ppV4 []config.Peer, ppV6 []config.Peer, nodes []v1.Node) {
for _, p := range ppV6 {
ValidatePrefixesForNeighbor(p.FRR, nodes, "fc00:f853:ccd:e799::/64", "fc00:f853:ccd:e800::/64")
ValidateNeighborCommunityPrefixes(p.FRR, "10:100", []string{"fc00:f853:ccd:e799::"}, ipfamily.IPv6)
ValidateNeighborCommunityPrefixes(p.FRR, "10:101", []string{"fc00:f853:ccd:e800::"}, ipfamily.IPv6)
}
},
}),
)
})
})
28 changes: 28 additions & 0 deletions e2etests/tests/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,31 @@ func ValidateNeighborNoPrefixes(neigh frrcontainer.FRR, nodes []v1.Node, prefixe
return nil
}, 5*time.Second, time.Second).ShouldNot(HaveOccurred())
}

func ValidateNeighborCommunityPrefixes(neigh frrcontainer.FRR, community string, prefixes []string, ipfam ipfamily.Family) {
Eventually(func() error {
routes, err := frr.RoutesForCommunity(neigh, community, ipfam)
if err != nil {
return err
}

communityPrefixes := map[string]struct{}{}
for p := range routes {
communityPrefixes[p] = struct{}{}
}

for _, prefix := range prefixes {
_, ok := communityPrefixes[prefix]
if !ok {
return fmt.Errorf("prefix %s not found in neighbor %s community %s unmatched routes %s", prefix, neigh.Name, community, communityPrefixes)
}
delete(communityPrefixes, prefix)
}

if len(communityPrefixes) != 0 {
return fmt.Errorf("routes %s for community %s were not matched for neighbor %s", communityPrefixes, community, neigh.Name)
}

return nil
}, 5*time.Second, time.Second).ShouldNot(HaveOccurred())
}

0 comments on commit a1d12c6

Please sign in to comment.