Beispiel #1
0
 def getBwDifferential(self):
     self.iat_length_tuples = [l for l in self.iat_length_tuples if len(l) > 0]
     if time.time() - self.session.startTime > 0.2 and len(self.iat_length_tuples) > 1:
         lengths0 = [t[1] for t in self.iat_length_tuples[-2]]
         lengths1 = [t[1] for t in self.iat_length_tuples[-1]]
         bw0 = sum(lengths0) / self._period
         bw1 = sum(lengths1) / self._period
         bw_diff = (bw1 - bw0) / self._period
         self.session.bw_diffs.append(bw_diff)
         log.debug("[bwdiff %s] - bw diffs: %s", self.end, self.session.bw_diffs)
         log.debug("[bwdiff %s] -  abs bwdiff (%s) > threshold (%s)",
                   self.end, abs(bw_diff), self._threshold)
         if abs(bw_diff) > self._threshold:
             # we should sample uniformly from the passed iats
             # convert self.iat_length_tuples to distribution
             # and pass it to wfpad iat distribution as dict.
             iats = gu.get_iats([t[0] for t in gu.flatten_list(self.iat_length_tuples)])
             h = {iat: 1 for iat in iats}
             self._burstHistoProbdist['snd'] = hs.new(h)
             self._gapHistoProbdist['snd'] = hs.new(h)
         else:
             self._burstHistoProbdist['snd'] = hs.uniform(const.INF_LABEL)
             self._gapHistoProbdist['snd'] = hs.uniform(const.INF_LABEL)
     self.iat_length_tuples.append([])
     log.debug("[bwdiff %s] A period has passed: %s", self.end, self.iat_length_tuples[-3:-1])
     if self.isVisiting():
         log.debug("[bwdiff %s] Calling next period (visiting = %s, padding = %s)",
                   self.end, self.isVisiting(), self.session.is_padding)
         cm.deferLater(self._period, self.getBwDifferential)
Beispiel #2
0
 def getAverageTs(self):
     avg_ts = mu.median(
         gu.get_iats(
             [t[0] for t in gu.flatten_list(self.iat_length_tuples)]))
     log.debug("[bwdiff - %s] Average ts in the session is: %s.", self.end,
               avg_ts)
     return avg_ts
Beispiel #3
0
 def estimate_rho(self, rho_star):
     """Estimate new value of rho based on past network performance."""
     #log.debug("[cs-buflo] rho stats: %s" % self._rho_stats)
     time_intervals = gu.flatten_list([gu.apply_consecutive_elements(burst_list, lambda x, y: (y - x) * const.SCALE)
                                       for burst_list in self._rho_stats])
     #log.debug("[cs-buflo] Time intervals = %s", time_intervals)
     if len(time_intervals) == 0:
         return rho_star
     else:
         return math.pow(2, math.floor(math.log(mu.median(time_intervals), 2)))
Beispiel #4
0
 def estimate_rho(self, rho_star):
     """Estimate new value of rho based on past network performance."""
     #log.debug("[cs-buflo] rho stats: %s" % self._rho_stats)
     time_intervals = gu.flatten_list([
         gu.apply_consecutive_elements(burst_list, lambda x, y:
                                       (y - x) * const.SCALE)
         for burst_list in self._rho_stats
     ])
     #log.debug("[cs-buflo] Time intervals = %s", time_intervals)
     if len(time_intervals) == 0:
         return rho_star
     else:
         return math.pow(2,
                         math.floor(math.log(mu.median(time_intervals), 2)))
Beispiel #5
0
 def getBwDifferential(self):
     self.iat_length_tuples = [
         l for l in self.iat_length_tuples if len(l) > 0
     ]
     if time.time() - self.session.startTime > 0.2 and len(
             self.iat_length_tuples) > 1:
         lengths0 = [t[1] for t in self.iat_length_tuples[-2]]
         lengths1 = [t[1] for t in self.iat_length_tuples[-1]]
         bw0 = sum(lengths0) / self._period
         bw1 = sum(lengths1) / self._period
         bw_diff = (bw1 - bw0) / self._period
         self.session.bw_diffs.append(bw_diff)
         log.debug("[bwdiff %s] - bw diffs: %s", self.end,
                   self.session.bw_diffs)
         log.debug("[bwdiff %s] -  abs bwdiff (%s) > threshold (%s)",
                   self.end, abs(bw_diff), self._threshold)
         if abs(bw_diff) > self._threshold:
             # we should sample uniformly from the passed iats
             # convert self.iat_length_tuples to distribution
             # and pass it to wfpad iat distribution as dict.
             iats = gu.get_iats(
                 [t[0] for t in gu.flatten_list(self.iat_length_tuples)])
             h = {iat: 1 for iat in iats}
             self._burstHistoProbdist['snd'] = hs.new(h)
             self._gapHistoProbdist['snd'] = hs.new(h)
         else:
             self._burstHistoProbdist['snd'] = hs.uniform(const.INF_LABEL)
             self._gapHistoProbdist['snd'] = hs.uniform(const.INF_LABEL)
     self.iat_length_tuples.append([])
     log.debug("[bwdiff %s] A period has passed: %s", self.end,
               self.iat_length_tuples[-3:-1])
     if self.isVisiting():
         log.debug(
             "[bwdiff %s] Calling next period (visiting = %s, padding = %s)",
             self.end, self.isVisiting(), self.session.is_padding)
         cm.deferLater(self._period, self.getBwDifferential)
Beispiel #6
0
 def getAverageTs(self):
     avg_ts = mu.median(gu.get_iats([t[0] for t in gu.flatten_list(self.iat_length_tuples)]))
     log.debug("[bwdiff - %s] Average ts in the session is: %s.",
               self.end, avg_ts)
     return avg_ts