Exemplo n.º 1
0
import sys
import time

ENABLE_CAPTURE = True

# This loads the TestCenter library.
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
szChassisIp1 = "10.29.0.49"
szChassisIp2 = "10.29.0.45"
txPortLoc = "//%s/%s/%s" % ( szChassisIp1, 1, 1)
rxPortLoc = "//%s/%s/%s" % ( szChassisIp2, 1, 1)

# Create the root project object
print "Creating project ..."
hProject = stc.create("project")

# Create ports
print "Creating ports ..."
hPortTx = stc.create("port", under=hProject, location=txPortLoc, useDefaultHost=False)
hPortRx = stc.create("port", under=hProject, location=rxPortLoc, useDefaultHost=False)
Exemplo n.º 2
0
    parent=hProject,
    resultParent=hProject,
    configType='analyzer',
    resultType='analyzerportresults',
    filterList='',
    viewAttributeList='totalframecount totalframerate totalbitrate',
    interval='1',
    filenamePrefix='analyzerportresults')

# If sequencer is configured in XML, start it and wait for it to finish
#stc.perform('sequencerStart')
#rv = stc.waitUntilComplete()  # this call is blocking. check rv for pass/fail

# Start generators without using sequencer
print("Starting generators\n")
generator1 = stc.get(ports[0], 'children-Generator')
generator2 = stc.get(ports[1], 'children-Generator')
stc.perform('GeneratorStart', GeneratorList=generator1)
stc.perform('GeneratorStart', GeneratorList=generator2)

print("Wait 10 seconds..\n")
time.sleep(10)

# Check frames per second
sb1 = stc.get(ports[0], 'children-StreamBlock')
rx_results1 = stc.get(sb1, 'children-RxStreamSummaryResults')
framerate1 = stc.get(rx_results1, 'FrameRate')
sb2 = stc.get(ports[1], 'children-StreamBlock')
rx_results2 = stc.get(sb2, 'children-RxStreamSummaryResults')
framerate2 = stc.get(rx_results2, 'FrameRate')
Exemplo n.º 3
0
# eg: os.environ['STC_PRIVATE_INSTALL_DIR'] = '/home/mjefferson/spirent/stc/stc4.59/'

print "Loading the Spirent TestCenter API..."
sys.path.append('/home/mjefferson/spirent/stc/stc4.61/API/Python')
from StcPython import StcPython
stc = StcPython()

# Instruct the API to not display all commands to STDOUT.
stc.config("AutomationOptions", logTo="stcapi.log", logLevel="INFO")

stc.perform("LoadFromDatabaseCommand",
            DatabaseConnectionString="capturetest.tcc")

# Remap port locations if necessary.
for port, location in zip(
        stc.get("system1.project", "children-port").split(), port_locations):
    print "Remapping " + port + " to " + location
    stc.config(port, location=location)

# Connect to the hardware.
stc.perform("AttachPorts",
            AutoConnect="true",
            PortList=stc.get("system1.project", "children-port"))
stc.apply()

captureStart()

# If the GeneratorList argument is not specified, then all generators is assumed.
print "Starting traffic"
stc.perform("GeneratorStartCommand")
Exemplo n.º 4
0
if labserverip:
    # If you are using a lab server, connect to it now.
    print("Connecting to Lab Server")
    stc.perform("CSTestSessionConnect",
                host=labserverip,
                TestSessionName="sample",
                CreateNewTestSession="true")

    # Terminate the Lab Server session when the last client disconnects.
    stc.perform("TerminateBll", TerminateType="ON_LAST_DISCONNECT")

# Instruct the API to not display all commands to STDOUT.
stc.config("AutomationOptions", logTo="stcapi.log", logLevel="INFO")

# Save the project handle for later. This is not strictly necessary.
project = stc.get("system1", "children-project")

# Create a port for each location specified.
for location in locationlist:
    # If you are connecting to a single-speed port, this is all you need to do.
    # If you are connecting to a multi-speed port, you may need to create the appropriate phy object (e.g., Ethernet10GigFiber).
    port = stc.create("port", under=project, location=location)

    # Configure the port rate to 100% line-rate.
    stc.config(port + ".generator.generatorconfig",
               fixedload=100,
               loadunit="PERCENT_LINE_RATE")

    # Create a raw streamblock. Headers include: EthernetII, Vlan, IPv4, IPv6, Mpls, Tcp, UDP, PPP, GRE, etc.
    streamblock = stc.create("StreamBlock",
                             under=port,
Exemplo n.º 5
0
# You first need to either set the environment variable "STC_PRIVATE_INSTALL_DIR",
# or change the StcPython.py file ("STC_PRIVATE_INSTALL_DIR") to point to your
# installation.
# eg: os.environ['STC_PRIVATE_INSTALL_DIR'] = '/home/mjefferson/spirent/stc/stc4.59/'

print "Loading the Spirent TestCenter API..."
sys.path.append('/home/mjefferson/spirent/stc/stc4.59/API/Python')
from StcPython import StcPython
stc = StcPython()

# Instruct the API to not display all log entries to STDOUT.
stc.config("AutomationOptions", logTo="stcapi.log", logLevel="INFO")

# Create the configuration from scratch.
print "Creating the configuration from scratch..."
project = stc.get("system1", "children-project")

# Start by creating two ports. port1 is the Tx port, and port2 is the Rx.
port1 = stc.create("port", under=project, location="10.140.99.120/1/1")
port2 = stc.create("port", under=project, location="10.140.99.121/1/1")

# Create a single Emulated Device on each port.
# The "IfStack" is the space-separated list of interface objects used by the device.
# It is sorted top-down, meaning that the EthIIIf object will be the last element of the list.
#   eg: EthIIIf, VlanIf, IPv4If, IPv6If, GREIf, L2tpv2If, MplsIf, etc
result = stc.perform("DeviceCreate",
                     ParentList=project,
                     DeviceType="Host",
                     IfStack="Ipv4If VlanIf EthIIIf",
                     IfCount="1 1 1",
                     Port=port1)
def loadTestCenter(version):
    from StcPython import StcPython
    stc = StcPython(version)
    print "Spirent TestCenter version : %s" % stc.get("system1", "version")
Exemplo n.º 7
0
# Note that a viable Tcl environment must be available for the library to run
# and that the Python Tkinter package must be installed.
# The version of the TestCenter library that will be loaded will be determined
# by normal Tcl package management. The easiest way to change versions will be
# to set the TCLLIBPATH environment variable to point to the desired version
# just like would be done in a normal Tcl installation.
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
szChassisIp = "192.168.22.253"
iTxSlot = 2
iTxPort = 1
iRxSlot = 2
iRxPort = 2

# Create the root project object
print("Creating project ...")
hProject = stc.create("project")

# Create ports
print("Creating ports ...")
hPortTx = stc.create("port",
Exemplo n.º 8
0
class StcDriver(API):
   
    def __init__(self):
        #super(API, self).__init__()
        self.handle = StcPython()
        main.log.info("STC component initialized")

    def connect(self,**connectargs):
        for key in connectargs:
            vars(self)[key] = connectargs[key]

        self.name = self.options['name']
        main.log.info("Component name is "+self.name)
        connect_result = super(API,self).connect()
        main.log.info("Main dir "+main.logdir)
        self.logFileName = main.logdir+"/"+self.name+".session"
        main.log.info("Session log file is "+self.logFileName)
        self.handle.config('automationoptions', loglevel='info',logto=self.logFileName)
        main.log.info("Connected successfully")
        return main.TRUE
    
    def apply(self):
        try :
            main.log.info("apply the action")
            return self.handle.apply()
        except :
            main.log.error("Apply failed because of Exception"+str(sys.exc_info()[0]))
            return { 'result' : main.FALSE , 'error' : sys.exc_info()[0]}
    
    def create(self,objectTypeString,**arguments) :
        try :
            main.log.info("creating arguments") 
            #return { result : main.TRUE,return value : self.handle.create(objectTypeString,**arguments) }
            return self.handle.create(objectTypeString,**arguments)
            #return ReturnValue(main.TRUE,self.handle.create(objectTypeString,**arguments))
        except :
            main.log.error("Operation "+str(objectTypeString)+" failed because of exception "+str(sys.exc_info()[0]))
            return { 'result' : main.FALSE, 'error' : sys.exc_info()[0] }

    
    def config(self,handleString,**attributes) :
        try :
            main.log.info("Configure Port locations")
            self.handle.config(handleString,**attributes)
            #return { result : main.TRUE, return value : slef.handle.config(handleString,**attributes)}
            return self.handle.config(handleString,**attributes)
            #return ReturnValue(main.TRUE,self.handle.config(handleString,**attributes))
        except :
            main.log.error("Operation "+str(handleString)+" failed because of exception "+str(sys.exc_info()[0]))
            return { 'result' : main.FALSE, 'error' : sys.exc_info()[0] } 
    
    def get(self,handleString, attribute) :
        try :
            main.log.info("Getting attributes for "+str(handleString))
            #return { result : main.TRUE , return value : self.handle.get(handleString,attribute)}
            return self.handle.get(handleString, attribute)
            #return ReturnValue(main.TRUE,self.handle.get(handleString, attribute))
        except :
            main.log.error("operation"+str(handleString)+"failed because of exception"+str(sys.exc_info()[0]))
            return { 'result' :main.FALSE , 'error': sys.exc_info()[0]}

    def perform(self,commandNameString, **attribute) :
        try :
            main.log.info("Performing action "+str(commandNameString))
            #return { result : main.TRUE , return value : self.handle.perform(commandNameString,**attribute)}
            return self.handle.perform(commandNameString, **attribute)
            #return ReturnValue(main.TRUE , self.handle.perform(commandNameString,**attribute))
        except :
            main.log.error("Operation "+str(commandNameString)+" failed because of exception "+str(sys.exc_info()[0]))
            return { 'result' : main.FALSE, 'error' : sys.exc_info()[0] }
    
    def subscribe(self,**inputParams) :
        try :
            main.log.info("subscribe the result")
            #return { result : main.TRUE , return value : self.handle.subscribe(**inputParams)}
            return self.handle.subscribe(**inputParams)
            #return ReturnValue(main.TRUE,self.handle.subscribe(**inputParams))
        except :
            main.log.error("Operation failed because of exception "+str(sys.exc_info()[0]))
            return { 'result' : main.FALSE , 'error' : sys.exc_info()[0] }

    def disconnect(self,hostNameString) :
        try :
            main.log.info("disconnect")
            #return { result : main.TRUE ,return value : self.handle.disconnect(hostNameString)}
            return self.handle.disconnect(str(hostNameString))
            #return ReturnValue(main.TRUE,self.handle.disconnect(hostNameString))
        except :
            main.log.error("Operation failed because of exception "+str(sys.exc_info()[0]))
            return { 'result' : main.FALSE, 'error' : sys.exc_info()[0] }

    def sleep(self,numberSecondsInteger) :
        try :
            main.log.info("sleep time is")
            #return { result : main.TRUE , return value : self.handle.sleep(numberSecondsInteger)}
            return self.handle.sleep(numberSecondsInteger)
            #return ReturnValue(main.TRUE,self.handle.sleep(numberSecondsInteger))
        except :
            main.log.error("Operation failed because of exception "+str(sys.exc_info()[0]))
            return { 'result' : main.FALSE, 'error' : sys.exc_info()[0] }

    def unsubscribe(self,resultDataSetHandleString) :
        try :
            main.log.info("unsubscribe the ports"+str(resultDataSetHandleString))
            return self.handle.unsubscribe(str(resultDataSetHandleString))
            #return { result : main.TRUE , return value : self.handle.unsubscribe(resultDataSetHandleString)}
            #return ReturnValue(main.TRUE,self.handle.unsubscribe(resultDataSetHandleString))
        except :
            main.log.error("unsubscribe"+str(resultDataSetHandleString)+" failed because of exception "+str(sys.exc_info()[0]))
            return { 'result' : main.FALSE, 'error' : sys.exc_info()[0] }

    def delete(self,handleString) :
        try :
            main.log.info("Deleting ports"+str(handleString))
            return self.handle.delete(str(handleString))
            #return ReturnValue(main.TRUE,self.handle.delete(handleString))
        except :
            main.log.error("Deletion of "+str(handleString)+"failed because of exception "+str(sys.exc_info()[0]))
            return { 'result' : main.FALSE, 'error' : sys.exc_info()[0] }
    def parseresults(self,Attribute,CsvFile) :
        
        try :
            main.log.info("parsing the CSV file for the traffic results")                 
            totalrows = len(open('/home/sudheer-570/Desktop/sk/TestON/bin/Untitled/'+CsvFile).readlines())
            fp = open("/home/sudheer-570/Desktop/sk/TestON/bin/Untitled/"+CsvFile,'Ur')
            data_list = []
            attributes=[]
            attribute_values=[]
            for line in fp:
                data_list.append(line.strip().split(','))
            attribute_values=data_list[totalrows-1]
            attributes=data_list[totalrows-3]

            for index in range (0,100) :
                if attributes[index]==Attribute:
                    main.log.info("Given Attribute Name is:'"+Attribute+"'")
                    main.log.info("Attribute value is:'"+attribute_values[index]+"'")
                    result = attribute_values[index]
                    if result == '0' :
                        main.log.info("Traffic is not generated on this attribute :"+Attribute)
                        return main.FALSE
                    else :
                        return result
        except :
            main.log.error("operation failed because of"+str(sys.exc_info()[0]))
            return { 'result' : main.FALSE, 'error' : sys.exc_info()[0] }
Exemplo n.º 9
0
chassisAddress = '172.33.42.4'
slot = 4
port = 3
print "using //%s/%s/%s" % (chassisAddress, slot, port)

#stc.connect('172.33.42.4')
#stc.reserve('//172.33.42.4/4/3')

print 'Create a Project  - root'

project = stc.create('project')

print 'Get Project attributes'

projectAtt = stc.get(project, 'name')

print projectAtt
print 'Create Ports under', project

port1 = stc.create('port', under=project)
print 'Configure Port locations'
stc.config(port1, location="//%s/%s/%s" % (chassisAddress, slot, port))

print 'Creating StreamBlock on Port  1'
streamBlock = stc.create('streamBlock', under=port1)
generator = stc.get(port1, 'children-generator')

print 'Attaching Ports...'

stc.perform('AttachPorts', portList=[port1], autoConnect='TRUE')
from StcPython import StcPython
stc = StcPython()

labserverip = "192.168.130.207"
sessionname = "test"
username = "******"

# Connect to an existing Lab Server session...
print("Connecting to the Lab Server...")
stc.perform("CSTestSessionConnect",
            host=labserverip,
            TestSessionName=sessionname,
            OwnerId=username,
            CreateNewTestSession="false")

project = stc.get("system1", "children-project")

# # Load from a configuration file, instead of connecting to an existing session.
# print("DEBUG ONLY!")
# stc.perform("LoadFromDatabaseCommand", DatabaseConnectionString="streamblock.tcc")
# project = stc.get("system1", "children-project")

# # Connect to the hardware.
# stc.perform("AttachPorts", AutoConnect="true", PortList=stc.get(project, "children-port"))
# stc.apply()

stc.perform("GeneratorStart")
time.sleep(5)

rds = sbrds()
import sys
sys.path.append('/home/mjefferson/spirent/stc/stc4.61/API/Python/')
from StcPython import StcPython
stc = StcPython()

port_traffic1 = stc.create("port", under="project1")
port_traffic2 = stc.create("port", under="project1")

# NOTE: The FrameConfig PDUs are case-sensitive.
#       Examples are: EthernetII, Vlan, IPv4, IPv6, Mpls, Tcp, UDP, PPP, Gre, etc. There are many more.
# Default: "EthernetII IPv4"}
streamblock1 = stc.create("StreamBlock",
                          under=port_traffic1,
                          FrameConfig="EthernetII IPv4")
stc.get(streamblock1)
stc.config(streamblock1 + ".ethernet:EthernetII",
           srcMac="00:11:94:00:00:02",
           dstMac="00:12:94:00:00:02")
stc.config(streamblock1 + ".ipv4:IPv4",
           sourceAddr="192.168.11.2",
           destAddr="192.168.12.2",
           gateway="192.168.11.1",
           prefixlength="24",
           destprefixlength="24")

streamblock2 = stc.create("StreamBlock",
                          under=port_traffic2,
                          FrameConfig="EthernetII IPv4")
stc.get(streamblock2)
stc.config(streamblock2 + ".ethernet:EthernetII",
           srcMac="00:12:94:00:00:02",
Exemplo n.º 12
0

###############################################################################
####
####    Main
####
###############################################################################

print("Connecting to Lab Server")
stc.perform("CSTestSessionConnect",
            host=labserverip,
            TestSessionName=sessionname,
            OwnerId=username,
            CreateNewTestSession="false")

project = stc.get("system1", "children-project")

# Subscribe to port results.
portrds = getRDS("GeneratorPortResults")

if portrds == "":
    print("Subscribing to port results...")
    # Port results. These result objects are stored under the generator and analyzer objects.
    rds = stc.subscribe(Parent=project,
                        ConfigType="Generator",
                        resulttype="GeneratorPortResults")
    stc.create("ResultQuery",
               under=rds,
               ResultRootList=project,
               ConfigClassId="Analyzer",
               ResultClassId="AnalyzerPortResults")
Exemplo n.º 13
0
# You first need to either set the environment variable "STC_PRIVATE_INSTALL_DIR",
# or change the StcPython.py file ("STC_PRIVATE_INSTALL_DIR") to point to your
# installation.
# eg: os.environ['STC_PRIVATE_INSTALL_DIR'] = '/home/mjefferson/spirent/stc/stc4.59/'

print "Loading the Spirent TestCenter API..."
sys.path.append('/home/mjefferson/spirent/stc/stc4.59/API/Python')
from StcPython import StcPython
stc = StcPython()

# Instruct the API to not display all commands to STDOUT.
stc.config("AutomationOptions", logTo="stcapi.log", logLevel="INFO")

# Create the configuration from scratch.
print "Creating the configuration from scratch..."
project = stc.get("system1", "children-project")

# Start by creating two ports. port1 is the Tx port, and port2 is the Rx.
port1 = stc.create("port", under=project, location="10.140.99.120/1/1")
port2 = stc.create("port", under=project, location="10.140.99.121/1/1")

# Create a single Emulated Device on each port.
# The "IfStack" is the space-separated list of interface objects used by the device.
# It is sorted top-down, meaning that the EthIIIf object will be the last element of the list.
#   eg: EthIIIf, VlanIf, IPv4If, IPv6If, GREIf, L2tpv2If, MplsIf, etc
# The "IfCount" is a space-separated list indicating how many interface object instances to create for each
# element of the IfStack. This list is ordered in the same way as the IfStack.
#   eg: IfStack="Ipv4If VlanIf EthIIIf", IfCount="2 2 1" will create two IPv4If, two VlanIf and one EthIIIf object.

result = stc.perform("DeviceCreate",
                     ParentList=project,
# Note that a viable Tcl environment must be available for the library to run
# and that the Python Tkinter package must be installed.
# The version of the TestCenter library that will be loaded will be determined
# by normal Tcl package management. The easiest way to change versions will be
# to set the TCLLIBPATH environment variable to point to the desired version
# just like would be done in a normal Tcl installation.
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
szChassisIp = "192.168.22.253"
iTxSlot = 2
iTxPort = 1
iRxSlot = 2
iRxPort = 2

# Create the root project object
print "Creating project ..."
hProject = stc.create("project")

# Create ports
print "Creating ports ..."
hPortTx = stc.create("port", under=hProject, location="//%s/%s/%s" % (szChassisIp, iTxSlot, iTxPort), useDefaultHost="False")
def main():
    parser = argparse.ArgumentParser()
    # Required parameters
    requirednamed = parser.add_argument_group("required named arguments")
    requirednamed.add_argument("--lab_server_addr",
                               required=True,
                               help="The IP address of the Spirent Lab Server",
                               dest="lab_server_addr")
    requirednamed.add_argument("--license_server_addr",
                               required=True,
                               help="The IP address of the Spirent License Server",
                               dest="license_server_addr")
    requirednamed.add_argument("--east_chassis_addr",
                               required=True,
                               help="The TestCenter chassis IP address to use for the east test port",
                               dest="east_chassis_addr")
    requirednamed.add_argument("--east_slot_num",
                               type=positive_int,
                               required=True,
                               help="The TestCenter slot number to use for the east test port",
                               dest="east_slot_num")
    requirednamed.add_argument("--east_port_num",
                               type=positive_int,
                               required=True,
                               help="The TestCenter port number to use for the east test port",
                               dest="east_port_num")
    requirednamed.add_argument("--west_chassis_addr",
                               required=True,
                               help="The TestCenter chassis IP address to use for the west test port",
                               dest="west_chassis_addr")
    requirednamed.add_argument("--west_slot_num",
                               type=positive_int,
                               required=True,
                               help="The TestCenter slot number to use for the west test port",
                               dest="west_slot_num")
    requirednamed.add_argument("--west_port_num",
                               type=positive_int,
                               required=True,
                               help="The TestCenter port number to use for the west test port",
                               dest="west_port_num")
    # Optional parameters
    optionalnamed = parser.add_argument_group("optional named arguments")
    optionalnamed.add_argument("--test_session_name",
                               required=False,
                               default="RFC2544 East-West Throughput",
                               help="The friendly name to identify the Spirent Lab Server test session",
                               dest="test_session_name")
    optionalnamed.add_argument("--results_dir",
                               required=False,
                               default="./Results",
                               help="The directory to copy results to",
                               dest="results_dir")
    optionalnamed.add_argument("--csv_results_file_prefix",
                               required=False,
                               default="Rfc2544Tput",
                               help="The prefix for the CSV results files",
                               dest="csv_results_file_prefix")
    optionalnamed.add_argument("--num_trials",
                               type=positive_int,
                               required=False,
                               default=1,
                               help="The number of trials to execute during the test",
                               dest="num_trials")
    optionalnamed.add_argument("--trial_duration_sec",
                               type=positive_int,
                               required=False,
                               default=60,
                               help="The duration of each trial executed during the test",
                               dest="trial_duration_sec")
    optionalnamed.add_argument("--traffic_pattern",
                               required=False,
                               choices=["BACKBONE", "MESH", "PAIR"],
                               default="PAIR",
                               help="The traffic pattern between endpoints",
                               dest="traffic_pattern")
    optionalnamed.add_argument("--search_mode",
                               required=False,
                               choices=["COMBO", "STEP", "BINARY"],
                               default="BINARY",
                               help="The search mode used to find the throughput rate",
                               dest="search_mode")
    optionalnamed.add_argument("--learning_mode",
                               required=False,
                               choices=["AUTO", "L2_LEARNING", "L3_LEARNING", "NONE"],
                               default="AUTO",
                               help="The learning mode used during the test, default = 'NONE'",
                               dest="learning_mode")
    optionalnamed.add_argument("--rate_lower_limit_pct",
                               type=percent_float,
                               required=False,
                               default=1.0,
                               help="The minimum percent line rate that will be used during the test",
                               dest="rate_lower_limit_pct")
    optionalnamed.add_argument("--rate_upper_limit_pct",
                               type=percent_float,
                               required=False,
                               default=99.0,
                               help="The maximum percent line rate that will be used during the test",
                               dest="rate_upper_limit_pct")
    optionalnamed.add_argument("--rate_initial_pct",
                               type=percent_float,
                               required=False,
                               default=99.0,
                               help="If Search Mode is BINARY, the percent line rate that will be used at the start of the test",
                               dest="rate_initial_pct")
    optionalnamed.add_argument("--rate_step_pct",
                               type=percent_float,
                               required=False,
                               default=10.0,
                               help="If SearchMode is STEP, the percent load increase per step",
                               dest="rate_step_pct")
    optionalnamed.add_argument("--resolution_pct",
                               type=percent_float,
                               required=False,
                               default=1.0,
                               help="The minimum percentage of load adjustment between iterations",
                               dest="resolution_pct")
    optionalnamed.add_argument("--frame_size_list",
                               type=lambda s: [int(item) for item in s.split(',')],
                               required=False,
                               default=[64, 128, 256],
                               help="A comma-delimited list of frame sizes",
                               dest="frame_size_list")
    optionalnamed.add_argument("--acceptable_frame_loss_pct",
                               type=percent_float,
                               required=False,
                               default=0.0,
                               help="The maximum acceptable frame loss percent in any iteration",
                               dest="acceptable_frame_loss_pct")
    optionalnamed.add_argument("--east_intf_addr",
                               required=False,
                               default="192.85.1.3",
                               help="The address to assign to the first emulated device interface on the first east port",
                               dest="east_intf_addr")
    optionalnamed.add_argument("--east_intf_gateway_addr",
                               required=False,
                               default="192.85.1.53",
                               help="The gateway address to assign to the first emulated device interface on the first east port",
                               dest="east_intf_gateway_addr")
    optionalnamed.add_argument("--west_intf_addr",
                               required=False,
                               default="192.85.1.53",
                               help="The address to assign to the first emulated device interface on the first west port",
                               dest="west_intf_addr")
    optionalnamed.add_argument("--west_intf_gateway_addr",
                               required=False,
                               default="192.85.1.53",
                               help="The gateway address to assign to the first emulated device interface on the first west port",
                               dest="west_intf_gateway_addr")
    parser.add_argument("-v",
                        "--verbose",
                        required=False,
                        default=False,
                        help="More output during operation when present",
                        action="store_true",
                        dest="verbose")
    args = parser.parse_args()

    if args.verbose:
        print("Make sure results directory exists")
    create_dir(args.results_dir)

    # Load Spirent Test Center library
    from StcPython import StcPython
    stc = StcPython()

    tx_port_loc = "//%s/%s/%s" % (args.east_chassis_addr,
                                  args.east_slot_num,
                                  args.east_port_num)
    rx_port_loc = "//%s/%s/%s" % (args.west_chassis_addr,
                                  args.west_slot_num,
                                  args.west_port_num)

    # This line will write the TestCenter commands to a log file
    stc.config("automationoptions", logto="test-op", loglevel="DEBUG")

    # Retrieve and display the current API version.
    if args.verbose:
        print ("SpirentTestCenter system version: %s" % stc.get("system1", "version"))

    create_session(stc, args.lab_server_addr, args.test_session_name)

    try:
        device_list = []

        if args.verbose:
            print("Bring up license server")
        license_mgr = stc.get("system1", "children-licenseservermanager")
        if args.verbose:
            print("license_mgr = %s" % license_mgr)
        stc.create("LicenseServer", under=license_mgr, server=args.license_server_addr)

        # Create the root project object
        if args.verbose:
            print ("Creating project ...")
        project = stc.get("System1", "children-Project")

        # Create ports
        if args.verbose:
            print ("Creating ports ...")
        east_chassis_port = stc.create("port",
                                       under=project,
                                       location=tx_port_loc,
                                       useDefaultHost="False")
        west_chassis_port = stc.create("port",
                                       under=project,
                                       location=rx_port_loc,
                                       useDefaultHost="False")

        if args.verbose:
            print ("Creating devices...")
        # Create emulated genparam for east port
        east_device_gen_params = stc.create("EmulatedDeviceGenParams",
                                            under=project,
                                            Port=east_chassis_port)
        # Create the DeviceGenEthIIIfParams object
        stc.create("DeviceGenEthIIIfParams",
                   under=east_device_gen_params)
        # Configuring Ipv4 interfaces
        stc.create("DeviceGenIpv4IfParams",
                   under=east_device_gen_params,
                   Addr=args.east_intf_addr,
                   Gateway=args.east_intf_gateway_addr)
        # Create Devices using the Device Wizard
        device_gen_config = stc.perform("DeviceGenConfigExpand",
                                        DeleteExisting="No",
                                        GenParams=east_device_gen_params)
        # Append to the device list
        device_list.append(device_gen_config['ReturnList'])

        # Create emulated genparam for west port
        west_device_gen_params = stc.create("EmulatedDeviceGenParams",
                                            under=project,
                                            Port=west_chassis_port)
        # Create the DeviceGenEthIIIfParams object
        stc.create("DeviceGenEthIIIfParams",
                   under=west_device_gen_params)
        # Configuring Ipv4 interfaces
        stc.create("DeviceGenIpv4IfParams",
                   under=west_device_gen_params,
                   Addr=args.west_intf_addr,
                   Gateway=args.west_intf_gateway_addr)
        # Create Devices using the Device Wizard
        device_gen_config = stc.perform("DeviceGenConfigExpand",
                                        DeleteExisting="No",
                                        GenParams=west_device_gen_params)
        # Append to the device list
        device_list.append(device_gen_config['ReturnList'])

        if args.verbose:
            print(device_list)

        # Create the RFC 2544 throughput test
        if args.verbose:
            print ("Set up the RFC2544 throughput test...")
        stc.perform("Rfc2544SetupThroughputTestCommand",
                    AcceptableFrameLoss=args.acceptable_frame_loss_pct,
                    Duration=args.trial_duration_sec,
                    FrameSizeList=args.frame_size_list,
                    LearningMode=args.learning_mode,
                    NumOfTrials=args.num_trials,
                    RateInitial=args.rate_initial_pct,
                    RateLowerLimit=args.rate_lower_limit_pct,
                    RateStep=args.rate_step_pct,
                    RateUpperLimit=args.rate_upper_limit_pct,
                    Resolution=args.resolution_pct,
                    SearchMode=args.search_mode,
                    TrafficPattern=args.traffic_pattern)

        # Save the configuration
        stc.perform("SaveToTcc", Filename="2544.tcc")

        # Connect to the hardware...
        stc.perform("AttachPorts", portList=stc.get("system1.project", "children-port"), autoConnect="TRUE")

        # Apply configuration.
        if args.verbose:
            print("Apply configuration...")
        stc.apply

        if args.verbose:
            print("Starting the sequencer...")
        stc.perform("SequencerStart")

        # Wait for sequencer to finish
        print("Starting test... Please wait for the test to complete...")
        stc.waitUntilComplete()
        print("The test has completed... Saving results...")

        # Determine what the results database filename is...
        lab_server_resultsdb = stc.get("system1.project.TestResultSetting", "CurrentResultFileName")

        if args.verbose:
            print("The lab server results database is %s" % lab_server_resultsdb)

        stc.perform("CSSynchronizeFiles",
                    DefaultDownloadDir=args.results_dir)

        resultsdb = args.results_dir + lab_server_resultsdb.split("/Results")[1]

        print("The local summary DB file has been saved to %s" % resultsdb)

        # The returns the "RFC2544ThroughputTestResultDetailedSummaryView" table view from the results database.
        # There are other views available.
        resultsdict = stc.perform("QueryResult",
                                  DatabaseConnectionString=resultsdb,
                                  ResultPath="RFC2544ThroughputTestResultDetailedSummaryView")
        if args.verbose:
            print("resultsdict[\"Columns\"]: %s" % resultsdict["Columns"])
            print("resultsdict[\"Output\"]: %s" % resultsdict["Output"])

        if args.verbose:
            print("Result paths: %s" % stc.perform("GetTestResultSettingPaths"))

        # Write results to csv
        if args.verbose:
            print("Writing CSV file to results directory %s" % args.results_dir)
        write_query_results_to_csv(args.results_dir, args.csv_results_file_prefix, resultsdict)

    except Exception, e:
        print("Exception: %s" % str(e))
        # destroy_session(stc, args.lab_server_addr, args.test_session_name)
        raise
Exemplo n.º 16
0
                OwnerId="matt",
                CreateNewTestSession="true")

    # Terminate the Lab Server session when the last client disconnects.
    stc.perform("TerminateBll", TerminateType="ON_LAST_DISCONNECT")

if tcc_configuration:
    print "Loading TCC configuration ", tcc_configuration, ' loading it now'

    stc.perform("LoadFromDatabaseCommand",
                DatabaseConnectionString=tcc_configuration)

    # Re-enable logging.
    stc.config("AutomationOptions", logTo="stcapi.log", logLevel="INFO")

    project = stc.get("system1", "children-project")

    print "Project = ", project

    # This is an example of DDN notation.
    ports = stc.get("system1.project", "children-port").split(" ")

    #if stc.get("system1.project", "children-port") != "":
    #    stc.config("system1.project.port(3)", name="blaw")

    port_traffic1 = ports[0]
    port_traffic2 = ports[1]

    # Find the Emulated Devices with the names "Traffic1" and "Traffic2".
    result = stc.perform("GetObjects",
                         ClassName="EmulatedDevice",
Exemplo n.º 17
0
# You first need to either set the environment variable "STC_PRIVATE_INSTALL_DIR",
# or change the StcPython.py file ("STC_PRIVATE_INSTALL_DIR") to point to your
# installation.
# eg: os.environ['STC_PRIVATE_INSTALL_DIR'] = '/home/mjefferson/spirent/stc/stc4.59/'

print "Loading the Spirent TestCenter API..."
sys.path.append('/home/mjefferson/spirent/stc/stc4.59/API/Python')
from StcPython import StcPython
stc = StcPython()

# Instruct the API to not display all log entries to STDOUT.
stc.config("AutomationOptions", logTo="stcapi.log", logLevel="INFO")

# Create the configuration from scratch.
print "Creating the configuration from scratch..."
project = stc.get("system1", "children-project")

# Start by creating two ports. port1 is the Tx port, and port2 is the Rx.
port1 = stc.create("port", under=project, location="10.140.99.120/1/1")

###############################################################################
####
####    Method 1 : DeviceCreateCommand
####
###############################################################################

# This is generally the easiest method. Simply execute a single command to
# generate the device. There are many options available for the command that
# allow you to customize what gets created.

# Create three Emulated Devices (CreateCount=3), with each device having 8 unique
Exemplo n.º 18
0
# Point to the StcPython.py file in your Spirent TestCenter installation.
# You first need to either set the environment variable "STC_PRIVATE_INSTALL_DIR",
# or change the StcPython.py file ("STC_PRIVATE_INSTALL_DIR") to point to your
# installation.
# eg: os.environ['STC_PRIVATE_INSTALL_DIR'] = '/home/mjefferson/spirent/stc/stc4.59/'

print "Loading the Spirent TestCenter API..."
sys.path.append('/home/mjefferson/spirent/stc/stc4.62/API/Python')
from StcPython import StcPython
stc = StcPython()

# Instruct the API to not display all log entries to STDOUT.
stc.config("AutomationOptions", logTo="stcapi.log", logLevel="INFO")

# The project object always exists (no need to create it).
project = stc.get("system1", "children-project")

# Create a single port that we want to enable routing emulation on.
port1 = stc.create("port", under=project, location="10.140.99.120/1/1")

# Create an emulated device associated with the port.
result = stc.perform("DeviceCreate", ParentList=project, DeviceType="Router", IfStack="Ipv4If EthIIIf", IfCount="1 1", Port=port1)
emulateddevice = result["ReturnList"]


###############################################################################
####
####    OSPF
####
###############################################################################
# Enable OSPF on the emulated device and create a 2x3 Router LSA topology.