Created
December 8, 2019 07:20
-
-
Save lovejavaee/89587f24d36bfdb46d581a6c1f880f7e to your computer and use it in GitHub Desktop.
network.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
"""Custom topology example | |
Two directly connected switches plus a host for each switch: | |
host --- switch --- switch --- host | |
_/ \_ | |
host / \ host | |
Adding the 'topos' dict with a key/value pair to generate our newly defined | |
topology enables one to pass in '--topo=mytopo' from the command line. | |
""" | |
from mininet.topo import Topo | |
from mininet.net import Mininet | |
from mininet.link import TCLink | |
from mininet.util import dumpNodeConnections | |
from mininet.log import setLogLevel | |
from mininet.cli import CLI | |
class TCPDemoTopo( Topo ): | |
def __init__( self ): | |
# Initialize topology | |
Topo.__init__( self ) | |
# Add hosts and switches | |
leftHost1 = self.addHost( 'h1' ) | |
leftHost2 = self.addHost( 'h2' ) | |
rightHost1 = self.addHost( 'h3' ) | |
rightHost2 = self.addHost( 'h4' ) | |
leftSwitch = self.addSwitch( 's1' ) | |
rightSwitch = self.addSwitch( 's2' ) | |
# Add links | |
self.addLink( leftHost1, leftSwitch, bw=100, delay='10ms' ) | |
self.addLink( leftHost2, leftSwitch, bw=100, delay='10ms' ) | |
self.addLink( leftSwitch, rightSwitch, bw=10, delay='100ms' ) | |
self.addLink( rightSwitch, rightHost1, bw=100, delay='10ms' ) | |
self.addLink( rightSwitch, rightHost2, bw=100, delay='10ms' ) | |
def setupTopo(): | |
"Create network" | |
topo = TCPDemoTopo() | |
net = Mininet( topo=topo, link=TCLink ) | |
net.start() | |
print "Dumping host connections" | |
dumpNodeConnections( net.hosts ) | |
print "Testing network connectivity" | |
net.pingAll() | |
CLI(net) | |
net.stop() | |
if __name__ == '__main__': | |
setLogLevel( 'info' ) | |
setupTopo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment