Beispiel #1
0
    def __init__(self, **params):
        
        self.config = params.get('config', None)
        self.results = params.get('results', None)
        self.type = params.get('type', None)
        self.tt = params.get('traffic_trace', None)
        #create a reference for logger
        self.log = l.getLogger( self.__class__.__name__, 
                                self.config['LOG_LEVEL'], 
                                self.config['app_start_date'],
                                self.config['LOG_PATH'])
        
        self.log.info("STARTED...")
        
        
#         self.log.debug(str(self.results))
        
        #create a reference to database helper object
        dbh = self.config['dbhelper']
        
        connect = dbh.connect()
        #connect to database
        if not connect:
            self.log.error("Database connection was working at the time NFPA " +\
                           "has been started, but now, NFPA could not connect!")
            self.log.error("EXITING")
            exit(-1)
        
        #get ids for foreign keys
        cpu = dbh.getCpu(self.config['cpu_make'], self.config['cpu_model'])
        nic = dbh.getNic(self.config['nic_make'], 
                         self.config['nic_model'],
                         self.config['port_type'])
        virtualization = dbh.getVirtualization(self.config['virtualization'])
        vnf = dbh.getVnf(self.config['vnf_name'],
                         self.config['vnf_version'], 
                         self.config['vnf_function'], 
                         self.config['vnf_driver'],
                         self.config['vnf_driver_version'])
        
        user_id = dbh.getUser(self.config['username'])
        
        repetitions = self.config['measurement_num']
        duration = self.config['measurementDuration']
        
        biDir = self.config['biDir']


        #create a temporary dict (Measurements_Results) where the results 
        #will be stored indexed by the database's column name, 
        #e.g., sent_pps_min
        mr = {}
        
        if self.type == "synthetic":

            #check for special bidirectional measurement
            ul_dl = False
            tmp_tt = [self.tt,self.tt]
            if(sbtc.checkSpecialTraffic(self.tt)):
                ul_dl = True
                biDir = '1'
                tmp_tt = sbtc.splitTraffic(self.tt)
            else:
                #set back biDir if no special traffic is set
                biDir = self.config['biDir']

            for ps in self.results:
                traffic = dbh.getTraffic(tmp_tt[0], ps)

                pkt_res = self.results[ps]
                for h in self.config['header_uni']:
                    for h_h in self.config['helper_header']:
                        self.log.debug("%s - %s - %s - %s: %s" %
                                       (tmp_tt[0],ps,h,h_h,
                                        pkt_res[h][h_h]))
                        #create proper column name from header and helper_header
                        measure_column = h + "_" + h_h
                        mr[measure_column] = round(float(pkt_res[h][h_h]),4)

                self.log.debug("UniDir mr: %s" % str(mr))
                #now we need to insert a row
                bidir_id = dbh.insertMeasurement(
                     ts = self.config['app_start_date'],
                     name = self.config['scenario_name'],
                     cpu = cpu,
                     nic = nic,
                     virtualization = virtualization,
                     vnf = vnf,
                     used_cpu_cores = self.config['vnf_num_cores'],
                     traffic = traffic,
                     repetitions = repetitions,
                     duration = duration,
                     sent_pps_min = mr['sent_pps_min'],
                     sent_pps_avg = mr['sent_pps_avg'],
                     sent_pps_max = mr['sent_pps_max'],
                     recv_pps_min = mr['recv_pps_min'],
                     recv_pps_avg = mr['recv_pps_avg'],
                     recv_pps_max = mr['recv_pps_max'],
                     miss_pps_min = mr['miss_pps_min'],
                     miss_pps_avg = mr['miss_pps_avg'],
                     miss_pps_max = mr['miss_pps_max'],
                     sent_bps_min = mr['sent_bps_min'],
                     sent_bps_avg = mr['sent_bps_avg'],
                     sent_bps_max = mr['sent_bps_max'],
                     recv_bps_min = mr['recv_bps_min'],
                     recv_bps_avg = mr['recv_bps_avg'],
                     recv_bps_max = mr['recv_bps_max'],
                     diff_bps_min = mr['diff_bps_min'],
                     diff_bps_avg = mr['diff_bps_avg'],
                     diff_bps_max = mr['diff_bps_max'],
                     user_id = user_id,
                     comment = self.config['vnf_comment'],
                     bidir = biDir,
                     control_nfpa = self.config['control_nfpa'])

                #if bidirectional measurement was carried out, we need to
                #add another row
                if((int(self.config['biDir']) == 1) or (ul_dl)):
                    biDir = '1'
                    #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
                    mr = {}

                    #update traffic (necessary if special bidirectional
                    #measurement was carried out
                    traffic = dbh.getTraffic(tmp_tt[1], ps)
                    for h in self.config['header_bi']:
                        for h_h in self.config['helper_header']:
                            self.log.debug("%s - %s - %s - %s: %s" %
                                           (tmp_tt,ps,h,h_h,
                                            pkt_res[h][h_h]))
                            #we need to remove '_bidir' from header
                            #we could also append min,max,avg immediately
                            measure_column = copy.deepcopy(h)
                            measure_column = measure_column.replace('bidir',
                                                                    h_h)
                            mr[measure_column] = round(
                                                   float(pkt_res[h][h_h]),
                                                   4)

                    self.log.debug("Bidir mr: %s" % str(mr))
                    row_id = dbh.insertMeasurement(
                       ts = self.config['app_start_date'],
                       name = self.config['scenario_name'],
                       cpu = cpu,
                       nic = nic,
                       virtualization = virtualization,
                       vnf = vnf,
                       used_cpu_cores=self.config['vnf_num_cores'],
                       traffic = traffic,
                       repetitions = repetitions,
                       duration = duration,
                       sent_pps_min = mr['sent_pps_min'],
                       sent_pps_avg = mr['sent_pps_avg'],
                       sent_pps_max = mr['sent_pps_max'],
                       recv_pps_min = mr['recv_pps_min'],
                       recv_pps_avg = mr['recv_pps_avg'],
                       recv_pps_max = mr['recv_pps_max'],
                       miss_pps_min = mr['miss_pps_min'],
                       miss_pps_avg = mr['miss_pps_avg'],
                       miss_pps_max = mr['miss_pps_max'],
                       sent_bps_min = mr['sent_bps_min'],
                       sent_bps_avg = mr['sent_bps_avg'],
                       sent_bps_max = mr['sent_bps_max'],
                       recv_bps_min = mr['recv_bps_min'],
                       recv_bps_avg = mr['recv_bps_avg'],
                       recv_bps_max = mr['recv_bps_max'],
                       diff_bps_min = mr['diff_bps_min'],
                       diff_bps_avg = mr['diff_bps_avg'],
                       diff_bps_max = mr['diff_bps_max'],
                       user_id = user_id,
                       comment = self.config['vnf_comment'],
                       bidir_twin_id = bidir_id,
                       bidir = biDir,
                       control_nfpa = self.config['control_nfpa'])
                        
                        
        if self.type == "realistic":
            biDir = self.config['biDir']
            #check for special bidirectional measurement
            ul_dl = False
            tmp_tt = [self.tt,self.tt]
            if(sbtc.checkSpecialTraffic(self.tt)):
                ul_dl = True
                biDir = '1'
                tmp_tt = sbtc.splitTraffic(self.tt)
            else:
                #set back biDir if no special traffic is set
                biDir = self.config['biDir']

            #there is no packet size set  for realistic traces
            #so set here the second param to 0 (we need to use "0" instead
            #of 0, since 0 is represented as NULL, and database will throw
            #error of trying to inserting NULL value into NOT NULL column
            ps = "0"
            traffic = dbh.getTraffic(tmp_tt[0], ps)

            pkt_res = self.results
            for h in self.config['header_uni']:
                for h_h in self.config['helper_header']:
                    self.log.debug("%s - %s - %s: %s" %
                                   (tmp_tt[0],h,h_h,
                                    pkt_res[h][h_h]))
                    #create proper column name from header and helper_header
                    measure_column = h + "_" + h_h
                    mr[measure_column] = round(float(pkt_res[h][h_h]),4)

            self.log.debug("UniDir mr: %s" % str(mr))
            #now we need to insert a row
            bidir_id = dbh.insertMeasurement(
                 ts = self.config['app_start_date'],
                 name = self.config['scenario_name'],
                 cpu = cpu,
                 nic = nic,
                 virtualization = virtualization,
                 vnf = vnf,
                 used_cpu_cores=self.config['vnf_num_cores'],
                 traffic = traffic,
                 repetitions = repetitions,
                 duration = duration,
                 sent_pps_min = mr['sent_pps_min'],
                 sent_pps_avg = mr['sent_pps_avg'],
                 sent_pps_max = mr['sent_pps_max'],
                 recv_pps_min = mr['recv_pps_min'],
                 recv_pps_avg = mr['recv_pps_avg'],
                 recv_pps_max = mr['recv_pps_max'],
                 miss_pps_min = mr['miss_pps_min'],
                 miss_pps_avg = mr['miss_pps_avg'],
                 miss_pps_max = mr['miss_pps_max'],
                 sent_bps_min = mr['sent_bps_min'],
                 sent_bps_avg = mr['sent_bps_avg'],
                 sent_bps_max = mr['sent_bps_max'],
                 recv_bps_min = mr['recv_bps_min'],
                 recv_bps_avg = mr['recv_bps_avg'],
                 recv_bps_max = mr['recv_bps_max'],
                 diff_bps_min = mr['diff_bps_min'],
                 diff_bps_avg = mr['diff_bps_avg'],
                 diff_bps_max = mr['diff_bps_max'],
                 user_id = user_id,
                 comment = self.config['vnf_comment'],
                 bidir = biDir,
                 control_nfpa = self.config['control_nfpa'])

            #if bidirectional measurement was carried out, we need to
            #add another row
            if((int(self.config['biDir']) == 1) or (ul_dl)):
                biDir = '1'
                #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
                mr = {}

                #there is no packet size set  for realistic traces
                #so set here the second param to "0"
                traffic = dbh.getTraffic(tmp_tt[1], ps)
                for h in self.config['header_bi']:
                    for h_h in self.config['helper_header']:
                        self.log.debug("%s - %s - %s: %s" %
                                       (tmp_tt,h,h_h,
                                        pkt_res[h][h_h]))
                        #we need to remove '_bidir' from header
                        #we could also append min,max,avg immediately
                        measure_column = copy.deepcopy(h)
                        measure_column = measure_column.replace('bidir', h_h)
                        mr[measure_column] = round(
                                               float(pkt_res[h][h_h]),
                                               4)

                self.log.debug("Bidir mr: %s" % str(mr))
                row_id = dbh.insertMeasurement(
                 ts = self.config['app_start_date'],
                 name = self.config['scenario_name'],
                 cpu = cpu,
                 nic = nic,
                 virtualization = virtualization,
                 vnf = vnf,
                 used_cpu_cores=self.config['vnf_num_cores'],
                 traffic = traffic,
                 repetitions = repetitions,
                 duration = duration,
                 sent_pps_min = mr['sent_pps_min'],
                 sent_pps_avg = mr['sent_pps_avg'],
                 sent_pps_max = mr['sent_pps_max'],
                 recv_pps_min = mr['recv_pps_min'],
                 recv_pps_avg = mr['recv_pps_avg'],
                 recv_pps_max = mr['recv_pps_max'],
                 miss_pps_min = mr['miss_pps_min'],
                 miss_pps_avg = mr['miss_pps_avg'],
                 miss_pps_max = mr['miss_pps_max'],
                 sent_bps_min = mr['sent_bps_min'],
                 sent_bps_avg = mr['sent_bps_avg'],
                 sent_bps_max = mr['sent_bps_max'],
                 recv_bps_min = mr['recv_bps_min'],
                 recv_bps_avg = mr['recv_bps_avg'],
                 recv_bps_max = mr['recv_bps_max'],
                 diff_bps_min = mr['diff_bps_min'],
                 diff_bps_avg = mr['diff_bps_avg'],
                 diff_bps_max = mr['diff_bps_max'],
                 user_id = user_id,
                 comment = self.config['vnf_comment'],
                 bidir_twin_id = bidir_id,
                 bidir = biDir,
                 control_nfpa = self.config['control_nfpa'])
Beispiel #2
0
    def startPktgenMeasurements(self):
        '''
        This  function is actually doing the stuff. It assembles the pktgen command
        and corresponding lua scripts, then starts the measurements
        :return:
        '''
        self.log.info("+----------------------------------------------+")
        self.log.info(
            str("|-    Estimated time required: %s        -|" %
                self.config['ETL']))
        self.log.info("+----------------------------------------------+")
        time.sleep(2)

        if self.config["trafficTypes"]:

            self.log.info(
                str("Pktgen will be started %s times" %
                    self.config["measurement_num"]))

            #iterate through traffic types
            for trafficType in self.config["trafficTypes"]:
                self.log.info("Traffic type: %s" % trafficType)
                self.configureVNFRemote(trafficType)

                #first, measure simple scenarios (if desired)
                if (trafficType == "simple"):
                    #create config file for LUA script
                    self.rc.generateLuaConfigFile(trafficType,
                                                  self.config["packetSizes"],
                                                  None)
                    #append simple lua script to pktgen command
                    cmd = self.rc.assemblePktgenCommand()
                    cmd += " -f nfpa_simple.lua"

                    self.repeatedly_call_pktgen(cmd)

                else:
                    for ps in self.config['packetSizes']:
                        #create config file for LUA script
                        self.rc.generateLuaConfigFile(trafficType, [ps], None)
                        #create the command first part
                        cmd = self.rc.assemblePktgenCommand()
                        #no special bidirectional traffic was not set
                        if not sbtc.checkSpecialTraffic(trafficType):
                            cmd += " -f nfpa_traffic.lua -s " + \
                                  self.config["sendPort"] + ":" + \
                                  self.config['MAIN_ROOT'] + \
                                  "/PCAP/nfpa." +\
                                  trafficType + "." + ps + "bytes.pcap"

                            #if bidDir is set, we need to set pcap file for the
                            #other port as well (add this part to the cmd)
                            if (int(self.config["biDir"]) == 1):
                                cmd +=  " -s " + self.config["recvPort"] +\
                                        ":" + self.config['MAIN_ROOT'] +\
                                        "/PCAP/nfpa." +\
                                        trafficType + "." + ps + "bytes.pcap"
                        else:
                            #special bidirectional traffic was set
                            tmp_tt = sbtc.splitTraffic(trafficType)
                            cmd += " -f nfpa_traffic.lua -s " + \
                                    self.config["sendPort"] + ":" + \
                                    self.config['MAIN_ROOT'] + \
                                    "/PCAP/nfpa." + tmp_tt[0] + "." + \
                                    ps + "bytes.pcap"
                            cmd +=  " -s " + self.config["recvPort"] + \
                                    ":" + self.config['MAIN_ROOT'] + \
                                    "/PCAP/nfpa." + tmp_tt[1] + "." + \
                                    ps + "bytes.pcap"

                        self.repeatedly_call_pktgen(cmd)
                    #ok, we got measurements for a given traffic trace
                    #with all the defined packetsizes

                self.stopVNFRemote()
                # Analyze results, make plots and insert into the database
                self.startAnalyzing("synthetic", trafficType)

        if self.config["realisticTraffics"]:
            #check realistic traffic traces
            for realistic in self.config["realisticTraffics"]:

                #create config file for LUA script
                self.rc.generateLuaConfigFile(None, None, realistic)
                cmd = self.rc.assemblePktgenCommand()

                #no special bidirectional traffic was not set
                if not sbtc.checkSpecialTraffic(realistic):
                    cmd +=" -f nfpa_realistic.lua -s " + \
                          self.config["sendPort"] + ":" + \
                          self.config['MAIN_ROOT'] + "/PCAP/nfpa." +\
                          realistic + ".pcap"

                    #if bidDir is set, we need to set pcap file for the
                    #other port as well (add this part to the cmd)
                    if (int(self.config["biDir"]) == 1):
                        cmd += " -s " + self.config["recvPort"] + ":" + \
                               self.config['MAIN_ROOT'] + "/PCAP/nfpa." +\
                               realistic + ".pcap"

                #special bidirectional traffic was set
                else:
                    tmp_tt = sbtc.splitTraffic(realistic)
                    cmd += " -f nfpa_realistic.lua -s " + \
                           self.config["sendPort"] + ":" + \
                           self.config['MAIN_ROOT'] + "/PCAP/nfpa." +\
                           tmp_tt[0] + ".pcap"

                    cmd +=  " -s " + self.config["recvPort"] + \
                            ":" + self.config['MAIN_ROOT'] + \
                            "/PCAP/nfpa." + tmp_tt[1] + ".pcap"

                self.repeatedly_call_pktgen(cmd)

                self.stopVNFRemote()
                self.startAnalyzing("realistic", realistic)

        #after everything is done, delete unnecessary res files
        self.deleteResFiles()

        stop = time.time()
        start = self.config['app_start_date']

        running_time = float(stop) - float(start)
        running_time = str(datetime.timedelta(seconds=running_time))
        self.log.info(str("Time elapsed: %s") % running_time)

        self.log.info("Log file can be found under: %s" % self.log_file_path)
        self.log.info("THANK YOU FOR USING NFPA %s" % self.config['version'])

        if (self.reset_terminal):
            self.log.info("Resetting terminal...")
            time.sleep(1)
            os.system("reset")
            #print out log automatically in this case to simulate 'no-reset' effect
            print_log_cmd = "cat " + self.log_file_path
            os.system(print_log_cmd)
Beispiel #3
0
    def checkPcapFileExists(self):
        '''
        This functions checks whether a pcap file exists for the desired
        packet size and traffic type
        (called from checkConfig())
        '''
        
        simple_traffic_set = False
        if self._config["trafficTypes"]:
            #only if any traffic type was set
            for traffic_type in self._config["trafficTypes"]:
                #there is no pcap file for simple scenarios, skipping file check
                if traffic_type == "simple":
                    self.log.info("Simple traffic type was set")
                    simple_traffic_set = True
                    continue

                        
                
                else:
                    self.log.info("Checking synthetic traffictype: %s" % traffic_type)
                    for packetSize in self._config["packetSizes"]:               
                        
                        #special traffic type for ul-dl traffic
                        self.log.info("Special bidirectional"
                                          " traffictype: %s ?" % traffic_type)
                        if sbtc.checkSpecialTraffic(traffic_type):
                            self.log.info("### SPECIAL TRAFFICTYPE FOUND - "
                                          "USING DIFFERENT PCAPS FOR DIFFERENT"
                                          "PORTS ###")
                            tmp_tt = sbtc.splitTraffic(traffic_type)
                            #check for the first one
                            pcap1 = self._config["MAIN_ROOT"].strip() 
                            pcap1 += "/PCAP/nfpa." + tmp_tt[0] + "." 
                            pcap1 += packetSize + "bytes.pcap"
                            #check for the second one
                            pcap2 = self._config["MAIN_ROOT"].strip() 
                            pcap2 += "/PCAP/nfpa." + tmp_tt[1] + "." 
                            pcap2 += packetSize + "bytes.pcap"
                            
                            #check pcap file existance for both of them
                            self.log.info("check pcap file existence %s " % 
                                          pcap1)
                            ok1 = os.path.isfile(pcap1)
                            
                            self.log.info("check pcap file existence %s " % 
                                          pcap2)
                            ok2 = os.path.isfile(pcap2)
                            
                            #if any pcap is missing, then nothing can be done
                            #with this setting
                            if ok1 and ok2:
                                ok = True
                            else:
                                ok = False
                                
                        
                        else:
                            self.log.info("-------------------------------- NO")
                            #no special ul-dl traffic type was set
                            pcap = self._config["MAIN_ROOT"].strip()
                            pcap += "/PCAP/nfpa." + traffic_type + "." 
                            pcap +=  packetSize + "bytes.pcap"
                            self.log.info("check pcap file existence %s " % pcap)
                            #if special traffic type was set, check the existence of the
                            #corresponding pcap files
                            ok = os.path.isfile(pcap)
                        
                        if not ok:
                            #PCAP file not found
                            self.log.error("Missing PCAP file for traffic type: %s "
                                         "and packet size: %s not exists" % 
                                         (traffic_type, packetSize))
                            self.log.error("Are you sure you have the corresponding "
                                         "PCAP file(s) in directory: %s/PCAP ?" % 
                                         self._config["MAIN_ROOT"])

                            return False
                        else:
                            self.log.info("[FOUND]")
             
        
        #check for realistic traffics
        if(self._config["realisticTraffics"]):
            self.log.info("Realistic Traffics was defined...")
            for realistic in self._config["realisticTraffics"]:
                
                ok = False
                #special traffic type for ul-dl traffic
                self.log.info("Checking for special bidirectional"
                                  " traffictype: %s" % realistic)
                if sbtc.checkSpecialTraffic(realistic):
                    self.log.info("### SPECIAL TRAFFICTYPE FOUND - "
                                  "USING DIFFERENT PCAPS FOR DIFFERENT"
                                  "PORTS ###")
                    tmp_tt = sbtc.splitTraffic(realistic)
                    #check for the first one
                    pcap1 = self._config["MAIN_ROOT"].strip() 
                    pcap1 += "/PCAP/nfpa." + tmp_tt[0] + ".pcap" 
                    
                    #check for the second one
                    pcap2 = self._config["MAIN_ROOT"].strip() 
                    pcap2 += "/PCAP/nfpa." + tmp_tt[1] + ".pcap"
                    
                    #check pcap file existance for both of them
                    self.log.info("check pcap file existence %s " % 
                                  pcap1)
                    ok1 = os.path.isfile(pcap1)
                    
                    self.log.info("check pcap file existence %s " % 
                                  pcap2)
                    ok2 = os.path.isfile(pcap2)
                    
                    #if any pcap is missing, then nothing can be done
                    #with this setting
                    if ok1 and ok2:
                        ok = True
                    else:
                        ok = False
                        
                        
                else:
                    #assemble complete path for realistic traffic   
                    pcap = self._config["MAIN_ROOT"] + "/PCAP/nfpa." +\
                                     realistic + ".pcap"
                    self.log.info("Looking for %s" % pcap)
                    ok = os.path.isfile(pcap)
                  
                    
                if not ok:
                    #PCAP file not found
                    self.log.error("Missing PCAP file for traffic type: %s "
                                  % realistic)
                    self.log.error("Are you sure you have the corresponding "
                                 "PCAP file(s) in directory: %s/PCAP ?" % 
                                 self._config["MAIN_ROOT"])
                    return False
                else:
                    self.log.info("[FOUND]")
                    

        #everything is good, pcap files were found for the given 
        #packetsizes and traffic types (including realistic ones if they were 
        #set)
        return True
Beispiel #4
0
    def startPktgenMeasurements(self):
        '''
        This  function is actually doing the stuff. It assembles the pktgen command
        and corresponding lua scripts, then starts the measurements
        :return:
        '''
        self.log.info("+----------------------------------------------+")
        self.log.info(str("|-    Estimated time required: %s        -|" % 
                          self.config['ETL']))
        self.log.info("+----------------------------------------------+")
        time.sleep(2)


        if self.config["trafficTypes"]:
            
            self.log.info(str("Pktgen will be started %s times" % 
                              self.config["measurement_num"]))

            #iterate through traffic types
            for trafficType in self.config["trafficTypes"]:
                #first, measure simple scenarios (if desired)
                if(trafficType == "simple"):
                    self.log.warn("SIMPLE TRACE - %s" % trafficType)

                    # configure VNF if set
                    if self.config["control_nfpa"]:
                        if not self.configureVNFRemote(self.config["vnf_function"],trafficType):
                            # configuring vnf did not succeed
                            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)

                    #create config file for LUA script
                    self.rc.generateLuaConfigFile(trafficType,
                                                  self.config["packetSizes"],
                                                  None)
                    #append simple lua script to pktgen command
                    cmd = self.rc.assemblePktgenCommand()
                    cmd += " -f nfpa_simple.lua"
                    self.log.info("PKTgen command: %s" % cmd)

                    #sleep 1s for reading command
                    time.sleep(1)

                    #change dir to pktgen's main dir
                    cd_cmd = "cd " + self.config["PKTGEN_ROOT"]

                    #concatenate main command
                    main_cmd = cd_cmd + " && " + cmd
                    #here should be start the actual pktgen command!
                    #we can't use our invoke function, since we could
                    #not follow pktgen's output due to forking

                    #start pktgen in measurement_num times
                    for i in range(0, int(self.config["measurement_num"])):
                        retval = os.system(main_cmd)
                        if (retval != 0):
                            self.log.error("ERROR OCCURRED DURING STARTING PKTGEN")

                            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)


                else:
                    # configure VNF if set
                    if self.config["control_nfpa"]:
                        if not self.configureVNFRemote(self.config["vnf_function"], trafficType):
                            # configuring vnf did not succeed
                            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)

                    for ps in self.config['packetSizes']:
                        #create config file for LUA script
                        self.rc.generateLuaConfigFile(trafficType,
                                                      [ps],
                                                      None)
                        #create the command first part
                        cmd = self.rc.assemblePktgenCommand()
                        #no special bidirectional traffic was not set
                        if not sbtc.checkSpecialTraffic(trafficType):
                            cmd += " -f nfpa_traffic.lua -s " + \
                                  self.config["sendPort"] + ":" + \
                                  self.config['MAIN_ROOT'] + \
                                  "/PCAP/nfpa." +\
                                  trafficType + "." + ps + "bytes.pcap"

                            #if bidDir is set, we need to set pcap file for the
                            #other port as well (add this part to the cmd)
                            if(int(self.config["biDir"]) == 1):
                                cmd +=  " -s " + self.config["recvPort"] +\
                                        ":" + self.config['MAIN_ROOT'] +\
                                        "/PCAP/nfpa." +\
                                        trafficType + "." + ps + "bytes.pcap"
                        else:
                            #special bidirectional traffic was set
                            tmp_tt = sbtc.splitTraffic(trafficType)
                            cmd += " -f nfpa_traffic.lua -s " + \
                                    self.config["sendPort"] + ":" + \
                                    self.config['MAIN_ROOT'] + \
                                    "/PCAP/nfpa." + tmp_tt[0] + "." + \
                                    ps + "bytes.pcap"
                            cmd +=  " -s " + self.config["recvPort"] + \
                                    ":" + self.config['MAIN_ROOT'] + \
                                    "/PCAP/nfpa." + tmp_tt[1] + "." + \
                                    ps + "bytes.pcap"

                        self.log.info(cmd)
                        #sleep 1s for reading command
                        time.sleep(1)


                        #change dir to pktgen's main dir
                        cd_cmd = "cd " + self.config["PKTGEN_ROOT"]
                        #concatenate main command
                        main_cmd = cd_cmd + " && " + cmd

                        # start pktgen in measurement_num times
                        for i in range(0, int(self.config["measurement_num"])):
                            #here should be start the actual pktgen command!
                            #we can't use our invoke function, since we could
                            #not follow pktgen's output due to forking
                            retval=os.system(main_cmd)
                            if(retval != 0):
                                self.log.error("ERROR OCCURRED DURING STARTING PKTGEN")

                                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)
                    #ok, we got measurements for a given traffic trace
                    #with all the defined packetsizes

                # Start analyzing existing results, make plots and insert
                #data into the database
                self.startAnalyzing("synthetic", trafficType)

        
        if self.config["realisticTraffics"]:                
            #check realistic traffic traces
            for realistic in self.config["realisticTraffics"]:

                #create config file for LUA script
                self.rc.generateLuaConfigFile(None, 
                                              None,
                                              realistic)
                cmd = self.rc.assemblePktgenCommand()

                #no special bidirectional traffic was not set
                if not sbtc.checkSpecialTraffic(realistic):
                    cmd +=" -f nfpa_realistic.lua -s " + \
                          self.config["sendPort"] + ":" + \
                          self.config['MAIN_ROOT'] + "/PCAP/nfpa." +\
                          realistic + ".pcap" 
                
                    #if bidDir is set, we need to set pcap file for the 
                    #other port as well (add this part to the cmd)
                    if(int(self.config["biDir"]) == 1):
                        cmd += " -s " + self.config["recvPort"] + ":" + \
                               self.config['MAIN_ROOT'] + "/PCAP/nfpa." +\
                               realistic + ".pcap"
                
                #special bidirectional traffic was set
                else:
                    tmp_tt = sbtc.splitTraffic(realistic)
                    cmd += " -f nfpa_realistic.lua -s " + \
                           self.config["sendPort"] + ":" + \
                           self.config['MAIN_ROOT'] + "/PCAP/nfpa." +\
                           tmp_tt[0] + ".pcap" 
                    
                    cmd +=  " -s " + self.config["recvPort"] + \
                            ":" + self.config['MAIN_ROOT'] + \
                            "/PCAP/nfpa." + tmp_tt[1] + ".pcap"         
                    
                self.log.info(cmd)
                
                #sleep 1s for reading command
                time.sleep(1)
                
                #change dir to pktgen's main dir
                cd_cmd = "cd " + self.config["PKTGEN_ROOT"]
                #concatenate main command
                main_cmd = cd_cmd + " && " + cmd

                # start pktgen in measurement_num times
                for i in range(0, int(self.config["measurement_num"])):
                    #here should be start the actual pktgen command!
                    #we can't use our invoke function, since we could
                    #not follow pktgen's output due to forking
                    retval=os.system(main_cmd)
                    if(retval != 0):
                        self.log.error("ERROR OCCURRED DURING STARTING PKTGEN")


                        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)

                # Start analyzing existing results
                self.startAnalyzing("realistic", realistic)
             

        
        #after everything is done, delete unnecessary res files
        self.deleteResFiles()

        stop = time.time()        
        start = self.config['app_start_date'] 
         
        running_time =  float(stop) - float(start)
        running_time = str(datetime.timedelta(seconds=running_time))
        self.log.info(str("Time elapsed: %s") % running_time)

        self.log.info("Log file can be found under: %s" % self.log_file_path)
        self.log.info("THANK YOU FOR USING NFPA %s" % self.config['version'])

        if(self.reset_terminal):
            self.log.info("Resetting terminal...")
            time.sleep(1)
            os.system("reset")
            #print out log automatically in this case to simulate 'no-reset' effect
            print_log_cmd="cat " + self.log_file_path
            os.system(print_log_cmd)
Beispiel #5
0
    def __init__(self, **params):

        self.config = params.get('config', None)
        self.results = params.get('results', None)
        self.type = params.get('type', None)
        self.tt = params.get('traffic_trace', None)
        #create a reference for logger
        self.log = l.getLogger(self.__class__.__name__,
                               self.config['LOG_LEVEL'],
                               self.config['app_start_date'],
                               self.config['LOG_PATH'])

        self.log.info("STARTED...")

        #         self.log.debug(str(self.results))

        #create a reference to database helper object
        dbh = self.config['dbhelper']

        connect = dbh.connect()
        #connect to database
        if not connect:
            self.log.error("Database connection was working at the time NFPA " +\
                           "has been started, but now, NFPA could not connect!")
            self.log.error("EXITING")
            exit(-1)

        #get ids for foreign keys
        cpu = dbh.getCpu(self.config['cpu_make'], self.config['cpu_model'])
        nic = dbh.getNic(self.config['nic_make'], self.config['nic_model'],
                         self.config['port_type'])
        virtualization = dbh.getVirtualization(self.config['virtualization'])
        vnf = dbh.getVnf(self.config['vnf_name'], self.config['vnf_version'],
                         self.config['vnf_function'],
                         self.config['vnf_driver'],
                         self.config['vnf_driver_version'])

        user_id = dbh.getUser(self.config['username'])

        repetitions = self.config['measurement_num']
        duration = self.config['measurementDuration']

        biDir = self.config['biDir']

        #create a temporary dict (Measurements_Results) where the results
        #will be stored indexed by the database's column name,
        #e.g., sent_pps_min
        mr = {}

        if self.type == "synthetic":

            #check for special bidirectional measurement
            ul_dl = False
            tmp_tt = [self.tt, self.tt]
            if (sbtc.checkSpecialTraffic(self.tt)):
                ul_dl = True
                biDir = '1'
                tmp_tt = sbtc.splitTraffic(self.tt)
            else:
                #set back biDir if no special traffic is set
                biDir = self.config['biDir']

            for ps in self.results:
                traffic = dbh.getTraffic(tmp_tt[0], ps)

                pkt_res = self.results[ps]
                for h in self.config['header_uni']:
                    for h_h in self.config['helper_header']:
                        self.log.debug(
                            "%s - %s - %s - %s: %s" %
                            (tmp_tt[0], ps, h, h_h, pkt_res[h][h_h]))
                        #create proper column name from header and helper_header
                        measure_column = h + "_" + h_h
                        mr[measure_column] = round(float(pkt_res[h][h_h]), 4)

                self.log.debug("UniDir mr: %s" % str(mr))
                #now we need to insert a row
                bidir_id = dbh.insertMeasurement(
                    ts=self.config['app_start_date'],
                    name=self.config['scenario_name'],
                    cpu=cpu,
                    nic=nic,
                    virtualization=virtualization,
                    vnf=vnf,
                    used_cpu_cores=self.config['vnf_num_cores'],
                    traffic=traffic,
                    repetitions=repetitions,
                    duration=duration,
                    sent_pps_min=mr['sent_pps_min'],
                    sent_pps_avg=mr['sent_pps_avg'],
                    sent_pps_max=mr['sent_pps_max'],
                    recv_pps_min=mr['recv_pps_min'],
                    recv_pps_avg=mr['recv_pps_avg'],
                    recv_pps_max=mr['recv_pps_max'],
                    miss_pps_min=mr['miss_pps_min'],
                    miss_pps_avg=mr['miss_pps_avg'],
                    miss_pps_max=mr['miss_pps_max'],
                    sent_bps_min=mr['sent_bps_min'],
                    sent_bps_avg=mr['sent_bps_avg'],
                    sent_bps_max=mr['sent_bps_max'],
                    recv_bps_min=mr['recv_bps_min'],
                    recv_bps_avg=mr['recv_bps_avg'],
                    recv_bps_max=mr['recv_bps_max'],
                    diff_bps_min=mr['diff_bps_min'],
                    diff_bps_avg=mr['diff_bps_avg'],
                    diff_bps_max=mr['diff_bps_max'],
                    user_id=user_id,
                    comment=self.config['vnf_comment'],
                    bidir=biDir,
                    control_nfpa=self.config['control_nfpa'])

                #if bidirectional measurement was carried out, we need to
                #add another row
                if ((int(self.config['biDir']) == 1) or (ul_dl)):
                    biDir = '1'
                    #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
                    mr = {}

                    #update traffic (necessary if special bidirectional
                    #measurement was carried out
                    traffic = dbh.getTraffic(tmp_tt[1], ps)
                    for h in self.config['header_bi']:
                        for h_h in self.config['helper_header']:
                            self.log.debug(
                                "%s - %s - %s - %s: %s" %
                                (tmp_tt, ps, h, h_h, pkt_res[h][h_h]))
                            #we need to remove '_bidir' from header
                            #we could also append min,max,avg immediately
                            measure_column = copy.deepcopy(h)
                            measure_column = measure_column.replace(
                                'bidir', h_h)
                            mr[measure_column] = round(float(pkt_res[h][h_h]),
                                                       4)

                    self.log.debug("Bidir mr: %s" % str(mr))
                    row_id = dbh.insertMeasurement(
                        ts=self.config['app_start_date'],
                        name=self.config['scenario_name'],
                        cpu=cpu,
                        nic=nic,
                        virtualization=virtualization,
                        vnf=vnf,
                        used_cpu_cores=self.config['vnf_num_cores'],
                        traffic=traffic,
                        repetitions=repetitions,
                        duration=duration,
                        sent_pps_min=mr['sent_pps_min'],
                        sent_pps_avg=mr['sent_pps_avg'],
                        sent_pps_max=mr['sent_pps_max'],
                        recv_pps_min=mr['recv_pps_min'],
                        recv_pps_avg=mr['recv_pps_avg'],
                        recv_pps_max=mr['recv_pps_max'],
                        miss_pps_min=mr['miss_pps_min'],
                        miss_pps_avg=mr['miss_pps_avg'],
                        miss_pps_max=mr['miss_pps_max'],
                        sent_bps_min=mr['sent_bps_min'],
                        sent_bps_avg=mr['sent_bps_avg'],
                        sent_bps_max=mr['sent_bps_max'],
                        recv_bps_min=mr['recv_bps_min'],
                        recv_bps_avg=mr['recv_bps_avg'],
                        recv_bps_max=mr['recv_bps_max'],
                        diff_bps_min=mr['diff_bps_min'],
                        diff_bps_avg=mr['diff_bps_avg'],
                        diff_bps_max=mr['diff_bps_max'],
                        user_id=user_id,
                        comment=self.config['vnf_comment'],
                        bidir_twin_id=bidir_id,
                        bidir=biDir,
                        control_nfpa=self.config['control_nfpa'])

        if self.type == "realistic":
            biDir = self.config['biDir']
            #check for special bidirectional measurement
            ul_dl = False
            tmp_tt = [self.tt, self.tt]
            if (sbtc.checkSpecialTraffic(self.tt)):
                ul_dl = True
                biDir = '1'
                tmp_tt = sbtc.splitTraffic(self.tt)
            else:
                #set back biDir if no special traffic is set
                biDir = self.config['biDir']

            #there is no packet size set  for realistic traces
            #so set here the second param to 0 (we need to use "0" instead
            #of 0, since 0 is represented as NULL, and database will throw
            #error of trying to inserting NULL value into NOT NULL column
            ps = "0"
            traffic = dbh.getTraffic(tmp_tt[0], ps)

            pkt_res = self.results
            for h in self.config['header_uni']:
                for h_h in self.config['helper_header']:
                    self.log.debug("%s - %s - %s: %s" %
                                   (tmp_tt[0], h, h_h, pkt_res[h][h_h]))
                    #create proper column name from header and helper_header
                    measure_column = h + "_" + h_h
                    mr[measure_column] = round(float(pkt_res[h][h_h]), 4)

            self.log.debug("UniDir mr: %s" % str(mr))
            #now we need to insert a row
            bidir_id = dbh.insertMeasurement(
                ts=self.config['app_start_date'],
                name=self.config['scenario_name'],
                cpu=cpu,
                nic=nic,
                virtualization=virtualization,
                vnf=vnf,
                used_cpu_cores=self.config['vnf_num_cores'],
                traffic=traffic,
                repetitions=repetitions,
                duration=duration,
                sent_pps_min=mr['sent_pps_min'],
                sent_pps_avg=mr['sent_pps_avg'],
                sent_pps_max=mr['sent_pps_max'],
                recv_pps_min=mr['recv_pps_min'],
                recv_pps_avg=mr['recv_pps_avg'],
                recv_pps_max=mr['recv_pps_max'],
                miss_pps_min=mr['miss_pps_min'],
                miss_pps_avg=mr['miss_pps_avg'],
                miss_pps_max=mr['miss_pps_max'],
                sent_bps_min=mr['sent_bps_min'],
                sent_bps_avg=mr['sent_bps_avg'],
                sent_bps_max=mr['sent_bps_max'],
                recv_bps_min=mr['recv_bps_min'],
                recv_bps_avg=mr['recv_bps_avg'],
                recv_bps_max=mr['recv_bps_max'],
                diff_bps_min=mr['diff_bps_min'],
                diff_bps_avg=mr['diff_bps_avg'],
                diff_bps_max=mr['diff_bps_max'],
                user_id=user_id,
                comment=self.config['vnf_comment'],
                bidir=biDir,
                control_nfpa=self.config['control_nfpa'])

            #if bidirectional measurement was carried out, we need to
            #add another row
            if ((int(self.config['biDir']) == 1) or (ul_dl)):
                biDir = '1'
                #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
                mr = {}

                #there is no packet size set  for realistic traces
                #so set here the second param to "0"
                traffic = dbh.getTraffic(tmp_tt[1], ps)
                for h in self.config['header_bi']:
                    for h_h in self.config['helper_header']:
                        self.log.debug("%s - %s - %s: %s" %
                                       (tmp_tt, h, h_h, pkt_res[h][h_h]))
                        #we need to remove '_bidir' from header
                        #we could also append min,max,avg immediately
                        measure_column = copy.deepcopy(h)
                        measure_column = measure_column.replace('bidir', h_h)
                        mr[measure_column] = round(float(pkt_res[h][h_h]), 4)

                self.log.debug("Bidir mr: %s" % str(mr))
                row_id = dbh.insertMeasurement(
                    ts=self.config['app_start_date'],
                    name=self.config['scenario_name'],
                    cpu=cpu,
                    nic=nic,
                    virtualization=virtualization,
                    vnf=vnf,
                    used_cpu_cores=self.config['vnf_num_cores'],
                    traffic=traffic,
                    repetitions=repetitions,
                    duration=duration,
                    sent_pps_min=mr['sent_pps_min'],
                    sent_pps_avg=mr['sent_pps_avg'],
                    sent_pps_max=mr['sent_pps_max'],
                    recv_pps_min=mr['recv_pps_min'],
                    recv_pps_avg=mr['recv_pps_avg'],
                    recv_pps_max=mr['recv_pps_max'],
                    miss_pps_min=mr['miss_pps_min'],
                    miss_pps_avg=mr['miss_pps_avg'],
                    miss_pps_max=mr['miss_pps_max'],
                    sent_bps_min=mr['sent_bps_min'],
                    sent_bps_avg=mr['sent_bps_avg'],
                    sent_bps_max=mr['sent_bps_max'],
                    recv_bps_min=mr['recv_bps_min'],
                    recv_bps_avg=mr['recv_bps_avg'],
                    recv_bps_max=mr['recv_bps_max'],
                    diff_bps_min=mr['diff_bps_min'],
                    diff_bps_avg=mr['diff_bps_avg'],
                    diff_bps_max=mr['diff_bps_max'],
                    user_id=user_id,
                    comment=self.config['vnf_comment'],
                    bidir_twin_id=bidir_id,
                    bidir=biDir,
                    control_nfpa=self.config['control_nfpa'])
Beispiel #6
0
    def __init__(self, config, **params):
        '''
        Constructor
        params -
        the config
        the current traffic type
        the current packet size
        '''

        # store config in local var
        self.config = config
        self.tt = params.get("trafficType", None)
        self.trace = params.get("traffic_trace", None)

        if (self.tt is None or self.trace is None):
            self.log.error(
                "Something went wrong: no traffic type or traffic trace was passed"
            )

        self.log = None
        # self.log.error(str(self.config))
        self.log = l.getLogger(self.__class__.__name__,
                               self.config['LOG_LEVEL'],
                               self.config['app_start_date'],
                               self.config['LOG_PATH'])

        print("========Caller method=========")
        curframe = inspect.currentframe()
        calframe = inspect.getouterframes(curframe, 2)
        self.log.debug('caller name: %s' % calframe[1][3])

        #create a dictionary for the results
        self._results = {}

        # change directory where the res files are (PKTGEN_ROOT)
        os.chdir(self.config["PKTGEN_ROOT"])
        self.log.debug("Changed directory to %s" % str(os.getcwd()))

        # special ul-dl bidirectional traffic bit
        ul_dl = False
        # check whether special ul-dl bidirectional traffic was set
        if sbtc.checkSpecialTraffic(self.trace):
            ul_dl = True

        # assemble headers from header_uni and header_bi(if bidir is
        # set) -- We need deepcopy, to preserve original ones as they
        # were
        headers = copy.deepcopy(self.config['header_uni'])

        # append bidir header if biDir is set
        if (int(self.config["biDir"]) == 1):
            headers += self.config['header_bi']

        # check whether special ul-dl bidirectional traffic was set
        if ul_dl:
            # prepare for specail ul-dl bidirectional traffic
            headers = copy.deepcopy(self.config['header_uni'])
            # append bidir header
            headers += self.config['header_bi']

        if self.tt == "simple":
            # create subdictionaries for the different packet sizes
            for ps in self.config['packetSizes']:
                self._results[ps] = {}

                # create sub dicts of the list of  measured components
                # (sent(pps),recv(pps), etc.)
                for h in headers:
                    self._results[ps][h] = []

                # assemble res file path
                file_name = self.config["PKTGEN_ROOT"] + "/nfpa." + \
                           "simple." + ps + \
                          "bytes.res"
                # check file exists
                ok = os.path.isfile(file_name)
                if not ok:
                    self.log.error("ERROR: file %s not exists (skipping)" %
                                   file_name)
                # Open res file and parse each line of it
                with open(file_name, 'r') as lines:
                    for line in lines:
                        # remove blank spaces
                        line = line.strip()
                        # removed blank lines
                        if not line:
                            continue
                        # print out first line, but only print out!
                        # in the following we omit it, when results are
                        # parsed
                        self.log.debug(line)
                        # omit commented lines in analyzing
                        if (line.startswith("#", 0, 1)):
                            continue
                        # split config params
                        # self.log.info(line)

                        # split line according to tabs, then we got
                        # 0=snt(pps)
                        # 1=rec(pps)
                        # 2=miss(pps)
                        # 3=snt(bps)
                        # 4=rec(bps)
                        # 5=diff(bps)
                        # from 6 comes the same results, but for
                        # bidirectional results
                        results_as_list = line.split("|")
                        # append results
                        for i, h in enumerate(headers):
                            try:
                                self._results[ps][h].append(results_as_list[i])
                            except IndexError as ie:
                                self.log.error("Error during parsing res file")
                                self.log.error("splitted line: %s" %
                                               str(results_as_list))
                                self.log.error(ie)
                                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)

        ######### SYNTHETIC TRAFFIC TYPE CASE ############
        elif self.tt == "synthetic":

            #create subdictionaries for the different packet sizes
            for ps in self.config['packetSizes']:
                self._results[ps] = {}

                # create sub dicts of the list of  measured components
                # (sent(pps),recv(pps), etc.)
                for h in headers:
                    self._results[ps][h] = []

                # assemble res file path
                file_name = self.config["PKTGEN_ROOT"] + "/nfpa." + \
                          self.trace + "." + ps + \
                          "bytes.res"
                # check file exists
                ok = os.path.isfile(file_name)
                if not ok:
                    self.log.error("ERROR: file %s not exists (skipping)" %
                                   file_name)
                # Open res file and parse each line of it
                with open(file_name, 'r') as lines:
                    for line in lines:
                        # remove blank spaces
                        line = line.strip()
                        # removed blank lines
                        if not line:
                            continue
                        # print out first line, but only print out!
                        # in the following we omit it, when results are
                        # parsed
                        self.log.debug(line)
                        # omit commented lines in analyzing
                        if (line.startswith("#", 0, 1)):
                            continue
                        # split config params
                        # self.log.info(line)

                        # split line according to tabs, then we got
                        # 0=snt(pps)
                        # 1=rec(pps)
                        # 2=miss(pps)
                        # 3=snt(bps)
                        # 4=rec(bps)
                        # 5=diff(bps)
                        # from 6 comes the same results, but for
                        # bidirectional results
                        results_as_list = line.split("|")
                        # append results
                        for i, h in enumerate(headers):
                            try:
                                self._results[ps][h].append(results_as_list[i])
                            except IndexError as ie:
                                self.log.error("Error during parsing res file")
                                self.log.error("splitted line: %s" %
                                               str(results_as_list))
                                self.log.error(ie)
                                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)

        ######### REALISTIC TRAFFIC TYPE CASE ############
        elif self.tt == "realistic":

            # create sub dicts of the list of  measured components
            # (sent(pps),recv(pps), etc.)
            for h in headers:
                self._results[h] = []

            # assemble res file path
            file_name = self.config["PKTGEN_ROOT"] + "/nfpa." + \
                      self.trace + ".res"

            # check file exists
            ok = os.path.isfile(file_name)
            if not ok:
                self.log.warn("File %s not exists (skipping)" % file_name)
            # res file exists

            # Open res file and parse each line of it
            with open(file_name, 'r') as lines:
                for line in lines:
                    # remove blank spaces
                    line = line.strip()
                    # removed blank lines
                    if not line:
                        continue
                    # print out first line, but only print out!
                    # in the following we omit it, when results are
                    # parsed
                    self.log.debug(line)
                    # omit commented lines in analyzing
                    if (line.startswith("#", 0, 1)):
                        continue
                    # split config params
                    # self.log.info(line)

                    # split line according to tabs, then we got
                    # 0=snt(pps)
                    # 1=rec(pps)
                    # 2=miss(pps)
                    # 3=snt(bps)
                    # 4=rec(bps)
                    # 5=diff(bps)
                    # from 6 comes the same results, but for
                    # bidirectional results
                    results_as_list = line.split("|")
                    # append results
                    for i, h in enumerate(headers):
                        try:
                            self._results[h].append(results_as_list[i])
                        except IndexError as ie:
                            self.log.error("Error during parsing res file")
                            self.log.error("splitted line: %s" %
                                           str(results_as_list))
                            self.log.error(ie)
                            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)
        else:
            self.log.error("Unknown traffic type %s" % self.tt)
            exit(-1)

        self.processResultsData()
Beispiel #7
0
    def __init__(self, config, **params):
        '''
        Constructor
        params -
        the config
        the current traffic type
        the current packet size
        '''

        # store config in local var
        self.config = config
        self.tt=params.get("trafficType", None)
        self.trace=params.get("traffic_trace", None)




        if(self.tt is None or self.trace is None):
            self.log.error("Something went wrong: no traffic type or traffic trace was passed")

        self.log = None
        # self.log.error(str(self.config))
        self.log = l.getLogger(self.__class__.__name__,
                             self.config['LOG_LEVEL'],
                             self.config['app_start_date'],
                             self.config['LOG_PATH'])

        print("========Caller method=========")
        curframe = inspect.currentframe()
        calframe = inspect.getouterframes(curframe, 2)
        self.log.debug('caller name: %s' % calframe[1][3])

        #create a dictionary for the results
        self._results = {}

        # change directory where the res files are (PKTGEN_ROOT)
        os.chdir(self.config["PKTGEN_ROOT"])
        self.log.debug("Changed directory to %s" % str(os.getcwd()))


        # special ul-dl bidirectional traffic bit
        ul_dl = False
        # check whether special ul-dl bidirectional traffic was set
        if sbtc.checkSpecialTraffic(self.trace):
            ul_dl = True

        # assemble headers from header_uni and header_bi(if bidir is
        # set) -- We need deepcopy, to preserve original ones as they
        # were
        headers = copy.deepcopy(self.config['header_uni'])

        # append bidir header if biDir is set
        if (int(self.config["biDir"]) == 1):
            headers += self.config['header_bi']

        # check whether special ul-dl bidirectional traffic was set
        if ul_dl:
            # prepare for specail ul-dl bidirectional traffic
            headers = copy.deepcopy(self.config['header_uni'])
            # append bidir header
            headers += self.config['header_bi']

        if self.tt == "simple":
            # create subdictionaries for the different packet sizes
            for ps in self.config['packetSizes']:
                self._results[ps] = {}

                # create sub dicts of the list of  measured components
                # (sent(pps),recv(pps), etc.)
                for h in headers:
                    self._results[ps][h] = []

                # assemble res file path
                file_name = self.config["PKTGEN_ROOT"] + "/nfpa." + \
                           "simple." + ps + \
                          "bytes.res"
                # check file exists
                ok = os.path.isfile(file_name)
                if not ok:
                    self.log.error("ERROR: file %s not exists (skipping)" %
                                     file_name)
                # Open res file and parse each line of it
                with open(file_name, 'r') as lines:
                    for line in lines:
                        # remove blank spaces
                        line = line.strip()
                        # removed blank lines
                        if not line:
                            continue
                        # print out first line, but only print out!
                        # in the following we omit it, when results are
                        # parsed
                        self.log.debug(line)
                        # omit commented lines in analyzing
                        if (line.startswith("#", 0, 1)):
                            continue
                        # split config params
                        # self.log.info(line)

                        # split line according to tabs, then we got
                        # 0=snt(pps)
                        # 1=rec(pps)
                        # 2=miss(pps)
                        # 3=snt(bps)
                        # 4=rec(bps)
                        # 5=diff(bps)
                        # from 6 comes the same results, but for
                        # bidirectional results
                        results_as_list = line.split("|")
                        # append results
                        for i, h in enumerate(headers):
                            try:
                                self._results[ps][h].append(results_as_list[i])
                            except IndexError as ie:
                                self.log.error("Error during parsing res file")
                                self.log.error("splitted line: %s" %
                                             str(results_as_list))
                                self.log.error(ie)
                                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)

        ######### SYNTHETIC TRAFFIC TYPE CASE ############
        elif self.tt == "synthetic":

            #create subdictionaries for the different packet sizes
            for ps in self.config['packetSizes']:
                self._results[ps] = {}

                # create sub dicts of the list of  measured components
                # (sent(pps),recv(pps), etc.)
                for h in headers:
                    self._results[ps][h] = []


                # assemble res file path
                file_name = self.config["PKTGEN_ROOT"] + "/nfpa." + \
                          self.trace + "." + ps + \
                          "bytes.res"
                # check file exists
                ok = os.path.isfile(file_name)
                if not ok:
                    self.log.error("ERROR: file %s not exists (skipping)" %
                                 file_name)
                # Open res file and parse each line of it
                with open(file_name, 'r') as lines:
                    for line in lines:
                        # remove blank spaces
                        line = line.strip()
                        # removed blank lines
                        if not line:
                            continue
                        # print out first line, but only print out!
                        # in the following we omit it, when results are
                        # parsed
                        self.log.debug(line)
                        # omit commented lines in analyzing
                        if (line.startswith("#", 0, 1)):
                            continue
                        # split config params
                        # self.log.info(line)

                        # split line according to tabs, then we got
                        # 0=snt(pps)
                        # 1=rec(pps)
                        # 2=miss(pps)
                        # 3=snt(bps)
                        # 4=rec(bps)
                        # 5=diff(bps)
                        # from 6 comes the same results, but for
                        # bidirectional results
                        results_as_list = line.split("|")
                        # append results
                        for i, h in enumerate(headers):
                            try:
                                self._results[ps][h].append(results_as_list[i])
                            except IndexError as ie:
                                self.log.error("Error during parsing res file")
                                self.log.error("splitted line: %s" %
                                str(results_as_list))
                                self.log.error(ie)
                                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)

        ######### REALISTIC TRAFFIC TYPE CASE ############
        elif self.tt == "realistic":

            # create sub dicts of the list of  measured components
            # (sent(pps),recv(pps), etc.)
            for h in headers:
                self._results[h] = []

            # assemble res file path
            file_name = self.config["PKTGEN_ROOT"] + "/nfpa." + \
                      self.trace + ".res"

            # check file exists
            ok = os.path.isfile(file_name)
            if not ok:
                self.log.warn("File %s not exists (skipping)" % file_name)
              # res file exists

            # Open res file and parse each line of it
            with open(file_name, 'r') as lines:
                for line in lines:
                    # remove blank spaces
                    line = line.strip()
                    # removed blank lines
                    if not line:
                        continue
                    # print out first line, but only print out!
                    # in the following we omit it, when results are
                    # parsed
                    self.log.debug(line)
                    # omit commented lines in analyzing
                    if (line.startswith("#", 0, 1)):
                        continue
                    # split config params
                    # self.log.info(line)

                    # split line according to tabs, then we got
                    # 0=snt(pps)
                    # 1=rec(pps)
                    # 2=miss(pps)
                    # 3=snt(bps)
                    # 4=rec(bps)
                    # 5=diff(bps)
                    # from 6 comes the same results, but for
                    # bidirectional results
                    results_as_list = line.split("|")
                    # append results
                    for i, h in enumerate(headers):
                        try:
                            self._results[h].append(results_as_list[i])
                        except IndexError as ie:
                            self.log.error("Error during parsing res file")
                            self.log.error("splitted line: %s" %
                                            str(results_as_list))
                            self.log.error(ie)
                            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)
        else:
            self.log.error("Unknown traffic type %s" % self.tt)
            exit(-1)

        self.processResultsData()
Beispiel #8
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)
Beispiel #9
0
    def checkPcapFileExists(self):
        '''
        This functions checks whether a pcap file exists for the desired
        packet size and traffic type
        (called from checkConfig())
        '''
        
        simple_traffic_set = False
        if self._config["trafficTypes"]:
            #only if any traffic type was set
            for traffic_type in self._config["trafficTypes"]:
                #there is no pcap file for simple scenarios, skipping file check
                if traffic_type == "simple":
                    self.log.info("Simple traffic type was set")
                    simple_traffic_set = True
                    continue

                        
                
                else:
                    self.log.info("Checking synthetic traffictype: %s" % traffic_type)
                    for packetSize in self._config["packetSizes"]:               
                        
                        #special traffic type for ul-dl traffic
                        self.log.info("Special bidirectional"
                                          " traffictype: %s ?" % traffic_type)
                        if sbtc.checkSpecialTraffic(traffic_type):
                            self.log.info("### SPECIAL TRAFFICTYPE FOUND - "
                                          "USING DIFFERENT PCAPS FOR DIFFERENT"
                                          "PORTS ###")
                            tmp_tt = sbtc.splitTraffic(traffic_type)
                            #check for the first one
                            pcap1 = self._config["MAIN_ROOT"].strip() 
                            pcap1 += "/PCAP/nfpa." + tmp_tt[0] + "." 
                            pcap1 += packetSize + "bytes.pcap"
                            #check for the second one
                            pcap2 = self._config["MAIN_ROOT"].strip() 
                            pcap2 += "/PCAP/nfpa." + tmp_tt[1] + "." 
                            pcap2 += packetSize + "bytes.pcap"
                            
                            #check pcap file existance for both of them
                            self.log.info("check pcap file existence %s " % 
                                          pcap1)
                            ok1 = os.path.isfile(pcap1)
                            
                            self.log.info("check pcap file existence %s " % 
                                          pcap2)
                            ok2 = os.path.isfile(pcap2)
                            
                            #if any pcap is missing, then nothing can be done
                            #with this setting
                            if ok1 and ok2:
                                ok = True
                            else:
                                ok = False
                                
                        
                        else:
                            self.log.info("-------------------------------- NO")
                            #no special ul-dl traffic type was set
                            pcap = self._config["MAIN_ROOT"].strip()
                            pcap += "/PCAP/nfpa." + traffic_type + "." 
                            pcap +=  packetSize + "bytes.pcap"
                            self.log.info("check pcap file existence %s " % pcap)
                            #if special traffic type was set, check the existence of the
                            #corresponding pcap files
                            ok = os.path.isfile(pcap)
                        
                        if not ok:
                            #PCAP file not found
                            self.log.error("Missing PCAP file for traffic type: %s "
                                         "and packet size: %s not exists" % 
                                         (traffic_type, packetSize))
                            self.log.error("Are you sure you have the corresponding "
                                         "PCAP file(s) in directory: %s/PCAP ?" % 
                                         self._config["MAIN_ROOT"])

                            return False
                        else:
                            self.log.info("[FOUND]")
             
        
        #check for realistic traffics
        if(self._config["realisticTraffics"]):
            self.log.info("Realistic Traffics was defined...")
            for realistic in self._config["realisticTraffics"]:
                
                ok = False
                #special traffic type for ul-dl traffic
                self.log.info("Checking for special bidirectional"
                                  " traffictype: %s" % realistic)
                if sbtc.checkSpecialTraffic(realistic):
                    self.log.info("### SPECIAL TRAFFICTYPE FOUND - "
                                  "USING DIFFERENT PCAPS FOR DIFFERENT"
                                  "PORTS ###")
                    tmp_tt = sbtc.splitTraffic(realistic)
                    #check for the first one
                    pcap1 = self._config["MAIN_ROOT"].strip() 
                    pcap1 += "/PCAP/nfpa." + tmp_tt[0] + ".pcap" 
                    
                    #check for the second one
                    pcap2 = self._config["MAIN_ROOT"].strip() 
                    pcap2 += "/PCAP/nfpa." + tmp_tt[1] + ".pcap"
                    
                    #check pcap file existance for both of them
                    self.log.info("check pcap file existence %s " % 
                                  pcap1)
                    ok1 = os.path.isfile(pcap1)
                    
                    self.log.info("check pcap file existence %s " % 
                                  pcap2)
                    ok2 = os.path.isfile(pcap2)
                    
                    #if any pcap is missing, then nothing can be done
                    #with this setting
                    if ok1 and ok2:
                        ok = True
                    else:
                        ok = False
                        
                        
                else:
                    #assemble complete path for realistic traffic   
                    pcap = self._config["MAIN_ROOT"] + "/PCAP/nfpa." +\
                                     realistic + ".pcap"
                    self.log.info("Looking for %s" % pcap)
                    ok = os.path.isfile(pcap)
                  
                    
                if not ok:
                    #PCAP file not found
                    self.log.error("Missing PCAP file for traffic type: %s "
                                  % realistic)
                    self.log.error("Are you sure you have the corresponding "
                                 "PCAP file(s) in directory: %s/PCAP ?" % 
                                 self._config["MAIN_ROOT"])
                    return False
                else:
                    self.log.info("[FOUND]")
                    

        #everything is good, pcap files were found for the given 
        #packetsizes and traffic types (including realistic ones if they were 
        #set)
        return True
Beispiel #10
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)