From 5be4b869a450530052f31e3325dfcfee49ac2178 Mon Sep 17 00:00:00 2001 From: Vladislav Grishenko Date: Sat, 2 Mar 2024 21:04:14 +0500 Subject: bpf_trace_filter: support bpf filter optimization and dump BPF filter w/o optimization can take x2 - x3 more instructions, causing significant slow down in fast path. Enable pcap optimization by default via cli and introduce api v2 with pcap optimization control, keep v1 for a while as it exists in previous release already. Intriduce bpf filter cli dump, similar to tcpdump -d. Also fix memleak, function name typo, cli pcap format hint and add related tests. Type: improvement Signed-off-by: Vladislav Grishenko Change-Id: I92b2b519e92326f1b8e1a4dda6a3e3edc52f87ad --- test/test_bpf_trace_filter.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'test/test_bpf_trace_filter.py') diff --git a/test/test_bpf_trace_filter.py b/test/test_bpf_trace_filter.py index 9ee74db681e..6958caa6b37 100644 --- a/test/test_bpf_trace_filter.py +++ b/test/test_bpf_trace_filter.py @@ -48,7 +48,7 @@ class TestBpfTraceFilter(VppTestCase): p = ( Ether(dst=src_if.local_mac, src=src_if.remote_mac) / IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4) - / UDP(sport=randint(49152, 65535), dport=5678) + / UDP(sport=randint(49152, 65535), dport=5678 + i) ) info.data = p.copy() packets.append(p) @@ -77,6 +77,9 @@ class TestBpfTraceFilter(VppTestCase): "Unexpected packets in the trace buffer", ) + reply = self.vapi.cli("show bpf trace filter") + self.assertIn("(000)", reply, "Unexpected bpf filter dump") + def test_bpf_trace_filter_vapi(self): """BPF Trace filter test [VAPI]""" self.vapi.bpf_trace_filter_set(filter="tcp") @@ -100,6 +103,34 @@ class TestBpfTraceFilter(VppTestCase): "Unexpected packets in the trace buffer", ) + def test_bpf_trace_filter_vapi_v2(self): + """BPF Trace filter test [VAPI v2]""" + self.vapi.bpf_trace_filter_set_v2(filter="tcp or dst port 5678") + self.vapi.trace_set_filter_function(filter_function_name="bpf_trace_filter") + + packets = self.create_stream(self.pg0, self.pg1, 3) + self.pg0.add_stream(packets) + self.pg_start(traceFilter=True) + + # verify that bpf trace filter has been selected + reply = self.vapi.cli("show trace filter function") + self.assertIn( + "(*) name:bpf_trace_filter", reply, "BPF Trace filter is not selected" + ) + + # verify that trace is filtered + reply = self.vapi.cli("show trace") + self.assertIn( + "Packet 1\n", + reply, + "No expected packets in the trace buffer", + ) + self.assertNotIn( + "Packet 2\n", + reply, + "Unexpected packets in the trace buffer", + ) + if __name__ == "__main__": unittest.main(testRunner=VppTestRunner) -- cgit 1.2.3-korg