20210419 期中週
Last updated
Last updated
cd mininet-wifi/
cd examples/
python miniedit.pycd ..
cd ..
cd test-miniedit/
gedit 1.pypython 1.pyh1 ping h2 -c 5#!/usr/bin/python
from mininet.net import Mininet
from mininet.node import Host, OVSKernelSwitch
from mininet.cli import CLI
from mininet.link import TCLink, Intf
from mininet.log import setLogLevel, info
from subprocess import call
def myNetwork():
net = Mininet(topo=None,
build=False,
ipBase='10.0.0.0/8')
info( '*** Adding controller\n' )
info( '*** Add switches/APs\n')
s1 = net.addSwitch('s1', cls=OVSKernelSwitch, failMode='standalone')
info( '*** Add hosts/stations\n')
h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
info( '*** Add links\n')
net.addLink(h1, s1)
net.addLink(h2, s1)
net.addLink(h3, s1)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches/APs\n')
net.get('s1').start([])
info( '*** Post configure nodes\n')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
myNetwork()cd ..cd mininet-wifi/
cd examples/
python miniedit.pycd ..
cd ..
cd test-miniedit/
gedit 2.pypython 2.pypingall -c 5#!/usr/bin/python
from mininet.net import Mininet
from mininet.node import Host, Node, OVSKernelSwitch
from mininet.cli import CLI
from mininet.link import TCLink, Intf
from mininet.log import setLogLevel, info
from subprocess import call
def myNetwork():
net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8')
info( '*** Adding controller\n' )
info( '*** Add switches/APs\n')
r1 = net.addHost('r1', ip='0.0.0.0')
r1.cmd('sysctl -w net.ipv4.ip_forward=1')
s3 = net.addSwitch('s3', cls=OVSKernelSwitch, failMode='standalone')
r2 = net.addHost('r2', ip='0.0.0.0')
r2.cmd('sysctl -w net.ipv4.ip_forward=1')
info( '*** Add hosts/stations\n')
h3 = net.addHost('h3', cls=Host, ip='192.168.20.2/24', defaultRoute='via 192.168.20.254')
h1 = net.addHost('h1', cls=Host, ip='192.168.10.1/24', defaultRoute='via 192.168.10.254')
h2 = net.addHost('h2', cls=Host, ip='192.168.20.1/24', defaultRoute='via 192.168.20.254')
info( '*** Add links\n')
net.addLink(s3, h3)
net.addLink(h1, r1)
net.addLink(r1, r2)
net.addLink(r2, s3)
net.addLink(h2, s3)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches/APs\n')
net.get('s3').start([])
info( '*** Post configure nodes\n')
r1.cmd("ifconfig r1-eth0 0")
r1.cmd("ifconfig r1-eth1 0")
r1.cmd("ifconfig r1-eth0 192.168.10.254/24")
r1.cmd("ifconfig r1-eth1 10.0.0.1/24")
r1.cmd("ip route add 192.168.20.0/24 via 10.0.0.2")
r2.cmd("ifconfig r2-eth0 0")
r2.cmd("ifconfig r2-eth1 0")
r2.cmd("ifconfig r2-eth0 10.0.0.2/24")
r2.cmd("ifconfig r2-eth1 192.168.20.254/24")
r2.cmd("ip route add 192.168.10.0/24 via 10.0.0.1")
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
myNetwork()cd ..cd mininet-wifi/
cd examples/
python miniedit.pycd ..
cd ..
cd test-miniedit/
gedit 3.pypython 3.pyh1 ping h2 -c 5!/usr/bin/python
from mininet.net import Mininet from mininet.node import Controller, OVSKernelSwitch, Host from mininet.cli import CLI from mininet.link import TCLink, Intf from mininet.log import setLogLevel, info from subprocess import call
def myNetwork():
net = Mininet(topo=None,
build=False,
ipBase='10.0.0.0/8')
info( '*** Adding controller\n' )
c0 = net.addController(name='c0',
controller=Controller,
protocol='tcp',
port=6633)
info( '*** Add switches/APs\n')
s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
info( '*** Add hosts/stations\n')
h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
info( '*** Add links\n')
net.addLink(s2, h2)
net.addLink(s1, h1)
net.addLink(s1, s2)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches/APs\n')
net.get('s2').start([c0])
net.get('s1').start([c0])
info( '*** Post configure nodes\n')
CLI(net)
net.stop()
if name == 'main': setLogLevel( 'info' ) myNetwork()ovs-ofctl dump-flows s1ovs-ofctl dump-flows s2ovs-ofctl dump-flows s1ovs-ofctl dump-flows s2cd ..cd mininet-wifi/
cd examples/
python miniedit.pycd ..
cd ..
cd test-miniedit/
gedit 3-1.pypython 3-1.pyh1 ping h2 -c 5h1 ping h2 -c 5#!/usr/bin/python
from mininet.net import Mininet
from mininet.node import RemoteController, OVSKernelSwitch, Host
from mininet.cli import CLI
from mininet.link import TCLink, Intf
from mininet.log import setLogLevel, info
from subprocess import call
def myNetwork():
net = Mininet(topo=None,
build=False,
ipBase='10.0.0.0/8')
info( '*** Adding controller\n' )
c0 = net.addController(name='c0',
controller=RemoteController,
ip='127.0.0.1',
protocol='tcp',
port=6633)
info( '*** Add switches/APs\n')
s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
info( '*** Add hosts/stations\n')
h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
info( '*** Add links\n')
net.addLink(s2, s1)
net.addLink(s1, h1)
net.addLink(s2, h2)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches/APs\n')
net.get('s1').start([c0])
net.get('s2').start([c0])
info( '*** Post configure nodes\n')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
myNetwork()
cd ryu/ryu/appryu-manager simple_switch.pyovs-ofctl dump-flows s1ovs-ofctl dump-flows s2mkdir examcd examgedit switch.py#!/usr/bin/env python
from mininet.cli import CLI
from mininet.net import Mininet
from mininet.link import Link,TCLink,Intf
from mininet.node import Controller,RemoteController
if '__main__' == __name__:
net = Mininet(link=TCLink)
h1 = net.addHost('h1', ip="192.168.10.1")
h2 = net.addHost('h2', ip="192.168.20.1")
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
s3 = net.addSwitch('s3')
s4 = net.addSwitch('s4')
c0 = net.addController('c0', controller=RemoteController)
net.addLink(h1, s1)
net.addLink(s1, s2)
net.addLink(s1, s3)
net.addLink(s2, s4)
net.addLink(s3, s4)
net.addLink(s4, h2)
net.build()
c0.start()
s1.start([c0])
s2.start([c0])
s3.start([c0])
s4.start([c0])
# rules for s1
# h1 ping h2
s1.cmd("ovs-ofctl add-flow s1 arp,arp_op=1,arp_spa=192.168.10.1,arp_tpa=192.168.20.1,actions=output:2")
s1.cmd("ovs-ofctl add-flow s1 arp,arp_op=1,arp_spa=192.168.20.1,arp_tpa=192.168.10.1,actions=output:1")
s1.cmd("ovs-ofctl add-flow s1 arp,arp_op=2,arp_spa=192.168.10.1,arp_tpa=192.168.20.1,actions=output:2")
s1.cmd("ovs-ofctl add-flow s1 arp,arp_op=2,arp_spa=192.168.20.1,arp_tpa=192.168.10.1,actions=output:1")
s1.cmd("ovs-ofctl add-flow s1 icmp,nw_src=192.168.10.1,nw_dst=192.168.20.1,icmp_type=8,icmp_code=0,actions=output:2")
s1.cmd("ovs-ofctl add-flow s1 icmp,nw_src=192.168.20.1,nw_dst=192.168.10.1,icmp_type=0,icmp_code=0,actions=output:1")
s1.cmd("ovs-ofctl add-flow s1 icmp,nw_src=192.168.20.1,nw_dst=192.168.10.1,icmp_type=8,icmp_code=0,actions=output:1")
s1.cmd("ovs-ofctl add-flow s1 icmp,nw_src=192.168.10.1,nw_dst=192.168.20.1,icmp_type=0,icmp_code=0,actions=output:3")
# rules for s2
# h1 ping h2
s2.cmd("ovs-ofctl add-flow s2 arp,arp_op=1,arp_spa=192.168.10.1,arp_tpa=192.168.20.1,actions=output:2")
s2.cmd("ovs-ofctl add-flow s2 arp,arp_op=1,arp_spa=192.168.20.1,arp_tpa=192.168.10.1,actions=output:1")
s2.cmd("ovs-ofctl add-flow s2 arp,arp_op=2,arp_spa=192.168.10.1,arp_tpa=192.168.20.1,actions=output:2")
s2.cmd("ovs-ofctl add-flow s2 arp,arp_op=2,arp_spa=192.168.20.1,arp_tpa=192.168.10.1,actions=output:1")
s2.cmd("ovs-ofctl add-flow s2 icmp,nw_src=192.168.10.1,nw_dst=192.168.20.1,icmp_type=8,icmp_code=0,actions=output:2")
s2.cmd("ovs-ofctl add-flow s2 icmp,nw_src=192.168.20.1,nw_dst=192.168.10.1,icmp_type=8,icmp_code=0,actions=output:1")
# rules for s3
s3.cmd("ovs-ofctl add-flow s3 icmp,nw_src=192.168.10.1,nw_dst=192.168.20.1,icmp_type=0,icmp_code=0,actions=output:2")
s3.cmd("ovs-ofctl add-flow s3 icmp,nw_src=192.168.20.1,nw_dst=192.168.10.1,icmp_type=0,icmp_code=0,actions=output:1")
# rules for s4
s4.cmd("ovs-ofctl add-flow s4 arp,arp_op=1,arp_spa=192.168.10.1,arp_tpa=192.168.20.1,actions=output:3")
s4.cmd("ovs-ofctl add-flow s4 arp,arp_op=1,arp_spa=192.168.20.1,arp_tpa=192.168.10.1,actions=output:1")
s4.cmd("ovs-ofctl add-flow s4 arp,arp_op=2,arp_spa=192.168.10.1,arp_tpa=192.168.20.1,actions=output:3")
s4.cmd("ovs-ofctl add-flow s4 arp,arp_op=2,arp_spa=192.168.20.1,arp_tpa=192.168.10.1,actions=output:1")
s4.cmd("ovs-ofctl add-flow s4 icmp,nw_src=192.168.10.1,nw_dst=192.168.20.1,icmp_type=8,icmp_code=0,actions=output:3")
s4.cmd("ovs-ofctl add-flow s4 icmp,nw_src=192.168.20.1,nw_dst=192.168.10.1,icmp_type=0,icmp_code=0,actions=output:2")
s4.cmd("ovs-ofctl add-flow s4 icmp,nw_src=192.168.20.1,nw_dst=192.168.10.1,icmp_type=8,icmp_code=0,actions=output:1")
s4.cmd("ovs-ofctl add-flow s4 icmp,nw_src=192.168.10.1,nw_dst=192.168.20.1,icmp_type=0,icmp_code=0,actions=output:3")
CLI(net)
net.stop()