def testReserveAbort(self): # these need to be constructed such that there is only one label option source_stp = nsa.STP(self.network, self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1782')) dest_stp = nsa.STP(self.network, self.dest_port, nsa.Label(cnt.ETHERNET_VLAN, '1782')) criteria = nsa.Criteria( 0, self.schedule, nsa.Point2PointService(source_stp, dest_stp, 200, cnt.BIDIRECTIONAL, False, None)) self.header.newCorrelationId() acid = yield self.provider.reserve(self.header, None, None, None, criteria) header, cid, gid, desc, sp = yield self.requester.reserve_defer yield self.provider.reserveAbort(self.header, acid) header, cid = yield self.requester.reserve_abort_defer self.requester.reserve_defer = defer.Deferred() # try to reserve the same resources acid2 = yield self.provider.reserve(self.header, None, None, None, criteria) header, cid, gid, desc, sp = yield self.requester.reserve_defer
def testInvalidNetworkReservation(self): provider = nsa.Network( 'Aruba', nsa.NetworkServiceAgent( 'Aruba-OpenNSA', 'http://localhost:9080/NSI/services/ConnectionService')) source_stp = nsa.STP('NoSuchNetwork', 'PS') dest_stp = nsa.STP('Aruba', 'A2') start_time = datetime.datetime.utcfromtimestamp(time.time() + 1.5) end_time = datetime.datetime.utcfromtimestamp(time.time() + 120) bwp = nsa.BandwidthParameters(200) service_params = nsa.ServiceParameters(start_time, end_time, source_stp, dest_stp, bandwidth=bwp) connection_id = 'conn-id1' try: yield self.client.reserve(self.client_nsa, provider.nsa, None, None, '', connection_id, service_params) self.fail('Reserve call should have failed') except error.ReserveError as e: self.failUnlessIn('No network named NoSuchNetwork', str(e)) errors = self.flushLoggedErrors(error.TopologyError) self.assertEqual(len(errors), 1)
def testReserveTimeout(self): # these need to be constructed such that there is only one label option source_stp = nsa.STP(self.network, self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1782') ) dest_stp = nsa.STP(self.network, self.dest_port, nsa.Label(cnt.ETHERNET_VLAN, '1782') ) criteria = nsa.Criteria(0, self.schedule, nsa.Point2PointService(source_stp, dest_stp, self.bandwidth, cnt.BIDIRECTIONAL, False, None) ) self.header.newCorrelationId() acid = yield self.provider.reserve(self.header, None, None, None, criteria) header, cid, gid, desc, sp = yield self.requester.reserve_defer self.clock.advance(self.backend.TPC_TIMEOUT + 1) header, cid, notification_id, timestamp, timeout_value, org_cid, org_nsa = yield self.requester.reserve_timeout_defer self.failUnlessEquals(cid, acid) self.requester.reserve_defer = defer.Deferred() # new criteria start_time = datetime.datetime.utcnow() + datetime.timedelta(seconds=2) end_time = datetime.datetime.utcnow() + datetime.timedelta(seconds=6) schedule = nsa.Schedule(start_time, end_time) criteria = nsa.Criteria(0, schedule, nsa.Point2PointService(source_stp, dest_stp, self.bandwidth, cnt.BIDIRECTIONAL, False, None) ) # try to reserve the same resources acid2 = yield self.provider.reserve(self.header, None, None, None, criteria) header, cid, gid, desc, sp = yield self.requester.reserve_defer
def testConnectSTPToItself(self): provider = nsa.Network( 'Aruba', nsa.NetworkServiceAgent( 'Aruba-OpenNSA', 'http://localhost:9080/NSI/services/ConnectionService')) source_stp = nsa.STP('Aruba', 'A1') dest_stp = nsa.STP('Aruba', 'A1') start_time = datetime.datetime.utcfromtimestamp(time.time() + 2) end_time = datetime.datetime.utcfromtimestamp(time.time() + 40) bwp = nsa.BandwidthParameters(200) service_params = nsa.ServiceParameters(start_time, end_time, source_stp, dest_stp, bandwidth=bwp) connection_id = 'conn-id1' try: yield self.client.reserve(self.client_nsa, provider.nsa, None, None, '', connection_id, service_params) self.fail('Reserve call should have failed') except error.ReserveError as e: self.failUnlessIn('Cannot connect <STP Aruba:A1> to itself', str(e)) errors = self.flushLoggedErrors(error.ReserveError) self.assertEqual(len(errors), 1)
def testPortSTPs(self): source_stp = nsa.STP(self.network, 'eth1', None) dest_stp = nsa.STP(self.network, 'eth2', None) criteria = nsa.Criteria(0, self.schedule, nsa.Point2PointService(source_stp, dest_stp, 200, cnt.BIDIRECTIONAL, False, None) ) self.header.newCorrelationId() acid = yield self.provider.reserve(self.header, None, None, None, criteria) header, cid, gid, desc, sc = yield self.requester.reserve_defer self.failUnlessEqual(cid, acid) yield self.provider.reserveCommit(self.header, acid) cid = yield self.requester.reserve_commit_defer yield self.provider.provision(self.header, acid) cid = yield self.requester.provision_defer self.clock.advance(3) header, cid, nid, timestamp, dps = yield self.requester.data_plane_change_defer active, version, consistent = dps self.requester.data_plane_change_defer = defer.Deferred() # need a new one for deactivate self.failUnlessEqual(cid, acid) self.failUnlessEqual(active, True) self.failUnlessEqual(consistent, True) #yield self.provider.release(self.header, cid) #cid = yield self.requester.release_defer yield self.provider.terminate(self.header, acid) cid = yield self.requester.terminate_defer
def setUp(self): self.clock = task.Clock() tcf = os.path.expanduser('~/.opennsa-test.json') tc = json.load( open(tcf) ) ncs_config = { config.NCS_SERVICES_URL : tc['ncs-url'], config.NCS_USER : tc['ncs-user'], config.NCS_PASSWORD : tc['ncs-password'] } self.requester = common.DUDRequester() self.backend = ncsvpn.NCSVPNBackend('Test', self.sr, self.requester, ncs_config) self.backend.scheduler.clock = self.clock self.backend.startService() database.setupDatabase(tc['database'], tc['database-user'], tc['database-password'], host=tc['hostname']) self.requester_nsa = nsa.NetworkServiceAgent('test-requester', 'http://example.org/nsa-test-requester') self.provider_nsa = nsa.NetworkServiceAgent('test-provider', 'http://example.org/nsa-test-provider') source_stp = nsa.STP('ncs', 'hel:ge-1/0/1', labels=[ nsa.Label(nml.ETHERNET_VLAN, '100-102') ] ) dest_stp = nsa.STP('ncs', 'sto:ge-1/0/1', labels=[ nsa.Label(nml.ETHERNET_VLAN, '101-104') ] ) start_time = datetime.datetime.utcnow() + datetime.timedelta(seconds=2) end_time = datetime.datetime.utcnow() + datetime.timedelta(seconds=30) bandwidth = 200 self.service_params = nsa.ServiceParameters(start_time, end_time, source_stp, dest_stp, bandwidth)
def testLabelRangeMultiReservation(self): source_stp = nsa.STP(self.network, self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1781-1783')) dest_stp = nsa.STP(self.network, self.dest_port, nsa.Label(cnt.ETHERNET_VLAN, '1781-1783')) criteria = nsa.Criteria( 0, self.schedule, nsa.Point2PointService(source_stp, dest_stp, 100, 'Bidirectional', False, None)) self.header.newCorrelationId() acid = yield self.provider.reserve(self.header, None, None, None, criteria) yield self.requester.reserve_defer self.header.newCorrelationId() yield self.provider.reserveCommit(self.header, acid) yield self.requester.reserve_commit_defer self.requester.reserve_defer = defer.Deferred() self.requester.reserve_commit_defer = defer.Deferred() self.header.newCorrelationId() acid2 = yield self.provider.reserve(self.header, None, None, None, criteria) yield self.requester.reserve_defer self.header.newCorrelationId() yield self.provider.reserveCommit(self.header, acid2) yield self.requester.reserve_commit_defer
def testSlowActivate(self): # key here is that end time is passed when activation is done start_time = datetime.datetime.utcnow() + datetime.timedelta(seconds=2) end_time = datetime.datetime.utcnow() + datetime.timedelta(seconds=4) schedule = nsa.Schedule(start_time, end_time) source_stp = nsa.STP(self.network, self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1780')) dest_stp = nsa.STP(self.network, self.dest_port, nsa.Label(cnt.ETHERNET_VLAN, '1780')) criteria = nsa.Criteria( 0, schedule, nsa.Point2PointService(source_stp, dest_stp, 200, cnt.BIDIRECTIONAL, False, None)) def setupLink(connection_id, src, dst, bandwidth): d = defer.Deferred() reactor.callLater(2, d.callback, None) return d # make activation fail via monkey patching self.backend.connection_manager.setupLink = setupLink self.header.newCorrelationId() acid = yield self.provider.reserve(self.header, None, None, None, criteria) header, cid, gid, desc, sp = yield self.requester.reserve_defer self.failUnlessEqual(cid, acid) yield self.provider.reserveCommit(self.header, cid) yield self.requester.reserve_commit_defer yield self.provider.provision(self.header, cid) yield self.requester.provision_defer self.clock.advance(3) header, cid, nid, timestamp, dps = yield self.requester.data_plane_change_defer active, version, consistent = dps self.failUnlessEqual(cid, acid) self.failUnlessEqual(active, True) self.failUnlessEqual(consistent, True) self.requester.data_plane_change_defer = defer.Deferred() self.clock.advance(2) header, cid, nid, timestamp, dps = yield self.requester.data_plane_change_defer active, version, consistent = dps self.failUnlessEqual(cid, acid) self.failUnlessEqual(active, False) yield self.provider.terminate(self.header, cid) yield self.requester.terminate_defer
def testReserveFailAndLabelSwapEnabled(self): # When you try to reserve a circuit using a labelSwap enabled backend and the dest_stp appers to be in use, # the src stp reservation never gets removed from the calendar self.assertTrue(self.backend.connection_manager.canSwapLabel(cnt.ETHERNET_VLAN),"DUD is not able to swapLabels") # Construct a valid circuit source_stp = nsa.STP(self.network, self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1782') ) dest_stp = nsa.STP(self.network, self.dest_port, nsa.Label(cnt.ETHERNET_VLAN, '1782') ) criteria = nsa.Criteria(0, self.schedule, nsa.Point2PointService(source_stp, dest_stp, 200, cnt.BIDIRECTIONAL, False, None) ) #We shouldn't have reservations in the calendar right now self.assertEquals(len(self.backend.calendar.reservations), 0, "Reservations size is %s should be 0" % len(self.backend.calendar.reservations)) self.header.newCorrelationId() acid = yield self.provider.reserve(self.header, None, None, None, criteria) header, cid, gid, desc, sp = yield self.requester.reserve_defer # reset deferred for reservation self.requester.reserve_defer = defer.Deferred() # 2 reservations, for source_stp and dest_stp self.assertEquals(len(self.backend.calendar.reservations), 2, "Reservations size is %s should be 2" % len(self.backend.calendar.reservations)) #Construct a second circuit, with the same dest_stp source_stp2 = nsa.STP(self.network,self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1781')) criteria2 = nsa.Criteria(0, self.schedule, nsa.Point2PointService(source_stp2, dest_stp, 200, cnt.BIDIRECTIONAL, False, None) ) self.header.newCorrelationId() try: acid2 = yield self.provider.reserve(self.header, None, None, None, criteria2) header2, cid2, gid2, desc2, sp2 = yield self.requester.reserve_defer except error.STPUnavailableError as e: pass # reset deferred for reservation self.requester.reserve_defer = defer.Deferred() # The second reserve request failed, so we should have the original 2 reservations in the calendar self.assertEquals(len(self.backend.calendar.reservations), 2, "Reservations size is %s should be 2" % len(self.backend.calendar.reservations)) # terminate the connection yield self.provider.terminate(self.header, cid) yield self.requester.terminate_defer for stp in [source_stp2,dest_stp,source_stp]: try: res = self.backend.connection_manager.getResource(stp.port, stp.label) resource_is_available = self.backend.calendar.checkReservation(res, self.schedule.start_time,self.schedule.end_time) except error.STPUnavailableError as e: self.fail("STP %s should be available" % res)
def testPruningEnd(self): ndn_link = nsa.Link( nsa.STP('nordu.net:2013:topology', 'funet', nsa.Label('vlan', '2031-2035')), nsa.STP('nordu.net:2013:topology', 'surfnet', nsa.Label('vlan', '2-4094')) ) sfn_link = nsa.Link( nsa.STP('surfnet.nl:1990:production7', 'nordunet', nsa.Label('vlan', '2-4094')), nsa.STP('surfnet.nl:1990:production7', '19523', nsa.Label('vlan', '2077')) ) path = [ ndn_link, sfn_link ] pruned_path = pruner.pruneLabels(path) self.assertEquals(pruned_path[0].dst_stp.label.labelValue(), '2077') self.assertEquals(pruned_path[1].src_stp.label.labelValue(), '2077')
def testInvalidNetworkReservation(self): source_stp = nsa.STP(self.network, self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1782') ) dest_stp = nsa.STP('NoSuchNetwork:topology', 'whatever', nsa.Label(cnt.ETHERNET_VLAN, '1782') ) criteria = nsa.Criteria(0, self.schedule, nsa.Point2PointService(source_stp, dest_stp, 200, 'Bidirectional', False, None) ) self.header.newCorrelationId() try: yield self.provider.reserve(self.header, None, None, None, criteria) self.fail('Should have raised TopologyError') except (error.ConnectionCreateError, error.STPResolutionError): # we raise ConnectionCreateError in backends, and STPResolutionError in aggregator pass # expected
def testIdenticalPortSTPs(self): source_stp = nsa.STP(self.network, 'eth1', None) dest_stp = nsa.STP(self.network, 'eth1', None) criteria = nsa.Criteria(0, self.schedule, nsa.Point2PointService(source_stp, dest_stp, 200, cnt.BIDIRECTIONAL, False, None) ) self.header.newCorrelationId() try: acid = yield self.provider.reserve(self.header, None, None, None, criteria) self.fail("Should have gotten service error for identical ports") except error.ServiceError: pass # expected
def setUp(self): self.backend = dud.DUDNSIBackend('TestDUD') source_stp = nsa.STP('Aruba', 'A1') dest_stp = nsa.STP('Aruba', 'A3') start_time = datetime.datetime.utcfromtimestamp(time.time() + 0.1) end_time = datetime.datetime.utcfromtimestamp(time.time() + 10) bwp = nsa.BandwidthParameters(200) self.service_params = nsa.ServiceParameters(start_time, end_time, source_stp, dest_stp, bandwidth=bwp)
def testHairpinConnectionAllowed(self): self.provider.policies.append(cnt.ALLOW_HAIRPIN) source_stp = nsa.STP(self.network, self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1782') ) dest_stp = nsa.STP(self.network, self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1783') ) sd = nsa.Point2PointService(source_stp, dest_stp, self.bandwidth, cnt.BIDIRECTIONAL, False, None) criteria = nsa.Criteria(0, self.schedule, sd) self.header.newCorrelationId() try: acid = yield self.provider.reserve(self.header, None, None, None, criteria) yield self.requester.reserve_defer except Exception as e: self.fail('Should not have raised exception: %s' % str(e))
def testHairpinConnection(self): source_stp = nsa.STP(self.network, self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1782') ) dest_stp = nsa.STP(self.network, self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1783') ) sd = nsa.Point2PointService(source_stp, dest_stp, self.bandwidth, cnt.BIDIRECTIONAL, False, None) criteria = nsa.Criteria(0, self.schedule, sd) self.header.newCorrelationId() try: yield self.provider.reserve(self.header, None, None, None, criteria) self.fail('Should have raised ServceError / TopologyError') except error.ServiceError: pass # expected - hairpin except error.TopologyError: pass # expected - double vlan assignment
def buildInternalTopology(triples): getSubject = lambda pred, obj : [ t[0] for t in triples if t[1] == pred and t[2] == obj ] getObjects = lambda subj, pred : [ t[2] for t in triples if t[0] == subj and t[1] == pred ] node_ports = {} urn_internal_ports = getSubject(RDF_TYPE, NRM_PORT_TYPE) for uip in sorted(urn_internal_ports): sp = _stripPrefix(uip, URN_NRM_PORT) node, port = sp.split(':',1) node_ports.setdefault(node, []).append(port) internal_topology = topology.Topology() for node, ports in node_ports.items(): nw = nsa.Network(node, None) for p in ports: dest_ports = getObjects(_createNRMPort(node, p), GLIF_CONNECTED_TO) if dest_ports: dest_port = dest_ports[0] if dest_ports else None dsp = _stripPrefix(dest_port, URN_NRM_PORT) d_node, d_port = dsp.split(':',1) dest_stp = nsa.STP(d_node, d_port) else: dest_stp = None ep = nsa.NetworkEndpoint(node, p, dest_stp=dest_stp) nw.addEndpoint(ep) internal_topology.addNetwork(nw) return internal_topology
def path(topology_file, source_stp, dest_stp): from opennsa.topology import gole topo, _ = gole.parseTopology([open(topology_file)]) source_network, source_port = source_stp.split(':', 1) dest_network, dest_port = dest_stp.split(':', 1) r_source_stp = nsa.STP(source_network, source_port) r_dest_stp = nsa.STP(dest_network, dest_port) paths = topo.findPaths(r_source_stp, r_dest_stp) for p in sorted(paths, key=lambda p: len(p.network_links)): log.msg(str(p))
def _query(self, header, connection_ids, global_reservation_ids, request_info=None): # generic query mechanism for summary and recursive # TODO: Match stps/ports that can be used with credentials and return connections using these STPs if connection_ids: conns = yield GenericBackendConnections.find(where=[ 'source_network = ? AND dest_network = ? AND requester_nsa = ? AND connection_id IN ?', self.network, self.network, header.requester_nsa, tuple(connection_ids) ]) elif global_reservation_ids: conns = yield GenericBackendConnections.find(where=[ 'source_network = ? AND dest_network = ? AND requester_nsa = ? AND global_reservation_ids IN ?', self.network, self.network, header.requester_nsa, tuple(global_reservation_ids) ]) else: raise error.MissingParameterError( 'Must specify connectionId or globalReservationId') reservations = [] for c in conns: source_stp = nsa.STP(c.source_network, c.source_port, c.source_label) dest_stp = nsa.STP(c.dest_network, c.dest_port, c.dest_label) schedule = nsa.Schedule(c.start_time, c.end_time) sd = nsa.Point2PointService(source_stp, dest_stp, c.bandwidth, cnt.BIDIRECTIONAL, False, None) criteria = nsa.QueryCriteria(c.revision, schedule, sd) data_plane_status = (c.data_plane_active, c.revision, True) states = (c.reservation_state, c.provision_state, c.lifecycle_state, data_plane_status) notification_id = self.getNotificationId() result_id = notification_id # whatever provider_nsa = cnt.URN_OGF_PREFIX + self.network.replace( 'topology', 'nsa') # hack on reservations.append( nsa.ConnectionInfo(c.connection_id, c.global_reservation_id, c.description, cnt.EVTS_AGOLE, [criteria], provider_nsa, c.requester_nsa, states, notification_id, result_id)) defer.returnValue(reservations)
def parseGOLERDFTopology(topology_source): def stripURNPrefix(text): URN_PREFIX = 'urn:ogf:network:' assert text.startswith(URN_PREFIX), "%s does not conform" % text return text.split(':')[-1] OWL_NS = rdflib.namespace.Namespace("http://www.w3.org/2002/07/owl#") RDF_NS = rdflib.namespace.Namespace( 'http://www.w3.org/1999/02/22-rdf-syntax-ns#') DTOX_NS = rdflib.namespace.Namespace( 'http://www.glif.is/working-groups/tech/dtox#') graph = rdflib.Graph() # TODO: Change this to some configurable option. # graph.open("/Users/jeroen/Projects/OpenNSA-UvA/opennsa/rdfdb") try: graph.parse(topology_source) except: raise error.TopologyError('Invalid topology source') topo = Topology() topo.graph = graph for nsnetwork in graph.subjects(RDF_NS['type'], DTOX_NS['NSNetwork']): # Setup the base network object, with NSA nsaId = graph.value(subject=nsnetwork, predicate=DTOX_NS['managedBy']) network_name = stripURNPrefix(str(nsnetwork)) network_nsa_ep = graph.value(subject=nsaId, predicate=DTOX_NS['csProviderEndpoint']) network_nsa = nsa.NetworkServiceAgent(stripURNPrefix(str(nsaId)), str(network_nsa_ep)) network = nsa.Network(network_name, network_nsa) loc = graph.value(subject=nsnetwork, predicate=DTOX_NS["locatedAt"]) network.location = (graph.value(subject=loc, predicate=DTOX_NS["lat"]), graph.value(subject=loc, predicate=DTOX_NS["long"])) # Add all the STPs and connections to the network for stp in graph.objects(nsnetwork, DTOX_NS['hasSTP']): stp_name = stripURNPrefix(str(stp)) dest_stp = graph.value(subject=stp, predicate=DTOX_NS['connectedTo']) # If there is a destination, add that, otherwise the value stays None. if dest_stp: dest_network = graph.value(predicate=DTOX_NS['hasSTP'], object=dest_stp) #print "adding %s for %s" % (dest_stp, dest_network) dest_stp = nsa.STP(stripURNPrefix(str(dest_network)), stripURNPrefix(str(dest_stp))) ep = nsa.NetworkEndpoint(network_name, stp_name, None, dest_stp, None, None) network.addEndpoint(ep) topo.addSTP(str(stp), ep) topo.addNetwork(network) return topo
def _doReserve(self, conn, correlation_id): # we have already checked resource availability, so can progress directly through checking state.reserveMultiSwitch(conn, state.RESERVE_CHECKING, state.RESERVE_HELD) yield conn.save() self.logStateUpdate(conn, 'RESERVE CHECKING/HELD') # schedule 2PC timeout if self.scheduler.hasScheduledCall(conn.connection_id): # this means that the build scheduler made a call while we yielded self.scheduler.cancelCall(conn.connection_id) now = datetime.datetime.utcnow() timeout_time = min(now + datetime.timedelta(seconds=self.TPC_TIMEOUT), conn.end_time) self.scheduler.scheduleCall(conn.connection_id, timeout_time, self._doReserveTimeout, conn) td = timeout_time - datetime.datetime.utcnow() log.msg( 'Connection %s: reserve abort scheduled for %s UTC (%i seconds)' % (conn.connection_id, timeout_time.replace(microsecond=0), td.total_seconds()), system=self.log_system) schedule = nsa.Schedule(conn.start_time, conn.end_time) sc_source_stp = nsa.STP(conn.source_network, conn.source_port, conn.source_label) sc_dest_stp = nsa.STP(conn.dest_network, conn.dest_port, conn.dest_label) sd = nsa.Point2PointService( sc_source_stp, sc_dest_stp, conn.bandwidth, cnt.BIDIRECTIONAL, False, None) # we fake some things due to db limitations crit = nsa.Criteria(conn.revision, schedule, sd) header = nsa.NSIHeader( conn.requester_nsa, conn.requester_nsa, correlation_id=correlation_id ) # The NSA is both requester and provider in the backend, but this might be problematic without aggregator yield self.parent_requester.reserveConfirmed( header, conn.connection_id, conn.global_reservation_id, conn.description, crit)
def testInvalidRewrite(self): source_stp = nsa.STP(self.network, 'eth1', None) criteria = nsa.Criteria(0, self.schedule, nsa.Point2PointService(source_stp, self.dest_stp, 200, cnt.BIDIRECTIONAL, False, None) ) self.header.newCorrelationId() try: acid = yield self.provider.reserve(self.header, None, None, None, criteria) self.fail("Should have gotten topology error ") except error.NSIError: pass # expected
def _createSTP(stp_arg): # no generic label stuff for now if '#' in stp_arg: stp_desc, vlan = stp_arg.split('#') network, port = stp_desc.rsplit(':',1) label = nsa.Label(cnt.ETHERNET_VLAN, vlan) else: network, port = stp_arg.rsplit(':',1) label = None return nsa.STP(network, port, label)
def reserve(client, client_nsa, provider_nsa, source_stp, dest_stp, start_time, end_time, bandwidth, connection_id, global_id): source_network, source_port = source_stp.split(':', 1) dest_network, dest_port = dest_stp.split(':', 1) r_source_stp = nsa.STP(source_network, source_port) r_dest_stp = nsa.STP(dest_network, dest_port) bwp = nsa.BandwidthParameters(bandwidth) service_params = nsa.ServiceParameters(start_time, end_time, r_source_stp, r_dest_stp, bandwidth=bwp) log.msg("Connection ID: %s" % connection_id) log.msg("Global ID: %s" % global_id) _ = yield client.reserve(client_nsa, provider_nsa, None, global_id, 'Test Connection', connection_id, service_params) print "Reservation created at %s" % provider_nsa
def testReserveTerminateReReserve(self): # Tamas Varga found a bug where calendar isn't probably cleanup up on reserve+terminate # This reproduces the the issue # these need to be constructed such that there is only one label option source_stp = nsa.STP(self.network, self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1782') ) dest_stp = nsa.STP(self.network, self.dest_port, nsa.Label(cnt.ETHERNET_VLAN, '1782') ) criteria = nsa.Criteria(0, self.schedule, nsa.Point2PointService(source_stp, dest_stp, 200, cnt.BIDIRECTIONAL, False, None) ) self.header.newCorrelationId() acid = yield self.provider.reserve(self.header, None, None, None, criteria) header, cid, gid, desc, sp = yield self.requester.reserve_defer # reset deferred for reservation self.requester.reserve_defer = defer.Deferred() # terminate the connection yield self.provider.terminate(self.header, cid) yield self.requester.terminate_defer # try to reserve the same resources acid2 = yield self.provider.reserve(self.header, None, None, None, criteria) yield self.requester.reserve_defer
def testDoubleReserve(self): source_stp = nsa.STP(self.network, self.source_port, nsa.Label(cnt.ETHERNET_VLAN, '1781') ) p2p = nsa.Point2PointService(source_stp, self.dest_stp, self.bandwidth, cnt.BIDIRECTIONAL, False, None) criteria = nsa.Criteria(0, self.schedule, p2p) self.header.newCorrelationId() acid = yield self.provider.reserve(self.header, None, None, None, criteria) header, cid, gid, desc, sp = yield self.requester.reserve_defer self.requester.reserve_defer = defer.Deferred() # new defer for new reserve request try: acid2 = yield self.provider.reserve(self.header, None, None, None, criteria) self.fail('Should have raised STPUnavailableError') except error.STPUnavailableError: pass # we expect this
def _createSTP(stp_arg): if not ':' in stp_arg: raise usage.UsageError('No ":" in stp, invalid format (see docs/cli.md)') if '#' in stp_arg: stp_desc, label_desc = stp_arg.split('#') network, port = stp_desc.rsplit(':',1) if not '=' in label_desc: raise usage.UsageError('No "=" in stp label, invalid format (see docs/cli.md)') label_type,label_value = label_desc.split("=") label = nsa.Label(LABEL_MAP[label_type],label_value) # FIXME need good error message if label type doesn't exist else: network, port = stp_arg.rsplit(':',1) label = None return nsa.STP(network, port, label)
def buildTopology(triples): getSubject = lambda pred, obj : [ t[0] for t in triples if t[1] == pred and t[2] == obj ] getObjects = lambda subj, pred : [ t[2] for t in triples if t[0] == subj and t[1] == pred ] topo = topology.Topology() networks = getSubject(RDF_TYPE, GLIF_NETWORK) for network in networks: nsas = getObjects(network, GLIF_MANAGED_BY) endpoints = getObjects(nsas[0], GLIF_PROVIDER_ENDPOINT) t_network_name = _stripPrefix(network, URN_NSNETWORK_PREFIX) t_nsa_name = _stripPrefix(nsas[0], URN_NSA_PREFIX) t_nsa_endpoint = endpoints[0] t_network_nsa = nsa.NetworkServiceAgent(t_nsa_name, t_nsa_endpoint) t_network = nsa.Network(t_network_name, t_network_nsa) stps = getObjects(network, GLIF_HAS_STP) for stp in stps: t_stp_name = _stripPrefix(stp, URN_STP_PREFIX).split(':')[-1] maps_to = getObjects(stp, GLIF_MAPS_TO) t_maps_to = _stripPrefix(maps_to[0], URN_NRM_PORT) if maps_to else None # this is for default/single backend to work, remove initial colon (backend seperator) if t_maps_to is not None and t_maps_to.startswith(':'): t_maps_to = t_maps_to[1:] dest_stps = getObjects(stp, GLIF_CONNECTED_TO) if dest_stps: dest_network, dest_port = _stripPrefix(dest_stps[0], URN_STP_PREFIX).split(':',1) t_dest_stp = nsa.STP(dest_network, dest_port) else: t_dest_stp = None ep = nsa.NetworkEndpoint(t_network_name, t_stp_name, t_maps_to, t_dest_stp, None, None) t_network.addEndpoint(ep) topo.addNetwork(t_network) return topo
def createSTP(stp_id): if not stp_id.startswith(URN_NETWORK): raise error.PayloadError('STP Id (%s) did not start with %s' % (stp_id, URN_NETWORK)) tsi = stp_id.replace(URN_NETWORK, '') if '?' in tsi: loc, lbp = tsi.split('?') label = parseLabel(lbp) else: loc = tsi label = None if not ':' in loc: raise error.PayloadError('No : in stp urn (%s)' % loc) network, port = loc.rsplit(':', 1) return nsa.STP(network, port, label)
def testPruningStart(self): sfn_link = nsa.Link( nsa.STP('surfnet.nl:1990:production7', 'ps', nsa.Label('vlan', '1784')), nsa.STP('surfnet.nl:1990:production7', 'sara-ndn1', nsa.Label('vlan', '1780-1799')) ) ndn_link = nsa.Link( nsa.STP('nordu.net:2013:topology', 'surfnet', nsa.Label('vlan', '1784-1789')), nsa.STP('nordu.net:2013:topology', 'deic1', nsa.Label('vlan', '1784-1789')) ) dec_link = nsa.Link( nsa.STP('deic.dk:2013:topology', 'ndn1', nsa.Label('vlan', '1784-1789')), nsa.STP('deic.dk:2013:topology', 'ps', nsa.Label('vlan', '1784')) ) path = [ sfn_link, ndn_link, dec_link ] pruned_path = pruner.pruneLabels(path) self.assertEquals(pruned_path[0].dst_stp.label.labelValue(), '1784') self.assertEquals(pruned_path[1].src_stp.label.labelValue(), '1784')
def createSTP(stp_id): if not stp_id.startswith(URN_NETWORK): raise error.PayloadError('STP Id (%s) did not start with %s' % (stp_id, URN_NETWORK)) tsi = stp_id.replace(URN_NETWORK, '') if '?' in tsi: loc, lbp = tsi.split('?') label = parseLabel(lbp) else: loc = tsi label = None if not ':' in loc: raise error.PayloadError('Invalid STP: No ":" in stp urn (%s)' % loc) # FIXME This may need to be updated for new stp structure (Uppsala) network, port = loc.rsplit(':', 1) return nsa.STP(network, port, label)