Revision 089e8130

View differences:

mininet/net.py
220 220
            return self.nameToNode[ args[ 0 ] ]
221 221
        return [ self.nameToNode[ n ] for n in args ]
222 222

  
223
    def get( self, *args ):
224
        "Convenience alias for getNodeByName"
225
        return self.getNodeByName( *args )
226

  
223 227
    def addLink( self, node1, node2, port1=None, port2=None,
224 228
                 cls=None, **params ):
225 229
        """"Add a link from node1 to node2
mininet/node.py
282 282
           cmd: string"""
283 283
        return self.cmd( *args, **{ 'verbose': True } )
284 284

  
285
    def popen( self, *args, **kwargs ):
286
        """Return a Popen() object in our namespace
287
           args: Popen() args, single list, or string
288
           kwargs: Popen() keyword args"""
289
        defaults = { 'stdout': PIPE, 'stderr': PIPE,
290
                     'mncmd': [ 'mnexec', '-a' ] }
291
        defaults.update( kwargs )
292
        if len( args ) == 1:
293
            if type( args[ 0 ] ) is list:
294
                # popen([cmd, arg1, arg2...])
295
                cmd = args[ 0 ]
296
            elif type( args[ 0 ] ) is str:
297
                # popen("cmd arg1 arg2...")
298
                cmd = args[ 0 ].split()
299
        elif len( args ) > 0:
300
            # popen( cmd, arg1, arg2... )
301
            cmd = args
302
        # Attach to our namespace  using mnexec -a
303
        mncmd = defaults[ 'mncmd' ]
304
        del defaults[ 'mncmd' ]
305
        cmd = mncmd + [ str( self.pid ) ] + cmd
306
        return Popen( cmd, **defaults )
307

  
308
    def pexec( self, *args, **kwargs ):
309
        """Execute a command using popen
310
           returns: out, err, exitcode"""
311
        popen = self.popen( *args, **kwargs)
312
        out, err = popen.communicate()
313
        exitcode = popen.wait()
314
        return out, err, exitcode
315

  
285 316
    # Interface management, configuration, and routing
286 317

  
287 318
    # BL notes: This might be a bit redundant or over-complicated.
......
529 560
        # still does better with larger period values.
530 561
        self.period_us = kwargs.get( 'period_us', 100000 )
531 562
        self.sched = sched
563
        self.rtprio = 20
532 564

  
533 565
    def cgroupSet( self, param, value, resource='cpu' ):
534 566
        "Set a cgroup parameter and return its value"
......
553 585
        _out, _err, exitcode = errRun( 'cgdelete -r ' + self.cgroup )
554 586
        return exitcode != 0
555 587

  
588
    def popen( self, *args, **kwargs ):
589
        """Return a Popen() object in node's namespace
590
           args: Popen() args, single list, or string
591
           kwargs: Popen() keyword args"""
592
        # Tell mnexec to execute command in our cgroup
593
        mncmd = [ 'mnexec', '-a', str( self.pid ), 
594
                  '-c', self.cgroup ]
595
        if self.sched == 'rt':
596
            mncmd = [ 'chrt', self.rtprio ] + mncmd
597
        return Host.popen( self, *args, mncmd=mncmd, **kwargs )
598

  
556 599
    def cleanup( self ):
557 600
        "Clean up our cgroup"
558 601
        retry( retries=3, delaySecs=1, fn=self.cgroupDel )
559 602

  
560
    def chrt( self, prio=20 ):
603
    def chrt( self ):
561 604
        "Set RT scheduling priority"
562
        quietRun( 'chrt -p %s %s' % ( prio, self.pid ) )
605
        quietRun( 'chrt -p %s %s' % ( self.rtprio, self.pid ) )
563 606
        result = quietRun( 'chrt -p %s' % self.pid )
564 607
        firstline = result.split( '\n' )[ 0 ]
565 608
        lastword = firstline.split( ' ' )[ -1 ]

Also available in: Unified diff