SDN第二次上机作业
SDN第二次上机作业
任务一
任务二
任务三
任务四
进阶任务
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import CPULimitedHost, RemoteController, Controller
from mininet.node import OVSKernelSwitch, UserSwitch, Node, Host
from mininet.log import setLogLevel
from mininet.link import TCLink
from mininet.cli import CLI
import os
class MyTopo(Topo):
def __init__(self):
Topo.__init__(self)
s1 = self.addSwitch('s1', cls=OVSKernelSwitch)
s2 = self.addSwitch('s2', cls=OVSKernelSwitch)
h1 = self.addHost('h1', cls=Host, ip='192.168.123.1')
h2 = self.addHost('h2', cls=Host, ip='192.168.123.2')
h3 = self.addHost('h3', cls=Host, ip='192.168.123.3')
h4 = self.addHost('h4', cls=Host, ip='192.168.123.4')
self.addLink(s1,h1)
self.addLink(s1,h2)
self.addLink(s2,h3)
self.addLink(s2,h4)
self.addLink(s1,s2)
os.system('ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:3')
os.system('ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:3')
os.system('ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:3')
os.system('ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:3')
os.system('ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=0,actions=pop_vlan,output:1')
os.system('ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=0,actions=pop_vlan,output:1')
os.system('ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=1,actions=pop_vlan,output:2')
os.system('ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=1,actions=pop_vlan,output:2')
os.system('ovs-vsctl show')
def simpleTest():
topo=MyTopo()
net = Mininet(topo,host=CPULimitedHost,link=TCLink)
net.start()
CLI(net)
net.stop()
if __name__=='__main__':
setLogLevel('info')
Mininet.init()
simpleTest()