def __init__(self):
     self.logger = logging.getLogger("Monitor.TestScenario")
     self.logger.setLevel(logging.DEBUG)
     self.switch3500 = SwitchMonitor("00:0a:74:46:a0:5f:1e:80")
     self.controller = HPSDNController("10.1.3.16")
     self.Iperf = BandwidthMeter("10.1.3.17", "marian", "descartes",
                                "10.1.3.11", "marian", "descartes",
                                'iperf -c 10.100.3.17 -i 1 -y C', 'iperf -s')
     self.Iperf.setTestDuraton(10000)
     self.Ping = DelayMonitor("10.1.3.11", "marian", "descartes", "10.100.3.17", 1000)
     self.Ping.setPingCount(10000)
 def __init__(self):
     self.logger = logging.getLogger("Monitor.TestScenario")
     self.logger.setLevel(logging.DEBUG)
     self.controller = HPSDNController("10.1.3.16")
     self.Iperf = BandwidthMeter("10.1.3.17", "marian", "descartes",
                                "10.1.3.11", "marian", "descartes",
                                'iperf -c 10.100.3.17 -i 1 -y C', 'iperf -s')
     self.Iperf.setTestDuraton(10000)
     self.Ping = DelayMonitor("10.1.3.11", "marian", "descartes", "10.100.3.17", 1000)
     self.Ping.setPingCount(10000)
class TestingScenario3500:
    def __init__(self):
        self.logger = logging.getLogger("Monitor.TestScenario")
        self.logger.setLevel(logging.DEBUG)
        self.switch3500 = SwitchMonitor("00:0a:74:46:a0:5f:1e:80")
        self.controller = HPSDNController("10.1.3.16")
        self.Iperf = BandwidthMeter("10.1.3.17", "marian", "descartes",
                                   "10.1.3.11", "marian", "descartes",
                                   'iperf -c 10.100.3.17 -i 1 -y C', 'iperf -s')
        self.Iperf.setTestDuraton(10000)
        self.Ping = DelayMonitor("10.1.3.11", "marian", "descartes", "10.100.3.17", 1000)
        self.Ping.setPingCount(10000)

    def start(self):
        #print "=================== Test 1:Measuring Standart Pipeline Processing Performance =========================="
        #self.switch3500.cli.disableOpenflowInstance()
        #self.hardwareProcessingPerformance(duration=90)
        #print "==============================================================================================="
        #self.switch3500.cli.setOpenFlowVersion(10)
        # self.switch3500.cli.setPolicyEngineUsageLimit(100)
        # print "=================== Test 1:Measuring Hardware Processing Performance =========================="
        # self.switch3500.cli.resetOpenflowInstance()
        # self.installPingRules(table_id=0)
        # self.hardwareProcessingPerformance(duration=90)
        # print "==============================================================================================="
        # print "=================== Test 2:Measuring Rules Insertion Performance =============================="
        # flow = SwitchParameters.switch2920_rule_10
        # self.measureRuleInsertionPerformance(flow=flow,table_id=0,max_rule_count=500)
        # print "==============================================================================================="
        # print "=================== Test 3:Measuring Max Rule Count ==========================================="
        # self.measureTableSizeForDifferentRules(flow_set=SwitchParameters.switch_compatible_rules["3500_OF10"],table_id=0)
        # print "==============================================================================================="
        # print "=================== Test 4:Flow Pull Performance =============================="
        # flow = SwitchParameters.switch2920_rule_10
        # self.measureGetFlowsImpact(flow=flow,table_id=0,max_table_size=100)
        # print "==============================================================================================="
        # print "=================== Test 5:OpenFlow Policy Engine dependency =============================="
        # self.measureOpenflowPolicyEngineDependency(table_id=0)
        # print "==============================================================================================="
        print "=================== Test 1:Measuring Software Processing Performance =========================="
        self.switch3500.cli.setPolicyEngineUsageLimit(10)
        self.switch3500.cli.setSoftwareFlowTableRateLimit(10000)
        self.fillHWTableWithDummyRules(dummy_rule=SwitchParameters.switch3500_rule_9_OF10,table_size=160,table_id=0)
        self.softwareProcessingPerformance(duration=90)
        print "==============================================================================================="
        # self.switch3500.cli.setSoftwareFlowTableRateLimit(10000)
        # print "=================== Test 2:Measuring Rules Insertion Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.measureRuleInsertionPerformance(flow,200,1526)
        # print "==============================================================================================="
        # print "=================== Test 3:Flow Pull Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.switch3500.cli.setSoftwareFlowTableRateLimit(10000)
        # self.measureGetFlowsImpact(flow,200,1526)
        # print "==============================================================================================="
        # print "=================== Test 4:PPS change =============================="
        # self.switch3500.cli.setPolicyEngineUsageLimit(100)
        # self.softwarePPSChange()
        # print "==============================================================================================="
        #print "========================================= Test Rule replacement Engine ==========================="
        #self.switch3500.cli.setPolicyEngineUsageLimit(20)
        #self.switch3500.cli.setSoftwareFlowTableRateLimit(10000)
        #self.fillHWTableWithDummyRules(dummy_rule=SwitchParameters.switch3500_rule_9_OF10,table_size=305,table_id=0)
        # print "==============================================================================================="
        #flow = SwitchParameters.switch3500_rule_ShortDummy_1_OF10


    def iperfComparisonForVariablePacketSize(self,pipeline_type="standard",duration=10):
        self.Iperf = BandwidthMeter("10.1.3.17", "marian", "descartes",
                                   "10.1.3.11", "marian", "descartes",'iperf -c 10.100.3.17 -i 1 -y C','iperf -s')
        self.Iperf.setTestDuraton(10000)
        self.switch3500.cli.setSoftwareFlowTableRateLimit(10000)
        print "Pipeline type: ",pipeline_type
        print "MTUSize\tThroughput\tDelay\n"
        for packet_size in range(20,120,10):
            command = 'iperf -c 10.100.3.17 -i 1 -y C -N -M '+str(packet_size)
            self.Iperf.setClientCommand(command)
            if pipeline_type=="standard":
                self.hardwareProcessingPerformance(duration=duration)
            if pipeline_type=="openflow":
                self.hardwareProcessingPerformance(duration=duration)
            if pipeline_type=="software":
                cpus,flows = self.softwareProcessingPerformance(duration=duration)
            throughputs,delays = self.processIperfAndPingOutput()
            print packet_size,"\t",self.calculateAvarage(throughputs),"\t",self.calculateAvarage(delays)
    def testPipelinePerformance(self):
        self.switch3500.cli.disableOpenflowInstance()
        self.iperfComparisonForVariablePacketSize(pipeline_type="standard")
        self.switch3500.cli.resetOpenflowInstance()
        self.iperfComparisonForVariablePacketSize(pipeline_type="openflow")
        self.switch3500.cli.resetOpenflowInstance()
        self.switch3500.cli.setPolicyEngineUsageLimit(5)
        self.fillHWTableWithDummyRules(dummy_rule=SwitchParameters.switch3500_rule_9_OF10,table_id=0,table_size=80)
        self.installSFPingRules(table_id=0,priority=30000)
        self.iperfComparisonForVariablePacketSize(pipeline_type="software")

    def testRuleReplacementEngine(self):
        self.switch3500.cli.setPolicyEngineUsageLimit(5)
        self.switch3500.cli.setSoftwareFlowTableRateLimit(10000)
        # Dummy rule matches only ipv4-src, priority 100
        # Ping rules matches in_port, ipv4_src and ipv4_dst, priority 2
        print "===================== Ping rules is the MOST EXACT and has LOWEST PRIORITY============="
        flow = SwitchParameters.switch3500_rule_ShortDummy_1_OF10
        flow["flow"]["idle_timeout"]=120
        flow["flow"]["priority"]=100
        self.switch3500.cli.resetOpenflowInstance()
        self.fillHWTableWithDummyRules(dummy_rule=flow,table_size=160,table_id=0)
        self.installSFPingRules(table_id=0,priority=2)
        self.softwareProcessingPerformance(duration=90)
        # Dummy rule machtes all fields, priority 100
        # Ping rules matches in_port, ipv4_src and ipv4_dst, priority 2
        print "===================== Ping rules is the LESS EXACT and has LOWEST PRIORITY============="
        flow = SwitchParameters.switch3500_rule_9_OF10
        flow["flow"]["idle_timeout"]=120
        flow["flow"]["priority"]=100
        self.switch3500.cli.resetOpenflowInstance()
        self.fillHWTableWithDummyRules(dummy_rule=flow,table_size=160,table_id=0)
        self.installSFPingRules(table_id=0, priority=2)
        self.softwareProcessingPerformance(duration=90)
        # Dummy rule machtes all fields, priority 100
        # Ping rules matches in_port, ipv4_src and ipv4_dst, priority 30000
        print "===================== Ping rules is the LESS EXACT and has HIGHEST PRIORITY============="
        flow = SwitchParameters.switch3500_rule_9_OF10
        flow["flow"]["idle_timeout"]=120
        flow["flow"]["priority"]=100
        self.switch3500.cli.resetOpenflowInstance()
        self.fillHWTableWithDummyRules(dummy_rule=flow,table_size=160,table_id=0)
        self.installSFPingRules(table_id=0, priority=30000)
        self.softwareProcessingPerformance(duration=90)
        # Dummy rule matches only ipv4-src, priority 100
        # Ping rules matches in_port, ipv4_src and ipv4_dst, priority 30000
        print "===================== Ping rules is the MOST EXACT and has HIGHEST PRIORITY============="
        flow = SwitchParameters.switch3500_rule_ShortDummy_1_OF10
        flow["flow"]["idle_timeout"]=120
        flow["flow"]["priority"]=100
        self.switch3500.cli.resetOpenflowInstance()
        self.fillHWTableWithDummyRules(dummy_rule=flow,table_size=160,table_id=0)
        self.installSFPingRules(table_id=0, priority=30000)
        self.softwareProcessingPerformance(duration=90)


    def processIperfAndPingOutput(self):
        while self.Iperf.finished==False:
            time.sleep(1)
        while self.Ping.finished==False:
            time.sleep(1)
        throughput_values = self.Iperf.values
        delay_values = self.Ping.values
        if len(throughput_values)<len(delay_values):
            l = len(throughput_values)
        else:
            l = len(delay_values)
        throughput_values = throughput_values[0:l]
        delay_values = delay_values[0:l]
        #avarage_throughput = self.calculateAvarage(throughput_values)
        #avarage_delay = self.calculateAvarage(delay_values)
        #print "Avarage Bandwidth: ",avarage_throughput
        #print "Avarage Delay: ",avarage_delay
        return throughput_values,delay_values

    def calculateAvarage(self,array):
        if len(array)==0:
            return 0
        sum = float(0)
        for i in array:
            sum+=int(i)
        return float(sum/len(array))


    def installPingRules(self, table_id=0, priority=0):
        flow1 = SwitchParameters.testbed_ping_rule_1_OF10
        flow2 = SwitchParameters.testbed_ping_rule_2_OF10
        flow1["flow"]["table_id"]=table_id
        flow2["flow"]["table_id"]=table_id
        flow1["flow"]["priority"]=priority
        flow2["flow"]["priority"]=priority
        self.controller.addFlow(self.switch3500.getDPID(),flow1)
        self.controller.addFlow(self.switch3500.getDPID(),flow2)


#=========================================  Hardware Processing Perfoemance performance =========================
    def hardwareProcessingPerformance(self,duration):
        p1 = self.Iperf.startCapturingThroughput()
        p2 = self.Ping.startCapturingDelay()
        time.sleep(duration)
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(5)
        #print self.processIperfAndPingOutput()


#=========================================  Software Processing Perfoemance performance =========================

    def installSFPingRules(self,table_id=0, priority=0):
        flow1 = SwitchParameters.testbed_ping_rule_1_OF10
        flow2 = SwitchParameters.testbed_ping_rule_2_OF10
        flow1["flow"]["table_id"]=table_id
        flow2["flow"]["table_id"]=table_id
        self.controller.addFlow(self.switch3500.getDPID(),flow1)
        self.controller.addFlow(self.switch3500.getDPID(),flow2)


    def softwareProcessingPerformance(self,duration=90):
        cpus = {}
        flows = {}  #Only For Test placement rule
        p1 = self.Iperf.startCapturingThroughput()
        p2 = self.Ping.startCapturingDelay()
        for i in range(0,duration,1):
            time.sleep(1)
            cpus[i]=(self.switch3500.getCurrentCPU())
            flows[i] = (self.switch3500.cli.getFlowsCountOverCLI()) #Only For Test placement rules
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(2)
        #results = self.processIperfAndPingOutput()
        #avarage_cpu = self.calculateAvarage(cpus.values())
        #for key in cpus.keys():
        #    print cpus[key],"\t",flows[key][0],"\t",flows[key][1]
        #print "Avarage CPU: ",avarage_cpu
        return cpus,flows


    def softwarePPSChange(self):
        f = open("3500_SfPpsChangePerformance.txt","w")
        f.write("PPS\tThroughput\tDelay\tCPU\n")
        for i in range(10000,10100,100):
            self.switch3500.cli.setSoftwareFlowTableRateLimit(i)
            self.installSFPingRules(200)
            r = self.softwareProcessingPerformance()
            #print r,"srthsh"
            f.write(str(i)+"\t"+
                    str(r[0])+"\t"+
                    str(r[1])+"\t"+
                    str(r[2])+"\t\n")
        f.close()


#=========================================  Rule insetion performance =========================
    def measureRuleInsertionPerformance(self,flow,table_id,max_rule_count):
        cpus = {}
        flow_insertion_delays = {}
        flow_insertion_moments = {}
        flow = flow
        flow["flow"]["table_id"]=table_id
        self.switch3500.cli.resetOpenflowInstance()
        if table_id is 100:
            self.installPingRules(100)
        if table_id is 200:
            self.installSFPingRules(200)
        self.Iperf.startCapturingThroughput()
        self.Ping.startCapturingDelay()
        rules_count = self.switch3500.getHardwareFlowsCount()
        start_time = datetime.now()
        while rules_count<max_rule_count:
            print "\r Rules = {0}".format(rules_count),
            flow = self.controller.buildDummyFlow(flow)
            flow["flow"]["priority"]=rules_count+1
            a = datetime.now()
            self.controller.addFlow(self.switch3500.getDPID(),flow)
            b = datetime.now()
            c = (b-a).microseconds
            flow_insertion_delays[rules_count]= c
            flow_insertion_moments[rules_count]= c
            if(rules_count%10)==0:
                cpus[rules_count]= self.switch3500.getCurrentCPU()
            else:
                cpus[rules_count]= 0
            rules_count+=1
        print
        end_time = datetime.now()
        duration = end_time - start_time
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(5)
        self.processIperfAndPingOutput()
        print "Experiment duration = "+str(duration)
        f = open("3500_RuleInsertionPerformance_"+str(table_id)+".txt","w")
        f.write("Rule\tMoment\tDelay\tCPU\n")
        for key in flow_insertion_moments.keys():
            f.write(str(key)+"\t"+
                    str(flow_insertion_moments[key])+"\t"+
                    str(flow_insertion_delays[key])+"\t"+
                    str(cpus[key])+"\t\n")
#=========================================  Policy Engine Dependencie =========================

    def measureOpenflowPolicyEngineDependency(self,table_id):
        flow = SwitchParameters.switch2920_rule_10
        flow["flow"]["table_id"]=table_id
        for i in range(0,100,10):
            self.switch3500.cli.setPolicyEngineUsageLimit(i)
            time.sleep(3)
            self.measureMaxRuleCountInHardware(flow)



#=========================================  MAX TABLE SIZES =========================
    def measureTableSizeForDifferentRules(self,flow_set,table_id):
        for flow in flow_set:
            self.switch3500.cli.resetOpenflowInstance()
            time.sleep(3)
            flow["flow"]["table_id"]=table_id
            self.measureMaxRuleCountInHardware(flow)
        print "========================================================="

    def measureMaxRuleCountInHardware(self,flow):
        print "Flow Pattern:", flow
        print "Number of wildcards: ",int(13-len(flow["flow"]["match"]))
        hw_table_size = self.switch3500.getHardwareFlowsCount()
        #while True:
        while hw_table_size<20:
            print "\r Rules = {0}".format(hw_table_size),
            for i in range(0,10,1):
                flow["flow"]["priority"]=hw_table_size+i
                flow = self.controller.buildDummyFlow(flow)
                self.controller.addFlow(self.switch3500.getDPID(),flow)
            current_count = self.switch3500.getHardwareFlowsCount()
            if hw_table_size==current_count:
                break
            hw_table_size = current_count
        print
        print "Rules number limit = ",str(hw_table_size)

#=========================================================================================
    #mac-ip aware enabled
    def measureGetFlowsImpact(self, flow, table_id, max_table_size):
        self.switch3500.cli.resetOpenflowInstance()
        if table_id is 100:
            self.installPingRules(100)
        if table_id is 200:
            self.installSFPingRules(200)
        time.sleep(5)
        self.Iperf.startCapturingThroughput()
        self.Ping.startCapturingDelay()
        t = threading.Thread(target=self.getFlowsInThread)
        t.start()
        flow = flow
        flow["flow"]["table_id"] = table_id
        rules_count = self.switch3500.getHardwareFlowsCount()
        while rules_count<=max_table_size:
            flow = self.controller.buildDummyFlow(flow)
            flow["flow"]["priority"]=rules_count+1
            self.controller.addFlow(self.switch3500.getDPID(),flow)
            rules_count+=1
            print "\rRules=",rules_count,
        time.sleep(10)
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        self.processIperfAndPingOutput()
        time.sleep(5)
        del t

    def getFlowsInThread(self):
        i = 0
        while i<1000:
            i+=1
            self.controller.getTableFlowsCount(self.switch3500.getDPID(),0)
            print "\rI=",i,

    def fillHWTableWithDummyRules(self,dummy_rule,table_size, table_id):
        flow = dummy_rule
        flow["flow"]["table_id"]=table_id
        for i in range(0,table_size,1):
            flow["flow"]["priority"]=100+i+1
            flow = self.controller.buildDummyFlow(flow=flow)
            print "\rInserting rules: ",i,self.switch3500.cli.getFlowsCountOverCLI(),
            self.controller.addFlow(self.switch3500.getDPID(),flow)
            self.switch3500.addFlow(flow=flow)
        print
        print "{0} rules have been inserted in table={1}".format(table_size,table_id)
class TestingScenario3500:
    def __init__(self):
        self.logger = logging.getLogger("Monitor.TestScenario")
        self.logger.setLevel(logging.DEBUG)
        self.switch3500 = SwitchMonitor("00:0a:74:46:a0:5f:1e:80")
        self.controller = HPSDNController("10.1.3.16")
        self.Iperf = BandwidthMeter("10.1.3.17", "marian", "descartes",
                                   "10.1.3.11", "marian", "descartes",
                                   'iperf -c 10.100.3.17 -i 1 -y C', 'iperf -s')
        self.Iperf.setTestDuraton(10000)
        self.Ping = DelayMonitor("10.1.3.11", "marian", "descartes", "10.100.3.17", 1000)
        self.Ping.setPingCount(10000)

    def start(self):
        # self.testActionsPerformace()
        # self.switch3500.cli.setOpenFlowVersion(10)
        # self.switch3500.cli.setPolicyEngineUsageLimit(100)
        # print "=================== Test 1:Measuring Hardware Processing Performance =========================="
        # self.hardwareProcessingPerformance(duration=20)
        # print "==============================================================================================="
        # print "=================== Test 2:Measuring Rules Insertion Performance =============================="
        # self.measureRuleInsertionPerformance(flow=flow,table_id=100,max_rule_count=20)
        # print "==============================================================================================="
        # print "=================== Test 3:Measuring Max Rule Count ==========================================="
        # self.measureTableSizeForDifferentRules()
        # print "==============================================================================================="
        # print "=================== Test 4:Flow Pull Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.measureGetFlowsImpact(flow=flow,table_id=100,max_table_size=20)
        # print "==============================================================================================="
        # print "=================== Test 5:OpenFlow Policy Engine dependency =============================="
        # self.measureOpenflowPolicyEngineDependency(table_id=100)
        # print "==============================================================================================="
        #self.switch3500.cli.setPolicyEngineUsageLimit(100)
        # print "=================== Test 1:Measuring Software Processing Performance =========================="
        # self.switch3500.cli.setSoftwareFlowTableRateLimit(10000)
        # self.installSFPingRules(200)
        # self.softwareProcessingPerformance()
        # print "==============================================================================================="
        # self.switch3500.cli.setSoftwareFlowTableRateLimit(10000)
        # print "=================== Test 2:Measuring Rules Insertion Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.measureRuleInsertionPerformance(flow,200,1526)
        # print "==============================================================================================="
        # print "=================== Test 3:Flow Pull Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.switch3500.cli.setSoftwareFlowTableRateLimit(10000)
        # self.measureGetFlowsImpact(flow,200,1526)
        # print "==============================================================================================="
        print "=================== Test 4:PPS change =============================="
        self.switch3500.cli.setPolicyEngineUsageLimit(100)
        self.softwarePPSChange()
        print "==============================================================================================="
        return

    def testActionsPerformace(self):
        self.switch3500.cli.resetOpenflowInstance()
        for i in range(0,10,1):
            for flow in SwitchParameters.switch3500_rule_action_performace_output_setipsrc:
                flow["flow"]["table_id"]=200
                self.controller.addFlow(self.switch3500.getDPID(),flow)
        self.hardwareProcessingPerformance(30)
        print self.processIperfAndPingOutput()
        return






    def processIperfAndPingOutput(self):
        while self.Iperf.finished==False:
            time.sleep(1)
        while self.Ping.finished==False:
            time.sleep(1)
        ia = self.Iperf.values
        pa = self.Ping.values
        if len(pa)<len(ia):
            l = len(pa)
        else:
            l = len(ia)
        ias = 0
        pas = 0
        for i in range(0,l,1):
            ias+=ia[i]
            pas+=pa[i]
            print ia[i],"\t",pa[i]
        aia = ias/l
        apa = pas/l
        print "Avarage Bandwidth: ",aia
        print "Avarage Delay: ",apa
        return [aia,apa]





    def installPingRules(self,table_id):
        flow1 = SwitchParameters.testbed_ping_rule_1
        flow2 = SwitchParameters.testbed_ping_rule_2
        flow1["flow"]["table_id"]=table_id
        flow2["flow"]["table_id"]=table_id
        self.controller.addFlow(self.switch3500.getDPID(),flow1)
        time.sleep(1)
        self.controller.addFlow(self.switch3500.getDPID(),flow2)
        time.sleep(1)


#=========================================  Hardware Processing Perfoemance performance =========================
    def hardwareProcessingPerformance(self,duration):
        #self.switch3500.cli.resetOpenflowInstance()
        #self.installPingRules(100)
        p1 = self.Iperf.startCapturingThroughput()
        p2 = self.Ping.startCapturingDelay()
        time.sleep(duration)
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(5)
        self.processIperfAndPingOutput()

#=========================================  Software Processing Perfoemance performance =========================

    def installSFPingRules(self,table_id):
        flow1 = SwitchParameters.switch3500_ping_rule_1
        flow2 = SwitchParameters.switch3500_ping_rule_2
        flow1["flow"]["table_id"]=table_id
        flow2["flow"]["table_id"]=table_id
        while(self.switch3500.getSoftwareFlowsCount()<3):
            self.controller.addFlow(self.switch3500.getDPID(),flow1)
            self.controller.addFlow(self.switch3500.getDPID(),flow2)


    def softwareProcessingPerformance(self):
        cpus = []
        p1 = self.Iperf.startCapturingThroughput()
        p2 = self.Ping.startCapturingDelay()
        for i in range(0,10,1):
            time.sleep(1)
            cpus.append(self.switch3500.getCurrentCPU())
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(2)
        results = self.processIperfAndPingOutput()
        sum = 0
        for i in cpus:
            sum+=int(i)
        print "Avarage CPU: ",str()
        results.append(float(sum/len(cpus)))
        return results


    def softwarePPSChange(self):
        f = open("3500_SfPpsChangePerformance.txt","w")
        f.write("PPS\tThroughput\tDelay\tCPU\n")
        for i in range(10000,10100,100):
            self.switch3500.cli.setSoftwareFlowTableRateLimit(i)
            self.installSFPingRules(200)
            r = self.softwareProcessingPerformance()
            #print r,"srthsh"
            f.write(str(i)+"\t"+
                    str(r[0])+"\t"+
                    str(r[1])+"\t"+
                    str(r[2])+"\t\n")
        f.close()






#=========================================  Rule insetion performance =========================
    def measureRuleInsertionPerformance(self,flow,table_id,max_rule_count):
        cpus = {}
        flow_insertion_delays = {}
        flow_insertion_moments = {}
        flow = flow
        flow["flow"]["table_id"]=table_id
        self.switch3500.cli.resetOpenflowInstance()
        if table_id is 100:
            self.installPingRules(100)
        if table_id is 200:
            self.installSFPingRules(200)
        self.Iperf.startCapturingThroughput()
        self.Ping.startCapturingDelay()
        rules_count = self.switch3500.getHardwareFlowsCount()
        start_time = datetime.now()
        while rules_count<max_rule_count:
            print "\r Rules = {0}".format(rules_count),
            flow = self.controller.buildDummyFlow(flow)
            flow["flow"]["priority"]=rules_count+1
            a = datetime.now()
            self.controller.addFlow(self.switch3500.getDPID(),flow)
            b = datetime.now()
            c = (b-a).microseconds
            flow_insertion_delays[rules_count]= c
            flow_insertion_moments[rules_count]= c
            if(rules_count%10)==0:
                cpus[rules_count]= self.switch3500.getCurrentCPU()
            else:
                cpus[rules_count]= 0
            rules_count+=1
        print
        end_time = datetime.now()
        duration = end_time - start_time
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(5)
        self.processIperfAndPingOutput()
        print "Experiment duration = "+str(duration)
        f = open("3500_RuleInsertionPerformance_"+str(table_id)+".txt","w")
        f.write("Rule\tMoment\tDelay\tCPU\n")
        for key in flow_insertion_moments.keys():
            f.write(str(key)+"\t"+
                    str(flow_insertion_moments[key])+"\t"+
                    str(flow_insertion_delays[key])+"\t"+
                    str(cpus[key])+"\t\n")
#=========================================  Policy Engine Dependencie =========================


    def measureOpenflowPolicyEngineDependency(self,table_id):
        flow = SwitchParameters.switch3500_rule_9_OF13
        flow["flow"]["table_id"]=table_id
        for i in range(0,100,10):
            self.switch3500.cli.setPolicyEngineUsageLimit(i)
            time.sleep(3)
            self.measureMaxRuleCountInHardware(flow)



#=========================================  MAX TABLE SIZES =========================
    def measureTableSizeForDifferentRules(self):
        table_id = 100
        for flow in SwitchParameters.switch_compatible_rules["3500_OF13"]:
            self.switch3500.cli.resetOpenflowInstance()
            time.sleep(3)
            flow["flow"]["table_id"]=table_id
            self.measureMaxRuleCountInHardware(flow)
        print "========================================================="

    def measureMaxRuleCountInHardware(self,flow):
        print "Flow Pattern:", flow
        print "Number of wildcards: ",int(13-len(flow["flow"]["match"]))
        hw_table_size = self.switch3500.getHardwareFlowsCount()
        #while True:
        while hw_table_size<20:
            print "\r Rules = {0}".format(hw_table_size),
            for i in range(0,10,1):
                flow["flow"]["priority"]=hw_table_size+i
                flow = self.controller.buildDummyFlow(flow)
                self.controller.addFlow(self.switch3500.getDPID(),flow)
            current_count = self.switch3500.getHardwareFlowsCount()
            if hw_table_size==current_count:
                break
            hw_table_size = current_count
        print
        print "Rules number limit = ",str(hw_table_size)

#=========================================================================================
    #mac-ip aware enabled
    def measureGetFlowsImpact(self, flow, table_id, max_table_size):
        self.switch3500.cli.resetOpenflowInstance()
        if table_id is 100:
            self.installPingRules(100)
        if table_id is 200:
            self.installSFPingRules(200)
        time.sleep(5)
        self.Iperf.startCapturingThroughput()
        self.Ping.startCapturingDelay()
        t = threading.Thread(target=self.getFlowsInThread)
        t.start()
        flow = flow
        flow["flow"]["table_id"] = table_id
        rules_count = self.switch3500.getHardwareFlowsCount()
        while rules_count<=max_table_size:
            flow = self.controller.buildDummyFlow(flow)
            flow["flow"]["priority"]=rules_count+1
            self.controller.addFlow(self.switch3500.getDPID(),flow)
            rules_count+=1
            print "\rRules=",rules_count,
        time.sleep(10)
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        self.processIperfAndPingOutput()
        time.sleep(5)
        del t

    def getFlowsInThread(self):
        i = 0
        while True:
            i+=1
            self.controller.getTableFlowsCount(self.switch3500.getDPID(),100)
            print "\rI=",i,



    def fillHWTableWithDummyRules(self):
        flow = SwitchParameters.switch3500_rule_9_OF13
        flow["flow"]["table_id"]=100
        for i in range(0,1527,1):
            flow["flow"]["priority"]=i+1
            print "\r",i,
            self.controller.addFlow(self.switch3500.getDPID(),flow)
        print "HW is full!"
 def __init__(self):
     self.logger = logging.getLogger("Monitor.TestScenario")
     self.logger.setLevel(logging.DEBUG)
     self.switch5700 = SwitchMonitor("00:00:00:00:00:00:00:16")
     self.switch5130 = SwitchMonitor("00:00:00:00:00:00:00:16")
     self.controller = HPSDNController("10.1.3.16")
class TestingScenario5700:
    def __init__(self):
        self.logger = logging.getLogger("Monitor.TestScenario")
        self.logger.setLevel(logging.DEBUG)
        self.switch5700 = SwitchMonitor("00:00:00:00:00:00:00:16")
        self.switch5130 = SwitchMonitor("00:00:00:00:00:00:00:16")
        self.controller = HPSDNController("10.1.3.16")

    def start(self):
        #self.measureExtensibilityTable()
        self.measureMacIPTable5700()

#=========================================  MAX TABLE SIZES 5700 =========================

    def measureExtensibilityTable5700(self):
        print "=================== Test 3:Measuring Max Rule Count for EXTENSIBILITY Table====================="
        table_id = 20
        self.switch5700.cli.enableExtensibilityTable()
        rules = SwitchParameters.switch_compatible_rules["5700_NORMAL"]
        for i in range(0, len(rules) - 1, 1):
            self.switch5700.cli.resetOpenflowInstance()
            self.measureMaxRuleCountInHardware(self.switch5700, rules[i],
                                               table_id)
        print "========================================================="

    def measureMacIPTable5700(self):
        print "=================== Test 3:Measuring Max Rule Count for EXTENSIBILITY Table====================="
        table_id = 10
        self.switch5700.cli.enableMacIPTable()
        rule = SwitchParameters.switch_compatible_rules["5700_MAC_IP"][0]
        self.switch5700.cli.resetOpenflowInstance()
        self.measureMaxRuleCountInHardware(self.switch5700, rule, table_id)
        print "========================================================="

#=========================================  MAX TABLE SIZES 5130 =========================

    def measureExtensibilityTable5130(self):
        print "=================== Test 3:Measuring Max Rule Count for EXTENSIBILITY Table====================="
        table_id = 20
        self.switch5130.cli.enableExtensibilityTable()
        rules = SwitchParameters.switch_compatible_rules["5130_NORMAL"]
        for i in range(0, len(rules) - 1, 1):
            self.switch5130.cli.resetOpenflowInstance()
            self.measureMaxRuleCountInHardware(self.switch5130, rules[i],
                                               table_id)
        print "========================================================="

    def measureMacIPTable5130(self):
        print "=================== Test 3:Measuring Max Rule Count for EXTENSIBILITY Table====================="
        table_id = 10
        self.switch5130.cli.enableMacIPTable()
        rule = SwitchParameters.switch_compatible_rules["5130_MAC_IP"][0]
        self.switch5130.cli.resetOpenflowInstance()
        self.measureMaxRuleCountInHardware(self.switch5130, rule, table_id)
        print "========================================================="

    def measureMaxRuleCountInHardware(self, switch, flow, table_id):
        flow["flow"]["table_id"] = table_id
        print "Flow Pattern:", flow
        print "Number of wildcards: ", int(13 - len(flow["flow"]["match"]))
        hw_table_size = switch.getHardwareFlowsCount()
        while True:
            print "\r Rules = {0}".format(hw_table_size),
            for i in range(0, 100, 1):
                flow["flow"]["priority"] = hw_table_size + i
                flow = self.controller.buildDummyFlow(flow)
                #print flow
                self.controller.addFlow(switch.getDPID(), flow)
            current_count = switch.getHardwareFlowsCount()
            if hw_table_size == current_count:
                break
            hw_table_size = current_count
        print
        print "Rules number limit = ", str(hw_table_size)
Example #7
0
class TestingScenario3500:
    def __init__(self):
        self.logger = logging.getLogger("Monitor.TestScenario")
        self.logger.setLevel(logging.DEBUG)
        self.switch3500 = SwitchMonitor("00:0a:74:46:a0:5f:1e:80")
        self.controller = HPSDNController("10.1.3.16")
        self.Iperf = BandwidthMeter("10.1.3.17", "marian", "descartes",
                                    "10.1.3.11", "marian", "descartes",
                                    'iperf -c 10.100.3.17 -i 1 -y C',
                                    'iperf -s')
        self.Iperf.setTestDuraton(10000)
        self.Ping = DelayMonitor("10.1.3.11", "marian", "descartes",
                                 "10.100.3.17", 1000)
        self.Ping.setPingCount(10000)

    def start(self):
        # self.testActionsPerformace()
        # self.switch3500.cli.setOpenFlowVersion(10)
        # self.switch3500.cli.setPolicyEngineUsageLimit(100)
        # print "=================== Test 1:Measuring Hardware Processing Performance =========================="
        # self.hardwareProcessingPerformance(duration=20)
        # print "==============================================================================================="
        # print "=================== Test 2:Measuring Rules Insertion Performance =============================="
        # self.measureRuleInsertionPerformance(flow=flow,table_id=100,max_rule_count=20)
        # print "==============================================================================================="
        # print "=================== Test 3:Measuring Max Rule Count ==========================================="
        # self.measureTableSizeForDifferentRules()
        # print "==============================================================================================="
        # print "=================== Test 4:Flow Pull Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.measureGetFlowsImpact(flow=flow,table_id=100,max_table_size=20)
        # print "==============================================================================================="
        # print "=================== Test 5:OpenFlow Policy Engine dependency =============================="
        # self.measureOpenflowPolicyEngineDependency(table_id=100)
        # print "==============================================================================================="
        #self.switch3500.cli.setPolicyEngineUsageLimit(100)
        # print "=================== Test 1:Measuring Software Processing Performance =========================="
        # self.switch3500.cli.setSoftwareFlowTableRateLimit(10000)
        # self.installSFPingRules(200)
        # self.softwareProcessingPerformance()
        # print "==============================================================================================="
        # self.switch3500.cli.setSoftwareFlowTableRateLimit(10000)
        # print "=================== Test 2:Measuring Rules Insertion Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.measureRuleInsertionPerformance(flow,200,1526)
        # print "==============================================================================================="
        # print "=================== Test 3:Flow Pull Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.switch3500.cli.setSoftwareFlowTableRateLimit(10000)
        # self.measureGetFlowsImpact(flow,200,1526)
        # print "==============================================================================================="
        print "=================== Test 4:PPS change =============================="
        self.switch3500.cli.setPolicyEngineUsageLimit(100)
        self.softwarePPSChange()
        print "==============================================================================================="
        return

    def testActionsPerformace(self):
        self.switch3500.cli.resetOpenflowInstance()
        for i in range(0, 10, 1):
            for flow in SwitchParameters.switch3500_rule_action_performace_output_setipsrc:
                flow["flow"]["table_id"] = 200
                self.controller.addFlow(self.switch3500.getDPID(), flow)
        self.hardwareProcessingPerformance(30)
        print self.processIperfAndPingOutput()
        return

    def processIperfAndPingOutput(self):
        while self.Iperf.finished == False:
            time.sleep(1)
        while self.Ping.finished == False:
            time.sleep(1)
        ia = self.Iperf.values
        pa = self.Ping.values
        if len(pa) < len(ia):
            l = len(pa)
        else:
            l = len(ia)
        ias = 0
        pas = 0
        for i in range(0, l, 1):
            ias += ia[i]
            pas += pa[i]
            print ia[i], "\t", pa[i]
        aia = ias / l
        apa = pas / l
        print "Avarage Bandwidth: ", aia
        print "Avarage Delay: ", apa
        return [aia, apa]

    def installPingRules(self, table_id):
        flow1 = SwitchParameters.testbed_ping_rule_1
        flow2 = SwitchParameters.testbed_ping_rule_2
        flow1["flow"]["table_id"] = table_id
        flow2["flow"]["table_id"] = table_id
        self.controller.addFlow(self.switch3500.getDPID(), flow1)
        time.sleep(1)
        self.controller.addFlow(self.switch3500.getDPID(), flow2)
        time.sleep(1)

#=========================================  Hardware Processing Perfoemance performance =========================

    def hardwareProcessingPerformance(self, duration):
        #self.switch3500.cli.resetOpenflowInstance()
        #self.installPingRules(100)
        p1 = self.Iperf.startCapturingThroughput()
        p2 = self.Ping.startCapturingDelay()
        time.sleep(duration)
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(5)
        self.processIperfAndPingOutput()

#=========================================  Software Processing Perfoemance performance =========================

    def installSFPingRules(self, table_id):
        flow1 = SwitchParameters.switch3500_ping_rule_1
        flow2 = SwitchParameters.switch3500_ping_rule_2
        flow1["flow"]["table_id"] = table_id
        flow2["flow"]["table_id"] = table_id
        while (self.switch3500.getSoftwareFlowsCount() < 3):
            self.controller.addFlow(self.switch3500.getDPID(), flow1)
            self.controller.addFlow(self.switch3500.getDPID(), flow2)

    def softwareProcessingPerformance(self):
        cpus = []
        p1 = self.Iperf.startCapturingThroughput()
        p2 = self.Ping.startCapturingDelay()
        for i in range(0, 10, 1):
            time.sleep(1)
            cpus.append(self.switch3500.getCurrentCPU())
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(2)
        results = self.processIperfAndPingOutput()
        sum = 0
        for i in cpus:
            sum += int(i)
        print "Avarage CPU: ", str()
        results.append(float(sum / len(cpus)))
        return results

    def softwarePPSChange(self):
        f = open("3500_SfPpsChangePerformance.txt", "w")
        f.write("PPS\tThroughput\tDelay\tCPU\n")
        for i in range(10000, 10100, 100):
            self.switch3500.cli.setSoftwareFlowTableRateLimit(i)
            self.installSFPingRules(200)
            r = self.softwareProcessingPerformance()
            #print r,"srthsh"
            f.write(
                str(i) + "\t" + str(r[0]) + "\t" + str(r[1]) + "\t" +
                str(r[2]) + "\t\n")
        f.close()

#=========================================  Rule insetion performance =========================

    def measureRuleInsertionPerformance(self, flow, table_id, max_rule_count):
        cpus = {}
        flow_insertion_delays = {}
        flow_insertion_moments = {}
        flow = flow
        flow["flow"]["table_id"] = table_id
        self.switch3500.cli.resetOpenflowInstance()
        if table_id is 100:
            self.installPingRules(100)
        if table_id is 200:
            self.installSFPingRules(200)
        self.Iperf.startCapturingThroughput()
        self.Ping.startCapturingDelay()
        rules_count = self.switch3500.getHardwareFlowsCount()
        start_time = datetime.now()
        while rules_count < max_rule_count:
            print "\r Rules = {0}".format(rules_count),
            flow = self.controller.buildDummyFlow(flow)
            flow["flow"]["priority"] = rules_count + 1
            a = datetime.now()
            self.controller.addFlow(self.switch3500.getDPID(), flow)
            b = datetime.now()
            c = (b - a).microseconds
            flow_insertion_delays[rules_count] = c
            flow_insertion_moments[rules_count] = c
            if (rules_count % 10) == 0:
                cpus[rules_count] = self.switch3500.getCurrentCPU()
            else:
                cpus[rules_count] = 0
            rules_count += 1
        print
        end_time = datetime.now()
        duration = end_time - start_time
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(5)
        self.processIperfAndPingOutput()
        print "Experiment duration = " + str(duration)
        f = open("3500_RuleInsertionPerformance_" + str(table_id) + ".txt",
                 "w")
        f.write("Rule\tMoment\tDelay\tCPU\n")
        for key in flow_insertion_moments.keys():
            f.write(
                str(key) + "\t" + str(flow_insertion_moments[key]) + "\t" +
                str(flow_insertion_delays[key]) + "\t" + str(cpus[key]) +
                "\t\n")
#=========================================  Policy Engine Dependencie =========================

    def measureOpenflowPolicyEngineDependency(self, table_id):
        flow = SwitchParameters.switch3500_rule_9_OF13
        flow["flow"]["table_id"] = table_id
        for i in range(0, 100, 10):
            self.switch3500.cli.setPolicyEngineUsageLimit(i)
            time.sleep(3)
            self.measureMaxRuleCountInHardware(flow)

#=========================================  MAX TABLE SIZES =========================

    def measureTableSizeForDifferentRules(self):
        table_id = 100
        for flow in SwitchParameters.switch_compatible_rules["3500_OF13"]:
            self.switch3500.cli.resetOpenflowInstance()
            time.sleep(3)
            flow["flow"]["table_id"] = table_id
            self.measureMaxRuleCountInHardware(flow)
        print "========================================================="

    def measureMaxRuleCountInHardware(self, flow):
        print "Flow Pattern:", flow
        print "Number of wildcards: ", int(13 - len(flow["flow"]["match"]))
        hw_table_size = self.switch3500.getHardwareFlowsCount()
        #while True:
        while hw_table_size < 20:
            print "\r Rules = {0}".format(hw_table_size),
            for i in range(0, 10, 1):
                flow["flow"]["priority"] = hw_table_size + i
                flow = self.controller.buildDummyFlow(flow)
                self.controller.addFlow(self.switch3500.getDPID(), flow)
            current_count = self.switch3500.getHardwareFlowsCount()
            if hw_table_size == current_count:
                break
            hw_table_size = current_count
        print
        print "Rules number limit = ", str(hw_table_size)


#=========================================================================================
#mac-ip aware enabled

    def measureGetFlowsImpact(self, flow, table_id, max_table_size):
        self.switch3500.cli.resetOpenflowInstance()
        if table_id is 100:
            self.installPingRules(100)
        if table_id is 200:
            self.installSFPingRules(200)
        time.sleep(5)
        self.Iperf.startCapturingThroughput()
        self.Ping.startCapturingDelay()
        t = threading.Thread(target=self.getFlowsInThread)
        t.start()
        flow = flow
        flow["flow"]["table_id"] = table_id
        rules_count = self.switch3500.getHardwareFlowsCount()
        while rules_count <= max_table_size:
            flow = self.controller.buildDummyFlow(flow)
            flow["flow"]["priority"] = rules_count + 1
            self.controller.addFlow(self.switch3500.getDPID(), flow)
            rules_count += 1
            print "\rRules=", rules_count,
        time.sleep(10)
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        self.processIperfAndPingOutput()
        time.sleep(5)
        del t

    def getFlowsInThread(self):
        i = 0
        while True:
            i += 1
            self.controller.getTableFlowsCount(self.switch3500.getDPID(), 100)
            print "\rI=", i,

    def fillHWTableWithDummyRules(self):
        flow = SwitchParameters.switch3500_rule_9_OF13
        flow["flow"]["table_id"] = 100
        for i in range(0, 1527, 1):
            flow["flow"]["priority"] = i + 1
            print "\r", i,
            self.controller.addFlow(self.switch3500.getDPID(), flow)
        print "HW is full!"
Example #8
0
 def __init__(self):
     self.logger = logging.getLogger("Monitor.TestScenario")
     self.logger.setLevel(logging.DEBUG)
     self.switch2920 = SwitchMonitor("00:64:38:63:bb:58:eb:00")
     self.controller = HPSDNController("10.1.3.16")
Example #9
0
class TestingScenario3500:
    def __init__(self):
        self.logger = logging.getLogger("Monitor.TestScenario")
        self.logger.setLevel(logging.DEBUG)
        self.switch2920 = SwitchMonitor("00:64:38:63:bb:58:eb:00")
        self.controller = HPSDNController("10.1.3.16")
        #self.Iperf = BandwidthMeter("10.1.3.17", "marian", "descartes",
        #                           "10.1.3.11", "marian", "descartes",
        #                           'iperf -c 10.100.3.17 -i 1 -y C', 'iperf -s')
        #self.Iperf.setTestDuraton(10000)
        #self.Ping = DelayMonitor("10.1.3.11", "marian", "descartes", "10.100.3.17", 1000)
        #self.Ping.setPingCount(10000)

    def start(self):
        # print "=================== Test 1:Measuring Hardware Processing Performance =========================="
        # self.hardwareProcessingPerformance()
        # print "==============================================================================================="
        # print "=================== Test 2:Measuring Rules Insertion Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF10
        # self.measureRuleInsertionPerformance(flow,100,100)
        # print "==============================================================================================="
        #print "=================== Test 3:Measuring Max Rule Count ==========================================="
        #self.switch2920.cli.setPolicyEngineUsageLimit(10)
        #self.measureTableSizeForDifferentRules()
        #print "==============================================================================================="
        # print "=================== Test 4:Flow Pull Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.measureGetFlowsImpact(flow,100,512)
        # print "==============================================================================================="
        #In order to work only with SF table OF policy usage resource should equal 0
        print "=================== Test 5:OpenFlow Policy Engine dependency =============================="
        self.openflowPolicyEngineDependency()
        print "==============================================================================================="
        #self.switch3500.cli.setPolicyEngineUsageLimit(0)
        # print "=================== Test 1:Measuring Software Processing Performance =========================="
        # self.switch3500.cli.resetOpenflowInstance()
        # self.installPingRules(200)
        # self.softwareProcessingPerformance()
        # print "==============================================================================================="
        # print "=================== Test 2:Measuring Rules Insertion Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.measureRuleInsertionPerformance(flow,200,1000)
        # print "==============================================================================================="
        # print "=================== Test 3:Flow Pull Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.measureGetFlowsImpact(flow,10,200)
        # print "==============================================================================================="
        # print "=================== Test 4:PPS change =============================="
        # self.switch3500.cli.setPolicyEngineUsageLimit(100)
        # self.softwarePPSChange()
        # print "==============================================================================================="

    def installPingRules(self, table_id):
        flow1 = SwitchParameters.testbed_ping_rule_1
        flow2 = SwitchParameters.testbed_ping_rule_2
        flow1["flow"]["table_id"] = table_id
        flow2["flow"]["table_id"] = table_id
        self.controller.addFlow(self.switch3500.getDPID(), flow1)
        time.sleep(1)
        self.controller.addFlow(self.switch3500.getDPID(), flow2)

#=========================================  Hardware Processing Perfoemance performance =========================

    def hardwareProcessingPerformance(self):
        self.switch3500.cli.resetOpenflowInstance()
        self.installPingRules(100)
        p1 = self.Iperf.startCapturingThroughput()
        p2 = self.Ping.startCapturingDelay()
        time.sleep(15)
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(5)

#=========================================  Software Processing Perfoemance performance =========================

    def softwareProcessingPerformance(self):
        cpus = []
        p1 = self.Iperf.startCapturingThroughput()
        p2 = self.Ping.startCapturingDelay()
        for i in range(0, 15, 1):
            time.sleep(1)
            cpus.append(self.switch3500.getCurrentCPU())
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(5)
        print "[Switch3500-CPU] ", cpus

    def softwarePPSChange(self):
        for i in range(1000, 10000, 1000):
            self.switch3500.cli.setSoftwareFlowTableRateLimit(i)
            self.installSFPingRules(200)
            self.softwareProcessingPerformance()

    def installSFPingRules(self, table_id):
        flow1 = SwitchParameters.switch3500_ping_rule_1
        flow2 = SwitchParameters.switch3500_ping_rule_2
        flow1["flow"]["table_id"] = 200
        flow2["flow"]["table_id"] = 200
        while (self.switch3500.getSoftwareFlowsCount() < 3):
            self.controller.addFlow(self.switch3500.getDPID(), flow1)
            self.controller.addFlow(self.switch3500.getDPID(), flow2)

#=========================================  Rule insetion performance =========================

    def measureRuleInsertionPerformance(self, flow, table_id, max_rule_count):
        cpus = {}
        flow_insertion_delays = {}
        flow_insertion_moments = {}
        flow = flow
        flow["flow"]["table_id"] = table_id
        self.switch3500.cli.resetOpenflowInstance()
        self.installPingRules(100)
        self.Iperf.startCapturingThroughput()
        self.Ping.startCapturingDelay()
        rules_count = self.switch3500.getHardwareFlowsCount()
        start_time = datetime.now()
        while rules_count < max_rule_count:
            print "\r Rules = {0}".format(rules_count),
            flow = self.controller.buildDummyFlow(flow)
            flow["flow"]["priority"] = rules_count + 1
            a = datetime.now()
            self.controller.addFlow(self.switch3500.getDPID(), flow)
            b = datetime.now()
            c = (b - a).microseconds
            flow_insertion_delays[rules_count] = c
            flow_insertion_moments[rules_count] = c
            if (rules_count % 10) == 0:
                cpus[rules_count] = self.switch3500.getCurrentCPU()
            else:
                cpus[rules_count] = 0
            rules_count += 1
        print
        end_time = datetime.now()
        duration = end_time - start_time
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(5)
        print "Experiment duration = " + str(duration)
        f = open("3500_RuleInsertionPerformance_" + str(table_id) + ".txt",
                 "w")
        f.write("Rule\tMoment\tDelay\tCPU\n")
        for key in flow_insertion_moments.keys():
            f.write(
                str(key) + "\t" + str(flow_insertion_moments[key]) + "\t" +
                str(flow_insertion_delays[key]) + "\t" + str(cpus[key]) +
                "\t\n")
#=========================================  Policy Engine Dependencie =========================

    def openflowPolicyEngineDependency(self):
        results = {}
        table_id = 0
        flow = SwitchParameters.switch2920_rule_10
        flow["flow"]["table_id"] = table_id
        for i in range(100, 105, 5):
            self.switch2920.cli.setPolicyEngineUsageLimit(i)
            time.sleep(3)
            results[i] = self.measureMaxRuleCountInHardware(flow)
        for key in results.keys():
            print "\r", key, "\t", results[key]

#=========================================  MAX TABLE SIZES =========================

    def measureTableSizeForDifferentRules(self):
        table_id = 0
        for flow in SwitchParameters.switch_compatible_rules["2920"]:
            self.switch2920.cli.resetOpenflowInstance()
            time.sleep(3)
            flow["flow"]["table_id"] = table_id
            self.measureMaxRuleCountInHardware(flow)
        print "========================================================="

    def measureMaxRuleCountInHardware(self, flow):
        print "Flow Pattern:", flow
        print "Number of wildcards: ", int(13 - len(flow["flow"]["match"]))
        hw_table_size = self.switch2920.getHardwareFlowsCount()
        while True:
            print "\r Rules = {0}".format(hw_table_size),
            for i in range(0, 10, 1):
                flow["flow"]["priority"] = hw_table_size + i
                flow = self.controller.buildDummyFlow(flow)
                self.controller.addFlow(self.switch2920.getDPID(), flow)
            current_count = self.switch2920.getHardwareFlowsCount()
            if hw_table_size == current_count:
                break
            hw_table_size = current_count
        print
        print "Rules number limit = ", str(hw_table_size)
        return hw_table_size


#=========================================================================================
#mac-ip aware enabled

    def measureGetFlowsImpact(self, flow, table_id, max_table_size):
        self.switch3500.cli.resetOpenflowInstance()
        self.installPingRules(table_id)
        self.Iperf.startCapturingThroughput()
        self.Ping.startCapturingDelay()
        time.sleep(5)
        flow = flow
        flow["flow"]["table_id"] = table_id
        rules_count = self.switch3500.getHardwareFlowsCount()
        while rules_count <= 50:
            flow = self.controller.buildDummyFlow(flow)
            flow["flow"]["priority"] = rules_count + 1
            self.controller.addFlow(self.switch3500.getDPID(), flow)
            if (rules_count % 10) == 0:
                for i in range(0, 10, 1):
                    self.controller.getTableFlowsCount(
                        self.switch3500.getDPID(), table_id)
            rules_count += 1
            print "\r", rules_count,
        time.sleep(5)
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()

    def fillHWTableWithDummyRules(self):
        flow = SwitchParameters.switch3500_rule_9_OF13
        flow["flow"]["table_id"] = 100
        for i in range(0, 1527, 1):
            flow["flow"]["priority"] = i + 1
            print "\r", i,
            self.controller.addFlow(self.switch3500.getDPID(), flow)
        print "HW is full!"
Example #10
0
class MeasurePerformanceForVariablePacketSize:
    def __init__(self):
        self.logger = logging.getLogger("Monitor.TestScenario")
        self.logger.setLevel(logging.DEBUG)
        self.controller = HPSDNController("10.1.3.16")
        self.Iperf = BandwidthMeter("10.1.3.17", "marian", "descartes",
                                    "10.1.3.11", "marian", "descartes",
                                    'iperf -c 10.100.3.17 -i 1 -y C',
                                    'iperf -s')
        self.Iperf.setTestDuraton(10000)
        self.Ping = DelayMonitor("10.1.3.11", "marian", "descartes",
                                 "10.100.3.17", 1000)
        self.Ping.setPingCount(10000)

    def start(self):
        # NO OpenFlow Pipeline
        self.measurePerformanceForVariablePacketSize(
            "5130_PerformanceForVariablePacketSize_NoOpenFlow.txt")
        #self.measureSwitch5130()

    def measureSwitch5130(self):
        self.switch5130 = SwitchMonitor("00:00:00:00:00:00:00:42")
        print "=================== Switch5130: Extensibility Table =========================="
        self.switch5130.cli.enableExtensibilityTable()
        self.measurePerformanceForVariablePacketSize(
            "5130_PerformanceForVariablePacketSize_20.txt")
        print "=============================================================================="
        print "=================== Switch5130: MAC-IP Table =========================="
        self.switch5130.cli.enableMacIPTable()
        self.measurePerformanceForVariablePacketSize(
            "5130_PerformanceForVariablePacketSize_10.txt")
        print "=============================================================================="

    def measurePerformanceForVariablePacketSize(
            self, filename="X_PerformanceForVariablePacketSize.txt"):
        f = open(filename, "w")
        s = "Packet Size\tThroughput\tDelay\n"
        f.write(s)
        print s
        for size in range(60, 1520, 20):
            self.Iperf.setClientCommand('iperf -c 10.100.3.17 -i 1 -y C -M ' +
                                        str(size))
            self.hardwareProcessingPerformance(20)
            throughput_values, delay_values = self.processIperfAndPingOutput()
            avarage_throughput = self.calculateAvarage(throughput_values)
            avarage_delay = self.calculateAvarage(delay_values)
            s = str(size) + "\t" + str(avarage_throughput) + "\t" + str(
                avarage_delay) + "\t\n"
            print s,
            f.write(s)
        f.close()

    #USED TO INSTALL FLOWS IN DIFFERENT TABLES
    def installPingRules(self, switch, flow1, flow2, table_id=20, priority=0):
        flow1 = SwitchParameters.testbed_ping_rule_1_OF10
        flow2 = SwitchParameters.testbed_ping_rule_2_OF10
        flow1["flow"]["table_id"] = table_id
        flow2["flow"]["table_id"] = table_id
        flow1["flow"]["priority"] = priority
        flow2["flow"]["priority"] = priority
        for i in range(0, 5, 1):
            self.controller.addFlow(switch.getDPID(), flow1)
            self.controller.addFlow(switch.getDPID(), flow2)


#=========================================  Hardware Processing Perfoemance performance =========================

    def hardwareProcessingPerformance(self, duration):
        self.Iperf.startCapturingThroughput()
        self.Ping.startCapturingDelay()
        time.sleep(duration)
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()

    def processIperfAndPingOutput(self):
        while self.Iperf.finished == False:
            time.sleep(1)
        while self.Ping.finished == False:
            time.sleep(1)
        throughput_values = self.Iperf.values
        delay_values = self.Ping.values
        if len(throughput_values) < len(delay_values):
            l = len(throughput_values)
        else:
            l = len(delay_values)
        # Since IPERF and Ping are not synchronized, output arrays have differnt lengths
        throughput_values = throughput_values[0:l]
        delay_values = delay_values[0:l]
        return throughput_values, delay_values

    def calculateAvarage(self, array):
        if len(array) == 0:
            return 0
        sum = float(0)
        for i in array:
            sum += int(i)
        return float(sum / len(array))
 def __init__(self):
     self.logger = logging.getLogger("Monitor.TestScenario")
     self.logger.setLevel(logging.DEBUG)
     self.switch2920 = SwitchMonitor("00:64:38:63:bb:58:eb:00")
     self.controller = HPSDNController("10.1.3.16")
class TestingScenario3500:
    def __init__(self):
        self.logger = logging.getLogger("Monitor.TestScenario")
        self.logger.setLevel(logging.DEBUG)
        self.switch2920 = SwitchMonitor("00:64:38:63:bb:58:eb:00")
        self.controller = HPSDNController("10.1.3.16")
        #self.Iperf = BandwidthMeter("10.1.3.17", "marian", "descartes",
        #                           "10.1.3.11", "marian", "descartes",
        #                           'iperf -c 10.100.3.17 -i 1 -y C', 'iperf -s')
        #self.Iperf.setTestDuraton(10000)
        #self.Ping = DelayMonitor("10.1.3.11", "marian", "descartes", "10.100.3.17", 1000)
        #self.Ping.setPingCount(10000)

    def start(self):
        # print "=================== Test 1:Measuring Hardware Processing Performance =========================="
        # self.hardwareProcessingPerformance()
        # print "==============================================================================================="
        # print "=================== Test 2:Measuring Rules Insertion Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF10
        # self.measureRuleInsertionPerformance(flow,100,100)
        # print "==============================================================================================="
        #print "=================== Test 3:Measuring Max Rule Count ==========================================="
        #self.switch2920.cli.setPolicyEngineUsageLimit(10)
        #self.measureTableSizeForDifferentRules()
        #print "==============================================================================================="
        # print "=================== Test 4:Flow Pull Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.measureGetFlowsImpact(flow,100,512)
        # print "==============================================================================================="
        #In order to work only with SF table OF policy usage resource should equal 0
        print "=================== Test 5:OpenFlow Policy Engine dependency =============================="
        self.openflowPolicyEngineDependency()
        print "==============================================================================================="
        #self.switch3500.cli.setPolicyEngineUsageLimit(0)
        # print "=================== Test 1:Measuring Software Processing Performance =========================="
        # self.switch3500.cli.resetOpenflowInstance()
        # self.installPingRules(200)
        # self.softwareProcessingPerformance()
        # print "==============================================================================================="
        # print "=================== Test 2:Measuring Rules Insertion Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.measureRuleInsertionPerformance(flow,200,1000)
        # print "==============================================================================================="
        # print "=================== Test 3:Flow Pull Performance =============================="
        # flow = SwitchParameters.switch3500_rule_9_OF13
        # self.measureGetFlowsImpact(flow,10,200)
        # print "==============================================================================================="
        # print "=================== Test 4:PPS change =============================="
        # self.switch3500.cli.setPolicyEngineUsageLimit(100)
        # self.softwarePPSChange()
        # print "==============================================================================================="






    def installPingRules(self,table_id):
        flow1 = SwitchParameters.testbed_ping_rule_1
        flow2 = SwitchParameters.testbed_ping_rule_2
        flow1["flow"]["table_id"]=table_id
        flow2["flow"]["table_id"]=table_id
        self.controller.addFlow(self.switch3500.getDPID(),flow1)
        time.sleep(1)
        self.controller.addFlow(self.switch3500.getDPID(),flow2)


#=========================================  Hardware Processing Perfoemance performance =========================
    def hardwareProcessingPerformance(self):
        self.switch3500.cli.resetOpenflowInstance()
        self.installPingRules(100)
        p1 = self.Iperf.startCapturingThroughput()
        p2 = self.Ping.startCapturingDelay()
        time.sleep(15)
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(5)

#=========================================  Software Processing Perfoemance performance =========================
    def softwareProcessingPerformance(self):
        cpus = []
        p1 = self.Iperf.startCapturingThroughput()
        p2 = self.Ping.startCapturingDelay()
        for i in range(0,15,1):
            time.sleep(1)
            cpus.append(self.switch3500.getCurrentCPU())
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(5)
        print "[Switch3500-CPU] ",cpus


    def softwarePPSChange(self):
        for i in range(1000,10000,1000):
            self.switch3500.cli.setSoftwareFlowTableRateLimit(i)
            self.installSFPingRules(200)
            self.softwareProcessingPerformance()

    def installSFPingRules(self,table_id):
        flow1 = SwitchParameters.switch3500_ping_rule_1
        flow2 = SwitchParameters.switch3500_ping_rule_2
        flow1["flow"]["table_id"]=200
        flow2["flow"]["table_id"]=200
        while(self.switch3500.getSoftwareFlowsCount()<3):
            self.controller.addFlow(self.switch3500.getDPID(),flow1)
            self.controller.addFlow(self.switch3500.getDPID(),flow2)

#=========================================  Rule insetion performance =========================
    def measureRuleInsertionPerformance(self,flow,table_id,max_rule_count):
        cpus = {}
        flow_insertion_delays = {}
        flow_insertion_moments = {}
        flow = flow
        flow["flow"]["table_id"]=table_id
        self.switch3500.cli.resetOpenflowInstance()
        self.installPingRules(100)
        self.Iperf.startCapturingThroughput()
        self.Ping.startCapturingDelay()
        rules_count = self.switch3500.getHardwareFlowsCount()
        start_time = datetime.now()
        while rules_count<max_rule_count:
            print "\r Rules = {0}".format(rules_count),
            flow = self.controller.buildDummyFlow(flow)
            flow["flow"]["priority"]=rules_count+1
            a = datetime.now()
            self.controller.addFlow(self.switch3500.getDPID(),flow)
            b = datetime.now()
            c = (b-a).microseconds
            flow_insertion_delays[rules_count]= c
            flow_insertion_moments[rules_count]= c
            if(rules_count%10)==0:
                cpus[rules_count]= self.switch3500.getCurrentCPU()
            else:
                cpus[rules_count]= 0
            rules_count+=1
        print
        end_time = datetime.now()
        duration = end_time - start_time
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()
        time.sleep(5)
        print "Experiment duration = "+str(duration)
        f = open("3500_RuleInsertionPerformance_"+str(table_id)+".txt","w")
        f.write("Rule\tMoment\tDelay\tCPU\n")
        for key in flow_insertion_moments.keys():
            f.write(str(key)+"\t"+
                    str(flow_insertion_moments[key])+"\t"+
                    str(flow_insertion_delays[key])+"\t"+
                    str(cpus[key])+"\t\n")
#=========================================  Policy Engine Dependencie =========================
    def openflowPolicyEngineDependency(self):
        results = {}
        table_id = 0
        flow = SwitchParameters.switch2920_rule_10
        flow["flow"]["table_id"]=table_id
        for i in range(100,105,5):
            self.switch2920.cli.setPolicyEngineUsageLimit(i)
            time.sleep(3)
            results[i]=self.measureMaxRuleCountInHardware(flow)
        for key in results.keys():
            print "\r",key,"\t",results[key]



#=========================================  MAX TABLE SIZES =========================
    def measureTableSizeForDifferentRules(self):
        table_id = 0
        for flow in SwitchParameters.switch_compatible_rules["2920"]:
            self.switch2920.cli.resetOpenflowInstance()
            time.sleep(3)
            flow["flow"]["table_id"]=table_id
            self.measureMaxRuleCountInHardware(flow)
        print "========================================================="

    def measureMaxRuleCountInHardware(self,flow):
        print "Flow Pattern:", flow
        print "Number of wildcards: ",int(13-len(flow["flow"]["match"]))
        hw_table_size = self.switch2920.getHardwareFlowsCount()
        while True:
            print "\r Rules = {0}".format(hw_table_size),
            for i in range(0,10,1):
                flow["flow"]["priority"]=hw_table_size+i
                flow = self.controller.buildDummyFlow(flow)
                self.controller.addFlow(self.switch2920.getDPID(),flow)
            current_count = self.switch2920.getHardwareFlowsCount()
            if hw_table_size==current_count:
                break
            hw_table_size = current_count
        print
        print "Rules number limit = ",str(hw_table_size)
        return hw_table_size

#=========================================================================================
    #mac-ip aware enabled
    def measureGetFlowsImpact(self, flow, table_id, max_table_size):
        self.switch3500.cli.resetOpenflowInstance()
        self.installPingRules(table_id)
        self.Iperf.startCapturingThroughput()
        self.Ping.startCapturingDelay()
        time.sleep(5)
        flow = flow
        flow["flow"]["table_id"] = table_id
        rules_count = self.switch3500.getHardwareFlowsCount()
        while rules_count<=50:
            flow = self.controller.buildDummyFlow(flow)
            flow["flow"]["priority"]=rules_count+1
            self.controller.addFlow(self.switch3500.getDPID(),flow)
            if(rules_count%10)==0:
                for i in range(0,10,1):
                    self.controller.getTableFlowsCount(self.switch3500.getDPID(),table_id)
            rules_count+=1
            print "\r",rules_count,
        time.sleep(5)
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()




    def fillHWTableWithDummyRules(self):
        flow = SwitchParameters.switch3500_rule_9_OF13
        flow["flow"]["table_id"]=100
        for i in range(0,1527,1):
            flow["flow"]["priority"]=i+1
            print "\r",i,
            self.controller.addFlow(self.switch3500.getDPID(),flow)
        print "HW is full!"
class TestingScenario5700:
    def __init__(self):
        self.logger = logging.getLogger("Monitor.TestScenario")
        self.logger.setLevel(logging.DEBUG)
        self.switch5700 = SwitchMonitor("00:00:00:00:00:00:00:16")
        self.controller = HPSDNController("10.1.3.16")
        self.Iperf5700 = BandwidthMeter("10.1.3.17", "marian", "descartes",
                                   "10.1.3.11", "marian", "descartes",
                                   'iperf -c 10.100.3.17 -i 1 -y C', 'iperf -s')
        self.Iperf5700.setTestDuraton(10000)
        self.Ping5700 = DelayMonitor("10.1.3.11", "marian", "descartes", "10.100.3.17", 1000)
        self.Ping5700.setPingCount(10000)

    def start(self):
        self.switch5700.cli.enableExtensibilityTable()
        print "=================== Test 1:Measuring Hardware Processing Performance =========================="
        self.hardwareProcessingPerformance()
        print "==============================================================================================="
        print "=================== Test 2:Measuring Rules Insertion Performance =============================="
        flow = SwitchParameters.switch5700_rule_10
        self.measureRuleInsertionPerformance(flow,20,20)
        print "==============================================================================================="
        # print "=================== Test 3:Measuring Max Rule Count ==========================================="
        # self.measureTableSizeForDifferentRules()
        # print "==============================================================================================="
        print "=================== Test 4:Flow Pull Performance =============================="
        flow = SwitchParameters.switch5700_rule_10
        self.measureGetFlowsImpact(flow,20,512)
        print "==============================================================================================="
        self.switch5700.cli.enableMacIPTable()
        print "=================== Test 1:Measuring Hardware Processing Performance =========================="
        self.hardwareProcessingPerformance()
        print "==============================================================================================="
        print "=================== Test 2:Measuring Rules Insertion Performance =============================="
        flow = SwitchParameters.switch5700_mac_ip_rule
        self.measureRuleInsertionPerformance(flow,10,1000)
        print "==============================================================================================="
        print "=================== Test 3:Flow Pull Performance =============================="
        flow = SwitchParameters.switch5700_mac_ip_rule
        self.measureGetFlowsImpact(flow,10,1000)
        print "==============================================================================================="




    def installPingRules(self):
        flow1 = SwitchParameters.testbed_ping_rule_1
        flow2 = SwitchParameters.testbed_ping_rule_2
        flow1["flow"]["table_id"]=20
        flow2["flow"]["table_id"]=20
        self.controller.addFlow(self.switch5700.getDPID(),flow1)
        self.controller.addFlow(self.switch5700.getDPID(),flow2)


#=========================================  Hardware Processing Perfoemance performance =========================
    def hardwareProcessingPerformance(self):
        self.switch5700.cli.resetOpenflowInstance()
        self.installPingRules()
        p1 = self.Iperf5700.startCapturingThroughput(20)
        p2 = self.Ping5700.startCapturingDelay(30)
        p1.join()
        p2.join()
        #@time.sleep(20)
        #self.Iperf5700.stopCapturingThroughput()
        #self.Ping5700.stopCapturingDelay()
        #time.sleep(15)

#=========================================  Rule insetion performance =========================
    def measureRuleInsertionPerformance(self,flow,table_id,max_rule_count):
        cpus = {}
        flow_insertion_delays = {}
        flow_insertion_moments = {}
        flow = flow
        flow["flow"]["table_id"]=table_id
        self.switch5700.cli.resetOpenflowInstance()
        self.installPingRules()
        self.Iperf5700.startCapturingThroughput(180)
        self.Ping5700.startCapturingDelay(180)
        rules_count = self.switch5700.getHardwareFlowsCount()
        start_time = datetime.now()
        while rules_count<max_rule_count:
            print "\r Rules = {0}".format(rules_count),
            flow = self.controller.buildDummyFlow(flow)
            flow["flow"]["priority"]=rules_count+1
            a = datetime.now()
            self.controller.addFlow(self.switch5700.getDPID(),flow)
            b = datetime.now()
            c = (b-a).microseconds
            flow_insertion_delays[rules_count]= c
            flow_insertion_moments[rules_count]= c
            if(rules_count%10)==0:
                cpus[rules_count]= self.switch5700.getCurrentCPU()
            else:
                cpus[rules_count]= 0
            rules_count+=1
        print
        end_time = datetime.now()
        duration = end_time - start_time
        self.Iperf5700.stopCapturingThroughput()
        self.Ping5700.stopCapturingDelay()
        time.sleep(5)
        print "Experiment duration = "+str(duration)
        f = open("5700_RuleInsertionPerformance_"+str(table_id)+".txt","w")
        f.write("Rule\tMoment\tDelay\tCPU\n")
        for key in flow_insertion_moments.keys():
            f.write(str(key)+"\t"+
                    str(flow_insertion_moments[key])+"\t"+
                    str(flow_insertion_delays[key])+"\t"+
                    str(cpus[key])+"\t\n")


#=========================================  MAX TABLE SIZES =========================
    def measureTableSizeForDifferentRules(self):
        table_id = 20
        for flow in SwitchParameters.switch_compatible_rules["5700_NORMAL"]:
            self.switch5700.cli.resetOpenflowInstance()
            flow["flow"]["table_id"]=table_id
            self.measureMaxRuleCountInHardware(flow)
        print "========================================================="

    def measureMaxRuleCountInHardware(self,flow):
        print "Flow Pattern:", flow
        print "Number of wildcards: ",int(13-len(flow["flow"]["match"]))
        hw_table_size = self.switch5700.getHardwareFlowsCount()
        while True:
            print "\r Rules = {0}".format(hw_table_size),
            for i in range(0,100,1):
                flow["flow"]["priority"]=hw_table_size+i
                flow = self.controller.buildDummyFlow(flow)
                self.controller.addFlow(self.switch5700.getDPID(),flow)
            current_count = self.switch5700.getHardwareFlowsCount()
            if hw_table_size==current_count:
                break
            hw_table_size = current_count
        print
        print "Rules number limit = ",str(hw_table_size)

#=========================================================================================
    #mac-ip aware enabled
    def measureGetFlowsImpact(self, flow, table_id, max_table_size):
        self.switch5700.cli.resetOpenflowInstance()
        #self.installPingRules()
        self.Iperf5700.startCapturingThroughput(180)
        self.Ping5700.startCapturingDelay(180)
        time.sleep(5)
        flow = flow
        flow["flow"]["table_id"] = table_id
        rules_count = self.switch5700.getHardwareFlowsCount()
        while rules_count<=max_table_size:
            flow = self.controller.buildDummyFlow(flow)
            flow["flow"]["priority"]=rules_count+1
            self.controller.addFlow(self.switch5700.getDPID(),flow)
            if(rules_count%10)==0:
                for i in range(0,10,1):
                    print self.controller.getTableFlowsCount(self.switch5700.getDPID(),table_id)
            rules_count+=1
        time.sleep(5)
        self.Iperf5700.stopCapturingThroughput()
        self.Ping5700.stopCapturingDelay()
class MeasurePerformanceForVariablePacketSize:
    def __init__(self):
        self.logger = logging.getLogger("Monitor.TestScenario")
        self.logger.setLevel(logging.DEBUG)
        self.controller = HPSDNController("10.1.3.16")
        self.Iperf = BandwidthMeter("10.1.3.17", "marian", "descartes",
                                   "10.1.3.11", "marian", "descartes",
                                   'iperf -c 10.100.3.17 -i 1 -y C', 'iperf -s')
        self.Iperf.setTestDuraton(10000)
        self.Ping = DelayMonitor("10.1.3.11", "marian", "descartes", "10.100.3.17", 1000)
        self.Ping.setPingCount(10000)

    def start(self):
        # NO OpenFlow Pipeline
        self.measurePerformanceForVariablePacketSize("5130_PerformanceForVariablePacketSize_NoOpenFlow.txt")
        #self.measureSwitch5130()


    def measureSwitch5130(self):
        self.switch5130 = SwitchMonitor("00:00:00:00:00:00:00:42")
        print "=================== Switch5130: Extensibility Table =========================="
        self.switch5130.cli.enableExtensibilityTable()
        self.measurePerformanceForVariablePacketSize("5130_PerformanceForVariablePacketSize_20.txt")
        print "=============================================================================="
        print "=================== Switch5130: MAC-IP Table =========================="
        self.switch5130.cli.enableMacIPTable()
        self.measurePerformanceForVariablePacketSize("5130_PerformanceForVariablePacketSize_10.txt")
        print "=============================================================================="



    def measurePerformanceForVariablePacketSize(self,filename="X_PerformanceForVariablePacketSize.txt"):
        f = open(filename,"w")
        s = "Packet Size\tThroughput\tDelay\n"
        f.write(s)
        print s
        for size in range(60,1520,20):
            self.Iperf.setClientCommand('iperf -c 10.100.3.17 -i 1 -y C -M '+str(size))
            self.hardwareProcessingPerformance(20)
            throughput_values,delay_values = self.processIperfAndPingOutput()
            avarage_throughput = self.calculateAvarage(throughput_values)
            avarage_delay = self.calculateAvarage(delay_values)
            s = str(size)+"\t"+str(avarage_throughput)+"\t"+str(avarage_delay)+"\t\n"
            print s,
            f.write(s)
        f.close()





    #USED TO INSTALL FLOWS IN DIFFERENT TABLES
    def installPingRules(self, switch, flow1, flow2, table_id=20, priority=0):
        flow1 = SwitchParameters.testbed_ping_rule_1_OF10
        flow2 = SwitchParameters.testbed_ping_rule_2_OF10
        flow1["flow"]["table_id"]=table_id
        flow2["flow"]["table_id"]=table_id
        flow1["flow"]["priority"]=priority
        flow2["flow"]["priority"]=priority
        for i in range(0,5,1):
            self.controller.addFlow(switch.getDPID(),flow1)
            self.controller.addFlow(switch.getDPID(),flow2)


#=========================================  Hardware Processing Perfoemance performance =========================
    def hardwareProcessingPerformance(self,duration):
        self.Iperf.startCapturingThroughput()
        self.Ping.startCapturingDelay()
        time.sleep(duration)
        self.Iperf.stopCapturingThroughput()
        self.Ping.stopCapturingDelay()


    def processIperfAndPingOutput(self):
        while self.Iperf.finished==False:
            time.sleep(1)
        while self.Ping.finished==False:
            time.sleep(1)
        throughput_values = self.Iperf.values
        delay_values = self.Ping.values
        if len(throughput_values)<len(delay_values):
            l = len(throughput_values)
        else:
            l = len(delay_values)
        # Since IPERF and Ping are not synchronized, output arrays have differnt lengths
        throughput_values = throughput_values[0:l]
        delay_values = delay_values[0:l]
        return throughput_values,delay_values

    def calculateAvarage(self,array):
        if len(array)==0:
            return 0
        sum = float(0)
        for i in array:
            sum+=int(i)
        return float(sum/len(array))