From c37d274d4eee73148b7f0dbe0ec83a3a215439e3 Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Tue, 29 Aug 2023 17:52:49 +0800 Subject: [PATCH] gen_setup.py: Add eth flowtype proto rx filter processing to json i225/i226 is using ethtool flowtype proto filtering to steer receiving packets to the correct queue. We are now adding this functionality to support ethtool flowtype. It will filter packet according to proto type to the specific queue. For example, we are steering ptp packets to queue 0. Signed-off-by: Noor Azura Ahmad Tarmizi Signed-off-by: Goh, Wei Sheng --- json/gen_setup.py | 50 ++++++++++++++++++++++++++++++-- json/i225/opcua-pkt1a-tsn.json.i | 11 +++++++ json/i225/opcua-pkt1b-tsn.json.i | 11 +++++++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/json/gen_setup.py b/json/gen_setup.py index 4445c5d..3fd93c3 100644 --- a/json/gen_setup.py +++ b/json/gen_setup.py @@ -50,6 +50,15 @@ def delete_qdiscs(iface): proc = sh_run(cmd) sh_run('sleep 5') +def delete_flowtype_filter(iface): + #print('Deleting existing flow type filters. Assuming we add max 4 (63-60) rules only') + for rule_ID in range (60,64): + del_flowtype_filt_cmd = "ethtool -N {} ".format(iface) + del_flowtype_filt_cmd += "delete {} ".format(rule_ID) + del_flowtype_filt_cmd += "2> /dev/null" + proc = sh_run(del_flowtype_filt_cmd) + sh_run('sleep 1') + def init_ingress(iface, show_qdisc_cmd): clear_rx_cmd = "tc qdisc del dev {} parent ffff:".format(iface) add_ingress_cmd = "tc qdisc add dev {} ingress".format(iface) @@ -71,6 +80,40 @@ def set_vlanrx(iface, config, show_qdisc_cmd): output = sh_run(set_vlanrx_cmd) +def set_flowtype_ether_proto(iface, config): + + if not 'proto' in config: + err_exit('Proto not defined in flow type filter config') + if not 'rx_queue' in config: + err_exit('Queue not defined in flow type filter config') + + proto = str(config['proto']) + rx_queue = str(config['rx_queue']) + + set_flowtype_filter_rx_cmd = "ethtool -N {} ".format(iface) + set_flowtype_filter_rx_cmd += "flow-type ether proto {} ".format(proto) + set_flowtype_filter_rx_cmd += "queue {} ".format(rx_queue) + + output = sh_run(set_flowtype_filter_rx_cmd) + sh_run('sleep 1') + +def process_eth_flowtype_ether_proto(data): + + # If file is empty then we do nothing + if len(data) == 0: + return + + if not 'interface' in data: + err_exit('Interface not found in eth flowtype ether proto config') + + interface = data.get('interface') + + delete_flowtype_filter(interface) + + if 'ether_proto' in data: + #print('Setup flowtype ether proto RX steering') + for each_config in data["ether_proto"]: + set_flowtype_ether_proto(interface, each_config) def set_taprio(iface, maps, config, basetime, clkid): schedules = "" @@ -345,8 +388,7 @@ def process_phc2sys(obj): ' leap61 0 leap59 0 currentUtcOffsetValid 0 ptpTimescale 1 timeTraceable' ' 1 frequencyTraceable 0 timeSource 0xa0', '"'] run_with_out(arglist, '/var/log/pmc.log') - - sh_run('sleep 2') + sh_run('sleep 30') # phc2sys -c CLOCK_REALTIME --step_threshold=1 -s eth0 \ # --transportSpecific=1 -O 0 -w -ml 7 @@ -464,6 +506,10 @@ def main(): if 'phc2sys' in data: process_phc2sys(data['phc2sys']) + if 'eth_flowtype_ether_proto' in data: + for each_eth_flow_type in data["eth_flowtype_ether_proto"]: + process_eth_flowtype_ether_proto(each_eth_flow_type) + if 'custom_sync_a' in data: process_custom_a(data['custom_sync_a']) if 'custom_sync_b' in data: process_custom_b(data['custom_sync_b']) diff --git a/json/i225/opcua-pkt1a-tsn.json.i b/json/i225/opcua-pkt1a-tsn.json.i index 03a1b05..abdb9f1 100644 --- a/json/i225/opcua-pkt1a-tsn.json.i +++ b/json/i225/opcua-pkt1a-tsn.json.i @@ -53,5 +53,16 @@ } ] } + ], + "eth_flowtype_ether_proto": [ + { + "interface": "_PREPROCESS_STR_interface", + "ether_proto": [ + { + "proto": "0x88f7", + "rx_queue": 0 + } + ] + } ] } diff --git a/json/i225/opcua-pkt1b-tsn.json.i b/json/i225/opcua-pkt1b-tsn.json.i index f68e399..b026740 100644 --- a/json/i225/opcua-pkt1b-tsn.json.i +++ b/json/i225/opcua-pkt1b-tsn.json.i @@ -38,5 +38,16 @@ } ] } + ], + "eth_flowtype_ether_proto": [ + { + "interface": "_PREPROCESS_STR_interface", + "ether_proto": [ + { + "proto": "0x88f7", + "rx_queue": 0 + } + ] + } ] }