OpenContrail DPDK support

Enable DPDK vrouter agent installation and configuration

Change-Id: I846267ea66a7cf8827881cbdbdd5be328707bc6e
Epic: PROD-9023
diff --git a/README.rst b/README.rst
index fb8ebbe..574d476 100644
--- a/README.rst
+++ b/README.rst
@@ -688,6 +688,21 @@
         rpc_port: 9160
       ....
 
+DPDK vRouter
+-------------
+
+.. code-block:: yaml
+
+    opencontrail:
+      compute:
+        dpdk:
+          enabled: true
+          taskset: 0x0000003C00003C
+        interface:
+          mac_address: 90:e2:ba:7c:22:e1
+          pci: 0000:81:00.1
+      ...
+
 Usage
 =====
 
diff --git a/opencontrail/compute.sls b/opencontrail/compute.sls
index 8d3d063..ea66e24 100644
--- a/opencontrail/compute.sls
+++ b/opencontrail/compute.sls
@@ -69,8 +69,61 @@
   - require_in:
     - service: opencontrail_compute_services
 
+/etc/udev/rules.d/vhost-net.rules:
+  file.managed:
+  - contents: 'KERNEL=="vhost-net", GROUP="kvm", MODE="0660"'
+
+/etc/modules:
+  file.append:
+  - text: "vhost-net"
+  - require:
+    - file: /etc/udev/rules.d/vhost-net.rules
+
 {% endif %}
 
+{%- if compute.dpdk.enabled %}
+
+opencontrail_vrouter_package:
+  pkg.installed:
+  - names:
+    - contrail-vrouter-dpdk
+    - contrail-vrouter-dpdk-init
+  - require_in:
+    - pkg: opencontrail_compute_packages
+
+/etc/contrail/supervisord_vrouter_files/contrail-vrouter-dpdk.ini:
+  file.managed:
+  - source: salt://opencontrail/files/{{ compute.version }}/contrail-vrouter-dpdk.ini
+  - template: jinja
+  - require:
+    - pkg: opencontrail_compute_packages
+    - pkg: opencontrail_vrouter_package
+  - require_in:
+    - service: opencontrail_compute_services
+
+modules_dpdk:
+  file.append:
+  - name: /etc/modules
+  - text: uio
+  - require:
+    - pkg: opencontrail_vrouter_package
+
+/usr/lib/contrail/if-vhost0:
+  file.managed:
+  - contents: "# Phony script as nothing to do in DPDK vRouter case."
+
+{%- else %}
+
+opencontrail_vrouter_package:
+  pkg.installed:
+  - name: contrail-vrouter-dkms
+  - require_in:
+    - pkg: opencontrail_compute_packages
+
+/etc/modprobe.d/vrouter.conf:
+  file.managed:
+  - contents: "options vrouter vr_flow_entries=2097152"
+
 {%- if network.interface.get('vhost0', {}).get('enabled', False) %}
 
 contrail_load_vrouter_kernel_module:
@@ -83,6 +136,8 @@
 
 {%- endif %}
 
+{%- endif %}
+
 opencontrail_compute_services:
   service.enabled:
   - names: {{ compute.services }}
diff --git a/opencontrail/files/3.0/agent_param b/opencontrail/files/3.0/agent_param
index ae5ed07..22560b5 100644
--- a/opencontrail/files/3.0/agent_param
+++ b/opencontrail/files/3.0/agent_param
@@ -2,9 +2,9 @@
 LOG=/var/log/contrail.log
 CONFIG=/etc/contrail/contrail-vrouter-agent.conf
 prog=/usr/bin/contrail-vrouter-agent
-kmod="vrouter vr_flow_entries=1048576"
+kmod="vrouter"
 pname=contrail-vrouter-agent
-LIBDIR=/usr/lib64
+LIBDIR=/usr/lib
 DEVICE=vhost0
 dev={{ compute.interface.dev }}
 vgw_subnet_ip=__VGW_SUBNET_IP__
diff --git a/opencontrail/files/3.0/contrail-analytics-api.conf b/opencontrail/files/3.0/contrail-analytics-api.conf
index 4a0a0f5..3ccc887 100644
--- a/opencontrail/files/3.0/contrail-analytics-api.conf
+++ b/opencontrail/files/3.0/contrail-analytics-api.conf
@@ -3,7 +3,7 @@
 host_ip = {{ collector.bind.address }}
 cassandra_server_list={% for member in collector.database.members %}{{ member.host }}:9042 {% endfor %}
 http_server_port = 8090
-api_host={{ collector.discovery.host }}:8082
+api_server={{ collector.discovery.host }}:8082
 rest_api_port = {{ collector.bind.get('port', '8081') }}
 rest_api_ip = 0.0.0.0 
 log_local = 1
diff --git a/opencontrail/files/3.0/contrail-vrouter-agent.conf b/opencontrail/files/3.0/contrail-vrouter-agent.conf
index 18f66de..911fb02 100644
--- a/opencontrail/files/3.0/contrail-vrouter-agent.conf
+++ b/opencontrail/files/3.0/contrail-vrouter-agent.conf
@@ -26,6 +26,19 @@
 # Aging time for flow-records in seconds
 # flow_cache_timeout=0
 
+{%- if compute.dpdk.enabled %}
+
+# DPDK or legacy work mode
+platform=dpdk
+
+# Physical address of PCI used by dpdk
+#physical_interface_address=0000:81:00.1
+physical_interface_address={{ compute.interface.pci }}
+
+# MAC address of device used by dpdk
+physical_interface_mac={{ compute.interface.mac_address }}
+
+{%- endif %}
 # Hostname of compute-node. If this is not configured value from `hostname`
 # will be taken
 # hostname=
@@ -142,9 +155,21 @@
 # Gateway IP address for virtual host
 gateway={{ compute.interface.gateway }}
 
+# Flag to indicate if hosts in vhost subnet can be resolved by ARP
+# If set to 1 host in subnet would be resolved by ARP, if set to 0
+# all the traffic destined to hosts within subnet also go via
+# default gateway
+# subnet_hosts_resolvable=0
+
 # Physical interface name to which virtual host interface maps to
 physical_interface={{ compute.interface.dev }}
 
+# List of IP addresses assigned for the compute node other than vhost. Specify
+# this only if vhost interface is un-numbered in host-os. Agent will use one
+# of the compute_node_address to run services that need IP Address in host-os
+# (like metadata...)
+#compute_node_address = 10.204.216.28
+
 # We can have multiple gateway sections with different indices in the 
 # following format
 # [GATEWAY-0]
@@ -186,3 +211,19 @@
 # Timeout for each netns command, when the timeout is reached, the netns
 # command is killed.
 #netns_timeout=30
+
+[TASK]
+# Number of threads used by TBB
+# thread_count = 8
+# Log message if time taken to execute task exceeds a threshold (in msec)
+# log_exec_threshold = 10
+#
+# Log message if time taken to schedule task exceeds a threshold (in msec)
+# log_schedule_threshold = 25
+#
+# TBB Keepawake timer interval
+# tbb_keepawake_timeout = 20
+
+[SERVICES]
+# bgp_as_a_service_port_range - reserving set of ports to be used.
+# bgp_as_a_service_port_range=30000-35000
\ No newline at end of file
diff --git a/opencontrail/files/3.0/contrail-vrouter-dpdk.ini b/opencontrail/files/3.0/contrail-vrouter-dpdk.ini
new file mode 100644
index 0000000..781cb1c
--- /dev/null
+++ b/opencontrail/files/3.0/contrail-vrouter-dpdk.ini
@@ -0,0 +1,11 @@
+{%- from "opencontrail/map.jinja" import compute with context %}
+[program:contrail-vrouter-dpdk]
+command=taskset {{ compute.dpdk.taskset }} /usr/bin/contrail-vrouter-dpdk --no-daemon --vr_flow_entries=2097152 --vr_mpls_labels 6000 --socket-mem 1024,1024
+priority=410
+autostart=true
+killasgroup=true
+stdout_capture_maxbytes=1MB
+redirect_stderr=true
+stdout_logfile=/var/log/contrail/contrail-vrouter-dpdk-stdout.log
+stderr_logfile=/var/log/contrail/contrail-vrouter-dpdk-stderr.log
+exitcodes=0                   ; 'expected' exit codes for process (default 0,2)
diff --git a/opencontrail/map.jinja b/opencontrail/map.jinja
index 4392732..53aee1e 100644
--- a/opencontrail/map.jinja
+++ b/opencontrail/map.jinja
@@ -25,12 +25,18 @@
 
 {% set compute = salt['grains.filter_by']({
     'Debian': {
-        'pkgs': ['contrail-vrouter','contrail-vrouter-dkms', 'iproute2', 'haproxy'],
-        'services': ['supervisor-vrouter']
+        'pkgs': ['contrail-vrouter-agent', 'contrail-utils', 'iproute2', 'haproxy'],
+        'services': ['supervisor-vrouter'],
+        'dpdk': {
+            'enabled': False
+        }
     },
     'RedHat': {
-        'pkgs': ['contrail-openstack-vrouter', 'haproxy', 'contrail-vrouter-source'],
-        'services': ['supervisor-vrouter']
+        'pkgs': ['contrail-openstack-vrouter', 'contrail-utils', 'haproxy', 'contrail-vrouter-source'],
+        'services': ['supervisor-vrouter'],
+        'dpdk': {
+            'enabled': False
+        }
     },
 }, merge=pillar.opencontrail.get('compute', {})) %}
 
diff --git a/tests/pillar/vrouter_dpdk.sls b/tests/pillar/vrouter_dpdk.sls
new file mode 100644
index 0000000..35f57f3
--- /dev/null
+++ b/tests/pillar/vrouter_dpdk.sls
@@ -0,0 +1,33 @@
+opencontrail:
+  common:
+    version: 3.0
+    identity:
+      engine: keystone
+      host: 127.0.0.1
+      port: 35357
+      token: token
+      password: password
+    network:
+      engine: neutron
+      host: 127.0.0.1
+      port: 9696
+  compute:
+    version: 3.0
+    enabled: True
+    dpdk:
+      enabled: True
+      taskset: 0x0000003C00003C
+    discovery:
+      host: 127.0.0.1
+    bind:
+      address: 127.0.0.1
+    interface:
+      mac_address: 90:e2:ba:7c:22:e1
+      pci: 0000:81:00.1
+      address: 127.0.0.1
+      dev: eth0
+      gateway: 127.0.0.1
+      mask: /24
+      dns: 127.0.0.1
+      mtu: 9000
+