Example #1
0
    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)
Example #2
0
    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)
Example #3
0
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
Example #4
0
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
Example #5
0
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
Example #6
0
    def testBasicConnectionLifeCycle(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', '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)
        global_reservation_id = 'urn:uuid:' + str(uuid.uuid1())
        connection_id = 'conn-id1'

        yield self.client.reserve(self.client_nsa, provider.nsa, None,
                                  global_reservation_id, 'Test Connection',
                                  connection_id, service_params)

        qr = yield self.client.query(self.client_nsa,
                                     provider.nsa,
                                     None,
                                     "Summary",
                                     connection_ids=[connection_id])
        self.assertEquals(qr.reservationSummary[0].connectionState, 'Reserved')

        yield self.client.provision(self.client_nsa, provider.nsa, None,
                                    connection_id)

        qr = yield self.client.query(self.client_nsa,
                                     provider.nsa,
                                     None,
                                     "Summary",
                                     connection_ids=[connection_id])
        self.assertEquals(qr.reservationSummary[0].connectionState,
                          'Provisioned')

        yield self.client.release(self.client_nsa, provider.nsa, None,
                                  connection_id)

        qr = yield self.client.query(self.client_nsa,
                                     provider.nsa,
                                     None,
                                     "Summary",
                                     connection_ids=[connection_id])
        self.assertEquals(qr.reservationSummary[0].connectionState,
                          'Scheduled')

        yield self.client.terminate(self.client_nsa, provider.nsa, None,
                                    connection_id)

        qr = yield self.client.query(self.client_nsa,
                                     provider.nsa,
                                     None,
                                     "Summary",
                                     connection_ids=[connection_id])
        self.assertEquals(qr.reservationSummary[0].connectionState,
                          'Terminated')

        # give the service side time to dump its connections
        # this prevents finishing the test with a dirty reactor
        from twisted.internet import task
        d = task.deferLater(reactor, 0.01, lambda: None)
        yield d
Example #7
0
def doMain():

    print 'OpenNSA WS test client'

    wsdl_dir =  os.path.join(os.path.dirname(os.path.abspath(__file__)), 'wsdl')

    client, factory = setup.createClient(HOST, PORT, wsdl_dir)

    reactor.listenTCP(PORT, factory)

    client_nsa      = nsa.NetworkServiceAgent('OpenNSA-testclient', LOCAL_REQUESTER)

    provider_local_aruba    = nsa.Network('Aruba',   nsa.NetworkServiceAgent('Aruba-OpenNSA', LOCALHOST_SERVICE))
    provider_orval_aruba    = nsa.Network('Aruba',   nsa.NetworkServiceAgent('Aruba-OpenNSA', OPENNSA_SERVICE))
    provider_martinique     = nsa.Network('Martinique', nsa.NetworkServiceAgent('Martinique-DynamicKL', DYNAMICKL_SERVICE))

    provider = provider_local_aruba
    #provider = provider_orval_aruba
    #provider = provider_martinique

    source_stp      = nsa.STP('Aruba', 'A1' )
    #source_stp      = nsa.STP('Aruba', 'Axel' )
    #source_stp      = nsa.STP('Martinique', 'M1')

    #dest_stp        = nsa.STP('Aruba', 'A2')
    dest_stp        = nsa.STP('Bonaire', 'B3')
    #dest_stp        = nsa.STP('Curacao', 'C3')

    start_time = datetime.datetime.utcfromtimestamp(time.time() + 3 )
    end_time   = datetime.datetime.utcfromtimestamp(time.time() + 120 )
    #start_time, end_time = end_time, start_time

    bandwidth = 200
    #service_params  = nsa.ServiceParameters('2011-09-01T08:56:00Z', '2011-10-01T08:56:00Z' , source_stp, dest_stp, bwp)
    service_params  = nsa.ServiceParameters(start_time, end_time, source_stp, dest_stp, bandwidth)
    global_reservation_id = 'urn:uuid:' + str(uuid.uuid1())
    connection_id         = 'urn:uuid:' + str(uuid.uuid1())

    print "Connection id", connection_id

    r = yield client.reserve(client_nsa, provider.nsa, None, global_reservation_id, 'Test Connection', connection_id, service_params)
    print "Reservation created. Connection ID:", connection_id

    qr = yield client.query(client_nsa, provider.nsa, None, "Summary", connection_ids = [ connection_id ] )
    matchState(qr, 'Reserved')

    d = client.provision(client_nsa, provider.nsa, None, connection_id)

    qr = yield client.query(client_nsa, provider.nsa, None, "Summary", connection_ids = [ connection_id ] )
    matchState(qr, 'Auto-Provision')

    yield d
    print "Connection provisioned"

    qr = yield client.query(client_nsa, provider.nsa, None, "Summary", connection_ids = [ connection_id ] )
    matchState(qr, 'Provisioned')

    _ = yield client.release(client_nsa, provider.nsa, None, connection_id)
    print "Connection released"

    qr = yield client.query(client_nsa, provider.nsa, None, "Summary", connection_ids = [ connection_id ] )
    matchState(qr, 'Scheduled')

    _ = yield client.terminate(client_nsa, provider.nsa, None, connection_id)
    print "Reservation terminated"

    qr = yield client.query(client_nsa, provider.nsa, None, "Summary", connection_ids = [ connection_id ] )
    matchState(qr, 'Terminated')