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 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'])
Exemplo n.º 3
0
    def testGetFilterHandleID(self):
        # Check seach for handle ID command.
        self.assertRaises(traffic_control.TrafficControlError,
                          traffic_control._GetFilterHandleId, 'fakeeth', 1)
        self.assertEquals(self.commands,
                          ['sudo tc filter list dev fakeeth parent '
                           '1:'])

        # Check with handle ID available.
        traffic_control._Exec = (
            lambda command, msg:
            'filter parent 1: protocol ip pref 1 u32 fh 800::800 order 2048 key ht '
            '800 bkt 0 flowid 1:1\nmatch 08ae0000/ffff0000 at 20')
        output = traffic_control._GetFilterHandleId('fakeeth', 1)
        self.assertEqual(output, '800::800')

        # Check with handle ID not available.
        traffic_control._Exec = (
            lambda command, msg:
            'filter parent 1: protocol ip pref 1 u32 fh 800::800 order 2048 key ht '
            '800 bkt 0 flowid 1:11\nmatch 08ae0000/ffff0000 at 20')
        self.assertRaises(traffic_control.TrafficControlError,
                          traffic_control._GetFilterHandleId, 'fakeeth', 1)

        traffic_control._Exec = lambda command, msg: 'NO ID IN HERE'
        self.assertRaises(traffic_control.TrafficControlError,
                          traffic_control._GetFilterHandleId, 'fakeeth', 1)
Exemplo n.º 4
0
    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 testGetFilterHandleID(self):
    # Check seach for handle ID command.
    self.assertRaises(traffic_control.TrafficControlError,
                      traffic_control._GetFilterHandleId, 'fakeeth', 1)
    self.assertEquals(self.commands, ['tc filter list dev fakeeth parent 1:'])

    # Check with handle ID available.
    traffic_control._Exec = (lambda command, msg:
      'filter parent 1: protocol ip'' pref 1 u32 fh 800::800 order 2048 key ht '
      '800 bkt 0 flowid 1:1')
    output = traffic_control._GetFilterHandleId('fakeeth', 1)
    self.assertEqual(output, '800::800')

    # Check with handle ID not available.
    traffic_control._Exec = lambda command, msg: 'NO ID IN HERE'
    self.assertRaises(traffic_control.TrafficControlError,
                      traffic_control._GetFilterHandleId, 'fakeeth', 1)
Exemplo n.º 6
0
    def testGetFilterHandleID(self):
        # Check seach for handle ID command.
        self.assertRaises(traffic_control.TrafficControlError, traffic_control._GetFilterHandleId, "fakeeth", 1)
        self.assertEquals(self.commands, ["sudo tc filter list dev fakeeth parent " "1:"])

        # Check with handle ID available.
        traffic_control._Exec = (
            lambda command, msg: "filter parent 1: protocol ip pref 1 u32 fh 800::800 order 2048 key ht "
            "800 bkt 0 flowid 1:1\nmatch 08ae0000/ffff0000 at 20"
        )
        output = traffic_control._GetFilterHandleId("fakeeth", 1)
        self.assertEqual(output, "800::800")

        # Check with handle ID not available.
        traffic_control._Exec = (
            lambda command, msg: "filter parent 1: protocol ip pref 1 u32 fh 800::800 order 2048 key ht "
            "800 bkt 0 flowid 1:11\nmatch 08ae0000/ffff0000 at 20"
        )
        self.assertRaises(traffic_control.TrafficControlError, traffic_control._GetFilterHandleId, "fakeeth", 1)

        traffic_control._Exec = lambda command, msg: "NO ID IN HERE"
        self.assertRaises(traffic_control.TrafficControlError, traffic_control._GetFilterHandleId, "fakeeth", 1)