OpenIxia / ixnetwork_restpy

The IxNetwork python client.
https://openixia.github.io/ixnetwork_restpy/#/
MIT License
29 stars 16 forks source link

Unable to update traffic flow when test is running. #68

Open sngx13 opened 2 years ago

sngx13 commented 2 years ago

Hi, I'm having issues regenerating traffic flow when "FrameRate" is updated on the fly (while loop based on packet loss of the "Traffic Item Statistics" this is obviously possible via the GUI. Code snippet:

    traffic_config = traffic_item.ConfigElement.find()
    traffic_item.Generate()
    ixnetwork.Traffic.Apply()
    ixnetwork.Traffic.StartStatelessTrafficBlocking()
    traffic_item_statistics = session.StatViewAssistant(
        'Traffic Item Statistics'
    )
    #
    total_loss = float(traffic_item_statistics.Rows['Loss %'])
    while total_loss < 1:
        print(
            f'[+] Current total loss: {total_loss}%'
        )
        initial_rate += 50
        print(
            {
                'total_tx_frames': traffic_item_statistics.Rows['Tx Frames'],
                'total_tx_rate_mbps': traffic_item_statistics.Rows['Tx Rate (Mbps)'],
                'total_rx_frames': traffic_item_statistics.Rows['Rx Frames'],
                'total_rx_rate_mbps': traffic_item_statistics.Rows['Rx Rate (Mbps)'],
                'total_loss': traffic_item_statistics.Rows['Loss %']
            }
        )
        sleep(10)
        traffic_config.FrameRate.update(
            Type='bitsPerSecond',
            Rate=initial_rate
        )
        traffic_item.Generate() <--------------------------
        ixnetwork.info(
            ixnetwork.Traffic.TrafficItem.find()
        )
        if total_loss > 1 or initial_rate == 1000:
            print('[+] Loss exceeded 1%')
            # Stop the test
            ixnetwork.info('[+] Stopping the test...')
            ixnetwork.Traffic.StopStatelessTrafficBlocking()
            break

Warnings: ['Traffic Generate required: The Traffic Item was modified. Please perform a Traffic Generate to update the associated traffic Flow Groups']

Error Msg: Unable to regenerate a started/transmitting trafficItem

therkong commented 2 years ago

Hi, traffic must be stopped when you do Traffic Generate. If you want to modified the tx rate while the traffic is flowing, you should modify HighLevelStream (flowGroup) instead of ConfigElement. When you update the Rate in HighLevelStream, there's no need to regenerate the traffic, the new rate will take effect immediately. code below: flowGroups = traffic_item.HighLevelStream.find() flowGroups.FrameRate.update(Type='bitsPerSecond', Rate=initial_rate)

sngx13 commented 2 years ago

Hi, Thank you for your reply, this has done the trick, is there better documentation where I could of find this out? I couldn't seem to find anything like this in the samples. Also is there an alternative way of getting packet loss information (close to real time) other than calling:

 session.StatViewAssistant(
        'Traffic Item Statistics'
    )

Kind regards.

therkong commented 2 years ago

Glad that my suggestion worked! As far as documentation, RestPy API Reference guide (https://openixia.github.io/ixnetwork_restpy/#/reference) under the TrafficItem/ConfigElement and HighLevelStreams mentions about the relationship between these two objects, but it is not clear unless you are familiar with ixNet GUI's relationship between TrafficItem Wizard and the Flow Groups that get created when you hit 'Generate' option for the Traffic Item. From GUI, you can update the rate, then start/stop a Flow Group. However, if you modify the rate from Traffic Item wizard, you must do 'Generate' again and 'Generate' requires the traffic to be in 'stopped' state.

To get packet loss information, the code you're using is correct. Can you tell me a bit more on your test scenario? Why do you need the 'packet loss' count in real time? What is the limitation of polling the stats with your current code?

sngx13 commented 2 years ago

Hi, Well it's not so much real time, we are trying to distinguish 0% los for a particular DUT type so we'd want to run a test and determine a "golden" value for a particular device. As long as counters returned within the 'while' loop are correct we should be fine right? Also one thing i've forgot to ask, is there a way of clearing statistics between test runs ("Clear All Statistics" in the GUI)? Thank you.

therkong commented 2 years ago

you can simply call session.StatViewAssistant('Traffic Item Statistics'). Below is example code snip on getting Loss % and few other counters: trafficItemStatistics = session.StatViewAssistant('Traffic Item Statistics') for rowNumber,trafItemStat in enumerate(trafficItemStatistics.Rows): ixNetwork.info('\n\nSTATS: {}\n\n'.format(trafItemStat)) ixNetwork.info('\nRow:{} TxFrames:{} RxFrames:{} Frames Delta:{} Loss %:{}\n'.format( rowNumber, trafItemStat['Tx Frames'], trafItemStat['Rx Frames'], trafItemStat['Frames Delta'], trafItemStat['Loss %']))

I am not sure why you have 'while' loop/

Clear stats doc below: clearStats(Arg1=list, async_operation=bool)

Example call: ixNetwork.ClearStats() ==> returns right away or ixNetwork.ClearStats(['waitForTrafficStatsRefresh']) to wait for Traffic Item Statistics View to refresh