Exemplo n.º 1
0
    def prepare_interfaces(self, cfg):
        """Configure interfaces up without IP addresses."""

        (pub_iface, pub_iface_name), (priv_iface, priv_iface_name) = helpers.get_ifaces(cfg)
        (pub_mtu, priv_mtu) = helpers.get_iface_mtus(cfg)

        self.set_rp_filter('all', False)

        if pub_iface is not None:
            self._prepare_interface(pub_iface_name, pub_mtu)
        if priv_iface is not None:
            self._prepare_interface(priv_iface_name, priv_mtu)
Exemplo n.º 2
0
    def prepare_interfaces(self, cfg):
        """Configure interfaces up without IP addresses."""

        (pub_iface,
         pub_iface_name), (priv_iface,
                           priv_iface_name) = helpers.get_ifaces(cfg)
        (pub_mtu, priv_mtu) = helpers.get_iface_mtus(cfg)

        self.set_rp_filter('all', False)

        if pub_iface is not None:
            self._prepare_interface(pub_iface_name, pub_mtu)
        if priv_iface is not None:
            self._prepare_interface(priv_iface_name, priv_mtu)
Exemplo n.º 3
0
    def up_qos_rules(self, cfg):
        """Configure and enable quality-of-service configuration."""

        #def _compute_burst(kbits, mtu):
        #    assumed_hz = 250
        #    burst = (float(kbits) / float(assumed_hz))  # example: 1024kbit/s, hz=250 => 4kbit
        #    return '%fkbit' % min(burst*2, (mtu*8.0/1000.0))

        _log.debug('up_qos_rules')

        (pub_iface,
         pub_iface_name), (priv_iface,
                           priv_iface_name) = helpers.get_ifaces(cfg)
        (_, proxyarp_interface) = helpers.get_proxyarp_iface(cfg)
        qos_cfg = helpers.get_qos_config(cfg)

        if qos_cfg.hasS(ns.globalUplinkRateLimit):
            pub_uplink = qos_cfg.getS(ns.globalUplinkRateLimit, rdf.Integer)
        else:
            pub_uplink = None

        # XXX: add to conf?
        pub_downlink = None
        priv_uplink = None
        priv_downlink = None
        pub_mtu, priv_mtu = helpers.get_iface_mtus(cfg)

        _log.debug('qos: %s, %s, %s, %s' %
                   (pub_uplink, pub_downlink, priv_uplink, priv_downlink))

        def_tx_limit = 100  # packets
        sfq_perturb = 30  # seconds
        sfq_quantum = None  # XXX: should we set this? defaults to iface mtu

        if pub_iface_name is not None:
            run_command([
                constants.CMD_TC, 'qdisc', 'del', 'dev', pub_iface_name, 'root'
            ])

        if priv_iface_name is not None:
            run_command([
                constants.CMD_TC, 'qdisc', 'del', 'dev', priv_iface_name,
                'root'
            ])

        if pub_iface_name is not None:
            if pub_uplink is None:
                # this leaves pfifo_fast in place
                pass
            else:
                pub_rate = '%skbit' % pub_uplink  # only uplink rate is relevant
                #pub_ceil = pub_rate
                #pub_burst = _compute_burst(pub_uplink, pub_mtu)
                run_command([
                    constants.CMD_TC, 'qdisc', 'add', 'dev', pub_iface_name,
                    'root', 'handle', '1:', 'htb', 'default', '1'
                ],
                            retval=runcommand.FAIL)
                run_command([
                    constants.CMD_TC, 'class', 'add', 'dev', pub_iface_name,
                    'parent', '1:', 'classid', '1:1', 'htb', 'rate', pub_rate,
                    'quantum',
                    str(pub_mtu)
                ],
                            retval=runcommand.FAIL)
                run_command([
                    constants.CMD_TC, 'qdisc', 'add', 'dev', pub_iface_name,
                    'parent', '1:1', 'handle', '10:', 'sfq', 'perturb',
                    str(sfq_perturb)
                ],
                            retval=runcommand.FAIL)

        if priv_iface_name is not None:
            if priv_uplink is None:
                # this leaves pfifo_fast in place
                pass
            else:
                priv_rate = '%skbps' % priv_uplink
                #priv_ceil = priv_rate
                #priv_burst = _compute_burst(priv_uplink, priv_mtu)
                run_command([
                    constants.CMD_TC, 'qdisc', 'add', 'dev', priv_iface_name,
                    'root', 'handle', '2:', 'htb', 'default', '1'
                ],
                            retval=runcommand.FAIL)
                run_command([
                    constants.CMD_TC, 'class', 'add', 'dev', priv_iface_name,
                    'parent', '2:', 'classid', '2:1', 'htb', 'rate', priv_rate,
                    'quantum',
                    str(priv_mtu)
                ],
                            retval=runcommand.FAIL)
                run_command([
                    constants.CMD_TC, 'qdisc', 'add', 'dev', priv_iface_name,
                    'parent', '2:1', 'handle', '20:', 'sfq', 'perturb',
                    str(sfq_perturb)
                ],
                            retval=runcommand.FAIL)

        if helpers.get_debug(cfg):
            run_command([constants.CMD_TC, '-d', 'qdisc', 'show'])
            run_command([constants.CMD_TC, '-d', 'class', 'show'])
Exemplo n.º 4
0
    def up_qos_rules(self, cfg):
        """Configure and enable quality-of-service configuration."""

        #def _compute_burst(kbits, mtu):
        #    assumed_hz = 250
        #    burst = (float(kbits) / float(assumed_hz))  # example: 1024kbit/s, hz=250 => 4kbit
        #    return '%fkbit' % min(burst*2, (mtu*8.0/1000.0))

        _log.debug('up_qos_rules')

        (pub_iface, pub_iface_name), (priv_iface, priv_iface_name) = helpers.get_ifaces(cfg)
        (_, proxyarp_interface) = helpers.get_proxyarp_iface(cfg)
        qos_cfg = helpers.get_qos_config(cfg)

        if qos_cfg.hasS(ns.globalUplinkRateLimit):
            pub_uplink = qos_cfg.getS(ns.globalUplinkRateLimit, rdf.Integer)
        else:
            pub_uplink = None

        # XXX: add to conf?
        pub_downlink = None
        priv_uplink = None
        priv_downlink = None
        pub_mtu, priv_mtu = helpers.get_iface_mtus(cfg)
        
        _log.debug('qos: %s, %s, %s, %s' % (pub_uplink, pub_downlink, priv_uplink, priv_downlink))

        def_tx_limit = 100  # packets
        sfq_perturb = 30    # seconds
        sfq_quantum = None  # XXX: should we set this? defaults to iface mtu

        if pub_iface_name is not None:
            run_command([constants.CMD_TC, 'qdisc', 'del', 'dev', pub_iface_name, 'root'])

        if priv_iface_name is not None:
            run_command([constants.CMD_TC, 'qdisc', 'del', 'dev', priv_iface_name, 'root'])

        if pub_iface_name is not None:
            if pub_uplink is None:
                # this leaves pfifo_fast in place
                pass
            else:
                pub_rate = '%skbit' % pub_uplink  # only uplink rate is relevant
                #pub_ceil = pub_rate
                #pub_burst = _compute_burst(pub_uplink, pub_mtu)
                run_command([constants.CMD_TC, 'qdisc', 'add', 'dev', pub_iface_name, 'root', 'handle', '1:', 'htb', 'default', '1'], retval=runcommand.FAIL)
                run_command([constants.CMD_TC, 'class', 'add', 'dev', pub_iface_name, 'parent', '1:', 'classid', '1:1', 'htb', 'rate', pub_rate, 'quantum', str(pub_mtu)], retval=runcommand.FAIL)
                run_command([constants.CMD_TC, 'qdisc', 'add', 'dev', pub_iface_name, 'parent', '1:1', 'handle', '10:', 'sfq', 'perturb', str(sfq_perturb)],retval=runcommand.FAIL)

        if priv_iface_name is not None:
            if priv_uplink is None:
                # this leaves pfifo_fast in place
                pass
            else:
                priv_rate = '%skbps' % priv_uplink
                #priv_ceil = priv_rate
                #priv_burst = _compute_burst(priv_uplink, priv_mtu)
                run_command([constants.CMD_TC, 'qdisc', 'add', 'dev', priv_iface_name, 'root', 'handle', '2:', 'htb', 'default', '1'], retval=runcommand.FAIL)
                run_command([constants.CMD_TC, 'class', 'add', 'dev', priv_iface_name, 'parent', '2:', 'classid', '2:1', 'htb', 'rate', priv_rate, 'quantum', str(priv_mtu)], retval=runcommand.FAIL)
                run_command([constants.CMD_TC, 'qdisc', 'add', 'dev', priv_iface_name, 'parent', '2:1', 'handle', '20:', 'sfq', 'perturb', str(sfq_perturb)],retval=runcommand.FAIL)

        if helpers.get_debug(cfg):
            run_command([constants.CMD_TC, '-d', 'qdisc', 'show'])
            run_command([constants.CMD_TC, '-d', 'class', 'show'])