def test_add_aggregate(self): resp = test_get_and_post_form( self.client, reverse("gopenflow_aggregate_create"), dict( name="DummyOF", description="DummyOF Description", location="Stanford, CA", url="test://testserver:80"+reverse("dummy_gopenflow"), ) ) self.assertEqual(GCFOpenFlowAggregate.objects.count(), 1) self.assertRedirects( resp, expected_url=reverse( "gopenflow_aggregate_add_links", args=[GCFOpenFlowAggregate.objects.all()[0].id]), ) exp_switches, exp_links = parse_external_rspec(self.of.adv_rspec) new_rspec = gapi.ListResources({}, None) new_switches, new_links = parse_external_rspec(new_rspec) self.assertEqual( self.sort_switches(new_switches), self.sort_switches(exp_switches)) self.assertEqual( self.links_to_set(new_links), self.links_to_set(exp_links))
def test_external_rspec(self): self.test_create_aggregates() adv_rspec = rspec_mod.get_resources(None, None) d1 = rspec_mod.parse_external_rspec(adv_rspec) # replace all the urn prefixes with external ones test_prefix = publicid_to_urn( "IDN %s//%s" % ("test//test", settings.OPENFLOW_GCF_BASE_SUFFIX)) adv_rspec2 = adv_rspec.replace(rspec_mod.OPENFLOW_GAPI_RSC_URN_PREFIX, test_prefix) d2 = rspec_mod.parse_external_rspec(adv_rspec2) self.assertEqual(d1, d2)
def test_external_rspec(self): self.test_create_aggregates() adv_rspec = rspec_mod.get_resources(None, None) d1 = rspec_mod.parse_external_rspec(adv_rspec) # replace all the urn prefixes with external ones test_prefix = publicid_to_urn( "IDN %s//%s" % ("test//test", settings.OPENFLOW_GCF_BASE_SUFFIX) ) adv_rspec2 = adv_rspec.replace( rspec_mod.OPENFLOW_GAPI_RSC_URN_PREFIX, test_prefix) d2 = rspec_mod.parse_external_rspec(adv_rspec2) self.assertEqual(d1, d2)
def _from_rspec(self, rspec): """ See L{GENIAggregate._from_rspec}. """ switches, links = parse_external_rspec(rspec) create_or_update_switches(self, switches) create_or_update_links(self, links)
def test_add_aggregate(self): resp = test_get_and_post_form( self.client, reverse("gopenflow_aggregate_create"), dict( name="DummyOF", description="DummyOF Description", location="Stanford, CA", url="test://testserver:80" + reverse("dummy_gopenflow"), )) self.assertEqual(GCFOpenFlowAggregate.objects.count(), 1) self.assertRedirects( resp, expected_url=reverse( "gopenflow_aggregate_add_links", args=[GCFOpenFlowAggregate.objects.all()[0].id]), ) exp_switches, exp_links = parse_external_rspec(self.of.adv_rspec) new_rspec = gapi.ListResources({}, None) new_switches, new_links = parse_external_rspec(new_rspec) self.assertEqual(self.sort_switches(new_switches), self.sort_switches(exp_switches)) self.assertEqual(self.links_to_set(new_links), self.links_to_set(exp_links))
def test_gapi_ListResources(self, create=True, zipped=False): # add aggregates if create: self.test_create_aggregates() self.client.logout() # get the rspec for the added resources options = dict(geni_compressed=zipped, geni_available=True) rspec = self.rpc.ListResources([self.slice_cred], options) logger.debug("Got advertisement RSpec:\n %s" % rspec) if zipped: import zlib, base64 rspec = zlib.decompress(base64.b64decode(rspec)) # parse the rspec and check the switches/links switches, links = rspec_mod.parse_external_rspec(rspec) # verify that all switches are listed dpids_actual = set( OpenFlowSwitch.objects.values_list("datapath_id", flat=True)) dpids_found = set(switches.keys()) self.assertEqual(dpids_found, dpids_actual) # verify the ports for each switch for dpid in dpids_actual: ports_actual = set( OpenFlowInterface.objects.filter( switch__datapath_id=dpid).values_list("port_num", flat=True)) ports_found = set(switches[dpid]) self.assertEqual(ports_found, ports_actual) # verify the links links_actual = set( OpenFlowConnection.objects.values_list( "src_iface__switch__datapath_id", "src_iface__port_num", "dst_iface__switch__datapath_id", "dst_iface__port_num", )) links_found = set([l[:-1] for l in links]) self.assertEquals(links_found, links_actual)
def test_gapi_ListResources(self, create=True, zipped=False): # add aggregates if create: self.test_create_aggregates() self.client.logout() # get the rspec for the added resources options = dict(geni_compressed=zipped, geni_available=True) rspec = self.rpc.ListResources([self.slice_cred], options) logger.debug("Got advertisement RSpec:\n %s" % rspec) if zipped: import zlib, base64 rspec = zlib.decompress(base64.b64decode(rspec)) # parse the rspec and check the switches/links switches, links = rspec_mod.parse_external_rspec(rspec) # verify that all switches are listed dpids_actual = set(OpenFlowSwitch.objects.values_list( "datapath_id", flat=True)) dpids_found = set(switches.keys()) self.assertEqual(dpids_found, dpids_actual) # verify the ports for each switch for dpid in dpids_actual: ports_actual = set(OpenFlowInterface.objects.filter( switch__datapath_id=dpid).values_list( "port_num", flat=True)) ports_found = set(switches[dpid]) self.assertEqual(ports_found, ports_actual) # verify the links links_actual = set(OpenFlowConnection.objects.values_list( "src_iface__switch__datapath_id", "src_iface__port_num", "dst_iface__switch__datapath_id", "dst_iface__port_num", )) links_found = set([l[:-1] for l in links]) self.assertEquals(links_found, links_actual)