Exemplo n.º 1
0
    def calculateTheoreticalMax(self, packetsize):
        '''
        This process will calculate the theoretical maximum according to the
        given packet size and the set port_type in nfpa.cfg.
        Then it converts it to the desired unit.
        :param  packetsize Int - calculate theoretical value accordingly
        return int - the theoretical maximum converted into the desired unit
        '''
        # get the port type from config file
        port_type = str(self.config['port_type']).split("_")[0]
        port_unit = str(self.config['port_type']).split("_")[1]

        # port rate will be an int according to port_type and the calculated
        # divisor for the given unit, for instance, in case of 10_G this will
        # be 10 * 1000000000 = 10.000.000.000 (dots are not commas, just for
        # easier reading!
        port_rate = int(port_type) * div.divisor(str(port_unit))

        #         self.log.debugug("port_rate: %d" % port_rate)

        # port rate is given in bit/s. Divide it by 8 to get byte/s.
        # packetsize should be extended with 20 bytes (interframe gap (12 bytes,
        # frame start seq. (7 bytes), and start delimiter (1 byte)
        theor_max = int(port_rate / 8 / (int(packetsize) + 20))

        return theor_max
Exemplo n.º 2
0
    def calculateTheoreticalMax(self, packetsize):
        '''
        This process will calculate the theoretical maximum according to the
        given packet size and the set port_type in nfpa.cfg.
        Then it converts it to the desired unit.
        return int - the theoretical maximum
        '''
        # get the port type from config file
        port_type = str(self.config['port_type']).split("_")[0]
        port_unit = str(self.config['port_type']).split("_")[1]

        # port rate will be an int according to port_type and the calculated
        # divisor for the given unit, for instance, in case of 10_G this will
        # be 10 * 1000000000 = 10.000.000.000 (dots are not commas, just for
        # easier reading!
        port_rate = int(port_type) * div.divisor(str(port_unit))

        #         self.log.debugug("port_rate: %d" % port_rate)

        # port rate is given in bit/s. Divide it by 8 to get byte/s.
        # packetsize should be extended with 20 bytes (interframe gap (12 bytes,
        # frame start seq. (7 bytes), and start delimiter (1 byte)
        theor_max = int(port_rate / 8 / (int(packetsize) + 20))

        return theor_max
Exemplo n.º 3
0
def blinker(
        # ~~~[Ports]~~~
        clock,
        leds,
        # ~~~[Parameters]~~~
        blink_clock=5000000,
        num_led=1):

    blink_signal = Signal(intbv(0)[1:])
    blink_uut = divisor(clk_in=clock,
                        clk_out=blink_signal,
                        division=blink_clock)

    @always_comb
    def map_N_led():
        for i in range(0, 8):
            if (i < num_led):
                leds.next[i] = blink_signal
            else:
                leds.next[i] = 0

    return blink_uut, map_N_led
Exemplo n.º 4
0
    def createGnuplotDataFile(self):    
        '''
        This procedure will create a gnuplot readable file from the results
        analyzed so far. One gnuplot file will represent one
        traffic scenario with the used packetsizes.
        ''' 
        #we need to divide the results according to the preset units!
        
        #just for easier usage
        pu = self.config['pps_unit']
        bu = self.config['bps_unit']
        
        #simple list for easier handling average, minimum and maximum values
        #store in results dictionaries
        helper_header = self.config['helper_header']
    
        #if synthetic traffic is needed to be plotted
        if self.type == "synthetic":

            #all right, we got the header data

            ul_dl = False
            if(sbtc.checkSpecialTraffic(self.tt)):
                ul_dl = True

            #assemble headers for accessing results dictionary
            headers = copy.deepcopy(self.config['header_uni'])
            if((int(self.config['biDir']) == 1) or (ul_dl)):
                #we need to check whether the special ul-dl bidirectional
                #traffic type was set. If so, then we also add header_bi
                #to headers var
                headers += self.config['header_bi']

            #theoretical
            header = "Size, Theor_max(p), "
                
            #assemble header to write out in gnuplot file
            #the following variables are necessary to know when to stop
            #writing commas
            headers_cnt = 1
            headers_len = len(headers) * len(helper_header)
            for h in headers:
                for h_h in helper_header:
                    if headers_cnt < headers_len:
                        comma = ", "
                    else:
                        comma = " "
                    header += h_h + "(" + h + ")" + comma
                    #increase headers counter
                    headers_cnt += 1

            header += "\n"

            #update units
            header = header.replace("pps", str("%spps" % pu))
            header = header.replace("bps", str("%sbps" % bu))


            #replace traffic type in file name to the current one
            data_file = self.prefix.replace("TRAFFICTYPE", str(self.tt))

            #update direction irrespectively whether biDir was set,so
            #replace uniDir to biDir - if biDir was set, nothing will happen
            if(ul_dl):
                data_file = data_file.replace("uniDir", "biDir")

            self.log.debug("Gnuplot data file will be: %s " % data_file)

            #assemble gnuplot arguments (input file will be the data file
            #that stores the results
            if not ul_dl:
                #if both ports are using the same pcap, we set that type
                #for both sent, and recv property in gnuplot params
                tmp_tt = [self.tt, self.tt]

            else:
                #indicate in ports which traffic is what
                tmp_tt = sbtc.splitTraffic(self.tt)

            gp_params = str("\"input_file='%s';"
                            "pps_unit='%s';"
                            "bps_unit='%s';"
                            "tr1='%s';"
                            "tr2='%s';\"" %
                             (data_file,
                              self.config['pps_unit'],
                              self.config['bps_unit'],
                              tmp_tt[0],
                              tmp_tt[1]))

            self.log.debug("Gnuplot params will be %s " % gp_params)

            try:
                #open file
                gp_data_file = open(data_file, 'w')
                #write out header
                gp_data_file.write(header)

                self.log.debug("create gnuplot file for traffic type: %s " % (self.tt))

                #we need to sort the results according to the packetsizes,
                #since data rows should be sorted for gnuplot, otherwise
                #very weird charts are generated
                #NOTE: it could be sorted via linux cat file|sort -n, but
                #do not want to restrict to BASH
                tmp_ps_list = []


                #iterate through the packet sizes
                for ps in self.results:

                    #so, we store the ps numbers in a list, then sort it, and
                    #iterate through the new list
                    tmp_ps_list.append(int(ps))

                tmp_ps_list.sort()

                self.log.debug(str(tmp_ps_list))


                for ps in tmp_ps_list:
                    ps = str(ps)

                    #create a simple pointer to main results dict
                    pkt_res = self.results[ps]

                    #theoretical
                    one_line = ps + ", " + \
                    str(round(float(pkt_res['theor_max']/div.divisor(pu)), 4)) + ", "

                    #getting results and print out
                    #the following variable is necessary to know when to stop
                    #writing commas
                    headers_cnt = 1
                    headers_len = len(headers) * len(helper_header)
                    for h in headers:
                        for h_h in helper_header:
                            if 'pps' in h:
                                #pps results needs to be divided by pps divisor
                                d = div.divisor(pu)
                            elif 'bps' in h:
                                #bps results needs to be divided by bps divisor
                                d = div.divisor(bu)
                            else:
                                #this part could be happened (ony if someone
                                #extends the programcode in a wrong manner)
                                self.log.error("Wrong headers are used...Segfault")
                                self.log.error("EXITING...")
                                if (self.config['email_adapter'] is not None) and \
                                    (not self.config['email_adapter'].sendErrorMail()):
                                    self.log.error("Sending ERROR email did not succeed...")
                                exit(-1)

                            #assemble one line with this embedded for loops
                            if headers_cnt < headers_len:
                                comma = ", "
                            else:
                                comma = " "

                            one_line += str(round(float(pkt_res[h][h_h]/d), 4)) + comma

                            #increase headers counter
                            headers_cnt += 1

                    one_line += "\n"

                    #write out one line
                    gp_data_file.write(one_line)

                #close file
                gp_data_file.close()
            except IOError as e:
                self.log.error("Cannot open results file GNUPLOT")
                self.log.error(str(e))
                self.log.error("EXITING...")
                if (self.config['email_adapter'] is not None) and \
                    (not self.config['email_adapter'].sendErrorMail()):
                    self.log.error("Sending ERROR email did not succeed...")
                exit(-1)

            #call gnuplot command to create chart
            self.drawChartViaGnuplot(gp_params, ul_dl=ul_dl)
        
        #if realistic traffic is needed to be plotted
        elif self.type == "realistic":

            self.log.debug("Visualizing %s" % self.tt)

            ul_dl = False
            if(sbtc.checkSpecialTraffic(self.tt)):
                ul_dl = True

            #assemble headers for accessing results dictionary
            headers = copy.deepcopy(self.config['header_uni'])
            if((int(self.config['biDir']) == 1) or (ul_dl)):
                #we need to check whether the special ul-dl bidirectional
                #traffic type was set. If so, then we also add header_bi
                #to headers var
                headers += self.config['header_bi']

            #assemble header in data file
            header = "Unit(" + self.config['pps_unit']
            header += "pps-" + self.config['bps_unit']
            header += "bps), Min, Avg, Max\n"
            #replace traffic type in file name to the current one
            data_file = self.prefix.replace("TRAFFICTYPE", str("realistic_%s"
                                                               % self.tt))

            #update direction irrespectively whether biDir was set,so
            #replace uniDir to biDir - if biDir was set, nothing will happen
            if(ul_dl):
                data_file = data_file.replace("uniDir", "biDir")

            self.log.debug("Gnuplot data file will be: %s " % data_file)

            #assemble gnuplot arguments (input file will be the data file
            #that stores the results
            if not ul_dl:
                #if both ports are using the same pcap, we set that type
                #for both sent, and recv property in gnuplot params
                tmp_tt = [self.tt, self.tt]

            else:
                #indicate in ports which traffic is what
                tmp_tt = sbtc.splitTraffic(self.tt)

            gp_params = str("\"input_file='%s';"
                            "pps_unit='%s';"
                            "bps_unit='%s';"
                            "tr1='%s';"
                            "tr2='%s';\"" %
                            (data_file,
                              self.config['pps_unit'],
                              self.config['bps_unit'],
                              tmp_tt[0],
                              tmp_tt[1]))


            self.log.debug("Gnuplot params will be %s " % gp_params)
            try:
                #open file
                gp_data_file = open(data_file, 'w')
                #write out header
                gp_data_file.write(header)

                self.log.debug("create gnuplot file for %s " % (self.tt))

                #create a simple pointer to main results dict
                pkt_res = self.results


                one_line = ""


                #getting results and print out
                for h in headers:
                    #print out unit as the first column
                    one_line += h + ", "
                    headers_cnt = 1
                    for h_h in helper_header:
                        if 'pps' in h:
                            #pps results needs to be divided by pps divisor
                            d = div.divisor(pu)
                        elif 'bps' in h:
                            #bps results needs to be divided by bps divisor
                            d = div.divisor(bu)
                        else:
                            #this part could be happened (only if someone
                            #extends the programcode in a wrong manner)
                            self.log.error("Wrong headers are used...Segfault")
                            self.log.error("EXITING...")
                            if (self.config['email_adapter'] is not None) and \
                                (not self.config['email_adapter'].sendErrorMail()):
                                self.log.error("Sending ERROR email did not succeed...")
                            exit(-1)

                        if(headers_cnt < 3):
                            comma = ", "
                        else:
                            comma = " "


                        one_line += str(round(float(pkt_res[h][h_h]/d), 4)) + comma

                        headers_cnt += 1
                    one_line += "\n"

                #update unit in the first column
                one_line = one_line.replace("pps", str("%spps" % pu))
                one_line = one_line.replace("bps", str("%sbps" % bu))
                #update column with the traffic types used for ports
#                 one_line = one_line.replace("sent_pps",
#                                             str("sent_%spps_%s" % (pu,
#                                                                    tmp_tt[0])))
#                 one_line = one_line.replace("recv_pps",
#                                             str("recv_%spps_%s" % (pu,
#                                                                    tmp_tt[0])))
#                 one_line = one_line.replace("miss_pps",
#                                             str("miss_%spps_%s" % (pu,
#                                                                    tmp_tt[0])))
#                 one_line = one_line.replace("sent_bps",
#                                             str("sent_%sbps_%s" % (bu,
#                                                                    tmp_tt[0])))
#                 one_line = one_line.replace("recv_bps",
#                                             str("recv_%sbps_%s" % (bu,
#                                                                    tmp_tt[0])))
#                 one_line = one_line.replace("diff_bps",
#                                             str("diff_%sbps_%s" % (bu,
#                                                                    tmp_tt[0])))
#
#                 #update bidirectional header elements as well
#                 if((int(self.config['biDir']) == 1) or (ul_dl)):
#                     one_line = one_line.replace(
#                                            "sent_pps_bidir",
#                                            str("sent_%spps_%s" % (pu,
#                                                                   tmp_tt[1])))
#                     one_line = one_line.replace(
#                                            "recv_pps_bidir",
#                                            str("recv_%spps_%s" % (pu,
#                                                                   tmp_tt[1])))
#
#                     one_line = one_line.replace(
#                                            "miss_pps_bidir",
#                                            str("miss_%spps_%s" % (pu,
#                                                                   tmp_tt[1])))
#
#                     one_line = one_line.replace(
#                                            "sent_bps_bidir",
#                                            str("sent_%sbps_%s" % (bu,
#                                                                   tmp_tt[1])))
#
#                     one_line = one_line.replace(
#                                            "recv_bps_bidir",
#                                            str("recv_%sbps_%s" % (bu,
#                                                                   tmp_tt[1])))
#
#                     one_line = one_line.replace(
#                                            "diff_bps_bidir",
#                                            str("diff_%sbps_%s" % (bu,
#                                                                   tmp_tt[1])))


                #write out one line
                gp_data_file.write(one_line)

                #close file
                gp_data_file.close()
            except IOError as e:
                self.log.error("Cannot open results file GNUPLOT")
                self.log.error(str(e))
                self.log.error("EXITING...")
                if (self.config['email_adapter'] is not None) and \
                    (not self.config['email_adapter'].sendErrorMail()):
                    self.log.error("Sending ERROR email did not succeed...")
                exit(-1)
            #call gnuplot command to create chart
            self.drawChartViaGnuplot(gp_params, ul_dl=ul_dl)
Exemplo n.º 5
0
    def createGnuplotDataFile(self):
        '''
        This procedure will create a gnuplot readable file from the results
        analyzed so far. One gnuplot file will represent one
        traffic scenario with the used packetsizes.
        '''
        #we need to divide the results according to the preset units!

        #just for easier usage
        pu = self.config['pps_unit']
        bu = self.config['bps_unit']

        #simple list for easier handling average, minimum and maximum values
        #store in results dictionaries
        helper_header = self.config['helper_header']

        #if synthetic traffic is needed to be plotted
        if self.type == "synthetic":

            #all right, we got the header data

            ul_dl = False
            if (sbtc.checkSpecialTraffic(self.tt)):
                ul_dl = True

            #assemble headers for accessing results dictionary
            headers = copy.deepcopy(self.config['header_uni'])
            if ((int(self.config['biDir']) == 1) or (ul_dl)):
                #we need to check whether the special ul-dl bidirectional
                #traffic type was set. If so, then we also add header_bi
                #to headers var
                headers += self.config['header_bi']

            #theoretical
            header = "Size, Theor_max(p), "

            #assemble header to write out in gnuplot file
            #the following variables are necessary to know when to stop
            #writing commas
            headers_cnt = 1
            headers_len = len(headers) * len(helper_header)
            for h in headers:
                for h_h in helper_header:
                    if headers_cnt < headers_len:
                        comma = ", "
                    else:
                        comma = " "
                    header += h_h + "(" + h + ")" + comma
                    #increase headers counter
                    headers_cnt += 1

            header += "\n"

            #update units
            header = header.replace("pps", str("%spps" % pu))
            header = header.replace("bps", str("%sbps" % bu))

            #replace traffic type in file name to the current one
            data_file = self.prefix.replace("TRAFFICTYPE", str(self.tt))

            #update direction irrespectively whether biDir was set,so
            #replace uniDir to biDir - if biDir was set, nothing will happen
            if (ul_dl):
                data_file = data_file.replace("uniDir", "biDir")

            self.log.debug("Gnuplot data file will be: %s " % data_file)

            #assemble gnuplot arguments (input file will be the data file
            #that stores the results
            if not ul_dl:
                #if both ports are using the same pcap, we set that type
                #for both sent, and recv property in gnuplot params
                tmp_tt = [self.tt, self.tt]

            else:
                #indicate in ports which traffic is what
                tmp_tt = sbtc.splitTraffic(self.tt)

            gp_params = str("\"input_file='%s';"
                            "pps_unit='%s';"
                            "bps_unit='%s';"
                            "tr1='%s';"
                            "tr2='%s';\"" %
                            (data_file, self.config['pps_unit'],
                             self.config['bps_unit'], tmp_tt[0], tmp_tt[1]))

            self.log.debug("Gnuplot params will be %s " % gp_params)

            try:
                #open file
                gp_data_file = open(data_file, 'w')
                #write out header
                gp_data_file.write(header)

                self.log.debug("create gnuplot file for traffic type: %s " %
                               (self.tt))

                #we need to sort the results according to the packetsizes,
                #since data rows should be sorted for gnuplot, otherwise
                #very weird charts are generated
                #NOTE: it could be sorted via linux cat file|sort -n, but
                #do not want to restrict to BASH
                tmp_ps_list = []

                #iterate through the packet sizes
                for ps in self.results:

                    #so, we store the ps numbers in a list, then sort it, and
                    #iterate through the new list
                    tmp_ps_list.append(int(ps))

                tmp_ps_list.sort()

                self.log.debug(str(tmp_ps_list))

                for ps in tmp_ps_list:
                    ps = str(ps)

                    #create a simple pointer to main results dict
                    pkt_res = self.results[ps]

                    #theoretical
                    one_line = ps + ", " + \
                    str(round(float(pkt_res['theor_max']/div.divisor(pu)), 4)) + ", "

                    #getting results and print out
                    #the following variable is necessary to know when to stop
                    #writing commas
                    headers_cnt = 1
                    headers_len = len(headers) * len(helper_header)
                    for h in headers:
                        for h_h in helper_header:
                            if 'pps' in h:
                                #pps results needs to be divided by pps divisor
                                d = div.divisor(pu)
                            elif 'bps' in h:
                                #bps results needs to be divided by bps divisor
                                d = div.divisor(bu)
                            else:
                                #this part could be happened (ony if someone
                                #extends the programcode in a wrong manner)
                                self.log.error(
                                    "Wrong headers are used...Segfault")
                                self.log.error("EXITING...")
                                if (self.config['email_adapter'] is not None) and \
                                    (not self.config['email_adapter'].sendErrorMail()):
                                    self.log.error(
                                        "Sending ERROR email did not succeed..."
                                    )
                                exit(-1)

                            #assemble one line with this embedded for loops
                            if headers_cnt < headers_len:
                                comma = ", "
                            else:
                                comma = " "

                            one_line += str(
                                round(float(pkt_res[h][h_h] / d), 4)) + comma

                            #increase headers counter
                            headers_cnt += 1

                    one_line += "\n"

                    #write out one line
                    gp_data_file.write(one_line)

                #close file
                gp_data_file.close()
            except IOError as e:
                self.log.error("Cannot open results file GNUPLOT")
                self.log.error(str(e))
                self.log.error("EXITING...")
                if (self.config['email_adapter'] is not None) and \
                    (not self.config['email_adapter'].sendErrorMail()):
                    self.log.error("Sending ERROR email did not succeed...")
                exit(-1)

            # only draw plots if initializing argument --noplot was not set
            if self.config['no_plot'] == False:
                #call gnuplot command to create chart
                self.drawChartViaGnuplot(gp_params, ul_dl=ul_dl)

        #if realistic traffic is needed to be plotted
        elif self.type == "realistic":

            self.log.debug("Visualizing %s" % self.tt)

            ul_dl = False
            if (sbtc.checkSpecialTraffic(self.tt)):
                ul_dl = True

            #assemble headers for accessing results dictionary
            headers = copy.deepcopy(self.config['header_uni'])
            if ((int(self.config['biDir']) == 1) or (ul_dl)):
                #we need to check whether the special ul-dl bidirectional
                #traffic type was set. If so, then we also add header_bi
                #to headers var
                headers += self.config['header_bi']

            #assemble header in data file
            header = "Unit(" + self.config['pps_unit']
            header += "pps-" + self.config['bps_unit']
            header += "bps), Min, Avg, Max\n"
            #replace traffic type in file name to the current one
            data_file = self.prefix.replace("TRAFFICTYPE",
                                            str("realistic_%s" % self.tt))

            #update direction irrespectively whether biDir was set,so
            #replace uniDir to biDir - if biDir was set, nothing will happen
            if (ul_dl):
                data_file = data_file.replace("uniDir", "biDir")

            self.log.debug("Gnuplot data file will be: %s " % data_file)

            #assemble gnuplot arguments (input file will be the data file
            #that stores the results
            if not ul_dl:
                #if both ports are using the same pcap, we set that type
                #for both sent, and recv property in gnuplot params
                tmp_tt = [self.tt, self.tt]

            else:
                #indicate in ports which traffic is what
                tmp_tt = sbtc.splitTraffic(self.tt)

            gp_params = str("\"input_file='%s';"
                            "pps_unit='%s';"
                            "bps_unit='%s';"
                            "tr1='%s';"
                            "tr2='%s';\"" %
                            (data_file, self.config['pps_unit'],
                             self.config['bps_unit'], tmp_tt[0], tmp_tt[1]))

            self.log.debug("Gnuplot params will be %s " % gp_params)
            try:
                #open file
                gp_data_file = open(data_file, 'w')
                #write out header
                gp_data_file.write(header)

                self.log.debug("create gnuplot file for %s " % (self.tt))

                #create a simple pointer to main results dict
                pkt_res = self.results

                one_line = ""

                #getting results and print out
                for h in headers:
                    #print out unit as the first column
                    one_line += h + ", "
                    headers_cnt = 1
                    for h_h in helper_header:
                        if 'pps' in h:
                            #pps results needs to be divided by pps divisor
                            d = div.divisor(pu)
                        elif 'bps' in h:
                            #bps results needs to be divided by bps divisor
                            d = div.divisor(bu)
                        else:
                            #this part could be happened (only if someone
                            #extends the programcode in a wrong manner)
                            self.log.error("Wrong headers are used...Segfault")
                            self.log.error("EXITING...")
                            if (self.config['email_adapter'] is not None) and \
                                (not self.config['email_adapter'].sendErrorMail()):
                                self.log.error(
                                    "Sending ERROR email did not succeed...")
                            exit(-1)

                        if (headers_cnt < 3):
                            comma = ", "
                        else:
                            comma = " "

                        one_line += str(round(float(pkt_res[h][h_h] / d),
                                              4)) + comma

                        headers_cnt += 1
                    one_line += "\n"

                #update unit in the first column
                one_line = one_line.replace("pps", str("%spps" % pu))
                one_line = one_line.replace("bps", str("%sbps" % bu))

                #write out one line
                gp_data_file.write(one_line)

                #close file
                gp_data_file.close()
            except IOError as e:
                self.log.error("Cannot open results file GNUPLOT")
                self.log.error(str(e))
                self.log.error("EXITING...")
                if (self.config['email_adapter'] is not None) and \
                    (not self.config['email_adapter'].sendErrorMail()):
                    self.log.error("Sending ERROR email did not succeed...")
                exit(-1)

            #only draw plots if initializing argument --noplot was not set
            if self.config['no_plot'] == False:
                #call gnuplot command to create chart
                self.drawChartViaGnuplot(gp_params, ul_dl=ul_dl)
Exemplo n.º 6
0
def divider(clock, leds, division=5000000):
    div = divisor(clk_in=clock, clk_out=leds, division=division)
    return div