def pathloadSend(cls): """ None -> None Client tests bandwidth with pathload and then adds callback to call itself """ shell = fi.throttle.shell.Shell() shell.add(os.path.join(fi.throttle.PATHLOAD_DIRECTORY, "pathload/pathload_snd -i"), callback=lambda data: cls.pathloadSend()) shell.execute()
def pathloadReceive(cls): """ None -> None Calls pathload binary to start measuring bandwidth """ shell = fi.throttle.shell.Shell() shell.add(os.path.join( fi.throttle.PATHLOAD_DIRECTORY, "pathload/pathload_rcv -s %s" % fi.throttle.PATHLOAD_CLIENT), callback=cls.onPathloadReceive) shell.execute()
def pathloadReceive(cls): """ None -> None Calls pathload binary to start measuring bandwidth """ shell = fi.throttle.shell.Shell() shell.add( os.path.join( fi.throttle.PATHLOAD_DIRECTORY, "pathload/pathload_rcv -s %s" % fi.throttle.PATHLOAD_CLIENT ), callback=cls.onPathloadReceive ) shell.execute()
def pathloadSend(cls): """ None -> None Client tests bandwidth with pathload and then adds callback to call itself """ shell = fi.throttle.shell.Shell() shell.add( os.path.join( fi.throttle.PATHLOAD_DIRECTORY, "pathload/pathload_snd -i" ), callback=lambda data: cls.pathloadSend() ) shell.execute()
def throttle(cls, allocations): """ allocations:[(str, int)] -> shell:fi.shell.Shell """ fi.logmsg(cls, "Making allocations") shell = fi.throttle.shell.Shell() interface = fi.throttle.VPN_INTERFACE toRun = ( # Drop current rules "/sbin/tc qdisc del dev %s root" % interface, "/sbin/iptables -t mangle -F", # Create queueing discipline on device root "/sbin/tc qdisc add dev %s root handle 1:0 htb" % interface, ) # Run above commands for command in toRun: shell.add(command) # Create node, filter, and /sbin/iptables mark rule for each client for i, (ip, allocation) in enumerate(allocations): bandwidth = float(allocation) * fi.throttle.BANDWIDTH_HEURISTIC # Create classes off of root qdisc shell.add("/sbin/tc class add dev %s parent 1: classid 1:%d htb rate %sbps prio %d" % ( interface, i + 1, bandwidth, i + 1 ) ) # Mark traffic shell.add("/sbin/iptables -t mangle -A POSTROUTING -d %s -j MARK --set-mark %d" % ( ip, i + 1 ) ) # Filter traffic shell.add("/sbin/tc filter add dev %s parent 1:0 protocol ip prio %d handle %d fw flowid 1:%d" % ( interface, i + 1, i + 1, i + 1 ) ) shell.execute()
def throttle(cls, allocations): """ allocations:[(str, int)] -> shell:fi.shell.Shell """ fi.logmsg(cls, "Making allocations") shell = fi.throttle.shell.Shell() interface = fi.throttle.VPN_INTERFACE toRun = ( # Drop current rules "/sbin/tc qdisc del dev %s root" % interface, "/sbin/iptables -t mangle -F", # Create queueing discipline on device root "/sbin/tc qdisc add dev %s root handle 1:0 htb" % interface, ) # Run above commands for command in toRun: shell.add(command) # Create node, filter, and /sbin/iptables mark rule for each client for i, (ip, allocation) in enumerate(allocations): bandwidth = float(allocation) * fi.throttle.BANDWIDTH_HEURISTIC # Create classes off of root qdisc shell.add( "/sbin/tc class add dev %s parent 1: classid 1:%d htb rate %sbps prio %d" % (interface, i + 1, bandwidth, i + 1)) # Mark traffic shell.add( "/sbin/iptables -t mangle -A POSTROUTING -d %s -j MARK --set-mark %d" % (ip, i + 1)) # Filter traffic shell.add( "/sbin/tc filter add dev %s parent 1:0 protocol ip prio %d handle %d fw flowid 1:%d" % (interface, i + 1, i + 1, i + 1)) shell.execute()