Revision 723d068c mininet/net.py

View differences:

mininet/net.py
5 5
@author Brandon Heller (brandonh@stanford.edu)
6 6

  
7 7
Mininet creates scalable OpenFlow test networks by using
8
process-based virtualization and network namespaces. 
8
process-based virtualization and network namespaces.
9 9

  
10 10
Simulated hosts are created as processes in separate network
11 11
namespaces. This allows a complete OpenFlow network to be simulated on
......
15 15
   A virtual console (pipes to a shell)
16 16
   A virtual interfaces (half of a veth pair)
17 17
   A parent shell (and possibly some child processes) in a namespace
18
   
18

  
19 19
Hosts have a network interface which is configured via ifconfig/ip
20 20
link/etc.
21 21

  
......
210 210

  
211 211
        For use with the user datapath only right now.
212 212

  
213
        @todo(brandonh) Test this code and verify that user-space works!
213
        @todo(brandonh) Test this code!
214 214
        '''
215 215
        # params were: controller, switches, ips
216 216

  
......
242 242
            while not switch.intfIsUp(switch.intfs[0]):
243 243
                lg.info('*** Waiting for %s to come up\n' % switch.intfs[0])
244 244
                sleep(1)
245
            if self.ping_test(hosts=[switch, controller]) != 0:
245
            if self.ping(hosts = [switch, controller]) != 0:
246 246
                lg.error('*** Error: control network test failed\n')
247 247
                exit(1)
248 248
        lg.info('\n')
249 249

  
250
    def _config_hosts( self ):
250
    def _config_hosts(self):
251 251
        '''Configure a set of hosts.'''
252 252
        # params were: hosts, ips
253 253
        for host_dpid in self.topo.hosts():
......
343 343
    def start(self):
344 344
        '''Start controller and switches\n'''
345 345
        lg.info('*** Starting controller\n')
346
        for cname, cnode in self.controllers.iteritems():
346
        for cnode in self.controllers.values():
347 347
            cnode.start()
348 348
        lg.info('*** Starting %s switches\n' % len(self.topo.switches()))
349 349
        for switch_dpid in self.topo.switches():
......
371 371
            switch.stop()
372 372
        lg.info('\n')
373 373
        lg.info('*** Stopping controller\n')
374
        for cname, cnode in self.controllers.iteritems():
374
        for cnode in self.controllers.values():
375 375
            cnode.stop()
376 376
        lg.info('*** Test complete\n')
377 377

  
......
387 387
    def _parse_ping(pingOutput):
388 388
        '''Parse ping output and return packets sent, received.'''
389 389
        r = r'(\d+) packets transmitted, (\d+) received'
390
        m = re.search( r, pingOutput )
390
        m = re.search(r, pingOutput)
391 391
        if m == None:
392 392
            lg.error('*** Error: could not parse ping output: %s\n' %
393 393
                     pingOutput)
......
422 422
                        lg.error('*** Error: received too many packets')
423 423
                        lg.error('%s' % result)
424 424
                        node.cmdPrint('route')
425
                        exit( 1 )
425
                        exit(1)
426 426
                    lost += sent - received
427 427
                    lg.info(('%s ' % dest.name) if received else 'X ')
428 428
            lg.info('\n')
......
490 490
        server = host0.cmd(iperf_args + '-s &')
491 491
        if verbose:
492 492
            lg.info('%s\n' % server)
493
        client = host1.cmd(iperf_args + '-t 5 -c ' + host0.IP() + ' ' + bw_args)
493
        client = host1.cmd(iperf_args + '-t 5 -c ' + host0.IP() + ' ' +
494
                           bw_args)
494 495
        if verbose:
495 496
            lg.info('%s\n' % client)
496 497
        server = host0.cmd('killall -9 iperf')
......
529 530
        self.nodelist = self.nodemap.values()
530 531
        self.run()
531 532

  
533
    # Disable pylint "Unused argument: 'arg's'" messages.
534
    # Each CLI function needs the same interface.
535
    # pylint: disable-msg=W0613
536

  
532 537
    # Commands
533 538
    def help(self, args):
534 539
        '''Semi-useful help for CLI.'''
......
561 566
            switch = self.mn.nodes[switch_dpid]
562 567
            lg.info('%s <->', switch.name)
563 568
            for intf in switch.intfs:
564
                node, remoteIntf = switch.connection[intf]
569
                node = switch.connection[intf]
565 570
                lg.info(' %s' % node.name)
566 571
            lg.info('\n')
567 572

  
......
588 593

  
589 594
    def intfs(self, args):
590 595
        '''List interfaces.'''
591
        for dpid, node in self.mn.nodes.iteritems():
596
        for node in self.mn.nodes.values():
592 597
            lg.info('%s: %s\n' % (node.name, ' '.join(node.intfs)))
593 598

  
594 599
    def dump(self, args):
595 600
        '''Dump node info.'''
596
        for dpid, node in self.mn.nodes.iteritems():
601
        for node in self.mn.nodes.values():
597 602
            lg.info('%s\n' % node)
598 603

  
604
    # Re-enable pylint "Unused argument: 'arg's'" messages.
605
    # pylint: enable-msg=W0613
606

  
599 607
    def run(self):
600 608
        '''Read and execute commands.'''
601 609
        lg.warn('*** Starting CLI:\n')
602 610
        while True:
603 611
            lg.warn('mininet> ')
604
            input = sys.stdin.readline()
605
            if input == '':
612
            input_line = sys.stdin.readline()
613
            if input_line == '':
606 614
                break
607
            if input[-1] == '\n':
608
                input = input[:-1]
609
            cmd = input.split(' ')
615
            if input_line[-1] == '\n':
616
                input_line = input_line[:-1]
617
            cmd = input_line.split(' ')
610 618
            first = cmd[0]
611 619
            rest = cmd[1:]
612 620
            if first in self.cmds and hasattr(self, first):
......
634 642
            elif first in ['exit', 'quit']:
635 643
                break
636 644
            elif first == '?':
637
                self.help( rest )
645
                self.help(rest)
638 646
            else:
639 647
                lg.error('CLI: unknown node or command: < %s >\n' % first)
640 648
            #lg.info('*** CLI: command complete\n')
641
        return 'exited by user command'
649
        return 'exited by user command'

Also available in: Unified diff