Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1 | ''' |
Joey Armstrong | 58cdf66 | 2023-01-03 14:11:34 -0500 | [diff] [blame] | 2 | Copyright 2016-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | |
| 16 | ''' |
| 17 | from mininet.cli import CLI |
| 18 | from mininet.log import setLogLevel |
| 19 | from mininet.net import Mininet |
| 20 | from mininet.topo import Topo |
| 21 | from mininet.node import RemoteController, UserSwitch |
| 22 | |
| 23 | class MinimalTopo( Topo ): |
| 24 | "Minimal topology with a single switch and two hosts" |
| 25 | |
| 26 | def build( self ): |
| 27 | # Create two hosts. |
| 28 | h1 = self.addHost( 'h1' ) |
| 29 | h2 = self.addHost( 'h2' ) |
| 30 | |
| 31 | # Create a switch |
| 32 | s1 = self.addSwitch( 's1', cls=UserSwitch) |
| 33 | |
| 34 | # Add links between the switch and each host |
| 35 | self.addLink( s1, h1 ) |
| 36 | self.addLink( s1, h2 ) |
| 37 | |
| 38 | def runMinimalTopo(): |
| 39 | "Bootstrap a Mininet network using the Minimal Topology" |
| 40 | |
| 41 | # Create an instance of our topology |
| 42 | topo = MinimalTopo() |
| 43 | |
| 44 | # Create a network based on the topology using OVS and controlled by |
| 45 | # a remote controller. |
| 46 | net = Mininet( |
| 47 | topo=topo, |
| 48 | controller=lambda name: RemoteController( name, ip='127.0.0.1' ), |
| 49 | switch=UserSwitch, |
| 50 | autoSetMacs=True ) |
| 51 | |
| 52 | # Actually start the network |
| 53 | net.start() |
| 54 | |
| 55 | # Drop the user in to a CLI so user can run commands. |
| 56 | CLI( net ) |
| 57 | |
| 58 | # After the user exits the CLI, shutdown the network. |
| 59 | net.stop() |
| 60 | |
| 61 | if __name__ == '__main__': |
| 62 | # This runs if this file is executed directly |
| 63 | setLogLevel( 'info' ) |
| 64 | runMinimalTopo() |
| 65 | |
| 66 | # Allows the file to be imported using `mn --custom <filename> --topo minimal` |
| 67 | topos = { |
| 68 | 'minimal': MinimalTopo |
| 69 | } |