1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 from robot.api import logger
16 __all__ = ['TrafficGenerator']
18 class TrafficGenerator(object):
27 def send_traffic_on(self, node, tx_port, rx_port, duration, rate,
32 (ret, stdout, stderr) = ssh.exec_command(
33 "sh -c 'cd MoonGen && sudo -S build/MoonGen "
34 "rfc2544/benchmarks/vpp-frameloss.lua --txport 0 --rxport 1 "
35 "--duration {0} --rate {1} --framesize {2}'".format(
36 duration, rate, framesize),
37 timeout=int(duration)+60)
43 for line in stdout.splitlines():
47 logger.info('TrafficGen result: {0}'.format(self._result))
49 self._loss = self._result.split(', ')[3].split('=')[1]
53 def no_traffic_loss_occured(self):
54 if self._loss is None:
55 raise Exception('The traffic generation has not been issued')
57 raise Exception('Traffic loss occured: {0}'.format(self._loss))