Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from mininet.node import Controller, RemoteController, OVSController
- from mininet.node import CPULimitedHost, Host, Node
- from mininet.node import OVSKernelSwitch, UserSwitch
- from mininet.node import OVSSwitch
- from mininet.net import Mininet
- from mininet.cli import CLI
- from mininet.log import setLogLevel, info
- from mininet.link import TCLink, Intf
- import datetime
- import os, sys, time
- def customRing2(upper, lower):
- net = Mininet( controller=RemoteController, switch=OVSKernelSwitch, autoStaticArp=True, autoSetMacs=True)
- info( "*** Creating (reference) controller\n" )
- c1=net.addController(name='c1',controller=RemoteController,ip='0.0.0.0',port=6633)
- info( "*** Creating switches\n" )
- s1 = net.addSwitch( 's1' )
- s2 = net.addSwitch( 's2' )
- s3 = net.addSwitch( 's3' )
- info( "*** Creating h\n" )
- h1 = net.addHost( 'h1')
- h2 = net.addHost( 'h2')
- h3 = net.addHost( 'h3')
- h4 = net.addHost( 'h4')
- h5 = net.addHost( 'h5')
- h6 = net.addHost( 'h6')
- info( "*** Creating links\n" )
- link = net.addLink(s1, h1)
- link.intf1.config(bw=0.03)
- link = net.addLink(s1, h2)
- link.intf1.config(bw=0.03)
- link = net.addLink(s2, h3)
- link.intf1.config(bw=0.03)
- link = net.addLink(s2, h4)
- link.intf1.config(bw=0.03)
- link = net.addLink(s3, h5)
- link.intf1.config(bw=0.03)
- link = net.addLink(s3, h6)
- link.intf1.config(bw=0.03)
- link = net.addLink(s1, s2)
- link.intf1.config(bw=0.03)
- link = net.addLink(s2, s3)
- link.intf1.config(bw=0.03)
- link = net.addLink(s1, s3)
- link.intf1.config(bw=0.03)
- info( "*** Starting network\n" )
- c1.start()
- s1.start( [c1] )
- s2.start( [c1] )
- s3.start( [c1] )
- net.build()
- info( "*** Please, run controller and ryu using the command: $ryu-manager ryu.app.qos_rest_router ryu.app.rest_qos ryu.app.rest_conf_switch\n" )
- CLI( net )
- #configuring switches
- s1.cmd('ovs-vsctl set Bridge s1 protocols=OpenFlow13')
- s1.cmd('ovs-vsctl set-manager ptcp:6632')
- s2.cmd('ovs-vsctl set Bridge s2 protocols=OpenFlow13')
- s2.cmd('ovs-vsctl set-manager ptcp:6632')
- s3.cmd('ovs-vsctl set Bridge s3 protocols=OpenFlow13')
- s3.cmd('ovs-vsctl set-manager ptcp:6632')
- #configuring hosts
- h1.cmd('ifconfig h1-eth0 inet 1.1.1.2/30 && ifconfig h1-eth0 up')
- h2.cmd('ifconfig h2-eth0 inet 1.1.2.2/30 && ifconfig h2-eth0 up')
- h3.cmd('ifconfig h3-eth0 inet 2.2.1.2/30 && ifconfig h3-eth0 up')
- h4.cmd('ifconfig h4-eth0 inet 2.2.2.2/30 && ifconfig h4-eth0 up')
- h5.cmd('ifconfig h5-eth0 inet 3.3.1.2/30 && ifconfig h5-eth0 up')
- h6.cmd('ifconfig h6-eth0 inet 3.3.2.2/30 && ifconfig h6-eth0 up')
- #configure hosts connections
- h1.cmd("ip route add default via 1.1.1.1")
- h2.cmd("ip route add default via 1.1.2.1")
- h3.cmd("ip route add default via 2.2.1.1")
- h4.cmd("ip route add default via 2.2.2.1")
- h5.cmd("ip route add default via 3.3.1.1")
- h6.cmd("ip route add default via 3.3.2.1")
- #local gateway networks
- c1.cmd("curl -X POST -d '{\"address\": \"1.1.1.1/30\"}' http://localhost:8080/router/0000000000000001")
- c1.cmd("curl -X POST -d '{\"address\": \"1.1.2.1/30\"}' http://localhost:8080/router/0000000000000001")
- c1.cmd("curl -X POST -d '{\"address\": \"2.2.1.1/30\"}' http://localhost:8080/router/0000000000000002")
- c1.cmd("curl -X POST -d '{\"address\": \"2.2.2.1/30\"}' http://localhost:8080/router/0000000000000002")
- c1.cmd("curl -X POST -d '{\"address\": \"3.3.1.1/30\"}' http://localhost:8080/router/0000000000000003")
- c1.cmd("curl -X POST -d '{\"address\": \"3.3.2.1/30\"}' http://localhost:8080/router/0000000000000003")
- #outer gateway networks
- c1.cmd("curl -X POST -d '{\"address\": \"13.13.13.1/30\"}' http://localhost:8080/router/0000000000000001")
- c1.cmd("curl -X POST -d '{\"address\": \"20.6.20.2/30\"}' http://localhost:8080/router/0000000000000001")
- c1.cmd("curl -X POST -d '{\"address\": \"20.6.20.1/30\"}' http://localhost:8080/router/0000000000000002")
- c1.cmd("curl -X POST -d '{\"address\": \"45.45.45.2/30\"}' http://localhost:8080/router/0000000000000002")
- c1.cmd("curl -X POST -d '{\"address\": \"45.45.45.1/30\"}' http://localhost:8080/router/0000000000000003")
- c1.cmd("curl -X POST -d '{\"address\": \"13.13.13.2/30\"}' http://localhost:8080/router/0000000000000003")
- #configure inter switches connections
- c1.cmd("curl -X POST -d '{\"gateway\": \"20.6.20.1\"}' http://localhost:8080/router/0000000000000001")
- c1.cmd("curl -X POST -d '{\"gateway\": \"45.45.45.1\"}' http://localhost:8080/router/0000000000000002")
- c1.cmd("curl -X POST -d '{\"gateway\": \"13.13.13.1\"}' http://localhost:8080/router/0000000000000003")
- # #configure static routes
- # #inter servers
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s1 priority=65535,nw_src=1.1.1.2,ip,nw_dst=3.3.1.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s2 priority=65535,nw_src=2.2.1.2,ip,nw_dst=1.1.1.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s3 priority=65535,nw_src=3.3.1.2,ip,nw_dst=2.2.1.2,actions=drop")
- # #server 1 - clients
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s1 priority=65535,nw_src=1.1.1.2,ip,nw_dst=1.1.2.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s1 priority=65535,nw_src=1.1.1.2,ip,nw_dst=2.2.2.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s1 priority=65535,nw_src=1.1.1.2,ip,nw_dst=3.3.2.2,actions=drop")
- # #server 2 - clients
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s2 priority=65535,nw_src=2.2.1.2,ip,nw_dst=1.1.2.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s2 priority=65535,nw_src=2.2.1.2,ip,nw_dst=2.2.2.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s2 priority=65535,nw_src=2.2.1.2,ip,nw_dst=3.3.2.2,actions=drop")
- # #server 3 - clients
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s3 priority=65535,nw_src=3.3.1.2,ip,nw_dst=1.1.2.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s3 priority=65535,nw_src=3.3.1.2,ip,nw_dst=2.2.2.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s3 priority=65535,nw_src=3.3.1.2,ip,nw_dst=3.3.2.2,actions=drop")
- # #client 1 - servers
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s1 priority=65535,nw_src=1.1.2.2,ip,nw_dst=1.1.1.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s1 priority=65535,nw_src=1.1.2.2,ip,nw_dst=2.2.1.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s1 priority=65535,nw_src=1.1.2.2,ip,nw_dst=3.3.1.2,actions=drop")
- # #client 2 - servers
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s2 priority=65535,nw_src=2.2.2.2,ip,nw_dst=1.1.1.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s2 priority=65535,nw_src=2.2.2.2,ip,nw_dst=2.2.1.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s2 priority=65535,nw_src=2.2.2.2,ip,nw_dst=3.3.1.2,actions=drop")
- # #client 3 - servers
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s3 priority=65535,nw_src=3.3.2.2,ip,nw_dst=1.1.1.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s3 priority=65535,nw_src=3.3.2.2,ip,nw_dst=2.2.1.2,actions=drop")
- # os.system("ovs-ofctl -O OpenFlow13 add-flow s3 priority=65535,nw_src=3.3.2.2,ip,nw_dst=3.3.1.2,actions=drop")
- #configuring controller
- c1.cmd('curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000001/ovsdb_addr')
- c1.cmd('curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000002/ovsdb_addr')
- c1.cmd('curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000003/ovsdb_addr')
- if(datetime.datetime.now().time().hour >= lower and datetime.datetime.now().time().hour < upper):
- info("*** Setting QOS rules.\n")
- c1.cmd('curl -X POST -d \'{"port_name": "s1-eth1", "type": "linux-htb", "max_rate": "30000", "queues": [{"min_rate": "20000"}]}\' http://localhost:8080/qos/queue/0000000000000001')
- c1.cmd('curl -X POST -d \'{"port_name": "s2-eth1", "type": "linux-htb", "max_rate": "30000", "queues": [{"min_rate": "20000"}]}\' http://localhost:8080/qos/queue/0000000000000002')
- c1.cmd('curl -X POST -d \'{"port_name": "s3-eth1", "type": "linux-htb", "max_rate": "30000", "queues": [{"min_rate": "20000"}]}\' http://localhost:8080/qos/queue/0000000000000003')
- c1.cmd('curl -X POST -d \'{"match": {"nw_dst": "1.1.1.2", "nw_proto": "TCP", "tp_dst": "1234"}, "actions":{"queue": "0"} }\' http://localhost:8080/qos/rules/0000000000000003')
- c1.cmd('curl -X POST -d \'{"match": {"nw_dst": "2.2.1.2", "nw_proto": "TCP", "tp_dst": "1234"}, "actions":{"queue": "0"} }\' http://localhost:8080/qos/rules/0000000000000001')
- c1.cmd('curl -X POST -d \'{"match": {"nw_dst": "3.3.1.2", "nw_proto": "TCP", "tp_dst": "1234"}, "actions":{"queue": "0"} }\' http://localhost:8080/qos/rules/0000000000000002')
- info( "*** Running CLI\n" )
- CLI( net )
- info( "*** Stopping network\n" )
- net.stop()
- if __name__ == '__main__':
- setLogLevel( 'info' )
- hourInterval = sys.argv[1]
- upper = int(hourInterval.split(":")[1])
- lower = int(hourInterval.split(":")[0])
- customRing2(upper, lower)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement