1 # Copyright 2016 Red Hat Inc & Xena Networks.
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.
16 # Rick Alongi, Red Hat Inc.
17 # Amit Supugade, Red Hat Inc.
18 # Dan Amzulescu, Xena Networks
19 # Christian Trautman, Red Hat Inc.
22 Xena Traffic Generator Model
31 import xml.etree.ElementTree as ET
32 from collections import OrderedDict
33 from time import sleep
35 import scapy.layers.inet as inet
37 from conf import merge_spec
38 from conf import settings
39 from core.results.results_constants import ResultsConstants
40 from tools.pkt_gen.trafficgen.trafficgen import ITrafficGenerator
41 from tools.pkt_gen.xena.XenaDriver import (
47 from tools.pkt_gen.xena.json.xena_json_mesh import XenaJSONMesh
48 from tools.pkt_gen.xena.json.xena_json_blocks import XenaJSONBlocks
49 from tools.pkt_gen.xena.json.xena_json_pairs import XenaJSONPairs
51 _CURR_DIR = os.path.dirname(os.path.realpath(__file__))
53 class Xena(ITrafficGenerator):
55 Xena Traffic generator wrapper class
57 _logger = logging.getLogger(__name__)
68 self._log_handle = None
70 user_home = os.path.expanduser('~')
71 self._log_path = '{}/Xena/Xena2544-2G/Logs/xena2544.log'.format(
74 # make the folder and log file if they doesn't exist
75 if not os.path.exists(self._log_path):
76 os.makedirs(os.path.dirname(self._log_path))
78 # empty the file contents
79 open(self._log_path, 'w').close()
82 def _create_throughput_result(root):
84 Create the results based off the output xml file from the Xena2544.exe
86 :param root: root dictionary from xml import
87 :return: Results Ordered dictionary based off ResultsConstants
89 # get the test type from the report file
90 test_type = root[0][1].get('TestType')
91 # set the version from the report file
92 settings.setValue('XENA_VERSION', root[0][0][1].get('GeneratedBy'))
94 if test_type == 'Throughput':
95 results = OrderedDict()
96 results[ResultsConstants.THROUGHPUT_RX_FPS] = float(
97 root[0][1][0][0].get('PortRxPps')) + float(
98 root[0][1][0][1].get('PortRxPps'))
99 results[ResultsConstants.THROUGHPUT_RX_MBPS] = (float(
100 root[0][1][0][0].get('PortRxBpsL1')) + float(
101 root[0][1][0][1].get('PortRxBpsL1')))/ 1000000
102 results[ResultsConstants.THROUGHPUT_RX_PERCENT] = (
103 100 - float(root[0][1][0].get('TotalLossRatioPcnt'))) * float(
104 root[0][1][0].get('TotalTxRatePcnt'))/100
105 results[ResultsConstants.TX_RATE_FPS] = root[0][1][0].get(
107 results[ResultsConstants.TX_RATE_MBPS] = float(
108 root[0][1][0].get('TotalTxRateBpsL1')) / 1000000
109 results[ResultsConstants.TX_RATE_PERCENT] = root[0][1][0].get(
112 results[ResultsConstants.MIN_LATENCY_NS] = float(
113 root[0][1][0][0].get('MinLatency')) * 1000
115 # Stats for latency returned as N/A so just post them
116 results[ResultsConstants.MIN_LATENCY_NS] = root[0][1][0][0].get(
119 results[ResultsConstants.MAX_LATENCY_NS] = float(
120 root[0][1][0][0].get('MaxLatency')) * 1000
122 # Stats for latency returned as N/A so just post them
123 results[ResultsConstants.MAX_LATENCY_NS] = root[0][1][0][0].get(
126 results[ResultsConstants.AVG_LATENCY_NS] = float(
127 root[0][1][0][0].get('AvgLatency')) * 1000
129 # Stats for latency returned as N/A so just post them
130 results[ResultsConstants.AVG_LATENCY_NS] = root[0][1][0][0].get(
132 elif test_type == 'Back2Back':
133 results = OrderedDict()
135 # Just mimic what Ixia does and only return the b2b frame count.
136 # This may change later once its decided the common results stats
137 # to be returned should be.
138 results[ResultsConstants.B2B_FRAMES] = root[0][1][0][0].get(
139 'TotalTxBurstFrames')
141 raise NotImplementedError('Unknown test type in report file.')
145 def _build_packet_header(self, reverse=False):
147 Build a packet header based on traffic profile using scapy external
149 :param reverse: Swap source and destination info when building header
150 :return: packet header in hex
152 srcmac = self._params['traffic']['l2'][
153 'srcmac'] if not reverse else self._params['traffic']['l2'][
155 dstmac = self._params['traffic']['l2'][
156 'dstmac'] if not reverse else self._params['traffic']['l2'][
158 srcip = self._params['traffic']['l3'][
159 'srcip'] if not reverse else self._params['traffic']['l3']['dstip']
160 dstip = self._params['traffic']['l3'][
161 'dstip'] if not reverse else self._params['traffic']['l3']['srcip']
162 layer2 = inet.Ether(src=srcmac, dst=dstmac)
163 layer3 = inet.IP(src=srcip, dst=dstip,
164 proto=self._params['traffic']['l3']['proto'])
165 layer4 = inet.UDP(sport=self._params['traffic']['l4']['srcport'],
166 dport=self._params['traffic']['l4']['dstport'])
167 if self._params['traffic']['vlan']['enabled']:
168 vlan = inet.Dot1Q(vlan=self._params['traffic']['vlan']['id'],
169 prio=self._params['traffic']['vlan']['priority'],
170 id=self._params['traffic']['vlan']['cfi'])
173 packet = layer2/vlan/layer3/layer4 if vlan else layer2/layer3/layer4
174 packet_bytes = bytes(packet)
175 packet_hex = '0x' + binascii.hexlify(packet_bytes).decode('utf-8')
178 def _create_api_result(self):
180 Create result dictionary per trafficgen specifications from socket API
181 stats. If stats are not available return values of 0.
182 :return: ResultsConstants as dictionary
184 # Handle each case of statistics based on if the data is available.
185 # This prevents uncaught exceptions when the stats aren't available.
186 result_dict = OrderedDict()
187 if self.tx_stats.data.get(self.tx_stats.pt_stream_keys[0]):
188 result_dict[ResultsConstants.TX_FRAMES] = self.tx_stats.data[
189 self.tx_stats.pt_stream_keys[0]]['packets']
190 result_dict[ResultsConstants.TX_RATE_FPS] = self.tx_stats.data[
191 self.tx_stats.pt_stream_keys[0]]['packets'] / self._duration
192 result_dict[ResultsConstants.TX_RATE_MBPS] = ((
193 self.tx_stats.data[self.tx_stats.pt_stream_keys[0]]['bytes']
194 * 8) / 1000000) / self._duration
195 result_dict[ResultsConstants.TX_BYTES] = self.tx_stats.data[
196 self.tx_stats.pt_stream_keys[0]]['bytes']
197 # tx rate percent may need to be halved if bi directional
198 result_dict[ResultsConstants.TX_RATE_PERCENT] = line_percentage(
199 self.xmanager.ports[0], self.tx_stats, self._duration,
200 self._params['traffic']['l2']['framesize']) if \
201 self._params['traffic']['bidir'] == 'False' else\
203 self.xmanager.ports[0], self.tx_stats, self._duration,
204 self._params['traffic']['l2']['framesize']) / 2
206 self._logger.error('Transmit stats not available.')
207 result_dict[ResultsConstants.TX_FRAMES] = 0
208 result_dict[ResultsConstants.TX_RATE_FPS] = 0
209 result_dict[ResultsConstants.TX_RATE_MBPS] = 0
210 result_dict[ResultsConstants.TX_BYTES] = 0
211 result_dict[ResultsConstants.TX_RATE_PERCENT] = 0
213 if self.rx_stats.data.get('pr_tpldstraffic'):
214 result_dict[ResultsConstants.RX_FRAMES] = self.rx_stats.data[
215 'pr_tpldstraffic']['0']['packets']
217 ResultsConstants.THROUGHPUT_RX_FPS] = self.rx_stats.data[
218 'pr_tpldstraffic']['0']['packets'] / self._duration
220 ResultsConstants.THROUGHPUT_RX_MBPS] = ((
221 self.rx_stats.data['pr_tpldstraffic']['0']['bytes']
222 *8) / 1000000) / self._duration
223 result_dict[ResultsConstants.RX_BYTES] = self.rx_stats.data[
224 'pr_tpldstraffic']['0']['bytes']
225 # throughput percent may need to be halved if bi directional
227 ResultsConstants.THROUGHPUT_RX_PERCENT] = line_percentage(
228 self.xmanager.ports[1], self.rx_stats, self._duration,
229 self._params['traffic']['l2']['framesize']) if \
230 self._params['traffic']['bidir'] == 'False' else \
232 self.xmanager.ports[1], self.rx_stats, self._duration,
233 self._params['traffic']['l2']['framesize']) / 2
236 self._logger.error('Receive stats not available.')
237 result_dict[ResultsConstants.RX_FRAMES] = 0
238 result_dict[ResultsConstants.THROUGHPUT_RX_FPS] = 0
239 result_dict[ResultsConstants.THROUGHPUT_RX_MBPS] = 0
240 result_dict[ResultsConstants.RX_BYTES] = 0
241 result_dict[ResultsConstants.THROUGHPUT_RX_PERCENT] = 0
243 if self.rx_stats.data.get('pr_tplderrors'):
244 result_dict[ResultsConstants.PAYLOAD_ERR] = self.rx_stats.data[
245 'pr_tplderrors']['0']['pld']
246 result_dict[ResultsConstants.SEQ_ERR] = self.rx_stats.data[
247 'pr_tplderrors']['0']['seq']
249 result_dict[ResultsConstants.PAYLOAD_ERR] = 0
250 result_dict[ResultsConstants.SEQ_ERR] = 0
252 if self.rx_stats.data.get('pr_tpldlatency'):
253 result_dict[ResultsConstants.MIN_LATENCY_NS] = self.rx_stats.data[
254 'pr_tpldlatency']['0']['min']
255 result_dict[ResultsConstants.MAX_LATENCY_NS] = self.rx_stats.data[
256 'pr_tpldlatency']['0']['max']
257 result_dict[ResultsConstants.AVG_LATENCY_NS] = self.rx_stats.data[
258 'pr_tpldlatency']['0']['avg']
260 result_dict[ResultsConstants.MIN_LATENCY_NS] = 0
261 result_dict[ResultsConstants.MAX_LATENCY_NS] = 0
262 result_dict[ResultsConstants.AVG_LATENCY_NS] = 0
266 def _setup_json_config(self, tests, loss_rate, testtype=None,
269 Create a 2bUsed json file that will be used for xena2544.exe execution.
270 :param tests: Number of tests
271 :param loss_rate: The acceptable loss rate as float
272 :param testtype: Either '2544_b2b' or '2544_throughput' as string
273 :param bonding_test: Specify if the test is a bonding test which will
274 enable the pairs topology
277 # set duplex mode, this code is valid, pylint complaining with a
278 # warning that many have complained about online.
279 # pylint: disable=redefined-variable-type
282 if self._params['traffic']['bidir'] == "True":
283 j_file = XenaJSONMesh()
284 elif self._params['traffic']['bidir'] == "False":
285 j_file = XenaJSONBlocks()
287 j_file = XenaJSONPairs()
289 j_file.set_chassis_info(
290 settings.getValue('TRAFFICGEN_XENA_IP'),
291 settings.getValue('TRAFFICGEN_XENA_PASSWORD')
293 j_file.set_port(0, settings.getValue('TRAFFICGEN_XENA_MODULE1'),
294 settings.getValue('TRAFFICGEN_XENA_PORT1'))
295 j_file.set_port(1, settings.getValue('TRAFFICGEN_XENA_MODULE2'),
296 settings.getValue('TRAFFICGEN_XENA_PORT2'))
297 j_file.set_port_ip_v4(
298 0, settings.getValue("TRAFFICGEN_XENA_PORT0_IP"),
299 settings.getValue("TRAFFICGEN_XENA_PORT0_CIDR"),
300 settings.getValue("TRAFFICGEN_XENA_PORT0_GATEWAY"))
301 j_file.set_port_ip_v4(
302 1, settings.getValue("TRAFFICGEN_XENA_PORT1_IP"),
303 settings.getValue("TRAFFICGEN_XENA_PORT1_CIDR"),
304 settings.getValue("TRAFFICGEN_XENA_PORT1_GATEWAY"))
306 if testtype == '2544_throughput':
307 j_file.set_test_options_tput(
308 packet_sizes=self._params['traffic']['l2']['framesize'],
309 iterations=tests, loss_rate=loss_rate,
310 duration=self._duration, micro_tpld=True if self._params[
311 'traffic']['l2']['framesize'] == 64 else False)
312 j_file.enable_throughput_test()
313 j_file.modify_2544_tput_options(
314 settings.getValue('TRAFFICGEN_XENA_2544_TPUT_INIT_VALUE'),
315 settings.getValue('TRAFFICGEN_XENA_2544_TPUT_MIN_VALUE'),
316 settings.getValue('TRAFFICGEN_XENA_2544_TPUT_MAX_VALUE'),
318 'TRAFFICGEN_XENA_2544_TPUT_VALUE_RESOLUTION'),
320 'TRAFFICGEN_XENA_2544_TPUT_USEPASS_THRESHHOLD'),
322 'TRAFFICGEN_XENA_2544_TPUT_PASS_THRESHHOLD')
325 elif testtype == '2544_b2b':
326 j_file.set_test_options_back2back(
327 packet_sizes=self._params['traffic']['l2']['framesize'],
328 iterations=tests, duration=self._duration,
329 startvalue=self._params['traffic']['frame_rate'],
330 endvalue=self._params['traffic']['frame_rate'],
331 micro_tpld=True if self._params[
332 'traffic']['l2']['framesize'] == 64 else False)
333 j_file.enable_back2back_test()
335 j_file.set_header_layer2(
336 dst_mac=self._params['traffic']['l2']['dstmac'],
337 src_mac=self._params['traffic']['l2']['srcmac'])
338 j_file.set_header_layer3(
339 src_ip=self._params['traffic']['l3']['srcip'],
340 dst_ip=self._params['traffic']['l3']['dstip'],
341 protocol=self._params['traffic']['l3']['proto'])
342 j_file.set_header_layer4_udp(
343 source_port=self._params['traffic']['l4']['srcport'],
344 destination_port=self._params['traffic']['l4']['dstport'])
345 if self._params['traffic']['vlan']['enabled']:
346 j_file.set_header_vlan(
347 vlan_id=self._params['traffic']['vlan']['id'],
348 id=self._params['traffic']['vlan']['cfi'],
349 prio=self._params['traffic']['vlan']['priority'])
350 j_file.add_header_segments(
351 flows=self._params['traffic']['multistream'],
352 multistream_layer=self._params['traffic']['stream_type'])
354 j_file.write_config(os.path.join(
355 _CURR_DIR, 'profiles/2bUsed.x2544'))
356 except Exception as exc:
357 self._logger.exception("Error during Xena JSON setup: %s", exc)
360 def _start_traffic_api(self, packet_limit):
362 Start the Xena traffic using the socket API driver
363 :param packet_limit: packet limit for stream, set to -1 for no limit
366 if not self.xmanager:
367 self._xsocket = XenaSocketDriver(
368 settings.getValue('TRAFFICGEN_XENA_IP'))
369 self.xmanager = XenaManager(
370 self._xsocket, settings.getValue('TRAFFICGEN_XENA_USER'),
371 settings.getValue('TRAFFICGEN_XENA_PASSWORD'))
373 # for the report file version info ask the chassis directly for its
375 settings.setValue('XENA_VERSION', 'XENA Socket API - {}'.format(
376 self.xmanager.get_version()))
378 if not self.xmanager.ports:
379 self.xmanager.ports[0] = self.xmanager.add_module_port(
380 settings.getValue('TRAFFICGEN_XENA_MODULE1'),
381 settings.getValue('TRAFFICGEN_XENA_PORT1'))
382 if not self.xmanager.ports[0].reserve_port():
384 'Unable to reserve port 0. Please release Xena Port')
386 if len(self.xmanager.ports) < 2:
387 self.xmanager.ports[1] = self.xmanager.add_module_port(
388 settings.getValue('TRAFFICGEN_XENA_MODULE2'),
389 settings.getValue('TRAFFICGEN_XENA_PORT2'))
390 if not self.xmanager.ports[1].reserve_port():
392 'Unable to reserve port 1. Please release Xena Port')
394 # Clear port configuration for a clean start
395 self.xmanager.ports[0].reset_port()
396 self.xmanager.ports[1].reset_port()
397 if settings.getValue('TRAFFICGEN_XENA_CONT_PORT_LEARNING_ENABLED'):
398 # turn on port learning
399 self.xmanager.ports[0].set_port_learning(1)
400 self.xmanager.ports[1].set_port_learning(1)
401 sleep(settings.getValue('TRAFFICGEN_XENA_CONT_PORT_LEARNING_DURATION'))
402 # turn off port learning
403 self.xmanager.ports[0].set_port_learning(0)
404 self.xmanager.ports[1].set_port_learning(0)
406 self.xmanager.ports[0].clear_stats()
407 self.xmanager.ports[1].clear_stats()
409 # set the port IP from the conf file
410 self.xmanager.ports[0].set_port_ip(
411 settings.getValue('TRAFFICGEN_XENA_PORT0_IP'),
412 settings.getValue('TRAFFICGEN_XENA_PORT0_CIDR'),
413 settings.getValue('TRAFFICGEN_XENA_PORT0_GATEWAY'))
414 self.xmanager.ports[1].set_port_ip(
415 settings.getValue('TRAFFICGEN_XENA_PORT1_IP'),
416 settings.getValue('TRAFFICGEN_XENA_PORT1_CIDR'),
417 settings.getValue('TRAFFICGEN_XENA_PORT1_GATEWAY'))
418 self.xmanager.ports[0].set_port_time_limit(self._duration)
419 self.xmanager.ports[1].set_port_time_limit(self._duration)
421 def setup_stream(stream, port, payload_id, flip_addr=False):
423 Helper function to configure streams.
424 :param stream: Stream object from XenaDriver module
425 :param port: Port object from XenaDriver module
426 :param payload_id: payload ID as int
427 :param flip_addr: Boolean if the source and destination addresses
432 if packet_limit != -1:
433 stream.set_packet_limit(packet_limit)
435 port.set_port_arp_reply(is_on=True)
436 port.set_port_arp_reply(is_on=True, ipv6=True)
437 port.set_port_ping_reply(is_on=True)
438 port.set_port_ping_reply(is_on=True, ipv6=True)
440 stream.set_rate_fraction(int(
441 10000 * self._params['traffic']['frame_rate']))
442 stream.set_packet_header(self._build_packet_header(
444 stream.set_header_protocol(
445 'ETHERNET VLAN IP UDP' if self._params['traffic']['vlan'][
446 'enabled'] else 'ETHERNET IP UDP')
447 stream.set_packet_length(
448 'fixed', self._params['traffic']['l2']['framesize'],
449 self._params['traffic']['l2']['framesize'])
450 stream.set_packet_payload('incrementing', '0x00')
451 stream.set_payload_id(payload_id)
452 port.set_port_time_limit(self._duration * 1000000)
454 if self._params['traffic']['l2']['framesize'] == 64:
456 port.micro_tpld_enable()
458 if self._params['traffic']['multistream']:
459 stream.enable_multistream(
460 flows=self._params['traffic']['multistream'],
461 layer=self._params['traffic']['stream_type'])
463 s1_p0 = self.xmanager.ports[0].add_stream()
464 setup_stream(s1_p0, self.xmanager.ports[0], 0)
466 if self._params['traffic']['bidir'] == 'True':
467 s1_p1 = self.xmanager.ports[1].add_stream()
468 setup_stream(s1_p1, self.xmanager.ports[1], 1, flip_addr=True)
470 if not self.xmanager.ports[0].traffic_on():
472 "Failure to start port 0. Check settings and retry.")
473 if self._params['traffic']['bidir'] == 'True':
474 if not self.xmanager.ports[1].traffic_on():
476 "Failure to start port 1. Check settings and retry.")
477 sleep(self._duration + 5) # the extra 5 seconds is to allow packets in flight to complete
479 if self._params['traffic']['bidir'] == 'True':
480 # need to aggregate out both ports stats and assign that data
481 self.rx_stats = self.xmanager.ports[1].get_rx_stats()
482 self.tx_stats = self.xmanager.ports[0].get_tx_stats()
483 self.tx_stats.data = aggregate_stats(
485 self.xmanager.ports[1].get_tx_stats().data)
486 self.rx_stats.data = aggregate_stats(
488 self.xmanager.ports[0].get_rx_stats().data)
490 # no need to aggregate, just grab the appropriate port stats
491 self.tx_stats = self.xmanager.ports[0].get_tx_stats()
492 self.rx_stats = self.xmanager.ports[1].get_rx_stats()
495 def _start_xena_2544(self):
497 Start the xena2544 exe.
500 args = ["mono", os.path.join(_CURR_DIR, "Xena2544.exe"), "-c",
501 os.path.join(_CURR_DIR, "profiles/2bUsed.x2544"), "-e", "-r",
503 settings.getValue('TRAFFICGEN_XENA_USER')]
504 # Sometimes Xena2544.exe completes, but mono holds the process without
505 # releasing it, this can cause a deadlock of the main thread. Use the
506 # xena log file as a way to detect this.
507 self._log_handle = open(self._log_path, 'r')
508 # read the contents of the log before we start so the next read in the
509 # wait method are only looking at the text from this test instance
510 self._log_handle.read()
511 self.mono_pipe = subprocess.Popen(args, stdout=sys.stdout)
513 def _wait_xena_2544_complete(self):
515 Wait for Xena2544.exe completion.
521 self.mono_pipe.wait(60)
522 self._log_handle.close()
524 except subprocess.TimeoutExpired:
525 # check the log to see if Xena2544 has completed and mono is
527 data += self._log_handle.read()
528 if 'TestCompletedSuccessfully' in data:
529 self._log_handle.close()
530 self.mono_pipe.terminate()
533 def _stop_api_traffic(self):
535 Stop traffic through the socket API
536 :return: Return results from _create_api_result method
538 self.xmanager.ports[0].traffic_off()
539 if self._params['traffic']['bidir'] == 'True':
540 self.xmanager.ports[1].traffic_off()
543 stat = self._create_api_result()
548 self._logger.debug('Connect')
551 def disconnect(self):
552 """Disconnect from the traffic generator.
554 As with :func:`connect`, this function is optional.
557 Where implemented, this function should raise an exception on
562 self._logger.debug('disconnect')
564 self.xmanager.disconnect()
568 self._xsocket.disconnect()
571 def send_burst_traffic(self, traffic=None, duration=20):
572 """Send a burst of traffic.
574 See ITrafficGenerator for description
576 self._duration = duration
578 self._params['traffic'] = self.traffic_defaults.copy()
580 self._params['traffic'] = merge_spec(self._params['traffic'],
582 self._start_traffic_api(traffic['burst_size'])
583 return self._stop_api_traffic()
585 def send_cont_traffic(self, traffic=None, duration=20):
586 """Send a continuous flow of traffic.
588 See ITrafficGenerator for description
590 self._duration = duration
593 self._params['traffic'] = self.traffic_defaults.copy()
595 self._params['traffic'] = merge_spec(self._params['traffic'],
597 self._start_traffic_api(-1)
598 return self._stop_api_traffic()
600 def start_cont_traffic(self, traffic=None, duration=20):
601 """Non-blocking version of 'send_cont_traffic'.
603 See ITrafficGenerator for description
605 self._duration = duration
608 self._params['traffic'] = self.traffic_defaults.copy()
610 self._params['traffic'] = merge_spec(self._params['traffic'],
612 self._start_traffic_api(-1)
614 def stop_cont_traffic(self):
615 """Stop continuous transmission and return results.
617 return self._stop_api_traffic()
619 def send_rfc2544_throughput(self, traffic=None, tests=1, duration=20,
621 """Send traffic per RFC2544 throughput test specifications.
623 See ITrafficGenerator for description
625 self._duration = duration
628 self._params['traffic'] = self.traffic_defaults.copy()
630 self._params['traffic'] = merge_spec(self._params['traffic'],
632 self._setup_json_config(tests, lossrate, '2544_throughput')
633 self._start_xena_2544()
634 self._wait_xena_2544_complete()
636 root = ET.parse(os.path.join(_CURR_DIR, "xena2544-report.xml")).getroot()
638 if settings.getValue('TRAFFICGEN_XENA_RFC2544_VERIFY'):
639 # make sure we have a pass before even trying the verify. No need
640 # to run verify on a failed iteration.
642 os.path.join(_CURR_DIR, "xena2544-report.xml")).getroot()
643 if root[0][1][0].get('TestState') == "FAIL":
644 self._logger.info('Test failed, skipping verify')
645 return Xena._create_throughput_result(root)
647 # record the previous settings so we can revert to them if needed to
648 # run the binary search again if the verify fails.
650 old_duration = self._duration
651 old_min = settings.getValue('TRAFFICGEN_XENA_2544_TPUT_MIN_VALUE')
653 # record the original values to restore after execution
654 orig_min = settings.getValue('TRAFFICGEN_XENA_2544_TPUT_MIN_VALUE')
655 orig_max = settings.getValue('TRAFFICGEN_XENA_2544_TPUT_MAX_VALUE')
656 orig_init = settings.getValue('TRAFFICGEN_XENA_2544_TPUT_INIT_VALUE')
658 for attempt in range(
659 1, settings.getValue(
660 'TRAFFICGEN_XENA_RFC2544_MAXIMUM_VERIFY_ATTEMPTS')+1):
661 self._logger.info('Running verify attempt %s', attempt)
662 # get the last pass tx rate from the binary search
663 pass_rate = float(root[0][1][0].get('TotalTxRatePcnt'))
664 # run a one pass rfc2544 with the pass rate to see if it passes
665 # the verify duration
667 'TRAFFICGEN_XENA_2544_TPUT_INIT_VALUE', pass_rate)
669 'TRAFFICGEN_XENA_2544_TPUT_MIN_VALUE', pass_rate)
671 'TRAFFICGEN_XENA_2544_TPUT_MAX_VALUE', pass_rate)
672 self.start_rfc2544_throughput(
673 traffic, 1, settings.getValue(
674 'TRAFFICGEN_XENA_RFC2544_VERIFY_DURATION'), lossrate)
675 self.wait_rfc2544_throughput()
677 os.path.join(_CURR_DIR, "xena2544-report.xml")).getroot()
679 # If it passed, report the number of lost frames and exit the
681 if root[0][1][0].get('TestState') == "PASS":
682 self._logger.info('Verify passed, packets lost = %s',
683 root[0][1][0].get('TotalLossFrames'))
685 elif attempt < settings.getValue(
686 'TRAFFICGEN_XENA_RFC2544_MAXIMUM_VERIFY_ATTEMPTS'):
688 'Verify failed, resuming binary search, packets lost = %s',
689 root[0][1][0].get('TotalLossFrames'))
691 'TRAFFICGEN_XENA_2544_TPUT_MAX_VALUE',
692 pass_rate - float(settings.getValue(
693 'TRAFFICGEN_XENA_2544_TPUT_VALUE_RESOLUTION')))
694 if settings.getValue(
695 'TRAFFICGEN_XENA_RFC2544_BINARY_RESTART_SMART_SEARCH'):
697 'TRAFFICGEN_XENA_2544_TPUT_INIT_VALUE',
698 (pass_rate - float(old_min)) / 2)
701 'TRAFFICGEN_XENA_2544_TPUT_INIT_VALUE',
702 pass_rate - float(settings.getValue(
703 'TRAFFICGEN_XENA_2544_TPUT_VALUE_RESOLUTION')))
705 'TRAFFICGEN_XENA_2544_TPUT_MIN_VALUE', old_min)
707 'RFC2544 Initial rate: %s',
708 settings.getValue('TRAFFICGEN_XENA_2544_TPUT_INIT_VALUE'))
710 'RFC2544 Maximum rate: %s',
711 settings.getValue('TRAFFICGEN_XENA_2544_TPUT_MAX_VALUE'))
713 'RFC2544 Minimum rate: %s',
714 settings.getValue('TRAFFICGEN_XENA_2544_TPUT_MIN_VALUE'))
715 self._duration = old_duration
716 self.start_rfc2544_throughput(
717 traffic, old_tests, self._duration, lossrate)
718 self.wait_rfc2544_throughput()
720 os.path.join(_CURR_DIR, "xena2544-report.xml")).getroot()
723 'Maximum number of verify attempts reached. Reporting last result')
725 #restore original values
726 settings.setValue('TRAFFICGEN_XENA_2544_TPUT_MIN_VALUE', orig_min)
727 settings.setValue('TRAFFICGEN_XENA_2544_TPUT_MAX_VALUE', orig_max)
728 settings.setValue('TRAFFICGEN_XENA_2544_TPUT_INIT_VALUE', orig_init)
730 return Xena._create_throughput_result(root)
732 def start_rfc2544_throughput(self, traffic=None, tests=1, duration=20,
734 """Non-blocking version of 'send_rfc2544_throughput'.
736 See ITrafficGenerator for description
738 self._duration = duration
740 self._params['traffic'] = self.traffic_defaults.copy()
742 self._params['traffic'] = merge_spec(self._params['traffic'],
744 self._setup_json_config(tests, lossrate, '2544_throughput')
745 self._start_xena_2544()
747 def wait_rfc2544_throughput(self):
748 """Wait for and return results of RFC2544 test.
750 See ITrafficGenerator for description
752 self._wait_xena_2544_complete()
753 root = ET.parse(os.path.join(_CURR_DIR, "xena2544-report.xml")).getroot()
754 return Xena._create_throughput_result(root)
756 def send_rfc2544_back2back(self, traffic=None, tests=1, duration=20,
758 """Send traffic per RFC2544 back2back test specifications.
760 See ITrafficGenerator for description
762 self._duration = duration
765 self._params['traffic'] = self.traffic_defaults.copy()
767 self._params['traffic'] = merge_spec(self._params['traffic'],
769 self._setup_json_config(tests, lossrate, '2544_b2b')
770 self._start_xena_2544()
771 self._wait_xena_2544_complete()
772 root = ET.parse(os.path.join(_CURR_DIR, "xena2544-report.xml")).getroot()
773 return Xena._create_throughput_result(root)
775 def start_rfc2544_back2back(self, traffic=None, tests=1, duration=20,
777 """Non-blocking version of 'send_rfc2544_back2back'.
779 See ITrafficGenerator for description
781 self._duration = duration
783 self._params['traffic'] = self.traffic_defaults.copy()
785 self._params['traffic'] = merge_spec(self._params['traffic'],
787 self._setup_json_config(tests, lossrate, '2544_b2b')
788 self._start_xena_2544()
790 def wait_rfc2544_back2back(self):
791 """Wait and set results of RFC2544 test.
793 self._wait_xena_2544_complete()
794 root = ET.parse(os.path.join(_CURR_DIR, "xena2544-report.xml")).getroot()
795 return Xena._create_throughput_result(root)
798 if __name__ == "__main__":