Пример #1
0
    def gotDocument(self, result, peer):

        if result is None:
            log.msg('Got empty NSA discovery document (URL: %s)' % peer.url, system=LOG_SYSTEM)
            return

        log.msg('Got NSA description from %s (%i bytes)' % (peer.url, len(result)), debug=True, system=LOG_SYSTEM)
        try:
            nsa_description = discovery.parse(result)

            nsa_id = nsa_description.id_

            cs_service_url = None
            for i in nsa_description.interface:
                if i.type_ == cnt.CS2_PROVIDER:
                    cs_service_url = i.href
                elif i.type_ == cnt.CS2_SERVICE_TYPE and cs_service_url is None: # compat, only overwrite if cs prov not specified
                    cs_service_url = i.href

            if cs_service_url is None:
                log.msg('NSA description does not have CS interface url, discarding description', system=LOG_SYSTEM)
                return

            network_ids = [ _baseName(nid) for nid in nsa_description.networkId if nid.startswith(cnt.URN_OGF_PREFIX) ] # silent discard weird stuff

            nsi_agent = nsa.NetworkServiceAgent( _baseName(nsa_id), cs_service_url, cnt.CS2_SERVICE_TYPE)

            self.provider_registry.spawnProvider(nsi_agent, network_ids)

            # first, build vectors
            vectors = {}
            if nsa_description.other is not None:
                for other in nsa_description.other:
                    if other.topologyReachability:
                        for tr in other.topologyReachability:
                            if tr.uri.startswith(cnt.URN_OGF_PREFIX): # silent discard weird stuff
                                vectors[_baseName(tr.uri)] = tr.cost + 1
            for nid in network_ids:
                vectors[nid] = 1

            # update per-port link vectors
            if vectors:
                for np in self.nrm_ports:
                    if np.remote_network in network_ids:
                        # this may add the vectors to multiple ports (though not likely)
                        self.link_vectors.updateVector(np.name, vectors )

            # there is lots of other stuff in the nsa description but we don't really use it


        except Exception as e:
            log.msg('Error parsing NSA description from url %s. Reason %s' % (peer.url, str(e)), system=LOG_SYSTEM)
            import traceback
            traceback.print_exc()
Пример #2
0
    def gotDocument(self, result, peer):
        log.msg('Got NSA description from %s (%i bytes)' % (peer.url, len(result)), debug=True, system=LOG_SYSTEM)
        try:
            nsa_description = discovery.parse(result)

            nsa_id = nsa_description.id_

            cs_service_url = None
            for i in nsa_description.interface:
                if i.type_ == cnt.CS2_PROVIDER:
                    cs_service_url = i.href
                elif i.type_ == cnt.CS2_SERVICE_TYPE and cs_service_url is None: # compat, only overwrite if cs prov not specified
                    cs_service_url = i.href

            if cs_service_url is None:
                log.msg('NSA description does not have CS interface url, discarding description', system=LOG_SYSTEM)
                return

            network_ids = [ _baseName(nid) for nid in nsa_description.networkId if nid.startswith(cnt.URN_OGF_PREFIX) ] # silent discard weird stuff

            nsi_agent = nsa.NetworkServiceAgent( _baseName(nsa_id), cs_service_url, cnt.CS2_SERVICE_TYPE)

            self.provider_registry.spawnProvider(nsi_agent, network_ids)

            # how to port ?
            vectors = {}
            if nsa_description.other is not None:
                for other in nsa_description.other:
                    if other.topologyReachability:
                        for tr in other.topologyReachability:
                            if tr.uri.startswith(cnt.URN_OGF_PREFIX): # silent discard weird stuff
                                vectors[_baseName(tr.uri)] = tr.cost + 1
            for nid in network_ids:
                vectors[nid] = 1

            if vectors:
                for np in self.nrm_ports:
                    if np.remote_network in network_ids:
                        # this may add the vectors to multiple ports (though not likely)
                        self.link_vectors.updateVector(np.name, vectors )

            # there is lots of other stuff in the nsa description but we don't really use it


        except Exception as e:
            log.msg('Error parsing NSA description from url %s. Reason %s' % (peer.url, str(e)), system=LOG_SYSTEM)
            import traceback
            traceback.print_exc()
Пример #3
0
    def testDiscovery(self):

        aruba_discovery_service = 'http://localhost:4080/NSI/discovery.xml'
        bonaire_discovery_service = 'http://localhost:4080/NSI/discovery.xml'

        requester_agent = nsa.NetworkServiceAgent('test-requester:nsa',
                                                  'dud_endpoint1')

        d = httpclient.httpRequest(aruba_discovery_service.encode('utf-8'),
                                   b'', {},
                                   b'GET',
                                   timeout=10)
        aruba_discovery_doc = yield d
        aruba_discovery = discovery.parse(aruba_discovery_doc)

        # basic tests
        self.failUnlessEqual('urn:ogf:network:aruba.net:nsa',
                             aruba_discovery.id_, 'nsa id seems to be wrong')
        self.failUnlessEqual(2, len(aruba_discovery.networkId),
                             'should have two networks')
        self.failUnlessIn('urn:ogf:network:aruba.net:san',
                          aruba_discovery.networkId,
                          'missing network in discovery')
        self.failUnlessIn('urn:ogf:network:aruba.net:san',
                          aruba_discovery.networkId,
                          'missing network in discovery')

        cs_service_url = None
        nml_topologies = []

        for intf in aruba_discovery.interface:
            if intf.type_ == constants.CS2_SERVICE_TYPE:
                cs_service_url = intf.href
            elif intf.type_ == constants.NML_SERVICE_TYPE:
                nml_topologies.append(intf.href)

        self.failIfEqual(cs_service_url, None, 'No service url found')