Make VXLAN configurable

This commit is contained in:
Nadja Reitzenstein
2022-11-02 22:52:16 +01:00
parent 017030dc3a
commit 488e458180
3 changed files with 16 additions and 14 deletions

View File

@@ -1,7 +1,6 @@
package li.cil.oc2.common.block;
import li.cil.oc2.common.blockentity.BlockEntities;
import li.cil.oc2.common.blockentity.NetworkHubBlockEntity;
import li.cil.oc2.common.blockentity.TickableBlockEntity;
import li.cil.oc2.common.blockentity.VxlanBlockEntity;
import net.minecraft.core.BlockPos;

View File

@@ -69,9 +69,7 @@ public final class VxlanBlockEntity extends ModBlockEntity implements NetworkInt
}
if (adjacentBlockInterfaces[0] != null) {
packetQueue.forEach(packet -> {
writeEthernetFrame(adjacentBlockInterfaces[0], packet, 255);
});
packetQueue.forEach(packet -> writeEthernetFrame(adjacentBlockInterfaces[0], packet, 255));
packetQueue.clear();
} else {
System.out.printf("VXLAN block is unregistered upstream: VTI=%d\n", vti);
@@ -105,7 +103,6 @@ public final class VxlanBlockEntity extends ModBlockEntity implements NetworkInt
@Override
public void loadServer() {
System.out.println("Tunnel VTI: " + vti);
adjacentBlockInterfaces[0] = TunnelManager.instance().registerVti(vti, this.packetQueue);
}

View File

@@ -2,6 +2,9 @@ package li.cil.oc2.common.vxlan;
import li.cil.oc2.api.capabilities.NetworkInterface;
import li.cil.oc2.common.Config;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.net.*;
@@ -9,6 +12,7 @@ import java.util.HashMap;
import java.util.concurrent.BlockingQueue;
public class TunnelManager {
private static final Logger LOGGER = LogManager.getLogger();
private final HashMap<Integer, TunnelInterface> tunnels = new HashMap<>();
private DatagramSocket socket;
@@ -26,14 +30,16 @@ public class TunnelManager {
}
public static void initialize() {
LOGGER.info("Initializing outernet tunnel manager");
try {
INSTANCE = new TunnelManager(
InetAddress.getByName("2001:16b8:4908:5700:d22e:ecd:e75b:f5a8"), (short) 4789,
InetAddress.getByName("2001:470:7398::a"), (short) 4789
InetAddress.getByName(Config.bindHost), (short) Config.bindPort,
InetAddress.getByName(Config.remoteHost), (short) Config.remotePort
);
} catch (SocketException | UnknownHostException e) {
System.out.println("Failed to bind host: " + e.getMessage());
e.printStackTrace();
LOGGER.error("Failed to bind to configured address: " + e.getMessage());
LOGGER.error(e);
}
if (Config.enable) {
@@ -41,7 +47,7 @@ public class TunnelManager {
try {
INSTANCE.listen();
} catch (IOException e) {
e.printStackTrace();
LOGGER.error(e);
}
});
bgThread.setName("VXLAN Background Thread");
@@ -50,14 +56,14 @@ public class TunnelManager {
}
public void listen() throws IOException {
System.out.printf("Binding %s:%s\n", bindHost, bindPort);
LOGGER.printf(Level.INFO, "Binding %s:%s\n", bindHost, bindPort);
if (Config.enable) {
socket = new DatagramSocket(bindPort, bindHost);
} else {
socket = null;
}
System.out.printf("Bind successful: connected=%s bound=%s\n", socket.isConnected(), socket.isBound());
LOGGER.printf(Level.INFO, "Bind successful: connected=%s bound=%s\n", socket.isConnected(), socket.isBound());
byte[] buffer = new byte[65535];
while (true) {
@@ -88,7 +94,7 @@ public class TunnelManager {
try {
iface.packetQueue.add(inner);
} catch (IllegalStateException ignored) {
System.err.println("Queue full");
LOGGER.error("Queue full");
}
}
}
@@ -118,7 +124,7 @@ public class TunnelManager {
e.printStackTrace();
}
} else {
System.out.printf("No socket in TunnelManager\n");
LOGGER.error("No socket in TunnelManager\n");
}
}