needs further debugging

This commit is contained in:
Jake Hillion 2020-11-09 14:18:23 +00:00
parent 268d26d802
commit ad07a44065
4 changed files with 131 additions and 84 deletions

View File

@ -331,55 +331,19 @@
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%% md\n"
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"### Equal Connection Scaling\n",
"This section shows equal connections scaling at various speeds and number of connections."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"plot_iperf_results(\n",
" {\n",
" '2x1MBps Connections (proxied)': directionInbound['Two1MBProxied'],\n",
" '1x1MBps Connection (not proxied)': directionInbound['One1MBNotProxied'],\n",
" },\n",
" 'Two Equal 1MB Connections',\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"plot_iperf_results(\n",
" {\n",
" '2x2MBps Connections (proxied)': directionInbound['Two2MBProxied'],\n",
" '1x2MBps Connection (not proxied)': directionInbound['One2MBNotProxied'],\n",
" },\n",
" 'Two Equal 2MB Connections',\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,

View File

@ -227,11 +227,11 @@ class ProxmoxRunner:
except (paramiko.ssh_exception.AuthenticationException, paramiko.ssh_exception.NoValidConnectionsError):
time.sleep(10)
node.client = client
node.ssh_client = client
def _close_ssh(self, node: structure.Node):
node.client.close()
del node.client
node.ssh_client.close()
del node.ssh_client
def ssh(
self,
@ -241,7 +241,7 @@ class ProxmoxRunner:
error_stdout=False,
return_stdout=False,
) -> Union[int, str]:
chan = node.client.get_transport().open_session()
chan = node.ssh_client.get_transport().open_session()
chan.exec_command(command)
exit_status = chan.recv_exit_status()
@ -296,7 +296,7 @@ class ProxmoxRunner:
self._setup_node_interfaces(node)
start_task = self._proxmox.nodes(self._proxmox_node).qemu(node.get_id()).status.start.post()
self._await_task(start_task)
self._await_task(start_task, timeout=20)
self._open_ssh(node)
node.ssh = (lambda n: lambda *args, **kwargs: self.ssh(n, *args, **kwargs))(node)
@ -310,15 +310,14 @@ class ProxmoxRunner:
interface = interfaces[i]
method = interface.get_method()
if method == structure.IpMethod.Manual:
pass
elif method == structure.IpMethod.Management:
if method == structure.IpMethod.Management:
interface.set_bridge(self._management_bridge)
addr = self._management_initial_ip + node.get_id() - self._initial_vm_id
kwargs['ipconfig{}'.format(i)] = 'ip={}/{}'.format(addr, self._management_netmask)
interface.set_address(addr)
elif method == structure.IpMethod.Auto4:
elif method == structure.IpMethod.Auto4 or method == structure.IpMethod.Manual:
# handle manual the same as auto4 so it doesn't get stuck in DHCP
bridge = interface.get_bridge()
addr = bridge.get_ip_address()
@ -365,7 +364,9 @@ class ProxmoxRunner:
def _setup_node(self, node: structure.Node):
if node.get_setup() is not None:
self.ssh(node, node.get_setup(), error_stdout=True, error_stderr=True)
cmd = node.get_setup()
print(cmd)
self.ssh(node, cmd, error_stdout=True, error_stderr=True)
def teardown(self):
for node in self._created_nodes:

View File

@ -126,12 +126,32 @@ class Node:
class SpeedTestServer(Node):
def __init__(self, clone_interface: Interface = None, **kwargs):
super().__init__([Interface(IpMethod.Manual)], **kwargs)
self.clone_interface = clone_interface
def get_internet_setup(self) -> Optional[str]:
return textwrap.dedent('''
cloud-init status --wait || cloud-init status --long
sleep 2
sudo apt-get install -y iperf3
''')
def get_setup(self) -> Optional[str]:
if self.clone_interface is None:
return None
self.get_interfaces()[0].set_address(self.clone_interface.get_address())
return textwrap.dedent('''
set -e
sudo ip addr flush dev eth0
sudo ip addr add {} dev eth0
sudo ip route add 192.168.1.1 dev eth0
sudo ip route add default via 192.168.1.1 dev eth0
''').format(self.clone_interface.get_address())
def server(self):
self.ssh('iperf3 -s -1 -D', error_stdout=True, error_stderr=True)
@ -164,13 +184,14 @@ class RemotePortal(Node):
chmod +x mpbl3p
cloud-init status --wait || cloud-init status --long
sudo apt-get install -y iperf3
''').format(**self.setup_params)
def get_setup(self) -> Optional[str]:
return textwrap.dedent('''
set -e
sudo sysctl -w net.ipv4.ip_forward=1
cat << EOF > config.ini
[Host]
PrivateKey = INVALID
@ -186,17 +207,17 @@ class RemotePortal(Node):
(nohup sudo ./mpbl3p > mpbl3p.log 2>&1 & echo $! > mpbl3p.pid)
sleep 1
sudo ip link set up nc0
sudo ip addr add 172.19.152.2/31 dev nc0
sudo ip link set up nc0
ip rule add from all table local priority 20
ip rule del 0
sudo ip rule add from all table local priority 20
sudo ip rule del 0
ip rule add to {local_host} dport 1234 table local priority 9
sudo ip rule add to {local_host} dport 1234 table local priority 9
ip route flush 10
ip route add table 10 to {local_host} via 172.19.152.3 dev nc0
ip rule add to {local_host} table 10 priority 10
sudo ip route flush 10
sudo ip route add table 10 to {local_host} via 172.19.152.3 dev nc0
sudo ip rule add to {local_host} table 10 priority 10
ps $(cat mpbl3p.pid)
''').format(
@ -204,14 +225,6 @@ class RemotePortal(Node):
**self.setup_params,
)
def speedtest_server(self):
self.ssh('iperf3 -s -1 -D', error_stdout=True, error_stderr=True)
def speedtest_client(self, target, time=30):
command = 'iperf3 -c {target} -t {time} -O 5 -J'.format(target=target, time=time)
out = self.ssh(command, error_stdout=True, error_stderr=True, return_stdout=True)
return json.loads(out)
class LocalPortal(Node):
def __init__(self, wan_interfaces: List[Interface], child: Optional[Node], **kwargs):
@ -241,7 +254,6 @@ class LocalPortal(Node):
chmod +x mpbl3p
cloud-init status --wait || cloud-init status --long
sudo apt-get install -y iperf3
''').format(**self.setup_params)
def get_setup(self) -> str:
@ -259,7 +271,7 @@ class LocalPortal(Node):
peers = '\n\n'.join([peer_string.format(
local_host=x.get_address(),
remote_host=self.remote_portal.get_interfaces()[0].get_address(),
) for x in self.get_interfaces()[:-1]])
) for x in self.get_interfaces()[:-2]])
policy_routing_string = textwrap.dedent('''
sudo ip route flush {table_number}
@ -280,6 +292,8 @@ class LocalPortal(Node):
sudo sysctl -w net.ipv4.conf.all.arp_announce=1
sudo sysctl -w net.ipv4.conf.all.arp_ignore=1
sudo sysctl -w net.ipv4.ip_forward=1
{policy_routing}
cat << EOF > config.ini
@ -291,17 +305,20 @@ class LocalPortal(Node):
(nohup sudo ./mpbl3p > mpbl3p.log 2>&1 & echo $! > mpbl3p.pid)
sleep 1
sleep 2
sudo ip link set up nc0
sudo ip addr add 172.19.152.3/31 dev nc0
ip route flush 8
ip route add table 8 default via 172.19.152.2 dev nc0
ip rule add from {remote_host} iif {local_interface} table 8 priority 8
sudo ip route flush 8
sudo ip route add table 8 default via 172.19.152.2 dev nc0
sudo ip rule add from {remote_host} iif {local_interface} table 8 priority 8
ip route flush 9
ip route add table 9 to {remote_host} dev {local_interface}
ip rule add to {remote_host} table 9 priority 9
sudo ip route flush 9
sudo ip route add table 9 to {remote_host} dev {local_interface}
sudo ip rule add to {remote_host} table 9 priority 9
sudo ip addr flush dev {local_interface}
sudo ip addr add 192.168.1.1 dev {local_interface}
ps $(cat mpbl3p.pid)
''').format(
@ -311,11 +328,3 @@ class LocalPortal(Node):
remote_host=self.remote_portal.get_interfaces()[0].get_address(),
local_interface='eth{}'.format(len(self.get_interfaces())-2),
)
def speedtest_server(self):
self.ssh('iperf3 -s -1 -D', error_stdout=True, error_stderr=True)
def speedtest_client(self, target, time=30):
command = 'iperf3 -c {target} -t {time} -O 5 -J'.format(target=target, time=time)
out = self.ssh(command, error_stdout=True, error_stderr=True, return_stdout=True)
return json.loads(out)

73
test.py Normal file
View File

@ -0,0 +1,73 @@
import os
import ipaddress
import runners
from structure import Bridge
from structure import RemotePortal, LocalPortal, SpeedTestServer
from structure import Interface, IpMethod
import dotenv
dotenv.load_dotenv()
runner = runners.ProxmoxRunner(
host=os.getenv('PROXMOX_HOST'),
node=os.getenv('PROXMOX_NODE'),
user=os.getenv('PROXMOX_USER'),
token_name=os.getenv('PROXMOX_TOKEN_NAME'),
token_value=os.getenv('PROXMOX_TOKEN_VALUE'),
template_id=9000,
initial_vm_id=21002,
internet_bridge=os.getenv('INTERNET_BRIDGE'),
management_bridge=os.getenv('MANAGEMENT_BRIDGE'),
management_initial_ip=ipaddress.ip_address(os.getenv('MANAGEMENT_INITIAL_IP')),
)
setup_params = {
'access_key': os.getenv('S3_ACCESS_KEY'),
'secret_key': os.getenv('S3_SECRET_KEY'),
'branch': os.getenv('TARGET_BRANCH'),
}
directionInbound = {}
directionOutbound = {}
rp = RemotePortal([Interface(IpMethod.Auto4)], setup_params=setup_params)
st = SpeedTestServer()
cl = SpeedTestServer(clone_interface=rp.get_interfaces()[0])
lp = LocalPortal([
Interface(IpMethod.Auto4),
Interface(IpMethod.Auto4),
], cl, setup_params=setup_params)
rp.set_local_portal(lp)
lp.set_remote_portal(rp)
top_level_bridge = Bridge(*[
st.get_interfaces()[0],
rp.get_interfaces()[0],
*lp.get_interfaces()[0:2],
])
try:
runner.build(top_level_bridge)
lp.get_interfaces()[0].set_rate(1)
lp.get_interfaces()[1].set_rate(1)
cl.server()
two1MbProxiedInbound = st.client(cl.get_interfaces()[0].get_address())
st.server()
two1MbProxiedOutbound = cl.client(st.get_interfaces()[0].get_address())
input('NO error: press enter to cleanup')
except Exception as e:
input('ERROR: press enter to cleanup')
raise e
finally:
runner.teardown()