From 1a8404737946c1d265a9ee0b928a0c86cc43e6e7 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 8 Aug 2024 14:11:07 -0700 Subject: [PATCH] sameLAN Change-Id: I575dcab31ca812edf7d04fa126772611cf89b9a7 Signed-off-by: Brad Fitzpatrick --- tstest/integration/nat/nat_test.go | 33 ++++++++++++++++++++++++++---- tstest/natlab/vnet/conf.go | 14 +++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/tstest/integration/nat/nat_test.go b/tstest/integration/nat/nat_test.go index 45783aa75..3b3980ede 100644 --- a/tstest/integration/nat/nat_test.go +++ b/tstest/integration/nat/nat_test.go @@ -87,7 +87,7 @@ func findKernelPath(goMod string) (string, error) { return "", fmt.Errorf("failed to find kernel in %v", goMod) } -type addNodeFunc func(c *vnet.Config) *vnet.Node +type addNodeFunc func(c *vnet.Config) *vnet.Node // returns nil to omit test func easy(c *vnet.Config) *vnet.Node { n := c.NumNodes() + 1 @@ -96,6 +96,17 @@ func easy(c *vnet.Config) *vnet.Node { fmt.Sprintf("192.168.%d.1/24", n), vnet.EasyNAT)) } +func sameLAN(c *vnet.Config) *vnet.Node { + nw := c.FirstNetwork() + if nw == nil { + return nil + } + if !nw.CanTakeMoreNodes() { + return nil + } + return c.AddNode(nw) +} + func one2one(c *vnet.Config) *vnet.Node { n := c.NumNodes() + 1 return c.AddNode(c.AddNetwork( @@ -132,6 +143,9 @@ func (nt *natTest) runTest(node1, node2 addNodeFunc) pingRoute { node1(&c), node2(&c), } + if nodes[0] == nil || nodes[1] == nil { + t.Skip("skipping test; not applicable combination") + } var err error nt.vnet, err = vnet.New(&c) @@ -413,6 +427,7 @@ type nodeType struct { {"easyPMP", easyPMP}, {"hardPMP", hardPMP}, {"one2one", one2one}, + {"sameLAN", sameLAN}, } sem := syncs.NewSemaphore(2) @@ -420,9 +435,10 @@ type nodeType struct { mu sync.Mutex res = make(map[string]pingRoute) ) - for i, a := range types { - for _, b := range types[i:] { + for _, a := range types { + for _, b := range types { key := a.name + "-" + b.name + keyBack := b.name + "-" + a.name t.Run(key, func(t *testing.T) { t.Parallel() @@ -431,6 +447,10 @@ type nodeType struct { filename := key + ".cache" contents, _ := os.ReadFile(filename) + if len(contents) == 0 { + filename2 := keyBack + ".cache" + contents, _ = os.ReadFile(filename2) + } route := pingRoute(strings.TrimSpace(string(contents))) if route == "" { @@ -464,13 +484,18 @@ type nodeType struct { pf("\n") for _, a := range types { + if a.name == "sameLAN" { + continue + } pf("%s", a.name) for _, b := range types { key := a.name + "-" + b.name key2 := b.name + "-" + a.name - v := cmp.Or(res[key], res[key2]) + v := cmp.Or(res[key], res[key2], "-") if v == "derp" { pf("
%s
", v) + } else if v == "local" { + pf("
%s
", v) } else { pf("%s", v) } diff --git a/tstest/natlab/vnet/conf.go b/tstest/natlab/vnet/conf.go index d4cc87410..5d44b90f6 100644 --- a/tstest/natlab/vnet/conf.go +++ b/tstest/natlab/vnet/conf.go @@ -33,6 +33,13 @@ func (c *Config) NumNodes() int { return len(c.nodes) } +func (c *Config) FirstNetwork() *Network { + if len(c.networks) == 0 { + return nil + } + return c.networks[0] +} + // AddNode creates a new node in the world. // // The opts may be of the following types: @@ -145,6 +152,13 @@ type Network struct { err error // carried error } +func (n *Network) CanTakeMoreNodes() bool { + if n.natType == One2OneNAT { + return len(n.nodes) == 0 + } + return len(n.nodes) < 150 +} + // NetworkService is a service that can be added to a network. type NetworkService string