From 488e4581809d6f49d0e60df41a3bc6ccb7136e93 Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Wed, 2 Nov 2022 22:52:16 +0100 Subject: [PATCH] Make VXLAN configurable --- .../li/cil/oc2/common/block/VxlanBlock.java | 1 - .../common/blockentity/VxlanBlockEntity.java | 5 +--- .../cil/oc2/common/vxlan/TunnelManager.java | 24 ++++++++++++------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/li/cil/oc2/common/block/VxlanBlock.java b/src/main/java/li/cil/oc2/common/block/VxlanBlock.java index 79f0cea6..57c4b364 100644 --- a/src/main/java/li/cil/oc2/common/block/VxlanBlock.java +++ b/src/main/java/li/cil/oc2/common/block/VxlanBlock.java @@ -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; diff --git a/src/main/java/li/cil/oc2/common/blockentity/VxlanBlockEntity.java b/src/main/java/li/cil/oc2/common/blockentity/VxlanBlockEntity.java index 9ce8f71a..ac2323ff 100644 --- a/src/main/java/li/cil/oc2/common/blockentity/VxlanBlockEntity.java +++ b/src/main/java/li/cil/oc2/common/blockentity/VxlanBlockEntity.java @@ -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); } diff --git a/src/main/java/li/cil/oc2/common/vxlan/TunnelManager.java b/src/main/java/li/cil/oc2/common/vxlan/TunnelManager.java index aa7170eb..db9c928a 100644 --- a/src/main/java/li/cil/oc2/common/vxlan/TunnelManager.java +++ b/src/main/java/li/cil/oc2/common/vxlan/TunnelManager.java @@ -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 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"); } }