Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sngx13 opened this issue Jun 24, 2022 · 5 comments
Open

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

sngx13 opened this issue Jun 24, 2022 · 5 comments
Assignees

Comments

@sngx13
Copy link

sngx13 commented Jun 24, 2022

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
Copy link
Collaborator

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)

@therkong therkong self-assigned this Jun 26, 2022
@sngx13
Copy link
Author

sngx13 commented Jun 26, 2022

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
Copy link
Collaborator

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
Copy link
Author

sngx13 commented Jun 27, 2022

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
Copy link
Collaborator

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)

  • Arg1 (list(str[waitForPortStatsRefresh | waitForTrafficStatsRefresh])):
  • async_operation (bool=False): True to execute the operation asynchronously. Any subsequent rest api calls made through the Connection class will block until the operation is complete.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants