A routing algorithm for networks based on distance-hereditary topologies