1 # Copyright (c) 2018 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 from yardstick.common import exceptions
16 from yardstick.common import utils
17 from yardstick.network_services.traffic_profile import base as tp_base
20 class PktgenTrafficProfile(tp_base.TrafficProfile):
21 """This class handles Pktgen Trex Traffic profile execution"""
23 def __init__(self, tp_config): # pragma: no cover
24 super(PktgenTrafficProfile, self).__init__(tp_config)
28 def init(self, host, port): # pragma: no cover
29 """Initialize control parameters
31 :param host: (str) ip or host name
32 :param port: (int) TCP socket port number for Lua commands
38 if utils.send_socket_command(self._host, self._port,
39 'pktgen.start("0")') != 0:
40 raise exceptions.PktgenActionError(action='start')
43 if utils.send_socket_command(self._host, self._port,
44 'pktgen.stop("0")') != 0:
45 raise exceptions.PktgenActionError(action='stop')
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')
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')
57 if utils.send_socket_command(self._host, self._port, 'help') != 0:
58 raise exceptions.PktgenActionError(action='help')
60 def execute_traffic(self, *args, **kwargs): # pragma: no cover