tdc_batch.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python3
  2. """
  3. tdc_batch.py - a script to generate TC batch file
  4. Copyright (C) 2017 Chris Mi <chrism@mellanox.com>
  5. """
  6. import argparse
  7. parser = argparse.ArgumentParser(description='TC batch file generator')
  8. parser.add_argument("device", help="device name")
  9. parser.add_argument("file", help="batch file name")
  10. parser.add_argument("-n", "--number", type=int,
  11. help="how many lines in batch file")
  12. parser.add_argument("-o", "--skip_sw",
  13. help="skip_sw (offload), by default skip_hw",
  14. action="store_true")
  15. parser.add_argument("-s", "--share_action",
  16. help="all filters share the same action",
  17. action="store_true")
  18. parser.add_argument("-p", "--prio",
  19. help="all filters have different prio",
  20. action="store_true")
  21. args = parser.parse_args()
  22. device = args.device
  23. file = open(args.file, 'w')
  24. number = 1
  25. if args.number:
  26. number = args.number
  27. skip = "skip_hw"
  28. if args.skip_sw:
  29. skip = "skip_sw"
  30. share_action = ""
  31. if args.share_action:
  32. share_action = "index 1"
  33. prio = "prio 1"
  34. if args.prio:
  35. prio = ""
  36. if number > 0x4000:
  37. number = 0x4000
  38. index = 0
  39. for i in range(0x100):
  40. for j in range(0x100):
  41. for k in range(0x100):
  42. mac = ("{:02x}:{:02x}:{:02x}".format(i, j, k))
  43. src_mac = "e4:11:00:" + mac
  44. dst_mac = "e4:12:00:" + mac
  45. cmd = ("filter add dev {} {} protocol ip parent ffff: flower {} "
  46. "src_mac {} dst_mac {} action drop {}".format
  47. (device, prio, skip, src_mac, dst_mac, share_action))
  48. file.write("{}\n".format(cmd))
  49. index += 1
  50. if index >= number:
  51. file.close()
  52. exit(0)