コード例 #1
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)
コード例 #2
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))
コード例 #3
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')
コード例 #4
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')
コード例 #5
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)