def parse_external_rspec(rspec):
    """Parse the given rspec and create dicts of the given switches.
    
    Parses the RSpec and creates a dict mapping switches to the ports they
    have. It also creates a list of (dpid, port, dpid, port) describing the
    links.
    
    @param rspec: The advertisement RSpec
    @type rspec: XML C{str}
    @return: tuple of a dict mapping datapath ID strings to list of port
        numbers and a list of
        (src dpid, src port num, dst dpid, dst port num, attrs)
        describing the links.
    @rtype: (C{dict} mapping C{str} to C{list} of C{int},
        C{list} of (C{str}, C{int}, C{str}, C{int}, C{dict}))
    """
    
    root = et.fromstring(rspec)
    
    switch_elems = root.findall(".//%s" % SWITCH_TAG)
    switches = {}
    for switch_elem in switch_elems:
        urn = switch_elem.get(URN)
        dpid = _urn_to_dpid(urn)
        switches[dpid] = []
    
    port_elems = root.findall(".//%s" % PORT_TAG)
    for port_elem in port_elems:
        urn = port_elem.get(URN)
        dpid, port = _urn_to_port(urn)
        try:
            switches[dpid].append(port)
        except __HOLE__:
            raise Exception("No switch with datapath ID %s found"
                            " for port with URN %s" % (dpid, urn))
        
    link_elems = root.findall(".//%s" % LINK_TAG)
    links = []
    for link_elem in link_elems:
        src_urn = link_elem.get(SRC_URN)
        dst_urn = link_elem.get(DST_URN)
        src_dpid, src_port = _urn_to_port(src_urn)
        dst_dpid, dst_port = _urn_to_port(dst_urn)
        links.append((src_dpid, src_port, dst_dpid, dst_port, {}))
        
    return switches, links
dataset/ETHPy150Open fp7-ofelia/ocf/expedient/src/python/plugins/openflow/plugin/gapi/rspec.py/parse_external_rspec