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
17 from robot.libraries.BuiltIn import BuiltIn
19 from resources.libraries.python.constants import Constants
20 from resources.libraries.python.ssh import SSH
21 from resources.libraries.python.topology import NodeType
22 from resources.libraries.python.topology import NodeSubTypeTG
23 from resources.libraries.python.topology import Topology
24 from resources.libraries.python.DropRateSearch import DropRateSearch
26 __all__ = ['TrafficGenerator', 'TGDropRateSearchImpl']
29 class TGDropRateSearchImpl(DropRateSearch):
30 """Drop Rate Search implementation."""
33 super(TGDropRateSearchImpl, self).__init__()
35 def measure_loss(self, rate, frame_size, loss_acceptance,
36 loss_acceptance_type, traffic_type):
37 """Runs the traffic and evaluate the measured results.
39 :param rate: Offered traffic load.
40 :param frame_size: Size of frame.
41 :param loss_acceptance: Permitted drop ratio or frames count.
42 :param loss_acceptance_type: Type of permitted loss.
43 :param traffic_type: Traffic profile ([2,3]-node-L[2,3], ...).
46 :type loss_acceptance: float
47 :type loss_acceptance_type: LossAcceptanceType
48 :type traffic_type: str
49 :returns: Drop threshold exceeded? (True/False)
51 :raises: NotImplementedError if TG is not supported.
52 :raises: RuntimeError if TG is not specified.
54 # we need instance of TrafficGenerator instantiated by Robot Framework
55 # to be able to use trex_stl-*()
56 tg_instance = BuiltIn().get_library_instance(
57 'resources.libraries.python.TrafficGenerator')
59 if tg_instance.node['subtype'] is None:
60 raise RuntimeError('TG subtype not defined')
61 elif tg_instance.node['subtype'] == NodeSubTypeTG.TREX:
62 unit_rate = str(rate) + self.get_rate_type_str()
63 tg_instance.trex_stl_start_remote_exec(self.get_duration(),
64 unit_rate, frame_size,
66 loss = tg_instance.get_loss()
67 sent = tg_instance.get_sent()
68 if self.loss_acceptance_type_is_percentage():
69 loss = (float(loss) / float(sent)) * 100
71 logger.trace("comparing: {} < {} {}".format(loss,
73 loss_acceptance_type))
74 if float(loss) > float(loss_acceptance):
79 raise NotImplementedError("TG subtype not supported")
81 def get_latency(self):
82 """Returns min/avg/max latency.
84 :returns: Latency stats.
87 tg_instance = BuiltIn().get_library_instance(
88 'resources.libraries.python.TrafficGenerator')
89 return tg_instance.get_latency_int()
92 class TrafficGenerator(object):
93 """Traffic Generator."""
95 # use one instance of TrafficGenerator for all tests in test suite
96 ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
103 self._received = None
105 # T-REX interface order mapping
106 self._ifaces_reordered = 0
112 :returns: Traffic generator node.
118 """Return number of lost packets.
120 :returns: Number of lost packets.
126 """Return number of sent packets.
128 :returns: Number of sent packets.
133 def get_received(self):
134 """Return number of received packets.
136 :returns: Number of received packets.
139 return self._received
141 def get_latency_int(self):
142 """Return rounded min/avg/max latency.
144 :returns: Latency stats.
149 def initialize_traffic_generator(self, tg_node, tg_if1, tg_if2,
150 tg_if1_adj_node, tg_if1_adj_if,
151 tg_if2_adj_node, tg_if2_adj_if,
153 tg_if1_dst_mac=None, tg_if2_dst_mac=None):
154 """TG initialization.
156 :param tg_node: Traffic generator node.
157 :param tg_if1: TG - name of first interface.
158 :param tg_if2: TG - name of second interface.
159 :param tg_if1_adj_node: TG if1 adjecent node.
160 :param tg_if1_adj_if: TG if1 adjecent interface.
161 :param tg_if2_adj_node: TG if2 adjecent node.
162 :param tg_if2_adj_if: TG if2 adjecent interface.
163 :param test_type: 'L2' or 'L3' - src/dst MAC address.
164 :param tg_if1_dst_mac: Interface 1 destination MAC address.
165 :param tg_if2_dst_mac: Interface 2 destination MAC address.
169 :type tg_if1_adj_node: dict
170 :type tg_if1_adj_if: str
171 :type tg_if2_adj_node: dict
172 :type tg_if2_adj_if: str
174 :type tg_if1_dst_mac: str
175 :type tg_if2_dst_mac: str
177 :raises: RuntimeError in case of issue during initialization.
182 if tg_node['type'] != NodeType.TG:
183 raise RuntimeError('Node type is not a TG')
186 if tg_node['subtype'] == NodeSubTypeTG.TREX:
187 trex_path = "/opt/trex-core-2.25"
192 (ret, stdout, stderr) = ssh.exec_command(
193 "sudo -E sh -c '{}/resources/tools/t-rex/"
194 "t-rex-installer.sh'".format(Constants.REMOTE_FW_DIR),
197 logger.error('trex installation failed: {0}'.format(
199 raise RuntimeError('Installation of TG failed')
201 if1_pci = topo.get_interface_pci_addr(tg_node, tg_if1)
202 if2_pci = topo.get_interface_pci_addr(tg_node, tg_if2)
203 if1_mac = topo.get_interface_mac(tg_node, tg_if1)
204 if2_mac = topo.get_interface_mac(tg_node, tg_if2)
206 if test_type == 'L2':
207 if1_adj_mac = if2_mac
208 if2_adj_mac = if1_mac
209 elif test_type == 'L3':
210 if1_adj_mac = topo.get_interface_mac(tg_if1_adj_node,
212 if2_adj_mac = topo.get_interface_mac(tg_if2_adj_node,
215 raise ValueError("test_type unknown")
217 if tg_if1_dst_mac is not None and tg_if2_dst_mac is not None:
218 if1_adj_mac = tg_if1_dst_mac
219 if2_adj_mac = tg_if2_dst_mac
221 if min(if1_pci, if2_pci) != if1_pci:
222 if1_mac, if2_mac = if2_mac, if1_mac
223 if1_pci, if2_pci = if2_pci, if1_pci
224 if1_adj_mac, if2_adj_mac = if2_adj_mac, if1_adj_mac
225 self._ifaces_reordered = 1
227 if1_mac_hex = "0x"+if1_mac.replace(":", ",0x")
228 if2_mac_hex = "0x"+if2_mac.replace(":", ",0x")
229 if1_adj_mac_hex = "0x"+if1_adj_mac.replace(":", ",0x")
230 if2_adj_mac_hex = "0x"+if2_adj_mac.replace(":", ",0x")
232 (ret, stdout, stderr) = ssh.exec_command(
233 "sudo sh -c 'cat << EOF > /etc/trex_cfg.yaml\n"
236 " interfaces : [\"{}\",\"{}\"]\n"
238 " - dest_mac : [{}]\n"
240 " - dest_mac : [{}]\n"
243 .format(if1_pci, if2_pci,
244 if1_adj_mac_hex, if1_mac_hex,
245 if2_adj_mac_hex, if2_mac_hex))
247 logger.error("failed to create t-rex config: {}"\
248 .format(stdout + stderr))
249 raise RuntimeError('trex config generation error')
251 max_startup_retries = 3
252 while max_startup_retries > 0:
253 # kill T-rex only if it is already running
254 (ret, _, _) = ssh.exec_command(
255 "sh -c 'pgrep t-rex && sudo pkill t-rex && sleep 3'")
258 (ret, stdout, stderr) = ssh.exec_command(
259 "sh -c 'cd {0}/scripts/ && sudo ./trex-cfg'"\
262 logger.error('trex-cfg failed: {0}'.format(stdout + stderr))
263 raise RuntimeError('trex-cfg failed')
266 (ret, _, _) = ssh.exec_command(
267 "sh -c 'cd {0}/scripts/ && "
268 "sudo nohup ./t-rex-64 -i -c 7 --iom 0 > /dev/null 2>&1 &'"
272 raise RuntimeError('t-rex-64 startup failed')
274 # get T-rex server info
275 (ret, _, _) = ssh.exec_command(
277 "{0}/resources/tools/t-rex/t-rex-server-info.py'"\
278 .format(Constants.REMOTE_FW_DIR),
281 # If we get info T-rex is running
284 max_startup_retries -= 1
285 # after max retries T-rex is still not responding to API
286 # critical error occured
287 raise RuntimeError('t-rex-64 startup failed')
290 def teardown_traffic_generator(node):
293 :param node: Traffic generator node.
296 :raises: RuntimeError if T-rex teardown failed.
297 :raises: RuntimeError if node type is not a TG.
299 if node['type'] != NodeType.TG:
300 raise RuntimeError('Node type is not a TG')
301 if node['subtype'] == NodeSubTypeTG.TREX:
304 (ret, stdout, stderr) = ssh.exec_command(
305 "sh -c 'sudo pkill t-rex && sleep 3'")
307 logger.error('pkill t-rex failed: {0}'.format(stdout + stderr))
308 raise RuntimeError('pkill t-rex failed')
311 def trex_stl_stop_remote_exec(node):
312 """Execute script on remote node over ssh to stop running traffic.
314 :param node: T-REX generator node.
317 :raises: RuntimeError if stop traffic script fails.
322 (ret, stdout, stderr) = ssh.exec_command(
323 "sh -c '{}/resources/tools/t-rex/"
324 "t-rex-stateless-stop.py'".format(Constants.REMOTE_FW_DIR))
327 raise RuntimeError('T-rex stateless runtime error')
329 def trex_stl_start_remote_exec(self, duration, rate, framesize,
330 traffic_type, async_call=False,
331 latency=True, warmup_time=5):
332 """Execute script on remote node over ssh to start traffic.
334 :param duration: Time expresed in seconds for how long to send traffic.
335 :param rate: Traffic rate expressed with units (pps, %)
336 :param framesize: L2 frame size to send (without padding and IPG).
337 :param traffic_type: Traffic profile.
338 :param async_call: If enabled then don't wait for all incomming trafic.
339 :param latency: With latency measurement.
340 :param warmup_time: Warmup time period.
344 :type traffic_type: str
345 :type async_call: bool
347 :type warmup_time: int
349 :raises: NotImplementedError if traffic type is not supported.
350 :raises: RuntimeError in case of TG driver issue.
353 ssh.connect(self._node)
357 _async = "--async" if async_call else ""
358 _latency = "--latency" if latency else ""
360 if self._ifaces_reordered != 0:
363 if traffic_type in ["3-node-xconnect", "3-node-bridge"]:
364 (ret, stdout, stderr) = ssh.exec_command(
365 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
366 "--duration={1} -r {2} -s {3} "
367 "--p{4}_src_start_ip 10.10.10.1 "
368 "--p{4}_src_end_ip 10.10.10.254 "
369 "--p{4}_dst_start_ip 20.20.20.1 "
370 "--p{5}_src_start_ip 20.20.20.1 "
371 "--p{5}_src_end_ip 20.20.20.254 "
372 "--p{5}_dst_start_ip 10.10.10.1 "
373 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
374 duration, rate, framesize,
375 _p0, _p1, _async, _latency,
377 timeout=int(duration)+60)
378 elif traffic_type in ["3-node-IPv4"]:
379 (ret, stdout, stderr) = ssh.exec_command(
380 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
381 "--duration={1} -r {2} -s {3} "
382 "--p{4}_src_start_ip 10.10.10.2 "
383 "--p{4}_src_end_ip 10.10.10.254 "
384 "--p{4}_dst_start_ip 20.20.20.2 "
385 "--p{5}_src_start_ip 20.20.20.2 "
386 "--p{5}_src_end_ip 20.20.20.254 "
387 "--p{5}_dst_start_ip 10.10.10.2 "
388 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
389 duration, rate, framesize,
390 _p0, _p1, _async, _latency,
392 timeout=int(duration)+60)
393 elif traffic_type in ["3-node-IPv4-dst-1"]:
394 (ret, stdout, stderr) = ssh.exec_command(
395 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
396 "--duration={1} -r {2} -s {3} "
397 "--p{4}_src_start_ip 10.0.0.1 "
398 "--p{4}_dst_start_ip 20.0.0.0 "
399 "--p{4}_dst_end_ip 20.0.0.0 "
400 "--p{5}_src_start_ip 20.0.0.1 "
401 "--p{5}_dst_start_ip 10.0.0.0 "
402 "--p{5}_dst_end_ip 10.0.0.0 "
403 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
404 duration, rate, framesize,
405 _p0, _p1, _async, _latency,
407 timeout=int(duration)+60)
408 elif traffic_type in ["3-node-IPv4-dst-100"]:
409 (ret, stdout, stderr) = ssh.exec_command(
410 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
411 "--duration={1} -r {2} -s {3} "
412 "--p{4}_src_start_ip 10.0.0.1 "
413 "--p{4}_dst_start_ip 20.0.0.0 "
414 "--p{4}_dst_end_ip 20.0.0.99 "
415 "--p{5}_src_start_ip 20.0.0.1 "
416 "--p{5}_dst_start_ip 10.0.0.0 "
417 "--p{5}_dst_end_ip 10.0.0.99 "
418 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
419 duration, rate, framesize,
420 _p0, _p1, _async, _latency,
422 timeout=int(duration)+60)
423 elif traffic_type in ["3-node-IPv4-dst-1000"]:
424 (ret, stdout, stderr) = ssh.exec_command(
425 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
426 "--duration={1} -r {2} -s {3} "
427 "--p{4}_src_start_ip 10.0.0.1 "
428 "--p{4}_dst_start_ip 20.0.0.0 "
429 "--p{4}_dst_end_ip 20.0.3.231 "
430 "--p{5}_src_start_ip 20.0.0.1 "
431 "--p{5}_dst_start_ip 10.0.0.0 "
432 "--p{5}_dst_end_ip 10.0.3.231 "
433 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
434 duration, rate, framesize,
435 _p0, _p1, _async, _latency,
437 timeout=int(duration)+60)
439 elif traffic_type in ["3-node-IPv4-SNAT-1u-1p"]:
440 (ret, stdout, stderr) = ssh.exec_command(
441 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
442 "--duration={1} -r {2} -s {3} "
443 "--p{4}_src_start_ip 20.0.0.0 "
444 "--p{4}_src_end_ip 20.0.0.0 "
445 "--p{4}_dst_start_ip 12.0.0.2 "
446 "--p{5}_src_start_ip 12.0.0.2 "
447 "--p{5}_src_end_ip 12.0.0.2 "
448 "--p{5}_dst_start_ip 200.0.0.0 "
449 "--p{4}_src_start_udp_port 1024 "
450 "--p{4}_src_end_udp_port 1024 "
451 "--p{4}_dst_start_udp_port 1024 "
452 "--p{5}_src_start_udp_port 1024 "
453 "--p{5}_dst_start_udp_port 1028 "
454 "--p{5}_dst_end_udp_port 1028 "
455 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
456 duration, rate, framesize,
457 _p0, _p1, _async, _latency,
459 timeout=int(duration)+60)
461 elif traffic_type in ["3-node-IPv4-SNAT-1u-15p"]:
462 (ret, stdout, stderr) = ssh.exec_command(
463 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
464 "--duration={1} -r {2} -s {3} "
465 "--p{4}_src_start_ip 20.0.0.0 "
466 "--p{4}_src_end_ip 20.0.0.0 "
467 "--p{4}_dst_start_ip 12.0.0.2 "
468 "--p{5}_src_start_ip 12.0.0.2 "
469 "--p{5}_src_end_ip 12.0.0.2 "
470 "--p{5}_dst_start_ip 200.0.0.0 "
471 "--p{4}_src_start_udp_port 1024 "
472 "--p{4}_src_end_udp_port 1038 "
473 "--p{4}_dst_start_udp_port 1024 "
474 "--p{5}_src_start_udp_port 1024 "
475 "--p{5}_dst_start_udp_port 1024 "
476 "--p{5}_dst_end_udp_port 1038 "
477 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
478 duration, rate, framesize,
479 _p0, _p1, _async, _latency,
481 timeout=int(duration)+60)
483 elif traffic_type in ["3-node-IPv4-SNAT-10u-15p"]:
484 (ret, stdout, stderr) = ssh.exec_command(
485 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
486 "--duration={1} -r {2} -s {3} "
487 "--p{4}_src_start_ip 20.0.0.0 "
488 "--p{4}_src_end_ip 20.0.0.9 "
489 "--p{4}_dst_start_ip 12.0.0.2 "
490 "--p{5}_src_start_ip 12.0.0.2 "
491 "--p{5}_src_end_ip 12.0.0.2 "
492 "--p{5}_dst_start_ip 200.0.0.0 "
493 "--p{4}_src_start_udp_port 1024 "
494 "--p{4}_src_end_udp_port 1038 "
495 "--p{4}_dst_start_udp_port 1024 "
496 "--p{5}_src_start_udp_port 1024 "
497 "--p{5}_dst_start_udp_port 1024 "
498 "--p{5}_dst_end_udp_port 1173 "
499 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
500 duration, rate, framesize,
501 _p0, _p1, _async, _latency,
503 timeout=int(duration)+60)
505 elif traffic_type in ["3-node-IPv4-SNAT-100u-15p"]:
506 (ret, stdout, stderr) = ssh.exec_command(
507 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
508 "--duration={1} -r {2} -s {3} "
509 "--p{4}_src_start_ip 20.0.0.0 "
510 "--p{4}_src_end_ip 20.0.0.99 "
511 "--p{4}_dst_start_ip 12.0.0.2 "
512 "--p{5}_src_start_ip 12.0.0.2 "
513 "--p{5}_src_end_ip 12.0.0.2 "
514 "--p{5}_dst_start_ip 200.0.0.0 "
515 "--p{4}_src_start_udp_port 1024 "
516 "--p{4}_src_end_udp_port 1038 "
517 "--p{4}_dst_start_udp_port 1024 "
518 "--p{5}_src_start_udp_port 1024 "
519 "--p{5}_dst_start_udp_port 1024 "
520 "--p{5}_dst_end_udp_port 2523 "
521 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
522 duration, rate, framesize,
523 _p0, _p1, _async, _latency,
525 timeout=int(duration) + 60)
527 elif traffic_type in ["3-node-IPv4-SNAT-1000u-15p"]:
528 (ret, stdout, stderr) = ssh.exec_command(
529 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
530 "--duration={1} -r {2} -s {3} "
531 "--p{4}_src_start_ip 20.0.0.0 "
532 "--p{4}_src_end_ip 20.0.3.231 "
533 "--p{4}_dst_start_ip 12.0.0.2 "
534 "--p{5}_src_start_ip 12.0.0.2 "
535 "--p{5}_src_end_ip 12.0.0.2 "
536 "--p{5}_dst_start_ip 200.0.0.0 "
537 "--p{4}_src_start_udp_port 1024 "
538 "--p{4}_src_end_udp_port 1038 "
539 "--p{4}_dst_start_udp_port 1024 "
540 "--p{5}_src_start_udp_port 1024 "
541 "--p{5}_dst_start_udp_port 1024 "
542 "--p{5}_dst_end_udp_port 16023 "
543 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
544 duration, rate, framesize,
545 _p0, _p1, _async, _latency,
547 timeout=int(duration)+60)
549 elif traffic_type in ["3-node-IPv4-SNAT-2000u-15p"]:
550 (ret, stdout, stderr) = ssh.exec_command(
551 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
552 "--duration={1} -r {2} -s {3} "
553 "--p{4}_src_start_ip 20.0.0.0 "
554 "--p{4}_src_end_ip 20.0.7.207 "
555 "--p{4}_dst_start_ip 12.0.0.2 "
556 "--p{5}_src_start_ip 12.0.0.2 "
557 "--p{5}_src_end_ip 12.0.0.2 "
558 "--p{5}_dst_start_ip 200.0.0.0 "
559 "--p{4}_src_start_udp_port 1024 "
560 "--p{4}_src_end_udp_port 1038 "
561 "--p{4}_dst_start_udp_port 1024 "
562 "--p{5}_src_start_udp_port 1024 "
563 "--p{5}_dst_start_udp_port 1024 "
564 "--p{5}_dst_end_udp_port 31022 "
565 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
566 duration, rate, framesize,
567 _p0, _p1, _async, _latency,
569 timeout=int(duration)+60)
571 elif traffic_type in ["3-node-IPv4-SNAT-4000u-15p"]:
572 (ret, stdout, stderr) = ssh.exec_command(
573 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
574 "--duration={1} -r {2} -s {3} "
575 "--p{4}_src_start_ip 20.0.0.0 "
576 "--p{4}_src_end_ip 20.0.15.159 "
577 "--p{4}_dst_start_ip 12.0.0.2 "
578 "--p{5}_src_start_ip 12.0.0.2 "
579 "--p{5}_src_end_ip 12.0.0.2 "
580 "--p{5}_dst_start_ip 200.0.0.0 "
581 "--p{4}_src_start_udp_port 1024 "
582 "--p{4}_src_end_udp_port 1038 "
583 "--p{4}_dst_start_udp_port 1024 "
584 "--p{5}_src_start_udp_port 1024 "
585 "--p{5}_dst_start_udp_port 1024 "
586 "--p{5}_dst_end_udp_port 61022 "
587 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
588 duration, rate, framesize,
589 _p0, _p1, _async, _latency,
591 timeout=int(duration)+60)
593 elif traffic_type in ["3-node-IPv4-dst-10000"]:
594 (ret, stdout, stderr) = ssh.exec_command(
595 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
596 "--duration={1} -r {2} -s {3} "
597 "--p{4}_src_start_ip 10.0.0.1 "
598 "--p{4}_dst_start_ip 20.0.0.0 "
599 "--p{4}_dst_end_ip 20.0.39.15 "
600 "--p{5}_src_start_ip 20.0.0.1 "
601 "--p{5}_dst_start_ip 10.0.0.0 "
602 "--p{5}_dst_end_ip 10.0.39.15 "
603 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
604 duration, rate, framesize,
605 _p0, _p1, _async, _latency,
607 timeout=int(duration)+60)
608 elif traffic_type in ["3-node-IPv4-dst-100000"]:
609 (ret, stdout, stderr) = ssh.exec_command(
610 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
611 "--duration={1} -r {2} -s {3} "
612 "--p{4}_src_start_ip 10.0.0.1 "
613 "--p{4}_dst_start_ip 20.0.0.0 "
614 "--p{4}_dst_end_ip 20.1.134.159 "
615 "--p{5}_src_start_ip 20.0.0.1 "
616 "--p{5}_dst_start_ip 10.0.0.0 "
617 "--p{5}_dst_end_ip 10.1.134.159 "
618 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
619 duration, rate, framesize,
620 _p0, _p1, _async, _latency,
622 timeout=int(duration)+60)
623 elif traffic_type in ["3-node-IPv4-dst-1000000"]:
624 (ret, stdout, stderr) = ssh.exec_command(
625 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
626 "--duration={1} -r {2} -s {3} "
627 "--p{4}_src_start_ip 10.0.0.1 "
628 "--p{4}_dst_start_ip 20.0.0.0 "
629 "--p{4}_dst_end_ip 20.15.66.63 "
630 "--p{5}_src_start_ip 20.0.0.1 "
631 "--p{5}_dst_start_ip 10.0.0.0 "
632 "--p{5}_dst_end_ip 10.15.66.63 "
633 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
634 duration, rate, framesize,
635 _p0, _p1, _async, _latency,
637 timeout=int(duration)+60)
638 elif traffic_type in ["3-node-IPv6"]:
639 (ret, stdout, stderr) = ssh.exec_command(
640 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
641 "--duration={1} -r {2} -s {3} -6 "
642 "--p{4}_src_start_ip 2001:1::2 "
643 "--p{4}_src_end_ip 2001:1::FE "
644 "--p{4}_dst_start_ip 2001:2::2 "
645 "--p{5}_src_start_ip 2001:2::2 "
646 "--p{5}_src_end_ip 2001:2::FE "
647 "--p{5}_dst_start_ip 2001:1::2 "
648 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
649 duration, rate, framesize,
650 _p0, _p1, _async, _latency,
652 timeout=int(duration)+60)
653 elif traffic_type in ["3-node-IPv6-dst-10000"]:
654 (ret, stdout, stderr) = ssh.exec_command(
655 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
656 "--duration={1} -r {2} -s {3} -6 "
657 "--p{4}_src_start_ip 2001:1::1 "
658 "--p{4}_dst_start_ip 2001:2::0 "
659 "--p{4}_dst_end_ip 2001:2::270F "
660 "--p{5}_src_start_ip 2001:2::1 "
661 "--p{5}_dst_start_ip 2001:1::0 "
662 "--p{5}_dst_end_ip 2001:1::270F "
663 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
664 duration, rate, framesize,
665 _p0, _p1, _async, _latency,
667 timeout=int(duration)+60)
668 elif traffic_type in ["3-node-IPv6-dst-100000"]:
669 (ret, stdout, stderr) = ssh.exec_command(
670 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
671 "--duration={1} -r {2} -s {3} -6 "
672 "--p{4}_src_start_ip 2001:1::1 "
673 "--p{4}_dst_start_ip 2001:2::0 "
674 "--p{4}_dst_end_ip 2001:2::1:869F "
675 "--p{5}_src_start_ip 2001:2::1 "
676 "--p{5}_dst_start_ip 2001:1::0 "
677 "--p{5}_dst_end_ip 2001:1::1:869F "
678 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
679 duration, rate, framesize,
680 _p0, _p1, _async, _latency,
682 timeout=int(duration)+60)
683 elif traffic_type in ["3-node-IPv6-dst-1000000"]:
684 (ret, stdout, stderr) = ssh.exec_command(
685 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
686 "--duration={1} -r {2} -s {3} -6 "
687 "--p{4}_src_start_ip 2001:1::1 "
688 "--p{4}_dst_start_ip 2001:2::0 "
689 "--p{4}_dst_end_ip 2001:2::F:423F "
690 "--p{5}_src_start_ip 2001:2::1 "
691 "--p{5}_dst_start_ip 2001:1::0 "
692 "--p{5}_dst_end_ip 2001:1::F:423F "
693 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
694 duration, rate, framesize,
695 _p0, _p1, _async, _latency,
697 timeout=int(duration)+60)
698 elif traffic_type in ["2-node-bridge"]:
699 (ret, stdout, stderr) = ssh.exec_command(
700 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
701 "--duration={1} -r {2} -s {3} "
702 "--p{4}_src_start_ip 10.10.10.2 "
703 "--p{4}_src_end_ip 10.10.10.254 "
704 "--p{4}_dst_start_ip 20.20.20.2 "
705 "--p{5}_src_start_ip 20.20.20.2 "
706 "--p{5}_src_end_ip 20.20.20.254 "
707 "--p{5}_dst_start_ip 10.10.10.2 "
708 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
709 duration, rate, framesize,
710 _p0, _p1, _async, _latency,
712 timeout = int(duration) + 60)
713 elif traffic_type in ["3-node-IPv4-l3fwd"]:
714 # add for the DPDK l3fwd routing test
715 # please make sure the TG port 0 connect to the DUT port 0
716 (ret, stdout, stderr) = ssh.exec_command(
717 "sh -c '{0}/resources/tools/t-rex/t-rex-stateless.py "
718 "--duration={1} -r {2} -s {3} "
719 "--p{4}_dst_start_ip 2.1.1.2 "
720 "--p{4}_dst_end_ip 2.1.1.254 "
721 "--p{4}_src_start_ip 20.20.20.2 "
722 "--p{5}_dst_start_ip 1.1.1.2 "
723 "--p{5}_dst_end_ip 1.1.1.254 "
724 "--p{5}_src_start_ip 10.10.10.2 "
725 "{6} {7} --warmup_time={8}'".format(Constants.REMOTE_FW_DIR,
726 duration, rate, framesize,
727 _p0, _p1, _async, _latency,
729 timeout=int(duration)+60)
731 raise NotImplementedError('Unsupported traffic type')
734 raise RuntimeError('T-rex stateless runtime error')
737 self._received = None
742 # last line from console output
743 line = stdout.splitlines()[-1]
746 logger.info('TrafficGen result: {0}'.format(self._result))
748 self._received = self._result.split(', ')[1].split('=')[1]
749 self._sent = self._result.split(', ')[2].split('=')[1]
750 self._loss = self._result.split(', ')[3].split('=')[1]
753 self._latency.append(self._result.split(', ')[4].split('=')[1])
754 self._latency.append(self._result.split(', ')[5].split('=')[1])
756 def stop_traffic_on_tg(self):
757 """Stop all traffic on TG.
760 :raises: RuntimeError if TG is not set.
762 if self._node is None:
763 raise RuntimeError("TG is not set")
764 if self._node['subtype'] == NodeSubTypeTG.TREX:
765 self.trex_stl_stop_remote_exec(self._node)
767 def send_traffic_on_tg(self, duration, rate, framesize,
768 traffic_type, warmup_time=5, async_call=False,
770 """Send traffic from all configured interfaces on TG.
772 :param duration: Duration of test traffic generation in seconds.
773 :param rate: Offered load per interface (e.g. 1%, 3gbps, 4mpps, ...).
774 :param framesize: Frame size (L2) in Bytes.
775 :param traffic_type: Traffic profile.
776 :param warmup_time: Warmup phase in seconds.
777 :param async_call: Async mode.
778 :param latency: With latency measurement.
782 :type traffic_type: str
783 :type warmup_time: int
784 :type async_call: bool
788 :raises: RuntimeError if TG is not set.
789 :raises: RuntimeError if node is not TG or subtype is not specified.
790 :raises: NotImplementedError if TG is not supported.
795 raise RuntimeError("TG is not set")
797 if node['type'] != NodeType.TG:
798 raise RuntimeError('Node type is not a TG')
800 if node['subtype'] is None:
801 raise RuntimeError('TG subtype not defined')
802 elif node['subtype'] == NodeSubTypeTG.TREX:
803 self.trex_stl_start_remote_exec(duration, rate, framesize,
804 traffic_type, async_call, latency,
805 warmup_time=warmup_time)
807 raise NotImplementedError("TG subtype not supported")
811 def no_traffic_loss_occurred(self):
812 """Fail if loss occurred in traffic run.
815 :raises: Exception if loss occured.
817 if self._loss is None:
818 raise Exception('The traffic generation has not been issued')
819 if self._loss != '0':
820 raise Exception('Traffic loss occurred: {0}'.format(self._loss))
822 def partial_traffic_loss_accepted(self, loss_acceptance,
823 loss_acceptance_type):
824 """Fail if loss is higher then accepted in traffic run.
826 :param loss_acceptance: Permitted drop ratio or frames count.
827 :param loss_acceptance_type: Type of permitted loss.
828 :type loss_acceptance: float
829 :type loss_acceptance_type: LossAcceptanceType
831 :raises: Exception if loss is above acceptance criteria.
833 if self._loss is None:
834 raise Exception('The traffic generation has not been issued')
836 if loss_acceptance_type == 'percentage':
837 loss = (float(self._loss) / float(self._sent)) * 100
838 elif loss_acceptance_type == 'frames':
839 loss = float(self._loss)
841 raise Exception('Loss acceptance type not supported')
843 if loss > float(loss_acceptance):
844 raise Exception("Traffic loss {} above loss acceptance: {}".format(
845 loss, loss_acceptance))