Enable PVP and PVVP deployments for Vanilla OVS
[vswitchperf.git] / vnfs / qemu / qemu_virtio_net.py
1 # Copyright 2016 Intel Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #   http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 """Automation of QEMU hypervisor for launching virtio-net enabled guests.
16 """
17
18 import logging
19 from vnfs.qemu.qemu import IVnfQemu
20 from conf import settings as S
21 from conf import get_test_param
22 from tools import tasks
23
24 class QemuVirtioNet(IVnfQemu):
25     """
26     Control an instance of QEMU with virtio-net guest communication.
27     """
28
29     def __init__(self):
30         """
31         Initialisation function.
32         """
33         super(QemuVirtioNet, self).__init__()
34         self._logger = logging.getLogger(__name__)
35
36         # insert vanilla ovs specific modules
37         tasks.run_task(['sudo', 'modprobe', 'vhost_net'], self._logger,
38                        'Loading vhost_net module...', True)
39
40         # calculate indexes of guest devices (e.g. charx, dpdkvhostuserx)
41         i = self._number * 2
42         if1 = str(i)
43         if2 = str(i + 1)
44         self._net1 = S.getValue('VANILLA_NIC1_NAME')[self._number]
45         self._net2 = S.getValue('VANILLA_NIC2_NAME')[self._number]
46
47         self._cmd += ['-netdev',
48                       'type=tap,id=' + self._net1 +
49                       ',script=no,downscript=no,' +
50                       'ifname=tap' + if1 + ',vhost=on',
51                       '-device',
52                       'virtio-net-pci,mac=' +
53                       S.getValue('GUEST_NET1_MAC')[self._number] +
54                       ',netdev=' + self._net1 + ',csum=off,gso=off,' +
55                       'guest_tso4=off,guest_tso6=off,guest_ecn=off',
56                       '-netdev',
57                       'type=tap,id=' + self._net2 +
58                       ',script=no,downscript=no,' +
59                       'ifname=tap' + if2 + ',vhost=on',
60                       '-device',
61                       'virtio-net-pci,mac=' +
62                       S.getValue('GUEST_NET2_MAC')[self._number] +
63                       ',netdev=' + self._net2 + ',csum=off,gso=off,' +
64                       'guest_tso4=off,guest_tso6=off,guest_ecn=off',
65                      ]
66
67     # helper functions
68
69     def _config_guest_loopback(self):
70         """
71         Configure VM to perform forwarding between NICs
72         """
73
74         # Disable services (F16)
75         self.execute_and_wait('systemctl stop iptables.service')
76         self.execute_and_wait('systemctl stop irqbalance.service')
77
78         nic1_name = get_test_param('vanilla_nic1_name', self._net1)
79         self.execute('ifconfig ' + nic1_name + ' ' +
80                      S.getValue('VANILLA_NIC1_IP_CIDR')[self._number])
81
82         nic2_name = get_test_param('vanilla_nic2_name', self._net2)
83         self.execute('ifconfig ' + nic2_name + ' ' +
84                      S.getValue('VANILLA_NIC2_IP_CIDR')[self._number])
85
86         # configure linux bridge
87         self.execute('brctl addbr br0')
88         self.execute('brctl addif br0 ' + self._net1 + ' ' + self._net2)
89         self.execute('ifconfig br0 ' +
90                      S.getValue('VANILLA_BRIDGE_IP')[self._number])
91
92         # Add the arp entries for the IXIA ports and the bridge you are using.
93         # Use command line values if provided.
94         trafficgen_mac = get_test_param('vanilla_tgen_port1_mac',
95                                         S.getValue('VANILLA_TGEN_PORT1_MAC'))
96         trafficgen_ip = get_test_param('vanilla_tgen_port1_ip',
97                                        S.getValue('VANILLA_TGEN_PORT1_IP'))
98
99         self.execute('arp -s ' + trafficgen_ip + ' ' + trafficgen_mac)
100
101         trafficgen_mac = get_test_param('vanilla_tgen_port2_mac',
102                                         S.getValue('VANILLA_TGEN_PORT2_MAC'))
103         trafficgen_ip = get_test_param('vanilla_tgen_port2_ip',
104                                        S.getValue('VANILLA_TGEN_PORT2_IP'))
105
106         self.execute('arp -s ' + trafficgen_ip + ' ' + trafficgen_mac)
107
108         # Enable forwarding
109         self.execute('sysctl -w net.ipv4.ip_forward=1')
110
111         # Controls source route verification
112         # 0 means no source validation
113         self.execute('sysctl -w net.ipv4.conf.all.rp_filter=0')
114         self.execute('sysctl -w net.ipv4.conf.' + self._net1 + '.rp_filter=0')
115         self.execute('sysctl -w net.ipv4.conf.' + self._net2 + '.rp_filter=0')