diff options
author | Maryam Tahhan <maryam.tahhan@intel.com> | 2015-06-08 15:03:08 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@172.30.200.206> | 2015-06-08 15:03:08 +0000 |
commit | f3f1ff9b08efa4a18bdcd2284d0a5f3b6ee526e0 (patch) | |
tree | a736bab8be95381d2277626c8df2f88ccce714d0 /tools/pkt_gen/ixia | |
parent | 1612a95c88e6ccff6f9b158f9b106e410b1d7324 (diff) | |
parent | 8d6777df09c3dc441013a31f21cc50ab3b0f42a3 (diff) |
Merge "framework: Add reworked framework to repo"
Diffstat (limited to 'tools/pkt_gen/ixia')
-rw-r--r-- | tools/pkt_gen/ixia/__init__.py | 18 | ||||
-rwxr-xr-x | tools/pkt_gen/ixia/ixia.py | 328 | ||||
-rwxr-xr-x | tools/pkt_gen/ixia/pass_fail.tcl | 721 |
3 files changed, 1067 insertions, 0 deletions
diff --git a/tools/pkt_gen/ixia/__init__.py b/tools/pkt_gen/ixia/__init__.py new file mode 100644 index 00000000..2f3d814a --- /dev/null +++ b/tools/pkt_gen/ixia/__init__.py @@ -0,0 +1,18 @@ +# Copyright 2015 Intel Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Implementation of IXIA traffic generator. +""" + +from .ixia import * diff --git a/tools/pkt_gen/ixia/ixia.py b/tools/pkt_gen/ixia/ixia.py new file mode 100755 index 00000000..92ef5203 --- /dev/null +++ b/tools/pkt_gen/ixia/ixia.py @@ -0,0 +1,328 @@ +# Copyright 2015 Intel Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""IXIA traffic generator model. + +Provides a model for the IXIA traffic generator. In addition, provides +a number of generic "helper" functions that are used to do the "heavy +lifting". + +This requires the following settings in your config file: + +* TRAFFICGEN_IXIA_LIB_PATH + IXIA libraries path +* TRAFFICGEN_IXIA_HOST + IXIA chassis IP address +* TRAFFICGEN_IXIA_CARD + IXIA card +* TRAFFICGEN_IXIA_PORT1 + IXIA Tx port +* TRAFFICGEN_IXIA_PORT2 + IXIA Rx port + +If any of these don't exist, the application will raise an exception +(EAFP). +""" + +import tkinter +import logging +import os + +from tools.pkt_gen import trafficgen +from conf import settings +from collections import OrderedDict +from core.results.results_constants import ResultsConstants + +_ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) +_IXIA_ROOT_DIR = settings.getValue('TRAFFICGEN_IXIA_ROOT_DIR') + + +def configure_env(): + """Configure envionment for TCL. + + """ + os.environ['IXIA_HOME'] = _IXIA_ROOT_DIR + + # USER MAY NEED TO CHANGE THESE IF USING OWN TCL LIBRARY + os.environ['TCL_HOME'] = _IXIA_ROOT_DIR + os.environ['TCLver'] = '8.5' + + # USER NORMALLY DOES NOT CHANGE ANY LINES BELOW + os.environ['IxiaLibPath'] = os.path.expandvars('$IXIA_HOME/lib') + os.environ['IxiaBinPath'] = os.path.expandvars('$IXIA_HOME/bin') + + os.environ['TCLLibPath'] = os.path.expandvars('$TCL_HOME/lib') + os.environ['TCLBinPath'] = os.path.expandvars('$TCL_HOME/bin') + + os.environ['TCL_LIBRARY'] = os.path.expandvars('$TCLLibPath/tcl$TCLver') + os.environ['TK_LIBRARY'] = os.path.expandvars('$TCLLibPath/tk$TCLver') + + os.environ['PATH'] = os.path.expandvars('$IxiaBinPath:.:$TCLBinPath:$PATH') + os.environ['TCLLIBPATH'] = os.path.expandvars('$IxiaLibPath') + os.environ['LD_LIBRARY_PATH'] = os.path.expandvars( + '$IxiaLibPath:$TCLLibPath:$LD_LIBRARY_PATH') + + os.environ['IXIA_RESULTS_DIR'] = '/tmp/Ixia/Results' + os.environ['IXIA_LOGS_DIR'] = '/tmp/Ixia/Logs' + os.environ['IXIA_TCL_DIR'] = os.path.expandvars('$IxiaLibPath') + os.environ['IXIA_SAMPLES'] = os.path.expandvars('$IxiaLibPath/ixTcl1.0') + os.environ['IXIA_VERSION'] = '6.60.1000.11' + + +def _build_set_cmds(values, prefix='dict set'): + """Generate a list of 'dict set' args for Tcl. + + Parse a dictionary and recursively build the arguments for the + 'dict set' Tcl command, given that this is of the format: + + dict set [name...] [key] [value] + + For example, for a non-nested dict (i.e. a non-dict element): + + dict set mydict mykey myvalue + + For a nested dict (i.e. a dict element): + + dict set mydict mysubdict mykey myvalue + + :param values: Dictionary to yield values for + :param prefix: Prefix to append to output string. Generally the + already generated part of the command. + + :yields: Output strings to be passed to a `Tcl` instance. + """ + for key in values: + value = values[key] + + # Not allowing derived dictionary types for now + # pylint: disable=unidiomatic-typecheck + if type(value) == dict: + _prefix = ' '.join([prefix, key]).strip() + for subkey in _build_set_cmds(value, _prefix): + yield subkey + continue + + # tcl doesn't recognise the strings "True" or "False", only "1" + # or "0". Special case to convert them + if type(value) == bool: + value = str(int(value)) + else: + value = str(value) + + if prefix: + yield ' '.join([prefix, key, value]).strip() + else: + yield ' '.join([key, value]).strip() + + +class Ixia(trafficgen.ITrafficGenerator): + """A wrapper around the IXIA traffic generator. + + Runs different traffic generator tests through an Ixia traffic + generator chassis by generating TCL scripts from templates. + """ + _script = os.path.join(os.path.dirname(__file__), 'pass_fail.tcl') + _tclsh = tkinter.Tcl() + _logger = logging.getLogger(__name__) + + def run_tcl(self, cmd): + """Run a TCL script using the TCL interpreter found in ``tkinter``. + + :param cmd: Command to execute + + :returns: Output of command, where applicable. + """ + self._logger.debug('%s%s', trafficgen.CMD_PREFIX, cmd) + + output = self._tclsh.eval(cmd) + + return output.split() + + def connect(self): + """Connect to Ixia chassis. + """ + ixia_cfg = { + 'lib_path': os.path.join(_IXIA_ROOT_DIR, 'lib', 'ixTcl1.0'), + 'host': settings.getValue('TRAFFICGEN_IXIA_HOST'), + 'card': settings.getValue('TRAFFICGEN_IXIA_CARD'), + 'port1': settings.getValue('TRAFFICGEN_IXIA_PORT1'), + 'port2': settings.getValue('TRAFFICGEN_IXIA_PORT2'), + } + + self._logger.info('Connecting to IXIA...') + + self._logger.debug('IXIA configuration configuration : %s', ixia_cfg) + + configure_env() + + for cmd in _build_set_cmds(ixia_cfg, prefix='set'): + self.run_tcl(cmd) + + output = self.run_tcl('source {%s}' % self._script) + if output: + self._logger.critical( + 'An error occured when connecting to IXIA...') + raise RuntimeError('Ixia failed to initialise.') + + self._logger.info('Connected to IXIA...') + + return self + + def disconnect(self): + """Disconnect from Ixia chassis. + """ + self._logger.info('Disconnecting from IXIA...') + + self.run_tcl('cleanUp') + + self._logger.info('Disconnected from IXIA...') + + def _send_traffic(self, flow, traffic): + """Send regular traffic. + + :param flow: Flow specification + :param traffic: Traffic specification + + :returns: Results from IXIA + """ + params = {} + + params['flow'] = flow + params['traffic'] = self.traffic_defaults.copy() + + if traffic: + params['traffic'] = trafficgen.merge_spec( + params['traffic'], traffic) + + for cmd in _build_set_cmds(params): + self.run_tcl(cmd) + + result = self.run_tcl('sendTraffic $flow $traffic') + + return result + + def send_burst_traffic(self, traffic=None, numpkts=100, time=20, + framerate=100): + """See ITrafficGenerator for description + """ + flow = { + 'numpkts': numpkts, + 'time': time, + 'type': 'stopStream', + 'framerate': framerate, + } + + result = self._send_traffic(flow, traffic) + + assert len(result) == 6 # fail-fast if underlying Tcl code changes + + #TODO - implement Burst results setting via TrafficgenResults. + + def send_cont_traffic(self, traffic=None, time=20, framerate=100, + multistream=False): + """See ITrafficGenerator for description + """ + flow = { + 'numpkts': 100, + 'time': time, + 'type': 'contPacket', + 'framerate': framerate, + 'multipleStreams': multistream, + } + + result = self._send_traffic(flow, traffic) + + return Ixia._create_result(result) + + def start_cont_traffic(self, traffic=None, time=20, framerate=100, + multistream=False): + """See ITrafficGenerator for description + """ + return self.send_cont_traffic(traffic, 0, framerate) + + def stop_cont_traffic(self): + """See ITrafficGenerator for description + """ + return self.run_tcl('stopTraffic') + + def send_rfc2544_throughput(self, traffic=None, trials=3, duration=20, + lossrate=0.0, multistream=False): + """See ITrafficGenerator for description + """ + params = {} + + params['config'] = { + 'trials': trials, + 'duration': duration, + 'lossrate': lossrate, + 'multipleStreams': multistream, + } + params['traffic'] = self.traffic_defaults.copy() + + if traffic: + params['traffic'] = trafficgen.merge_spec( + params['traffic'], traffic) + + for cmd in _build_set_cmds(params): + self.run_tcl(cmd) + + # this will return a list with one result + result = self.run_tcl('rfcThroughputTest $config $traffic') + + return Ixia._create_result(result) + + @staticmethod + def _create_result(result): + """Create result based on list returned from tcl script. + + :param result: list representing output from tcl script. + + :returns: dictionary strings representing results from + traffic generator. + """ + assert len(result) == 8 # fail-fast if underlying Tcl code changes + + result_dict = OrderedDict() + # drop the first 4 elements as we don't use/need them. In + # addition, IxExplorer does not support latency or % line rate + # metrics so we have to return dummy values for these metrics + result_dict[ResultsConstants.THROUGHPUT_RX_FPS] = result[4] + result_dict[ResultsConstants.THROUGHPUT_TX_FPS] = result[5] + result_dict[ResultsConstants.THROUGHPUT_RX_MBPS] = result[6] + result_dict[ResultsConstants.THROUGHPUT_TX_MBPS] = result[7] + result_dict[ResultsConstants.THROUGHPUT_TX_PERCENT] = \ + ResultsConstants.UNKNOWN_VALUE + result_dict[ResultsConstants.THROUGHPUT_RX_PERCENT] = \ + ResultsConstants.UNKNOWN_VALUE + result_dict[ResultsConstants.MIN_LATENCY_NS] = \ + ResultsConstants.UNKNOWN_VALUE + result_dict[ResultsConstants.MAX_LATENCY_NS] = \ + ResultsConstants.UNKNOWN_VALUE + result_dict[ResultsConstants.AVG_LATENCY_NS] = \ + ResultsConstants.UNKNOWN_VALUE + + return result_dict + +if __name__ == '__main__': + TRAFFIC = { + 'l3': { + 'proto': 'udp', + 'srcip': '10.1.1.1', + 'dstip': '10.1.1.254', + }, + } + + with Ixia() as dev: + print(dev.send_burst_traffic(traffic=TRAFFIC)) + print(dev.send_cont_traffic(traffic=TRAFFIC)) + print(dev.send_rfc2544_throughput(traffic=TRAFFIC)) diff --git a/tools/pkt_gen/ixia/pass_fail.tcl b/tools/pkt_gen/ixia/pass_fail.tcl new file mode 100755 index 00000000..63d4d914 --- /dev/null +++ b/tools/pkt_gen/ixia/pass_fail.tcl @@ -0,0 +1,721 @@ +#!/usr/bin/env tclsh + +# Copyright (c) 2014, Ixia +# Copyright (c) 2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +# This file is a modified version of a script generated by Ixia +# IxExplorer. + +lappend auto_path [list $lib_path] + +package req IxTclHal + +################################################################### +########################## Configuration ########################## +################################################################### + +# Verify that the IXIA chassis spec is given + +set reqVars [list "host" "card" "port1" "port2"] + +foreach var $reqVars { + set var_ns [namespace which -variable "$var"] + if { [string compare $var_ns ""] == 0 } { + errorMsg "The '$var' variable is undefined. Did you set it?" + return -1 + } +} + +# constants + +set fullHex "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF" +set hexToC5 "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5" + +#set payloadLookup(64) [string range $fullHex 0 11] +set payloadLookup(64) "000102030405" +set payloadLookup(128) "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445" +set payloadLookup(256) "$hexToC5" +set payloadLookup(512) "$fullHex$hexToC5" +set payloadLookup(1024) "$fullHex$fullHex$fullHex$hexToC5" + +################################################################### +###################### Chassis Configuration ###################### +################################################################### + +if {[isUNIX]} { + if {[ixConnectToTclServer $host]} { + errorMsg "Error connecting to Tcl Server $host" + return $::TCL_ERROR + } +} + +######### Chassis ######### + +# Now connect to the chassis +if [ixConnectToChassis $host] { + ixPuts $::ixErrorInfo + return 1 +} + +# Get the chassis ID to use in port lists +set chassis [ixGetChassisID $host] + +######### Ports ######### + +set portList [list [list $chassis $card $port1] \ + [list $chassis $card $port2]] + +# Clear ownership of the ports we’ll use +if [ixClearOwnership $portList force] { + ixPuts $::ixErrorInfo + return 1 +} + +# Take ownership of the ports we’ll use +if [ixTakeOwnership $portList] { + ixPuts $::ixErrorInfo + return 1 +} + +foreach portElem $portList { + set chasNum [lindex $portElem 0] + set cardNum [lindex $portElem 1] + set portNum [lindex $portElem 2] + + port setFactoryDefaults $chasNum $cardNum $portNum + port config -speed 10000 + port config -flowControl true + port config -transmitMode portTxModeAdvancedScheduler + port config -receiveMode [expr $::portCapture|$::portRxModeWidePacketGroup] + port config -advertise100FullDuplex false + port config -advertise100HalfDuplex false + port config -advertise10FullDuplex false + port config -advertise10HalfDuplex false + port config -portMode port10GigLanMode + port config -enableTxRxSyncStatsMode true + port config -txRxSyncInterval 2000 + port config -enableTransparentDynamicRateChange true + port config -enableDynamicMPLSMode true + if {[port set $chasNum $cardNum $portNum]} { + errorMsg "Error calling port set $chasNum $cardNum $portNum" + } + + packetGroup setDefault + packetGroup config -numTimeBins 1 + if {[packetGroup setRx $chasNum $cardNum $portNum]} { + errorMsg "Error calling packetGroup setRx $chasNum $cardNum $portNum" + } + + sfpPlus setDefault + sfpPlus config -enableAutomaticDetect false + sfpPlus config -txPreTapControlValue 1 + sfpPlus config -txMainTapControlValue 63 + sfpPlus config -txPostTapControlValue 2 + sfpPlus config -rxEqualizerControlValue 0 + if {[sfpPlus set $chasNum $cardNum $portNum]} { + errorMsg "Error calling sfpPlus set $chasNum $cardNum $portNum" + } + + filter setDefault + filter config -captureTriggerFrameSizeFrom 48 + filter config -captureTriggerFrameSizeTo 48 + filter config -captureFilterFrameSizeFrom 48 + filter config -captureFilterFrameSizeTo 48 + filter config -userDefinedStat1FrameSizeFrom 48 + filter config -userDefinedStat1FrameSizeTo 48 + filter config -userDefinedStat2FrameSizeFrom 48 + filter config -userDefinedStat2FrameSizeTo 48 + filter config -asyncTrigger1FrameSizeFrom 48 + filter config -asyncTrigger1FrameSizeTo 48 + filter config -asyncTrigger2FrameSizeFrom 48 + filter config -asyncTrigger2FrameSizeTo 48 + filter config -userDefinedStat1Enable true + filter config -userDefinedStat2Enable true + filter config -asyncTrigger1Enable true + filter config -asyncTrigger2Enable true + if {[filter set $chasNum $cardNum $portNum]} { + errorMsg "Error calling filter set $chasNum $cardNum $portNum" + } + + filterPallette setDefault + filterPallette config -pattern1 00 + filterPallette config -patternMask1 00 + filterPallette config -patternOffset1 20 + filterPallette config -patternOffset2 20 + if {[filterPallette set $chasNum $cardNum $portNum]} { + errorMsg "Error calling filterPallette set $chasNum $cardNum $portNum" + } + + capture setDefault + capture config -sliceSize 65536 + if {[capture set $chasNum $cardNum $portNum]} { + errorMsg "Error calling capture set $chasNum $cardNum $portNum" + } + + if {[interfaceTable select $chasNum $cardNum $portNum]} { + errorMsg "Error calling interfaceTable select $chasNum $cardNum $portNum" + } + + interfaceTable setDefault + if {[interfaceTable set]} { + errorMsg "Error calling interfaceTable set" + } + + interfaceTable clearAllInterfaces + if {[interfaceTable write]} { + errorMsg "Error calling interfaceTable write" + } + + ixEnablePortIntrinsicLatencyAdjustment $chasNum $cardNum $portNum true +} + +ixWritePortsToHardware portList + +if {[ixCheckLinkState $portList] != 0} { + errorMsg "One or more port links are down" +} + +proc sendTraffic { flowSpec trafficSpec } { + # Send traffic from IXIA. + # + # Transmits traffic from Rx port (port1), and captures traffic at + # Tx port (port2). + # + # Parameters: + # flowSpec - a dict detailing how the packet should be sent. Should be + # of format: + # {type, numpkts, time, framerate} + # trafficSpec - a dict describing the packet to be sent. Should be + # of format: + # { l2, vlan, l3} + # where each item is in turn a dict detailing the configuration of each + # layer of the packet + # Returns: + # Output from Rx end of Ixia if time != 0, else 0 + + ################################################## + ################# Initialisation ################# + ################################################## + + # Configure global variables. See documentation on 'global' for more + # information on why this is necessary + # https://www.tcl.tk/man/tcl8.5/tutorial/Tcl13.html + global portList + + # Extract the provided dictionaries to local variables to simplify the + # rest of the script + + # flow spec + + set streamType [dict get $flowSpec type] + set numPkts [dict get $flowSpec numpkts] + set time [expr {[dict get $flowSpec time] * 1000}] + set frameRate [dict get $flowSpec framerate] + + # traffic spec + + # extract nested dictionaries + set trafficSpec_l2 [dict get $trafficSpec l2] + set trafficSpec_l3 [dict get $trafficSpec l3] + set trafficSpec_vlan [dict get $trafficSpec vlan] + + set frameSize [dict get $trafficSpec_l2 framesize] + set srcMac [dict get $trafficSpec_l2 srcmac] + set dstMac [dict get $trafficSpec_l2 dstmac] + set srcPort [dict get $trafficSpec_l2 srcport] + set dstPort [dict get $trafficSpec_l2 dstport] + + set proto [dict get $trafficSpec_l3 proto] + set srcIp [dict get $trafficSpec_l3 srcip] + set dstIp [dict get $trafficSpec_l3 dstip] + + set vlanEnabled [dict get $trafficSpec_vlan enabled] + if {$vlanEnabled == 1 } { + # these keys won't exist if vlan wasn't enabled + set vlanId [dict get $trafficSpec_vlan id] + set vlanUserPrio [dict get $trafficSpec_vlan priority] + set vlanCfi [dict get $trafficSpec_vlan cfi] + } + + ################################################## + ##################### Streams #################### + ################################################## + + streamRegion get $::chassis $::card $::port1 + if {[streamRegion enableGenerateWarningList $::chassis $::card $::port1 false]} { + errorMsg "Error calling streamRegion enableGenerateWarningList $::chassis $::card $::port1 false" + } + + set streamId 1 + + stream setDefault + stream config -ifg 9.6 + stream config -ifgMIN 19.2 + stream config -ifgMAX 25.6 + stream config -ibg 9.6 + stream config -isg 9.6 + stream config -rateMode streamRateModePercentRate + stream config -percentPacketRate $frameRate + stream config -framesize $frameSize + stream config -frameType "08 00" + stream config -sa $srcMac + stream config -da $dstMac + stream config -numSA 16 + stream config -numDA 16 + stream config -asyncIntEnable true + stream config -dma $streamType + stream config -numBursts 1 + stream config -numFrames $numPkts + stream config -patternType incrByte + stream config -dataPattern x00010203 + stream config -pattern "00 01 02 03" + + protocol setDefault + protocol config -name ipV4 + protocol config -ethernetType ethernetII + if {$vlanEnabled == 1} { + protocol config -enable802dot1qTag vlanSingle + } + + ip setDefault + ip config -ipProtocol ipV4Protocol[string totitle $proto] + ip config -checksum "f6 75" + ip config -sourceIpAddr $srcIp + ip config -sourceIpAddrRepeatCount 10 + ip config -sourceClass classA + ip config -destIpAddr $dstIp + ip config -destIpAddrRepeatCount 10 + ip config -destClass classA + ip config -destMacAddr $dstMac + ip config -destDutIpAddr 0.0.0.0 + ip config -ttl 64 + if {[ip set $::chassis $::card $::port1]} { + errorMsg "Error calling ip set $::chassis $::card $::port1" + } + + "$proto" setDefault + "$proto" config -checksum "25 81" + if {["$proto" set $::chassis $::card $::port1]} { + errorMsg "Error calling $proto set $::chassis $::card $::port" + } + + if {$vlanEnabled == 1 } { + vlan setDefault + vlan config -vlanID $vlanId + vlan config -userPriority $vlanUserPrio + vlan config -cfi $vlanCfi + vlan config -mode vIdle + vlan config -repeat 10 + vlan config -step 1 + vlan config -maskval "0000XXXXXXXXXXXX" + vlan config -protocolTagId vlanProtocolTag8100 + } + + if {[vlan set $::chassis $::card $::port1]} { + errorMsg "Error calling vlan set $::chassis $::card $::port1" + } + + if {[port isValidFeature $::chassis $::card $::port1 $::portFeatureTableUdf]} { + tableUdf setDefault + tableUdf clearColumns + if {[tableUdf set $::chassis $::card $::port1]} { + errorMsg "Error calling tableUdf set $::chassis $::card $::port1" + } + } + + if {[port isValidFeature $::chassis $::card $::port1 $::portFeatureRandomFrameSizeWeightedPair]} { + weightedRandomFramesize setDefault + if {[weightedRandomFramesize set $::chassis $::card $::port1]} { + errorMsg "Error calling weightedRandomFramesize set $::chassis $::card $::port1" + } + } + + if {$proto == "tcp"} { + tcp setDefault + tcp config -sourcePort $srcPort + tcp config -destPort $dstPort + if {[tcp set $::chassis $::card $::port1 ]} { + errorMsg "Error setting tcp on port $::chassis.$::card.$::port1" + } + + if {$vlanEnabled != 1} { + udf setDefault + udf config -repeat 1 + udf config -continuousCount true + udf config -initval {00 00 00 01} + udf config -updown uuuu + udf config -cascadeType udfCascadeNone + udf config -step 1 + + packetGroup setDefault + packetGroup config -insertSequenceSignature true + packetGroup config -sequenceNumberOffset 38 + packetGroup config -signatureOffset 42 + packetGroup config -signature "08 71 18 05" + packetGroup config -groupIdOffset 52 + packetGroup config -groupId $streamId + packetGroup config -allocateUdf true + if {[packetGroup setTx $::chassis $::card $::port1 $streamId]} { + errorMsg "Error calling packetGroup setTx $::chassis $::card $::port1 $streamId" + } + } + } elseif {$proto == "udp"} { + udp setDefault + udp config -sourcePort $srcPort + udp config -destPort $dstPort + if {[udp set $::chassis $::card $::port1]} { + errorMsg "Error setting udp on port $::chassis.$::card.$::port1" + } + } + + if {[stream set $::chassis $::card $::port1 $streamId]} { + errorMsg "Error calling stream set $::chassis $::card $::port1 $streamId" + } + + incr streamId + streamRegion generateWarningList $::chassis $::card $::port1 + ixWriteConfigToHardware portList -noProtocolServer + + if {[packetGroup getRx $::chassis $::card $::port2]} { + errorMsg "Error calling packetGroup getRx $::chassis $::card $::port2" + } + + ################################################## + ######### Traffic Transmit and Results ########### + ################################################## + + # Transmit traffic + + logMsg "Clearing stats for all ports" + ixClearStats portList + + logMsg "Starting packet groups on port $::port2" + ixStartPortPacketGroups $::chassis $::card $::port2 + + logMsg "Starting Capture on port $::port2" + ixStartPortCapture $::chassis $::card $::port2 + + logMsg "Starting transmit on port $::port1" + ixStartPortTransmit $::chassis $::card $::port1 + + # If time=0 is passed, exit after starting transmit + + if {$time == 0} { + logMsg "Sending traffic until interrupted" + return + } + + logMsg "Waiting for $time ms" + + # Wait for time - 1 second to get traffic rate + + after [expr "$time - 1"] + + # Get result + + set result [stopTraffic] + + if {$streamType == "contPacket"} { + return $result + } elseif {$streamType == "stopStream"} { + set payError 0 + set seqError 0 + set captureLimit 3000 + + # explode results from 'stopTraffic' for ease of use later + set framesSent [lindex $result 0] + set framesRecv [lindex $result 1] + set bytesSent [lindex $result 2] + set bytesRecv [lindex $result 3] + + if {$framesSent <= $captureLimit} { + captureBuffer get $::chassis $::card $::port2 1 $framesSent + set capturedFrames [captureBuffer cget -numFrames] + + set notCaptured [expr "$framesRecv - $capturedFrames"] + if {$notCaptured != 0} { + errorMsg "'$notCaptured' frames were not captured" + } + + if {$proto == "tcp"} { + for {set z 1} {$z <= $capturedFrames} {incr z} { + captureBuffer getframe $z + set capFrame [captureBuffer cget -frame] + regsub -all " " $capFrame "" frameNoSpaces + set frameNoSpaces + + set startPayload 108 + set endPayload [expr "[expr "$frameSize * 2"] - 9"] + set payload [string range $frameNoSpaces $startPayload $endPayload] + + if {$vlanEnabled != 1} { + set startSequence 76 + set endSequence 83 + set sequence [string range $frameNoSpaces $startSequence $endSequence] + scan $sequence %x seqDecimal + set seqDecimal + if {"$payload" != $::payloadLookup($frameSize)} { + errorMsg "frame '$z' payload: invalid payload" + incr payError + } + # variable z increments from 1 to total number of packets + # captured TCP sequence numbers start at 0, not 1. When + # comparing sequence numbers for captured frames, reduce + # variable z by 1 i.e. frame 1 with sequence 0 is compared + # to expected sequence 0. + if {$seqDecimal != $z-1} { + errorMsg "frame '$z' sequence number: Found '$seqDecimal'. Expected '$z'" + incr seqError + } + } + } + } + logMsg "Sequence Errors: $seqError" + logMsg "Payload Errors: $payError\n" + } else { + errorMsg "Too many packets for capture." + } + + set result [list $framesSent $framesRecv $bytesSent $bytesRecv $payError $seqError] + return $result + } else { + errorMsg "streamtype is not supported: '$streamType'" + } +} + +proc stopTraffic {} { + # Stop sending traffic from IXIA. + # + # Stops Transmit of traffic from Rx port. + # + # Returns: + # Output from Rx end of Ixia. + + ################################################## + ################# Initialisation ################# + ################################################## + + # Configure global variables. See documentation on 'global' for more + # information on why this is necessary + # https://www.tcl.tk/man/tcl8.5/tutorial/Tcl13.html + global portList + + ################################################## + ####### Stop Traffic Transmit and Results ######## + ################################################## + + # Read frame rate of transmission + + if {[stat getRate statAllStats $::chassis $::card $::port1]} { + errorMsg "Error reading stat rate on port $::chassis $::card $::port1" + return $::TCL_ERROR + } + + set sendRate [stat cget -framesSent] + set sendRateBytes [stat cget -bytesSent] + + if {[stat getRate statAllStats $::chassis $::card $::port2]} { + errorMsg "Error reading stat rate on port $::chassis $::card $::port2" + return $::TCL_ERROR + } + + set recvRate [stat cget -framesReceived] + set recvRateBytes [stat cget -bytesReceived] + + # Wait for a second, else we get funny framerate statistics + after 1 + + # Stop transmission of traffic + ixStopTransmit portList + + if {[ixCheckTransmitDone portList] == $::TCL_ERROR} { + return -code error + } else { + logMsg "Transmission is complete.\n" + } + + ixStopPacketGroups portList + ixStopCapture portList + + # Get statistics + + if {[stat get statAllStats $::chassis $::card $::port1]} { + errorMsg "Error reading stat on port $::chassis $::card $::port1" + return $::TCL_ERROR + } + + set bytesSent [stat cget -bytesSent] + set framesSent [stat cget -framesSent] + + if {[stat get statAllStats $::chassis $::card $::port2]} { + errorMsg "Error reading stat on port $::chassis $::card $::port2" + return $::TCL_ERROR + } + + set bytesRecv [stat cget -bytesReceived] + set framesRecv [stat cget -framesReceived] + + set bytesDropped [expr "$bytesSent - $bytesRecv"] + set framesDropped [expr "$framesSent - $framesRecv"] + + logMsg "Frames Sent: $framesSent" + logMsg "Frames Recv: $framesRecv" + logMsg "Frames Dropped: $framesDropped\n" + + logMsg "Bytes Sent: $bytesSent" + logMsg "Bytes Recv: $bytesRecv" + logMsg "Bytes Dropped: $bytesDropped\n" + + logMsg "Frame Rate Sent: $sendRate" + logMsg "Frame Rate Recv: $recvRate\n" + + set result [list $framesSent $framesRecv $bytesSent $bytesRecv $sendRate $recvRate $sendRateBytes $recvRateBytes] + + return $result +} + +proc rfcThroughputTest { testSpec trafficSpec } { + # Execute RFC tests from IXIA. + # + # Wraps the sendTraffic proc, repeatedly calling it, storing the result and + # performing an iterative binary search to find the highest possible RFC + # transmission rate. Abides by the specification of RFC2544 as given by the + # IETF: + # + # https://www.ietf.org/rfc/rfc2544.txt + # + # Parameters: + # testSpec - a dict detailing how the test should be run. Should be + # of format: + # {numtrials, duration, lossrate} + # trafficSpec - a dict describing the packet to be sent. Should be + # of format: + # { l2, l3} + # where each item is in turn a dict detailing the configuration of each + # layer of the packet + # Returns: + # Highest rate with acceptable packet loss. + + ################################################## + ################# Initialisation ################# + ################################################## + + # Configure global variables. See documentation on 'global' for more + # information on why this is necessary + # https://www.tcl.tk/man/tcl8.5/tutorial/Tcl13.html + global portList + + # Extract the provided dictionaries to local variables to simplify the + # rest of the script + + # testSpec + + set numTrials [dict get $testSpec trials] ;# we don't use this yet + set duration [dict get $testSpec duration] + set lossRate [dict get $testSpec lossrate] + set multipleStream [dict get $testSpec multipleStreams] ;# we don't use this yet + + # variables used for binary search of results + set min 1 + set max 100 + set diff [expr "$max - $min"] + + set result [list 0 0 0 0 0 0 0 0] ;# best result found so far + set percentRate 100 ;# starting throughput percentage rate + + ################################################## + ######### Traffic Transmit and Results ########### + ################################################## + + # iterate a maximum of 20 times, sending packets at a set rate to + # find fastest possible rate with acceptable packetloss + # + # As a reminder, the binary search works something like this: + # + # percentRate < idealValue --> min = percentRate + # percentRate > idealValue --> max = percentRate + # percentRate = idealValue --> max = min = percentRate + # + for {set i 0} {$i < 20} {incr i} { + dict set flowSpec type "contPacket" + dict set flowSpec numpkts 100 ;# this can be bypassed + dict set flowSpec time $duration + dict set flowSpec framerate $percentRate + + set flowStats [sendTraffic $flowSpec $trafficSpec] + + # explode results from 'sendTraffic' for ease of use later + set framesSent [lindex $flowStats 0] + set framesRecv [lindex $flowStats 1] + set sendRate [lindex $flowStats 4] + + set framesDropped [expr "$framesSent - $framesRecv"] + if {$framesSent > 0} { + set framesDroppedRate [expr "double($framesDropped) / $framesSent"] + } else { + set framesDroppedRate 100 + } + + # check if we've already found the rate before 10 iterations, i.e. + # 'percentRate = idealValue'. This is as accurate as we can get with + # integer values. + if {[expr "$max - $min"] <= 0.5 } { + break + } + + # handle 'percentRate <= idealValue' case + if {$framesDroppedRate <= $lossRate} { + logMsg "Frame sendRate of '$sendRate' pps succeeded ('$framesDropped' frames dropped)" + + set result $flowStats + set min $percentRate + + set percentRate [expr "$percentRate + ([expr "$max - $min"] * 0.5)"] + # handle the 'percentRate > idealValue' case + } else { + if {$framesDropped == $framesSent} { + errorMsg "Dropped all frames!" + } + + errorMsg "Frame sendRate of '$sendRate' pps failed ('$framesDropped' frames dropped)" + + set max $percentRate + set percentRate [expr "$percentRate - ([expr "$max - $min"] * 0.5)"] + } + } + + set bestRate [lindex $result 4] + + logMsg "$lossRate% packet loss rate: $bestRate" + + return $result +} |