当前位置: 首页>>代码示例>>Python>>正文


Python Mininet.terms方法代码示例

本文整理汇总了Python中mininet.net.Mininet.terms方法的典型用法代码示例。如果您正苦于以下问题:Python Mininet.terms方法的具体用法?Python Mininet.terms怎么用?Python Mininet.terms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mininet.net.Mininet的用法示例。


在下文中一共展示了Mininet.terms方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: customNet

# 需要导入模块: from mininet.net import Mininet [as 别名]
# 或者: from mininet.net.Mininet import terms [as 别名]
def customNet(username, enableBlank, enableBasic, enableDhcp):
	user = username
	link_opts = {"bw":1000, "delay":10, "loss": 0, "use_htb": False}
	filename = "netanim_topo.xml"
	basic = enableBasic
	blank = enableBlank
	dhcp = enableDhcp

	print "enableBlank = ", enableBlank
	print "enableDhcp = ", enableDhcp
	print "enableBasic = ", enableBasic

	if(basic == "true" or blank == "true"):
		topo = basicTopo(link_opts = link_opts, filename = filename)
		net = Mininet(topo, switch = BridgeSwitch, controller = OVSController, link = TCLink)

	elif(dhcp == "true"):
		print("Setting up dhcp...")
		topo = dhcpTopo(link_opts = link_opts, filename = filename)
		net = Mininet(topo, switch = Router, controller = OVSController, link = TCLink)
	
	net.start()

	macs = random_macs(len(net.hosts))

	for offset, host in enumerate(net.hosts):
		#Set up default network with hardcoded ip addresses.
		if(basic == "true"):
			print "Capturing on hosts...", offset
			path = "/home/comhghall/Final-Year-Project/resources/" + str(host) + ".pcap"
			print "path = ", path
			host.cmd("tcpdump -u -w", path, "&")

		#Set up a blank network.
		elif(blank == "true" or dhcp == "true"):
			print "Capturing on hosts...", offset
			path = "/home/comhghall/Final-Year-Project/resources/" + str(host) + ".pcap"
			print "path = ", path
			interface = host.intf()
			print "Setting interfaces down..."
			host.cmd("ifconfig", interface, "down")
			host.cmd("ifconfig", interface, "0.0.0.0")
			host.cmd("ifconfig", interface, hex(macs[offset]))
			host.cmd("ifconfig", interface, "down")
			host.cmd("tcpdump -u -w", path, "&")

	for offset, switch in enumerate(net.switches):
		if(basic == "true" or blank == "true"):
			print "Capturing on switches...", offset
			print switch
			path = "/home/comhghall/Final-Year-Project/resources/" + str(switch) + "-eth0.pcap"
			print "path = ", path
			switch.cmd("tcpdump -i", switch, "-u -w", path, "&")

		if(dhcp == "true"):
			print "Capturing on switches...", offset
			print switch
			path = "/home/comhghall/Final-Year-Project/resources/" + str(switch) + "-eth0.pcap"
			print "path = ", path
			switch.cmd("sysctl -w net.ipv4.ip_forward=1")
			if str(switch)[0] != "r":
				print "Bridge switch..."
				switch.cmd("brctl", switch, "down")
				switch.cmd("brclt delbr", switch)
				switch.cmd("brctl addbr", switch)
				for interface in switch.intfNames():
					if interface != "lo":
						switch.cmd("ifconfig", interface, "down")
				for interface in switch.intfNames():
					if interface != "lo":
						switch.cmd("brctl addif", switch, interface)
				switch.cmd("brctl", switch, "up")
				for interface in switch.intfNames():
					if interface != "lo":
						switch.cmd("ifconfig", interface, "up")
				switch.cmd("tcpdump -i", switch, "-u -w", path, "&")
			else:
				print "Router..."
				switch.cmd("echo","",">/etc/dnsmasq.conf")
				for interface in switch.intfNames():
					if interface != "lo":
						switch.cmd("ifconfig", interface, "down")
						prefix,subnet_mask = random_subnet(24)
						dhcp_entry = "dhcp-range=" + socket.inet_ntoa(struct.pack('!L', prefix+10)) +"," + socket.inet_ntoa(struct.pack('!L', prefix+20))+",30s"
						print dhcp_entry
						switch.cmd("echo",dhcp_entry,">>/etc/dnsmasq.conf")
						switch.cmd("ifconfig", interface, "{0}/{1}".format(prefix+1, subnet_mask))
						switch.cmd("ifconfig", interface, "up")
						print interface
						if interface.count("eth"):
							print "Capturing on router..."
							path = "/home/comhghall/Final-Year-Project/resources/" + str(interface) + ".pcap"
							switch.cmd("tcpdump -i", interface, "-u -w", path, "&")
				switch.cmd("dnsmasq")

	net.terms = makeTabbedTerm(net.hosts, term = "xfce")
	net.terms = makeTabbedTerm(net.switches, term = "xfce")

	CLI(net)
	net.stop()
开发者ID:OysterKing,项目名称:Final-Year-Project,代码行数:102,代码来源:NetInitialiser.py


注:本文中的mininet.net.Mininet.terms方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。