Exemplo n.º 1
0
def buildQuerySummaryResultType(connection_infos):

    query_results = []
    for ci in connection_infos:

        criterias = []
        for crit in ci.criterias:
            sched_start_time = createXMLTime(
                crit.schedule.start_time
            ) if crit.schedule.start_time is not None else None
            sched_end_time = createXMLTime(
                crit.schedule.end_time
            ) if crit.schedule.end_time is not None else None
            schedule = nsiconnection.ScheduleType(sched_start_time,
                                                  sched_end_time)
            service_type = cnt.EVTS_AGOLE
            service_def = buildServiceDefinitionType(crit.service_def)
            children = []
            criteria = nsiconnection.QuerySummaryResultCriteriaType(
                crit.revision, schedule, service_type, children, service_def)
            criterias.append(criteria)

        connection_states = buildConnectionStatesType(ci.states)

        qsrt = nsiconnection.QuerySummaryResultType(
            ci.connection_id, ci.global_reservation_id, ci.description,
            criterias, ci.requester_nsa, connection_states, ci.notification_id,
            ci.result_id)
        query_results.append(qsrt)

    return query_results
Exemplo n.º 2
0
    def xml(self):

        # location not really supported yet
        interface_types = [ discovery.InterfaceType(i[0], i[1], i[2]) for i in self.interfaces ]
        feature_types   = [ discovery.FeatureType(f[0], f[1]) for f in self.features ]

        peers_with = self.provider_registry.providers.keys()
        try:
            peers_with.remove(self.nsa_id)
        except ValueError:
            pass # running in aggregetor-only mode

        topology_vectors = [ (cnt.URN_OGF_PREFIX + tv, cost) for tv, cost in self.link_vector.listVectors().items() ]
        other = discovery.HolderType( [ discovery.Topology(t,c) for (t,c) in topology_vectors ] )

        nsa_element = discovery.NsaType(
            self.nsa_id,
            xmlhelper.createXMLTime(self.version),
            None,
            self.name,
            self.software_version,
            xmlhelper.createXMLTime(self.start_time),
            self.network_ids,
            interface_types,
            feature_types,
            peers_with,
            other,
           )

        e = nsa_element.xml(discovery.nsa)
        payload = ET.tostring(e, 'utf-8')
        return payload
Exemplo n.º 3
0
    def xml(self):

        # location not really supported yet
        interface_types = [
            discovery.InterfaceType(i[0], i[1], i[2]) for i in self.interfaces
        ]
        feature_types = [
            discovery.FeatureType(f[0], f[1]) for f in self.features
        ]

        # if we have multiple networks, we get the provider urn multiple times
        peers_with = set(self.provider_registry.provider_urns.values())

        try:
            peers_with.remove(self.nsa_id)
        except ValueError:
            pass  # running in aggregator-only mode

        nsa_element = discovery.NsaType(
            self.nsa_id,
            xmlhelper.createXMLTime(self.version),
            None,
            self.name,
            self.software_version,
            xmlhelper.createXMLTime(self.start_time),
            self.network_ids,
            interface_types,
            feature_types,
            peers_with,
            None,
        )

        e = nsa_element.xml(discovery.nsa)
        payload = ET.tostring(e, 'utf-8')
        return payload
Exemplo n.º 4
0
    def reserveConfirmed(self, nsi_header, connection_id, global_reservation_id, description, criteria):

        header_element = helper.createRequesterHeader(nsi_header.requester_nsa, nsi_header.provider_nsa, correlation_id=nsi_header.correlation_id)

        schedule = nsiconnection.ScheduleType(
            xmlhelper.createXMLTime(criteria.schedule.start_time) if criteria.schedule.start_time is not None else None,
            xmlhelper.createXMLTime(criteria.schedule.end_time)   if criteria.schedule.end_time   is not None else None
        )

        sd = criteria.service_def

        # we only support p2p for now
        p2p = p2pservices.P2PServiceBaseType(sd.capacity, sd.directionality, sd.symmetric, sd.source_stp.urn(), sd.dest_stp.urn(), None, [])

        criteria = nsiconnection.ReservationConfirmCriteriaType(criteria.revision, schedule, cnt.EVTS_AGOLE, str(p2pservices.p2ps), p2p)

        reserve_conf = nsiconnection.ReserveConfirmedType(connection_id, global_reservation_id, description, criteria)

        body_element = reserve_conf.xml(nsiconnection.reserveConfirmed)
        payload = minisoap.createSoapPayload(body_element, header_element)

        def gotReply(data):
            # we don't really do anything about these
            return ""

        d = httpclient.soapRequest(nsi_header.reply_to, actions.RESERVE_CONFIRMED, payload, ctx_factory=self.ctx_factory)
        d.addCallbacks(gotReply) #, errReply)
        return d
Exemplo n.º 5
0
    def reserveTimeout(
        self,
        requester_url,
        requester_nsa,
        provider_nsa,
        correlation_id,
        connection_id,
        notification_id,
        timestamp,
        timeout_value,
        originating_connection_id,
        originating_nsa,
    ):

        header_element = helper.createRequesterHeader(requester_nsa, provider_nsa, correlation_id=correlation_id)

        reserve_timeout = nsiconnection.ReserveTimeoutRequestType(
            connection_id,
            notification_id,
            xmlhelper.createXMLTime(timestamp),
            timeout_value,
            originating_connection_id,
            originating_nsa,
        )

        body_element = reserve_timeout.xml(nsiconnection.reserveTimeout)

        payload = minisoap.createSoapPayload(body_element, header_element)

        d = httpclient.soapRequest(requester_url, actions.RESERVE_TIMEOUT, payload, ctx_factory=self.ctx_factory)
        return d
Exemplo n.º 6
0
    def dataPlaneStateChange(
        self,
        requester_url,
        requester_nsa,
        provider_nsa,
        correlation_id,
        connection_id,
        notification_id,
        timestamp,
        active,
        version,
        consistent,
    ):

        header_element = helper.createRequesterHeader(requester_nsa, provider_nsa, correlation_id=correlation_id)

        data_plane_status = nsiconnection.DataPlaneStatusType(active, version, consistent)
        dps = nsiconnection.DataPlaneStateChangeRequestType(
            connection_id, notification_id, xmlhelper.createXMLTime(timestamp), data_plane_status
        )

        body_element = dps.xml(nsiconnection.dataPlaneStateChange)

        payload = minisoap.createSoapPayload(body_element, header_element)

        d = httpclient.soapRequest(
            requester_url, actions.DATA_PLANE_STATE_CHANGE, payload, ctx_factory=self.ctx_factory
        )
        return d
Exemplo n.º 7
0
    def errorEvent(self, requester_url, requester_nsa, provider_nsa,
                   correlation_id, connection_id, notification_id, timestamp,
                   event, info, service_ex):

        header_element = helper.createRequesterHeader(
            requester_nsa, provider_nsa, correlation_id=correlation_id)

        if service_ex:
            nsa_id, connection_id, error_id, text, variables, child_ex = service_ex
            service_exception = nsiconnection.ServiceExceptionType(
                nsa_id, connection_id, error_id, text, None, None)
        else:
            service_exception = None

        org_connection_id = None
        org_nsa_id = None
        additional_info = None
        error_event = nsiconnection.ErrorEventType(
            connection_id, notification_id, xmlhelper.createXMLTime(timestamp),
            event, org_connection_id, org_nsa_id, additional_info,
            service_exception)

        body_element = error_event.xml(nsiconnection.errorEvent)

        payload = minisoap.createSoapPayload(body_element, header_element)

        d = httpclient.soapRequest(requester_url,
                                   actions.ERROR_EVENT,
                                   payload,
                                   ctx_factory=self.ctx_factory)
        return d
Exemplo n.º 8
0
def conn2dict(conn):
    def label(label):
        if label is None:
            return ''
        else:
            return '?%s=%s' % (label.type_, label.labelValue())

    d = {}

    d['connection_id'] = conn.connection_id
    d[START_TIME] = xmlhelper.createXMLTime(
        conn.start_time) if conn.start_time is not None else None
    d[END_TIME] = xmlhelper.createXMLTime(
        conn.end_time) if conn.end_time is not None else None
    d['source'] = '%s:%s%s' % (conn.source_network, conn.source_port,
                               label(conn.source_label))
    d['destination'] = '%s:%s%s' % (conn.dest_network, conn.dest_port,
                                    label(conn.dest_label))
    d['capacity'] = conn.bandwidth
    d['created'] = xmlhelper.createXMLTime(conn.reserve_time)
    d['reservation_state'] = conn.reservation_state
    d['provision_state'] = conn.provision_state
    d['lifecycle_state'] = conn.lifecycle_state

    # this really needs to be in the database module (aggregator uses this too)
    df = database.SubConnection.findBy(service_connection_id=conn.id)
    sub_conns = yield df

    # copied from aggregator, refactor sometime
    if len(sub_conns) == 0:  # apparently this can happen
        data_plane_status = (False, 0, False)
    else:
        aggr_active = all([sc.data_plane_active for sc in sub_conns])
        aggr_version = max([sc.data_plane_version
                            for sc in sub_conns]) or 0  # can be None otherwise
        aggr_consistent = all([sc.data_plane_consistent for sc in sub_conns])
        data_plane_status = (aggr_active, aggr_version, aggr_consistent)

    d['data_plane_active'] = conn.data_plane = data_plane_status[0]

    #return d
    defer.returnValue(d)
Exemplo n.º 9
0
def topologyXML(network, labelSwap=False):
    # creates nml:Topology object from an nml network

    BASE_URN = cnt.URN_OGF_PREFIX + network.id_

    topology_id = cnt.URN_OGF_PREFIX + network.id_
    nml_topology = ET.Element(NML_TOPOLOGY, {ID: topology_id, VERSION: xmlhelper.createXMLTime(network.version) } )

    ET.SubElement(nml_topology, NML_NAME).text = network.name

    portName = lambda port : BASE_URN + ':' + port.name

    def addPort(nml_port_relation, port):
        nml_port = ET.SubElement(nml_port_relation, NML_PORTGROUP, {ID: portName(port)} )
        label = port.label()
        if label:
            ln = ET.SubElement(nml_port, NML_LABELGROUP, { LABEL_TYPE : NML_LABEL_MAPPING[label.type_] } )
            ln.text = label.labelValue()
        if port.remote_port is not None:
            rpa = ET.SubElement(nml_port, NML_RELATION, { TYPE : NML_ISALIAS} )
            ET.SubElement(rpa, NML_PORTGROUP, { ID : cnt.URN_OGF_PREFIX + port.remote_port})

    for port in network.bidirectional_ports:
        pn = ET.SubElement(nml_topology, NML_BIDIRECTIONALPORT, { ID: portName(port) } )
        ET.SubElement(pn, NML_NAME).text = port.name
        ET.SubElement(pn, NML_PORTGROUP, {ID: BASE_URN + ':' + port.inbound_port.name} )
        ET.SubElement(pn, NML_PORTGROUP, {ID: BASE_URN + ':' + port.outbound_port.name} )

    if network.inbound_ports:
        nml_inbound_ports = ET.SubElement(nml_topology, NML_RELATION, {TYPE: NML_HASINBOUNDPORT})
        for port in network.inbound_ports:
            addPort(nml_inbound_ports, port)

    if network.outbound_ports:
        nml_outbound_ports = ET.SubElement(nml_topology, NML_RELATION, {TYPE: NML_HASOUTBOUNDPORT})
        for port in network.outbound_ports:
            addPort(nml_outbound_ports, port)

    service_def_id = topology_id + ':sd:EVTS.A-GOLE'
    service_def = ET.SubElement(nml_topology, NSI_SERVICE_DEFINITION, { ID: service_def_id } )
    ET.SubElement(service_def, 'name').text = 'GLIF Automated GOLE Ethernet VLAN Transfer Service'
    ET.SubElement(service_def, 'serviceType').text = cnt.EVTS_AGOLE

    switch_id = topology_id + ':switch:EVTS.A-GOLE'
    labelSwapping = 'true' if labelSwap else 'false'
    switch_attrib = { ID: switch_id, LABEL_SWAPPING: labelSwapping, LABEL_TYPE_CAMEL : cnt.NML_ETHERNET_VLAN }

    service_rel = ET.SubElement(nml_topology, NML_RELATION, { 'type': NML_HASSERVICE} )
    switch = ET.SubElement(service_rel, NML_SWITCHINGSERVICE, switch_attrib)

    ET.SubElement(switch, NSI_SERVICE_DEFINITION, { ID: service_def_id } )

    return nml_topology
Exemplo n.º 10
0
    def buildQueryRecursiveResultCriteriaType(criteria):
        assert type(
            criteria
        ) is nsa.QueryCriteria, 'Wrong criteria type for buildQueryRecursiveResultCriteriaType: %s' % (
            str(criteria))

        # handle optional start / end time
        start_time = createXMLTime(
            criteria.schedule.start_time
        ) if criteria.schedule.start_time is not None else None
        end_time = createXMLTime(
            criteria.schedule.end_time
        ) if criteria.schedule.end_time is not None else None
        schedule = nsiconnection.ScheduleType(start_time, end_time)

        service_type = str(
            p2pservices.p2ps
        )  # we need this to have the bindings working properly
        service_def = buildServiceDefinitionType(criteria.service_def)

        crts = []
        for idx, child in enumerate(criteria.children):
            assert type(
                child
            ) is nsa.ConnectionInfo, 'Invalid child criteria type for buildQueryRecursiveResultCriteriaType: %s' % str(
                type(child))

            sub_states = buildConnectionStatesType(child.states)
            sub_qrrct = [
                buildQueryRecursiveResultCriteriaType(sc)
                for sc in child.criterias
            ]
            crt = nsiconnection.ChildRecursiveType(idx, child.connection_id,
                                                   child.provider_nsa,
                                                   sub_states, sub_qrrct)
            crts.append(crt)

        qrrct = nsiconnection.QueryRecursiveResultCriteriaType(
            criteria.revision, schedule, service_type, crts, service_def)
        return qrrct
Exemplo n.º 11
0
    def xml(self):

        # location not really supported yet
        interface_types = [
            discovery.InterfaceType(i[0], i[1], i[2]) for i in self.interfaces
        ]
        feature_types = [
            discovery.FeatureType(f[0], f[1]) for f in self.features
        ]

        peers_with = self.provider_registry.providers.keys()
        try:
            peers_with.remove(self.nsa_id)
        except ValueError:
            pass  # running in aggregetor-only mode

        topology_vectors = [
            (cnt.URN_OGF_PREFIX + tv, cost)
            for tv, cost in self.link_vector.listVectors().items()
        ]
        other = discovery.HolderType(
            [discovery.Topology(t, c) for (t, c) in topology_vectors])

        nsa_element = discovery.NsaType(
            self.nsa_id,
            xmlhelper.createXMLTime(self.version),
            None,
            self.name,
            self.software_version,
            xmlhelper.createXMLTime(self.start_time),
            self.network_ids,
            interface_types,
            feature_types,
            peers_with,
            other,
        )

        e = nsa_element.xml(discovery.nsa)
        payload = ET.tostring(e, 'utf-8')
        return payload
Exemplo n.º 12
0
def conn2dict(conn):

    def label(label):
        if label is None:
            return ''
        else:
            return '?%s=%s' % (label.type_, label.labelValue())

    d = {}

    d['connection_id']     = conn.connection_id
    d['start_time']        = xmlhelper.createXMLTime(conn.start_time) if conn.start_time is not None else None
    d['end_time']          = xmlhelper.createXMLTime(conn.end_time)   if conn.end_time   is not None else None
    d['source']            = '%s:%s%s' % (conn.source_network, conn.source_port, label(conn.source_label))
    d['destination']       = '%s:%s%s' % (conn.dest_network, conn.dest_port, label(conn.dest_label))
    d['bandwidth']         = conn.bandwidth
    d['created']           = xmlhelper.createXMLTime(conn.reserve_time)
    d['reservation_state'] = conn.reservation_state
    d['provision_state']   = conn.provision_state
    d['lifecycle_state']   = conn.lifecycle_state

    # this really needs to be in the database module (aggregator uses this too)
    df = database.SubConnection.findBy(service_connection_id=conn.id)
    sub_conns = yield df

    # copied from aggregator, refactor sometime
    if len(sub_conns) == 0: # apparently this can happen
        data_plane_status = (False, 0, False)
    else:
        aggr_active     = all( [ sc.data_plane_active     for sc in sub_conns ] )
        aggr_version    = max( [ sc.data_plane_version    for sc in sub_conns ] ) or 0 # can be None otherwise
        aggr_consistent = all( [ sc.data_plane_consistent for sc in sub_conns ] )
        data_plane_status = (aggr_active, aggr_version, aggr_consistent)

    d['data_plane_active'] = conn.data_plane = data_plane_status[0]

    #return d
    defer.returnValue(d)
Exemplo n.º 13
0
def buildQuerySummaryResultType(connection_infos):

    query_results = []
    for ci in connection_infos:

        criterias = []
        for crit in ci.criterias:
            sched_start_time = createXMLTime(crit.schedule.start_time) if crit.schedule.start_time is not None else None
            schedule = nsiconnection.ScheduleType(sched_start_time, createXMLTime(crit.schedule.end_time))
            #service_type = cnt.EVTS_AGOLE
            service_type = str(p2pservices.p2ps) # we need this to have the bindings working properly
            service_def = buildServiceDefinitionType(crit.service_def)
            children = []
            criteria = nsiconnection.QuerySummaryResultCriteriaType(crit.revision, schedule, service_type, children, service_def)
            criterias.append(criteria)

        connection_states = buildConnectionStatesType(ci.states)

        qsrt = nsiconnection.QuerySummaryResultType(ci.connection_id, ci.global_reservation_id, ci.description, criterias,
                                                    ci.requester_nsa, connection_states, ci.notification_id, ci.result_id)
        query_results.append(qsrt)

    return query_results
Exemplo n.º 14
0
    def buildQueryRecursiveResultCriteriaType(criteria):
        assert type(criteria) is nsa.QueryCriteria, 'Wrong criteria type for buildQueryRecursiveResultCriteriaType: %s' % (str(criteria))

        schedule = nsiconnection.ScheduleType(createXMLTime(criteria.schedule.start_time), createXMLTime(criteria.schedule.end_time))
        #service_type, service_def = buildServiceDefinition(criteria.service_def)
        service_type = str(p2pservices.p2ps) # we need this to have the bindings working properly
        service_def = buildServiceDefinitionType(criteria.service_def)

        crts = []
        for idx, child in enumerate(criteria.children):
            assert type(child) is nsa.ConnectionInfo, 'Invalid child criteria type for buildQueryRecursiveResultCriteriaType: %s' % str(type(child))

            sub_states = buildConnectionStatesType(child.states)
            sub_qrrct = [ buildQueryRecursiveResultCriteriaType( sc ) for sc in child.criterias ]
            crt = nsiconnection.ChildRecursiveType(idx, child.connection_id, child.provider_nsa, sub_states, sub_qrrct)
            crts.append(crt)

        qrrct = nsiconnection.QueryRecursiveResultCriteriaType(criteria.revision, schedule, service_type, crts, service_def)
        return qrrct
Exemplo n.º 15
0
    def errorEvent(
        self,
        requester_url,
        requester_nsa,
        provider_nsa,
        correlation_id,
        connection_id,
        notification_id,
        timestamp,
        event,
        info,
        service_ex,
    ):

        header_element = helper.createRequesterHeader(requester_nsa, provider_nsa, correlation_id=correlation_id)

        if service_ex:
            nsa_id, connection_id, error_id, text, variables, child_ex = service_ex
            service_exception = nsiconnection.ServiceExceptionType(nsa_id, connection_id, error_id, text, None, None)
        else:
            service_exception = None

        org_connection_id = None
        org_nsa_id = None
        additional_info = None
        error_event = nsiconnection.ErrorEventType(
            connection_id,
            notification_id,
            xmlhelper.createXMLTime(timestamp),
            event,
            org_connection_id,
            org_nsa_id,
            additional_info,
            service_exception,
        )

        body_element = error_event.xml(nsiconnection.errorEvent)

        payload = minisoap.createSoapPayload(body_element, header_element)

        d = httpclient.soapRequest(requester_url, actions.ERROR_EVENT, payload, ctx_factory=self.ctx_factory)
        return d
Exemplo n.º 16
0
    def reserveTimeout(self, requester_url, requester_nsa, provider_nsa,
                       correlation_id, connection_id, notification_id,
                       timestamp, timeout_value, originating_connection_id,
                       originating_nsa):

        header_element = helper.createRequesterHeader(
            requester_nsa, provider_nsa, correlation_id=correlation_id)

        reserve_timeout = nsiconnection.ReserveTimeoutRequestType(
            connection_id, notification_id, xmlhelper.createXMLTime(timestamp),
            timeout_value, originating_connection_id, originating_nsa)

        body_element = reserve_timeout.xml(nsiconnection.reserveTimeout)

        payload = minisoap.createSoapPayload(body_element, header_element)

        d = httpclient.soapRequest(requester_url,
                                   actions.RESERVE_TIMEOUT,
                                   payload,
                                   ctx_factory=self.ctx_factory)
        return d
Exemplo n.º 17
0
def topologyXML(network):
    # creates nml:Topology object from an nml network

    BASE_URN = cnt.URN_OGF_PREFIX + network.id_

    topology_id = cnt.URN_OGF_PREFIX + network.id_
    nml_topology = ET.Element(NML_TOPOLOGY, {ID: topology_id, VERSION: xmlhelper.createXMLTime(network.version) } )

    ET.SubElement(nml_topology, NML_NAME).text = network.name

    portName = lambda port : BASE_URN + ':' + port.name

    def addPort(nml_port_relation, port):
        nml_port = ET.SubElement(nml_port_relation, NML_PORTGROUP, {ID: portName(port)} )
        label = port.label()
        if label:
            ln = ET.SubElement(nml_port, NML_LABELGROUP, { LABEL_TYPE : NML_LABEL_MAPPING[label.type_] } )
            ln.text = label.labelValue()
        if port.remote_port is not None:
            rpa = ET.SubElement(nml_port, NML_RELATION, { TYPE : NML_ISALIAS} )
            ET.SubElement(rpa, NML_PORTGROUP, { ID : cnt.URN_OGF_PREFIX + port.remote_port})

    for port in network.bidirectional_ports:
        pn = ET.SubElement(nml_topology, NML_BIDIRECTIONALPORT, { ID: portName(port) } )
        ET.SubElement(pn, NML_NAME).text = port.name
        ET.SubElement(pn, NML_PORTGROUP, {ID: BASE_URN + ':' + port.inbound_port.name} )
        ET.SubElement(pn, NML_PORTGROUP, {ID: BASE_URN + ':' + port.outbound_port.name} )

    if network.inbound_ports:
        nml_inbound_ports = ET.SubElement(nml_topology, NML_RELATION, {TYPE: NML_HASINBOUNDPORT})
        for port in network.inbound_ports:
            addPort(nml_inbound_ports, port)

    if network.outbound_ports:
        nml_outbound_ports = ET.SubElement(nml_topology, NML_RELATION, {TYPE: NML_HASOUTBOUNDPORT})
        for port in network.outbound_ports:
            addPort(nml_outbound_ports, port)

    return nml_topology
Exemplo n.º 18
0
    def dataPlaneStateChange(self, requester_url, requester_nsa, provider_nsa,
                             correlation_id, connection_id, notification_id,
                             timestamp, active, version, consistent):

        header_element = helper.createRequesterHeader(
            requester_nsa, provider_nsa, correlation_id=correlation_id)

        data_plane_status = nsiconnection.DataPlaneStatusType(
            active, version, consistent)
        dps = nsiconnection.DataPlaneStateChangeRequestType(
            connection_id, notification_id, xmlhelper.createXMLTime(timestamp),
            data_plane_status)

        body_element = dps.xml(nsiconnection.dataPlaneStateChange)

        payload = minisoap.createSoapPayload(body_element, header_element)

        d = httpclient.soapRequest(requester_url,
                                   actions.DATA_PLANE_STATE_CHANGE,
                                   payload,
                                   ctx_factory=self.ctx_factory)
        return d
Exemplo n.º 19
0
def topologyXML(network, labelSwap=False):
    # creates nml:Topology object from an nml network

    BASE_URN = cnt.URN_OGF_PREFIX + network.id_

    topology_id = cnt.URN_OGF_PREFIX + network.id_
    nml_topology = ET.Element(NML_TOPOLOGY, {
        ID: topology_id,
        VERSION: xmlhelper.createXMLTime(network.version)
    })

    ET.SubElement(nml_topology, NML_NAME).text = network.name

    portName = lambda port: BASE_URN + ':' + port.name

    def addPort(nml_port_relation, port):
        nml_port = ET.SubElement(nml_port_relation, NML_PORTGROUP,
                                 {ID: portName(port)})
        label = port.label()
        if label:
            ln = ET.SubElement(nml_port, NML_LABELGROUP,
                               {LABEL_TYPE: NML_LABEL_MAPPING[label.type_]})
            ln.text = label.labelValue()
        if port.remote_port is not None:
            rpa = ET.SubElement(nml_port, NML_RELATION, {TYPE: NML_ISALIAS})
            ET.SubElement(rpa, NML_PORTGROUP,
                          {ID: cnt.URN_OGF_PREFIX + port.remote_port})

    for port in network.bidirectional_ports:
        pn = ET.SubElement(nml_topology, NML_BIDIRECTIONALPORT,
                           {ID: portName(port)})
        ET.SubElement(pn, NML_NAME).text = port.name
        ET.SubElement(pn, NML_PORTGROUP,
                      {ID: BASE_URN + ':' + port.inbound_port.name})
        ET.SubElement(pn, NML_PORTGROUP,
                      {ID: BASE_URN + ':' + port.outbound_port.name})

    if network.inbound_ports:
        nml_inbound_ports = ET.SubElement(nml_topology, NML_RELATION,
                                          {TYPE: NML_HASINBOUNDPORT})
        for port in network.inbound_ports:
            addPort(nml_inbound_ports, port)

    if network.outbound_ports:
        nml_outbound_ports = ET.SubElement(nml_topology, NML_RELATION,
                                           {TYPE: NML_HASOUTBOUNDPORT})
        for port in network.outbound_ports:
            addPort(nml_outbound_ports, port)

    service_def_id = topology_id + ':sd:EVTS.A-GOLE'
    service_def = ET.SubElement(nml_topology, NSI_SERVICE_DEFINITION,
                                {ID: service_def_id})
    ET.SubElement(
        service_def,
        'name').text = 'GLIF Automated GOLE Ethernet VLAN Transfer Service'
    ET.SubElement(service_def, 'serviceType').text = cnt.EVTS_AGOLE

    switch_id = topology_id + ':switch:EVTS.A-GOLE'
    labelSwapping = 'true' if labelSwap else 'false'
    switch_attrib = {
        ID: switch_id,
        LABEL_SWAPPING: labelSwapping,
        LABEL_TYPE_CAMEL: cnt.NML_ETHERNET_VLAN
    }

    service_rel = ET.SubElement(nml_topology, NML_RELATION,
                                {'type': NML_HASSERVICE})
    switch = ET.SubElement(service_rel, NML_SWITCHINGSERVICE, switch_attrib)

    ET.SubElement(switch, NSI_SERVICE_DEFINITION, {ID: service_def_id})

    return nml_topology