コード例 #1
0
        def reservationConfirmed(_, pp):
            log.msg(
                'Received reservation reply from Argia. CID: %s, Ports: %s -> %s'
                % (id(self), self.source_port, self.dest_port),
                system=LOG_SYSTEM)
            try:
                tree = ET.parse(pp.stdout)
                argia_state = list(tree.getiterator('state'))[0].text
                reservation_id = list(
                    tree.getiterator('reservationId'))[0].text

                if argia_state == ARGIA_RESERVED:
                    self.argia_id = reservation_id
                    self.state.switchState(state.RESERVED)
                    self.scheduler.scheduleTransition(
                        self.service_parameters.start_time, scheduled,
                        state.SCHEDULED)
                    d.callback(self)
                else:
                    d.errback(
                        error.ReserveError(
                            'Got unexpected state from Argia (%s)' %
                            argia_state))

            except Exception, e:
                log.msg('Error handling reservation reply: %s' % str(e),
                        system=LOG_SYSTEM)
                self._logProcessPipes(pp)
                d.errback(
                    error.ReserveError('Error handling reservation reply: %s' %
                                       str(e)))
コード例 #2
0
    def reserve(self):
        def scheduled(st):
            self.state.switchState(state.SCHEDULED)
            self.scheduler.scheduleTransition(self.service_parameters.end_time,
                                              lambda _: self.terminate(),
                                              state.TERMINATING)

        log.msg('RESERVE. CID: %s, Ports: %s -> %s' %
                (id(self), self.source_port, self.dest_port),
                system=LOG_SYSTEM)

        try:
            self.state.switchState(state.RESERVING)
        except error.StateTransitionError:
            return defer.fail(
                error.ReserveError('Cannot reserve connection in state %s' %
                                   self.state()))

        payload = self._constructReservationPayload(
        )  #self.source_port, self.dest_port, self.service_parameters)
        process_proto = ArgiaProcessProtocol(payload)

        try:
            reactor.spawnProcess(process_proto,
                                 self.command,
                                 [self.command_bin, ARGIA_CMD_RESERVE],
                                 path=self.command_dir)
        except OSError, e:
            return defer.fail(
                error.ReserveError(
                    'Failed to invoke argia control command (%s)' % str(e)))
コード例 #3
0
 def reservationFailed(err, pp):
     log.msg('Received reservation failure from Argia. CID: %s, Ports: %s -> %s' % (id(self), self.source_port, self.dest_port), system=LOG_SYSTEM)
     try:
         self.state.switchState(state.TERMINATED)
         tree = ET.parse(pp.stderr)
         message = list(tree.getiterator('message'))[0].text
         d.errback( error.ReserveError('Reservation failed in Argia backend: %s' % message) )
     except Exception, e:
         log.msg('Error handling reservation failure: %s' % str(e), system=LOG_SYSTEM)
         self._logProcessPipes(pp)
         d.errback( error.ReserveError('Error handling reservation failure: %s' % str(e)) )
コード例 #4
0
        def provisionConfirmed(_, pp):
            log.msg(
                'Received provision reply from Argia. CID: %s, Ports: %s -> %s'
                % (id(self), self.source_port, self.dest_port),
                system=LOG_SYSTEM)
            try:
                tree = ET.parse(pp.stdout)
                argia_state = list(tree.getiterator('state'))[0].text
                argia_id = list(tree.getiterator('reservationId'))[0].text

                if argia_state not in (ARGIA_PROVISIONED,
                                       ARGIA_AUTO_PROVISION):
                    d.errback(
                        error.ProvisionError(
                            'Got unexpected state from Argia (%s)' %
                            argia_state))
                else:
                    self.state.switchState(state.PROVISIONED)
                    self.argia_id = argia_id
                    log.msg('Connection provisioned. CID: %s' % id(self),
                            system=LOG_SYSTEM)
                    self.scheduler.scheduleTransition(
                        self.service_parameters.end_time,
                        lambda _: self.terminate(), state.TERMINATED)
                    d.callback(self)

            except Exception, e:
                log.msg('Error handling provision reply: %s' % str(e),
                        system=LOG_SYSTEM)
                self._logProcessPipes(pp)
                d.errback(
                    error.ReserveError('Error handling reservation reply: %s' %
                                       str(e)))
コード例 #5
0
ファイル: simplebackend.py プロジェクト: jeroenh/OpenNSA
    def reserve(self):
        def scheduled(st):
            self.state.switchState(state.SCHEDULED)
            self.scheduler.scheduleTransition(self.service_parameters.end_time,
                                              lambda _: self.terminate(),
                                              state.TERMINATING)
            self.logStateUpdate('SCHEDULED')

        try:
            self.state.switchState(state.RESERVING)
            self.logStateUpdate('RESERVING')
            self.state.switchState(state.RESERVED)
        except error.StateTransitionError:
            return defer.fail(
                error.ReserveError('Cannot reserve connection in state %s' %
                                   self.state()))

        self.scheduler.scheduleTransition(self.service_parameters.start_time,
                                          scheduled, state.SCHEDULED)
        self.logStateUpdate('RESERVED')
        return defer.succeed(self)
コード例 #6
0
ファイル: requester.py プロジェクト: jeroenh/OpenNSA
 def reserveFailed(self, correlation_id, requester_nsa, provider_nsa,
                   global_reservation_id, connection_id, connection_state,
                   error_message):
     log.msg('Reservation failed (by callback): %s' % error_message)
     self.triggerCall(provider_nsa, correlation_id, 'reserve',
                      error.ReserveError(error_message))
コード例 #7
0
ファイル: requester.py プロジェクト: jeroenh/OpenNSA
 def reserveRequestFailed(err):
     # invocation failed, so we error out immediately
     log.msg('Reserve invocation failed: %s' % str(err))
     self.triggerCall(provider_nsa.urn(), correlation_id, 'reserve',
                      error.ReserveError(err.getErrorMessage()))
コード例 #8
0
                elif state == ARGIA_RESERVED:
                    self.state.switchState(state.RESERVED)
                else:
                    log.msg('Unexpected state from argia provision failure: %s' % state, system=LOG_SYSTEM)

                d.errback( error.ProvisionError(message) )
            except Exception, e:
                log.msg('Error handling provision failure: %s' % str(e), system=LOG_SYSTEM)
                self._logProcessPipes(pp)
                d.errback( error.ProvisionError('Error handling reservation failure: %s' % str(e)) )

        process_proto = ArgiaProcessProtocol()
        try:
            reactor.spawnProcess(process_proto, self.command, args=[self.command_bin, ARGIA_CMD_PROVISION, self.argia_id], path=self.command_dir)
        except OSError, e:
            return defer.fail(error.ReserveError('Failed to invoke argia control command (%s)' % str(e)))
        process_proto.d.addCallbacks(provisionConfirmed, provisionFailed, callbackArgs=[process_proto], errbackArgs=[process_proto])

        return defer.succeed(None), d


    def release(self):

        log.msg('Releasing connection. CID %s' % id(self), system=LOG_SYSTEM)

        try:
            self.state.switchState(state.RELEASING)
        except error.InvalidTransitionError as e:
            return defer.fail(e)

        self.scheduler.cancelTransition() # cancel scheduled switch to terminate+release
コード例 #9
0
                        system=LOG_SYSTEM)
                self._logProcessPipes(pp)
                d.errback(
                    error.ProvisionError(
                        'Error handling reservation failure: %s' % str(e)))

        process_proto = ArgiaProcessProtocol()
        try:
            reactor.spawnProcess(
                process_proto,
                self.command,
                args=[self.command_bin, ARGIA_CMD_PROVISION, self.argia_id],
                path=self.command_dir)
        except OSError, e:
            return defer.fail(
                error.ReserveError(
                    'Failed to invoke argia control command (%s)' % str(e)))
        process_proto.d.addCallbacks(provisionConfirmed,
                                     provisionFailed,
                                     callbackArgs=[process_proto],
                                     errbackArgs=[process_proto])

        return defer.succeed(None), d

    def release(self):

        log.msg('Releasing connection. CID %s' % id(self), system=LOG_SYSTEM)

        try:
            self.state.switchState(state.RELEASING)
        except error.StateTransitionError:
            return defer.fail(
コード例 #10
0
    def reserve(self, requester_nsa, provider_nsa, session_security_attr,
                global_reservation_id, description, connection_id,
                service_parameters, sub):

        # --

        log.msg('', system='opennsa')
        log.msg('Connection %s. Reserve request from %s.' %
                (connection_id, requester_nsa),
                system=LOG_SYSTEM)

        if connection_id in self.connections.get(requester_nsa, {}):
            return defer.fail(
                error.ReserveError('Connection with id %s already exists' %
                                   connection_id))

        source_stp = service_parameters.source_stp
        dest_stp = service_parameters.dest_stp

        if source_stp == dest_stp:
            return defer.fail(
                error.ReserveError('Cannot connect %s to itself.' %
                                   source_stp))

        conn = connection.Connection(self.service_registry, requester_nsa,
                                     connection_id, source_stp, dest_stp,
                                     service_parameters, global_reservation_id,
                                     description)

        self.connections.setdefault(requester_nsa,
                                    {})[conn.connection_id] = conn

        # figure out nature of request

        path_info = (connection_id, source_stp.network, source_stp.endpoint,
                     dest_stp.network, dest_stp.endpoint, self.network)

        if source_stp.network == self.network and dest_stp.network == self.network:
            log.msg(
                'Connection %s: Simple path creation: %s:%s -> %s:%s (%s)' %
                path_info,
                system=LOG_SYSTEM)
            link = nsa.Link(source_stp.network, source_stp.endpoint,
                            dest_stp.endpoint)
            self.setupSubConnection(link, conn, service_parameters)

        # This code is for chaining requests and is currently not used, but might be needed sometime in the future
        # Once we get proper a topology service, some chaining will be necessary.

        #elif source_stp.network == self.network:
        #    # make path and chain on - common chaining
        #    log.msg('Reserve %s: Common chain creation: %s:%s -> %s:%s (%s)' % path_info, system=LOG_SYSTEM)
        #    paths = self.topology.findPaths(source_stp, dest_stp)
        #    # check for no paths
        #    paths.sort(key=lambda e : len(e.endpoint_pairs))
        #    selected_path = paths[0] # shortest path
        #    log.msg('Attempting to create path %s' % selected_path, system=LOG_SYSTEM)
        #    assert selected_path.source_stp.network == self.network
        #   # setup connection data - does this work with more than one hop?
        #    setupSubConnection(selected_path.source_stp, selected_path.endpoint_pairs[0].sourceSTP(), conn)
        #    setupSubConnection(selected_path.endpoint_pairs[0].destSTP(), dest_stp, conn)
        #elif dest_stp.network == self.network:
        #    # make path and chain on - backwards chaining
        #    log.msg('Backwards chain creation %s: %s:%s -> %s:%s (%s)' % path_info, system=LOG_SYSTEM)
        #    paths = self.topology.findPaths(source_stp, dest_stp)
        #    # check for no paths
        #    paths.sort(key=lambda e : len(e.endpoint_pairs))
        #    selected_path = paths[0] # shortest path
        #    log.msg('Attempting to create path %s' % selected_path, system=LOG_SYSTEM)
        #    assert selected_path.dest_stp.network == self.network
        #   # setup connection data
        #    setupSubConnection(selected_path.source_stp, selected_path.endpoint_pairs[0].sourceSTP(), conn)
        #    setupSubConnection(selected_path.endpoint_pairs[0].destSTP(), dest_stp, conn)
        #else:
        #    log.msg('Tree creation %s:  %s:%s -> %s:%s (%s)' % path_info, system=LOG_SYSTEM)

        # create the connection in tree/fanout style
        else:
            # log about creation and the connection type
            log.msg(
                'Connection %s: Aggregate path creation: %s:%s -> %s:%s (%s)' %
                path_info,
                system=LOG_SYSTEM)
            # making the connection is the same for all though :-)
            paths = self.topology.findPaths(source_stp, dest_stp)

            # error out if we could not find a path
            if not paths:
                error_msg = 'Could not find a path for route %s:%s -> %s:%s' % (
                    source_stp.network, source_stp.endpoint, dest_stp.network,
                    dest_stp.endpoint)
                log.msg(error_msg, system=LOG_SYSTEM)
                raise error.TopologyError(error_msg)

            # check for no paths
            paths.sort(key=lambda e: len(e.links()))
            selected_path = paths[0]  # shortest path
            log.msg('Attempting to create path %s' % selected_path,
                    system=LOG_SYSTEM)

            for link in selected_path.links():
                self.setupSubConnection(link, conn, service_parameters)

        # now reserve connections needed to create path
        conn.addSubscription(sub)
        d = task.deferLater(reactor, 0, conn.reserve)
        d.addErrback(log.err)
        return defer.succeed(None)