<commit_before>"""
OpenNSA NSI Service -> Backend adaptor (router).

Author: <NAME> <<EMAIL>>
Copyright: NORDUnet (2011)
"""

from zope.interface import implements

from opennsa.interface import NSIServiceInterface



class NSIRouterAdaptor:

    implements(NSIServiceInterface)

    def __init__(self, network, backend):
        self.network = network
        self.backend = backend


    def reserve(self, requester_nsa, provider_nsa, reservation_id, description, connection_id,
                service_parameters, session_security_attributes):

        source_stp = service_parameters.source_stp
        dest_stp   = service_parameters.dest_stp

        if source_stp.network != self.network:
            raise ReserveError('Invalid source network')
        if dest_stp.network != self.network:
            raise ReserveError('Invalid dest network')
        if service_parameters.stps:
            raise ReserveError('Sub-connections cannot be specified in router adaptor')

        d = self.backend.reserve(source_stp.endpoint, dest_stp.endpoint, service_parameters)
        return d


    def cancelReservation(self, requester_nsa, provider_nsa, connection_id, session_security_attributes):

        d = self.backend.cancelReservation(connection_id)
        return d


    def provision(self, requester_nsa, provider_nsa, connection_id, session_security_attributes):

        d = self.backend.provision(connection_id)
        return d


    def releaseProvision(self, requester_nsa, provider_nsa, connection_id, session_security_attributes):

        d = self.backend.releaseProvision(connection_id)
        return d


    def query(self, requester_nsa, provider_nsa, session_security_attributes):

        raise NotImplementedError('NSIService Query for Router adaptor not implemented.')


<commit_msg>return correct values to the client in nsirouter<commit_after>"""
OpenNSA NSI Service -> Backend adaptor (router).

Author: <NAME> <<EMAIL>>
Copyright: NORDUnet (2011)
"""

from zope.interface import implements

from opennsa.interface import NSIServiceInterface



class NSIRouterAdaptor:

    implements(NSIServiceInterface)

    def __init__(self, network, backend):
        self.network = network
        self.backend = backend


    def reserve(self, requester_nsa, provider_nsa, reservation_id, description, connection_id,
                service_parameters, session_security_attributes):

        source_stp = service_parameters.source_stp
        dest_stp   = service_parameters.dest_stp

        if source_stp.network != self.network:
            raise ReserveError('Invalid source network')
        if dest_stp.network != self.network:
            raise ReserveError('Invalid dest network')
        if service_parameters.stps:
            raise ReserveError('Sub-connections cannot be specified in router adaptor')

        d = self.backend.reserve(source_stp.endpoint, dest_stp.endpoint, service_parameters)
        #d.addCallback(lambda internal_reservation_id : reservation_id) # client should not get internal reservation id
        return d


    def cancelReservation(self, requester_nsa, provider_nsa, connection_id, session_security_attributes):

        d = self.backend.cancelReservation(connection_id)
        return d


    def provision(self, requester_nsa, provider_nsa, connection_id, session_security_attributes):

        d = self.backend.provision(connection_id)
        d.addCallback(lambda internal_connection_id : connection_id)
        return d


    def releaseProvision(self, requester_nsa, provider_nsa, connection_id, session_security_attributes):

        d = self.backend.releaseProvision(connection_id)
        return d


    def query(self, requester_nsa, provider_nsa, session_security_attributes):

        raise NotImplementedError('NSIService Query for Router adaptor not implemented.')



{'fraction_non_alphanumeric': 0.071875, 'fraction_numerical': 0.0020833333333333333, 'mean_word_length': 3.6501210653753025, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7017551', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1030, 'n_words': 258}