-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_counters.py
32 lines (21 loc) · 862 Bytes
/
read_counters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from p4utils.utils.topology import Topology
from p4utils.utils.sswitch_API import SimpleSwitchAPI
import sys
class ReadCounters(object):
def __init__(self, sw_name):
self.topo = Topology(db="topology.db")
self.sw_name = sw_name
self.thrift_port = self.topo.get_thrift_port(sw_name)
self.controller = SimpleSwitchAPI(self.thrift_port)
def direct(self):
entries = self.controller.table_num_entries("count_table")
for i in range(int(entries)):
self.controller.counter_read("direct_port_counter", i)
def indirect(self):
for i in range(1,4):
self.controller.counter_read("port_counter", i)
if __name__ == "__main__":
# if sys.argv[1] == "direct":
# ReadCounters("s1").direct()
# elif sys.argv[1] == "indirect":
ReadCounters("s1").indirect()