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 tripleTopo( 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 | |
| 56 | # ... and now hosts |
| 57 | s1_host = self.addHost( 'h1', ip='10.1.0.1/24', cls=dualStackHost, v6Addr='1000::1/64' ) |
| 58 | s2_host = self.addHost( 'h2', ip='10.1.0.2/24', cls=dualStackHost, v6Addr='1000::2/64' ) |
| 59 | s3_host = self.addHost( 'h3', ip='10.1.0.3/24', cls=dualStackHost, v6Addr='1000::3/64' ) |
| 60 | |
| 61 | # add edges between switch and corresponding host |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 62 | self.addLink( s1, s1_host ) |
| 63 | self.addLink( s2, s2_host ) |
| 64 | self.addLink( s3, s3_host ) |
| 65 | self.addLink( s1, s2 ) |
| 66 | self.addLink( s1, s3 ) |
| 67 | self.addLink( s2, s3 ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 68 | |
| 69 | topos = { 'triple': ( lambda: tripleTopo() ) } |
| 70 | |
| 71 | # HERE THE CODE DEFINITION OF THE TOPOLOGY ENDS |
| 72 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 73 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 74 | def setupNetwork(): |
| 75 | "Create network" |
| 76 | topo = tripleTopo() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 77 | # if controller_ip == '': |
| 78 | # controller_ip = '10.0.2.2'; |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 79 | # controller_ip = '127.0.0.1'; |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 80 | network = Mininet( topo=topo, switch=OVSSwitch, autoSetMacs=True, controller=None ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 81 | network.start() |
| 82 | CLI( network ) |
| 83 | network.stop() |
| 84 | |
| 85 | if __name__ == '__main__': |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 86 | setLogLevel( 'info' ) |
| 87 | # setLogLevel( 'debug' ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 88 | setupNetwork() |