Пример #1
0
 def setUp(self):
     self.api = SciPass( logger = logging.getLogger(__name__),
                         config = str(os.getcwd()) + "/t/etc/SciPass_balancer_only.xml", 
                         readState = False)
     self.datapath = Mock(id=1)
     self.api.switchJoined(self.datapath)
     self.state = "/var/run/" + "%016x" % self.datapath.id +  "IUPUI" + ".json"
Пример #2
0
    def __init__(self, *args, **kwargs):
        super(Ryu, self).__init__(*args, **kwargs)
        #--- register for configuration options
        self.CONF.register_opts([
            cfg.StrOpt('SciPassConfig',
                       default='/etc/SciPass/SciPass.xml',
                       help='where to find the SciPass config file'),
        ])

        self.logger.error("Starting SciPass")
        self.datapaths = {}
        self.isactive = 1
        self.statsInterval = 5
        self.balanceInterval = 15
        self.bal = None
        self.stats = {}
        self.stats_thread = hub.spawn(self._stats_loop)
        self.balance_thread = hub.spawn(self._balance_loop)

        self.ports = defaultdict(dict)
        self.prefix_bytes = defaultdict(lambda: defaultdict(int))
        self.lastStatsTime = None
        self.flowmods = {}

        api = SciPass(logger=self.logger, config_file=self.CONF.SciPassConfig)

        api.registerForwardingStateChangeHandler(
            self.changeSwitchForwardingState)

        self.api = api

        wsgi = kwargs['wsgi']
        wsgi.register(SciPassRest, {'api': self.api})
Пример #3
0
    def __init__(self, *args, **kwargs):
        super(Ryu,self).__init__(*args,**kwargs)
        #--- register for configuration options
        self.CONF.register_opts([
                cfg.StrOpt('SciPassConfig',default='/etc/SciPass/SciPass.xml',
                           help='where to find the SciPass config file'),
                ])
        
        self.logger.error("Starting SciPass")
        self.datapaths = {}
        self.isactive = 1
        self.statsInterval = 5
        self.balanceInterval = 15
        self.bal = None
        self.stats = {}
        self.stats_thread = hub.spawn(self._stats_loop)
        self.balance_thread = hub.spawn(self._balance_loop)
        
        self.ports = defaultdict(dict);
        self.prefix_bytes = defaultdict(lambda: defaultdict(int))
        self.lastStatsTime = None
        self.flowmods = {}
        
        api = SciPass(logger = self.logger,
                      config_file = self.CONF.SciPassConfig )
        
        api.registerForwardingStateChangeHandler(self.changeSwitchForwardingState)

        self.api = api
        
        wsgi = kwargs['wsgi']
        wsgi.register(SciPassRest, {'api' : self.api})
Пример #4
0
 def test_state_restore(self):
     net1 = ipaddr.IPv4Network("192.168.0.0/24")
     group = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").getPrefixGroup(net1)
     res = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").splitSensorPrefix(group, net1, check=False)
     self.assertTrue(res == 1)
     net2 = ipaddr.IPv6Network("2001:0DB8::/48")
     group = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").getPrefixGroup(net2)
     res = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").splitSensorPrefix(group, net2, check=False)
     self.assertTrue(res == 1)
     self.api.switchLeave(self.datapath)
     time.sleep(3)
     self.api = SciPass(
         logger=logging.getLogger(__name__),
         config=str(os.getcwd()) + "/t/etc/SciPass_balancer_only.xml",
         readState=True,
     )
     self.api.switchJoined(self.datapath)
     prefixes = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").getPrefixes()
     prefixList = prefixes.keys()
     assert net1 not in prefixList
     assert net2 not in prefixList
     net = [ipaddr.IPv4Network("192.168.0.0/25"), ipaddr.IPv4Network("192.168.0.128/25")]
     assert (n in prefixList for n in net)
     net = [ipaddr.IPv6Network("2001:db8::/49"), ipaddr.IPv6Network("2001:db8:0:8000::/49")]
     assert (n in prefixList for n in net)
Пример #5
0
 def setUp(self):
     self.api = SciPass(
         logger=logging.getLogger(__name__),
         config=str(os.getcwd()) + "/t/etc/SciPass_balancer_only.xml",
         readState=False,
     )
     self.datapath = Mock(id=1)
     self.api.switchJoined(self.datapath)
     self.state = "/var/run/" + "%016x" % self.datapath.id + "IUPUI" + ".json"
Пример #6
0
 def test_state_restore(self):
     net1 = ipaddr.IPv4Network("192.168.0.0/24")
     group = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").getPrefixGroup(net1)
     res = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").splitSensorPrefix(group,net1,check=False)
     self.assertTrue(res == 1)
     net2 = ipaddr.IPv6Network("2001:0DB8::/48")
     group = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").getPrefixGroup(net2)
     res = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").splitSensorPrefix(group,net2,check=False)
     self.assertTrue(res == 1)
     self.api.switchLeave(self.datapath)
     time.sleep(3)
     self.api = SciPass( logger = logging.getLogger(__name__),
                         config = str(os.getcwd()) + "/t/etc/SciPass_balancer_only.xml",
                         readState = True)
     self.api.switchJoined(self.datapath)
     prefixes = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").getPrefixes()
     prefixList = prefixes.keys()
     assert(net1 not in prefixList)
     assert(net2 not in prefixList)
     net  = [ipaddr.IPv4Network('192.168.0.0/25'), ipaddr.IPv4Network('192.168.0.128/25')]
     assert(n in prefixList for n in net)
     net = [ipaddr.IPv6Network('2001:db8::/49'), ipaddr.IPv6Network('2001:db8:0:8000::/49')]
     assert(n in prefixList for n in net)
Пример #7
0
    def test_switch_init(self):
        api = SciPass(logger=logging.getLogger(__name__),
                      config=str(os.getcwd()) + "/t/etc/SciPass.xml")

        #first setup the handler to get all the flows that were sent
        flows = []

        def flowSent(dpid=None,
                     domain=None,
                     header=None,
                     actions=None,
                     command=None,
                     priority=None,
                     idle_timeout=None,
                     hard_timeout=None):
            obj = {
                'dpid': dpid,
                'header': header,
                'actions': actions,
                'command': command,
                'priority': priority,
                'idle_timeout': idle_timeout,
                'hard_timeout': hard_timeout
            }
            flows.append(obj)
            logging.error(obj)

        api.registerForwardingStateChangeHandler(flowSent)
        datapath = Mock(id=1)
        api.switchJoined(datapath)

        self.assertTrue(len(flows) == 25)
        #verify all of the 'flow details are set properly'
        for flow in flows:
            self.assertEquals(flow['dpid'], "%016x" % datapath.id)
            self.assertEquals(flow['hard_timeout'], 0)
            self.assertEquals(flow['idle_timeout'], 0)

        flow = flows[0]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {'phys_port': 1, 'dl_type': None})
        self.assertEquals(flow['priority'], 5)
        flow = flows[1]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 1}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 5,
            'nw_dst': ipaddr.IPv4Network('10.0.17.0/24')
        })
        self.assertEquals(flow['priority'], 10)
        flow = flows[2]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 1,
            'nw_src': ipaddr.IPv4Network('10.0.17.0/24')
        })
        self.assertEquals(flow['priority'], 10)
        flow = flows[3]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 1}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 5,
            'nw_dst': ipaddr.IPv4Network('10.0.18.0/24')
        })
        self.assertEquals(flow['priority'], 10)
        flow = flows[4]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 1,
            'nw_src': ipaddr.IPv4Network('10.0.18.0/24')
        })
        self.assertEquals(flow['priority'], 10)
        flow = flows[5]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {'phys_port': 2, 'dl_type': None})
        self.assertEquals(flow['priority'], 5)
        flow = flows[6]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 2}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 5,
            'nw_dst': ipaddr.IPv4Network('10.0.19.0/24')
        })
        self.assertEquals(flow['priority'], 10)
        flow = flows[7]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 2,
            'nw_src': ipaddr.IPv4Network('10.0.19.0/24')
        })
        self.assertEquals(flow['priority'], 10)
        flow = flows[8]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 2}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 5,
            'nw_dst': ipaddr.IPv4Network('10.0.20.0/24')
        })
        self.assertEquals(flow['priority'], 10)
        flow = flows[9]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 2,
            'nw_src': ipaddr.IPv4Network('10.0.20.0/24')
        })
        self.assertEquals(flow['priority'], 10)
        flow = flows[10]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 2}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 5,
            'nw_dst': ipaddr.IPv6Network('2001:0DB8::/48')
        })
        self.assertEquals(flow['priority'], 10)
        flow = flows[11]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 2,
            'nw_src': ipaddr.IPv6Network('2001:0DB8::/48')
        })
        self.assertEquals(flow['priority'], 10)
        flow = flows[12]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 1
        }, {
            'type': 'output',
            'port': 2
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {'phys_port': 5, 'dl_type': None})
        self.assertEquals(flow['priority'], 3)
        flow = flows[13]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 10}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {'phys_port': 6, 'dl_type': None})
        self.assertEquals(flow['priority'], 10)
        flow = flows[14]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 6}])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {'phys_port': 10, 'dl_type': None})
        self.assertEquals(flow['priority'], 10)
        flow = flows[15]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 27
        }, {
            'type': 'output',
            'port': 26
        }, {
            'type': 'output',
            'port': 5
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 1,
            'nw_src': ipaddr.IPv4Network('10.0.17.0/24')
        })
        self.assertEquals(flow['priority'], 500)
        flow = flows[16]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 27
        }, {
            'type': 'output',
            'port': 26
        }, {
            'type': 'output',
            'port': 6
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 10,
            'nw_dst': ipaddr.IPv4Network('10.0.17.0/24')
        })
        self.assertEquals(flow['priority'], 500)
        flow = flows[17]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 21
        }, {
            'type': 'output',
            'port': 20
        }, {
            'type': 'output',
            'port': 5
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 1,
            'nw_src': ipaddr.IPv4Network('10.0.18.0/24')
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[18]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 21
        }, {
            'type': 'output',
            'port': 20
        }, {
            'type': 'output',
            'port': 6
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 10,
            'nw_dst': ipaddr.IPv4Network('10.0.18.0/24')
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[19]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 25
        }, {
            'type': 'output',
            'port': 24
        }, {
            'type': 'output',
            'port': 5
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 2,
            'nw_src': ipaddr.IPv4Network('10.0.19.0/24')
        })
        self.assertEquals(flow['priority'], 700)
        flow = flows[20]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 25
        }, {
            'type': 'output',
            'port': 24
        }, {
            'type': 'output',
            'port': 6
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 10,
            'nw_dst': ipaddr.IPv4Network('10.0.19.0/24')
        })
        self.assertEquals(flow['priority'], 700)
        flow = flows[21]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 23
        }, {
            'type': 'output',
            'port': 22
        }, {
            'type': 'output',
            'port': 5
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 2,
            'nw_src': ipaddr.IPv4Network('10.0.20.0/24')
        })
        self.assertEquals(flow['priority'], 800)
        flow = flows[22]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 23
        }, {
            'type': 'output',
            'port': 22
        }, {
            'type': 'output',
            'port': 6
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 10,
            'nw_dst': ipaddr.IPv4Network('10.0.20.0/24')
        })
        self.assertEquals(flow['priority'], 800)
Пример #8
0
class TestFunctionality(unittest.TestCase):
    def setUp(self):
        self.api = SciPass(logger=logging.getLogger(__name__),
                           config=str(os.getcwd()) + "/t/etc/SciPass.xml")

    def test_update_prefix_bw(self):
        #first setup the handler to get all the flows that were sent
        flows = []

        def flowSent(dpid=None,
                     domain=None,
                     header=None,
                     actions=None,
                     command=None,
                     priority=None,
                     idle_timeout=None,
                     hard_timeout=None):
            flows.append({
                'dpid': dpid,
                'header': header,
                'actions': actions,
                'command': command,
                'priority': priority,
                'idle_timeout': idle_timeout,
                'hard_timeout': hard_timeout
            })

        self.api.registerForwardingStateChangeHandler(flowSent)
        datapath = Mock(id=1)
        self.api.switchJoined(datapath)

        self.assertEquals(len(flows), 25)
        self.api.updatePrefixBW("%016x" % datapath.id,
                                ipaddr.IPv4Network("10.0.19.0/24"), 500, 500)
        self.assertTrue(
            self.api.getBalancer("%016x" % datapath.id, "R&E").getPrefixBW(
                ipaddr.IPv4Network("10.0.19.0/24")), 1000)
        self.api.updatePrefixBW("%016x" % datapath.id,
                                ipaddr.IPv4Network("10.0.17.0/24"), 500, 500)
        self.assertTrue(
            self.api.getBalancer("%016x" % datapath.id, "R&E").getPrefixBW(
                ipaddr.IPv4Network("10.0.17.0/24")), 1000)
        self.api.updatePrefixBW("%016x" % datapath.id,
                                ipaddr.IPv6Network("2001:0DB8::/48"), 500, 500)
        self.assertTrue(
            self.api.getBalancer("%016x" % datapath.id, "R&E").getPrefixBW(
                ipaddr.IPv6Network("2001:0DB8::/48")), 1000)

    def test_good_flow(self):
        flows = []

        def flowSent(dpid=None,
                     domain=None,
                     header=None,
                     actions=None,
                     command=None,
                     priority=None,
                     idle_timeout=None,
                     hard_timeout=None):
            flows.append({
                'dpid': dpid,
                'header': header,
                'actions': actions,
                'command': command,
                'priority': priority,
                'idle_timeout': idle_timeout,
                'hard_timeout': hard_timeout
            })

        self.api.registerForwardingStateChangeHandler(flowSent)
        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        #self.logger.error("testing good flow")
        self.assertEquals(len(flows), 25)
        flows = []
        self.api.good_flow({
            "nw_src": "10.0.20.2/32",
            "nw_dst": "156.56.6.1/32",
            "tp_src": 1,
            "tp_dst": 2
        })
        self.assertEquals(len(flows), 2)
        flow = flows[0]
        self.assertEqual(int(flow['hard_timeout']), 0)
        self.assertEqual(int(flow['idle_timeout']), 90)
        self.assertEqual(flow['actions'], [{'type': 'output', 'port': '10'}])
        self.assertEqual(
            flow['header'], {
                'phys_port': 2,
                'nw_src': ipaddr.IPv4Network('10.0.20.2/32'),
                'tp_dst': 2,
                'tp_src': 1,
                'nw_dst': ipaddr.IPv4Network('156.56.6.1/32')
            })
        self.assertEqual(int(flow['priority']), 65535)
        self.assertEqual(flow['command'], "ADD")
        self.assertEqual(flow['dpid'], "%016x" % datapath.id)
        flow = flows[1]
        self.assertEqual(int(flow['hard_timeout']), 0)
        self.assertEqual(int(flow['idle_timeout']), 90)
        self.assertEqual(flow['actions'], [{'type': 'output', 'port': '2'}])
        self.assertEqual(
            flow['header'], {
                'phys_port': 10,
                'nw_dst': ipaddr.IPv4Network('10.0.20.2/32'),
                'tp_dst': 1,
                'tp_src': 2,
                'nw_src': ipaddr.IPv4Network('156.56.6.1/32')
            })
        self.assertEqual(int(flow['priority']), 65535)
        self.assertEqual(flow['command'], "ADD")
        self.assertEqual(flow['dpid'], "%016x" % datapath.id)

    def test_bad_flow(self):
        flows = []

        def flowSent(dpid=None,
                     domain=None,
                     header=None,
                     actions=None,
                     command=None,
                     priority=None,
                     idle_timeout=None,
                     hard_timeout=None):
            flows.append({
                'dpid': dpid,
                'header': header,
                'actions': actions,
                'command': command,
                'priority': priority,
                'idle_timeout': idle_timeout,
                'hard_timeout': hard_timeout
            })

        self.api.registerForwardingStateChangeHandler(flowSent)
        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        #self.logger.error("testing good flow")
        self.assertEquals(len(flows), 25)
        flows = []
        self.api.bad_flow({
            "nw_src": "10.0.20.2/32",
            "nw_dst": "156.56.6.1/32",
            "tp_src": 1,
            "tp_dst": 2
        })
        self.assertEquals(len(flows), 2)
        print flows[0]
        print flows[1]
        flow = flows[0]
        self.assertEqual(int(flow['hard_timeout']), 0)
        self.assertEqual(int(flow['idle_timeout']), 90)
        self.assertEqual(flow['actions'], [])
        self.assertEqual(
            flow['header'], {
                'phys_port': 2,
                'nw_src': ipaddr.IPv4Network('10.0.20.2/32'),
                'tp_dst': 2,
                'tp_src': 1,
                'nw_dst': ipaddr.IPv4Network('156.56.6.1/32')
            })
        self.assertEqual(int(flow['priority']), 65535)
        self.assertEqual(flow['command'], "ADD")
        self.assertEqual(flow['dpid'], "%016x" % datapath.id)
        flow = flows[1]
        self.assertEqual(int(flow['hard_timeout']), 0)
        self.assertEqual(int(flow['idle_timeout']), 90)
        self.assertEqual(flow['actions'], [])
        self.assertEqual(
            flow['header'], {
                'phys_port': 10,
                'nw_dst': ipaddr.IPv4Network('10.0.20.2/32'),
                'tp_dst': 1,
                'tp_src': 2,
                'nw_src': ipaddr.IPv4Network('156.56.6.1/32')
            })
        self.assertEqual(int(flow['priority']), 65535)
        self.assertEqual(flow['command'], "ADD")
        self.assertEqual(flow['dpid'], "%016x" % datapath.id)

    def test_block_unknown_prefix(self):
        pass

    def test_bypass_unknown_prefix(self):
        pass
Пример #9
0
class BalancerInitTest(unittest.TestCase):
    def setUp(self):
        self.api = SciPass(
            logger=logging.getLogger(__name__), config=str(os.getcwd()) + "/t/etc/SciPass_balancer_only.xml"
        )

    def test_bad_flow(self):
        # first setup the handler to get all the flows that were sent
        flows = []

        def flowSent(
            dpid=None,
            domain=None,
            header=None,
            actions=None,
            command=None,
            priority=None,
            idle_timeout=None,
            hard_timeout=None,
        ):
            obj = {
                "dpid": dpid,
                "header": header,
                "actions": actions,
                "command": command,
                "priority": priority,
                "idle_timeout": idle_timeout,
                "hard_timeout": hard_timeout,
            }
            flows.append(obj)
            logging.error(obj)

        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertTrue(len(flows) == 1132)
        flows = []

        self.api.bad_flow({"nw_src": "10.0.20.2/32", "nw_dst": "8.8.8.8/32", "tp_src": 1, "tp_dst": 2})
        self.assertEquals(len(flows), 2)
        print flows[0]
        print flows[1]
        flow = flows[0]
        self.assertEqual(int(flow["hard_timeout"]), 0)
        self.assertEqual(int(flow["idle_timeout"]), 90)
        self.assertEqual(flow["actions"], [])
        self.assertEqual(
            flow["header"],
            {
                "phys_port": 10,
                "nw_src": ipaddr.IPv4Network("10.0.20.2/32"),
                "tp_dst": 2,
                "tp_src": 1,
                "nw_dst": ipaddr.IPv4Network("8.8.8.8/32"),
            },
        )
        self.assertEqual(int(flow["priority"]), 65535)
        self.assertEqual(flow["command"], "ADD")
        self.assertEqual(flow["dpid"], "%016x" % datapath.id)
        flow = flows[1]
        self.assertEqual(int(flow["hard_timeout"]), 0)
        self.assertEqual(int(flow["idle_timeout"]), 90)
        self.assertEqual(flow["actions"], [])
        self.assertEqual(
            flow["header"],
            {
                "phys_port": 9,
                "nw_src": ipaddr.IPv4Network("10.0.20.2/32"),
                "tp_dst": 2,
                "tp_src": 1,
                "nw_dst": ipaddr.IPv4Network("8.8.8.8/32"),
            },
        )
        self.assertEqual(int(flow["priority"]), 65535)
        self.assertEqual(flow["command"], "ADD")
        self.assertEqual(flow["dpid"], "%016x" % datapath.id)

        flows = []
        self.api.bad_flow({"nw_dst": "10.0.20.2/32", "nw_src": "8.8.8.8/32", "tp_src": 2, "tp_dst": 1})
        self.assertEquals(len(flows), 2)
        print flows[0]
        print flows[1]
        flow = flows[0]
        self.assertEqual(int(flow["hard_timeout"]), 0)
        self.assertEqual(int(flow["idle_timeout"]), 90)
        self.assertEqual(flow["actions"], [])
        self.assertEqual(
            flow["header"],
            {
                "phys_port": 10,
                "nw_src": ipaddr.IPv4Network("10.0.20.2/32"),
                "tp_dst": 2,
                "tp_src": 1,
                "nw_dst": ipaddr.IPv4Network("8.8.8.8/32"),
            },
        )
        self.assertEqual(int(flow["priority"]), 65535)
        self.assertEqual(flow["command"], "ADD")
        self.assertEqual(flow["dpid"], "%016x" % datapath.id)
        flow = flows[1]
        self.assertEqual(int(flow["hard_timeout"]), 0)
        self.assertEqual(int(flow["idle_timeout"]), 90)
        self.assertEqual(flow["actions"], [])
        self.assertEqual(
            flow["header"],
            {
                "phys_port": 9,
                "nw_src": ipaddr.IPv4Network("10.0.20.2/32"),
                "tp_dst": 2,
                "tp_src": 1,
                "nw_dst": ipaddr.IPv4Network("8.8.8.8/32"),
            },
        )
        self.assertEqual(int(flow["priority"]), 65535)
        self.assertEqual(flow["command"], "ADD")
        self.assertEqual(flow["dpid"], "%016x" % datapath.id)

    def test_good_flow(self):
        # first setup the handler to get all the flows that were sent
        flows = []

        def flowSent(
            dpid=None,
            domain=None,
            header=None,
            actions=None,
            command=None,
            priority=None,
            idle_timeout=None,
            hard_timeout=None,
        ):
            obj = {
                "dpid": dpid,
                "header": header,
                "actions": actions,
                "command": command,
                "priority": priority,
                "idle_timeout": idle_timeout,
                "hard_timeout": hard_timeout,
            }
            flows.append(obj)
            logging.error(obj)

        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertTrue(len(flows) == 1132)
        flows = []

        self.api.good_flow({"nw_src": "10.0.20.2/32", "nw_dst": "8.8.8.8/32", "tp_src": 1, "tp_dst": 2})
        self.assertEquals(len(flows), 2)
        print flows[0]
        print flows[1]
        flow = flows[0]
        self.assertEqual(int(flow["hard_timeout"]), 0)
        self.assertEqual(int(flow["idle_timeout"]), 90)
        self.assertEqual(flow["actions"], [])
        self.assertEqual(
            flow["header"],
            {
                "phys_port": 10,
                "nw_src": ipaddr.IPv4Network("10.0.20.2/32"),
                "tp_dst": 2,
                "tp_src": 1,
                "nw_dst": ipaddr.IPv4Network("8.8.8.8/32"),
            },
        )
        self.assertEqual(int(flow["priority"]), 65535)
        self.assertEqual(flow["command"], "ADD")
        self.assertEqual(flow["dpid"], "%016x" % datapath.id)
        flow = flows[1]
        self.assertEqual(int(flow["hard_timeout"]), 0)
        self.assertEqual(int(flow["idle_timeout"]), 90)
        self.assertEqual(flow["actions"], [])
        self.assertEqual(
            flow["header"],
            {
                "phys_port": 9,
                "nw_src": ipaddr.IPv4Network("10.0.20.2/32"),
                "tp_dst": 2,
                "tp_src": 1,
                "nw_dst": ipaddr.IPv4Network("8.8.8.8/32"),
            },
        )
        self.assertEqual(int(flow["priority"]), 65535)
        self.assertEqual(flow["command"], "ADD")
        self.assertEqual(flow["dpid"], "%016x" % datapath.id)

        flows = []
        self.api.good_flow({"nw_dst": "10.0.20.2/32", "nw_src": "8.8.8.8/32", "tp_src": 2, "tp_dst": 1})
        self.assertEquals(len(flows), 2)
        print flows[0]
        print flows[1]
        flow = flows[0]
        self.assertEqual(int(flow["hard_timeout"]), 0)
        self.assertEqual(int(flow["idle_timeout"]), 90)
        self.assertEqual(flow["actions"], [])
        self.assertEqual(
            flow["header"],
            {
                "phys_port": 10,
                "nw_src": ipaddr.IPv4Network("10.0.20.2/32"),
                "tp_dst": 2,
                "tp_src": 1,
                "nw_dst": ipaddr.IPv4Network("8.8.8.8/32"),
            },
        )
        self.assertEqual(int(flow["priority"]), 65535)
        self.assertEqual(flow["command"], "ADD")
        self.assertEqual(flow["dpid"], "%016x" % datapath.id)
        flow = flows[1]
        self.assertEqual(int(flow["hard_timeout"]), 0)
        self.assertEqual(int(flow["idle_timeout"]), 90)
        self.assertEqual(flow["actions"], [])
        self.assertEqual(
            flow["header"],
            {
                "phys_port": 9,
                "nw_src": ipaddr.IPv4Network("10.0.20.2/32"),
                "tp_dst": 2,
                "tp_src": 1,
                "nw_dst": ipaddr.IPv4Network("8.8.8.8/32"),
            },
        )
        self.assertEqual(int(flow["priority"]), 65535)
        self.assertEqual(flow["command"], "ADD")
        self.assertEqual(flow["dpid"], "%016x" % datapath.id)

    def testInit(self):

        # first setup the handler to get all the flows that were sent
        flows = []

        def flowSent(
            dpid=None,
            domain=None,
            header=None,
            actions=None,
            command=None,
            priority=None,
            idle_timeout=None,
            hard_timeout=None,
        ):
            obj = {
                "dpid": dpid,
                "header": header,
                "actions": actions,
                "command": command,
                "priority": priority,
                "idle_timeout": idle_timeout,
                "hard_timeout": hard_timeout,
            }
            flows.append(obj)
            logging.error(obj)

        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertTrue(len(flows) == 1132)

        flow = flows[0]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 7}, {"type": "output", "port": 8}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 10, "nw_src": ipaddr.IPv4Network("10.0.0.0/16")})
        self.assertEquals(flow["priority"], 500)
        flow = flows[1]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 7}, {"type": "output", "port": 8}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 10, "nw_dst": ipaddr.IPv4Network("10.0.0.0/16")})
        self.assertEquals(flow["priority"], 500)
        flow = flows[2]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 7}, {"type": "output", "port": 8}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 9, "nw_src": ipaddr.IPv4Network("10.0.0.0/16")})
        self.assertEquals(flow["priority"], 500)
        flow = flows[3]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 7}, {"type": "output", "port": 8}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 9, "nw_dst": ipaddr.IPv4Network("10.0.0.0/16")})
        self.assertEquals(flow["priority"], 500)
        flow = flows[4]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 1}, {"type": "output", "port": 2}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 10, "nw_src": ipaddr.IPv4Network("10.1.0.0/16")})
        self.assertEquals(flow["priority"], 600)
        flow = flows[5]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 1}, {"type": "output", "port": 2}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 10, "nw_dst": ipaddr.IPv4Network("10.1.0.0/16")})
        self.assertEquals(flow["priority"], 600)
        flow = flows[6]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 1}, {"type": "output", "port": 2}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 9, "nw_src": ipaddr.IPv4Network("10.1.0.0/16")})
        self.assertEquals(flow["priority"], 600)
        flow = flows[7]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 1}, {"type": "output", "port": 2}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 9, "nw_dst": ipaddr.IPv4Network("10.1.0.0/16")})
        self.assertEquals(flow["priority"], 600)
        flow = flows[8]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 7}, {"type": "output", "port": 8}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 10, "nw_src": ipaddr.IPv4Network("10.2.0.0/16")})
        self.assertEquals(flow["priority"], 700)
        flow = flows[9]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 7}, {"type": "output", "port": 8}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 10, "nw_dst": ipaddr.IPv4Network("10.2.0.0/16")})
        self.assertEquals(flow["priority"], 700)
        flow = flows[10]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 7}, {"type": "output", "port": 8}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 9, "nw_src": ipaddr.IPv4Network("10.2.0.0/16")})
        self.assertEquals(flow["priority"], 700)
        flow = flows[11]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 7}, {"type": "output", "port": 8}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 9, "nw_dst": ipaddr.IPv4Network("10.2.0.0/16")})
        self.assertEquals(flow["priority"], 700)
        flow = flows[12]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 1}, {"type": "output", "port": 2}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 10, "nw_src": ipaddr.IPv4Network("10.3.0.0/16")})
        self.assertEquals(flow["priority"], 800)
        flow = flows[13]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 1}, {"type": "output", "port": 2}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 10, "nw_dst": ipaddr.IPv4Network("10.3.0.0/16")})
        self.assertEquals(flow["priority"], 800)
        flow = flows[14]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 1}, {"type": "output", "port": 2}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 9, "nw_src": ipaddr.IPv4Network("10.3.0.0/16")})
        self.assertEquals(flow["priority"], 800)
        flow = flows[15]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 1}, {"type": "output", "port": 2}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 9, "nw_dst": ipaddr.IPv4Network("10.3.0.0/16")})
        self.assertEquals(flow["priority"], 800)

    def testBalance(self):

        # first setup the handler to get all the flows that were sent
        flows = []

        def flowSent(
            dpid=None,
            domain=None,
            header=None,
            actions=None,
            command=None,
            priority=None,
            idle_timeout=None,
            hard_timeout=None,
        ):
            obj = {
                "dpid": dpid,
                "header": header,
                "actions": actions,
                "command": command,
                "priority": priority,
                "idle_timeout": idle_timeout,
                "hard_timeout": hard_timeout,
            }
            flows.append(obj)
            logging.error(obj)

        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertTrue(len(flows) == 1132)

        # reset the flows array to nothing
        flows = []
        self.api.run_balancers()
        # without network traffic there is nothing to balance!
        self.assertTrue(len(flows) == 0)

        self.api.updatePrefixBW("0000000000000001", ipaddr.IPv4Network("129.79.0.0/16"), 2000000000, 0)
        self.api.updatePrefixBW("0000000000000001", ipaddr.IPv4Network("134.68.0.0/16"), 8000000000, 0)
        self.api.updatePrefixBW("0000000000000001", ipaddr.IPv4Network("140.182.0.0/16"), 500000000, 0)
        self.api.updatePrefixBW("0000000000000001", ipaddr.IPv4Network("149.159.0.0/16"), 80000000, 0)
        self.api.run_balancers()

        self.assertEquals(len(flows), 560)

        flow = flows[0]
        self.assertEquals(flow["actions"], [])
        self.assertEquals(flow["command"], "DELETE_STRICT")
        self.assertEquals(flow["header"], {"phys_port": 10, "nw_src": ipaddr.IPv4Network("10.1.0.0/16")})
        self.assertEquals(flow["priority"], 600)
        flow = flows[1]
        self.assertEquals(flow["actions"], [])
        self.assertEquals(flow["command"], "DELETE_STRICT")
        self.assertEquals(flow["header"], {"phys_port": 10, "nw_dst": ipaddr.IPv4Network("10.1.0.0/16")})
        self.assertEquals(flow["priority"], 600)
        flow = flows[2]
        self.assertEquals(flow["actions"], [])
        self.assertEquals(flow["command"], "DELETE_STRICT")
        self.assertEquals(flow["header"], {"phys_port": 9, "nw_src": ipaddr.IPv4Network("10.1.0.0/16")})
        self.assertEquals(flow["priority"], 600)
        flow = flows[3]
        self.assertEquals(flow["actions"], [])
        self.assertEquals(flow["command"], "DELETE_STRICT")
        self.assertEquals(flow["header"], {"phys_port": 9, "nw_dst": ipaddr.IPv4Network("10.1.0.0/16")})
        self.assertEquals(flow["priority"], 600)
        flow = flows[4]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 4}, {"type": "output", "port": 3}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 10, "nw_src": ipaddr.IPv4Network("10.1.0.0/16")})
        self.assertEquals(flow["priority"], 600)
        flow = flows[5]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 4}, {"type": "output", "port": 3}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 10, "nw_dst": ipaddr.IPv4Network("10.1.0.0/16")})
        self.assertEquals(flow["priority"], 600)
        flow = flows[6]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 4}, {"type": "output", "port": 3}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 9, "nw_src": ipaddr.IPv4Network("10.1.0.0/16")})
        self.assertEquals(flow["priority"], 600)
        flow = flows[7]
        self.assertEquals(flow["actions"], [{"type": "output", "port": 4}, {"type": "output", "port": 3}])
        self.assertEquals(flow["command"], "ADD")
        self.assertEquals(flow["header"], {"phys_port": 9, "nw_dst": ipaddr.IPv4Network("10.1.0.0/16")})
        self.assertEquals(flow["priority"], 600)

        # we should be balanced after this!

        total_runs = 0
        # make our while condition true to enter :)
        flows.append({})
        while len(flows) != 0:
            flows = []
            self.api.run_balancers()
            total_runs += 1

        self.assertEquals(len(flows), 0)
Пример #10
0
class SimpleBalancerInitTest(unittest.TestCase):
    def setUp(self):
        self.api = SciPass( logger = logging.getLogger(__name__),
                          config = str(os.getcwd()) + "/t/etc/Simple_SciPass_balancer_only.xml" )
        
    def testInit(self):

        #first setup the handler to get all the flows that were sent
        flows = []
        def flowSent(dpid = None, domain=None, header = None, actions = None,command = None, priority = None, idle_timeout = None, hard_timeout = None):
            obj = {'dpid': dpid, 'header': header,
                   'actions': actions, 'command': command,
                   'priority': priority,
                   'idle_timeout': idle_timeout,
                   'hard_timeout': hard_timeout}
            flows.append(obj)
            logging.error(obj)


        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertEquals(len(flows), 566)

        flow = flows[0]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 7}, {'type': 'output', 'port': 8}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_src': 167772160, 'nw_src_mask': 16})
#        self.assertEquals(flow['priority'], 500)
#        flow = flows[1]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 7}, {'type': 'output', 'port': 8}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_dst_mask': 16, 'nw_dst': 167772160})
#        self.assertEquals(flow['priority'], 500)
#        flow = flows[2]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_src': 167837696, 'nw_src_mask': 16})
#        self.assertEquals(flow['priority'], 600)
#        flow = flows[3]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_dst_mask': 16, 'nw_dst': 167837696})
#        self.assertEquals(flow['priority'], 600)
#        flow = flows[4]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 7}, {'type': 'output', 'port': 8}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_src': 167903232, 'nw_src_mask': 16})
#        self.assertEquals(flow['priority'], 700)
#        flow = flows[5]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 7}, {'type': 'output', 'port': 8}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_dst_mask': 16, 'nw_dst': 167903232})
#        self.assertEquals(flow['priority'], 700)
#        flow = flows[6]
#        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_src': 167968768, 'nw_src_mask': 16})
#        self.assertEquals(flow['priority'], 800)
#        flow = flows[7]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_dst_mask': 16, 'nw_dst': 167968768})
#        self.assertEquals(flow['priority'], 800)


    def testSimpleBalance(self):

        #first setup the handler to get all the flows that were sent
        flows = []
        def flowSent(dpid = None,  domain=None, header = None, actions = None,command = None, priority = None, idle_timeout = None, hard_timeout = None):
            obj = {'dpid': dpid, 'header': header,
                   'actions': actions, 'command': command,
                   'priority': priority,
                   'idle_timeout': idle_timeout,
                   'hard_timeout': hard_timeout}
            flows.append(obj)
            logging.error(obj)


        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertTrue( len(flows) == 566)        

        #reset the flows array to nothing
        flows = []
        self.api.run_balancers()
        #without network traffic there is nothing to balance!
        self.assertTrue( len(flows) == 0)

        self.api.updatePrefixBW("0000000000000001", ipaddr.IPv4Network("129.79.0.0/16"), 2000000000, 0)
        self.api.updatePrefixBW("0000000000000001", ipaddr.IPv4Network("134.68.0.0/16"), 8000000000, 0)
        self.api.updatePrefixBW("0000000000000001", ipaddr.IPv4Network("140.182.0.0/16"), 500000000, 0)
        self.api.updatePrefixBW("0000000000000001", ipaddr.IPv4Network("149.159.0.0/16"), 80000000, 0)
        self.api.run_balancers()
        
#        self.assertEquals( len(flows), 10)
#        flow = flows[0]
#        self.assertEquals(flow['actions'],[])
#        self.assertEquals(flow['command'],"DELETE_STRICT")
#        self.assertEquals(flow['header'], {'nw_src': 167837696, 'nw_src_mask': 16})
#        self.assertEquals(flow['priority'], 600)
#        flow = flows[1]
#        self.assertEquals(flow['actions'],[])
#        self.assertEquals(flow['command'],"DELETE_STRICT")
#        self.assertEquals(flow['header'], {'nw_dst_mask': 16, 'nw_dst': 167837696})
#        self.assertEquals(flow['priority'], 600)
#        flow = flows[2]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 4}, {'type': 'output', 'port': 3}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_src': 167837696, 'nw_src_mask': 16})
#        self.assertEquals(flow['priority'], 600)
#        flow = flows[3]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 4}, {'type': 'output', 'port': 3}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_dst': 167837696, 'nw_dst_mask': 16})
#        self.assertEquals(flow['priority'], 600)
#        flow = flows[4]
#        self.assertEquals(flow['actions'],[])
#        self.assertEquals(flow['command'],"DELETE_STRICT")
#        self.assertEquals(flow['header'], {'nw_src': 2252603392, 'nw_src_mask': 16})
#        self.assertEquals(flow['priority'], 26200)
#        flow = flows[5]
#        self.assertEquals(flow['actions'],[])
#        self.assertEquals(flow['command'],"DELETE_STRICT")
#        self.assertEquals(flow['header'],  {'nw_dst_mask': 16, 'nw_dst': 2252603392})
#        self.assertEquals(flow['priority'], 26200)
#        flow = flows[6]
#        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_src': 2252603392, 'nw_src_mask': 17})
#        self.assertEquals(flow['priority'], 26200)
#        flow = flows[7]
#        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_dst_mask': 17, 'nw_dst': 2252603392})
#        self.assertEquals(flow['priority'], 26200)
#        flow = flows[8]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_src': 2252636160, 'nw_src_mask': 17})
#        self.assertEquals(flow['priority'], 26250)
#        flow = flows[9]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_dst_mask': 17, 'nw_dst': 2252636160})
#        self.assertEquals(flow['priority'], 26250)

        #run the balancer again!
        
        total_runs = 1
        while len(flows) != 0:
            flows = []
            self.api.run_balancers()
            total_runs +=1

        self.assertEquals(total_runs, 46)

        self.api.updatePrefixBW("0000000000000001", ipaddr.IPv4Network("134.68.80.0/20"), 8000000000, 0)

        total_runs = 0
        #make our while condition true to enter :)
        flows.append({})
        while len(flows) != 0:
            flows = []
            self.api.run_balancers()
            total_runs += 1

        self.assertEquals(total_runs, 25)
        
        self.api.updatePrefixBW("0000000000000001", ipaddr.IPv4Network("134.68.91.0/24"), 8000000000, 0)

        total_runs = 0
        #make our while condition true to enter :)
        flows.append({})
        while len(flows) != 0:
            flows = []
            self.api.run_balancers()
            total_runs += 1

        self.assertEquals(total_runs, 4)
Пример #11
0
 def setUp(self):
     self.api = SciPass( logger = logging.getLogger(__name__),
                       config = str(os.getcwd()) + "/t/etc/SciPass.xml" )
Пример #12
0
class TestStateChange(unittest.TestCase):
    
    def setUp(self):
        self.api = SciPass( logger = logging.getLogger(__name__),
                            config = str(os.getcwd()) + "/t/etc/SciPass_balancer_only.xml", 
                            readState = False)
        self.datapath = Mock(id=1)
        self.api.switchJoined(self.datapath)
        self.state = "/var/run/" + "%016x" % self.datapath.id +  "IUPUI" + ".json"

    def tearDown(self):
        os.remove(self.state)                                                                                                                  
        

    def test_initial_config(self):
        assert(os.path.isfile(self.state) == 1)
        with open(self.state) as data_file:
            data = json.load(data_file)
        data = data[0]
        switches = data["switch"].keys()
        assert(switches[0] == "%016x" % self.datapath.id)
        domain = data["switch"]["%016x" % self.datapath.id]["domain"].keys()
        assert(domain[0] == "IUPUI")
        mode = data["switch"]["%016x" % self.datapath.id]["domain"][domain[0]]["mode"].keys()
        assert(mode[0] == "Balancer")
                 
    def test_state_restore(self):
        net1 = ipaddr.IPv4Network("192.168.0.0/24")
        group = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").getPrefixGroup(net1)
        res = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").splitSensorPrefix(group,net1,check=False)
        self.assertTrue(res == 1)
        net2 = ipaddr.IPv6Network("2001:0DB8::/48")
        group = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").getPrefixGroup(net2)
        res = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").splitSensorPrefix(group,net2,check=False)
        self.assertTrue(res == 1)
        self.api.switchLeave(self.datapath)
        time.sleep(3)
        self.api = SciPass( logger = logging.getLogger(__name__),
                            config = str(os.getcwd()) + "/t/etc/SciPass_balancer_only.xml",
                            readState = True)
        self.api.switchJoined(self.datapath)
        prefixes = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").getPrefixes()
        prefixList = prefixes.keys()
        assert(net1 not in prefixList)
        assert(net2 not in prefixList)
        net  = [ipaddr.IPv4Network('192.168.0.0/25'), ipaddr.IPv4Network('192.168.0.128/25')]
        assert(n in prefixList for n in net)
        net = [ipaddr.IPv6Network('2001:db8::/49'), ipaddr.IPv6Network('2001:db8:0:8000::/49')]
        assert(n in prefixList for n in net)
Пример #13
0
class TestStateChange(unittest.TestCase):
    def setUp(self):
        self.api = SciPass(
            logger=logging.getLogger(__name__),
            config=str(os.getcwd()) + "/t/etc/SciPass_balancer_only.xml",
            readState=False,
        )
        self.datapath = Mock(id=1)
        self.api.switchJoined(self.datapath)
        self.state = "/var/run/" + "%016x" % self.datapath.id + "IUPUI" + ".json"

    def tearDown(self):
        os.remove(self.state)

    def test_initial_config(self):
        assert os.path.isfile(self.state) == 1
        with open(self.state) as data_file:
            data = json.load(data_file)
        data = data[0]
        switches = data["switch"].keys()
        assert switches[0] == "%016x" % self.datapath.id
        domain = data["switch"]["%016x" % self.datapath.id]["domain"].keys()
        assert domain[0] == "IUPUI"
        mode = data["switch"]["%016x" % self.datapath.id]["domain"][domain[0]]["mode"].keys()
        assert mode[0] == "Balancer"

    def test_state_restore(self):
        net1 = ipaddr.IPv4Network("192.168.0.0/24")
        group = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").getPrefixGroup(net1)
        res = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").splitSensorPrefix(group, net1, check=False)
        self.assertTrue(res == 1)
        net2 = ipaddr.IPv6Network("2001:0DB8::/48")
        group = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").getPrefixGroup(net2)
        res = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").splitSensorPrefix(group, net2, check=False)
        self.assertTrue(res == 1)
        self.api.switchLeave(self.datapath)
        time.sleep(3)
        self.api = SciPass(
            logger=logging.getLogger(__name__),
            config=str(os.getcwd()) + "/t/etc/SciPass_balancer_only.xml",
            readState=True,
        )
        self.api.switchJoined(self.datapath)
        prefixes = self.api.getBalancer("%016x" % self.datapath.id, "IUPUI").getPrefixes()
        prefixList = prefixes.keys()
        assert net1 not in prefixList
        assert net2 not in prefixList
        net = [ipaddr.IPv4Network("192.168.0.0/25"), ipaddr.IPv4Network("192.168.0.128/25")]
        assert (n in prefixList for n in net)
        net = [ipaddr.IPv6Network("2001:db8::/49"), ipaddr.IPv6Network("2001:db8:0:8000::/49")]
        assert (n in prefixList for n in net)
Пример #14
0
class InlineInitTest(unittest.TestCase):
    def setUp(self):
        self.api = SciPass( logger = logging.getLogger(__name__),
                          config = str(os.getcwd()) + "/t/etc/Inline.xml" )
        
    def testInit(self):

        #first setup the handler to get all the flows that were sent
        flows = []
        def flowSent(dpid = None, domain=None, header = None, actions = None,command = None, priority = None, idle_timeout = None, hard_timeout = None):
            obj = {'dpid': dpid, 'header': header,
                   'actions': actions, 'command': command,
                   'priority': priority,
                   'idle_timeout': idle_timeout,
                   'hard_timeout': hard_timeout}
            flows.append(obj)
            logging.error(obj)


        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertEquals(len(flows), 4114)

        flow = flows[0]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'dl_type': None, 'phys_port': 17})
        self.assertEquals(flow['priority'], 3)
        flow = flows[1]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 17}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'dl_type': None, 'phys_port': 25})
        self.assertEquals(flow['priority'], 3)
        flow = flows[2]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 17, 'nw_src': ipaddr.IPv4Network('0.0.0.0/8')})
        self.assertEquals(flow['priority'], 500)
        flow = flows[3]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], { 'phys_port': 25, 'nw_dst': ipaddr.IPv4Network('0.0.0.0/8')})
        self.assertEquals(flow['priority'], 500)
        flow = flows[4]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 18, 'nw_src':ipaddr.IPv4Network('0.0.0.0/8')})
        self.assertEquals(flow['priority'], 500)
        flow = flows[5]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 25, 'nw_dst': ipaddr.IPv4Network('0.0.0.0/8')})
        self.assertEquals(flow['priority'], 500)

        flow = flows[6]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'],{'phys_port': 19, 'nw_src':ipaddr.IPv4Network('0.0.0.0/8') })
        self.assertEquals(flow['priority'], 500)

        flow = flows[7]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 25, 'nw_dst': ipaddr.IPv4Network('0.0.0.0/8')})
        self.assertEquals(flow['priority'], 500)

        flow = flows[8]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 20, 'nw_src':ipaddr.IPv4Network('0.0.0.0/8')})
        self.assertEquals(flow['priority'], 500)
Пример #15
0
class BalancerInitTest(unittest.TestCase):
    def setUp(self):
        self.api = SciPass(logger=logging.getLogger(__name__),
                           config=str(os.getcwd()) +
                           "/t/etc/SciPass_balancer_only.xml")

    def test_bad_flow(self):
        #first setup the handler to get all the flows that were sent
        flows = []

        def flowSent(dpid=None,
                     header=None,
                     actions=None,
                     command=None,
                     priority=None,
                     idle_timeout=None,
                     hard_timeout=None):
            obj = {
                'dpid': dpid,
                'header': header,
                'actions': actions,
                'command': command,
                'priority': priority,
                'idle_timeout': idle_timeout,
                'hard_timeout': hard_timeout
            }
            flows.append(obj)
            logging.error(obj)

        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertTrue(len(flows) == 1132)
        flows = []

        self.api.bad_flow({
            "nw_src": "10.0.20.2/32",
            "nw_dst": "8.8.8.8/32",
            "tp_src": 1,
            "tp_dst": 2
        })
        self.assertEquals(len(flows), 2)
        print flows[0]
        print flows[1]
        flow = flows[0]
        self.assertEqual(int(flow['hard_timeout']), 0)
        self.assertEqual(int(flow['idle_timeout']), 90)
        self.assertEqual(flow['actions'], [])
        self.assertEqual(
            flow['header'], {
                'phys_port': 10,
                'nw_src_mask': 32,
                'nw_dst_mask': 32,
                'nw_src': 167777282,
                'tp_dst': 2,
                'tp_src': 1,
                'nw_dst': 134744072
            })
        self.assertEqual(int(flow['priority']), 65535)
        self.assertEqual(flow['command'], "ADD")
        self.assertEqual(flow['dpid'], "%016x" % datapath.id)
        flow = flows[1]
        self.assertEqual(int(flow['hard_timeout']), 0)
        self.assertEqual(int(flow['idle_timeout']), 90)
        self.assertEqual(flow['actions'], [])
        self.assertEqual(
            flow['header'], {
                'phys_port': 9,
                'nw_src_mask': 32,
                'nw_dst_mask': 32,
                'nw_src': 167777282,
                'tp_dst': 2,
                'tp_src': 1,
                'nw_dst': 134744072
            })
        self.assertEqual(int(flow['priority']), 65535)
        self.assertEqual(flow['command'], "ADD")
        self.assertEqual(flow['dpid'], "%016x" % datapath.id)

        flows = []
        self.api.bad_flow({
            "nw_dst": "10.0.20.2/32",
            "nw_src": "8.8.8.8/32",
            "tp_src": 2,
            "tp_dst": 1
        })
        self.assertEquals(len(flows), 2)
        print flows[0]
        print flows[1]
        flow = flows[0]
        self.assertEqual(int(flow['hard_timeout']), 0)
        self.assertEqual(int(flow['idle_timeout']), 90)
        self.assertEqual(flow['actions'], [])
        self.assertEqual(
            flow['header'], {
                'phys_port': 10,
                'nw_src_mask': 32,
                'nw_dst_mask': 32,
                'nw_src': 167777282,
                'tp_dst': 2,
                'tp_src': 1,
                'nw_dst': 134744072
            })
        self.assertEqual(int(flow['priority']), 65535)
        self.assertEqual(flow['command'], "ADD")
        self.assertEqual(flow['dpid'], "%016x" % datapath.id)
        flow = flows[1]
        self.assertEqual(int(flow['hard_timeout']), 0)
        self.assertEqual(int(flow['idle_timeout']), 90)
        self.assertEqual(flow['actions'], [])
        self.assertEqual(
            flow['header'], {
                'phys_port': 9,
                'nw_src_mask': 32,
                'nw_dst_mask': 32,
                'nw_src': 167777282,
                'tp_dst': 2,
                'tp_src': 1,
                'nw_dst': 134744072
            })
        self.assertEqual(int(flow['priority']), 65535)
        self.assertEqual(flow['command'], "ADD")
        self.assertEqual(flow['dpid'], "%016x" % datapath.id)

    def test_good_flow(self):
        #first setup the handler to get all the flows that were sent
        flows = []

        def flowSent(dpid=None,
                     header=None,
                     actions=None,
                     command=None,
                     priority=None,
                     idle_timeout=None,
                     hard_timeout=None):
            obj = {
                'dpid': dpid,
                'header': header,
                'actions': actions,
                'command': command,
                'priority': priority,
                'idle_timeout': idle_timeout,
                'hard_timeout': hard_timeout
            }
            flows.append(obj)
            logging.error(obj)

        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertTrue(len(flows) == 1132)
        flows = []

        self.api.good_flow({
            "nw_src": "10.0.20.2/32",
            "nw_dst": "8.8.8.8/32",
            "tp_src": 1,
            "tp_dst": 2
        })
        self.assertEquals(len(flows), 2)
        print flows[0]
        print flows[1]
        flow = flows[0]
        self.assertEqual(int(flow['hard_timeout']), 0)
        self.assertEqual(int(flow['idle_timeout']), 90)
        self.assertEqual(flow['actions'], [])
        self.assertEqual(
            flow['header'], {
                'phys_port': 10,
                'nw_src_mask': 32,
                'nw_dst_mask': 32,
                'nw_src': 167777282,
                'tp_dst': 2,
                'tp_src': 1,
                'nw_dst': 134744072
            })
        self.assertEqual(int(flow['priority']), 65535)
        self.assertEqual(flow['command'], "ADD")
        self.assertEqual(flow['dpid'], "%016x" % datapath.id)
        flow = flows[1]
        self.assertEqual(int(flow['hard_timeout']), 0)
        self.assertEqual(int(flow['idle_timeout']), 90)
        self.assertEqual(flow['actions'], [])
        self.assertEqual(
            flow['header'], {
                'phys_port': 9,
                'nw_src_mask': 32,
                'nw_dst_mask': 32,
                'nw_src': 167777282,
                'tp_dst': 2,
                'tp_src': 1,
                'nw_dst': 134744072
            })
        self.assertEqual(int(flow['priority']), 65535)
        self.assertEqual(flow['command'], "ADD")
        self.assertEqual(flow['dpid'], "%016x" % datapath.id)

        flows = []
        self.api.good_flow({
            "nw_dst": "10.0.20.2/32",
            "nw_src": "8.8.8.8/32",
            "tp_src": 2,
            "tp_dst": 1
        })
        self.assertEquals(len(flows), 2)
        print flows[0]
        print flows[1]
        flow = flows[0]
        self.assertEqual(int(flow['hard_timeout']), 0)
        self.assertEqual(int(flow['idle_timeout']), 90)
        self.assertEqual(flow['actions'], [])
        self.assertEqual(
            flow['header'], {
                'phys_port': 10,
                'nw_src_mask': 32,
                'nw_dst_mask': 32,
                'nw_src': 167777282,
                'tp_dst': 2,
                'tp_src': 1,
                'nw_dst': 134744072
            })
        self.assertEqual(int(flow['priority']), 65535)
        self.assertEqual(flow['command'], "ADD")
        self.assertEqual(flow['dpid'], "%016x" % datapath.id)
        flow = flows[1]
        self.assertEqual(int(flow['hard_timeout']), 0)
        self.assertEqual(int(flow['idle_timeout']), 90)
        self.assertEqual(flow['actions'], [])
        self.assertEqual(
            flow['header'], {
                'phys_port': 9,
                'nw_src_mask': 32,
                'nw_dst_mask': 32,
                'nw_src': 167777282,
                'tp_dst': 2,
                'tp_src': 1,
                'nw_dst': 134744072
            })
        self.assertEqual(int(flow['priority']), 65535)
        self.assertEqual(flow['command'], "ADD")
        self.assertEqual(flow['dpid'], "%016x" % datapath.id)

    def testInit(self):

        #first setup the handler to get all the flows that were sent
        flows = []

        def flowSent(dpid=None,
                     header=None,
                     actions=None,
                     command=None,
                     priority=None,
                     idle_timeout=None,
                     hard_timeout=None):
            obj = {
                'dpid': dpid,
                'header': header,
                'actions': actions,
                'command': command,
                'priority': priority,
                'idle_timeout': idle_timeout,
                'hard_timeout': hard_timeout
            }
            flows.append(obj)
            logging.error(obj)

        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertTrue(len(flows) == 1132)

        flow = flows[0]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 7
        }, {
            'type': 'output',
            'port': 8
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 10,
            'nw_src': 167772160,
            'nw_src_mask': 16
        })
        self.assertEquals(flow['priority'], 500)
        flow = flows[1]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 7
        }, {
            'type': 'output',
            'port': 8
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'nw_dst_mask': 16,
            'phys_port': 10,
            'nw_dst': 167772160
        })
        self.assertEquals(flow['priority'], 500)
        flow = flows[2]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 7
        }, {
            'type': 'output',
            'port': 8
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 9,
            'nw_src': 167772160,
            'nw_src_mask': 16
        })
        self.assertEquals(flow['priority'], 500)
        flow = flows[3]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 7
        }, {
            'type': 'output',
            'port': 8
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'nw_dst_mask': 16,
            'phys_port': 9,
            'nw_dst': 167772160
        })
        self.assertEquals(flow['priority'], 500)
        flow = flows[4]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 1
        }, {
            'type': 'output',
            'port': 2
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 10,
            'nw_src': 167837696,
            'nw_src_mask': 16
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[5]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 1
        }, {
            'type': 'output',
            'port': 2
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'nw_dst_mask': 16,
            'phys_port': 10,
            'nw_dst': 167837696
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[6]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 1
        }, {
            'type': 'output',
            'port': 2
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 9,
            'nw_src': 167837696,
            'nw_src_mask': 16
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[7]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 1
        }, {
            'type': 'output',
            'port': 2
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'nw_dst_mask': 16,
            'phys_port': 9,
            'nw_dst': 167837696
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[8]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 7
        }, {
            'type': 'output',
            'port': 8
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 10,
            'nw_src': 167903232,
            'nw_src_mask': 16
        })
        self.assertEquals(flow['priority'], 700)
        flow = flows[9]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 7
        }, {
            'type': 'output',
            'port': 8
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'nw_dst_mask': 16,
            'phys_port': 10,
            'nw_dst': 167903232
        })
        self.assertEquals(flow['priority'], 700)
        flow = flows[10]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 7
        }, {
            'type': 'output',
            'port': 8
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 9,
            'nw_src': 167903232,
            'nw_src_mask': 16
        })
        self.assertEquals(flow['priority'], 700)
        flow = flows[11]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 7
        }, {
            'type': 'output',
            'port': 8
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'nw_dst_mask': 16,
            'phys_port': 9,
            'nw_dst': 167903232
        })
        self.assertEquals(flow['priority'], 700)
        flow = flows[12]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 1
        }, {
            'type': 'output',
            'port': 2
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 10,
            'nw_src': 167968768,
            'nw_src_mask': 16
        })
        self.assertEquals(flow['priority'], 800)
        flow = flows[13]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 1
        }, {
            'type': 'output',
            'port': 2
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'nw_dst_mask': 16,
            'phys_port': 10,
            'nw_dst': 167968768
        })
        self.assertEquals(flow['priority'], 800)
        flow = flows[14]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 1
        }, {
            'type': 'output',
            'port': 2
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 9,
            'nw_src': 167968768,
            'nw_src_mask': 16
        })
        self.assertEquals(flow['priority'], 800)
        flow = flows[15]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 1
        }, {
            'type': 'output',
            'port': 2
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'nw_dst_mask': 16,
            'phys_port': 9,
            'nw_dst': 167968768
        })
        self.assertEquals(flow['priority'], 800)

    def testBalance(self):

        #first setup the handler to get all the flows that were sent
        flows = []

        def flowSent(dpid=None,
                     header=None,
                     actions=None,
                     command=None,
                     priority=None,
                     idle_timeout=None,
                     hard_timeout=None):
            obj = {
                'dpid': dpid,
                'header': header,
                'actions': actions,
                'command': command,
                'priority': priority,
                'idle_timeout': idle_timeout,
                'hard_timeout': hard_timeout
            }
            flows.append(obj)
            logging.error(obj)

        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertTrue(len(flows) == 1132)

        #reset the flows array to nothing
        flows = []
        self.api.run_balancers()
        #without network traffic there is nothing to balance!
        self.assertTrue(len(flows) == 0)

        self.api.updatePrefixBW("0000000000000001",
                                ipaddr.IPv4Network("129.79.0.0/16"),
                                2000000000, 0)
        self.api.updatePrefixBW("0000000000000001",
                                ipaddr.IPv4Network("134.68.0.0/16"),
                                8000000000, 0)
        self.api.updatePrefixBW("0000000000000001",
                                ipaddr.IPv4Network("140.182.0.0/16"),
                                500000000, 0)
        self.api.updatePrefixBW("0000000000000001",
                                ipaddr.IPv4Network("149.159.0.0/16"), 80000000,
                                0)
        self.api.run_balancers()

        self.assertEquals(len(flows), 560)

        flow = flows[0]
        self.assertEquals(flow['actions'], [])
        self.assertEquals(flow['command'], "DELETE_STRICT")
        self.assertEquals(flow['header'], {
            'phys_port': 10,
            'nw_src': 167837696,
            'nw_src_mask': 16
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[1]
        self.assertEquals(flow['actions'], [])
        self.assertEquals(flow['command'], "DELETE_STRICT")
        self.assertEquals(flow['header'], {
            'nw_dst_mask': 16,
            'phys_port': 10,
            'nw_dst': 167837696
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[2]
        self.assertEquals(flow['actions'], [])
        self.assertEquals(flow['command'], "DELETE_STRICT")
        self.assertEquals(flow['header'], {
            'phys_port': 9,
            'nw_src': 167837696,
            'nw_src_mask': 16
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[3]
        self.assertEquals(flow['actions'], [])
        self.assertEquals(flow['command'], "DELETE_STRICT")
        self.assertEquals(flow['header'], {
            'nw_dst_mask': 16,
            'phys_port': 9,
            'nw_dst': 167837696
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[4]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 4
        }, {
            'type': 'output',
            'port': 3
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 10,
            'nw_src': 167837696,
            'nw_src_mask': 16
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[5]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 4
        }, {
            'type': 'output',
            'port': 3
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'nw_dst_mask': 16,
            'phys_port': 10,
            'nw_dst': 167837696
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[6]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 4
        }, {
            'type': 'output',
            'port': 3
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'phys_port': 9,
            'nw_src': 167837696,
            'nw_src_mask': 16
        })
        self.assertEquals(flow['priority'], 600)
        flow = flows[7]
        self.assertEquals(flow['actions'], [{
            'type': 'output',
            'port': 4
        }, {
            'type': 'output',
            'port': 3
        }])
        self.assertEquals(flow['command'], "ADD")
        self.assertEquals(flow['header'], {
            'nw_dst_mask': 16,
            'phys_port': 9,
            'nw_dst': 167837696
        })
        self.assertEquals(flow['priority'], 600)

        #we should be balanced after this!

        total_runs = 0
        #make our while condition true to enter :)
        flows.append({})
        while len(flows) != 0:
            flows = []
            self.api.run_balancers()
            total_runs += 1

        self.assertEquals(len(flows), 0)
Пример #16
0
 def setUp(self):
     self.api = SciPass( logger = logging.getLogger(__name__),
                       config = str(os.getcwd()) + "/t/etc/Inline.xml" )
Пример #17
0
class SimpleBalancerInitTest(unittest.TestCase):
    def setUp(self):
        self.api = SciPass(logger=logging.getLogger(__name__),
                           config=str(os.getcwd()) +
                           "/t/etc/Simple_SciPass_balancer_only.xml")

    def testInit(self):

        #first setup the handler to get all the flows that were sent
        flows = []

        def flowSent(dpid=None,
                     header=None,
                     actions=None,
                     command=None,
                     priority=None,
                     idle_timeout=None,
                     hard_timeout=None):
            obj = {
                'dpid': dpid,
                'header': header,
                'actions': actions,
                'command': command,
                'priority': priority,
                'idle_timeout': idle_timeout,
                'hard_timeout': hard_timeout
            }
            flows.append(obj)
            logging.error(obj)

        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertEquals(len(flows), 566)

        flow = flows[0]


#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 7}, {'type': 'output', 'port': 8}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_src': 167772160, 'nw_src_mask': 16})
#        self.assertEquals(flow['priority'], 500)
#        flow = flows[1]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 7}, {'type': 'output', 'port': 8}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_dst_mask': 16, 'nw_dst': 167772160})
#        self.assertEquals(flow['priority'], 500)
#        flow = flows[2]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_src': 167837696, 'nw_src_mask': 16})
#        self.assertEquals(flow['priority'], 600)
#        flow = flows[3]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_dst_mask': 16, 'nw_dst': 167837696})
#        self.assertEquals(flow['priority'], 600)
#        flow = flows[4]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 7}, {'type': 'output', 'port': 8}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_src': 167903232, 'nw_src_mask': 16})
#        self.assertEquals(flow['priority'], 700)
#        flow = flows[5]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 7}, {'type': 'output', 'port': 8}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_dst_mask': 16, 'nw_dst': 167903232})
#        self.assertEquals(flow['priority'], 700)
#        flow = flows[6]
#        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_src': 167968768, 'nw_src_mask': 16})
#        self.assertEquals(flow['priority'], 800)
#        flow = flows[7]
#        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
#        self.assertEquals(flow['command'],"ADD")
#        self.assertEquals(flow['header'], {'nw_dst_mask': 16, 'nw_dst': 167968768})
#        self.assertEquals(flow['priority'], 800)

    def testSimpleBalance(self):

        #first setup the handler to get all the flows that were sent
        flows = []

        def flowSent(dpid=None,
                     header=None,
                     actions=None,
                     command=None,
                     priority=None,
                     idle_timeout=None,
                     hard_timeout=None):
            obj = {
                'dpid': dpid,
                'header': header,
                'actions': actions,
                'command': command,
                'priority': priority,
                'idle_timeout': idle_timeout,
                'hard_timeout': hard_timeout
            }
            flows.append(obj)
            logging.error(obj)

        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertTrue(len(flows) == 566)

        #reset the flows array to nothing
        flows = []
        self.api.run_balancers()
        #without network traffic there is nothing to balance!
        self.assertTrue(len(flows) == 0)

        self.api.updatePrefixBW("0000000000000001",
                                ipaddr.IPv4Network("129.79.0.0/16"),
                                2000000000, 0)
        self.api.updatePrefixBW("0000000000000001",
                                ipaddr.IPv4Network("134.68.0.0/16"),
                                8000000000, 0)
        self.api.updatePrefixBW("0000000000000001",
                                ipaddr.IPv4Network("140.182.0.0/16"),
                                500000000, 0)
        self.api.updatePrefixBW("0000000000000001",
                                ipaddr.IPv4Network("149.159.0.0/16"), 80000000,
                                0)
        self.api.run_balancers()

        #        self.assertEquals( len(flows), 10)
        #        flow = flows[0]
        #        self.assertEquals(flow['actions'],[])
        #        self.assertEquals(flow['command'],"DELETE_STRICT")
        #        self.assertEquals(flow['header'], {'nw_src': 167837696, 'nw_src_mask': 16})
        #        self.assertEquals(flow['priority'], 600)
        #        flow = flows[1]
        #        self.assertEquals(flow['actions'],[])
        #        self.assertEquals(flow['command'],"DELETE_STRICT")
        #        self.assertEquals(flow['header'], {'nw_dst_mask': 16, 'nw_dst': 167837696})
        #        self.assertEquals(flow['priority'], 600)
        #        flow = flows[2]
        #        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 4}, {'type': 'output', 'port': 3}])
        #        self.assertEquals(flow['command'],"ADD")
        #        self.assertEquals(flow['header'], {'nw_src': 167837696, 'nw_src_mask': 16})
        #        self.assertEquals(flow['priority'], 600)
        #        flow = flows[3]
        #        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 4}, {'type': 'output', 'port': 3}])
        #        self.assertEquals(flow['command'],"ADD")
        #        self.assertEquals(flow['header'], {'nw_dst': 167837696, 'nw_dst_mask': 16})
        #        self.assertEquals(flow['priority'], 600)
        #        flow = flows[4]
        #        self.assertEquals(flow['actions'],[])
        #        self.assertEquals(flow['command'],"DELETE_STRICT")
        #        self.assertEquals(flow['header'], {'nw_src': 2252603392, 'nw_src_mask': 16})
        #        self.assertEquals(flow['priority'], 26200)
        #        flow = flows[5]
        #        self.assertEquals(flow['actions'],[])
        #        self.assertEquals(flow['command'],"DELETE_STRICT")
        #        self.assertEquals(flow['header'],  {'nw_dst_mask': 16, 'nw_dst': 2252603392})
        #        self.assertEquals(flow['priority'], 26200)
        #        flow = flows[6]
        #        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
        #        self.assertEquals(flow['command'],"ADD")
        #        self.assertEquals(flow['header'], {'nw_src': 2252603392, 'nw_src_mask': 17})
        #        self.assertEquals(flow['priority'], 26200)
        #        flow = flows[7]
        #        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
        #        self.assertEquals(flow['command'],"ADD")
        #        self.assertEquals(flow['header'], {'nw_dst_mask': 17, 'nw_dst': 2252603392})
        #        self.assertEquals(flow['priority'], 26200)
        #        flow = flows[8]
        #        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
        #        self.assertEquals(flow['command'],"ADD")
        #        self.assertEquals(flow['header'], {'nw_src': 2252636160, 'nw_src_mask': 17})
        #        self.assertEquals(flow['priority'], 26250)
        #        flow = flows[9]
        #        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
        #        self.assertEquals(flow['command'],"ADD")
        #        self.assertEquals(flow['header'], {'nw_dst_mask': 17, 'nw_dst': 2252636160})
        #        self.assertEquals(flow['priority'], 26250)

        #run the balancer again!

        total_runs = 1
        while len(flows) != 0:
            flows = []
            self.api.run_balancers()
            total_runs += 1

        self.assertEquals(total_runs, 49)

        self.api.updatePrefixBW("0000000000000001",
                                ipaddr.IPv4Network("134.68.80.0/20"),
                                8000000000, 0)

        total_runs = 0
        #make our while condition true to enter :)
        flows.append({})
        while len(flows) != 0:
            flows = []
            self.api.run_balancers()
            total_runs += 1

        self.assertEquals(total_runs, 24)

        self.api.updatePrefixBW("0000000000000001",
                                ipaddr.IPv4Network("134.68.91.0/24"),
                                8000000000, 0)

        total_runs = 0
        #make our while condition true to enter :)
        flows.append({})
        while len(flows) != 0:
            flows = []
            self.api.run_balancers()
            total_runs += 1

        self.assertEquals(total_runs, 8)
Пример #18
0
class TestFunctionality(unittest.TestCase):
    def setUp(self):
        self.api = SciPass( logger = logging.getLogger(__name__),
                          config = str(os.getcwd()) + "/t/etc/SciPass.xml" )
        
    def test_update_prefix_bw(self):
        #first setup the handler to get all the flows that were sent
        flows = []
        def flowSent(dpid = None, header = None, actions = None,command = None, priority = None, idle_timeout = None, hard_timeout = None):
            flows.append({'dpid': dpid, 'header': header, 'actions': actions, 'command': command, 'priority': priority, 'idle_timeout': idle_timeout, 'hard_timeout': hard_timeout})

        self.api.registerForwardingStateChangeHandler(flowSent)
        datapath = Mock(id=1)
        self.api.switchJoined(datapath)

        self.assertEquals( len(flows), 25)
        self.api.updatePrefixBW("%016x" % datapath.id, ipaddr.IPv4Network("10.0.19.0/24"), 500,500)
        self.assertTrue(self.api.getBalancer("%016x" % datapath.id, "R&E").getPrefixBW(ipaddr.IPv4Network("10.0.19.0/24")), 1000)
        self.api.updatePrefixBW("%016x" % datapath.id, ipaddr.IPv4Network("10.0.17.0/24"), 500,500)
        self.assertTrue(self.api.getBalancer("%016x" % datapath.id, "R&E").getPrefixBW(ipaddr.IPv4Network("10.0.17.0/24")), 1000)
        

    def test_good_flow(self):
        flows = []
        def flowSent(dpid = None, header = None, actions = None,command = None, priority = None, idle_timeout = None, hard_timeout = None):
            flows.append({'dpid': dpid, 'header': header, 'actions': actions, 'command': command, 'priority': priority, 'idle_timeout': idle_timeout, 'hard_timeout': hard_timeout})

        self.api.registerForwardingStateChangeHandler(flowSent)
        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        #self.logger.error("testing good flow")
        self.assertEquals(len(flows),25)
        flows = []
        self.api.good_flow({"nw_src": "10.0.20.2/32", "nw_dst":"156.56.6.1/32", "tp_src":1, "tp_dst":2})
        self.assertEquals(len(flows),2)
        flow = flows[0]
        self.assertEqual(int(flow['hard_timeout']),0)
        self.assertEqual(int(flow['idle_timeout']),90)
        self.assertEqual(flow['actions'],[{'type': 'output', 'port': '10'}])
        self.assertEqual(flow['header'],{'phys_port': 2, 'nw_src_mask': 32, 'nw_dst_mask': 32, 'nw_src': 167777282, 'tp_dst': 2, 'tp_src': 1, 'nw_dst': 2620917249})
        self.assertEqual(int(flow['priority']),65535)
        self.assertEqual(flow['command'],"ADD")
        self.assertEqual(flow['dpid'],"%016x" % datapath.id)
        flow = flows[1]
        self.assertEqual(int(flow['hard_timeout']),0)
        self.assertEqual(int(flow['idle_timeout']),90)
        self.assertEqual(flow['actions'],[{'type': 'output', 'port': '2'}])
        self.assertEqual(flow['header'],{'phys_port': 10, 'nw_src_mask': 32, 'nw_dst_mask': 32, 'nw_dst': 167777282, 'tp_dst': 1, 'tp_src': 2, 'nw_src': 2620917249})
        self.assertEqual(int(flow['priority']),65535)
        self.assertEqual(flow['command'],"ADD")
        self.assertEqual(flow['dpid'],"%016x" % datapath.id)
        
        

    def test_bad_flow(self):
        flows = []
        def flowSent(dpid = None, header = None, actions = None,command = None, priority = None, idle_timeout = None, hard_timeout = None):
            flows.append({'dpid': dpid, 'header': header, 'actions': actions, 'command': command, 'priority': priority, 'idle_timeout': idle_timeout, 'hard_timeout': hard_timeout})

        self.api.registerForwardingStateChangeHandler(flowSent)
        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        #self.logger.error("testing good flow")
        self.assertEquals(len(flows),25)
        flows = []
        self.api.bad_flow({"nw_src": "10.0.20.2/32", "nw_dst":"156.56.6.1/32", "tp_src":1, "tp_dst":2})
        self.assertEquals(len(flows),2)
        print flows[0]
        print flows[1]
        flow = flows[0]
        self.assertEqual(int(flow['hard_timeout']),0)
        self.assertEqual(int(flow['idle_timeout']),90)
        self.assertEqual(flow['actions'],[])
        self.assertEqual(flow['header'],{'phys_port': 2, 'nw_src_mask': 32, 'nw_dst_mask': 32, 'nw_src': 167777282, 'tp_dst': 2, 'tp_src': 1, 'nw_dst': 2620917249})
        self.assertEqual(int(flow['priority']),65535)
        self.assertEqual(flow['command'],"ADD")
        self.assertEqual(flow['dpid'],"%016x" % datapath.id)
        flow = flows[1]
        self.assertEqual(int(flow['hard_timeout']),0)
        self.assertEqual(int(flow['idle_timeout']),90)
        self.assertEqual(flow['actions'],[])
        self.assertEqual(flow['header'],{'phys_port': 10, 'nw_src_mask': 32, 'nw_dst_mask': 32, 'nw_dst': 167777282, 'tp_dst': 1, 'tp_src': 2, 'nw_src': 2620917249})
        self.assertEqual(int(flow['priority']),65535)
        self.assertEqual(flow['command'],"ADD")
        self.assertEqual(flow['dpid'],"%016x" % datapath.id)

    def test_block_unknown_prefix(self):
        pass
    
    def test_bypass_unknown_prefix(self):
        pass       
Пример #19
0
 def setUp(self):
     self.api = SciPass(logger=logging.getLogger(__name__),
                        config=str(os.getcwd()) +
                        "/t/etc/Simple_SciPass_balancer_only.xml")
Пример #20
0
    def test_switch_init(self):
        api = SciPass( logger = logging.getLogger(__name__),
                          config = str(os.getcwd()) + "/t/etc/SciPass.xml" )

        #first setup the handler to get all the flows that were sent
        flows = []
        def flowSent(dpid = None, header = None, actions = None,command = None, priority = None, idle_timeout = None, hard_timeout = None):
            obj = {'dpid': dpid, 'header': header,
                   'actions': actions, 'command': command,
                   'priority': priority, 
                   'idle_timeout': idle_timeout,
                   'hard_timeout': hard_timeout}
            flows.append(obj)
            logging.error(obj)
            

        api.registerForwardingStateChangeHandler(flowSent)
        datapath = Mock(id=1)
        api.switchJoined(datapath)

        self.assertTrue( len(flows) == 25)
        #verify all of the 'flow details are set properly'
        for flow in flows:
            self.assertEquals(flow['dpid'], "%016x" % datapath.id)
            self.assertEquals(flow['hard_timeout'], 0)
            self.assertEquals(flow['idle_timeout'], 0)
        
        flow = flows[0]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 1, 'dl_type': None})
        self.assertEquals(flow['priority'], 5)
        flow = flows[1]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port':5, 'nw_dst': 167776512, 'nw_dst_mask': 24})
        self.assertEquals(flow['priority'], 10)
        flow = flows[2]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port':1, 'nw_src': 167776512, 'nw_src_mask': 24})
        self.assertEquals(flow['priority'], 10)
        flow = flows[3]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port':5, 'nw_dst': 167776768, 'nw_dst_mask': 24})
        self.assertEquals(flow['priority'], 10)
        flow = flows[4]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port':1, 'nw_src': 167776768, 'nw_src_mask': 24})
        self.assertEquals(flow['priority'], 10)
        flow = flows[5]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 2, 'dl_type': None})
        self.assertEquals(flow['priority'], 5)
        flow = flows[6]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 2}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port':5, 'nw_dst': 167777024, 'nw_dst_mask': 24})
        self.assertEquals(flow['priority'], 10)
        flow = flows[7]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port':2, 'nw_src': 167777024, 'nw_src_mask': 24})
        self.assertEquals(flow['priority'], 10)
        flow = flows[8]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 2}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port':5, 'nw_dst': 167777280, 'nw_dst_mask': 24})
        self.assertEquals(flow['priority'], 10)
        flow = flows[9]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port':2, 'nw_src': 167777280, 'nw_src_mask': 24})
        self.assertEquals(flow['priority'], 10)
        flow = flows[10]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 2}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'dl_type': 34525, 'phys_port': 5})
        self.assertEquals(flow['priority'], 10)
        flow = flows[11]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'dl_type': 34525, 'phys_port': 2})
        self.assertEquals(flow['priority'], 10)
        flow = flows[12]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 1}, {'type': 'output', 'port': 2}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 5, 'dl_type': None})
        self.assertEquals(flow['priority'], 3)
        flow = flows[13]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 10}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 6, 'dl_type': None})
        self.assertEquals(flow['priority'], 10)
        flow = flows[14]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 6}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 10, 'dl_type': None})
        self.assertEquals(flow['priority'], 10)
        flow = flows[15]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 27}, {'type': 'output', 'port': 26}, {'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 1, 'nw_src': 167776512, 'nw_src_mask': 24})
        self.assertEquals(flow['priority'], 500)
        flow = flows[16]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 27}, {'type': 'output', 'port': 26}, {'type': 'output', 'port': 6}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 10, 'nw_dst': 167776512, 'nw_dst_mask': 24})
        self.assertEquals(flow['priority'], 500)
        flow = flows[17]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 21}, {'type': 'output', 'port': 20}, {'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 1, 'nw_src': 167776768, 'nw_src_mask': 24})
        self.assertEquals(flow['priority'], 600)
        flow = flows[18]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 21}, {'type': 'output', 'port': 20}, {'type': 'output', 'port': 6}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'nw_dst_mask': 24, 'phys_port': 10, 'nw_dst': 167776768})
        self.assertEquals(flow['priority'], 600)
        flow = flows[19]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 25}, {'type': 'output', 'port': 24}, {'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 2, 'nw_src': 167777024, 'nw_src_mask': 24})
        self.assertEquals(flow['priority'], 700)
        flow = flows[20]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 25}, {'type': 'output', 'port': 24}, {'type': 'output', 'port': 6}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'],  {'nw_dst_mask': 24, 'phys_port': 10, 'nw_dst': 167777024})
        self.assertEquals(flow['priority'], 700)
        flow = flows[21]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 23}, {'type': 'output', 'port': 22}, {'type': 'output', 'port': 5}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 2, 'nw_src': 167777280, 'nw_src_mask': 24})
        self.assertEquals(flow['priority'], 800)
        flow = flows[22]
        self.assertEquals(flow['actions'], [{'type': 'output', 'port': 23}, {'type': 'output', 'port': 22}, {'type': 'output', 'port': 6}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'nw_dst_mask': 24, 'phys_port': 10, 'nw_dst': 167777280})
        self.assertEquals(flow['priority'], 800)
Пример #21
0
 def test_valid_config(self):
     api = SciPass(logger=logging.getLogger(__name__),
                   config=str(os.getcwd()) + "/t/etc/SciPass.xml")
     self.assertTrue(isinstance(api, SciPass))
Пример #22
0
 def setUp(self):
     self.api = SciPass( logger = logging.getLogger(__name__),
                       config = str(os.getcwd()) + "/t/etc/Simple_SciPass_balancer_only.xml" )
Пример #23
0
class InlineInitTest(unittest.TestCase):
    def setUp(self):
        self.api = SciPass( logger = logging.getLogger(__name__),
                          config = str(os.getcwd()) + "/t/etc/Inline.xml" )
        
    def testInit(self):

        #first setup the handler to get all the flows that were sent
        flows = []
        def flowSent(dpid = None, header = None, actions = None,command = None, priority = None, idle_timeout = None, hard_timeout = None):
            obj = {'dpid': dpid, 'header': header,
                   'actions': actions, 'command': command,
                   'priority': priority,
                   'idle_timeout': idle_timeout,
                   'hard_timeout': hard_timeout}
            flows.append(obj)
            logging.error(obj)


        self.api.registerForwardingStateChangeHandler(flowSent)

        datapath = Mock(id=1)
        self.api.switchJoined(datapath)
        self.assertEquals(len(flows), 4114)

        flow = flows[0]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'dl_type': None, 'phys_port': 17})
        self.assertEquals(flow['priority'], 3)
        flow = flows[1]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 17}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'dl_type': None, 'phys_port': 25})
        self.assertEquals(flow['priority'], 3)
        flow = flows[2]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 17, 'nw_src': 0, 'nw_src_mask': 8})
        self.assertEquals(flow['priority'], 500)
        flow = flows[3]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'nw_dst_mask': 8, 'phys_port': 25, 'nw_dst': 0})
        self.assertEquals(flow['priority'], 500)
        flow = flows[4]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 18, 'nw_src': 0, 'nw_src_mask': 8})
        self.assertEquals(flow['priority'], 500)
        flow = flows[5]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'nw_dst_mask': 8, 'phys_port': 25, 'nw_dst': 0})
        self.assertEquals(flow['priority'], 500)

        flow = flows[6]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'],{'phys_port': 19, 'nw_src': 0, 'nw_src_mask': 8})
        self.assertEquals(flow['priority'], 500)

        flow = flows[7]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'nw_dst_mask': 8, 'phys_port': 25, 'nw_dst': 0})
        self.assertEquals(flow['priority'], 500)

        flow = flows[8]
        self.assertEquals(flow['actions'],[{'type': 'output', 'port': 34}, {'type': 'output', 'port': 44}, {'type': 'output', 'port': 25}])
        self.assertEquals(flow['command'],"ADD")
        self.assertEquals(flow['header'], {'phys_port': 20, 'nw_src': 0, 'nw_src_mask': 8})
        self.assertEquals(flow['priority'], 500)