Пример #1
0
    def reserveConfirmed(self, soap_data, request_info):

        header, reservation = helper.parseRequest(soap_data)

        criteria = reservation.criteria

        # Create DTOs - this overlaps heavily with the parsing done in providerservice - unify sometime

        start_time = xmlhelper.parseXMLTimestamp(criteria.schedule.startTime) if criteria.schedule.startTime is not None else None
        end_time   = xmlhelper.parseXMLTimestamp(criteria.schedule.endTime)   if criteria.schedule.endTime   is not None else None
        schedule   = nsa.Schedule(start_time, end_time)

        # check for service type sometime
        p2ps = criteria.serviceDefinition
        if type(p2ps) is not p2pservices.P2PServiceBaseType:
            raise ValueError('Only P2P service supported.')

        # (ERO missing)
        src_stp = helper.createSTP(p2ps.sourceSTP)
        dst_stp = helper.createSTP(p2ps.destSTP)

        if p2ps.ero:
            print('ERO parsing in reserveConfirmed not implemented yet, full path will not be available')

        sd = nsa.Point2PointService(src_stp, dst_stp, p2ps.capacity, p2ps.directionality, p2ps.symmetricPath, None)
        crt = nsa.Criteria(criteria.version, schedule, sd)

        self.requester.reserveConfirmed(header, reservation.connectionId,  reservation.globalReservationId, reservation.description, crt)

        return helper.createGenericRequesterAcknowledgement(header)
Пример #2
0
    def reserveConfirmed(self, soap_data):

        header, reservation = helper.parseRequest(soap_data)

        criteria = reservation.criteria

        # Create DTOs - this overlaps heavily with the parsing done in providerservice - unify sometime

        start_time = xmlhelper.parseXMLTimestamp(criteria.schedule.startTime) if criteria.schedule.startTime is not None else None
        end_time   = xmlhelper.parseXMLTimestamp(criteria.schedule.endTime)
        schedule   = nsa.Schedule(start_time, end_time)

        # check for service type sometime
        p2ps = criteria.serviceDefinition
        if type(p2ps) is not p2pservices.P2PServiceBaseType:
            raise ValueError('Only P2P service supported.')

        # (ERO missing)
        src_stp = helper.createSTP(p2ps.sourceSTP)
        dst_stp = helper.createSTP(p2ps.destSTP)

        if p2ps.ero:
            print "ERO parsing in reserveConfirmed not implemented yet, full path will not be available"

        sd = nsa.Point2PointService(src_stp, dst_stp, p2ps.capacity, p2ps.directionality, p2ps.symmetricPath, None)
        crt = nsa.Criteria(criteria.version, schedule, sd)

        self.requester.reserveConfirmed(header, reservation.connectionId,  reservation.globalReservationId, reservation.description, crt)

        return helper.createGenericRequesterAcknowledgement(header)
Пример #3
0
def buildSchedule(schedule):

    start_time = parseXMLTimestamp(
        schedule.startTime) if schedule.startTime is not None else None
    end_time = parseXMLTimestamp(
        schedule.endTime) if schedule.endTime is not None else None
    return nsa.Schedule(start_time, end_time)
Пример #4
0
    def reserveTimeout(self, soap_data, request_info):

        header, reserve_timeout = helper.parseRequest(soap_data)

        rt = reserve_timeout
        timestamp = xmlhelper.parseXMLTimestamp(rt.timeStamp)
        self.requester.reserveTimeout(header, rt.connectionId, rt.notificationId, timestamp, rt.timeoutValue, rt.originatingConnectionId, rt.originatingNSA)

        return helper.createGenericRequesterAcknowledgement(header)
Пример #5
0
    def reserveTimeout(self, soap_data, request_info):

        header, reserve_timeout = helper.parseRequest(soap_data)

        rt = reserve_timeout
        timestamp = xmlhelper.parseXMLTimestamp(rt.timeStamp)
        self.requester.reserveTimeout(header, rt.connectionId, rt.notificationId, timestamp, rt.timeoutValue, rt.originatingConnectionId, rt.originatingNSA)

        return helper.createGenericRequesterAcknowledgement(header)
Пример #6
0
    def render_POST(self, request):

        allowed, msg, request_info = requestauthz.checkAuthz(request, self.allowed_hosts)
        if not allowed:
            payload = msg + RN
            return _requestResponse(request, 401, payload) # Not Authorized

        payload = request.content.read()

        if len(payload) == 0:
            log.msg('No data received in request', system=LOG_SYSTEM)
            payload = 'No data received in request' + RN
            return _requestResponse(request, 400, payload) # Bad Request

        if len(payload) > 32*1024:
            log.msg('Rejecting request, payload too large. Length %i' % len(payload), system=LOG_SYSTEM)
            payload = 'Requests too large' + RN
            return _requestResponse(request, 413, payload) # Payload Too Large

        try:
            data = json.loads(payload)
        except ValueError:
            log.msg('Invalid JSON data received, returning 400', system=LOG_SYSTEM)
            payload = 'Invalid JSON data' + RN
            return _requestResponse(request, 400, payload) # Bad Request


        def createResponse(connection_id):

            payload = 'Connection created' + RN
            header = { 'location': self.base_path + '/' + connection_id }
            _finishRequest(request, 201, payload, header) # Created

        # extract stuffs
        try:
            source = data['source']
            if not source.startswith(cnt.URN_OGF_PREFIX):
                source = cnt.URN_OGF_PREFIX + source

            destination = data['destination']
            if not destination.startswith(cnt.URN_OGF_PREFIX):
                destination = cnt.URN_OGF_PREFIX + destination

            source_stp = helper.createSTP(str(source))
            destination_stp = helper.createSTP(str(destination))

            start_time = xmlhelper.parseXMLTimestamp(data['start']) if 'start' in data else None
            end_time   = xmlhelper.parseXMLTimestamp(data['end'])   if 'end'   in data else None
            capacity   = data['capacity'] if 'capacity' in data else 0 # Maybe None should just be best effort

            # fillers, we don't really do this in this api
            symmetric = False
            ero       = None
            params    = None
            version   = 0

            service_def = nsa.Point2PointService(source_stp, destination_stp, capacity, cnt.BIDIRECTIONAL, symmetric, ero, params)
            schedule = nsa.Schedule(start_time, end_time)
            criteria = nsa.Criteria(version, schedule, service_def)

            header = nsa.NSIHeader('rest-dud-requester', 'rest-dud-provider') # completely bogus header

            d = self.provider.reserve(header, None, None, None, criteria, request_info) # nones are connectoin id, global resv id, description
            d.addCallbacks(createResponse, _createErrorResponse, errbackArgs=(request,))
            return server.NOT_DONE_YET

        except Exception as e:
            error_code = _errorCode(e)
            return _requestResponse(request, error_code, str(e))
Пример #7
0
def buildSchedule(schedule):

    start_time = parseXMLTimestamp(schedule.startTime) if schedule.startTime is not None else None
    end_time   = parseXMLTimestamp(schedule.endTime)
    return nsa.Schedule(start_time, end_time)
Пример #8
0
    def render_POST(self, request):

        allowed, msg, request_info = requestauthz.checkAuthz(
            request, self.allowed_hosts)
        if not allowed:
            payload = msg + RN
            return _requestResponse(request, 401, payload)  # Not Authorized

        payload = request.content.read()

        if len(payload) == 0:
            log.msg('No data received in request', system=LOG_SYSTEM)
            payload = 'No data received in request' + RN
            return _requestResponse(request, 400, payload)  # Bad Request

        if len(payload) > 32 * 1024:
            log.msg('Rejecting request, payload too large. Length %i' %
                    len(payload),
                    system=LOG_SYSTEM)
            payload = 'Requests too large' + RN
            return _requestResponse(request, 413, payload)  # Payload Too Large

        try:
            data = json.loads(payload)
        except ValueError:
            log.msg('Invalid JSON data received, returning 400',
                    system=LOG_SYSTEM)
            payload = 'Invalid JSON data' + RN
            return _requestResponse(request, 400, payload)  # Bad Request

        def createResponse(connection_id):

            payload = 'Connection created' + RN
            header = {'location': self.base_path + '/' + connection_id}
            _finishRequest(request, 201, payload, header)  # Created
            return connection_id

        # extract stuffs
        try:
            source = data['source']
            if not source.startswith(cnt.URN_OGF_PREFIX):
                source = cnt.URN_OGF_PREFIX + source

            destination = data['destination']
            if not destination.startswith(cnt.URN_OGF_PREFIX):
                destination = cnt.URN_OGF_PREFIX + destination

            source_stp = helper.createSTP(str(source))
            destination_stp = helper.createSTP(str(destination))

            start_time = xmlhelper.parseXMLTimestamp(
                data[START_TIME]) if START_TIME in data else None
            end_time = xmlhelper.parseXMLTimestamp(
                data[END_TIME]) if END_TIME in data else None
            capacity = data[
                'capacity'] if 'capacity' in data else 0  # Maybe None should just be best effort

            # auto commit (default true) and auto provision (defult false)
            auto_commit = False if 'auto_commit' in data and not data[
                'auto_commit'] else True
            auto_provision = True if 'auto_provision' in data and data[
                'auto_provision'] else False

            if auto_provision and not auto_commit:
                msg = 'Cannot have auto-provision without auto-commit'
                log.msg('Rejecting request: ' + msg, system=LOG_SYSTEM)
                return _requestResponse(request, 400, msg + RN)  # Bad Request

            # fillers, we don't really do this in this api
            symmetric = False
            ero = None
            params = None
            version = 0

            service_def = nsa.Point2PointService(source_stp, destination_stp,
                                                 capacity, cnt.BIDIRECTIONAL,
                                                 symmetric, ero, params)
            schedule = nsa.Schedule(start_time, end_time)
            criteria = nsa.Criteria(version, schedule, service_def)

            header = nsa.NSIHeader(
                'rest-dud-requester',
                'rest-dud-provider')  # completely bogus header

            d = self.provider.reserve(
                header, None, None, None, criteria, request_info
            )  # nones are connection_id, global resv id, description
            d.addCallbacks(createResponse,
                           _createErrorResponse,
                           errbackArgs=(request, ))

            if auto_commit:

                @defer.inlineCallbacks
                def connectionCreated(conn_id):
                    if conn_id is None:
                        # error creating connection
                        # not exactly optimal code flow here, but chainining the callback correctly for this is tricky
                        return

                    conn = yield self.provider.getConnection(conn_id)

                    def stateUpdate():
                        log.msg(
                            'stateUpdate reservation_state: %s, provision_state: %s'
                            % (str(conn.reservation_state),
                               str(conn.provision_state)),
                            debug=True,
                            system=LOG_SYSTEM)
                        if conn.reservation_state == state.RESERVE_HELD:
                            self.provider.reserveCommit(
                                header, conn_id, request_info)
                        if conn.reservation_state == state.RESERVE_START and conn.provision_state == state.RELEASED and auto_provision:
                            self.provider.provision(header, conn_id,
                                                    request_info)
                        if conn.provision_state == state.PROVISIONED:
                            state.desubscribe(conn_id, stateUpdate)

                    state.subscribe(conn_id, stateUpdate)

                d.addCallback(connectionCreated)

            return server.NOT_DONE_YET

        except Exception as e:
            #log.err(e, system=LOG_SYSTEM)
            log.msg('Error creating connection: %s' % str(e),
                    system=LOG_SYSTEM)

            error_code = _errorCode(e)
            return _requestResponse(request, error_code, str(e))
Пример #9
0
    def reserve(self, soap_data):

        t_start = time.time()

        header, reservation = helper.parseRequest(soap_data)

        # do some checking here

        #        print header.protocolVersion
        #        print header.correlationId
        #        print header.requesterNSA
        #        print header.providerNSA
        #        print header.replyTo

        criteria = reservation.criteria

        #version      = criteria.version # not used at the moment
        service_type = criteria.serviceType  # right now we just ignore this, either we know the service type or not
        p2ps = criteria.serviceDefinition

        #        if len(service_defs) == 0:
        #            err = failure.Failure ( error.PayloadError('No service definition element in message') )
        #            return self._createSOAPFault(err, header.provider_nsa, service_type=service_type)

        #        if len(service_defs) != 1:
        #            err = failure.Failure ( error.PayloadError('Only one service definition allowed') )
        #            return self._createSOAPFault(err, header.provider_nsa, service_type=service_type)

        if type(p2ps) is not p2pservices.P2PServiceBaseType:
            err = failure.Failure(
                error.PayloadError(
                    'Only supports Point2PointService service for now.'))
            return self._createSOAPFault(err,
                                         header.provider_nsa,
                                         service_type=service_type)

        if p2ps.directionality in (None, ''):
            err = failure.Failure(
                error.MissingParameterError(
                    'Directionality parameter not defined'))
            return self._createSOAPFault(err, header.provider_nsa)

        # create DTOs (EROs not supported yet)

        start_time = xmlhelper.parseXMLTimestamp(
            criteria.schedule.startTime
        ) if criteria.schedule.startTime is not None else None
        end_time = xmlhelper.parseXMLTimestamp(criteria.schedule.endTime)
        schedule = nsa.Schedule(start_time, end_time)

        src_stp = helper.createSTP(p2ps.sourceSTP)
        dst_stp = helper.createSTP(p2ps.destSTP)

        if p2ps.ero:
            err = failure.Failure(
                error.PayloadError('ERO not supported, go away.'))
            return self._createSOAPFault(err, header.provider_nsa)

#        if p2ps.parameter:
#            p = p2ps.parameter[0]
#            err = failure.Failure ( error.UnsupportedParameter('Unsupported parameter: %s/%s' % (p.type_, p.value) ) )
#            return self._createSOAPFault(err, header.provider_nsa)
        params = [(p.type_, p.value)
                  for p in p2ps.parameter] if p2ps.parameter else None
        symmetric = p2ps.symmetricPath or False  # the p2p service specifies default behaviour as false, but doesn't specify default
        sd = nsa.Point2PointService(src_stp, dst_stp, p2ps.capacity,
                                    p2ps.directionality, symmetric, None,
                                    params)

        crt = nsa.Criteria(criteria.version, schedule, sd)

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

        d = self.provider.reserve(header, reservation.connectionId,
                                  reservation.globalReservationId,
                                  reservation.description, crt)

        def createReserveAcknowledgement(connection_id):
            # no reply to / security attrs / trace
            soap_header_element = helper.createProviderHeader(
                header.requester_nsa, header.provider_nsa, None,
                header.correlation_id)

            reserve_response = nsiconnection.ReserveResponseType(connection_id)
            reserve_response_element = reserve_response.xml(
                nsiconnection.reserveResponse)

            payload = minisoap.createSoapPayload(reserve_response_element,
                                                 soap_header_element)
            return payload

        d.addCallbacks(createReserveAcknowledgement,
                       self._createSOAPFault,
                       errbackArgs=(header.provider_nsa, ))
        return d
Пример #10
0
    def reserve(self, soap_data, request_info):

        t_start = time.time()

        header, reservation = helper.parseRequest(soap_data)

        # do some checking here

#        print header.protocolVersion
#        print header.correlationId
#        print header.requesterNSA
#        print header.providerNSA
#        print header.replyTo

        criteria = reservation.criteria

        #version      = criteria.version # not used at the moment
        service_type = criteria.serviceType # right now we just ignore this, either we know the service type or not
        p2ps         = criteria.serviceDefinition

#        if len(service_defs) == 0:
#            err = failure.Failure ( error.PayloadError('No service definition element in message') )
#            return self._createSOAPFault(err, header.provider_nsa, service_type=service_type)

#        if len(service_defs) != 1:
#            err = failure.Failure ( error.PayloadError('Only one service definition allowed') )
#            return self._createSOAPFault(err, header.provider_nsa, service_type=service_type)

        if type(p2ps) is not p2pservices.P2PServiceBaseType:
            err = failure.Failure ( error.PayloadError('Only supports Point2PointService service for now.') )
            return self._createSOAPFault(err, header.provider_nsa, service_type=service_type)

        if p2ps.directionality in (None, ''):
            err = failure.Failure ( error.MissingParameterError('Directionality parameter not defined'))
            return self._createSOAPFault(err, header.provider_nsa)

        # create DTOs (EROs not supported yet)

        start_time = xmlhelper.parseXMLTimestamp(criteria.schedule.startTime) if criteria.schedule.startTime is not None else None
        end_time = xmlhelper.parseXMLTimestamp(criteria.schedule.endTime) if criteria.schedule.endTime is not None else None
        schedule = nsa.Schedule(start_time, end_time)

        src_stp = helper.createSTP(p2ps.sourceSTP)
        dst_stp = helper.createSTP(p2ps.destSTP)

        if p2ps.ero:
            err = failure.Failure ( error.PayloadError('ERO not supported, go away.') )
            return self._createSOAPFault(err, header.provider_nsa)

#        if p2ps.parameter:
#            p = p2ps.parameter[0]
#            err = failure.Failure ( error.UnsupportedParameter('Unsupported parameter: %s/%s' % (p.type_, p.value) ) )
#            return self._createSOAPFault(err, header.provider_nsa)
        params = [ (p.type_, p.value) for p in p2ps.parameter ] if p2ps.parameter else None
        symmetric = p2ps.symmetricPath or False # the p2p service specifies default behaviour as false, but doesn't specify default
        sd = nsa.Point2PointService(src_stp, dst_stp, p2ps.capacity, p2ps.directionality, symmetric, None, params)

        crt = nsa.Criteria(criteria.version, schedule, sd)

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

        d = self.provider.reserve(header, reservation.connectionId, reservation.globalReservationId, reservation.description, crt, request_info)

        def createReserveAcknowledgement(connection_id):
            # no reply to / security attrs / trace
            soap_header_element = helper.createProviderHeader(header.requester_nsa, header.provider_nsa, None, header.correlation_id)

            reserve_response = nsiconnection.ReserveResponseType(connection_id)
            reserve_response_element = reserve_response.xml(nsiconnection.reserveResponse)

            payload = minisoap.createSoapPayload(reserve_response_element, soap_header_element)
            return payload


        d.addCallbacks(createReserveAcknowledgement, self._createSOAPFault, errbackArgs=(header.provider_nsa,))
        return d