# Path: opennsa/error.py
# LOG_SYSTEM = 'error'
# NSI_ERROR_CODE_TABLE = {
#     '00100' : PayloadError,
#     '00101' : MissingParameterError,
#     '00200' : ConnectionError,
#     '00201' : InvalidTransitionError,
#     '00202' : ConnectionExistsError,
#     '00203' : ConnectionNonExistentError,
#     '00204' : ConnectionGoneError,
#     '00205' : ConnectionCreateError,
#     '00300' : SecurityError,
#     '00301' : AuthenticationFailure,
#     '00302' : UnauthorizedError,
#     '00400' : TopologyError,
#     '00401' : UnknownSTPError,                      # compat
#     '00402' : STPResolutionError,                   # compat
#     '00403' : NoPathFoundError,
#     '00404' : VLANInterchangeNotSupportedError,     # compat
#     '00500' : InternalServerError,
#     '00501' : InternalNRMError,
#     '00600' : ResourceUnavailableError,
#     '00601' : STPUnavailableError,                  # compat
#     '00602' : BandwidthUnavailableError,            # compat
#     '00700' : ServiceError,
#     '00701' : UnknownSTPError,
#     '00702' : STPResolutionError,
#     '00703' : VLANInterchangeNotSupportedError,
#     '00704' : STPUnavailableError,
#     '00705' : BandwidthUnavailableError             # compat
# }
# class CallbackTimeoutError(Exception):
# class NSIError(Exception):
# class UnknownNSIError(NSIError):
# class PayloadError(NSIError):
# class MissingParameterError(PayloadError):
# class UnsupportedParameter(PayloadError):
# class ConnectionError(NSIError):
# class InvalidTransitionError(ConnectionError):
# class ConnectionExistsError(ConnectionError):
# class ConnectionNonExistentError(ConnectionError):
# class ConnectionGoneError(ConnectionError):
# class ConnectionCreateError(ConnectionError):
# class SecurityError(NSIError):
# class AuthenticationFailure(SecurityError):
# class UnauthorizedError(SecurityError):
# class TopologyError(NSIError):
# class NoPathFoundError(NSIError):
# class InternalServerError(NSIError):
# class InternalNRMError(InternalServerError):
# class DownstreamNSAError(InternalServerError):
# class ResourceUnavailableError(NSIError):
# class ServiceError(NSIError): # only use this if nothing else applies
# class UnknownSTPError(ServiceError):
# class STPResolutionError(NSIError):
# class VLANInterchangeNotSupportedError(TopologyError):
# class STPUnavailableError(ServiceError, TopologyError): # need this to be a topology error internally
# class BandwidthUnavailableError(ServiceError): # NSI error name is CAPACITY_UNAVAILABLE
#     def __init__(self, message, nsa_id=None, connection_id=None, variables=None):
# def lookup(error_code):
# 
# Path: opennsa/constants.py
# URN_OGF_PREFIX      = 'urn:ogf:network:'
# CS2_SERVICE_TYPE    = 'application/vnd.org.ogf.nsi.cs.v2+soap'
# NML_SERVICE_TYPE    = 'application/vnd.ogf.nsi.topology.v2+xml'
# CS2_REQUESTER       = 'application/vnd.ogf.nsi.cs.v2.requester+soap'
# CS2_PROVIDER        = 'application/vnd.ogf.nsi.cs.v2.provider+soap'
# OPENNSA_REST        = 'application/vnd.net.nordu.opennsa+rest'
# BIDIRECTIONAL       = 'Bidirectional'
# EVTS_AGOLE          = 'http://services.ogf.org/nsi/2013/07/descriptions/EVTS.A-GOLE'
# ETHERNET            = 'ethernet' # bidirectional implied
# ETHERNET_VLAN       = 'vlan'
# MPLS                = 'mpls'
# RESTRICTTRANSIT     = 'restricttransit'
# ETHERNET_NS         = 'http://schemas.ogf.org/nml/2012/10/ethernet'
# NML_ETHERNET_VLAN   = '%s#vlan' % ETHERNET_NS
# NML_MPLS            = 'http://nsi.nordu.net/nml#mpls' # pretty much just made up
# FEATURE_AGGREGATOR  = 'vnd.ogf.nsi.cs.v2.role.aggregator'
# FEATURE_UPA         = 'vnd.ogf.nsi.cs.v2.role.uPA'
# REQUIRE_USER        = 'requireuser'
# REQUIRE_TRACE       = 'requiretrace'
# AGGREGATOR          = 'aggregator'
# ALLOW_HAIRPIN       = 'allowhairpin'


import uuid
import random
import itertools
from urllib.parse import urlparse
from opennsa import error, constants as cnt
    def __eq__(self, other):
        if not type(other) is Label:
            return False
        return self.type_ == other.type_ and sorted(self.values) == sorted(other.values)


    def __repr__(self):
        return '<Label %s:%s>' % (self.type_, self.labelValue())



class STP(object): # Service Termination Point

    def __init__(self, network, port, label=None):
        assert type(network) is str, 'Invalid network type provided for STP (got %s)' % type(network)
        assert type(port) is str, 'Invalid port type provided for STP (got %s)' % type(port)
        assert label is None or type(label) is Label, 'Invalid label type provided for STP'
        self.network = network
        self.port = port
        self.label = label


    def shortName(self):
        base = '%s:%s' % (self.network, self.port)
        if self.label:
            base += '?' + self.label.type_.split('#')[-1] + '=' + self.label.labelValue()
        return base


    def baseURN(self):

# Path: opennsa/error.py
# LOG_SYSTEM = 'error'
# NSI_ERROR_CODE_TABLE = {
#     '00100' : PayloadError,
#     '00101' : MissingParameterError,
#     '00200' : ConnectionError,
#     '00201' : InvalidTransitionError,
#     '00202' : ConnectionExistsError,
#     '00203' : ConnectionNonExistentError,
#     '00204' : ConnectionGoneError,
#     '00205' : ConnectionCreateError,
#     '00300' : SecurityError,
#     '00301' : AuthenticationFailure,
#     '00302' : UnauthorizedError,
#     '00400' : TopologyError,
#     '00401' : UnknownSTPError,                      # compat
#     '00402' : STPResolutionError,                   # compat
#     '00403' : NoPathFoundError,
#     '00404' : VLANInterchangeNotSupportedError,     # compat
#     '00500' : InternalServerError,
#     '00501' : InternalNRMError,
#     '00600' : ResourceUnavailableError,
#     '00601' : STPUnavailableError,                  # compat
#     '00602' : BandwidthUnavailableError,            # compat
#     '00700' : ServiceError,
#     '00701' : UnknownSTPError,
#     '00702' : STPResolutionError,
#     '00703' : VLANInterchangeNotSupportedError,
#     '00704' : STPUnavailableError,
#     '00705' : BandwidthUnavailableError             # compat
# }
# class CallbackTimeoutError(Exception):
# class NSIError(Exception):
# class UnknownNSIError(NSIError):
# class PayloadError(NSIError):
# class MissingParameterError(PayloadError):
# class UnsupportedParameter(PayloadError):
# class ConnectionError(NSIError):
# class InvalidTransitionError(ConnectionError):
# class ConnectionExistsError(ConnectionError):
# class ConnectionNonExistentError(ConnectionError):
# class ConnectionGoneError(ConnectionError):
# class ConnectionCreateError(ConnectionError):
# class SecurityError(NSIError):
# class AuthenticationFailure(SecurityError):
# class UnauthorizedError(SecurityError):
# class TopologyError(NSIError):
# class NoPathFoundError(NSIError):
# class InternalServerError(NSIError):
# class InternalNRMError(InternalServerError):
# class DownstreamNSAError(InternalServerError):
# class ResourceUnavailableError(NSIError):
# class ServiceError(NSIError): # only use this if nothing else applies
# class UnknownSTPError(ServiceError):
# class STPResolutionError(NSIError):
# class VLANInterchangeNotSupportedError(TopologyError):
# class STPUnavailableError(ServiceError, TopologyError): # need this to be a topology error internally
# class BandwidthUnavailableError(ServiceError): # NSI error name is CAPACITY_UNAVAILABLE
#     def __init__(self, message, nsa_id=None, connection_id=None, variables=None):
# def lookup(error_code):
# 
# Path: opennsa/constants.py
# URN_OGF_PREFIX      = 'urn:ogf:network:'
# CS2_SERVICE_TYPE    = 'application/vnd.org.ogf.nsi.cs.v2+soap'
# NML_SERVICE_TYPE    = 'application/vnd.ogf.nsi.topology.v2+xml'
# CS2_REQUESTER       = 'application/vnd.ogf.nsi.cs.v2.requester+soap'
# CS2_PROVIDER        = 'application/vnd.ogf.nsi.cs.v2.provider+soap'
# OPENNSA_REST        = 'application/vnd.net.nordu.opennsa+rest'
# BIDIRECTIONAL       = 'Bidirectional'
# EVTS_AGOLE          = 'http://services.ogf.org/nsi/2013/07/descriptions/EVTS.A-GOLE'
# ETHERNET            = 'ethernet' # bidirectional implied
# ETHERNET_VLAN       = 'vlan'
# MPLS                = 'mpls'
# RESTRICTTRANSIT     = 'restricttransit'
# ETHERNET_NS         = 'http://schemas.ogf.org/nml/2012/10/ethernet'
# NML_ETHERNET_VLAN   = '%s#vlan' % ETHERNET_NS
# NML_MPLS            = 'http://nsi.nordu.net/nml#mpls' # pretty much just made up
# FEATURE_AGGREGATOR  = 'vnd.ogf.nsi.cs.v2.role.aggregator'
# FEATURE_UPA         = 'vnd.ogf.nsi.cs.v2.role.uPA'
# REQUIRE_USER        = 'requireuser'
# REQUIRE_TRACE       = 'requiretrace'
# AGGREGATOR          = 'aggregator'
# ALLOW_HAIRPIN       = 'allowhairpin'


# Path: opennsa/nsa.py
import uuid
import random
import itertools
from urllib.parse import urlparse
from opennsa import error, constants as cnt

    def __eq__(self, other):
        if not type(other) is Label:
            return False
        return self.type_ == other.type_ and sorted(self.values) == sorted(other.values)


    def __repr__(self):
        return '<Label %s:%s>' % (self.type_, self.labelValue())



class STP(object): # Service Termination Point

    def __init__(self, network, port, label=None):
        assert type(network) is str, 'Invalid network type provided for STP (got %s)' % type(network)
        assert type(port) is str, 'Invalid port type provided for STP (got %s)' % type(port)
        assert label is None or type(label) is Label, 'Invalid label type provided for STP'
        self.network = network
        self.port = port
        self.label = label


    def shortName(self):
        base = '%s:%s' % (self.network, self.port)
        if self.label:
            base += '?' + self.label.type_.split('#')[-1] + '=' + self.label.labelValue()
        return base


    def baseURN(self):

        return cnt.URN_OGF_PREFIX + self.network + ':' + self.port