From 31f44e1856b5581514af84c94d46021ed3961571 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Tue, 5 Mar 2019 19:07:56 -0800 Subject: [PATCH] Change Link/TCLink to accept universal parameters This also enables us to specify IP addresses for both sides of a TCLink, which enables LinuxRouter to work with TCLink. fixes #854 fixes #634 --- mininet/link.py | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/mininet/link.py b/mininet/link.py index e8b0190..70f1178 100644 --- a/mininet/link.py +++ b/mininet/link.py @@ -407,7 +407,7 @@ class Link( object ): def __init__( self, node1, node2, port1=None, port2=None, intfName1=None, intfName2=None, addr1=None, addr2=None, intf=Intf, cls1=None, cls2=None, params1=None, - params2=None, fast=True ): + params2=None, fast=True, **params ): """Create veth link to another node, making two new interfaces. node1: first node node2: second node @@ -417,18 +417,15 @@ class Link( object ): cls1, cls2: optional interface-specific constructors intfName1: node1 interface name (optional) intfName2: node2 interface name (optional) - params1: parameters for interface 1 - params2: parameters for interface 2""" + params1: parameters for interface 1 (optional) + params2: parameters for interface 2 (optional) + **params: additional parameters for both interfaces""" + # This is a bit awkward; it seems that having everything in # params is more orthogonal, but being able to specify # in-line arguments is more convenient! So we support both. - if params1 is None: - params1 = {} - if params2 is None: - params2 = {} - # Allow passing in params1=params2 - if params2 is params1: - params2 = dict( params1 ) + params1 = dict( params1 ) if params1 else {} + params2 = dict( params2 ) if params2 else {} if port1 is not None: params1[ 'port' ] = port1 if port2 is not None: @@ -442,6 +439,10 @@ class Link( object ): if not intfName2: intfName2 = self.intfName( node2, params2[ 'port' ] ) + # Update with remaining parameter list + params1.update( params ) + params2.update( params ) + self.fast = fast if fast: params1.setdefault( 'moveIntfFn', self._ignore ) @@ -463,6 +464,7 @@ class Link( object ): # All we are is dust in the wind, and our two interfaces self.intf1, self.intf2 = intf1, intf2 + # pylint: enable=too-many-branches @staticmethod @@ -548,17 +550,11 @@ class OVSLink( Link ): class TCLink( Link ): - "Link with symmetric TC interfaces configured via opts" - def __init__( self, node1, node2, port1=None, port2=None, - intfName1=None, intfName2=None, - addr1=None, addr2=None, **params ): - Link.__init__( self, node1, node2, port1=port1, port2=port2, - intfName1=intfName1, intfName2=intfName2, - cls1=TCIntf, - cls2=TCIntf, - addr1=addr1, addr2=addr2, - params1=params, - params2=params ) + "Link with TC interfaces" + def __init__( self, *args, **kwargs): + kwargs.setdefault( 'cls1', TCIntf ) + kwargs.setdefault( 'cls2', TCIntf ) + Link.__init__( self, *args, **kwargs) class TCULink( TCLink ):