def test_UserOptIn2(self): """ Test a user opting in. """ from expedient.common.tests.client import Browser from openflow.optin_manager.opts.models import Experiment,ExperimentFLowSpace import random slices = self.fv_clients[0].api.listSlices() self.assertEqual(len(slices), 1) # root # get the resources slice_urn, cred = self.create_ch_slice() options = dict(geni_compressed=False, geni_available=True) rspec = self.am_client.ListResources(cred, options) # Create switches and links switches, links = parse_rspec(rspec) exp = Experiment.objects.create(slice_id="slice_id", project_name="project name", project_desc="project description", slice_name="slice name", slice_desc="slice description", controller_url="controller url", owner_email="owner email", owner_password="******") for switch in switches: exp_ip_src_s = random.randint(0,0x80000000) & 0xFFFF0000 exp_ip_src_e = random.randint(0x80000000,0xFFFFFFFF) & 0xFFFF0000 ExperimentFLowSpace.objects.create(exp=exp, dpid=switch.dpid, ip_src_s=exp_ip_src_s, ip_src_e=exp_ip_src_e, ) logger.debug("Done creating sliver") # Get user to opt in logger.debug("Logging into browser") b = Browser() logged_in = b.login(SCHEME+"://%s:%s/accounts/login/"% (test_settings.HOST, test_settings.OM_PORT), "user","password") self.assertTrue(logged_in,"Could not log in") logger.debug("Login success") # drop_to_shell(local=locals()) f = b.get_and_post_form(SCHEME+"://%s:%s/opts/opt_in"% (test_settings.HOST, test_settings.OM_PORT), dict(experiment=1)) logger.debug("Posted opt-in request, reading response.") res = f.read() self.assertEqual(f.code, 200) self.assertTrue("successfully" in res, "Did not get successful opt in message: %s" % res) logger.debug("Response fine, opting out.") # now test opt out: f = b.get_and_post_form(SCHEME+"://%s:%s/opts/opt_out"% (test_settings.HOST, test_settings.OM_PORT), {"1":"checked"}) res = f.read() self.assertEqual(f.code, 200) self.assertTrue("Successful" in res, "Returned %s"%res)
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_ListResources(self): """ Check the list of resources. """ # check the switches on the FV devices = self.fv_clients[0].api.listDevices() logger.debug("FV devices: %s" % devices) self.assertEqual(len(set(devices)), self.EXPECTED_NUM_SWITCHES) 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], {}, test_settings.TIMEOUT) logger.debug(rspec) # Create switches and links self.switches, self.links = parse_rspec(rspec) # check the number of switches and links self.assertEqual(len(self.switches), self.EXPECTED_NUM_SWITCHES) self.assertEqual(len(self.links), self.EXPECTED_NUM_LINKS) return slice_urn, cred
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_ListResources(self, zipped=False): """ Check the list of resources. """ from openflow.dummyom.models import DummyOM slice_urn, cred = self.create_ch_slice() options = dict(geni_compressed=zipped, geni_available=True) rspec = wrap_xmlrpc_call( self.am_client.ListResources, [cred, options], {}, settings.TIMEOUT) logger.debug("Got Advertisement RSpec: \n%s" % rspec) if zipped: import zlib, base64 rspec = zlib.decompress(base64.b64decode(rspec)) # Create switches and links self.switches, self.links = parse_rspec(rspec) # check the number of switches and links num_links = sum([len(d.get_switches()) for d in DummyOM.objects.all()]) self.assertEqual(len(self.switches), num_links) self.assertEqual(len(self.links), settings.NUM_LINKS_PER_AGG * settings.NUM_DUMMY_OMS)
def test_topoChange_ListResources(self): """ Check the list of resources before and after a topology change """ from openflow.dummyom.models import DummyOM 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) # check the number of switches and links num_links = sum([len(d.get_switches()) for d in DummyOM.objects.all()]) self.assertEqual(len(self.switches), num_links) self.assertEqual(len(self.links), settings.NUM_LINKS_PER_AGG*settings.NUM_DUMMY_OMS) killed_dpids = [] for om in DummyOM.objects.all(): killed_dpids.append(om.kill_dpid()) om.dummycallbackproxy.call_back() # Create switches and links options = dict(geni_compressed=False, geni_available=True) rspec = self.am_client.ListResources(cred, options) self.switches, self.links = parse_rspec(rspec) # check the number of switches num_links = sum([len(d.get_switches()) for d in DummyOM.objects.all()]) self.assertEqual(len(self.switches), num_links) # make sure all killed dpids are gone: None of the dpids still # here should have the dpid of a killed switch. for s in self.switches: for d in killed_dpids: self.assertNotEqual(str(s.dpid), str(d))
def test_topoChange_ListResources(self): """ Check the list of resources before and after a topology change """ from openflow.dummyom.models import DummyOM 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) # check the number of switches and links num_links = sum([len(d.get_switches()) for d in DummyOM.objects.all()]) self.assertEqual(len(self.switches), num_links) self.assertEqual(len(self.links), settings.NUM_LINKS_PER_AGG * settings.NUM_DUMMY_OMS) killed_dpids = [] for om in DummyOM.objects.all(): killed_dpids.append(om.kill_dpid()) om.dummycallbackproxy.call_back() # Create switches and links options = dict(geni_compressed=False, geni_available=True) rspec = self.am_client.ListResources(cred, options) self.switches, self.links = parse_rspec(rspec) # check the number of switches num_links = sum([len(d.get_switches()) for d in DummyOM.objects.all()]) self.assertEqual(len(self.switches), num_links) # make sure all killed dpids are gone: None of the dpids still # here should have the dpid of a killed switch. for s in self.switches: for d in killed_dpids: self.assertNotEqual(str(s.dpid), str(d))
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)
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)
def test_ListResources(self, zipped=False): """ Check the list of resources. """ from openflow.dummyom.models import DummyOM slice_urn, cred = self.create_ch_slice() options = dict(geni_compressed=zipped, geni_available=True) rspec = wrap_xmlrpc_call(self.am_client.ListResources, [cred, options], {}, settings.TIMEOUT) logger.debug("Got Advertisement RSpec: \n%s" % rspec) if zipped: import zlib, base64 rspec = zlib.decompress(base64.b64decode(rspec)) # Create switches and links self.switches, self.links = parse_rspec(rspec) # check the number of switches and links num_links = sum([len(d.get_switches()) for d in DummyOM.objects.all()]) self.assertEqual(len(self.switches), num_links) self.assertEqual(len(self.links), settings.NUM_LINKS_PER_AGG * settings.NUM_DUMMY_OMS)
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)
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)