Esempio n. 1
0
    def _SetupPort(self, port, **kwargs):
        """Setup network constraints on port using the requested parameters.

    Args:
      port: The port number to setup network constraints on.
      **kwargs: Network constraints to set up on the port.

    Returns:
      True if setting the network constraints on the port was successful, false
      otherwise.
    """
        kwargs['port'] = port
        try:
            cherrypy.log('Setting up port %d' % port)
            traffic_control.CreateConstrainedPort(kwargs)
            return True
        except traffic_control.TrafficControlError as e:
            cherrypy.log('Error: %s\nOutput: %s' % (e.msg, e.error))
            return False
Esempio n. 2
0
 def testCreateConstrainedPortDefaults(self):
     config = {
         'interface': 'fakeeth',
         'port': 12345,
         'server_port': 8888,
         'latency': None
     }
     traffic_control.CreateConstrainedPort(config)
     expected = [
         'sudo tc qdisc add dev fakeeth root handle 1: htb',
         'sudo tc class add dev fakeeth parent 1: classid 1:3039 htb rate '
         '%dkbit ceil %dkbit' %
         (traffic_control._DEFAULT_MAX_BANDWIDTH_KBIT,
          traffic_control._DEFAULT_MAX_BANDWIDTH_KBIT),
         'sudo tc qdisc add dev fakeeth parent 1:3039 handle 3039:0 netem',
         'sudo tc filter add dev fakeeth protocol ip parent 1: prio 1 u32 '
         'match ip sport 12345 0xffff flowid 1:3039',
         'sudo iptables -t nat -A PREROUTING -i fakeeth -p tcp --dport 12345 -j '
         'REDIRECT --to-port 8888',
         'sudo iptables -t nat -A OUTPUT -p tcp --dport 12345 -j REDIRECT '
         '--to-port 8888'
     ]
     self.assertEqual(expected, self.commands)
Esempio n. 3
0
 def testCreateConstrainedPort(self):
     config = {
         'interface': 'fakeeth',
         'port': 12345,
         'server_port': 8888,
         'bandwidth': 256,
         'latency': 100,
         'loss': 2
     }
     traffic_control.CreateConstrainedPort(config)
     expected = [
         'sudo tc qdisc add dev fakeeth root handle 1: htb',
         'sudo tc class add dev fakeeth parent 1: classid 1:3039 htb rate '
         '256kbit ceil 256kbit',
         'sudo tc qdisc add dev fakeeth parent 1:3039 handle 3039:0 netem loss '
         '2% delay 100ms',
         'sudo tc filter add dev fakeeth protocol ip parent 1: prio 1 u32 match '
         'ip sport 12345 0xffff flowid 1:3039',
         'sudo iptables -t nat -A PREROUTING -i fakeeth -p tcp --dport 12345 -j '
         'REDIRECT --to-port 8888',
         'sudo iptables -t nat -A OUTPUT -p tcp --dport 12345 -j REDIRECT '
         '--to-port 8888'
     ]
     self.assertEqual(expected, self.commands)