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()

个人总结

这次实验的难度明显比上次难了不少,我在上课的时候也是听得一知半解,但是亲手实践明显能更好的理解这次的内容。在实验的过程中我在划分vlan的时候卡了很久,最后还是多次修改之后才成功,还是得要有耐心。进阶任务只要把任务四的划分代码整出来后ovs命令部分就很轻松了,看参考文档也看的不是很懂,还是要多去学习,代码只不过是拙劣地模仿罢了,像参考文档那样的方法我个人运行不了,可能缺少什么运行环境。还是要努力提高自己的知识水平,向大佬们学习。

posted @ 2021-09-10 16:01  Katra丶  阅读(35)  评论(0编辑  收藏  举报