| 1 |
|
| 2 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 3 |
# not use this file except in compliance with the License. You may obtain |
| 4 |
# a copy of the License at |
| 5 |
# |
| 6 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
# |
| 8 |
# Unless required by applicable law or agreed to in writing, software |
| 9 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 |
# License for the specific language governing permissions and limitations |
| 12 |
# under the License. |
| 13 |
|
| 14 |
import argparse |
| 15 |
import os |
| 16 |
import pathlib |
| 17 |
import subprocess # nosec: B404 |
| 18 |
|
| 19 |
|
| 20 |
def main(): |
| 21 |
parser = argparse.ArgumentParser( |
| 22 |
prog='i40e_sysfs_command', |
| 23 |
usage='1. VLANs to VF mirroring: %(prog)s <phy_device_name>' |
| 24 |
'<dest_vf_index> <vlan_mirror> <add|rem> <vlan_ranges_string>' |
| 25 |
'2. VF to VF mirroring: %(prog)s <phy_device_name>' |
| 26 |
'<src_vf_index> <ingress_mirror|egress_mirror> <add|rem> ' |
| 27 |
'<dest_vf_index>' |
| 28 |
) |
| 29 |
parser.add_argument('phy_device_name') |
| 30 |
parser.add_argument('vf_index', |
| 31 |
help='In case of VLANs to VF mirroring this is ' |
| 32 |
'dest_vf_index, in case of VF to VF mirroring this ' |
| 33 |
'is src_vf_index') |
| 34 |
parser.add_argument('mirror', |
| 35 |
help='In case of VLANs to VF mirroring this is ' |
| 36 |
'vlan_mirror, in case of VF to VF mirroring this ' |
| 37 |
'is ingress_mirror or egress_mirror') |
| 38 |
parser.add_argument('add_rem', help="This can be the string add or rem") |
| 39 |
parser.add_argument('vlan_range_or_dest_vf', |
| 40 |
help='In case of VLANs to VF mirroring this is ' |
| 41 |
'vlan_ranges_string, in case of VF to VF mirroring' |
| 42 |
'this is dest_vf_index') |
| 43 |
args = parser.parse_args() |
| 44 |
|
| 45 |
my_device = pathlib.Path("/sys/class/net/%s/device/sriov/%s/%s" % ( |
| 46 |
args.phy_device_name, args.vf_index, args.mirror |
| 47 |
)) |
| 48 |
if my_device.is_file(): |
| 49 |
subprocess.run( |
| 50 |
['/usr/bin/echo', args.add_rem, args.vlan_range_or_dest_vf, |
| 51 |
'>', '/sys/class/net/%s/device/sriov/%s/%s' % ( |
| 52 |
args.phy_device_name, args.vf_index, |
| 53 |
args.mirror)], check=True, shell=False) # nosec B603 |
| 54 |
else: |
| 55 |
print("Invalid sysfs path: /sys/class/net/%s/device/sriov/%s/%s" % |
| 56 |
(args.phy_device_name, args.vf_index, args.mirror)) |
| 57 |
os._exit(1) |
| 58 |
|
| 59 |
|
| 60 |
if __name__ == '__main__': |
| 61 |
main() |