Revision c771b2d7 mininet/util.py

View differences:

mininet/util.py
171 171
        error( "*** gave up after %i retries\n" % tries )
172 172
        exit( 1 )
173 173

  
174
def moveIntfNoRetry( intf, node, printError=False ):
174
def moveIntfNoRetry( intf, dstNode, srcNode=None, printError=False ):
175 175
    """Move interface to node, without retrying.
176 176
       intf: string, interface
177
       node: Node object
178
       printError: if true, print error"""
179
    cmd = 'ip link set ' + intf + ' netns ' + repr( node.pid )
180
    quietRun( cmd )
181
    links = node.cmd( 'ip link show' )
177
        dstNode: destination Node
178
        srcNode: source Node or None (default) for root ns
179
        printError: if true, print error"""
180
    intf = str( intf )
181
    cmd = 'ip link set %s netns %s' % ( intf, dstNode.pid )
182
    if srcNode:
183
        srcNode.cmd( cmd )
184
    else:
185
        quietRun( cmd )
186
    links = dstNode.cmd( 'ip link show' )
182 187
    if not ( ' %s:' % intf ) in links:
183 188
        if printError:
184 189
            error( '*** Error: moveIntf: ' + intf +
185
                   ' not successfully moved to ' + node.name + '\n' )
190
                   ' not successfully moved to ' + dstNode.name + '\n' )
186 191
        return False
187 192
    return True
188 193

  
189
def moveIntf( intf, node, printError=False, retries=3, delaySecs=0.001 ):
194
def moveIntf( intf, dstNode, srcNode=None, printError=False,
195
             retries=3, delaySecs=0.001 ):
190 196
    """Move interface to node, retrying on failure.
191 197
       intf: string, interface
192
       node: Node object
198
       dstNode: destination Node
199
       srcNode: source Node or None (default) for root ns
193 200
       printError: if true, print error"""
194
    retry( retries, delaySecs, moveIntfNoRetry, intf, node, printError )
201
    retry( retries, delaySecs, moveIntfNoRetry, intf, dstNode,
202
          srcNode=srcNode, printError=printError )
195 203

  
196 204
# Support for dumping network
197 205

  

Also available in: Unified diff