title: Networkx: connecting nodes using ports
body: <p>I have this network:</p>
  
  <pre><code>r1 = dict( name  = 'R1', ports = dict(p1 = 'p1', p2 = 'p2') )
  r2 = dict( name  = 'R2', ports = dict(p1 = 'p1', p2 = 'p2') )
  r3 = dict( name  = 'R3', ports = dict(p1 = 'p1', p2 = 'p2') )
  routers = [r1,r2,r3]
  G = nx.Graph()
  [G.add_node(r['name'], name=r['name']) for r in routers]
  G.add_edges_from([('R1','R2'),('R2','R3')]
  </code></pre>
  
  <p>The previous produces the next topology.</p>
  
  <p><a href="https://i.stack.imgur.com/ucnL0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ucnL0.png" alt="enter image description here"></a></p>
  
  <p>As you can see, each of the nodes have their ports <code>p1</code> and <code>p2</code>. I know how to create these edges or connections in the graph:</p>
  
  <pre><code>In [53]: G.edges()
  Out[53]: EdgeView([('R1', 'R2'), ('R2', 'R3')])
  </code></pre>
  
  <p>However I'm mostly interested in using the ports of each node as point of connection. Meaning:</p>
  
  <pre><code>In [53]: G.edges()
  Out[53]: EdgeView([('R1'.'p1', 'R2'.'p2'), ('R2'.'p1', 'R3'.'p2')])
  </code></pre>
  
  <p>How can I accomplish that? Or, in other words, how could I model that, in the sense of having nodes+ports where the anchor points are ultimately these ports?</p>
  
  <p>thanks!</p>