Skip to content

Commit

Permalink
E2E: test leaking routes from VRFs
Browse files Browse the repository at this point in the history
Here we test leaking routes from / to VRFs with different types of
allowed prefixes.

Signed-off-by: Federico Paolinelli <[email protected]>
  • Loading branch information
fedepaol committed Jul 19, 2024
1 parent 745ef31 commit 0f83339
Show file tree
Hide file tree
Showing 5 changed files with 503 additions and 13 deletions.
32 changes: 32 additions & 0 deletions e2etests/pkg/address/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier:Apache-2.0

package address

import (
"net"

"go.universe.tf/e2etest/pkg/ipfamily"
)

func FilterForFamily(ips []string, family ipfamily.Family) []string {
if family == ipfamily.DualStack {
return ips
}
var res []string
for _, ip := range ips {
parsedIP, _, _ := net.ParseCIDR(ip)
if parsedIP == nil {
panic("invalid ip") // it's a test after all, should never happen
}
isV4 := (parsedIP.To4() != nil)
if family == ipfamily.IPv4 && isV4 {
res = append(res, ip)
continue
}
if family == ipfamily.IPv6 && !isV4 {
res = append(res, ip)
continue
}
}
return res
}
7 changes: 3 additions & 4 deletions e2etests/pkg/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ import (

// PodHasPrefixFromContainer tells if the given frr-k8s pod has recevied a route for
// the given prefix from the given container.
func PodHasPrefixFromContainer(pod *v1.Pod, frr frrcontainer.FRR, prefix string) bool {
func PodHasPrefixFromContainer(pod *v1.Pod, frr frrcontainer.FRR, vrf, prefix string) bool {
_, cidr, _ := net.ParseCIDR(prefix)
ipFamily := ipfamily.ForCIDR(cidr)
nextHop := frr.Ipv4
if ipFamily == ipfamily.IPv6 {
nextHop = frr.Ipv6
}
vrf := frr.RouterConfig.VRF
return hasPrefix(pod, ipFamily, cidr, nextHop, vrf)
}

// CheckNeighborHasPrefix tells if the given frr container has a route toward the given prefix
// via the set of node passed to this function.
func CheckNeighborHasPrefix(neighbor frrcontainer.FRR, prefix string, nodes []v1.Node) error {
func CheckNeighborHasPrefix(neighbor frrcontainer.FRR, vrf, prefix string, nodes []v1.Node) error {
routesV4, routesV6, err := frr.Routes(neighbor)
if err != nil {
return err
Expand All @@ -47,7 +46,7 @@ func CheckNeighborHasPrefix(neighbor frrcontainer.FRR, prefix string, nodes []v1
}

cidrFamily := ipfamily.ForCIDR(cidr)
err = frr.RoutesMatchNodes(nodes, route, cidrFamily, neighbor.RouterConfig.VRF)
err = frr.RoutesMatchNodes(nodes, route, cidrFamily, vrf)
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions e2etests/tests/graceful_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ var _ = ginkgo.Describe("Establish BGP session with EnableGracefulRestart", func

check := func() error {
for _, p := range peersConfig.Peers() {
found, err := routes.CheckNeighborHasPrefix(p.FRR, prefix, nodes)
Expect(err).NotTo(HaveOccurred())
if !found {
return fmt.Errorf("Neigh %s does not have prefix %s", p.FRR.Name, prefix)
err := routes.CheckNeighborHasPrefix(p.FRR, p.FRR.RouterConfig.VRF, prefix, nodes)
if err != nil {
return fmt.Errorf("Neigh %s does not have prefix %s: %w", p.FRR.Name, prefix, err)
}
}
return nil
Expand Down
Loading

0 comments on commit 0f83339

Please sign in to comment.