f17519e0f02fe415701334b99f3abac718a4a5fc,profilerProcess.py,ProfilerProcess,get_timewindow,#ProfilerProcess#Any#Any#,1060

Before Change


                    twid = lasttwid
                elif lasttw_end_time <= flowtime:
                    // The flow was not in the last TW, its NEWER than it
                    self.outputqueue.put("04|profiler|[Profiler] The flow ({}) is NOT on the last time window ({}). Its newer".format(flowtime, lasttw_end_time))
                    amount_of_new_tw = int((flowtime - lasttw_end_time) / self.width)
                    self.outputqueue.put("04|profiler|[Profiler] We have to create {} empty TWs in the midle.".format(amount_of_new_tw))
                    temp_end = lasttw_end_time
                    for id in range(0, amount_of_new_tw + 1):
                        new_start = temp_end
                        twid = __database__.addNewTW(profileid, new_start)
                        self.outputqueue.put("04|profiler|[Profiler] Creating the TW id {}. Start: {}.".format(twid, new_start))
                        temp_end = new_start + self.width
                    // Now get the id of the last TW so we can return it
                elif lasttw_start_time > flowtime:
                    // The flow was not in the last TW, its OLDER that it
                    self.outputqueue.put("04|profiler|[Profiler] The flow ({}) is NOT on the last time window ({}). Its older".format(flowtime, lasttw_end_time))
                    // Find out if we already have this TW in the past
                    data = __database__.getTWforScore(profileid, flowtime)
                    if data:
                        // We found a TW where this flow belongs to
                        (twid, tw_start_time) = data
                        return twid
                    else:
                        // There was no TW that included the time of this flow, so create them in the past
                        // How many new TW we need in the past?
                        // amount_of_new_tw is the total amount of tw we should have under the new situation
                        amount_of_new_tw = int((lasttw_end_time - flowtime) / self.width)
                        // amount_of_current_tw is the real amount of tw we have now
                        amount_of_current_tw = __database__.getamountTWsfromProfile(profileid)
                        // diff is the new ones we should add in the past. (Yes, we could have computed this differently)
                        diff = amount_of_new_tw - amount_of_current_tw
                        self.outputqueue.put("05|profiler|[Profiler] We need to create {} TW before the first".format(diff + 1))
                        // Get the first TW
                        [(firsttwid, firsttw_start_time)] = __database__.getFirstTWforProfile(profileid)
                        firsttw_start_time = float(firsttw_start_time)
                        // The start of the new older TW should be the first - the width
                        temp_start = firsttw_start_time - self.width
                        for id in range(0, diff + 1):
                            new_start = temp_start
                            // The method to add an older TW is the same as to add a new one, just the starttime changes
                            twid = __database__.addNewOlderTW(profileid, new_start)
                            self.outputqueue.put("02|profiler|[Profiler] Creating the new older TW id {}. Start: {}.".format(twid, new_start))
                            temp_start = new_start - self.width
            except ValueError:
                // There is no last tw. So create the first TW
                // If the option for only-one-tw was selected, we should create the TW at least 100 years before the flowtime, to cover for

After Change


            self.print("[Profile] {}".format(inst), 0, 1)
            self.print("[Profile] {}".format(traceback.format_exc()), 0, 1)

    def get_timewindow(self, flowtime, profileid):
        "
        This function should get the id of the TW in the database where the flow belong.
        If the TW is not there, we create as many tw as necessary in the future or past until we get the correct TW for this flow.
        - We use this function to avoid retrieving all the data from the DB for the complete profile. We use a separate table for the TW per profile.
        -- Returns the time window id
        THIS IS NOT WORKING:
        - The empty profiles in the middle are not being created!!!
        - The Dtp ips are stored in the first time win
        
        try:
            // First check of we are not in the last TW. Since this will be the majority of cases
            try:
                [(lasttwid, lasttw_start_time)] = __database__.getLastTWforProfile(profileid)
                lasttw_start_time = float(lasttw_start_time)
                lasttw_end_time = lasttw_start_time + self.width
                flowtime = float(flowtime)
                self.print("The last TW id for profile {} was {}. Start:{}. End: {}".format(profileid, lasttwid, lasttw_start_time, lasttw_end_time), 0, 4)
                // There was a last TW, so check if the current flow belongs here.
                if lasttw_end_time > flowtime and lasttw_start_time <= flowtime:
                    self.print("[Profiler] The flow ({}) is on the last time window ({})".format(flowtime, lasttw_end_time), 0, 4)
                    twid = lasttwid
                elif lasttw_end_time <= flowtime:
                    // The flow was not in the last TW, its NEWER than it
                    self.print("[Profiler] The flow ({}) is NOT on the last time window ({}). Its newer".format(flowtime, lasttw_end_time), 0, 4)
                    amount_of_new_tw = int((flowtime - lasttw_end_time) / self.width)
                    self.print("[Profiler] We have to create {} empty TWs in the midle.".format(amount_of_new_tw), 0, 4)
                    temp_end = lasttw_end_time
                    for id in range(0, amount_of_new_tw + 1):
                        new_start = temp_end
                        twid = __database__.addNewTW(profileid, new_start)
                        self.print("[Profiler] Creating the TW id {}. Start: {}.".format(twid, new_start), 0, 4)
                        temp_end = new_start + self.width
                    // Now get the id of the last TW so we can return it
                elif lasttw_start_time > flowtime:
                    // The flow was not in the last TW, its OLDER that it
                    self.print("[Profiler] The flow ({}) is NOT on the last time window ({}). Its older".format(flowtime, lasttw_end_time), 0, 4)
                    // Find out if we already have this TW in the past
                    data = __database__.getTWforScore(profileid, flowtime)
                    if data:
                        // We found a TW where this flow belongs to
                        (twid, tw_start_time) = data
                        return twid
                    else:
                        // There was no TW that included the time of this flow, so create them in the past
                        // How many new TW we need in the past?
                        // amount_of_new_tw is the total amount of tw we should have under the new situation
                        amount_of_new_tw = int((lasttw_end_time - flowtime) / self.width)
                        // amount_of_current_tw is the real amount of tw we have now
                        amount_of_current_tw = __database__.getamountTWsfromProfile(profileid)
                        // diff is the new ones we should add in the past. (Yes, we could have computed this differently)
                        diff = amount_of_new_tw - amount_of_current_tw
                        self.print("[Profiler] We need to create {} TW before the first".format(diff + 1), 0, 5)
                        // Get the first TW
                        [(firsttwid, firsttw_start_time)] = __database__.getFirstTWforProfile(profileid)
                        firsttw_start_time = float(firsttw_start_time)
                        // The start of the new older TW should be the first - the width
                        temp_start = firsttw_start_time - self.width
                        for id in range(0, diff + 1):
                            new_start = temp_start
                            // The method to add an older TW is the same as to add a new one, just the starttime changes
                            twid = __database__.addNewOlderTW(profileid, new_start)
                            self.print("[Profiler] Creating the new older TW id {}. Start: {}.".format(twid, new_start), 0, 2)
                            temp_start = new_start - self.width
            except ValueError:
                // There is no last tw. So create the first TW
                // If the option for only-one-tw was selected, we should create the TW at least 100 years before the flowtime, to cover for
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 13

Instances


Project Name: stratosphereips/StratosphereLinuxIPS
Commit Name: f17519e0f02fe415701334b99f3abac718a4a5fc
Time: 2019-06-08
Author: eldraco@gmail.com
File Name: profilerProcess.py
Class Name: ProfilerProcess
Method Name: get_timewindow


Project Name: stratosphereips/StratosphereLinuxIPS
Commit Name: f17519e0f02fe415701334b99f3abac718a4a5fc
Time: 2019-06-08
Author: eldraco@gmail.com
File Name: profilerProcess.py
Class Name: ProfilerProcess
Method Name: get_timewindow


Project Name: stratosphereips/StratosphereLinuxIPS
Commit Name: 6f75c4e5a85fe91a4d1e9f3d3b888ac79e573f0e
Time: 2019-06-08
Author: eldraco@gmail.com
File Name: profilerProcess.py
Class Name: ProfilerProcess
Method Name: add_flow_to_profile


Project Name: stratosphereips/StratosphereLinuxIPS
Commit Name: 725ba9a972e0d73e1b3d9476604270c8fc67b5c3
Time: 2019-04-03
Author: eldraco@gmail.com
File Name: evidenceProcess.py
Class Name: EvidenceProcess
Method Name: run