예제 #1
0
파일: tinc.py 프로젝트: joanmarkt/ToMaTo
def _startEndpoint(endpoint):
	assert getState(endpoint) == generic.State.PREPARED
	host = endpoint.getHost()
	assert host
	assert process.portFree(host, endpoint.getPort())
	iface = _tincName(endpoint)
	host.execute("tincd --net=%s" % iface )
	util.waitFor(lambda :ifaceutil.interfaceExists(host, iface))
	assert ifaceutil.interfaceExists(host, iface), "Tinc deamon did not start"
	ifaceutil.ifup(host, iface)
예제 #2
0
파일: tc.py 프로젝트: david-hock/ToMaTo
def setIncomingRedirect(host, srcDev, dstDev):
	assert ifaceutil.interfaceExists(host, srcDev)
	assert ifaceutil.interfaceExists(host, dstDev)
	_tc_mod(host, "qdisc", "dev %s ingress" % util.escape(srcDev))
	""" 
	Protocol all would forward all traffic but that results
	in ARP traffic being multiplied and causing lots of traffic
	""" 
	_tc_mod(host, "filter", "dev %s parent ffff:" % util.escape(srcDev), \
	 "protocol all prio 49152 u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev %s" % util.escape(dstDev))
예제 #3
0
파일: tinc.py 프로젝트: david-hock/ToMaTo
def _startEndpoint(endpoint):
	state = getState(endpoint)
	assert state != generic.State.CREATED
	if state == generic.State.STARTED:
		_stopEndpoint(endpoint)
	host = endpoint.getHost()
	assert host
	if not process.portFree(host, endpoint.getPort()):
		process.killPortUser(host, endpoint.getPort())
	iface = _tincName(endpoint)
	host.execute("tincd --net=%s" % iface )
	util.waitFor(lambda :ifaceutil.interfaceExists(host, iface))
	assert ifaceutil.interfaceExists(host, iface), "Tinc deamon did not start"
	ifaceutil.ifup(host, iface)
예제 #4
0
파일: vzctl.py 프로젝트: m3z/ToMaTo
def addInterface(host, vmid, iface):
	state = getState(host, vmid)
	assert state != generic.State.CREATED, "VM not prepared"
	_vzctl(host, vmid, "set", ["--netif_add", iface, "--save"])
	_vzctl(host, vmid, "set", ["--ifname", iface, "--host_ifname", interfaceDevice(vmid, iface), "--save"])
	if state == generic.State.STARTED:
		assert ifaceutil.interfaceExists(host, interfaceDevice(vmid, iface))
예제 #5
0
파일: tc.py 프로젝트: david-hock/ToMaTo
def setLinkEmulation(host, dev, bandwidth=None, **kwargs):
	assert ifaceutil.interfaceExists(host, dev)
	netem_ref = "dev %s root handle 1:0" % util.escape(dev)
	if not bandwidth is None:
		netem_ref = "dev %s parent 1:1 handle 10:" % util.escape(dev)
		_tc_mod(host, "qdisc", "dev %s root handle 1:" % util.escape(dev), _buildTbf(bandwidth))
	_tc_mod(host, "qdisc", netem_ref, _buildNetem(bandwidth=bandwidth, **kwargs))
예제 #6
0
파일: tc.py 프로젝트: m3z/ToMaTo
def clearLinkEmulation(host, dev):
	assert ifaceutil.interfaceExists(host, dev)
	try:
		host.execute(_tc_cmd("qdisc", "del", "root dev %s" % util.escape(dev)))
	except exceptions.CommandError, exc:
		if not "No such file or directory" in exc.errorMessage:
			raise
예제 #7
0
def startCaptureToFile(host, name, iface, filter=""):
	assert name, "Name not given"
	assert ifaceutil.interfaceExists(host, iface), "Interface does not exist"
	assert _checkSyntax(host, iface, filter), "Syntax error: tcpdump -i %s %s" % (iface, filter)
	rdir = _remoteDir(name) 
	fileutil.mkdir(host, rdir)
	ifaceutil.ifup(host, iface)
	_tcpdump(host, "-i %(iface)s -n -C 10 -w %(rdir)s/capture -U -W 5 -s0 %(filter)s >/dev/null 2>&1 </dev/null & echo $! > %(rdir)s.file.pid" % {"iface": util.escape(iface), "rdir": rdir, "filter": util.escape(filter) })		
예제 #8
0
파일: qm.py 프로젝트: joanmarkt/ToMaTo
def addInterface(host, vmid, iface):
	assert getState(host, vmid) == generic.State.PREPARED, "VM must be stopped to add interfaces"
	iface_id = int(re.match("eth(\d+)", iface).group(1))
	# qm automatically connects ethN to vmbrN
	# if this bridge does not exist, kvm start fails
	if not ifaceutil.interfaceExists(host, "vmbr%d" % iface_id):
		ifaceutil.bridgeCreate(host, "vmbr%d" % iface_id)
	_qm(host, vmid, "set", "--vlan%d e1000" % iface_id)			
예제 #9
0
def startCaptureViaNet(host, name, port, iface, filter=""):
	assert name, "Name not given"
	assert port, "Port not given"
	assert ifaceutil.interfaceExists(host, iface), "Interface does not exist"
	assert process.portFree(host, port), "Port already in use"
	assert _checkSyntax(host, iface, filter), "Syntax error: tcpdump -i %s %s" % (iface, filter)
	rdir = _remoteDir(name) 
	fileutil.mkdir(host, rdir)
	ifaceutil.ifup(host, iface)
	host.execute("tcpserver -qHRl 0 0 %(port)d tcpdump -i %(iface)s -nUw - '%(filter)s' >/dev/null 2>&1 </dev/null & echo $! > %(rdir)s.net.pid" % {"iface": util.escape(iface), "rdir": rdir, "filter": util.escape(filter), "port": port })
	assert not process.portFree(host, port)
예제 #10
0
파일: tc.py 프로젝트: m3z/ToMaTo
def setLinkEmulation(host, dev, bandwidth=None, keepBandwidth=False, **kwargs):
	assert ifaceutil.interfaceExists(host, dev)
	netem_ref = "dev %s root handle 1:0" % util.escape(dev)
	cmd = ""
	if not bandwidth is None:
		netem_ref = "dev %s parent 1:1 handle 10:" % util.escape(dev)
		if not keepBandwidth:
			cmd = _tc_cmd("qdisc", "replace", "dev %s root handle 1:" % util.escape(dev), _buildTbf(bandwidth))
			cmd += ";"
	cmd += _tc_cmd("qdisc", "replace", netem_ref, _buildNetem(bandwidth=bandwidth, **kwargs))
	host.execute(cmd)
예제 #11
0
파일: tinc.py 프로젝트: joanmarkt/ToMaTo
def _setupRouting(endpoint):
	host = endpoint.getHost()
	assert host
	bridge = endpoint.getBridge()
	assert bridge
	id = endpoint.getId()
	assert id
	assert ifaceutil.bridgeExists(host, bridge)
	tincname = _tincName(endpoint)
	assert ifaceutil.interfaceExists(host, tincname)
	assert not ifaceutil.interfaceBridge(host, tincname)
	#enable ip forwarding
	host.execute ("sysctl -q -w net.ipv6.conf.all.forwarding=1");
	host.execute ("sysctl -q -w net.ipv4.conf.all.forwarding=1");
	#add gateway addresses
	for gw in endpoint.getGateways():
		ifaceutil.addAddress(host, bridge, gw)
	#set bridge up
	ifaceutil.ifup(host, bridge)
	ifaceutil.connectInterfaces(host, bridge, tincname, id, endpoint.getGateways())
예제 #12
0
파일: tinc.py 프로젝트: m3z/ToMaTo
def _setupRouting(endpoint):
	host = endpoint.getHost()
	assert host
	bridge = endpoint.getBridge()
	assert bridge
	id = endpoint.getId()
	assert id
	assert ifaceutil.bridgeExists(host, bridge)
	tincname = _tincName(endpoint)
	assert ifaceutil.interfaceExists(host, tincname)
	assert not ifaceutil.interfaceBridge(host, tincname)
	#enable ip forwarding
	host.execute ("sysctl -q -w net.ipv6.conf.all.forwarding=1");
	host.execute ("sysctl -q -w net.ipv4.conf.all.forwarding=1");
	#add gateway addresses
	for gw in endpoint.getGateways():
		ifaceutil.addAddress(host, bridge, gw)
	#set bridge up
	ifaceutil.ifup(host, bridge)
	ifaceutil.connectInterfaces(host, bridge, tincname, id, endpoint.getGateways())
	for gw in endpoint.getGateways():
		ip = gw.split("/")[0]
		util.waitFor(lambda :ifaceutil.reachable(host, ip, iface=bridge))
		assert ifaceutil.reachable(host, ip, iface=bridge), "Cannot reach %s in interface %s" % (ip, bridge)
예제 #13
0
파일: repy.py 프로젝트: david-hock/ToMaTo
def waitForInterface(host, vmid, iface):
	util.waitFor(lambda :ifaceutil.interfaceExists(host, interfaceDevice(vmid, iface)), maxWait=2)
	assert ifaceutil.interfaceExists(host, interfaceDevice(vmid, iface)), "Interface does not exist"
예제 #14
0
파일: tc.py 프로젝트: david-hock/ToMaTo
def clearIncomingRedirect(host, dev):
	assert ifaceutil.interfaceExists(host, dev)
	_tc(host, "qdisc", "del", "dev %s ingress" % util.escape(dev))
	_tc(host, "filter", "del", "dev %s parent ffff: prio 49152" % util.escape(dev))
예제 #15
0
파일: tc.py 프로젝트: david-hock/ToMaTo
def clearLinkEmulation(host, dev):
	assert ifaceutil.interfaceExists(host, dev)
	_tc(host, "qdisc", "del", "root dev %s" % util.escape(dev))