added initial scripts

This commit is contained in:
Jake Hillion 2021-03-14 18:04:18 +00:00
parent 1d04faa40b
commit c05794ed81
5 changed files with 189 additions and 39 deletions

View File

@ -1,5 +1,5 @@
plugins {
id 'java'
id 'application'
id 'com.diffplug.spotless' version '5.9.0'
}
@ -19,9 +19,13 @@ spotless {
}
dependencies {
implementation 'com.github.JakeHillion:virtual-tests:55b7d1a73e9d16e91d70874c8bc225301f14ac64'
implementation 'io.github.cdimascio:dotenv-java:2.2.0'
implementation 'com.github.JakeHillion:virtual-tests:1a560528f4c174f592c4412d5710b2c57e0a5be6'
}
application {
mainClass = 'uk.ac.cam.jsh77.dissertationevaluation.DissertationEvaluation'
}
test {

View File

@ -4,4 +4,46 @@ set -e
wget -q https://f001.backblazeb2.com/file/dissertation/binaries/debian/%1$s_linux_amd64 -O mpbl3p
chmod +x mpbl3p
mkdir -p /opt/netcombiner
mv mpbl3p /opt/netcombiner/mpbl3p
cat <<EOF > /etc/systemd/system/netcombiner.service
[Unit]
Description=NetCombiner
After=network-online.target
[Service]
ExecStartPre=/opt/netcombiner/exec-start-pre.sh
ExecStart=/opt/netcombiner/mpbl3p
ExecStartPost=/opt/netcombiner/exec-start-post.sh
User=root
Group=root
WorkingDirectory=/opt/netcombiner
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF > /opt/netcombiner/exec-start-pre.sh
EOF
cat <<EOF > /opt/netcombiner/exec-start-post.sh
EOF
cat <<EOF > /opt/netcombiner/config.ini
[Host]
Crypto = None
[Peer]
Method = TCP
LocalHost = %2$s
LocalPort = 1234
EOF
cloud-init status --wait || cloud-init status --long

View File

@ -4,4 +4,102 @@ set -e
wget -q https://f001.backblazeb2.com/file/dissertation/binaries/debian/%1$s_linux_amd64 -O mpbl3p
chmod +x mpbl3p
mkdir -p /opt/netcombiner
mv mpbl3p /opt/netcombiner/mpbl3p
cat <<EOF > /etc/systemd/system/netcombiner.service
[Unit]
Description=NetCombiner
After=network-online.target
[Service]
ExecStartPre=/opt/netcombiner/exec-start-pre.sh
ExecStart=/opt/netcombiner/mpbl3p
ExecStartPost=/opt/netcombiner/exec-start-post.sh
User=root
Group=root
WorkingDirectory=/opt/netcombiner
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF > /opt/netcombiner/exec-start-pre.sh
#!/bin/bash
set -e
## Set up variables
REMOTE_PORTAL_ADDRESS=188.166.158.211
## IPv4 Forwarding
sysctl -w net.ipv4.ip_forward=1
sysctl -w net.ipv4.conf.eth0.proxy_arp=1
## Transfer the local routing table to a much lower priority
(ip rule show | grep '20:') > /dev/null || ip rule add from all table local priority 20
ip rule del 0 2> /dev/null || true
## Ports to route locally
### NetCombiner
ip rule del 1 2> /dev/null || true
ip rule add to "$REMOTE_PORTAL_ADDRESS" dport 4724 table local priority 1
ip rule del 1 2> /dev/null || true
ip rule add to "$REMOTE_PORTAL_ADDRESS" dport 4725 table local priority 2
### SSH
ip rule del 2 2> /dev/null || true
ip rule add to "$REMOTE_PORTAL_ADDRESS" dport 22 table local priority 3
echo "ExecStartPre complete"
EOF
chmod +x /opt/netcombiner/exec-start-pre.sh
cat <<EOF > /opt/netcombiner/exec-start-post.sh
#!/bin/bash
set -e
## Set up variables
REMOTE_PORTAL_ADDRESS=10.20.0.50
GATEWAY_INTERFACE=eth0
## Tunnel Address and Enable
ip addr add 172.19.152.3/31 dev nc0
ip link set up nc0
## Route Outbound Packets Correctly
ip route flush table 20
ip route add table 20 default via 172.19.152.2 dev nc0
ip rule del priority 20 2> /dev/null || true
ip rule add from $REMOTE_PORTAL_ADDRESS iif $GATEWAY_INTERFACE table 20 priority 20
## Route Inbound Packets Correctly
ip route flush table 21
ip route add table 21 to $REMOTE_PORTAL_ADDRESS dev $GATEWAY_INTERFACE
ip rule del priority 21 2> /dev/null || true
ip rule add to $REMOTE_PORTAL_ADDRESS iif nc0 table 21 priority 21
echo "ExecStartPost complete"
EOF
chmod +x /opt/netcombiner/exec-start-post.sh
cat <<EOF > /opt/netcombiner/config.ini
[Host]
Crypto = None
[Peer]
Method = TCP
LocalHost = %2$s
LocalPort = 1234
EOF
cloud-init status --wait || cloud-init status --long

View File

@ -1,46 +1,53 @@
package uk.ac.cam.jsh77.dissertationevaluation;
import io.github.cdimascio.dotenv.Dotenv;
import java.io.IOException;
import java.net.InetAddress;
import uk.co.hillion.jake.virtualtests.providers.Environment;
import uk.co.hillion.jake.virtualtests.providers.ImpossibleBlueprintException;
import uk.co.hillion.jake.virtualtests.providers.Provider;
import uk.co.hillion.jake.virtualtests.providers.Proxmox;
import uk.co.hillion.jake.virtualtests.structure.Distribution;
import java.io.IOException;
import java.net.InetAddress;
public class DissertationEvaluation {
public static String targetBranch;
public static String targetBranch;
public static void main(String[] args) throws IOException {
Dotenv dotenv = Dotenv.load();
public static void main(String[] args) throws InterruptedException, IOException {
Dotenv dotenv = Dotenv.load();
targetBranch = dotenv.get("TARGET_BRANCH", "develop");
targetBranch = dotenv.get("TARGET_BRANCH", "develop");
Provider p =
new Proxmox(
new Proxmox.ProxmoxAuth(
dotenv.get("PROXMOX_HOST"),
dotenv.get("PROXMOX_NODE"),
dotenv.get("PROXMOX_USER"),
dotenv.get("PROXMOX_TOKEN_NAME"),
dotenv.get("PROXMOX_TOKEN_VALUE")
), new Proxmox.ProxmoxConfig()
.registerTemplate(Distribution.Debian10, 9000)
.setManagementBridge(dotenv.get("MANAGEMENT_BRIDGE"))
.setInitialManagementIp(InetAddress.getByName(dotenv.get("MANAGEMENT_INITIAL_IP")))
.setManagementNetmask(24)
.setInitialVmId(21002)
.setInternetBridge(dotenv.get("INTERNET_BRIDGE")),
false);
try (Environment e = p.build(new StandardTest(4))) {
System.out.println("completed build");
} catch (ImpossibleBlueprintException e) {
e.printStackTrace();
} catch (IOException e) {
throw e;
}
InetAddress managementInitialIp;
try {
managementInitialIp = InetAddress.getByName(dotenv.get("MANAGEMENT_INITIAL_IP"));
} catch (IOException e) {
System.err.printf("error resolving management ip: %s%n", dotenv.get("MANAGEMENT_INITIAL_IP"));
System.exit(1);
return;
}
Provider p =
new Proxmox(
new Proxmox.ProxmoxAuth(
dotenv.get("PROXMOX_HOST"),
dotenv.get("PROXMOX_NODE"),
dotenv.get("PROXMOX_USER"),
dotenv.get("PROXMOX_TOKEN_NAME"),
dotenv.get("PROXMOX_TOKEN_VALUE")),
new Proxmox.ProxmoxConfig()
.registerTemplate(Distribution.Debian10, 9000)
.setManagementBridge(dotenv.get("MANAGEMENT_BRIDGE"))
.setInitialManagementIp(managementInitialIp)
.setManagementNetmask(24)
.setInitialVmId(21002)
.setInternetBridge(dotenv.get("INTERNET_BRIDGE")),
false);
try (Environment e = p.build(new StandardTest(4))) {
System.out.println("completed build");
Thread.sleep(15000);
} catch (ImpossibleBlueprintException e) {
e.printStackTrace();
}
}
}

View File

@ -1,5 +1,8 @@
package uk.ac.cam.jsh77.dissertationevaluation;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import uk.co.hillion.jake.virtualtests.providers.Environment;
import uk.co.hillion.jake.virtualtests.providers.Node;
import uk.co.hillion.jake.virtualtests.structure.Blueprint;
@ -7,10 +10,6 @@ import uk.co.hillion.jake.virtualtests.structure.BridgeRequest;
import uk.co.hillion.jake.virtualtests.structure.Distribution;
import uk.co.hillion.jake.virtualtests.structure.Template;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public class StandardTest implements Blueprint {
public final int interfaces;
@ -29,7 +28,7 @@ public class StandardTest implements Blueprint {
@Override
public List<BridgeRequest> getBridges() {
return List.of();
return List.of(new BridgeRequest(), new BridgeRequest());
}
public static class SpeedTestTemplate extends Template {