mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Cleanup device name confusion in packetimpact testbench
There are two device names on the test net. - The sniffer/injector device which is always a linux device. Only the testbench library is interested in this device. - The device which is on the DUT. It happens to be the same device as the former if DUT is linux. An individual test might be interested in this device if the test cares about the device name. PiperOrigin-RevId: 332112968
This commit is contained in:
@@ -172,7 +172,7 @@ func TestWithDUT(ctx context.Context, t *testing.T, mkDevice func(*dockerutil.Co
|
||||
}
|
||||
|
||||
device := mkDevice(dut)
|
||||
remoteIPv6, remoteMAC, dutDeviceID, testNetDev := device.Prepare(ctx, t, runOpts, ctrlNet, testNet, containerAddr)
|
||||
remoteIPv6, remoteMAC, dutDeviceID, dutTestNetDev := device.Prepare(ctx, t, runOpts, ctrlNet, testNet, containerAddr)
|
||||
|
||||
// Create the Docker container for the testbench.
|
||||
testbench := dockerutil.MakeNativeContainer(ctx, logger("testbench"))
|
||||
@@ -181,12 +181,16 @@ func TestWithDUT(ctx context.Context, t *testing.T, mkDevice func(*dockerutil.Co
|
||||
containerTestbenchBinary := filepath.Join("/packetimpact", tbb)
|
||||
testbench.CopyFiles(&runOpts, "/packetimpact", filepath.Join("test/packetimpact/tests", tbb))
|
||||
|
||||
// snifferNetDev is a network device on the test orchestrator that we will
|
||||
// run sniffer (tcpdump or tshark) on and inject traffic to, not to be
|
||||
// confused with the device on the DUT.
|
||||
const snifferNetDev = "eth2"
|
||||
// Run tcpdump in the test bench unbuffered, without DNS resolution, just on
|
||||
// the interface with the test packets.
|
||||
snifferArgs := []string{
|
||||
"tcpdump",
|
||||
"-S", "-vvv", "-U", "-n",
|
||||
"-i", testNetDev,
|
||||
"-i", snifferNetDev,
|
||||
"-w", testOutputDir + "/dump.pcap",
|
||||
}
|
||||
snifferRegex := "tcpdump: listening.*\n"
|
||||
@@ -194,7 +198,7 @@ func TestWithDUT(ctx context.Context, t *testing.T, mkDevice func(*dockerutil.Co
|
||||
// Run tshark in the test bench unbuffered, without DNS resolution, just on
|
||||
// the interface with the test packets.
|
||||
snifferArgs = []string{
|
||||
"tshark", "-V", "-l", "-n", "-i", testNetDev,
|
||||
"tshark", "-V", "-l", "-n", "-i", snifferNetDev,
|
||||
"-o", "tcp.check_checksum:TRUE",
|
||||
"-o", "udp.check_checksum:TRUE",
|
||||
}
|
||||
@@ -228,7 +232,7 @@ func TestWithDUT(ctx context.Context, t *testing.T, mkDevice func(*dockerutil.Co
|
||||
// this, we can install the following iptables rules. The raw socket that
|
||||
// packetimpact tests use will still be able to see everything.
|
||||
for _, bin := range []string{"iptables", "ip6tables"} {
|
||||
if logs, err := testbench.Exec(ctx, dockerutil.ExecOpts{}, bin, "-A", "INPUT", "-i", testNetDev, "-p", "tcp", "-j", "DROP"); err != nil {
|
||||
if logs, err := testbench.Exec(ctx, dockerutil.ExecOpts{}, bin, "-A", "INPUT", "-i", snifferNetDev, "-p", "tcp", "-j", "DROP"); err != nil {
|
||||
t.Fatalf("unable to Exec %s on container %s: %s, logs from testbench:\n%s", bin, testbench.Name, err, logs)
|
||||
}
|
||||
}
|
||||
@@ -251,7 +255,8 @@ func TestWithDUT(ctx context.Context, t *testing.T, mkDevice func(*dockerutil.Co
|
||||
"--remote_ipv6", remoteIPv6.String(),
|
||||
"--remote_mac", remoteMAC.String(),
|
||||
"--remote_interface_id", fmt.Sprintf("%d", dutDeviceID),
|
||||
"--device", testNetDev,
|
||||
"--local_device", snifferNetDev,
|
||||
"--remote_device", dutTestNetDev,
|
||||
fmt.Sprintf("--native=%t", native),
|
||||
)
|
||||
testbenchLogs, err := testbench.Exec(ctx, dockerutil.ExecOpts{}, testArgs...)
|
||||
|
||||
@@ -139,7 +139,7 @@ type Injector struct {
|
||||
func NewInjector(t *testing.T) (Injector, error) {
|
||||
t.Helper()
|
||||
|
||||
ifInfo, err := net.InterfaceByName(Device)
|
||||
ifInfo, err := net.InterfaceByName(LocalDevice)
|
||||
if err != nil {
|
||||
return Injector{}, err
|
||||
}
|
||||
|
||||
@@ -29,8 +29,11 @@ import (
|
||||
var (
|
||||
// Native indicates that the test is being run natively.
|
||||
Native = false
|
||||
// Device is the local device on the test network.
|
||||
Device = ""
|
||||
// LocalDevice is the device that testbench uses to inject traffic.
|
||||
LocalDevice = ""
|
||||
// RemoteDevice is the device name on the DUT, individual tests can
|
||||
// use the name to construct tests.
|
||||
RemoteDevice = ""
|
||||
|
||||
// LocalIPv4 is the local IPv4 address on the test network.
|
||||
LocalIPv4 = ""
|
||||
@@ -80,7 +83,8 @@ func RegisterFlags(fs *flag.FlagSet) {
|
||||
fs.StringVar(&RemoteIPv4, "remote_ipv4", RemoteIPv4, "remote IPv4 address for test packets")
|
||||
fs.StringVar(&RemoteIPv6, "remote_ipv6", RemoteIPv6, "remote IPv6 address for test packets")
|
||||
fs.StringVar(&RemoteMAC, "remote_mac", RemoteMAC, "remote mac address for test packets")
|
||||
fs.StringVar(&Device, "device", Device, "local device for test packets")
|
||||
fs.StringVar(&LocalDevice, "local_device", LocalDevice, "local device to inject traffic")
|
||||
fs.StringVar(&RemoteDevice, "remote_device", RemoteDevice, "remote device on the DUT")
|
||||
fs.BoolVar(&Native, "native", Native, "whether the test is running natively")
|
||||
fs.Uint64Var(&RemoteInterfaceID, "remote_interface_id", RemoteInterfaceID, "remote interface ID for test packets")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user