Example #1
0
File: gapi.py Project: cargious/ocf
    def test_CreateDeleteSliver(self):
        """
        Tests that we can create a sliver.
        """
        from expedient.clearinghouse.slice.models import Slice
        from openflow.dummyom.models import DummyOMSlice

        # get the resources
        slice_urn, cred = self.create_ch_slice()
        options = dict(geni_compressed=False, geni_available=True)
        rspec = wrap_xmlrpc_call(self.am_client.ListResources, [cred, options],
                                 {}, settings.TIMEOUT)

        # Create switches and links
        self.switches, self.links = parse_rspec(rspec)

        # create a random reservation
        resv_rspec, flowspaces = create_random_resv(20, self.switches)
        users = [{'key': ''}]
        self.am_client.CreateSliver(slice_urn, cred, resv_rspec, users)

        # delete the sliver
        self.assertTrue(self.am_client.DeleteSliver(slice_urn, cred))

        time.sleep(5)

        # Make sure it is gone from the CH and the OMs
        self.assertTrue(Slice.objects.all().count() == 0,
                        "Slice not deleted in Expedient")
        self.assertTrue(DummyOMSlice.objects.all().count() == 0,
                        "Slice not deleted in the OMs")
    def test_CreateDeleteSliver(self):
        """
        Tests that we can create a sliver.
        """
        from expedient.clearinghouse.slice.models import Slice
        from openflow.dummyom.models import DummyOMSlice
        
        # get the resources
        slice_urn, cred = self.create_ch_slice()
        options = dict(geni_compressed=False, geni_available=True)
        rspec = wrap_xmlrpc_call(
            self.am_client.ListResources,
            [cred, options], {}, settings.TIMEOUT)
        
        # Create switches and links
        self.switches, self.links = parse_rspec(rspec)

        # create a random reservation
        resv_rspec, flowspaces = create_random_resv(20, self.switches)
        users = [{'key':''}]
        self.am_client.CreateSliver(slice_urn, cred, resv_rspec, users)
        
        # delete the sliver
        self.assertTrue(self.am_client.DeleteSliver(slice_urn, cred))
        
        time.sleep(5)
        
        # Make sure it is gone from the CH and the OMs
        self.assertTrue(Slice.objects.all().count() == 0,
                        "Slice not deleted in Expedient")
        self.assertTrue(DummyOMSlice.objects.all().count() == 0,
                        "Slice not deleted in the OMs")
Example #3
0
    def create_sliver_core(self, fs_randomness):
        """
        Check that we can create slice on the FV
        """
        # check no other slices
        slices = self.fv_clients[0].api.listSlices()
        self.assertEqual(len(slices), 1)  # root

        # get the resources
        slice_urn, cred = self.test_ListResources()

        # create a random reservation
        slice_name = "SliceNameBla"
        email = "*****@*****.**"
        url = "tcp:%s:%s" % (test_settings.MININET_VMS[0][0], 6633)
        resv_rspec, flowspaces = create_random_resv(
            2,
            self.switches,
            slice_name=slice_name,
            email=email,
            ctrl_url=url,
            fs_randomness=fs_randomness,
        )
        users = [{'key': ''}]
        self.am_client.CreateSliver(slice_urn, cred, resv_rspec, users)

        # TODO: check that the full reservation rspec is returned
        slices = self.fv_clients[0].api.listSlices()
        logger.debug(slices)

        self.assertEqual(len(slices), 2)  # root + new slice

        fv_slice_name = slices[1] if slices[0] == "root" else slices[0]

        # Check the name
        self.assertTrue(
            slice_name in fv_slice_name,
            "Expected to find '%s' in slice name '%s', but didn't" % (
                slice_name,
                fv_slice_name,
            ))

        # Check the slice information
        slice_info = self.fv_clients[0].api.getSliceInfo(fv_slice_name)
        logger.debug("Slice info is %s" % slice_info)
        self.assertEqual(slice_info["contact_email"], email)
        self.assertEqual(slice_info["controller_port"], "6633")
        self.assertEqual(slice_info["controller_hostname"],
                         test_settings.MININET_VMS[0][0])

        return (slice_urn, cred)
Example #4
0
    def create_sliver_core(self,fs_randomness):
        """
        Check that we can create slice on the FV
        """
        # check no other slices
        slices = self.fv_clients[0].api.listSlices()
        self.assertEqual(len(slices), 1) # root
        
        # get the resources
        slice_urn, cred = self.test_ListResources()
        
        # create a random reservation
        slice_name = "SliceNameBla"
        email = "*****@*****.**"
        url = "tcp:%s:%s" % (test_settings.MININET_VMS[0][0], 6633)
        resv_rspec, flowspaces = create_random_resv(
            2, self.switches,
            slice_name=slice_name,
            email=email,
            ctrl_url=url,
            fs_randomness = fs_randomness,
        )
        users = [{'key':''}]
        self.am_client.CreateSliver(slice_urn, cred, resv_rspec, users)
        
        # TODO: check that the full reservation rspec is returned
        slices = self.fv_clients[0].api.listSlices()
        logger.debug(slices)

        self.assertEqual(len(slices), 2) # root + new slice
        
        fv_slice_name = slices[1] if slices[0] == "root" else slices[0]
        
        # Check the name
        self.assertTrue(
            slice_name in fv_slice_name, 
            "Expected to find '%s' in slice name '%s', but didn't" % (
                slice_name, fv_slice_name,
            )
        )
        
        # Check the slice information
        slice_info = self.fv_clients[0].api.getSliceInfo(fv_slice_name)
        logger.debug("Slice info is %s" % slice_info)
        self.assertEqual(slice_info["contact_email"], email)
        self.assertEqual(slice_info["controller_port"], "6633")
        self.assertEqual(slice_info["controller_hostname"],
                         test_settings.MININET_VMS[0][0])
        
        return (slice_urn, cred)
Example #5
0
File: gapi.py Project: cargious/ocf
    def test_parse_slice(self):
        from openflow.plugin.gapi.rspec import parse_slice

        # get the resources
        slice_urn, cred = self.create_ch_slice()
        options = dict(geni_compressed=False, geni_available=True)
        rspec = wrap_xmlrpc_call(self.am_client.ListResources, [cred, options],
                                 {}, settings.TIMEOUT)

        logger.debug("Got RSpec\n%s" % rspec)

        # Create switches and links
        self.switches, self.links = parse_rspec(rspec)

        # create a random reservation
        vals = dict(firstname="John",
                    lastname="Doe",
                    email="*****@*****.**",
                    password="******",
                    proj_name="Stanford Networking",
                    proj_desc="Making the world better.",
                    slice_name="Crazy Load Balancer",
                    slice_desc="Does this and that...",
                    ctrl_url="tcp:controller.stanford.edu:6633")
        resv_rspec, flowspaces = create_random_resv(2, self.switches, **vals)

        project_name, project_desc, slice_name, slice_desc,\
        controller_url, email, password, iface_fs_map = parse_slice(resv_rspec)

        self.assertEqual(project_name, vals["proj_name"])
        self.assertEqual(project_desc, vals["proj_desc"])
        self.assertEqual(slice_name, vals["slice_name"])
        self.assertEqual(slice_desc, vals["slice_desc"])
        self.assertEqual(controller_url, vals["ctrl_url"])
        self.assertEqual(email, vals["email"])
        self.assertEqual(password, vals["password"])

        dpid_fs_map = {}  # map dpid to requested fs
        for fs in flowspaces:
            for sw in fs.switches:
                if sw.dpid not in dpid_fs_map:
                    dpid_fs_map[sw.dpid] = []
                dpid_fs_map[sw.dpid].append(fs)

        logger.debug(iface_fs_map)
 def test_parse_slice(self):
     from openflow.plugin.gapi.rspec import parse_slice
     
     # get the resources
     slice_urn, cred = self.create_ch_slice()
     options = dict(geni_compressed=False, geni_available=True)
     rspec = wrap_xmlrpc_call(
         self.am_client.ListResources,
         [cred, options], {}, settings.TIMEOUT)
     
     logger.debug("Got RSpec\n%s" % rspec)
     
     # Create switches and links
     self.switches, self.links = parse_rspec(rspec)
     
     # create a random reservation
     vals = dict(
        firstname="John", lastname="Doe",
        email="*****@*****.**", password="******",
        proj_name="Stanford Networking",
        proj_desc="Making the world better.",
        slice_name="Crazy Load Balancer",
        slice_desc="Does this and that...",
        ctrl_url="tcp:controller.stanford.edu:6633")
     resv_rspec, flowspaces = create_random_resv(2, self.switches, **vals)
     
     project_name, project_desc, slice_name, slice_desc,\
     controller_url, email, password, iface_fs_map = parse_slice(resv_rspec)
     
     self.assertEqual(project_name, vals["proj_name"])
     self.assertEqual(project_desc, vals["proj_desc"])
     self.assertEqual(slice_name, vals["slice_name"])
     self.assertEqual(slice_desc, vals["slice_desc"])
     self.assertEqual(controller_url, vals["ctrl_url"])
     self.assertEqual(email, vals["email"])
     self.assertEqual(password, vals["password"])
     
     dpid_fs_map = {} # map dpid to requested fs
     for fs in flowspaces:
         for sw in fs.switches:
             if sw.dpid not in dpid_fs_map:
                 dpid_fs_map[sw.dpid] = []
             dpid_fs_map[sw.dpid].append(fs)
     
     logger.debug(iface_fs_map)
    def test_CreateSliver(self):
        """
        Tests that we can create a sliver.
        """
        from openflow.plugin.models import OpenFlowSwitch
        from openflow.dummyom.models import DummyOMSlice
        from expedient.clearinghouse.slice.models import Slice
        
        # get the resources
        slice_urn, cred = self.create_ch_slice()
        options = dict(geni_compressed=False, geni_available=True)
        rspec = wrap_xmlrpc_call(
            self.am_client.ListResources,
            [cred, options], {}, settings.TIMEOUT)
        
        # Create switches and links
        self.switches, self.links = parse_rspec(rspec)

        # create a random reservation
        resv_rspec, flowspaces = create_random_resv(20, self.switches)
        users = [{'key':''}]
        ret = self.am_client.CreateSliver(slice_urn, cred, resv_rspec, users)
        
        self.assertEqual(resv_rspec, ret)
        
        # check that all the switches are stored in the slice on the CH
        slice = Slice.objects.get(gapislice__slice_urn=slice_urn)
        
        switches = OpenFlowSwitch.objects.filter(
            openflowinterface__slice_set=slice).distinct()
        
        dpids = []
        for fs in flowspaces:
            for switch in fs.switches:
                dpids.append(switch.dpid)
        dpids = set(dpids)
        
        # TODO: Do a better check
        self.assertEqual(len(dpids), len(switches))
        
        # check that the create_slice call has reached the dummyoms correctly
        # TODO: Do a better check
        self.assertEqual(len(DummyOMSlice.objects.all()),
                         settings.NUM_DUMMY_OMS)
Example #8
0
File: gapi.py Project: cargious/ocf
    def test_CreateSliver(self):
        """
        Tests that we can create a sliver.
        """
        from openflow.plugin.models import OpenFlowSwitch
        from openflow.dummyom.models import DummyOMSlice
        from expedient.clearinghouse.slice.models import Slice

        # get the resources
        slice_urn, cred = self.create_ch_slice()
        options = dict(geni_compressed=False, geni_available=True)
        rspec = wrap_xmlrpc_call(self.am_client.ListResources, [cred, options],
                                 {}, settings.TIMEOUT)

        # Create switches and links
        self.switches, self.links = parse_rspec(rspec)

        # create a random reservation
        resv_rspec, flowspaces = create_random_resv(20, self.switches)
        users = [{'key': ''}]
        ret = self.am_client.CreateSliver(slice_urn, cred, resv_rspec, users)

        self.assertEqual(resv_rspec, ret)

        # check that all the switches are stored in the slice on the CH
        slice = Slice.objects.get(gapislice__slice_urn=slice_urn)

        switches = OpenFlowSwitch.objects.filter(
            openflowinterface__slice_set=slice).distinct()

        dpids = []
        for fs in flowspaces:
            for switch in fs.switches:
                dpids.append(switch.dpid)
        dpids = set(dpids)

        # TODO: Do a better check
        self.assertEqual(len(dpids), len(switches))

        # check that the create_slice call has reached the dummyoms correctly
        # TODO: Do a better check
        self.assertEqual(len(DummyOMSlice.objects.all()),
                         settings.NUM_DUMMY_OMS)
Example #9
0
    def test_ListCreateDelete(self):
        """
        List resources, createsliver, opt-in, deletesliver.
        """
        ###### ListResources ######
        slice_urn, cred = self.create_ch_slice()
        options = dict(geni_compressed=False, geni_available=True)
        rspec = self.am_client.ListResources(cred, options)

        logger.debug(rspec)

        # Create switches and links
        self.switches, self.links = parse_rspec(rspec)

        # check the number of switches and links
        logger.debug("Found the following switches: %s" % self.switches)
        logger.debug("Found the following links: %s" % self.links)

        slices_before = self.fv_client.api.listSlices()
        logger.debug("Slices at the FlowVisor before creating slice: %s" %
                     slices_before)

        ###### CreateSliver ######

        # create a random reservation
        slice_name = "SliceNameBla %s" % random.randint(1, 10000000)
        email = "*****@*****.**"
        url = CONTROLLER_URL

        fs = [
            Flowspace({"tp_dst": ("80", "80")}, self.switches),
            Flowspace({"tp_src": ("80", "80")}, self.switches),
        ]

        logger.debug("Flowspace: [%s, %s]" % (fs[0], fs[1]))

        resv_rspec, flowspaces = create_random_resv(
            2,
            self.switches,
            slice_name=slice_name,
            email=email,
            ctrl_url=url,
            flowspaces=fs,
        )

        logger.debug("Reservation rspec: %s" % resv_rspec)
        logger.debug("Flowspaces in rspec: [%s, %s]" %
                     (flowspaces[0], flowspaces[1]))

        raw_input("Press Enter to proceed with the reservation:")

        logger.debug(
            "RSpec returned by reservation: %s" %
            self.am_client.CreateSliver(slice_urn, cred, resv_rspec, users=[]))

        slices_after = self.fv_client.api.listSlices()
        logger.debug("Slices at the FlowVisor after creation: %s" %
                     slices_after)

        slices_new = set(slices_after) - set(slices_before)
        logger.debug("Created: %s" % slices_new)
        self.assertEqual(len(slices_new), 1)

        slice_name = slices_new.pop()

        logger.debug("Slice information at the FlowVisor %s" %
                     self.fv_client.api.getSliceInfo(slice_name))

        ###### Opt-In ######
        flowspace = self.fv_client.api.listFlowSpace()
        logger.debug("FlowSpace before opt-in: %s" % flowspace)

        raw_input("Now opt-in a user to the slice and press Enter when done.")

        flowspace = self.fv_client.api.listFlowSpace()
        logger.debug("FlowSpace after opt-in: %s" % flowspace)

        ###### Opt-Out ######
        flowspace = self.fv_client.api.listFlowSpace()
        logger.debug("FlowSpace before opt-out: %s" % flowspace)

        raw_input(
            "Now opt-out the user from the slice and press Enter when done.")

        flowspace = self.fv_client.api.listFlowSpace()
        logger.debug("FlowSpace after opt-out: %s" % flowspace)

        ###### DeleteSliver ######
        slices_before = self.fv_client.api.listSlices()
        logger.debug("Slices at the FlowVisor before deleting slice: %s" %
                     slices_before)

        self.assertTrue(self.am_client.DeleteSliver(slice_urn, cred),
                        "Failed to delete sliver.")

        slices_after = self.fv_client.api.listSlices()
        logger.debug("Slices at the FlowVisor after deleting slice: %s" %
                     slices_after)
Example #10
0
    def test_ListCreateDelete(self):
        """
        List resources, createsliver, opt-in, deletesliver.
        """
        ###### ListResources ######
        slice_urn, cred = self.create_ch_slice()
        options = dict(geni_compressed=False, geni_available=True)
        rspec = self.am_client.ListResources(cred, options)

        logger.debug(rspec)

        # Create switches and links
        self.switches, self.links = parse_rspec(rspec)

        # check the number of switches and links
        logger.debug("Found the following switches: %s" % self.switches)
        logger.debug("Found the following links: %s" % self.links)

        slices_before = self.fv_client.api.listSlices()
        logger.debug("Slices at the FlowVisor before creating slice: %s" % slices_before)

        ###### CreateSliver ######

        # create a random reservation
        slice_name = "SliceNameBla %s" % random.randint(1, 10000000)
        email = "*****@*****.**"
        url = CONTROLLER_URL

        fs = [Flowspace({"tp_dst": ("80", "80")}, self.switches), Flowspace({"tp_src": ("80", "80")}, self.switches)]

        logger.debug("Flowspace: [%s, %s]" % (fs[0], fs[1]))

        resv_rspec, flowspaces = create_random_resv(
            2, self.switches, slice_name=slice_name, email=email, ctrl_url=url, flowspaces=fs
        )

        logger.debug("Reservation rspec: %s" % resv_rspec)
        logger.debug("Flowspaces in rspec: [%s, %s]" % (flowspaces[0], flowspaces[1]))

        raw_input("Press Enter to proceed with the reservation:")

        logger.debug(
            "RSpec returned by reservation: %s" % self.am_client.CreateSliver(slice_urn, cred, resv_rspec, users=[])
        )

        slices_after = self.fv_client.api.listSlices()
        logger.debug("Slices at the FlowVisor after creation: %s" % slices_after)

        slices_new = set(slices_after) - set(slices_before)
        logger.debug("Created: %s" % slices_new)
        self.assertEqual(len(slices_new), 1)

        slice_name = slices_new.pop()

        logger.debug("Slice information at the FlowVisor %s" % self.fv_client.api.getSliceInfo(slice_name))

        ###### Opt-In ######
        flowspace = self.fv_client.api.listFlowSpace()
        logger.debug("FlowSpace before opt-in: %s" % flowspace)

        raw_input("Now opt-in a user to the slice and press Enter when done.")

        flowspace = self.fv_client.api.listFlowSpace()
        logger.debug("FlowSpace after opt-in: %s" % flowspace)

        ###### Opt-Out ######
        flowspace = self.fv_client.api.listFlowSpace()
        logger.debug("FlowSpace before opt-out: %s" % flowspace)

        raw_input("Now opt-out the user from the slice and press Enter when done.")

        flowspace = self.fv_client.api.listFlowSpace()
        logger.debug("FlowSpace after opt-out: %s" % flowspace)

        ###### DeleteSliver ######
        slices_before = self.fv_client.api.listSlices()
        logger.debug("Slices at the FlowVisor before deleting slice: %s" % slices_before)

        self.assertTrue(self.am_client.DeleteSliver(slice_urn, cred), "Failed to delete sliver.")

        slices_after = self.fv_client.api.listSlices()
        logger.debug("Slices at the FlowVisor after deleting slice: %s" % slices_after)