def testConfigureClassAdd(self): """Checks adding and deleting a class to the root qdisc.""" config = { 'interface': self._INTERFACE, 'port': 12345, 'server_port': 33333, 'bandwidth': 2000 } class_detail = ( 'class htb 1:%x root prio 0 rate %dKbit ceil %dKbit' % (config['port'], config['bandwidth'], config['bandwidth'])) # Add root qdisc. traffic_control._AddRootQdisc(config['interface']) # Assert class does not exist prior to adding it. command = ['tc', 'class', 'ls', 'dev', config['interface']] output = traffic_control._Exec(command) self.assertFalse(class_detail in output) # Add class to root. traffic_control._ConfigureClass('add', config) # Assert class is added. command = ['tc', 'class', 'ls', 'dev', config['interface']] output = traffic_control._Exec(command) self.assertTrue(class_detail in output) # Delete class. traffic_control._ConfigureClass('del', config) # Assert class is deleted. command = ['tc', 'class', 'ls', 'dev', config['interface']] output = traffic_control._Exec(command) self.assertFalse(class_detail in output)
def testAddDeleteFilter(self): config = { 'interface': self._INTERFACE, 'port': 12345, 'bandwidth': 2000 } # Assert no filter exists. command = [ 'tc', 'filter', 'list', 'dev', config['interface'], 'parent', '1:0' ] output = traffic_control._Exec(command) self.assertEqual(output, '') # Create the root and class to which the filter will be attached. # Add root qdisc. traffic_control._AddRootQdisc(config['interface']) # Add class to root. traffic_control._ConfigureClass('add', config) # Add the filter. traffic_control._AddFilter(config['interface'], config['port']) handle_id = traffic_control._GetFilterHandleId(config['interface'], config['port']) self.assertNotEqual(handle_id, None) # Delete the filter. # The output of tc filter list is not None because tc adds default filters. traffic_control._DeleteFilter(config['interface'], config['port']) self.assertRaises(traffic_control.TrafficControlError, traffic_control._GetFilterHandleId, config['interface'], config['port'])
def testConfigureClassAdd(self): """Checks adding and deleting a class to the root qdisc.""" config = { 'interface': self._INTERFACE, 'port': 12345, 'server_port': 33333, 'bandwidth': 2000 } class_detail = ('class htb 1:%x root prio 0 rate %dKbit ceil %dKbit' % (config['port'], config['bandwidth'], config['bandwidth'])) # Add root qdisc. traffic_control._AddRootQdisc(config['interface']) # Assert class does not exist prior to adding it. command = ['tc', 'class', 'ls', 'dev', config['interface']] output = traffic_control._Exec(command) self.assertFalse(class_detail in output) # Add class to root. traffic_control._ConfigureClass('add', config) # Assert class is added. command = ['tc', 'class', 'ls', 'dev', config['interface']] output = traffic_control._Exec(command) self.assertTrue(class_detail in output) # Delete class. traffic_control._ConfigureClass('del', config) # Assert class is deleted. command = ['tc', 'class', 'ls', 'dev', config['interface']] output = traffic_control._Exec(command) self.assertFalse(class_detail in output)
def testAddSubQdisc(self): """Checks adding a sub qdisc to existing class.""" config = { 'interface': self._INTERFACE, 'port': 12345, 'server_port': 33333, 'bandwidth': 2000, 'latency': 250, 'loss': 5 } qdisc_re_detail = ( 'qdisc netem %x: parent 1:%x .* delay %d.0ms loss %d%%' % (config['port'], config['port'], config['latency'], config['loss'])) # Add root qdisc. traffic_control._AddRootQdisc(config['interface']) # Add class to root. traffic_control._ConfigureClass('add', config) # Assert qdisc does not exist prior to adding it. command = ['tc', 'qdisc', 'ls', 'dev', config['interface']] output = traffic_control._Exec(command) handle_id_re = re.search(qdisc_re_detail, output) self.assertEqual(handle_id_re, None) # Add qdisc to class. traffic_control._AddSubQdisc(config) # Assert qdisc is added. command = ['tc', 'qdisc', 'ls', 'dev', config['interface']] output = traffic_control._Exec(command) handle_id_re = re.search(qdisc_re_detail, output) self.assertNotEqual(handle_id_re, None)
def testAddDeleteFilter(self): config = { 'interface': self._INTERFACE, 'port': 12345, 'bandwidth': 2000 } # Assert no filter exists. command = ['tc', 'filter', 'list', 'dev', config['interface'], 'parent', '1:0'] output = traffic_control._Exec(command) self.assertEqual(output, '') # Create the root and class to which the filter will be attached. # Add root qdisc. traffic_control._AddRootQdisc(config['interface']) # Add class to root. traffic_control._ConfigureClass('add', config) # Add the filter. traffic_control._AddFilter(config['interface'], config['port']) handle_id = traffic_control._GetFilterHandleId(config['interface'], config['port']) self.assertNotEqual(handle_id, None) # Delete the filter. # The output of tc filter list is not None because tc adds default filters. traffic_control._DeleteFilter(config['interface'], config['port']) self.assertRaises(traffic_control.TrafficControlError, traffic_control._GetFilterHandleId, config['interface'], config['port'])
def testAddSubQdisc(self): """Checks adding a sub qdisc to existing class.""" config = { 'interface': self._INTERFACE, 'port': 12345, 'server_port': 33333, 'bandwidth': 2000, 'latency': 250, 'loss': 5 } qdisc_re_detail = ('qdisc netem %x: parent 1:%x .* delay %d.0ms loss %d%%' % (config['port'], config['port'], config['latency'], config['loss'])) # Add root qdisc. traffic_control._AddRootQdisc(config['interface']) # Add class to root. traffic_control._ConfigureClass('add', config) # Assert qdisc does not exist prior to adding it. command = ['tc', 'qdisc', 'ls', 'dev', config['interface']] output = traffic_control._Exec(command) handle_id_re = re.search(qdisc_re_detail, output) self.assertEqual(handle_id_re, None) # Add qdisc to class. traffic_control._AddSubQdisc(config) # Assert qdisc is added. command = ['tc', 'qdisc', 'ls', 'dev', config['interface']] output = traffic_control._Exec(command) handle_id_re = re.search(qdisc_re_detail, output) self.assertNotEqual(handle_id_re, None)
def testConfigureClassAdd(self): """Checks adding and deleting a class to the root qdisc.""" config = {"interface": self._INTERFACE, "port": 12345, "server_port": 33333, "bandwidth": 2000} class_detail = "class htb 1:%x root prio 0 rate %dKbit ceil %dKbit" % ( config["port"], config["bandwidth"], config["bandwidth"], ) # Add root qdisc. traffic_control._AddRootQdisc(config["interface"]) # Assert class does not exist prior to adding it. command = ["tc", "class", "ls", "dev", config["interface"]] output = traffic_control._Exec(command) self.assertFalse(class_detail in output) # Add class to root. traffic_control._ConfigureClass("add", config) # Assert class is added. command = ["tc", "class", "ls", "dev", config["interface"]] output = traffic_control._Exec(command) self.assertTrue(class_detail in output) # Delete class. traffic_control._ConfigureClass("del", config) # Assert class is deleted. command = ["tc", "class", "ls", "dev", config["interface"]] output = traffic_control._Exec(command) self.assertFalse(class_detail in output)
def testAddDeleteFilter(self): config = {"interface": self._INTERFACE, "port": 12345, "bandwidth": 2000} # Assert no filter exists. command = ["tc", "filter", "list", "dev", config["interface"], "parent", "1:0"] output = traffic_control._Exec(command) self.assertEqual(output, "") # Create the root and class to which the filter will be attached. # Add root qdisc. traffic_control._AddRootQdisc(config["interface"]) # Add class to root. traffic_control._ConfigureClass("add", config) # Add the filter. traffic_control._AddFilter(config["interface"], config["port"]) handle_id = traffic_control._GetFilterHandleId(config["interface"], config["port"]) self.assertNotEqual(handle_id, None) # Delete the filter. # The output of tc filter list is not None because tc adds default filters. traffic_control._DeleteFilter(config["interface"], config["port"]) self.assertRaises( traffic_control.TrafficControlError, traffic_control._GetFilterHandleId, config["interface"], config["port"] )
def testAddRootQdisc(self): """Checks adding a root qdisc is successful.""" config = {'interface': self._INTERFACE} root_detail = 'qdisc htb 1: root' # Assert no htb root at startup. command = ['tc', 'qdisc', 'ls', 'dev', config['interface']] output = traffic_control._Exec(command) self.assertFalse(root_detail in output) traffic_control._AddRootQdisc(config['interface']) output = traffic_control._Exec(command) # Assert htb root is added. self.assertTrue(root_detail in output)
def testAddRootQdisc(self): """Checks adding a root qdisc is successful.""" config = {"interface": self._INTERFACE} root_detail = "qdisc htb 1: root" # Assert no htb root at startup. command = ["tc", "qdisc", "ls", "dev", config["interface"]] output = traffic_control._Exec(command) self.assertFalse(root_detail in output) traffic_control._AddRootQdisc(config["interface"]) output = traffic_control._Exec(command) # Assert htb root is added. self.assertTrue(root_detail in output)
def testAddSubQdisc(self): """Checks adding a sub qdisc to existing class.""" config = { "interface": self._INTERFACE, "port": 12345, "server_port": 33333, "bandwidth": 2000, "latency": 250, "loss": 5, } qdisc_re_detail = "qdisc netem %x: parent 1:%x .* delay %d.0ms loss %d%%" % ( config["port"], config["port"], config["latency"], config["loss"], ) # Add root qdisc. traffic_control._AddRootQdisc(config["interface"]) # Add class to root. traffic_control._ConfigureClass("add", config) # Assert qdisc does not exist prior to adding it. command = ["tc", "qdisc", "ls", "dev", config["interface"]] output = traffic_control._Exec(command) handle_id_re = re.search(qdisc_re_detail, output) self.assertEqual(handle_id_re, None) # Add qdisc to class. traffic_control._AddSubQdisc(config) # Assert qdisc is added. command = ["tc", "qdisc", "ls", "dev", config["interface"]] output = traffic_control._Exec(command) handle_id_re = re.search(qdisc_re_detail, output) self.assertNotEqual(handle_id_re, None)