rv = stc.perform('attachPorts', RevokeOwner='FALSE') if not rv: print("Error: Failed to reserve ports - exiting..\n") exit(1) # Apply configuration (verify and upload to chassis) stc.apply() # Subscribe to test results. Configured attributes will be saved to .csv results file every 1 second of # the test. Possible fields in viewAttributeList are listed in API docs: 'RxStreamSummaryResults.htm'. # Results may be viewed in .csv file or you may browse the SQL .db file directly. # Best way to view them is via Results API object. rx_dataset = stc.subscribe(parent=hProject, resultParent=hProject, configType='StreamBlock', resultType='RxStreamSummaryResults', viewAttributeList='framerate', interval='1', filenamePrefix='RxStreamSummaryResults') # Subscribe to generator and analyzer results generator_dataset = stc.subscribe( parent=hProject, resultParent=hProject, configType='generator', resultType='generatorportresults', filterList='', viewAttributeList= 'totalframecount generatorframecount totalframerate generatorframerate totalbitrate generatorbitrate', interval='1', filenamePrefix='generatorportresults')
DurationMode="BURSTS", \ BurstSize=1, \ Duration=100, \ LoadMode="FIXED", \ FixedLoad=100, \ LoadUnit="PERCENT_LINE_RATE", \ SchedulingMode="PORT_BASED") # Analyzer Configuration. print "Configuring Analyzer" hAnalyzerConfig = stc.get(hAnalyzer, "children-AnalyzerConfig") # Subscribe to realtime results. print "Subscribe to results" hAnaResults = stc.subscribe(Parent=hProject, \ ConfigType="Analyzer", \ resulttype="AnalyzerPortResults", \ filenameprefix="Analyzer_Port_Results") hGenResults = stc.subscribe(Parent=hProject, \ ConfigType="Generator", \ resulttype="GeneratorPortResults", \ filenameprefix="Generator_Port_Counter", \ Interval=2) # Configure Capture. if ENABLE_CAPTURE: print "\nStarting Capture..." # Create a capture object. Automatically created. hCapture = stc.get(hPortRx, "children-capture") stc.config(hCapture, mode="REGULAR_MODE", srcMode="TX_RX_MODE")
# Create a raw streamblock. Headers include: EthernetII, Vlan, IPv4, IPv6, Mpls, Tcp, UDP, PPP, GRE, etc. streamblock = stc.create("StreamBlock", under=port, FrameConfig="EthernetII IPv4") # This get is required to update the API. stc.get(streamblock) stc.config(streamblock + ".ethernet:EthernetII", SrcMac="00:00:00:00:00:01") stc.config(streamblock + ".ipv4:IPv4", SourceAddr="1.1.1.2", DestAddr="2.1.1.2") print("Subscribing to 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") #stc.subscribe(Parent=project, ConfigType="Analyzer", resulttype="AnalyzerPortResults") # Stream Results. streamrds = stc.subscribe(Parent=project, ConfigType="StreamBlock", resulttype="TxStreamResults", RecordsPerPage=256) stc.create("ResultQuery", under=streamrds,
# Add a bound streamblock from port_traffic1 to port_traffic2. Notice how we are "binding" the # streamblock to the Emulated Device's IPv4 interface objects. # If we were in an L2 environment, you would bind to the ethernet interface objects instead. streamblock1 = stc.create("StreamBlock", under=port_traffic1, srcbinding=stc.get(ed_traffic1, "children-ipv4if"), dstbinding=stc.get(ed_traffic2, "children-ipv4if")) pdb.set_trace() print "Subscribing to results..." # Results are also stored in objects. Where these objects are located varies for each result type. # Port results. These result objects are stored under the generator and analyzer objects. stc.subscribe(Parent=project, ConfigType="Generator", resulttype="GeneratorPortResults") stc.subscribe(Parent=project, ConfigType="Analyzer", resulttype="AnalyzerPortResults") # Stream Results. These result objects are stored under the StreamBlock objects. rds = stc.subscribe(Parent=project, ConfigType="StreamBlock", resulttype="TxStreamResults") stc.create("ResultQuery", under=rds, ResultRootList=project, ConfigClassId="StreamBlock", ResultClassId="RxStreamSummaryResults")
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') 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)
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] }