#!/usr/bin/env python # -*- coding: utf8 -*- """ 2016.07.31 2 host n switch, topo is link, with failmode setting h1--s1--...--sn--h2 $ sudo python hw3_net.py [switchnum] or sudo ./hw3_net.py [switchnum] """ import sys from mininet.log import setLogLevel, info from mininet.net import Mininet from mininet.cli import CLI from mininet.node import RemoteController, OVSSwitch def MininetTopo(switchnum): switchlist = [] net = Mininet() info("Create host nodes.\n") lefthost = net.addHost("h1") righthost = net.addHost("h2") info("Create switch node.\n") count = 1 while count <= int(switchnum): switchname = "s" + str(count) switchlist.append(net.addSwitch(switchname, switch=OVSSwitch, protocols='OpenFlow13', failMode='secure')) count+=1 info("Connect to controller node.\n") net.addController(name='c1',controller=RemoteController,ip='192.168.1.22',port=6633) info("Create Links.\n") net.addLink(lefthost, switchlist[0]) count=1 while count <= int(switchnum)-1: net.addLink(switchlist[count-1],switchlist[count]) count+=1 net.addLink(righthost, switchlist[len(switchlist)-1]) info("build and start.\n") net.build() net.start() CLI(net) if __name__ == '__main__': setLogLevel('info') if len(sys.argv) > 2: print "Too much argv!!" sys.exit(0) elif len(sys.argv) == 2: MininetTopo(sys.argv[1]) else: MininetTopo(1)