2019-10-31 13:31:07 -05:00
|
|
|
#!/usr/bin/env python3
|
2019-03-11 05:04:12 -07:00
|
|
|
|
|
|
|
import unittest
|
|
|
|
import psutil
|
|
|
|
from vpp_papi.vpp_stats import VPPStats
|
|
|
|
|
2023-08-31 00:47:44 -04:00
|
|
|
from framework import VppTestCase
|
|
|
|
from asfframework import VppTestRunner
|
2021-03-11 10:26:54 -08:00
|
|
|
from scapy.layers.l2 import Ether
|
|
|
|
from scapy.layers.inet import IP
|
2019-03-11 05:04:12 -07:00
|
|
|
|
|
|
|
|
|
|
|
class StatsClientTestCase(VppTestCase):
|
|
|
|
"""Test Stats Client"""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(StatsClientTestCase, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(StatsClientTestCase, cls).tearDownClass()
|
|
|
|
|
2023-02-24 16:13:29 +01:00
|
|
|
def setUp(self):
|
|
|
|
super(StatsClientTestCase, self).setUp()
|
|
|
|
self.create_pg_interfaces([])
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(StatsClientTestCase, self).tearDown()
|
|
|
|
for i in self.pg_interfaces:
|
|
|
|
i.unconfig()
|
|
|
|
i.admin_down()
|
|
|
|
|
2021-03-11 10:26:54 -08:00
|
|
|
@classmethod
|
|
|
|
def setUpConstants(cls):
|
|
|
|
cls.extra_vpp_statseg_config = "per-node-counters on"
|
|
|
|
cls.extra_vpp_statseg_config += "update-interval 0.05"
|
|
|
|
super(StatsClientTestCase, cls).setUpConstants()
|
|
|
|
|
2019-05-16 15:01:34 +02:00
|
|
|
def test_set_errors(self):
|
|
|
|
"""Test set errors"""
|
|
|
|
self.assertEqual(self.statistics.set_errors(), {})
|
2021-03-18 11:12:01 +01:00
|
|
|
self.assertEqual(
|
2023-02-24 16:13:29 +01:00
|
|
|
self.statistics.get_counter("/err/ethernet-input/no error"),
|
|
|
|
[0] * (1 + self.vpp_worker_count),
|
2022-04-26 19:02:15 +02:00
|
|
|
)
|
2019-05-16 15:01:34 +02:00
|
|
|
|
2019-03-11 05:04:12 -07:00
|
|
|
def test_client_fd_leak(self):
|
|
|
|
"""Test file descriptor count - VPP-1486"""
|
|
|
|
|
|
|
|
cls = self.__class__
|
|
|
|
p = psutil.Process()
|
|
|
|
initial_fds = p.num_fds()
|
|
|
|
|
|
|
|
for _ in range(100):
|
2021-03-16 12:52:12 +01:00
|
|
|
stats = VPPStats(socketname=cls.get_stats_sock_path())
|
2019-03-11 05:04:12 -07:00
|
|
|
stats.disconnect()
|
|
|
|
|
|
|
|
ending_fds = p.num_fds()
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(
|
|
|
|
initial_fds,
|
|
|
|
ending_fds,
|
|
|
|
"initial client side file descriptor count: %s "
|
|
|
|
"is not equal to "
|
|
|
|
"ending client side file descriptor count: %s" % (initial_fds, ending_fds),
|
|
|
|
)
|
2019-06-18 09:56:07 -07:00
|
|
|
|
2021-03-11 10:26:54 -08:00
|
|
|
def test_symlink_values(self):
|
|
|
|
"""Test symlinks reported values"""
|
|
|
|
self.create_pg_interfaces(range(2))
|
|
|
|
|
|
|
|
for i in self.pg_interfaces:
|
|
|
|
i.admin_up()
|
|
|
|
i.config_ip4()
|
|
|
|
i.resolve_arp()
|
|
|
|
|
|
|
|
p = list()
|
|
|
|
for i in range(5):
|
2022-04-26 19:02:15 +02:00
|
|
|
packet = Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IP(
|
|
|
|
src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4
|
|
|
|
)
|
2021-03-11 10:26:54 -08:00
|
|
|
p.append(packet)
|
|
|
|
|
|
|
|
self.send_and_expect(self.pg0, p, self.pg1)
|
2022-04-26 19:02:15 +02:00
|
|
|
pg1_tx = self.statistics.get_counter("/interfaces/pg1/tx")
|
|
|
|
if_tx = self.statistics.get_counter("/if/tx")
|
2021-03-11 10:26:54 -08:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(pg1_tx[0]["bytes"], if_tx[0][self.pg1.sw_if_index]["bytes"])
|
2021-03-11 10:26:54 -08:00
|
|
|
|
|
|
|
def test_symlink_add_del_interfaces(self):
|
|
|
|
"""Test symlinks when adding and deleting interfaces"""
|
|
|
|
# We first create and delete interfaces
|
|
|
|
self.create_loopback_interfaces(1)
|
|
|
|
self.create_pg_interfaces(range(1))
|
|
|
|
self.loop0.remove_vpp_config()
|
|
|
|
self.create_pg_interfaces(range(2))
|
|
|
|
|
|
|
|
for i in self.pg_interfaces:
|
|
|
|
i.admin_up()
|
|
|
|
i.config_ip4()
|
|
|
|
i.resolve_arp()
|
|
|
|
|
|
|
|
p = list()
|
|
|
|
bytes_to_send = 0
|
|
|
|
for i in range(5):
|
2022-04-26 19:02:15 +02:00
|
|
|
packet = Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / IP(
|
|
|
|
src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4
|
|
|
|
)
|
2021-03-11 10:26:54 -08:00
|
|
|
bytes_to_send += len(packet)
|
|
|
|
p.append(packet)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
tx_before_sending = self.statistics.get_counter("/interfaces/pg1/tx")
|
|
|
|
rx_before_sending = self.statistics.get_counter("/interfaces/pg0/rx")
|
2021-03-11 10:26:54 -08:00
|
|
|
self.send_and_expect(self.pg0, p, self.pg1)
|
2022-04-26 19:02:15 +02:00
|
|
|
tx = self.statistics.get_counter("/interfaces/pg1/tx")
|
|
|
|
rx = self.statistics.get_counter("/interfaces/pg0/rx")
|
2021-03-11 10:26:54 -08:00
|
|
|
|
|
|
|
# We wait for nodes symlinks to update (interfaces created/deleted).
|
2023-02-24 16:13:29 +01:00
|
|
|
self.virtual_sleep(1)
|
2022-04-26 19:02:15 +02:00
|
|
|
vectors = self.statistics.get_counter("/nodes/pg1-tx/vectors")
|
|
|
|
|
2023-02-24 16:13:29 +01:00
|
|
|
rx_bytes = 0
|
|
|
|
rx_packets = 0
|
|
|
|
tx_bytes = 0
|
|
|
|
tx_packets = 0
|
|
|
|
for i in range(1 + self.vpp_worker_count):
|
|
|
|
rx_bytes += rx[i]["bytes"] - rx_before_sending[i]["bytes"]
|
|
|
|
rx_packets += rx[i]["packets"] - rx_before_sending[i]["packets"]
|
|
|
|
tx_bytes += tx[i]["bytes"] - tx_before_sending[i]["bytes"]
|
|
|
|
tx_packets += tx[i]["packets"] - tx_before_sending[i]["packets"]
|
|
|
|
self.assertEqual(tx_bytes, bytes_to_send)
|
|
|
|
self.assertEqual(tx_packets, 5)
|
|
|
|
self.assertEqual(rx_bytes, bytes_to_send)
|
|
|
|
self.assertEqual(rx_packets, 5)
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(vectors[0], rx[0]["packets"])
|
2021-03-11 10:26:54 -08:00
|
|
|
|
|
|
|
def test_index_consistency(self):
|
|
|
|
"""Test index consistency despite changes in the stats"""
|
2022-04-26 19:02:15 +02:00
|
|
|
d = self.statistics.ls(["/if/names"])
|
2021-03-11 10:26:54 -08:00
|
|
|
self.create_loopback_interfaces(10)
|
|
|
|
for i in range(10):
|
|
|
|
try:
|
|
|
|
s = self.statistics.dump(d)
|
|
|
|
break
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
k, v = s.popitem()
|
|
|
|
self.assertEqual(len(v), 11)
|
|
|
|
|
|
|
|
for i in self.lo_interfaces:
|
|
|
|
i.remove_vpp_config()
|
|
|
|
|
2019-06-16 12:33:51 +02:00
|
|
|
@unittest.skip("Manual only")
|
|
|
|
def test_mem_leak(self):
|
|
|
|
def loop():
|
2022-04-26 19:02:15 +02:00
|
|
|
print("Running loop")
|
2019-06-16 12:33:51 +02:00
|
|
|
for i in range(50):
|
|
|
|
rv = self.vapi.papi.tap_create_v2(id=i, use_random_mac=1)
|
|
|
|
self.assertEqual(rv.retval, 0)
|
|
|
|
rv = self.vapi.papi.tap_delete_v2(sw_if_index=rv.sw_if_index)
|
|
|
|
self.assertEqual(rv.retval, 0)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
before = self.statistics.get_counter("/mem/statseg/used")
|
2019-06-16 12:33:51 +02:00
|
|
|
loop()
|
|
|
|
self.vapi.cli("memory-trace on stats-segment")
|
|
|
|
for j in range(100):
|
|
|
|
loop()
|
|
|
|
print(self.vapi.cli("show memory stats-segment verbose"))
|
2022-04-26 19:02:15 +02:00
|
|
|
print("AFTER", before, self.statistics.get_counter("/mem/statseg/used"))
|
2019-06-18 09:56:07 -07:00
|
|
|
|
2019-03-11 05:04:12 -07:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
if __name__ == "__main__":
|
2019-03-11 05:04:12 -07:00
|
|
|
unittest.main(testRunner=VppTestRunner)
|