#NEWLINE# def parsePortSpec( source ) : #NEWLINE# #INDENT# assert ( isinstance ( source , file ) or isinstance ( source , StringIO . StringIO ) ) , 'Topology source must be file or StringIO instance' #NEWLINE# nrm_ports = [ ] #NEWLINE# for line in source : #NEWLINE# #INDENT# line = line . strip ( ) #NEWLINE# if ( ( not line ) or line . startswith ( '#' ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# tokens = [ t for t in line . split ( ' ' ) if ( t != '' ) ] #NEWLINE# if ( len ( tokens ) != 7 ) : #NEWLINE# #INDENT# raise NRMSpecificationError ( ( 'Invalid number of entries for entry: %s' % line ) ) #NEWLINE# #UNINDENT# ( port_type , port_name , remote_spec , label_spec , bandwidth , interface , authz_spec ) = tokens #NEWLINE# if ( not ( port_type in PORT_TYPES ) ) : #NEWLINE# #INDENT# raise error . TopologyError ( ( 'Port type %s is not a valid port type' % port_type ) ) #NEWLINE# #UNINDENT# ( remote_network , remote_port , in_suffix , out_suffix ) = _parseRemoteSpec ( remote_spec ) #NEWLINE# label = _parseLabelSpec ( label_spec ) #NEWLINE# try : #NEWLINE# #INDENT# bandwidth = int ( bandwidth ) #NEWLINE# #UNINDENT# except ValueError as e : #NEWLINE# #INDENT# raise NRMSpecificationError ( ( 'Invalid bandwidth: %s' % str ( e ) ) ) #NEWLINE# #UNINDENT# if ( port_type == cnt . NRM_ETHERNET ) : #NEWLINE# #INDENT# if ( remote_network is None ) : #NEWLINE# #INDENT# remote_port = None #NEWLINE# remote_in = None #NEWLINE# remote_out = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not in_suffix ) or ( not out_suffix ) ) : #NEWLINE# #INDENT# raise NRMSpecificationError ( ( 'Suffix not defined for bidirectional port %s' % port_name ) ) #NEWLINE# #UNINDENT# remote_port = ( ( remote_network + ':' ) + remote_port ) #NEWLINE# remote_in = ( remote_port + in_suffix ) #NEWLINE# remote_out = ( remote_port + out_suffix ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise AssertionError ( ( 'do not know what to with port of type %s' % port_type ) ) #NEWLINE# #UNINDENT# authz_attributes = [ ] #NEWLINE# link_vectors = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# transit_restricted = False #NEWLINE# if ( authz_spec != '-' ) : #NEWLINE# #INDENT# for aa in authz_spec . split ( ',' ) : #NEWLINE# #INDENT# if ( '=' in aa ) : #NEWLINE# #INDENT# ( ak , av ) = aa . split ( '=' , 2 ) #NEWLINE# if ( ak in authz . AUTH_ATTRIBUTES ) : #NEWLINE# #INDENT# if ( ak in authz . HEADER_ATTRIBUTES ) : #NEWLINE# #INDENT# log . msg ( ( "WARNING: Port %s: Using header attribute %s as authorization isn't really secure. Be careful." % ( port_name , ak ) ) ) #NEWLINE# #UNINDENT# authz_attributes . append ( authz . AuthorizationAttribute ( ak , av ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ak in PATH_ATTRIBUTES ) : #NEWLINE# #INDENT# if ( not ( '@' in av ) ) : #NEWLINE# #INDENT# raise config . ConfigurationError ( ( 'Invalid path value: %s' % av ) ) #NEWLINE# #UNINDENT# ( network , weight ) = av . split ( '@' , 1 ) #NEWLINE# link_vectors [ network ] = int ( weight ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise config . ConfigurationError ( ( 'Invalid attribute: %s' % aa ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( aa in ATTRIBUTES ) and ( aa == cnt . NRM_RESTRICTTRANSIT ) ) : #NEWLINE# #INDENT# transit_restricted = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise config . ConfigurationError ( ( 'Invalid attribute: %s' % aa ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# nrm_ports . append ( NRMPort ( port_type , port_name , remote_network , remote_port , remote_in , remote_out , label , bandwidth , interface , authz_attributes , link_vectors , transit_restricted ) ) #NEWLINE# #UNINDENT# return nrm_ports