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.

195 line
6.3KB

  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. {%- if network.openvswitch.get('vhost_socket_dir',{}).get('path') %}
  50. {%- do ovs_options.append("vhost-sock-dir=\""+network.openvswitch.vhost_socket_dir.path+"\"") %}
  51. {%- endif %}
  52. {%- for option in ovs_options %}
  53. linux_network_dpdk_ovs_option_{{ option }}:
  54. cmd.run:
  55. - name: 'ovs-vsctl set Open_vSwitch . other_config:{{ option }}'
  56. - watch_in:
  57. - service: service_openvswitch
  58. - require:
  59. - cmd: linux_network_dpdk_ovs_service
  60. - unless: |
  61. ovs-vsctl get Open_vSwitch . other_config | grep '{{ option }}'
  62. {%- endfor %}
  63. service_openvswitch:
  64. service.running:
  65. - name: openvswitch-switch
  66. - enable: true
  67. - watch:
  68. - cmd: linux_network_dpdk_ovs_service
  69. {%- endif %}
  70. {%- for interface_name, interface in network.interface.iteritems() if interface.get('enabled', True) %}
  71. {%- if interface.type == "dpdk_ovs_bond" %}
  72. {%- set bond_interfaces = {} %}
  73. {%- for iface_name, iface in network.interface.iteritems() if iface.get('enabled', True) and iface.get('bond',"") == interface_name %}
  74. {#- Get list of child interfaces #}
  75. {%- do bond_interfaces.update({iface_name: iface}) %}
  76. {%- endfor %}
  77. linux_network_dpdk_bond_interface_{{ interface_name }}:
  78. cmd.run:
  79. - 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 %}"
  80. - unless: "ovs-vsctl show | grep {{ interface_name }}"
  81. - require:
  82. - cmd: linux_network_dpdk_bridge_interface_{{ interface.bridge }}
  83. linux_network_dpdk_bond_mode_{{ interface_name }}:
  84. cmd.run:
  85. - name: "ovs-vsctl set port {{ interface_name }} bond_mode={{ interface.mode }}"
  86. - unless: "ovs-appctl bond/show {{ interface_name }} | grep {{ interface.mode }}"
  87. - require:
  88. - cmd: linux_network_dpdk_bond_interface_{{ interface_name }}
  89. {%- elif interface.type == 'dpdk_ovs_bridge' %}
  90. linux_network_dpdk_bridge_interface_{{ interface_name }}:
  91. cmd.run:
  92. - name: "ovs-vsctl add-br {{ interface_name }} -- set bridge {{ interface_name }} datapath_type=netdev"
  93. - unless: "ovs-vsctl show | grep {{ interface_name }}"
  94. {# OVS dpdk needs ip address for vxlan termination on bridge br-prv #}
  95. {%- if interface.address is defined %}
  96. {# create override for openvswitch dependency for dpdk br-prv #}
  97. /etc/systemd/system/ifup@{{ interface_name }}.service.d/override.conf:
  98. file.managed:
  99. - makedirs: true
  100. - require:
  101. - cmd: linux_network_dpdk_bridge_interface_{{ interface_name }}
  102. - contents: |
  103. [Unit]
  104. Requires=openvswitch-switch.service
  105. After=openvswitch-switch.service
  106. {# enforce ip address and mtu for ovs dpdk br-prv #}
  107. /etc/network/interfaces.d/ifcfg-{{ interface_name }}:
  108. file.managed:
  109. - contents: |
  110. auto {{ interface_name }}
  111. iface {{ interface_name }} inet static
  112. address {{ interface.address }}
  113. netmask {{ interface.netmask }}
  114. {%- if interface.mtu is defined %}
  115. mtu {{ interface.mtu }}
  116. {%- endif %}
  117. - require:
  118. - file: /etc/systemd/system/ifup@{{ interface_name }}.service.d/override.conf
  119. {%- endif %}
  120. {%- elif interface.type == 'dpdk_ovs_port' and interface.bridge is defined %}
  121. linux_network_dpdk_bridge_port_interface_{{ interface_name }}:
  122. cmd.run:
  123. - name: "ovs-vsctl add-port {{ interface.bridge }} dpdk0 -- set Interface dpdk0 type=dpdk options:dpdk-devargs={{ interface.pci }}"
  124. - unless: "ovs-vsctl show | grep dpdk0"
  125. - require:
  126. - cmd: linux_network_dpdk_bridge_interface_{{ interface.bridge }}
  127. {%- endif %}
  128. {# Multiqueue n_rxq, pmd_rxq_affinity and mtu setup on interfaces #}
  129. {%- if interface.type == 'dpdk_ovs_port' %}
  130. {%- if interface.n_rxq is defined %}
  131. linux_network_dpdk_bridge_port_interface_n_rxq_{{ interface_name }}:
  132. cmd.run:
  133. - name: "ovs-vsctl set Interface {{ interface_name }} options:n_rxq={{ interface.n_rxq }} "
  134. - unless: |
  135. ovs-vsctl get Interface {{ interface_name }} options | grep 'n_rxq="{{ interface.n_rxq }}"'
  136. {%- endif %}
  137. {%- if interface.pmd_rxq_affinity is defined %}
  138. linux_network_dpdk_bridge_port_interface_pmd_rxq_affinity_{{ interface_name }}:
  139. cmd.run:
  140. - name: "ovs-vsctl set Interface {{ interface_name }} other_config:pmd-rxq-affinity={{ interface.pmd_rxq_affinity }} "
  141. - unless: |
  142. ovs-vsctl get Interface {{ interface_name }} other_config | grep 'pmd-rxq-affinity="{{ interface.pmd_rxq_affinity }}"'
  143. {%- endif %}
  144. {%- if interface.mtu is defined %}
  145. {# MTU ovs dpdk setup on interfaces #}
  146. linux_network_dpdk_bridge_port_interface_mtu_{{ interface_name }}:
  147. cmd.run:
  148. - name: "ovs-vsctl set Interface {{ interface_name }} mtu_request={{ interface.mtu }} "
  149. - unless: "ovs-vsctl get Interface {{ interface_name }} mtu_request | grep {{ interface.mtu }}"
  150. {%- endif %}
  151. {%- endif %}
  152. {%- endfor %}
  153. {%- endif %}