question

Diwakar01 avatar image
Diwakar01 asked Diwakar01 published

Unable to capture traffic from xml file on specific port

Hi Guys ,


I am a new bee to spirent and have created a script which fetches xml file and tries to run from it but looks like it doesnt works at all :


I get the follwoing error on hCapture line :

hCapture = stc.get(hPortRx, "children-capture")

Error:

Spirent: 22:43:42.324 INFO - stc::get port2 -children-capture
Spirent: 22:43:42.324 ERROR - in get: invalid handle "port2": should have been obtained using create or get
Traceback (most recent call last):
File "SpirentSTCtraffic1.py", line 125, in <module>
hCapture = stc.get(hPortRx, "children-capture") #<port handle means the handle of the port on which capture needs to be performed.
File "path/StcPython.py", line 71, in get
retSvec = self.stcInt.salGet(handle, svecDashes)
RuntimeError: in get: invalid handle "port2": should have been obtained using create or get

why do i get this error ?

please find my script below:


#!/usr/bin/env python2.7

import sys

print sys.argv[1]

ENABLE_CAPTURE = True

from StcPython import StcPython
stc = StcPython()

stc.log("INFO", "Starting Test")

# This line will show the TestCenter commands on stdout
# stc.config("automationoptions", logto="stdout", loglevel="INFO")

# Retrieve and display the current API version.
print("SpirentTestCenter system version:\t", stc.get("system1", "version"))

# Physical topology

# Create the root project object

print("Creating project ...")
hProject = stc.create("project")

stc.config("automationoptions", logto="stdout", loglevel="INFO")

### Spirent Chassis and port details
#stc.reserve("{0}/{1}/{2} {3}/{4}/{5}".format(szChassisIp, iTxSlot, iTxPort, szChassisIp, iRxSlot, iRxPort))

szChassisIp = "10.22.32.2"
port1 = "2/2"
port2 = "2/4"
port_list = ['$port1',' $port2']

hPortTx = stc.create("port", under=hProject, location="//{0}/{1}".format(szChassisIp, port1), useDefaultHost="False")
hPortRx = stc.create("port", under=hProject, location="//{0}/{1}".format(szChassisIp, port2), useDefaultHost="False")


##### Load the saved .xml file. Modify the path as per your requirement.

stc.perform("LoadFromXml", Filename=sys.argv[1])

stc.apply()

# Connect to a chassis
print("Connecting ", szChassisIp)
stc.connect(szChassisIp)

## reserve the ports
print("Reserving / and / ".format(szChassisIp, port1, szChassisIp, port2))

stc.reserve("{0}/{1} {2}/{3}".format(szChassisIp, port1, szChassisIp, port2))

# Create the mapping between the physical ports and their logical
# representation in the test configuration.

print("Set up port mappings")
stc.perform("SetupPortMappings")

#Issue these commands to get the devices and port handles
#hProject = stc.get("system1", "children-project")

print ("project", hProject)

portList = stc.get(hProject, "children-port")
print ("ports" , portList)

deviceList = stc.get(hProject, "children-emulateddevice")
print ("devices" , deviceList)

##Query and list the streamblocks
sb_list = []
portList = portList.split()
for port in portList :
sb = stc.get(port, 'children-streamblock');
sb_list.append(sb );

print ("the list of streamblocks :", sb_list)


### start all devices
stc.perform("DevicesStartAll")

### start streamblocks
stc.perform("streamblockstartcommand" , StreamBlockList = sb_list)

# Subscribe the Streamblock Level Statistics
rds1 = stc.subscribe(Parent=hProject, resultparent=sb_list, ConfigType="StreamBlock", viewAttributeList="StreamId", resulttype="TxStreamResults")
rds2 = stc.subscribe(Parent=hProject, resultparent=sb_list, ConfigType="StreamBlock", viewAttributeList= ['FrameCount', 'StreamIndex', 'DroppedFrameCount'], resulttype="RxStreamSummaryResults")

# Refresh the views. Refresh is applied only on the receiving side to get the real time stats.
stc.perform("RefreshResultViewCommand" , ResultDataSet = rds2)

print ("the value of rds1 is :", rds1)
print ("the value of rds2 is :", rds2)

# Stop the streamblocks
stc.perform("streamblockstopcommand" , StreamBlockList = sb_list)


#### get the resultHandle and Pagecount
resultList = stc.get(rds2, "ResultHandleList")
resultList = resultList.split()

for result in resultList :
print("FrameCount :", stc.get(result, "FrameCount"))
print ("StreamIndex :", stc.get(result, "StreamIndex"))
print ("DroppedFrameCount :", stc.get(result, "DroppedFrameCount"))

###Stop all devices
print ("Stoping all the Devices ...\n")
stc.perform("DevicesStopAllCommand")

print (" ......................END OF TEST ......................................\n")

#perform generator and analyzer start

stc.perform("GeneratorStart", GeneratorList=hProject )
stc.perform("AnalyzerStart", AnalyzerList=hProject)

# Create a capture object. Automatically created and start capture
hCapture = stc.get(hPortRx, "children-capture") #<port handle means the handle of the port on which capture needs to be performed.
stc.config(hCapture, mode="REGULAR_MODE", srcMode="TX_RX_MODE")
stc.perform("CaptureStart", captureProxyId=hCapture)

#from time import gmtime, strftime
#print(strftime("%Y-%m-%d %H:%M:%S", gmtime()), " Retrieving Captured frames...")

stc.perform("CaptureStop", captureProxyId=hCapture)

# Save captured frames to a file.
stc.perform("CaptureDataSave", captureProxyId=hCapture, FileName="capture.pcap", FileNameFormat="PCAP", IsScap="FALSE")

print("Captured frames:\t", stc.get(hCapture, "PktCount"))


# Stop the generator.
stc.perform("GeneratorStop", GeneratorList=hProject)

# Stop the analyzer.
stc.perform("AnalyzerStop", AnalyzerList=hProject)

# Display some statistics.
hAnalyzerResults = stc.get(hProject, "children-AnalyzerPortResults")

print (hAnalyzerResults)

# Disconnect from a chassis
print("Disconnect from the chassis ...")
szChassisIp="10.22.12.4"
stc.disconnect(szChassisIp)
#stc.perform("CSTestSessionDisconnect", terminate="true")
# Delete configuration
print("Deleting project")
stc.delete(hProject)

stc.log("INFO", "Ending Test")

Spirent TestCenter (STC)Spirent Forumspythonpython script
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

eangeles avatar image
eangeles answered Diwakar01 commented

If you are going to load an existing config file, you should use the objects (ports in this case) that the configuration has already.
So don't create ports if you are going to load a config file since the handles seems to be deleting once you load the config.

If you want to get a list of the ports after you load the config, you can use the following:

ports = stc.get("project1", "children-port").split()

Regards,

Eduardo

1 comment
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Diwakar01 avatar image Diwakar01 commented ·

I want to capture it on a single port , port 1 . How should i fetch port 1

0 Likes 0 ·
Diwakar01 avatar image
Diwakar01 answered

hi guys ,

any inputs will be helpful

10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.