Exemplo n.º 1
0
# Save the configuration as an XML file. Can be imported into the GUI.
print "\nSave configuration as an XML file."
stc.perform("SaveAsXml")

# Start the analyzer and generator.
print "Start Analyzer"
stc.perform("AnalyzerStart", AnalyzerList=hAnalyzer)
print "Current analyzer state ", stc.get(hAnalyzer, "state")

print "Start Generator"
stc.perform("GeneratorStart", GeneratorList=hGenerator)
print "Current generator state",  stc.get(hGenerator, "state")

print "Wait 2 seconds ..."
stc.sleep(2)

print "Wait until generator stops ..."
stc.waitUntilComplete(timeout=100)

print "Current analyzer state ", stc.get(hAnalyzer, "state")
print "Current generator state ", stc.get(hGenerator, "state")
print "Stop Analyzer"

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

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

# Display some statistics.
Exemplo n.º 2
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.º 3
0
stc.perform('AttachPorts', portList=[port1], autoConnect='TRUE')
stc.apply()

print 'Call Subscribe...'

port1GeneratorResult = stc.subscribe(
    Parent=project,
    ResultParent=port1,
    ConfigType='Generator',
    resulttype='GeneratorPortResults',
    filenameprefix="Generator_port1_counter_%s" % port1,
    Interval=2)

print 'Starting Traffic...'
# wait for analyzer to start
stc.sleep(10)
stc.perform('GeneratorStart', generatorList=generator)
print "start", generator
# generate traffic for  5 seconds
print 'Sleep 5 seconds...'
stc.sleep(5)
print 'Stopping Traffic...'

stc.perform('GeneratorStop', generatorList=generator)

print 'stop', generator

print 'Call Unsubscribe...'

stc.unsubscribe(port1GeneratorResult)
# Save the configuration as an XML file. Can be imported into the GUI.
print "\nSave configuration as an XML file."
stc.perform("SaveAsXml")

# Start the analyzer and generator.
print "Start Analyzer"
stc.perform("AnalyzerStart", AnalyzerList=hAnalyzer)
print "Current analyzer state ", stc.get(hAnalyzer, "state")

print "Start Generator"
stc.perform("GeneratorStart", GeneratorList=hGenerator)
print "Current generator state",  stc.get(hGenerator, "state")

print "Wait 2 seconds ..."
stc.sleep(2)

print "Wait until generator stops ..."
stc.waitUntilComplete(timeout=100)

print "Current analyzer state ", stc.get(hAnalyzer, "state")
print "Current generator state ", stc.get(hGenerator, "state")
print "Stop Analyzer"

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

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

# Display some statistics.