Saltstack Official Linux Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dpdk.sls 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. {%- from "linux/map.jinja" import network with context %}
  2. {%- from "linux/map.jinja" import system with context %}
  3. {%- if network.dpdk.enabled %}
  4. linux_dpdk_pkgs:
  5. pkg.installed:
  6. - pkgs: {{ network.dpdk_pkgs }}
  7. linux_dpdk_kernel_module:
  8. kmod.present:
  9. - name: {{ network.dpdk.driver }}
  10. - require:
  11. - pkg: linux_dpdk_pkgs
  12. - require_in:
  13. - service: linux_network_dpdk_service
  14. /etc/dpdk/interfaces:
  15. file.managed:
  16. - source: salt://linux/files/dpdk_interfaces
  17. - template: jinja
  18. - user: root
  19. - group: root
  20. - mode: 644
  21. - require:
  22. - pkg: linux_dpdk_pkgs
  23. linux_network_dpdk_service:
  24. service.running:
  25. - enable: true
  26. - name: dpdk
  27. - watch:
  28. - file: /etc/dpdk/interfaces
  29. {%- if network.openvswitch is defined %}
  30. openvswitch_dpdk_pkgs:
  31. pkg.installed:
  32. - pkgs:
  33. - openvswitch-switch-dpdk
  34. - openvswitch-switch
  35. - bridge-utils
  36. linux_network_dpdk_ovs_service:
  37. cmd.run:
  38. - name: "ovs-vsctl --no-wait set Open_vSwitch . other_config:dpdk-init=true"
  39. - require:
  40. - service: linux_network_dpdk_service
  41. - unless: 'ovs-vsctl get Open_vSwitch . other_config | grep "dpdk-init=\"true\""'
  42. {%- set ovs_options = [
  43. "pmd-cpu-mask=\""+network.openvswitch.pmd_cpu_mask+"\"",
  44. "dpdk-socket-mem=\""+network.openvswitch.dpdk_socket_mem+"\"",
  45. "dpdk-lcore-mask=\""+network.openvswitch.dpdk_lcore_mask+"\"",
  46. "dpdk-extra=\"-n "+network.openvswitch.memory_channels+" --vhost-owner libvirt-qemu:kvm --vhost-perm 0664\""
  47. ]
  48. %}
  49. {%- for option in ovs_options %}
  50. linux_network_dpdk_ovs_option_{{ option }}:
  51. cmd.run:
  52. - name: 'ovs-vsctl set Open_vSwitch . other_config:{{ option }}'
  53. - watch_in:
  54. - service: service_openvswitch
  55. - require:
  56. - cmd: linux_network_dpdk_ovs_service
  57. - unless: |
  58. ovs-vsctl get Open_vSwitch . other_config | grep '{{ option }}'
  59. {%- endfor %}
  60. service_openvswitch:
  61. service.running:
  62. - name: openvswitch-switch
  63. - enable: true
  64. - watch:
  65. - cmd: linux_network_dpdk_ovs_service
  66. {%- endif %}
  67. {%- for interface_name, interface in network.interface.iteritems() if interface.get('enabled', True) %}
  68. {%- if interface.type == "dpdk_ovs_bond" %}
  69. {%- set bond_interfaces = {} %}
  70. {%- for iface_name, iface in network.interface.iteritems() if iface.get('enabled', True) and iface.get('bond',"") == interface_name %}
  71. {#- Get list of child interfaces #}
  72. {%- do bond_interfaces.update({iface_name: iface}) %}
  73. {%- endfor %}
  74. linux_network_dpdk_bond_interface_{{ interface_name }}:
  75. cmd.run:
  76. - name: "ovs-vsctl add-bond {{ interface.bridge }} {{ interface_name }} {{ bond_interfaces.keys()|join(' ') }} {% for iface_name, iface in bond_interfaces.iteritems() %}-- set Interface {{ iface_name }} type=dpdk options:dpdk-devargs={{ iface.pci }} {% endfor %}"
  77. - unless: "ovs-vsctl show | grep {{ interface_name }}"
  78. - require:
  79. - cmd: linux_network_dpdk_bridge_interface_{{ interface.bridge }}
  80. linux_network_dpdk_bond_mode_{{ interface_name }}:
  81. cmd.run:
  82. - name: "ovs-vsctl set port {{ interface_name }} bond_mode={{ interface.mode }}"
  83. - unless: "ovs-appctl bond/show {{ interface_name }} | grep {{ interface.mode }}"
  84. - require:
  85. - cmd: linux_network_dpdk_bond_interface_{{ interface_name }}
  86. {%- elif interface.type == 'dpdk_ovs_bridge' %}
  87. linux_network_dpdk_bridge_interface_{{ interface_name }}:
  88. cmd.run:
  89. - name: "ovs-vsctl add-br {{ interface_name }} -- set bridge {{ interface_name }} datapath_type=netdev"
  90. - unless: "ovs-vsctl show | grep {{ interface_name }}"
  91. {# OVS dpdk needs ip address for vxlan termination on bridge br-prv #}
  92. {%- if interface.address is defined %}
  93. {# create override for openvswitch dependency for dpdk br-prv #}
  94. /etc/systemd/system/ifup@{{ interface_name }}.service.d/override.conf:
  95. file.managed:
  96. - require:
  97. - cmd: linux_network_dpdk_bridge_interface_{{ interface_name }}
  98. - contents: |
  99. [Unit]
  100. Requires=openvswitch-switch.service
  101. After=openvswitch-switch.service
  102. {# enforce ip address and mtu for ovs dpdk br-prv #}
  103. /etc/network/interfaces.d/ifcfg-{{ interface_name }}:
  104. file.managed:
  105. - contents: |
  106. auto {{ interface_name }}
  107. iface {{ interface_name }} inet static
  108. address {{ interface.address }}
  109. netmask {{ interface.netmask }}
  110. {%- if interface.mtu is defined %}
  111. mtu {{ interface.mtu }}
  112. {%- endif %}
  113. - require:
  114. - file: /etc/systemd/system/ifup@{{ interface_name }}.service.d/override.conf
  115. {%- endif %}
  116. {%- elif interface.type == 'dpdk_ovs_port' and interface.bridge is defined %}
  117. linux_network_dpdk_bridge_port_interface_{{ interface_name }}:
  118. cmd.run:
  119. - name: "ovs-vsctl add-port {{ interface.bridge }} dpdk0 -- set Interface dpdk0 type=dpdk options:dpdk-devargs={{ interface.pci }}"
  120. - unless: "ovs-vsctl show | grep dpdk0"
  121. - require:
  122. - cmd: linux_network_dpdk_bridge_interface_{{ interface.bridge }}
  123. {# Multiqueue n_rxq and mtu setup on interfaces #}
  124. {%- elif interface.type == 'dpdk_ovs_port' and (interface.n_rxq is defined or interface.mtu is defined) %}
  125. {%- if interface.n_rxq is defined %}
  126. linux_network_dpdk_bridge_port_interface_n_rxq_{{ interface_name }}:
  127. cmd.run:
  128. - name: "ovs-vsctl set Interface {{ interface_name }} options:n_rxq={{ interface.n_rxq }} "
  129. - unless: |
  130. ovs-vsctl get Interface {{ interface_name }} options | grep 'n_rxq="{{ interface.n_rxq }}"'
  131. {%- endif %}
  132. {%- if interface.mtu is defined %}
  133. {# MTU ovs dpdk setup on interfaces #}
  134. linux_network_dpdk_bridge_port_interface_mtu_{{ interface_name }}:
  135. cmd.run:
  136. - name: "ovs-vsctl set Interface {{ interface_name }} mtu_request={{ interface.mtu }} "
  137. - unless: "ovs-vsctl get Interface {{ interface_name }} mtu_request | grep {{ interface.mtu }}"
  138. {%- endif %}
  139. {%- endif %}
  140. {%- endfor %}
  141. {%- endif %}