1 # Copyright 2016 Intel Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 """Automation of QEMU hypervisor for launching virtio-net enabled guests.
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
24 class QemuVirtioNet(IVnfQemu):
26 Control an instance of QEMU with virtio-net guest communication.
31 Initialisation function.
33 super(QemuVirtioNet, self).__init__()
34 self._logger = logging.getLogger(__name__)
36 # insert vanilla ovs specific modules
37 tasks.run_task(['sudo', 'modprobe', 'vhost_net'], self._logger,
38 'Loading vhost_net module...', True)
40 # calculate indexes of guest devices (e.g. charx, dpdkvhostuserx)
44 self._net1 = S.getValue('VANILLA_NIC1_NAME')[self._number]
45 self._net2 = S.getValue('VANILLA_NIC2_NAME')[self._number]
47 self._cmd += ['-netdev',
48 'type=tap,id=' + self._net1 +
49 ',script=no,downscript=no,' +
50 'ifname=tap' + if1 + ',vhost=on',
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',
57 'type=tap,id=' + self._net2 +
58 ',script=no,downscript=no,' +
59 'ifname=tap' + if2 + ',vhost=on',
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',
69 def _config_guest_loopback(self):
71 Configure VM to perform forwarding between NICs
74 # Disable services (F16)
75 self.execute_and_wait('systemctl stop iptables.service')
76 self.execute_and_wait('systemctl stop irqbalance.service')
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])
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])
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])
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'))
99 self.execute('arp -s ' + trafficgen_ip + ' ' + trafficgen_mac)
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'))
106 self.execute('arp -s ' + trafficgen_ip + ' ' + trafficgen_mac)
109 self.execute('sysctl -w net.ipv4.ip_forward=1')
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')