class ShaperMixin(object): def setUp(self): self.shaper_conf = { (self.server_addr[0],) : {'upload': 256, 'download': 1024, 'delay': 5}, (self.client_addr[0],) : {'upload': 128, 'download': 512, 'delay': 30}, } self.sh = Shaper() self.sh.set_shaping(self.shaper_conf) def tearDown(self): self.sh.teardown_all() def estimate_transfer_time(self, filesize, a, b): """ Determines how long the transfer of filesize bytes from A to B should take. units for filesize are bytes, a and b are IP addresses """ up = self.shaper_conf[(a,)]['upload'] down = self.shaper_conf[(b,)]['download'] return eta(filesize, up, down) def estimate_delay(self, a, b): da = self.shaper_conf[(a,)]['delay'] db = self.shaper_conf[(b,)]['delay'] return da+db
class ShaperMixin(object): def setUp(self): self.shaper_conf = { (self.server_addr[0], ): { 'upload': 256, 'download': 1024, 'delay': 5 }, (self.client_addr[0], ): { 'upload': 128, 'download': 512, 'delay': 30 }, } self.sh = Shaper() self.sh.set_shaping(self.shaper_conf) def tearDown(self): self.sh.teardown_all() def estimate_transfer_time(self, filesize, a, b): """ Determines how long the transfer of filesize bytes from A to B should take. units for filesize are bytes, a and b are IP addresses """ up = self.shaper_conf[(a, )]['upload'] down = self.shaper_conf[(b, )]['download'] return eta(filesize, up, down) def estimate_delay(self, a, b): da = self.shaper_conf[(a, )]['delay'] db = self.shaper_conf[(b, )]['delay'] return da + db
'jitter': 5 }, ("127.0.0.3", ): { 'upload': 256, 'download': 512, 'delay': 20 }, ("127.0.0.4", ): { 'upload': 256, 'download': 512, 'delay': 20 }, } sh = Shaper() sh.set_shaping(ps) #print sh.ip_handles #sh.teardown_all() #up, down = sh.get_traffic("127.0.0.2") #print up, down # Please be aware that second call to set_shaping with the same IP will not change the settings # How to generate large range of IP adresses: #ps = {tuple([ "127.0.0.%d" % x for x in range(1,250) ]) : {'upload': 256, 'download': 1024, 'delay': 25}, # } # # sh.set_shaping(ps)
import logging logging.basicConfig(level=logging.INFO, datefmt='%H:%M:%S', format='%(asctime)s %(name)s %(levelname)s: %(message)s') from shapy import register_settings register_settings('settings') from shapy.emulation.shaper import Shaper if __name__ == '__main__': ps = {("127.0.0.2",) : {'upload': 1024, 'download': 1024, 'delay': 5, 'jitter': 5}, ("127.0.0.3",) : {'upload': 256, 'download': 512, 'delay': 20}, ("127.0.0.4",) : {'upload': 256, 'download': 512, 'delay': 20}, } sh = Shaper() sh.set_shaping(ps) #print sh.ip_handles #sh.teardown_all() #up, down = sh.get_traffic("127.0.0.2") #print up, down # Please be aware that second call to set_shaping with the same IP will not change the settings # How to generate large range of IP adresses: #ps = {tuple([ "127.0.0.%d" % x for x in range(1,250) ]) : {'upload': 256, 'download': 1024, 'delay': 25}, # } #