Skip to content

Commit

Permalink
Add direct/indirect counter tests (#8)
Browse files Browse the repository at this point in the history
* Add direct/indirect counter tests

* address comments

 - rename traffic_class_counter to fwd_type_counter
 - rename read_counter to read_indirect_counter
 - make fwd_type_counter optional
  • Loading branch information
Yi Tseng committed Jun 29, 2020
1 parent 33cc9a4 commit 9424cb6
Show file tree
Hide file tree
Showing 14 changed files with 98,965 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ model_0.log
pcap_output
*.log
zlog-cfg-cur
.DS_Store
10 changes: 10 additions & 0 deletions p4src/include/control/filtering.p4
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ control Filtering (inout parsed_headers_t hdr,
fwd_classifier_counter.count();
}

/*
* Counter that collects classes for all traffics.
*/
#ifdef WTIH_DEBUG
Counter<bit<64>, bit<3>>(8, CounterType_t.PACKETS_AND_BYTES) fwd_type_counter;
#endif

table fwd_classifier {
key = {
ig_intr_md.ingress_port : exact @name("ig_port");
Expand All @@ -94,5 +101,8 @@ control Filtering (inout parsed_headers_t hdr,
apply {
ingress_port_vlan.apply();
fwd_classifier.apply();
#ifdef WTIH_DEBUG
fwd_type_counter.count(fabric_md.fwd_type);
#endif
}
}
14 changes: 13 additions & 1 deletion ptf/tests/ptf/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,19 @@ def send_request_add_entry_to_group(self, t_name, mk, grp_id):
self.push_update_add_entry_to_group(req, t_name, mk, grp_id)
return req, self.write_request(req, store=(mk is not None))

def read_counter(self, c_name, c_index, typ):
def read_direct_counter(self, table_entry):
req = self.get_new_read_request()
entity = req.entities.add()
direct_counter_entry = entity.direct_counter_entry
direct_counter_entry.table_entry.CopyFrom(table_entry)

for entity in self.read_request(req):
if entity.HasField("direct_counter_entry"):
return entity.direct_counter_entry
return None


def read_indirect_counter(self, c_name, c_index, typ):
# Check counter type with P4Info
counter = self.get_counter(c_name)
counter_type_unit = p4info_pb2.CounterSpec.Unit.items()[counter.spec.unit][0]
Expand Down
61 changes: 59 additions & 2 deletions ptf/tests/ptf/fabric.ptf/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

from itertools import combinations

from ptf import testutils
from ptf.testutils import group
from scapy.layers.ppp import PPPoED

from base_test import autocleanup, stringify
from fabric_test import *

from unittest import skip
from time import sleep

vlan_confs = {
"tag->tag": [True, True],
Expand Down Expand Up @@ -916,6 +918,7 @@ def doRunTest(self):
self.verify_p4runtime_entity(expected_bridging_entry, received_bridging_entry)

def runTest(self):
print("")
self.doRunTest()

@group("p4r-function")
Expand All @@ -930,6 +933,7 @@ def doRunTest(self):
self.verify_p4runtime_entity(expected_action_profile_member, received_action_profile_member)

def runTest(self):
print("")
self.doRunTest()

@group("p4r-function")
Expand All @@ -948,6 +952,7 @@ def doRunTest(self):
self.verify_p4runtime_entity(expected_action_profile_group, received_action_profile_group)

def runTest(self):
print("")
self.doRunTest()

@group("p4r-function")
Expand Down Expand Up @@ -976,6 +981,7 @@ def doRunTest(self):
self.verify_p4runtime_entity(expected_action_profile_group, received_action_profile_group)

def runTest(self):
print("")
self.doRunTest()

@group("p4r-function")
Expand All @@ -990,8 +996,8 @@ def doRunTest(self):
received_mc_entry = self.read_mcast_group(grp_id)
self.verify_p4runtime_entity(expected_mc_entry, received_mc_entry)


def runTest(self):
print("")
self.doRunTest()


Expand All @@ -1017,4 +1023,55 @@ def doRunTest(self):
self.delete_mcast_group(grp_id)

def runTest(self):
self.doRunTest()
print("")
self.doRunTest()

@group("p4r-function")
class CounterTest(BridgingTest):

@autocleanup
def doRunTest(self):
pkt = getattr(testutils, "simple_tcp_packet")(pktlen=120)
self.runBridgingTest(False, False, pkt)
# Check direct counters from 'ingress_port_vlan' table
table_entries = [req.updates[0].entity.table_entry for req in self.reqs
if req.updates[0].entity.HasField('table_entry')]
table_entries = [te for te in table_entries
if te.table_id == self.get_table_id('ingress_port_vlan')]

for table_entry in table_entries:
self.read_direct_counter(table_entry)

# Wait counter being synced
sleep(1)
for table_entry in table_entries:
direct_counter = self.read_direct_counter(table_entry)
# Here, both table entries hits once with a
# simple TCP packet(120 bytes + 2*2 bytes checksum inserted by scapy)
if direct_counter.data.byte_count != 124 or \
direct_counter.data.packet_count != 1:
self.fail("Incorrect direct counter value:\n" + direct_counter)

try:
self.get_counter("fwd_type_counter")
except Exception as ex:
print("Unable to find indirect counter `fwd_type_counter`, skip")
return

# Read indirect counter (fwd_type_counter)
# Here we are trying to read counter for traffic class "0"
# which means how many traffic for bridging
self.read_indirect_counter("fwd_type_counter", 0, "BOTH")
# Wait counter being synced
sleep(1)
counter_entry = self.read_indirect_counter("fwd_type_counter", 0, "BOTH")

# In the bridging test we sent two TCP packets and both packets
# are classified as bridging class.
if counter_entry.data.byte_count != 248 or \
counter_entry.data.packet_count != 2:
self.fail("Incorrect direct counter value:\n" + counter_entry)

def runTest(self):
print("")
self.doRunTest()
10 changes: 5 additions & 5 deletions ptf/tests/ptf/fabric_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def set_ingress_port_vlan(self, ingress_port,
inner_vlan_id_mask_ = stringify(4095, 2)
matches.append(self.Ternary("inner_vlan_id", inner_vlan_id_, inner_vlan_id_mask_))

self.send_request_add_entry_to_action(
return self.send_request_add_entry_to_action(
"filtering.ingress_port_vlan",
matches,
"filtering." + action_name, action_params,
Expand Down Expand Up @@ -1079,11 +1079,11 @@ def runPacketInTest(self, pkt, eth_type, tagged=False, vlan_id=10):
class SpgwSimpleTest(IPv4UnicastTest):

def read_pkt_count(self, c_name, idx):
counter = self.read_counter(c_name, idx, typ="PACKETS")
counter = self.read_indirect_counter(c_name, idx, typ="PACKETS")
return counter.data.packet_count

def read_byte_count(self, c_name, idx):
counter = self.read_counter(c_name, idx, typ="BYTES")
counter = self.read_indirect_counter(c_name, idx, typ="BYTES")
return counter.data.byte_count

def add_ue_pool(self, ip_prefix, prefix_len):
Expand Down Expand Up @@ -1592,11 +1592,11 @@ def setup_bng(self, pppoe_cp_codes=PPPOED_CODES):
self.set_upstream_pppoe_cp_table(pppoe_codes=pppoe_cp_codes)

def read_pkt_count(self, c_name, line_id):
counter = self.read_counter(c_name, line_id, typ="PACKETS")
counter = self.read_indirect_counter(c_name, line_id, typ="PACKETS")
return counter.data.packet_count

def read_byte_count(self, c_name, line_id):
counter = self.read_counter(c_name, line_id, typ="BYTES")
counter = self.read_indirect_counter(c_name, line_id, typ="BYTES")
return counter.data.byte_count

def read_pkt_count_upstream(self, type, line_id):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"build_date": "Thu Jun 11 16:39:05 2020",
"build_date": "Mon Jun 29 19:46:16 2020",
"schema_version": "1.11.0",
"compiler_version": "9.2.0",
"target": "tofino",
Expand Down Expand Up @@ -90338,6 +90338,6 @@
]
}
],
"run_id": "638b4807bc4cce43",
"run_id": "ba297d21a3861413",
"driver_options": { "hash_parity_enabled": false, "high_availability_enabled": true }
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"build_date": "Thu Jun 11 16:38:33 2020",
"build_date": "Mon Jun 29 19:45:51 2020",
"schema_version": "1.11.0",
"compiler_version": "9.2.0",
"target": "tofino",
Expand Down Expand Up @@ -90338,6 +90338,6 @@
]
}
],
"run_id": "51a550de853ecc83",
"run_id": "f93816109dba282d",
"driver_options": { "hash_parity_enabled": false, "high_availability_enabled": true }
}
Binary file not shown.
Loading

0 comments on commit 9424cb6

Please sign in to comment.