Saltstack Official Linux Formula
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

dpdk.sls 7.1KB

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