Exemplo n.º 1
0
    def __init__(self, external_add_task, config, set_config,
                 get_remote_endpoints, get_rates):
        if debug:
            if config['bandwidth_management']:
                print "bandwidth management is up."
            else:
                print "!@#!@#!@#!@#!@# bandwidth management is down."

        self.external_add_task = external_add_task
        self.config = config
        self.set_config = set_config
        self.get_rates = get_rates
        if os.name == 'nt':
            icmp_impl = Win32Icmp()
        elif os.name == 'posix':
            icmp_impl = UnixIcmp(external_add_task, config['xicmp_port'])

        def got_new_rtt(rtt):
            print "got_new_rtt, rtt=", rtt
            self.external_add_task(0, self._inspect_rates, rtt)

        self.rttmonitor = RTTMonitor(got_new_rtt, icmp_impl)
        self.nodefeeder = NodeFeeder(add_task=external_add_task,
                                     get_remote_endpoints=get_remote_endpoints,
                                     rttmonitor=self.rttmonitor)

        self.start_time = bttime()

        if config['control_law'] == 'aimd':
            self.control_law = AIMDControlLaw(config['increase_delta'],
                                              config['decrease_factor'])
        elif config['control_law'] == 'aiad':
            self.control_law = AIADControlLaw(config['increase_delta'],
                                              config['decrease_delta'])

        # This configurability is temporary during testing/tuning.  --Dave
        if config['congestion_estimator'] == "chebyshev":
            self.congestion_estimator = ChebyshevCongestionEstimator(
                config['window_size'], config['drop_every_nth'],
                config['cheby_max_probability'],
                config['cheby_max_consecutive'], config['cheby_max_threshold'],
                config['ewma'])

        elif config['congestion_estimator'] == "variance":
            self.congestion_estimator = VarianceCongestionEstimator(
                config['window_size'])
        elif config['congestion_estimator'] == "vegasish":
            self.congestion_estimator = VegasishCongestionEstimator(
                config['window_size'], config['drop_every_nth'])
        else:
            raise BTFailure(
                _("Unrecognized congestion estimator '%s'.") %
                config['congestion_estimator'])

        self.starvation_prevention = FixedStarvationPrevention(
            config['min_upload_rate_limit'])

        if stats:
            rlimit_vs_time = \
                           os.path.join( stats_dir, "rlimit_vs_time.plotdata" )
            fp = open(rlimit_vs_time, "w")
            self.control_law = StreamTracer(self.control_law, fp)
            _copy_gnuplot("rlimit_vs_time.gnuplot")

            # samples are max(min_upload_rate_limit,rate).
            slimit_vs_time = \
                           os.path.join( stats_dir, "slimit_vs_time.plotdata" )
            fp = open(slimit_vs_time, "w")
            self.starvation_prevention = StreamTracer(
                self.starvation_prevention, fp)

            delay_vs_time = os.path.join(stats_dir, "delay_vs_time.plotdata")
            self.dfp = open(delay_vs_time, "w")
            _copy_gnuplot("delay_vs_time.gnuplot")
Exemplo n.º 2
0
    def __init__(self, external_add_task, config, set_option,
                 get_remote_endpoints, get_rates):
        if debug:
            if config['bandwidth_management']:
                print "bandwidth management is up."
            else:
                print "!@#!@#!@#!@#!@# bandwidth management is down."
        self.external_add_task = external_add_task
        self.config = config
        self.set_option = set_option
        self.get_rates = get_rates

        # Next few lines were added by David Harrison to use RTTMonitor2
        #if os.name == 'nt':
        #    icmp_impl = Win32Icmp()
        #elif os.name == 'posix':
        #    icmp_impl = UnixIcmp(external_add_task, config['xicmp_port'])
        def got_new_rtt(rtt):
            self.external_add_task(0, self._inspect_rates, rtt)

        #self.rttmonitor = RTTMonitor(got_new_rtt, icmp_impl)
        self.rttmonitor = RTTMonitor(got_new_rtt)
        self.nodefeeder = NodeFeeder(external_add_task=external_add_task,
                                     get_remote_endpoints=get_remote_endpoints,
                                     rttmonitor=self.rttmonitor)

        self.start_time = None

        self.max_samples = 10  # hmm...
        self.u = SizedList(self.max_samples)
        self.d = SizedList(self.max_samples)
        self.t = SizedList(self.max_samples * 2)
        self.ur = SizedList(self.max_samples)
        self.dr = SizedList(self.max_samples)

        self.current_std = 0.001
        self.max_std = 0.001
        self.last_max = bttime()

        self.max_rates = {}
        self.max_rates["upload"] = 1.0
        self.max_rates["download"] = 1.0
        self.max_p = 1.0
        self.min_p = 2**500
        self.mid_p = ((self.max_p - self.min_p) / 2.0) + self.min_p
        self.old_p = None

        # I pulled these numbers out of my ass.

        if stats:
            tmp_dir = platform.get_temp_dir()
            timestr = "%d_%d_%d_%d_%d" % time.localtime()[1:6]
            stats_dir = os.path.join(
                tmp_dir, "bittorrent%s_%d" % (timestr, os.getpid()))
            os.mkdir(stats_dir)
            if debug: print "BandwidthManager: stats_dir = %s" % stats_dir
            rate_vs_time = os.path.join(stats_dir, "rate_vs_time.plotdata")
            self.rfp = open(rate_vs_time, "w")
            delay_vs_time = os.path.join(stats_dir, "delay_vs_time.plotdata")
            self.dfp = open(delay_vs_time, "w")
            sdev_vs_time = os.path.join(stats_dir, "stddev_vs_time.plotdata")
            self.sdevfp = open(sdev_vs_time, "w")