aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVladislav Grishenko <themiron@yandex-team.ru>2024-03-02 21:04:14 +0500
committerMohammed HAWARI <momohawari@gmail.com>2024-03-04 09:29:12 +0000
commit5be4b869a450530052f31e3325dfcfee49ac2178 (patch)
tree22b30d0a8bd39412bbd005b9be776a3cffdb2be2 /test
parent4b6614030f384f7c8d847360cacf5c7f7560c6be (diff)
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 <themiron@yandex-team.ru> Change-Id: I92b2b519e92326f1b8e1a4dda6a3e3edc52f87ad
Diffstat (limited to 'test')
-rw-r--r--test/test_bpf_trace_filter.py33
1 files changed, 32 insertions, 1 deletions
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)