summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2020-12-08 09:21:49 -0800
committergVisor bot <gvisor-bot@google.com>2020-12-08 09:24:02 -0800
commit5ea6419478676560e617fe0c19c9e37bf88dd8bc (patch)
treeee19e60ffb81b7341b55608744b4ea82a73e226c /test
parent9c198e5df4216feb5ebbf144e3b616888dfe3c27 (diff)
Consolidate sniffer program logic
Avoid action at a distance where both `snifferArgs` and `snifferProg` must stay in sync. PiperOrigin-RevId: 346341231
Diffstat (limited to 'test')
-rw-r--r--test/packetimpact/runner/dut.go53
1 files changed, 28 insertions, 25 deletions
diff --git a/test/packetimpact/runner/dut.go b/test/packetimpact/runner/dut.go
index 4fc9fce2b..b607c0b04 100644
--- a/test/packetimpact/runner/dut.go
+++ b/test/packetimpact/runner/dut.go
@@ -265,12 +265,36 @@ func TestWithDUT(ctx context.Context, t *testing.T, mkDevice func(*dockerutil.Co
t.Fatalf("failed to marshal %v into json: %s", dutTestNets, err)
}
- snifferProg := "tcpdump"
+ baseSnifferArgs := []string{
+ "tcpdump",
+ "-vvv",
+ "--absolute-tcp-sequence-numbers",
+ "--packet-buffered",
+ // Disable DNS resolution.
+ "-n",
+ }
if tshark {
- snifferProg = "tshark"
+ baseSnifferArgs = []string{
+ "tshark",
+ "-V",
+ "-o", "tcp.check_checksum:TRUE",
+ "-o", "udp.check_checksum:TRUE",
+ // Disable buffering.
+ "-l",
+ // Disable DNS resolution.
+ "-n",
+ }
}
for _, n := range dutTestNets {
- _, err := testbenchContainer.ExecProcess(ctx, dockerutil.ExecOpts{}, snifferArgs(n.LocalDevName)...)
+ snifferArgs := append(baseSnifferArgs, "-i", n.LocalDevName)
+ if !tshark {
+ snifferArgs = append(
+ snifferArgs,
+ "-w",
+ filepath.Join(testOutputDir, fmt.Sprintf("%s.pcap", n.LocalDevName)),
+ )
+ }
+ _, err := testbenchContainer.ExecProcess(ctx, dockerutil.ExecOpts{}, snifferArgs...)
if err != nil {
t.Fatalf("failed to start exec a sniffer on %s: %s", n.LocalDevName, err)
}
@@ -292,7 +316,7 @@ func TestWithDUT(ctx context.Context, t *testing.T, mkDevice func(*dockerutil.Co
// any packets. On linux tests killing it immediately can
// sometimes result in partial pcaps.
time.Sleep(1 * time.Second)
- if logs, err := testbenchContainer.Exec(ctx, dockerutil.ExecOpts{}, "killall", snifferProg); err != nil {
+ if logs, err := testbenchContainer.Exec(ctx, dockerutil.ExecOpts{}, "killall", baseSnifferArgs[0]); err != nil {
t.Errorf("failed to kill all sniffers: %s, logs: %s", err, logs)
}
})
@@ -549,24 +573,3 @@ func mountTempDirectory(t *testing.T, runOpts *dockerutil.RunOpts, hostDirTempla
})
return tmpDir, nil
}
-
-// snifferArgs returns the correct command line to run sniffer on the testbench.
-func snifferArgs(devName string) []string {
- if tshark {
- // Run tshark in the test bench unbuffered, without DNS resolution, just
- // on the interface with the test packets.
- return []string{
- "tshark", "-V", "-l", "-n", "-i", devName,
- "-o", "tcp.check_checksum:TRUE",
- "-o", "udp.check_checksum:TRUE",
- }
- }
- // Run tcpdump in the test bench unbuffered, without DNS resolution, just
- // on the interface with the test packets.
- return []string{
- "tcpdump",
- "-S", "-vvv", "-U", "-n",
- "-i", devName,
- "-w", filepath.Join(testOutputDir, fmt.Sprintf("%s.pcap", devName)),
- }
-}