1 from config import config
2 from asfframework import VppTestRunner
4 from framework import VppTestCase
5 from scapy.layers.l2 import Ether
6 from scapy.layers.inet import IP, UDP
7 from random import randint
11 def create_stream(src_if, dst_if, count):
13 for i in range(count):
15 Ether(dst=src_if.local_mac, src=src_if.remote_mac)
16 / IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4)
17 / UDP(sport=randint(49152, 65535), dport=5678)
25 "tracedump" in config.excluded_plugins, "Exclude tracedump plugin tests"
27 class TestTracedump(VppTestCase):
28 """Tracedump plugin tests"""
32 super(TestTracedump, cls).setUpClass()
33 cls.create_pg_interfaces(range(2))
34 for i in cls.pg_interfaces:
40 def tearDownClass(cls):
41 for i in cls.pg_interfaces:
44 super(TestTracedump, cls).tearDownClass()
46 def test_tracedump_include(self):
47 """Check API/CLI output + include node"""
48 packets = create_stream(self.pg0, self.pg1, 5)
49 self.pg0.add_stream(packets)
51 self.vapi.trace_clear_cache()
52 self.vapi.trace_clear_capture()
54 self.vapi.trace_set_filters(flag=1, node_index=425, count=5)
55 self.vapi.trace_capture_packets(
60 pre_capture_clear=True,
63 reply = self.vapi.cli(
64 "show graph node want_arcs input drop output punt handoff no_free polling interrupt"
66 self.assertIn("af-packet-input", reply)
69 reply = self.vapi.graph_node_get(cursor=ctypes.c_uint32(~0).value, index=425)
70 self.assertTrue(reply[1][0].name == "pg-input")
71 reply = self.vapi.trace_v2_dump(
72 thread_id=ctypes.c_uint32(~0).value, position=0, clear_cache=False
74 self.assertTrue(reply)
75 reply = self.vapi.trace_filter_function_dump()
76 self.assertTrue(reply[1].selected)
78 def test_tracedump_exclude(self):
79 """Exclude node (no trace output)"""
80 self.vapi.trace_clear_cache()
81 self.vapi.trace_clear_capture()
83 packets = create_stream(self.pg0, self.pg1, 5)
84 self.pg0.add_stream(packets)
87 self.vapi.trace_set_filters(flag=2, node_index=425, count=5)
88 self.vapi.trace_capture_packets(
93 pre_capture_clear=True,
96 reply = self.vapi.trace_v2_dump(thread_id=0, position=1, clear_cache=False)
97 self.assertFalse(reply)
100 if __name__ == "__main__":
101 unittest.main(testRunner=VppTestRunner)