You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 2 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 3 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 4 | Copyright 2016 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 5 | |
| 6 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 7 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 8 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 9 | |
| 10 | TestON is free software: you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 13 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 14 | |
| 15 | TestON is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 22 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 23 | from mininet.topo import Topo |
| 24 | from mininet.net import Mininet |
| 25 | from mininet.node import Host, RemoteController |
| 26 | from mininet.node import Node |
| 27 | from mininet.node import CPULimitedHost |
| 28 | from mininet.link import TCLink |
| 29 | from mininet.cli import CLI |
| 30 | from mininet.log import setLogLevel |
| 31 | from mininet.util import dumpNodeConnections |
| 32 | from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch ) |
| 33 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 34 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 35 | class dualStackHost( Host ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 36 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 37 | def config( self, v6Addr='1000::1/64', **params ): |
| 38 | r = super( Host, self ).config( **params ) |
| 39 | intf = self.defaultIntf() |
| 40 | self.cmd( 'ip -6 addr add %s dev %s' % ( v6Addr, intf ) ) |
| 41 | return r |
| 42 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 43 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 44 | class ringTopo( Topo ): |
| 45 | |
| 46 | def __init__( self, **opts ): |
| 47 | "Create a topology." |
| 48 | |
| 49 | # Initialize Topology |
| 50 | Topo.__init__( self, **opts ) |
| 51 | |
| 52 | s1 = self.addSwitch( 's1' ) |
| 53 | s2 = self.addSwitch( 's2' ) |
| 54 | s3 = self.addSwitch( 's3' ) |
| 55 | s4 = self.addSwitch( 's4' ) |
| 56 | s5 = self.addSwitch( 's5' ) |
| 57 | s6 = self.addSwitch( 's6' ) |
| 58 | s7 = self.addSwitch( 's7' ) |
| 59 | s8 = self.addSwitch( 's8' ) |
| 60 | s9 = self.addSwitch( 's9' ) |
| 61 | s10 = self.addSwitch( 's10' ) |
| 62 | |
| 63 | # ... and now hosts |
| 64 | s1_host = self.addHost( 'h1', ip='10.1.0.1/24', cls=dualStackHost, v6Addr='1000::1/64' ) |
| 65 | s2_host = self.addHost( 'h2', ip='10.1.0.2/24', cls=dualStackHost, v6Addr='1000::2/64' ) |
| 66 | s3_host = self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='1000::3/64' ) |
| 67 | s4_host = self.addHost( 'h4', ip='10.1.0.4/24', cls=dualStackHost, v6Addr='1000::4/64' ) |
| 68 | s5_host = self.addHost( 'h5', ip='10.1.0.5/24', cls=dualStackHost, v6Addr='1000::5/64' ) |
| 69 | s6_host = self.addHost( 'h6', ip='10.1.0.6/24', cls=dualStackHost, v6Addr='1000::6/64' ) |
| 70 | s7_host = self.addHost( 'h7', ip='10.1.0.7/24', cls=dualStackHost, v6Addr='1000::7/64' ) |
| 71 | s8_host = self.addHost( 'h8', ip='10.1.0.8/24', cls=dualStackHost, v6Addr='1000::8/64' ) |
| 72 | s9_host = self.addHost( 'h9', ip='10.1.0.9/24', cls=dualStackHost, v6Addr='1000::9/64' ) |
| 73 | s10_host = self.addHost( 'h10', ip='10.1.0.10/24', cls=dualStackHost, v6Addr='1000::10/64' ) |
| 74 | |
| 75 | # add edges between switch and corresponding host |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 76 | self.addLink( s1, s1_host ) |
| 77 | self.addLink( s2, s2_host ) |
| 78 | self.addLink( s3, s3_host ) |
| 79 | self.addLink( s4, s4_host ) |
| 80 | self.addLink( s5, s5_host ) |
| 81 | self.addLink( s6, s6_host ) |
| 82 | self.addLink( s7, s7_host ) |
| 83 | self.addLink( s8, s8_host ) |
| 84 | self.addLink( s9, s9_host ) |
| 85 | self.addLink( s10, s10_host ) |
| 86 | self.addLink( s1, s2 ) |
| 87 | self.addLink( s2, s3 ) |
| 88 | self.addLink( s3, s4 ) |
| 89 | self.addLink( s4, s5 ) |
| 90 | self.addLink( s5, s6 ) |
| 91 | self.addLink( s6, s7 ) |
| 92 | self.addLink( s7, s8 ) |
| 93 | self.addLink( s8, s9 ) |
| 94 | self.addLink( s9, s10 ) |
| 95 | self.addLink( s10, s1 ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 96 | |
| 97 | topos = { 'ring': ( lambda: ringTopo() ) } |
| 98 | |
| 99 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 100 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 101 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 102 | def setupNetwork(): |
| 103 | "Create network" |
| 104 | topo = ringTopo() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 105 | # if controller_ip == '': |
| 106 | # controller_ip = '10.0.2.2'; |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 107 | # controller_ip = '127.0.0.1'; |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 108 | network = Mininet( topo=topo, switch=OVSSwitch, autoSetMacs=True, controller=None ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 109 | network.start() |
| 110 | CLI( network ) |
| 111 | network.stop() |
| 112 | |
| 113 | if __name__ == '__main__': |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 114 | setLogLevel( 'info' ) |
| 115 | # setLogLevel( 'debug' ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 116 | setupNetwork() |