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 """Performance testing traffic generator library."""
16 from robot.api import logger
18 from resources.libraries.python.ssh import SSH
19 from resources.libraries.python.topology import NodeType
20 from resources.libraries.python.topology import NodeSubTypeTG
22 __all__ = ['TrafficGenerator']
24 class TrafficGenerator(object):
25 """Traffic Generator"""
34 def initialize_traffic_generator(node, interface1, interface2):
36 :param node: Traffic generator node
37 :param interface1: PCI address of first interface
38 :param interface2: PCI address of second interface
45 trex_path = "/opt/trex-core-1.91"
47 if node['type'] != NodeType.TG:
48 raise Exception('Node type is not a TG')
49 if node['subtype'] == NodeSubTypeTG.TREX:
53 (ret, stdout, stderr) = ssh.exec_command(
54 "sh -c 'cd {0}/scripts/ && sudo modprobe uio && "
55 "sudo insmod ./ko/src/igb_uio.ko'"\
58 (ret, stdout, stderr) = ssh.exec_command(
59 "sh -c 'cd {0}/scripts/ && "
60 "sudo nohup ./t-rex-64 -i -c 4 --iom 0 > /dev/null 2>&1 &'"\
64 def teardown_traffic_generator(node):
66 :param node: Traffic generator node
71 if node['type'] != NodeType.TG:
72 raise Exception('Node type is not a TG')
73 if node['subtype'] == NodeSubTypeTG.TREX:
76 (ret, stdout, stderr) = ssh.exec_command(
77 "sh -c 'sudo pkill t-rex'")
79 def send_traffic_on(self, nodes_info, duration, rate,
80 framesize, traffic_type):
81 """Send traffic from all configured interfaces on TG
82 :param nodes_info: Dictionary containing information on all nodes
84 :param duration: Duration of test traffic generation in seconds
85 :param rate: Percentage of linerate
86 :param framesize: Frame size (L2) in Bytes
87 :param traffic_type: Traffic profile
88 :type nodes_info: dict
92 :type traffic_type: str
97 node = nodes_info["TG"]
99 if node['type'] != NodeType.TG:
100 raise Exception('Node type is not a TG')
102 if node['subtype'] is None:
103 raise Exception('TG subtype not defined')
108 if node['subtype'] == NodeSubTypeTG.TREX:
109 if traffic_type in ["3-node-xconnect", "3-node-bridge"]:
110 (ret, stdout, stderr) = ssh.exec_command(
111 "sh -c '/tmp/openvpp-testing/resources/tools/t-rex-stateless.py "
112 "-d {0} -r {1}% -s {2} "
113 "--p1_src_start_ip 10.10.10.1 "
114 "--p1_src_end_ip 10.10.10.254 "
115 "--p1_dst_start_ip 20.20.20.1 "
116 "--p2_src_start_ip 20.20.20.1 "
117 "--p2_src_end_ip 20.20.20.254 "
118 "--p2_dst_start_ip 10.10.10.1'".\
119 format(duration, rate, framesize), timeout=int(duration)+60)
120 elif traffic_type in ["3-node-IPv4"]:
121 (ret, stdout, stderr) = ssh.exec_command(
122 "sh -c '/tmp/openvpp-testing/resources/tools/t-rex-stateless.py "
123 "-d {0} -r {1}% -s {2} "
124 "--p1_src_start_ip 10.10.10.2 "
125 "--p1_src_end_ip 10.10.10.254 "
126 "--p1_dst_start_ip 20.20.20.2 "
127 "--p2_src_start_ip 20.20.20.2 "
128 "--p2_src_end_ip 20.20.20.254 "
129 "--p2_dst_start_ip 10.10.10.2'".\
130 format(duration, rate, framesize),\
131 timeout=int(duration)+60)
133 raise NotImplementedError('Unsupported traffic type')
136 raise NotImplementedError("TG subtype not supported")
142 for line in stdout.splitlines():
146 logger.info('TrafficGen result: {0}'.format(self._result))
148 self._loss = self._result.split(', ')[3].split('=')[1]
152 def no_traffic_loss_occured(self):
153 """Fail is loss occured in traffic run
157 if self._loss is None:
158 raise Exception('The traffic generation has not been issued')
159 if self._loss != '0':
160 raise Exception('Traffic loss occured: {0}'.format(self._loss))