Improve IXIA TG Rx/TX throughput calculation
[yardstick.git] / yardstick / network_services / traffic_profile / pktgen.py
1 # Copyright (c) 2018 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 from yardstick.common import exceptions
16 from yardstick.common import utils
17 from yardstick.network_services.traffic_profile import base as tp_base
18
19
20 class PktgenTrafficProfile(tp_base.TrafficProfile):
21     """This class handles Pktgen Trex Traffic profile execution"""
22
23     def __init__(self, tp_config):  # pragma: no cover
24         super(PktgenTrafficProfile, self).__init__(tp_config)
25         self._host = None
26         self._port = None
27
28     def init(self, host, port):  # pragma: no cover
29         """Initialize control parameters
30
31         :param host: (str) ip or host name
32         :param port: (int) TCP socket port number for Lua commands
33         """
34         self._host = host
35         self._port = port
36
37     def start(self):
38         if utils.send_socket_command(self._host, self._port,
39                                      'pktgen.start("0")') != 0:
40             raise exceptions.PktgenActionError(action='start')
41
42     def stop(self):
43         if utils.send_socket_command(self._host, self._port,
44                                      'pktgen.stop("0")') != 0:
45             raise exceptions.PktgenActionError(action='stop')
46
47     def rate(self, rate):
48         command = 'pktgen.set("0", "rate", ' + str(rate) + ')'
49         if utils.send_socket_command(self._host, self._port, command) != 0:
50             raise exceptions.PktgenActionError(action='rate')
51
52     def clear_all_stats(self):
53         if utils.send_socket_command(self._host, self._port, 'clr') != 0:
54             raise exceptions.PktgenActionError(action='clear all stats')
55
56     def help(self):
57         if utils.send_socket_command(self._host, self._port, 'help') != 0:
58             raise exceptions.PktgenActionError(action='help')
59
60     def execute_traffic(self, *args, **kwargs):  # pragma: no cover
61         pass