Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
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
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 8
0
    def reserve(self, soap_action, soap_data):

        assert soap_action == '"http://schemas.ogf.org/nsi/2011/10/connection/service/reserve"'

        t_start = time.time()

        method, req = self.decoder.parse_request('reserve', soap_data)

        correlation_id, reply_to, = self._getRequestParameters(req)
        res = req.reserve.reservation

        requester_nsa, provider_nsa = _decodeNSAs(req.reserve)
        session_security_attr = None
        connection_id = res.connectionId
        global_reservation_id = res.globalReservationId if 'globalReservationId' in res else None
        description = res.description if 'description' in res else None
        sp = res.serviceParameters
        path = res.path

        def parseSTPID(stp_id):
            tokens = stp_id.replace(nsa.STP_PREFIX, '').split(':', 2)
            return nsa.STP(str(tokens[0]), str(tokens[1]))

        source_stp = parseSTPID(path.sourceSTP.stpId)
        dest_stp = parseSTPID(path.destSTP.stpId)
        # how to check for existence of optional parameters easily  - in / hasattr both works
        bw = sp.bandwidth
        bwp = nsa.BandwidthParameters(bw.desired if 'desired' in bw else None,
                                      bw.minimum if 'minimum' in bw else None,
                                      bw.maximum if 'maximum' in bw else None)
        start_time = sudsdate.DateTime(sp.schedule.startTime).value
        end_time = sudsdate.DateTime(sp.schedule.endTime).value

        st = start_time.utctimetuple()
        start_time = datetime.datetime(st.tm_year, st.tm_mon, st.tm_mday,
                                       st.tm_hour, st.tm_min, st.tm_sec)

        et = end_time.utctimetuple()
        end_time = datetime.datetime(et.tm_year, et.tm_mon, et.tm_mday,
                                     et.tm_hour, et.tm_min, et.tm_sec)

        t_delta = time.time() - t_start
        log.msg('Profile: Reserve request parse time: %s' % round(t_delta, 3),
                profile=True,
                system=LOG_SYSTEM)

        service_parameters = nsa.ServiceParameters(start_time,
                                                   end_time,
                                                   source_stp,
                                                   dest_stp,
                                                   bandwidth=bwp)

        d = self.provider.reserve(correlation_id, reply_to, requester_nsa,
                                  provider_nsa, session_security_attr,
                                  global_reservation_id, description,
                                  connection_id, service_parameters)
        d.addCallbacks(self._createReply,
                       self._createFault,
                       callbackArgs=(method, correlation_id),
                       errbackArgs=(method, ))
        return d