guest_binding: Add dpdk driver binding options for guests
[vswitchperf.git] / tools / pkt_fwd / testpmd.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 """VSPERF TestPMD implementation
16 """
17
18 import logging
19 import pexpect
20 from conf import settings
21 from src.dpdk import dpdk
22 from src.dpdk import TestPMDProcess
23 from tools.pkt_fwd.pkt_fwd import IPktFwd
24
25 _LOGGER = logging.getLogger(__name__)
26 _VSWITCHD_CONST_ARGS = ['--', '-i']
27
28 class TestPMD(IPktFwd):
29     """TestPMD implementation (only phy2phy deployment is supported)
30
31     This is wrapper for functionality implemented in ${DPDK}/app/test-pmd.
32
33     The method docstrings document only considerations specific to this
34     implementation. For generic information of the nature of the methods,
35     see the interface definition.
36     """
37
38     _logger = logging.getLogger()
39
40     def __init__(self):
41         vswitchd_args = settings.getValue('VSWITCHD_DPDK_ARGS')
42         vswitchd_args += _VSWITCHD_CONST_ARGS
43         vswitchd_args += settings.getValue('TESTPMD_ARGS')
44
45         self._nports = len(settings.getValue('NICS'))
46         self._fwdmode = settings.getValue('TESTPMD_FWD_MODE')
47         self._csum_layer = settings.getValue('TESTPMD_CSUM_LAYER')
48         self._csum_calc = settings.getValue('TESTPMD_CSUM_CALC')
49         self._csum_tunnel = settings.getValue('TESTPMD_CSUM_PARSE_TUNNEL')
50
51         self._testpmd = TestPMDProcess(testpmd_args=vswitchd_args)
52
53     def start(self):
54         """See IPktFwd for general description
55
56         Activates testpmd.
57         """
58         self._logger.info("Starting TestPMD...")
59         dpdk.init()
60         self._testpmd.start()
61         self._logger.info("TestPMD...Started.")
62
63         self._testpmd.send('set fwd {}'.format(self._fwdmode), 1)
64
65         for port in range(self._nports):
66             self._testpmd.send('csum set {} {} {}'.format(
67                 self._csum_layer, self._csum_calc, port), 1)
68             self._testpmd.send('csum parse_tunnel {} {}'.format(
69                 self._csum_tunnel, port), 1)
70
71         self._testpmd.send('start', 1)
72
73     def stop(self):
74         """See IPktFwd for general description
75
76         Kills testpmd.
77         """
78         try:
79             self._testpmd.send('stop')
80             self._testpmd.wait('Done.', 5)
81             self._testpmd.send('quit', 2)
82             self._testpmd.kill()
83         except pexpect.EOF:
84             pass
85         dpdk.cleanup()
86
87