Skip to content

Instantly share code, notes, and snippets.

@pichuang
Created April 27, 2015 03:36
Show Gist options
  • Save pichuang/d8c4f7fc55a0d04e5b35 to your computer and use it in GitHub Desktop.
Save pichuang/d8c4f7fc55a0d04e5b35 to your computer and use it in GitHub Desktop.
regular l2 switch on mininet
#!/usr/bin/env python2
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.link import TCLink
from mininet.log import setLogLevel, info
from mininet.node import Controller, RemoteController
from mininet.cli import CLI
from mininet.link import Intf
from mininet.util import dumpNodeConnections
def MininetTopo():
'''
Prepare Your Topology
'''
net = Mininet (topo=None, build=False)
info("Create Host node\n")
teacher1 = net.addHost('teacher1', ip='10.0.0.1')
teacher2 = net.addHost('teacher2', ip='10.0.0.2')
student1 = net.addHost('student1', ip='10.0.0.3')
student2 = net.addHost('student2', ip='10.0.0.4')
info("Create Switch node\n")
info("Method 1: Use addSwitch to set-fail-mode\n")
switch1 = net.addSwitch('ovs1', protocols='OpenFlow13', failMode='standalone')
switch2 = net.addSwitch('ovs2', protocols='OpenFlow13', failMode='standalone')
switch3 = net.addSwitch('ovs3', protocols='OpenFlow13', failMode='standalone')
info("Link switch to host\n")
net.addLink(switch1, student1)
net.addLink(switch3, student2)
net.addLink(switch1, teacher1)
net.addLink(switch3, teacher2)
net.addLink(switch1, switch2)
net.addLink(switch2, switch3)
'''
Working your topology
'''
info("Start network\n")
net.start()
info("Dumping host connections\n")
dumpNodeConnections(net.hosts)
#info("Method 2: Use command line to set-fail-mode\n")
#switch1.cmdPrint("ovs-vsctl set-fail-mode ovs1 standalone")
#switch2.cmdPrint("ovs-vsctl set-fail-mode ovs2 standalone")
#switch3.cmdPrint("ovs-vsctl set-fail-mode ovs3 standalone")
info("Testing network connectivity\n")
net.pingAll()
'''
Clean mininet
'''
net.stop()
if __name__ == '__main__':
setLogLevel('info')
MininetTopo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment