From d856c81896532c08bb560702bfb4728be1d87f9f Mon Sep 17 00:00:00 2001
From: Brandon Heller <brandonh@stanford.edu>
Date: Wed, 6 Jan 2010 21:23:33 -0800
Subject: [PATCH] Support out-of-order link addition

Sort interface names before passing to dpctl for kernel switch, so that
links for multipath topologies can be added in any order.
---
 mininet/net.py  |  2 ++
 mininet/node.py | 10 ++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/mininet/net.py b/mininet/net.py
index 41afd4c0..0305e023 100755
--- a/mininet/net.py
+++ b/mininet/net.py
@@ -159,6 +159,8 @@ def _add_link(self, src, dst):
         make_veth_pair(src_intf, dst_intf)
         src_node.intfs.append(src_intf)
         dst_node.intfs.append(dst_intf)
+        src_node.ports[src_port] = src_intf
+        dst_node.ports[dst_port] = dst_intf
         #lg.info('\n')
         #lg.info('added intf %s to src node %x\n' % (src_intf, src))
         #lg.info('added intf %s to dst node %x\n' % (dst_intf, dst))
diff --git a/mininet/node.py b/mininet/node.py
index f29acb5f..ca1f4f96 100644
--- a/mininet/node.py
+++ b/mininet/node.py
@@ -41,6 +41,8 @@ def __init__(self, name, inNamespace = True):
         self.connection = {}
         self.waiting = False
         self.execed = False
+        self.ports = {} # dict of ints to interface strings
+                        # replace with Port object, eventually
 
     def fdToNode(self, f):
         '''Insert docstring.
@@ -316,8 +318,12 @@ def start(self, controllers):
             intf = 'of%i' % self.dp
             mac_str = macColonHex(self.dpid)
             self.cmd(['ifconfig', intf, 'hw', 'ether', mac_str])
-        self.cmdPrint('dpctl addif nl:' + str(self.dp) + ' ' +
-                      ' '.join(self.intfs))
+
+        if len(self.ports) != max(self.ports.keys()) + 1:
+            raise Exception('only contiguous, zero-indexed port ranges'
+                            'supported: %s' % self.ports)
+        intfs = [self.ports[port] for port in self.ports.keys()]
+        self.cmdPrint('dpctl addif nl:' + str(self.dp) + ' ' + ' '.join(intfs))
         # Run protocol daemon
         self.cmdPrint('ofprotocol nl:' + str(self.dp) + ' tcp:' +
                       controllers['c0'].IP() + ':' +
-- 
GitLab