'Links two nodes on given ports
np1 is (node1, port1)
np2 is (node2, port2)'

def link(self, np1, np2):

    try:
        _ = np1[0]
    except:
        for free in xrange(1000):
            if (free not in np1.ports):
                np1 = (np1, free)
                break
    try:
        _ = np2[0]
    except:
        for free in xrange(1000):
            if (free not in np2.ports):
                np2 = (np2, free)
                break
    self._g.add_node(np1[0])
    self._g.add_node(np2[0])
    self.disconnect_port(np1)
    self.disconnect_port(np2)
    self._g.add_edge(np1[0], np2[0], link=Link(np1, np2))
    self.node_port[np1[0]][np1[1]] = np2
    self.node_port[np2[0]][np2[1]] = np1
