コード例 #1
0
    def updatePerLinkProfile(self, iface, dstIpAddr, profile):
        self.log.debug('updatePerLinkProfile on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.updatePerLinkProfile(profile, dstIpAddr)
        return "OK"
コード例 #2
0
    def removePerLinkProfile(self, iface, dstIpAddr):
        self.log.debug('removePerLinkProfile on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.cleanPerLinkProfile(dstIpAddr)
        return "OK"
コード例 #3
0
    def removeProfile(self, iface):
        self.log.debug('removeProfile on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.clean()
        return "OK"
コード例 #4
0
    def setProfile(self, iface, profile):
        self.log.debug('set_profile on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.setProfile(profile)
        return "OK"
コード例 #5
0
    def installEgressScheduler(self, iface, scheduler):
        self.log.debug('installEgressScheduler on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.setEgressScheduler(scheduler)
        return "OK"
コード例 #6
0
    def setMarking(self, flowId, table="mangle", chain="POSTROUTING", markId=None):
        
        if not markId:
            tcMgr = TrafficControl()
            markId = tcMgr.generateMark()

        rule = iptc.Rule()

        if flowId.srcAddress:
            rule.src = flowId.srcAddress

        if flowId.dstAddress:
            rule.dst = flowId.dstAddress

        if flowId.prot:
            rule.protocol = flowId.prot
            match = iptc.Match(rule, flowId.prot)

            if flowId.srcPort:
                match.sport = flowId.srcPort

            if flowId.dstPort:
                match.dport = flowId.dstPort

            rule.add_match(match)

        target = iptc.Target(rule, "MARK")
        target.set_mark = str(markId)
        rule.target = target
        chain = iptc.Chain(iptc.Table(table), chain)
        chain.insert_rule(rule)
コード例 #7
0
    def setMarking(self,
                   flowId,
                   table="mangle",
                   chain="POSTROUTING",
                   markId=None):
        if not markId:
            tcMgr = TrafficControl()
            markId = tcMgr.generateMark()

        rule = iptc.Rule()

        if flowId.srcAddress:
            rule.src = flowId.srcAddress

        if flowId.dstAddress:
            rule.dst = flowId.dstAddress

        if flowId.prot:
            rule.protocol = flowId.prot
            match = iptc.Match(rule, flowId.prot)

            if flowId.srcPort:
                match.sport = flowId.srcPort

            if flowId.dstPort:
                match.dport = flowId.dstPort

            rule.add_match(match)

        target = iptc.Target(rule, "MARK")
        target.set_mark = str(markId)
        rule.target = target
        chain = iptc.Chain(iptc.Table(table), chain)
        chain.insert_rule(rule)
コード例 #8
0
    def updatePerLinkProfile(self, iface, dstIpAddr, profile):
        self.log.debug('updatePerLinkProfile on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.updatePerLinkProfile(profile, dstIpAddr)
        return "OK"
コード例 #9
0
    def installEgressScheduler(self, iface, scheduler):
        self.log.debug('installEgressScheduler on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.setEgressScheduler(scheduler)
        return "OK"
コード例 #10
0
    def removeProfile(self, iface):
        self.log.debug('removeProfile on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.clean()
        return "OK"
コード例 #11
0
    def removePerLinkProfile(self, iface, dstIpAddr):
        self.log.debug('removePerLinkProfile on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.cleanPerLinkProfile(dstIpAddr)
        return "OK"
コード例 #12
0
    def set_per_flow_tx_power(self, flowId, txPower):
        self.log.debug('set_per_flow_tx_power on iface: {}'.format(
            self.interface))

        tcMgr = TrafficControl()
        markId = tcMgr.generateMark()
        self.setMarking(flowId,
                        table="mangle",
                        chain="POSTROUTING",
                        markId=markId)

        cmd_str = ('sudo iw ' + self.interface + ' info')
        cmd_output = subprocess.check_output(cmd_str,
                                             shell=True,
                                             stderr=subprocess.STDOUT)

        for item in cmd_output.split("\n"):
            if "wiphy" in item:
                line = item.strip()

        phyId = [int(s) for s in line.split() if s.isdigit()][0]

        try:
            myfile = open(
                '/sys/kernel/debug/ieee80211/phy' + str(phyId) +
                '/ath9k/per_flow_tx_power', 'w')
            value = str(markId) + " " + str(txPower) + " 0"
            myfile.write(value)
            myfile.close()
            return "OK"
        except Exception as e:
            self.log.fatal("Operation not supported: %s" % e)
            raise exceptions.UPIFunctionExecutionFailedException(
                func_name='radio.set_per_flow_tx_power',
                err_msg='cannot open file')
コード例 #13
0
    def setProfile(self, iface, profile):
        self.log.debug('set_profile on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.setProfile(profile)
        return "OK"
コード例 #14
0
    def set_per_flow_tx_power(self, flowId, txPower):
        self.log.debug('set_per_flow_tx_power on iface: {}'.format(self.interface))

        tcMgr = TrafficControl()
        markId = tcMgr.generateMark()
        self.setMarking(flowId, table="mangle", chain="POSTROUTING", markId=markId)

        cmd_str = ('sudo iw ' + self.interface + ' info')
        cmd_output = subprocess.check_output(cmd_str, shell=True, stderr=subprocess.STDOUT)

        for item in cmd_output.split("\n"):
             if "wiphy" in item:
                line = item.strip()

        phyId = [int(s) for s in line.split() if s.isdigit()][0]

        try:
            myfile = open('/sys/kernel/debug/ieee80211/phy'+str(phyId)+'/ath9k/per_flow_tx_power', 'w')
            value = str(markId) + " " + str(txPower) + " 0"
            myfile.write(value)
            myfile.close()
            return "OK"
        except Exception as e:
            self.log.fatal("Operation not supported: %s" % e)
            raise exceptions.UPIFunctionExecutionFailedException(func_name='radio.set_per_flow_tx_power', err_msg='cannot open file')
コード例 #15
0
    def set_per_flow_tx_power(self, iface, flowId, txPower):
        self.log.debug('set_per_flow_tx_power on iface: {}'.format(iface))

        try:
            tcMgr = TrafficControl()
            markId = tcMgr.generateMark()
            self.setMarking(flowId,
                            table="mangle",
                            chain="POSTROUTING",
                            markId=markId)

            cmd_str = ('sudo iw ' + iface + ' info')
            cmd_output = subprocess.check_output(cmd_str,
                                                 shell=True,
                                                 stderr=subprocess.STDOUT)

            for item in cmd_output.split("\n"):
                if "wiphy" in item:
                    line = item.strip()

            phyId = [int(s) for s in line.split() if s.isdigit()][0]

            myfile = open(
                '/sys/kernel/debug/ieee80211/phy' + str(phyId) +
                '/ath9k/per_flow_tx_power', 'w')
            value = str(markId) + " " + str(txPower) + " 0"
            myfile.write(value)
            myfile.close()
            return True
        except Exception as e:
            self.log.fatal("Failed to set per flow tx power: %s" % str(e))
            raise exceptions.FunctionExecutionFailedException(
                func_name=inspect.currentframe().f_code.co_name,
                err_msg='Failed to set per flow tx power: ' + str(e))
コード例 #16
0
    def removeEgressScheduler(self, iface):
        self.log.debug('removeEgressScheduler on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.clean()
        tcMgr.cleanIpTables()
        return "OK"
コード例 #17
0
    def removeEgressScheduler(self, iface):
        self.log.debug('removeEgressScheduler on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.clean()
        tcMgr.cleanIpTables()
        return "OK"
コード例 #18
0
    def update_per_link_netem_profile(self, iface, dstIpAddr, profile):
        """
            Update per link network emulation parameters
        """
        self.log.debug('updatePerLinkProfile on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.updatePerLinkProfile(profile, dstIpAddr)
        return True
コード例 #19
0
    def install_egress_scheduler(self, iface, scheduler):
        """
            Traffic control: install egress scheduler
        """
        self.log.debug('installEgressScheduler on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.setEgressScheduler(scheduler)
        return True
コード例 #20
0
    def remove_per_link_netem_profile(self, iface, dstIpAddr):
        """
            Remove per link network emulation parameters
        """
        self.log.debug('removePerLinkProfile on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.cleanPerLinkProfile(dstIpAddr)
        return True
コード例 #21
0
    def remove_netem_profile(self, iface):
        """
            Removes the network emulation parameters
        """
        self.log.debug('removeProfile on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.clean()
        return True
コード例 #22
0
    def update_netem_profile(self, iface, profile):
        """
            Updates the network emulation parameters
        """
        self.log.debug('updateProfile on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.updateProfile(profile)
        return True
コード例 #23
0
    def remove_egress_scheduler(self, iface):
        """
            Traffic control: remove egress scheduler
        """
        self.log.debug('removeEgressScheduler on interface: {}'.format(iface))

        tcMgr = TrafficControl()
        intface = tcMgr.getInterface(iface)
        intface.clean()
        tcMgr.cleanIpTables()
        return True
コード例 #24
0
EU project WISHFUL
"""

if __name__ == "__main__":

    FORMAT = "%(asctime)-15s %(message)s"
    logging.basicConfig(format=FORMAT)
    log = logging.getLogger()
    log.setLevel(logging.DEBUG)
    log.warning("Test Traffic Control")

    operation = "del"
    if len(sys.argv) > 1:
        operation = str(sys.argv[1])

    tcMgr = TrafficControl()
    wlan0 = tcMgr.getInterface("wlan0")

    if operation == "add":
        prioSched = PrioScheduler(bandNum=4)

        pfifo1 = prioSched.addQueue(PfifoQueue(limit=50))
        bfifo2 = prioSched.addQueue(BfifoQueue(limit=20000))
        pfifo3 = prioSched.addQueue(SfqQueue(perturb=11))
        tbf4 = prioSched.addQueue(TbfQueue(rate=1000 * 1024, burst=1600, limit=10 * 1024))

        filter1 = Filter(name="BnControlTraffic")
        filter1.setFiveTuple(src=None, dst="192.168.1.178", prot="udp", srcPort=None, dstPort="5001")
        filter1.setTarget(pfifo1)
        filter1.setFilterPriority(1)
        filter1.setFlowId(5)
コード例 #25
0
ファイル: test_ipr.py プロジェクト: wishful-project/python-tc
from pyroute2 import IPRoute
from pyroute2.netlink.rtnl import TC_H_ROOT
from pyroute2.netlink.rtnl import RTM_DELQDISC
from pyroute2.netlink import NetlinkError
from pyroute2.netlink import NLM_F_REQUEST
from pyroute2.netlink import NLM_F_ACK
from pyroute2.netlink.rtnl import RTM_NEWQDISC

ETH_P_IP = 0x0800
PRIO = 1
HANDLE_MIN = 2
HANDLE_MAX = (2 ** 16) - 1

if __name__ == '__main__':
    ipr = IPRoute()
    tcMgr = TrafficControl()
    wlan0 = tcMgr.getInterface('wlan0')
    ifindex = wlan0.getIndex()
     
    operation = "del"
    if len(sys.argv) > 1:
        operation = str(sys.argv[1])

    if operation == "add":
        wlan0.clean()
        
        ipr.tc("add", "prio", ifindex, 0x10000, bands=5)
        ipr.tc("add", "pfifo", ifindex, 0x20000, parent=0x10001, limit=135)
        ipr.tc("add", "bfifo", ifindex, 0x30000, parent=0x10002, limit=150000)
        ipr.tc("add", "tbf",   ifindex, 0x40000, parent=0x10003, rate=10000, burst=20000, limit=1000)
コード例 #26
0
EU project WISHFUL
"""

if __name__ == '__main__':

    FORMAT = '%(asctime)-15s %(message)s'
    logging.basicConfig(format=FORMAT)
    log = logging.getLogger()
    log.setLevel(logging.DEBUG)
    log.warning('Test Traffic Control')

    operation = "del"
    if len(sys.argv) > 1:
        operation = str(sys.argv[1])

    tcMgr = TrafficControl()
    wlan0 = tcMgr.getInterface('wlan0')

    if operation == "add":
        prioSched = PrioScheduler(bandNum=4)

        pfifo1 = prioSched.addQueue(PfifoQueue(limit=50))
        bfifo2 = prioSched.addQueue(BfifoQueue(limit=20000))
        pfifo3 = prioSched.addQueue(SfqQueue(perturb=11))
        tbf4   = prioSched.addQueue(TbfQueue(rate=1000*1024, burst=1600, limit=10*1024))

        filter1 = Filter(name="BnControlTraffic");
        filter1.setFiveTuple(src=None, dst='192.168.1.178', prot='udp', srcPort=None, dstPort='5001')
        filter1.setTarget(pfifo1)
        filter1.setFilterPriority(1)
        filter1.setFlowId(5)
コード例 #27
0
ファイル: tc-test.py プロジェクト: wishful-project/python-tc
EU project WISHFUL
"""

if __name__ == '__main__':

    FORMAT = '%(asctime)-15s %(message)s'
    logging.basicConfig(format=FORMAT)
    log = logging.getLogger()
    log.setLevel(logging.DEBUG)
    log.warning('Test Traffic Control')

    operation = "del"
    if len(sys.argv) > 1:
        operation = str(sys.argv[1])

    tcMgr = TrafficControl()
    wlan0 = tcMgr.getInterface('wlan0')

    if operation == "add":
        prioSched = PrioScheduler(bandNum=4)

        pfifo1 = prioSched.addQueue(PfifoQueue(limit=50))
        bfifo2 = prioSched.addQueue(BfifoQueue(limit=20000))
        pfifo3 = prioSched.addQueue(SfqQueue(perturb=11))
        tbf4   = prioSched.addQueue(TbfQueue(rate=1000*1024, burst=1600, limit=10*1024))

        filter1 = Filter(name="BnControlTraffic");
        filter1.setFiveTuple(src=None, dst='192.168.1.178', prot='udp', srcPort=None, dstPort='5001')
        filter1.setTarget(pfifo1)
        filter1.setFilterPriority(1)
        filter1.setFlowId(5)