Revision 06dbd774

View differences:

examples/miniedit.py
13 13
OpenFlow icon from https://www.opennetworking.org/
14 14
"""
15 15

  
16
MINIEDIT_VERSION = '2.1.0.8.1'
16
MINIEDIT_VERSION = '2.1.0.9'
17 17

  
18 18
from optparse import OptionParser
19 19
from Tkinter import *
......
38 38
from mininet.net import Mininet, VERSION
39 39
from mininet.util import ipStr, netParse, ipAdd, quietRun
40 40
from mininet.util import buildTopo
41
from mininet.util import custom, customConstructor
41 42
from mininet.term import makeTerm, cleanUpScreens
42 43
from mininet.node import Controller, RemoteController, NOX, OVSController
43 44
from mininet.node import CPULimitedHost, Host, Node
......
66 67
                'nox': NOX,
67 68
                'remote': RemoteController,
68 69
                'none': lambda name: None }
70
LINKDEF = 'default'
71
LINKS = { 'default': Link,
72
          'tc': TCLink }
73
HOSTDEF = 'proc'
74
HOSTS = { 'proc': Host,
75
          'rt': custom( CPULimitedHost, sched='rt' ),
76
          'cfs': custom( CPULimitedHost, sched='cfs' ) }
77

  
69 78

  
70 79
class InbandController( RemoteController ):
71 80

  
......
201 210
            # Selection of switch type
202 211
            Label(self.leftfieldFrame, text="Default Switch:").grid(row=3, sticky=E)
203 212
            self.switchType = StringVar(self.leftfieldFrame)
204
            self.switchTypeMenu = OptionMenu(self.leftfieldFrame, self.switchType, "Open vSwitch", "Indigo Virtual Switch", "Userspace Switch", "Userspace Switch inNamespace")
213
            self.switchTypeMenu = OptionMenu(self.leftfieldFrame, self.switchType, "Open vSwitch Kernel Mode", "Indigo Virtual Switch", "Userspace Switch", "Userspace Switch inNamespace")
205 214
            self.switchTypeMenu.grid(row=3, column=1, sticky=W)
206 215
            switchTypePref = self.prefValues['switchType']
207 216
            if switchTypePref == 'ivs':
......
211 220
            elif switchTypePref == 'user':
212 221
                self.switchType.set("Userspace Switch")
213 222
            else:
214
                self.switchType.set("Open vSwitch")
223
                self.switchType.set("Open vSwitch Kernel Mode")
215 224

  
216 225

  
217 226
            # Fields for OVS OpenFlow version
......
516 525
            for vlanInterface in vlanInterfaces:
517 526
                self.vlanTableFrame.addRow(value=vlanInterface)
518 527

  
528
            self.commandFrame = Frame(self.rootFrame)
529
            self.commandFrame.grid(row=3, column=0, sticky='nswe', columnspan=4)
530
            self.commandFrame.columnconfigure(1, weight=1)
531

  
532
            # Start command
533
            Label(self.commandFrame, text="Start Command:").grid(row=0, sticky=E)
534
            self.startEntry = Entry(self.commandFrame)
535
            self.startEntry.grid(row=0, column=1, sticky='nswe')
536
            if 'startCommand' in self.prefValues:
537
                self.startEntry.insert(0, str(self.prefValues['startCommand']))
538
            # Stop command
539
            Label(self.commandFrame, text="Stop Command:").grid(row=1, sticky=E)
540
            self.stopEntry = Entry(self.commandFrame)
541
            self.stopEntry.grid(row=1, column=1, sticky='nswe')
542
            if 'stopCommand' in self.prefValues:
543
                self.stopEntry.insert(0, str(self.prefValues['stopCommand']))
544

  
519 545
        def addVlanInterface( self ):
520 546
            self.vlanTableFrame.addRow()
521 547

  
......
541 567
                       'hostname':self.hostnameEntry.get(),
542 568
                       'ip':self.ipEntry.get(),
543 569
                       'defaultRoute':self.routeEntry.get(),
570
                       'startCommand':self.startEntry.get(),
571
                       'stopCommand':self.stopEntry.get(),
544 572
                       'externalInterfaces':externalInterfaces,
545 573
                       'vlanInterfaces':vlanInterfaces}
546 574
            self.result = results
......
555 583

  
556 584
        def body(self, master):
557 585
            self.rootFrame = master
586
            self.leftfieldFrame = Frame(self.rootFrame)
587
            self.rightfieldFrame = Frame(self.rootFrame)
588
            self.leftfieldFrame.grid(row=0, column=0, sticky='nswe')
589
            self.rightfieldFrame.grid(row=0, column=1, sticky='nswe')
558 590

  
559 591
            rowCount = 0
560 592
            externalInterfaces = []
561 593
            if 'externalInterfaces' in self.prefValues:
562 594
                externalInterfaces = self.prefValues['externalInterfaces']
563 595

  
564
            self.fieldFrame = Frame(self.rootFrame)
565
            self.fieldFrame.grid(row=0, column=0, sticky='nswe')
566

  
567 596
            # Field for Hostname
568
            Label(self.fieldFrame, text="Hostname:").grid(row=rowCount, sticky=E)
569
            self.hostnameEntry = Entry(self.fieldFrame)
597
            Label(self.leftfieldFrame, text="Hostname:").grid(row=rowCount, sticky=E)
598
            self.hostnameEntry = Entry(self.leftfieldFrame)
570 599
            self.hostnameEntry.grid(row=rowCount, column=1)
571 600
            self.hostnameEntry.insert(0, self.prefValues['hostname'])
572 601
            rowCount+=1
573 602

  
574 603
            # Field for DPID
575
            Label(self.fieldFrame, text="DPID:").grid(row=rowCount, sticky=E)
576
            self.dpidEntry = Entry(self.fieldFrame)
604
            Label(self.leftfieldFrame, text="DPID:").grid(row=rowCount, sticky=E)
605
            self.dpidEntry = Entry(self.leftfieldFrame)
577 606
            self.dpidEntry.grid(row=rowCount, column=1)
578 607
            if 'dpid' in self.prefValues:
579 608
                self.dpidEntry.insert(0, self.prefValues['dpid'])
580 609
            rowCount+=1
581 610

  
582 611
            # Field for Netflow
583
            Label(self.fieldFrame, text="Enable NetFlow:").grid(row=rowCount, sticky=E)
612
            Label(self.leftfieldFrame, text="Enable NetFlow:").grid(row=rowCount, sticky=E)
584 613
            self.nflow = IntVar()
585
            self.nflowButton = Checkbutton(self.fieldFrame, variable=self.nflow)
614
            self.nflowButton = Checkbutton(self.leftfieldFrame, variable=self.nflow)
586 615
            self.nflowButton.grid(row=rowCount, column=1, sticky=W)
587 616
            if 'netflow' in self.prefValues:
588 617
                if self.prefValues['netflow'] == '0':
......
594 623
            rowCount+=1
595 624

  
596 625
            # Field for sflow
597
            Label(self.fieldFrame, text="Enable sFlow:").grid(row=rowCount, sticky=E)
626
            Label(self.leftfieldFrame, text="Enable sFlow:").grid(row=rowCount, sticky=E)
598 627
            self.sflow = IntVar()
599
            self.sflowButton = Checkbutton(self.fieldFrame, variable=self.sflow)
628
            self.sflowButton = Checkbutton(self.leftfieldFrame, variable=self.sflow)
600 629
            self.sflowButton.grid(row=rowCount, column=1, sticky=W)
601 630
            if 'sflow' in self.prefValues:
602 631
                if self.prefValues['sflow'] == '0':
......
608 637
            rowCount+=1
609 638

  
610 639
            # Selection of switch type
611
            Label(self.fieldFrame, text="Switch Type:").grid(row=rowCount, sticky=E)
612
            self.switchType = StringVar(self.fieldFrame)
613
            self.switchTypeMenu = OptionMenu(self.fieldFrame, self.switchType, "Default", "Open vSwitch", "Indigo Virtual Switch", "Userspace Switch", "Userspace Switch inNamespace")
640
            Label(self.leftfieldFrame, text="Switch Type:").grid(row=rowCount, sticky=E)
641
            self.switchType = StringVar(self.leftfieldFrame)
642
            self.switchTypeMenu = OptionMenu(self.leftfieldFrame, self.switchType, "Default", "Open vSwitch Kernel Mode", "Indigo Virtual Switch", "Userspace Switch", "Userspace Switch inNamespace")
614 643
            self.switchTypeMenu.grid(row=rowCount, column=1, sticky=W)
615 644
            if 'switchType' in self.prefValues:
616 645
                switchTypePref = self.prefValues['switchType']
......
621 650
                elif switchTypePref == 'user':
622 651
                    self.switchType.set("Userspace Switch")
623 652
                elif switchTypePref == 'ovs':
624
                    self.switchType.set("Open vSwitch")
653
                    self.switchType.set("Open vSwitch Kernel Mode")
625 654
                else:
626 655
                    self.switchType.set("Default")
627 656
            else:
......
629 658
            rowCount+=1
630 659

  
631 660
            # Field for Switch IP
632
            Label(self.fieldFrame, text="IP Address:").grid(row=rowCount, sticky=E)
633
            self.ipEntry = Entry(self.fieldFrame)
661
            Label(self.leftfieldFrame, text="IP Address:").grid(row=rowCount, sticky=E)
662
            self.ipEntry = Entry(self.leftfieldFrame)
634 663
            self.ipEntry.grid(row=rowCount, column=1)
635 664
            if 'switchIP' in self.prefValues:
636 665
                self.ipEntry.insert(0, self.prefValues['switchIP'])
637 666
            rowCount+=1
638 667

  
639 668
            # Field for DPCTL port
640
            Label(self.fieldFrame, text="DPCTL port:").grid(row=rowCount, sticky=E)
641
            self.dpctlEntry = Entry(self.fieldFrame)
669
            Label(self.leftfieldFrame, text="DPCTL port:").grid(row=rowCount, sticky=E)
670
            self.dpctlEntry = Entry(self.leftfieldFrame)
642 671
            self.dpctlEntry.grid(row=rowCount, column=1)
643 672
            if 'dpctl' in self.prefValues:
644 673
                self.dpctlEntry.insert(0, self.prefValues['dpctl'])
645 674
            rowCount+=1
646 675

  
647 676
            # External Interfaces
648
            Label(self.fieldFrame, text="External Interface:").grid(row=rowCount, sticky=E)
649
            self.b = Button( self.fieldFrame, text='Add', command=self.addInterface)
650
            self.b.grid(row=rowCount, column=1)
677
            Label(self.rightfieldFrame, text="External Interface:").grid(row=0, sticky=E)
678
            self.b = Button( self.rightfieldFrame, text='Add', command=self.addInterface)
679
            self.b.grid(row=0, column=1)
651 680

  
652
            self.interfaceFrame = VerticalScrolledTable(self.rootFrame, rows=0, columns=1, title='External Interfaces')
653
            self.interfaceFrame.grid(row=2, column=0, sticky='nswe')
681
            self.interfaceFrame = VerticalScrolledTable(self.rightfieldFrame, rows=0, columns=1, title='External Interfaces')
682
            self.interfaceFrame.grid(row=1, column=0, sticky='nswe', columnspan=2)
654 683
            self.tableFrame = self.interfaceFrame.interior
655 684

  
656 685
            # Add defined interfaces
657 686
            for externalInterface in externalInterfaces:
658 687
                self.tableFrame.addRow(value=[externalInterface])
659
            rowCount+=1
688

  
689
            self.commandFrame = Frame(self.rootFrame)
690
            self.commandFrame.grid(row=1, column=0, sticky='nswe', columnspan=2)
691
            self.commandFrame.columnconfigure(1, weight=1)
692
            # Start command
693
            Label(self.commandFrame, text="Start Command:").grid(row=0, column=0, sticky=W)
694
            self.startEntry = Entry(self.commandFrame)
695
            self.startEntry.grid(row=0, column=1,  sticky='nsew')
696
            if 'startCommand' in self.prefValues:
697
                self.startEntry.insert(0, str(self.prefValues['startCommand']))
698
            # Stop command
699
            Label(self.commandFrame, text="Stop Command:").grid(row=1, column=0, sticky=W)
700
            self.stopEntry = Entry(self.commandFrame)
701
            self.stopEntry.grid(row=1, column=1, sticky='nsew')
702
            if 'stopCommand' in self.prefValues:
703
                self.stopEntry.insert(0, str(self.prefValues['stopCommand']))
660 704

  
661 705
        def addInterface( self ):
662 706
            self.tableFrame.addRow()
......
692 736
            results = {'externalInterfaces':externalInterfaces,
693 737
                       'hostname':self.hostnameEntry.get(),
694 738
                       'dpid':dpid,
739
                       'startCommand':self.startEntry.get(),
740
                       'stopCommand':self.stopEntry.get(),
695 741
                       'sflow':str(self.sflow.get()),
696 742
                       'netflow':str(self.nflow.get()),
697 743
                       'dpctl':self.dpctlEntry.get(),
......
707 753
                results['switchType'] = 'userns'
708 754
            elif sw == 'Userspace Switch':
709 755
                results['switchType'] = 'user'
710
            elif sw == 'Open vSwitch':
756
            elif sw == 'Open vSwitch Kernel Mode':
711 757
                results['switchType'] = 'ovs'
712 758
            else:
713 759
                results['switchType'] = 'default'
......
1144 1190
        fileMenu.add_command( label="New", font=font, command=self.newTopology )
1145 1191
        fileMenu.add_command( label="Open", font=font, command=self.loadTopology )
1146 1192
        fileMenu.add_command( label="Save", font=font, command=self.saveTopology )
1147
        fileMenu.add_command( label="Export", font=font, command=self.exportTopology )
1193
        fileMenu.add_command( label="Export Level 2 Script", font=font, command=self.exportScript )
1148 1194
        fileMenu.add_separator()
1149 1195
        fileMenu.add_command( label='Quit', command=self.quit, font=font )
1150 1196

  
......
1305 1351
        self.itemToWidget[ item ] = icon
1306 1352
        icon.links = {}
1307 1353

  
1354
    def convertJsonUnicode(self, input):
1355
        "Some part of Mininet don't like Unicode"
1356
        if isinstance(input, dict):
1357
            return {self.convertJsonUnicode(key): self.convertJsonUnicode(value) for key, value in input.iteritems()}
1358
        elif isinstance(input, list):
1359
            return [self.convertJsonUnicode(element) for element in input]
1360
        elif isinstance(input, unicode):
1361
            return input.encode('utf-8')
1362
        else:
1363
            return input
1364

  
1308 1365
    def loadTopology( self ):
1309 1366
        "Load command."
1310 1367
        c = self.canvas
......
1317 1374
        if f == None:
1318 1375
            return
1319 1376
        self.newTopology()
1320
        loadedTopology = eval(f.read())
1377
        loadedTopology = self.convertJsonUnicode(json.load(f))
1321 1378

  
1322 1379
        # Load application preferences
1323 1380
        if 'application' in loadedTopology:
......
1545 1602

  
1546 1603
            try:
1547 1604
                f = open(fileName, 'wb')
1548
                #f.write(str(savingDictionary))
1549 1605
                f.write(json.dumps(savingDictionary, sort_keys=True, indent=4, separators=(',', ': ')))
1550 1606
            except Exception as er:
1551 1607
                print er
1552 1608
            finally:
1553 1609
                f.close()
1554 1610

  
1555
    def exportTopology( self ):
1611
    def exportScript( self ):
1556 1612
        "Export command."
1557 1613
        myFormats = [
1558 1614
            ('Mininet Custom Topology','*.py'),
......
1575 1631
            f.write("from mininet.cli import CLI\n")
1576 1632
            f.write("from mininet.log import setLogLevel, info\n")
1577 1633
            f.write("from mininet.link import TCLink, Intf\n")
1634
            f.write("from subprocess import call\n")
1578 1635

  
1579 1636
            inBandCtrl = False
1580 1637
            hasLegacySwitch = False
......
1757 1814
                    f.write("    "+srcName+dstName+" = "+linkOpts+"\n")
1758 1815
                f.write("    net.addLink("+srcName+", "+dstName)
1759 1816
                if optsExist:
1760
                    f.write(", link=TCLink , **"+srcName+dstName)
1817
                    f.write(", cls=TCLink , **"+srcName+dstName)
1761 1818
                f.write(")\n")
1762 1819

  
1763 1820
            f.write("\n")
......
1780 1837

  
1781 1838
            f.write("\n")
1782 1839

  
1783
            f.write("    info( '*** Configuring switches\\n')\n")
1840
            f.write("    info( '*** Post configure switches and hosts\\n')\n")
1784 1841
            for widget in self.widgetToItem:
1785 1842
                name = widget[ 'text' ]
1786 1843
                tags = self.canvas.gettags( self.widgetToItem[ widget ] )
......
1821 1878
                        for vlanInterface in opts['vlanInterfaces']:
1822 1879
                            f.write("    "+name+".cmd('vconfig add "+name+"-eth0 "+vlanInterface[1]+"')\n")
1823 1880
                            f.write("    "+name+".cmd('ifconfig "+name+"-eth0."+vlanInterface[1]+" "+vlanInterface[0]+"')\n")
1824

  
1881
                    # Run User Defined Start Command
1882
                    if ('startCommand' in opts):
1883
                        f.write("    "+name+".cmdPrint('"+opts['startCommand']+"')\n")
1884
                if 'Switch' in tags:
1885
                    opts = self.switchOpts[name]
1886
                    # Run User Defined Start Command
1887
                    if ('startCommand' in opts):
1888
                        f.write("    "+name+".cmdPrint('"+opts['startCommand']+"')\n")
1889

  
1890
            # Configure NetFlow
1891
            nflowValues = self.appPrefs['netflow']
1892
            if len(nflowValues['nflowTarget']) > 0:
1893
                nflowEnabled = False
1894
                nflowSwitches = ''
1895
                for widget in self.widgetToItem:
1896
                    name = widget[ 'text' ]
1897
                    tags = self.canvas.gettags( self.widgetToItem[ widget ] )
1898
    
1899
                    if 'Switch' in tags:
1900
                        opts = self.switchOpts[name]
1901
                        if 'netflow' in opts:
1902
                            if opts['netflow'] == '1':
1903
                                nflowSwitches = nflowSwitches+' -- set Bridge '+name+' netflow=@MiniEditNF'
1904
                                nflowEnabled=True
1905
                if nflowEnabled:
1906
                    nflowCmd = 'ovs-vsctl -- --id=@MiniEditNF create NetFlow '+ 'target=\\\"'+nflowValues['nflowTarget']+'\\\" '+ 'active-timeout='+nflowValues['nflowTimeout']
1907
                    if nflowValues['nflowAddId'] == '1':
1908
                        nflowCmd = nflowCmd + ' add_id_to_interface=true'
1909
                    else:
1910
                        nflowCmd = nflowCmd + ' add_id_to_interface=false'
1911
                    f.write("    \n")
1912
                    f.write("    call('"+nflowCmd+nflowSwitches+"', shell=True)\n")
1913

  
1914
            # Configure sFlow
1915
            sflowValues = self.appPrefs['sflow']
1916
            if len(sflowValues['sflowTarget']) > 0:
1917
                sflowEnabled = False
1918
                sflowSwitches = ''
1919
                for widget in self.widgetToItem:
1920
                    name = widget[ 'text' ]
1921
                    tags = self.canvas.gettags( self.widgetToItem[ widget ] )
1922
    
1923
                    if 'Switch' in tags:
1924
                        opts = self.switchOpts[name]
1925
                        if 'sflow' in opts:
1926
                            if opts['sflow'] == '1':
1927
                                sflowSwitches = sflowSwitches+' -- set Bridge '+name+' sflow=@MiniEditSF'
1928
                                sflowEnabled=True
1929
                if sflowEnabled:
1930
                    sflowCmd = 'ovs-vsctl -- --id=@MiniEditSF create sFlow '+ 'target=\\\"'+sflowValues['sflowTarget']+'\\\" '+ 'header='+sflowValues['sflowHeader']+' '+ 'sampling='+sflowValues['sflowSampling']+' '+ 'polling='+sflowValues['sflowPolling']
1931
                    f.write("    \n")
1932
                    f.write("    call('"+sflowCmd+sflowSwitches+"', shell=True)\n")
1825 1933

  
1826 1934
            f.write("\n")
1827 1935
            f.write("    CLI(net)\n")
1936
            for widget in self.widgetToItem:
1937
                name = widget[ 'text' ]
1938
                tags = self.canvas.gettags( self.widgetToItem[ widget ] )
1939
                if 'Host' in tags:
1940
                    opts = self.hostOpts[name]
1941
                    # Run User Defined Stop Command
1942
                    if ('stopCommand' in opts):
1943
                        f.write("    "+name+".cmdPrint('"+opts['stopCommand']+"')\n")
1944
                if 'Switch' in tags:
1945
                    opts = self.switchOpts[name]
1946
                    # Run User Defined Stop Command
1947
                    if ('stopCommand' in opts):
1948
                        f.write("    "+name+".cmdPrint('"+opts['stopCommand']+"')\n")
1949

  
1828 1950
            f.write("    net.stop()\n")
1829 1951
            f.write("\n")
1830 1952
            f.write("if __name__ == '__main__':\n")
......
2272 2394
        if hostBox.result:
2273 2395
            newHostOpts = {'nodeNum':self.hostOpts[name]['nodeNum']}
2274 2396
            newHostOpts['sched'] = hostBox.result['sched']
2397
            if len(hostBox.result['startCommand']) > 0:
2398
                newHostOpts['startCommand'] = hostBox.result['startCommand']
2399
            if len(hostBox.result['stopCommand']) > 0:
2400
                newHostOpts['stopCommand'] = hostBox.result['stopCommand']
2275 2401
            if len(hostBox.result['cpu']) > 0:
2276 2402
                newHostOpts['cpu'] = float(hostBox.result['cpu'])
2277 2403
            if len(hostBox.result['cores']) > 0:
......
2309 2435
            newSwitchOpts = {'nodeNum':self.switchOpts[name]['nodeNum']}
2310 2436
            newSwitchOpts['switchType'] = switchBox.result['switchType']
2311 2437
            newSwitchOpts['controllers'] = self.switchOpts[name]['controllers']
2438
            if len(switchBox.result['startCommand']) > 0:
2439
                newSwitchOpts['startCommand'] = switchBox.result['startCommand']
2440
            if len(switchBox.result['stopCommand']) > 0:
2441
                newSwitchOpts['stopCommand'] = switchBox.result['stopCommand']
2312 2442
            if len(switchBox.result['dpctl']) > 0:
2313 2443
                newSwitchOpts['dpctl'] = switchBox.result['dpctl']
2314 2444
            if len(switchBox.result['dpid']) > 0:
......
2494 2624
        for widget in self.widgetToItem:
2495 2625
            name = widget[ 'text' ]
2496 2626
            tags = self.canvas.gettags( self.widgetToItem[ widget ] )
2497
            #print name+' has '+str(tags)
2627
            print name+' has '+str(tags)
2498 2628

  
2499 2629
            if 'Switch' in tags:
2500 2630
                opts = self.switchOpts[name]
2631
                print str(opts)
2501 2632

  
2502 2633
                # Create the correct switch class
2503 2634
                switchClass = customOvs
......
2548 2679
                newSwitch = net.addHost( name , cls=LegacyRouter)
2549 2680
            elif 'Host' in tags:
2550 2681
                opts = self.hostOpts[name]
2682
                print str(opts)
2551 2683
                ip = None
2552 2684
                defaultRoute = None
2553 2685
                if 'defaultRoute' in opts and len(opts['defaultRoute']) > 0:
......
2637 2769
                dst=link['dest']
2638 2770
                linkopts=link['linkOpts']
2639 2771
                srcName, dstName = src[ 'text' ], dst[ 'text' ]
2640
                src, dst = net.nameToNode[ srcName ], net.nameToNode[ dstName ]
2772
                srcNode, dstNode = net.nameToNode[ srcName ], net.nameToNode[ dstName ]
2641 2773
                if linkopts:
2642
                    net.addLink(src, dst, cls=TCLink, **linkopts)
2774
                    net.addLink(srcNode, dstNode, cls=TCLink, **linkopts)
2643 2775
                else:
2644
                    net.addLink(src, dst)
2776
                    print str(srcNode)
2777
                    print str(dstNode)
2778
                    net.addLink(srcNode, dstNode)
2645 2779
                self.canvas.itemconfig(key, dash=())
2646 2780

  
2647 2781

  
......
2667 2801

  
2668 2802
    def postStartSetup( self ):
2669 2803

  
2670
        # Setup host VLAN subinterfaces
2804
        # Setup host details
2671 2805
        for widget in self.widgetToItem:
2672 2806
            name = widget[ 'text' ]
2673 2807
            tags = self.canvas.gettags( self.widgetToItem[ widget ] )
2674 2808
            if 'Host' in tags:
2809
                newHost = self.net.get(name)
2675 2810
                opts = self.hostOpts[name]
2676 2811
                # Attach vlan interfaces
2677 2812
                if ('vlanInterfaces' in opts):
2678 2813
                    for vlanInterface in opts['vlanInterfaces']:
2679 2814
                        print 'adding vlan interface '+vlanInterface[1]
2680
                        newHost = self.net.get(name)
2681
                        newHost.cmdPrint('vconfig add '+name+'-eth0 '+vlanInterface[1])
2682 2815
                        newHost.cmdPrint('ifconfig '+name+'-eth0.'+vlanInterface[1]+' '+vlanInterface[0])
2816
                # Run User Defined Start Command
2817
                if ('startCommand' in opts):
2818
                    newHost.cmdPrint(opts['startCommand'])
2819
            if 'Switch' in tags:
2820
                newNode = self.net.get(name)
2821
                opts = self.switchOpts[name]
2822
                # Run User Defined Start Command
2823
                if ('startCommand' in opts):
2824
                    newNode.cmdPrint(opts['startCommand'])
2825

  
2683 2826

  
2684 2827
        # Configure NetFlow
2685 2828
        nflowValues = self.appPrefs['netflow']
......
2782 2925
    def stop( self ):
2783 2926
        "Stop network."
2784 2927
        if self.net is not None:
2928
            # Stop host details
2929
            for widget in self.widgetToItem:
2930
                name = widget[ 'text' ]
2931
                tags = self.canvas.gettags( self.widgetToItem[ widget ] )
2932
                if 'Host' in tags:
2933
                    newHost = self.net.get(name)
2934
                    opts = self.hostOpts[name]
2935
                    # Run User Defined Stop Command
2936
                    if ('stopCommand' in opts):
2937
                        newHost.cmdPrint(opts['stopCommand'])
2938
                if 'Switch' in tags:
2939
                    newNode = self.net.get(name)
2940
                    opts = self.switchOpts[name]
2941
                    # Run User Defined Stop Command
2942
                    if ('stopCommand' in opts):
2943
                        newNode.cmdPrint(opts['stopCommand'])
2944

  
2785 2945
            self.net.stop()
2786 2946
        cleanUpScreens()
2787 2947
        self.net = None
......
2908 3068
        opts = OptionParser( description=desc, usage=usage )
2909 3069

  
2910 3070
        addDictOption( opts, TOPOS, TOPODEF, 'topo' )
3071
        addDictOption( opts, LINKS, LINKDEF, 'link' )
3072

  
2911 3073
        opts.add_option( '--custom', type='string', default=None,
2912 3074
                         help='read custom topo and node params from .py' +
2913 3075
                         'file' )
......
2947 3109
            return
2948 3110
        self.newTopology()
2949 3111
        topo = buildTopo( TOPOS, self.options.topo )
2950
        importNet = Mininet(topo=topo, build=False)
3112
        link = customConstructor( LINKS, self.options.link )
3113
        importNet = Mininet(topo=topo, build=False, link=link)
2951 3114
        importNet.build()
2952 3115

  
2953 3116
        c = self.canvas
......
3038 3201
        print 'links:'+str(len(topo.links()))
3039 3202
        #[('h1', 's3'), ('h2', 's4'), ('s3', 's4')]
3040 3203
        for link in topo.links():
3204
            print str(link)
3041 3205
            srcNode = link[0]
3042 3206
            src = self.findWidgetByName(srcNode)
3043 3207
            sx, sy = self.canvas.coords( self.widgetToItem[ src ] )
......
3046 3210
            dest = self.findWidgetByName(destNode)
3047 3211
            dx, dy = self.canvas.coords( self.widgetToItem[ dest]  )
3048 3212

  
3213
            params = topo.linkInfo( srcNode, destNode )
3214
            print 'Link Parameters='+str(params)
3215

  
3049 3216
            self.link = self.canvas.create_line( sx, sy, dx, dy, width=4,
3050 3217
                                             fill='blue', tag='link' )
3051 3218
            c.itemconfig(self.link, tags=c.gettags(self.link)+('data',))
3052
            self.addLink( src, dest )
3219
            self.addLink( src, dest, linkopts=params )
3053 3220
            self.createDataLinkBindings()
3054 3221
            self.link = self.linkWidget = None
3055 3222

  

Also available in: Unified diff