forked from KNEMC/KLALB
隧道链接改成标准URI格式
This commit is contained in:
@@ -116,9 +116,7 @@ public class DatagramKLALBPacketLink implements KLALBPacketLink {
|
||||
}*/
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
@@ -128,15 +126,14 @@ import java.net.SocketException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.kne.cloud.network.DatagramServerSocket;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
import org.kne.cloud.network.SpeedLimiter;
|
||||
|
||||
public class DatagramKLALBPacketLink extends AbstractKLALBPacketLink implements KLALBPacketLink {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new MultipurposeSocketAddress("UDP",(InetSocketAddress)ds.getLocalSocketAddress())+"←"+new MultipurposeSocketAddress("UDP",(InetSocketAddress)ds.getRemoteSocketAddress());
|
||||
return new MultiProtocolSocketAddress("UDP",(InetSocketAddress)ds.getLocalSocketAddress())+"←"+new MultiProtocolSocketAddress("UDP",(InetSocketAddress)ds.getRemoteSocketAddress());
|
||||
}
|
||||
|
||||
private DatagramSocket ds;
|
||||
|
||||
@@ -1,39 +1,31 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.annotation.processing.Filer;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.JavaFileManager.Location;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
public class KLALBConfig extends ArrayList<KLALBConfigItem>{
|
||||
|
||||
public KLALBConfig(){
|
||||
}
|
||||
public static KLALBConfig getDefault(){
|
||||
KLALBConfig config=new KLALBConfig();
|
||||
config.add(new KLALBControllerConfigItem());
|
||||
return config;
|
||||
}
|
||||
public static void main(String[] args) throws UnknownHostException, JsonSyntaxException, JsonIOException, FileNotFoundException {
|
||||
GsonBuilder gb=new GsonBuilder().setPrettyPrinting();
|
||||
MultipurposeSocketAddress.registerToGsonBuilder(gb);
|
||||
MultiProtocolSocketAddress.registerToGsonBuilder(gb);
|
||||
KLALBConfigItem.registerToGsonBuilder(gb);
|
||||
Gson gson=gb.create();
|
||||
KLALBConfig kc=gson.fromJson(new FileReader(new File("klalb-config.json")),KLALBConfig.class);
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import org.kne.cloud.clock.HighAccuracyClock;
|
||||
import org.kne.cloud.network.IPMulticastDiscovery;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.PortPair;
|
||||
import org.kne.cloud.network.SocketType;
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
@@ -67,7 +67,7 @@ public class KLALBController {
|
||||
public HighAccuracyClock getClock() {
|
||||
return clock;
|
||||
}
|
||||
private final long TIME_WINDOW=5000000000L;
|
||||
private final long TIME_WINDOW=2000000000L;
|
||||
private SpeedAndTrafficMonitorDataImpl linkMonitor = new SpeedAndTrafficMonitorDataImpl(
|
||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "up", 100,TIME_WINDOW ),
|
||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "down", 100, TIME_WINDOW));
|
||||
@@ -76,8 +76,13 @@ public class KLALBController {
|
||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "up", 100, TIME_WINDOW),
|
||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "down", 100, TIME_WINDOW));
|
||||
|
||||
private List<MultipurposeSocketAddress> selflineTable = new ArrayList<>();
|
||||
private List<MultiProtocolSocketAddress> selflineTable = new ArrayList<>();
|
||||
|
||||
private List<MultiProtocolSocketAddress> listensSocketAddress = new CopyOnWriteArrayList<>();
|
||||
|
||||
public List<MultiProtocolSocketAddress> getListenSocketAddress() {
|
||||
return listensSocketAddress;
|
||||
}
|
||||
private static final boolean debug=false;
|
||||
private static final boolean showpacket = false;
|
||||
|
||||
@@ -86,10 +91,12 @@ public class KLALBController {
|
||||
|
||||
private static List<IPMulticastDiscovery> ipmd = new ArrayList<>();
|
||||
|
||||
private List<NetworkInterface> networkInterfaceExcept = new ArrayList<>();
|
||||
|
||||
private NetworkInterfaceManager networkInterfaceManager=new NetworkInterfaceManager();
|
||||
public NetworkInterfaceManager getNetworkInterfaceManager() {
|
||||
return networkInterfaceManager;
|
||||
}
|
||||
public List<NetworkInterface> getNetworkInterfaceExcept() {
|
||||
return networkInterfaceExcept;
|
||||
return networkInterfaceManager.getNetworkInterfaceExcept();
|
||||
}
|
||||
|
||||
private List<InetAddress> dnsAddresses = new ArrayList<>();
|
||||
@@ -111,50 +118,23 @@ public class KLALBController {
|
||||
|
||||
private Timer twk = new Timer("网卡检测扫描计时器", true);
|
||||
|
||||
private List<InetAddress> getAllNetworkInterfaceAddress() throws SocketException {
|
||||
List<InetAddress> addresses = new ArrayList<InetAddress>();
|
||||
Enumeration<NetworkInterface> eu = NetworkInterface.getNetworkInterfaces();
|
||||
while (eu.hasMoreElements()) {
|
||||
NetworkInterface networkInterface = (NetworkInterface) eu.nextElement();
|
||||
|
||||
if (networkInterface.getDisplayName()
|
||||
.startsWith(CONST.KLALB_DECENTRALIZED_S_RV6_NETWORK)) {
|
||||
continue;
|
||||
}
|
||||
if (networkInterfaceExcept.contains(networkInterface)) {
|
||||
continue;
|
||||
}
|
||||
if (networkInterface.isUp()) {
|
||||
// System.out.println(networkInterface+" "+networkInterface.isUp());
|
||||
Enumeration<InetAddress> ei = networkInterface.getInetAddresses();
|
||||
while (ei.hasMoreElements()) {
|
||||
InetAddress inetAddress = (InetAddress) ei.nextElement();
|
||||
if (checkIsSelfLocator(inetAddress)) {
|
||||
continue;
|
||||
}
|
||||
addresses.add(inetAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
return addresses;
|
||||
}
|
||||
|
||||
private TimerTask tsk1 = new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<InetAddress> localaddress = getAllNetworkInterfaceAddress();
|
||||
List<InetAddress> localaddress = networkInterfaceManager.getAllNetworkInterfaceAddress();
|
||||
|
||||
for (InetAddress inetAddress : localaddress) {
|
||||
if (!inetAddress.isLoopbackAddress())
|
||||
for (Iterator<MultipurposeSocketAddress> iterator = listens.iterator(); iterator.hasNext();) {
|
||||
MultipurposeSocketAddress tcpl = (MultipurposeSocketAddress) iterator.next();
|
||||
for (Iterator<MultiProtocolSocketAddress> iterator = listensSocketAddress.iterator(); iterator.hasNext();) {
|
||||
MultiProtocolSocketAddress tcpl = (MultiProtocolSocketAddress) iterator.next();
|
||||
|
||||
try {
|
||||
if (tcpl.getInetAddress().isAnyLocalAddress()
|
||||
|| tcpl.getInetAddress().equals(inetAddress)) {
|
||||
MultipurposeSocketAddress bind = new MultipurposeSocketAddress(tcpl.getType(),
|
||||
MultiProtocolSocketAddress bind = new MultiProtocolSocketAddress(tcpl.getProtocol(),
|
||||
inetAddress.getHostAddress(), tcpl.getPort());
|
||||
// System.out.println(bind);
|
||||
synchronized (selflineTable) {
|
||||
@@ -175,46 +155,45 @@ public class KLALBController {
|
||||
try {
|
||||
|
||||
|
||||
Set<MultipurposeSocketAddress> st = new HashSet<>();
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
IPv6NetworkLink link = iterator.next();
|
||||
if (link instanceof KLALBRemoteLink) {
|
||||
KLALBRemoteLink multipurposeSocketAddress = (KLALBRemoteLink) link;
|
||||
if (multipurposeSocketAddress.getSocketAddress() != null)
|
||||
st.add(multipurposeSocketAddress.getSocketAddress());
|
||||
}
|
||||
}
|
||||
Set<MultiProtocolSocketAddress> st = new HashSet<>();
|
||||
for (IPv6NetworkLink link : srv6Router.getLinkTabel()) {
|
||||
if (link instanceof KLALBRemoteLink) {
|
||||
KLALBRemoteLink multipurposeSocketAddress = (KLALBRemoteLink) link;
|
||||
if (multipurposeSocketAddress.getSocketAddress() != null)
|
||||
st.add(multipurposeSocketAddress.getSocketAddress());
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<MultipurposeSocketAddress> iterator = st.iterator(); iterator.hasNext();) {
|
||||
MultipurposeSocketAddress target = (MultipurposeSocketAddress) iterator.next();
|
||||
addRemoteLines(target);
|
||||
}
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
IPv6NetworkLink link = iterator.next();
|
||||
if (link instanceof KLALBRemoteLink) {
|
||||
KLALBRemoteLink reml = (KLALBRemoteLink) link;
|
||||
if (reml.getSocketAddress() != null) {
|
||||
if (reml.getBindAddress() != null || reml.getRemoteVaddr() != null)
|
||||
try {
|
||||
MultipurposeSocketAddress iadr=reml.getBindAddress();
|
||||
if(iadr!=null) {
|
||||
if (!localaddress.contains(iadr.getInetAddress())) {
|
||||
reml.close();
|
||||
srv6Router.getLinkTabel().remove(reml);
|
||||
}
|
||||
}else {
|
||||
for (MultiProtocolSocketAddress target : st) {
|
||||
addRemoteLines(target);
|
||||
}
|
||||
|
||||
reml.close();
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
reml.close();
|
||||
srv6Router.getLinkTabel().remove(reml);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
for (IPv6NetworkLink link : srv6Router.getLinkTabel()) {
|
||||
if (link instanceof KLALBRemoteLink) {
|
||||
KLALBRemoteLink reml = (KLALBRemoteLink) link;
|
||||
if (reml.getSocketAddress() != null) {
|
||||
if (reml.getBindAddress() != null || reml.getRemoteVaddr() != null)
|
||||
try {
|
||||
MultipurposeSocketAddress iadr = reml.getBindAddress();
|
||||
if (iadr != null) {
|
||||
if (!localaddress.contains(iadr.getInetAddress())) {
|
||||
reml.close();
|
||||
srv6Router.getLinkTabel().remove(reml);
|
||||
}
|
||||
} else {
|
||||
|
||||
reml.close();
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
reml.close();
|
||||
srv6Router.getLinkTabel().remove(reml);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
} finally {
|
||||
lineslock.writeLock().unlock();
|
||||
}
|
||||
@@ -228,9 +207,9 @@ public class KLALBController {
|
||||
}
|
||||
|
||||
private void updateBroadcastNetworkInterface() throws SocketException {
|
||||
for (Iterator<IPMulticastDiscovery> iterator = ipmd.iterator(); iterator.hasNext();) {
|
||||
for (Iterator<IPMulticastDiscovery> iterator = ipmd.iterator(); iterator.hasNext(); ) {
|
||||
IPMulticastDiscovery ipMulticastDiscovery = (IPMulticastDiscovery) iterator.next();
|
||||
if (ipMulticastDiscovery.isClosed() || (!ipMulticastDiscovery.getNinterface().isUp())
|
||||
if (ipMulticastDiscovery.isClosed() || (!ipMulticastDiscovery.getInterface().isUp())
|
||||
|| (configItem != null && configItem.isDenyLineTableBroadcast())) {
|
||||
iterator.remove();
|
||||
try {
|
||||
@@ -238,99 +217,86 @@ public class KLALBController {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(debug)
|
||||
System.out.println("关闭网卡地址广播:" + ipMulticastDiscovery.getNinterface());
|
||||
if (debug)
|
||||
System.out.println("关闭网卡地址广播:" + ipMulticastDiscovery.getInterface());
|
||||
}
|
||||
}
|
||||
|
||||
if (configItem != null && configItem.isDenyLineTableBroadcast()) {
|
||||
|
||||
} else {
|
||||
Enumeration<NetworkInterface> eu2 = NetworkInterface.getNetworkInterfaces();
|
||||
while (eu2.hasMoreElements()) {
|
||||
NetworkInterface networkInterface = (NetworkInterface) eu2.nextElement();
|
||||
if (networkInterface.getDisplayName()
|
||||
.startsWith(CONST.KLALB_DECENTRALIZED_S_RV6_NETWORK)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (networkInterfaceExcept.contains(networkInterface)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (networkInterface.isUp()) {
|
||||
|
||||
Enumeration<InetAddress> ei = networkInterface.getInetAddresses();
|
||||
loop: while (ei.hasMoreElements()) {
|
||||
InetAddress bidr = (InetAddress) ei.nextElement();
|
||||
if (checkIsSelfLocator(bidr)) {
|
||||
continue;
|
||||
}
|
||||
for (Iterator<IPMulticastDiscovery> iterator = ipmd.iterator(); iterator.hasNext();) {
|
||||
IPMulticastDiscovery ipMulticastDiscovery = (IPMulticastDiscovery) iterator.next();
|
||||
if (networkInterface.equals(ipMulticastDiscovery.getNinterface())
|
||||
&& bidr.equals(ipMulticastDiscovery.getBind().getAddress())) {
|
||||
continue loop;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// InetAddress bidr=InetAddress.getByName("::0");
|
||||
|
||||
if (bidr instanceof Inet6Address) {
|
||||
IPMulticastDiscovery ipd = new IPMulticastDiscovery(
|
||||
new InetSocketAddress(bidr, DISCOVERY_PORT),
|
||||
new InetSocketAddress(InetAddress.getByName("ff02::2486"),
|
||||
DISCOVERY_PORT),
|
||||
networkInterface, selflineTable, nodeuuid,10000L);
|
||||
ipd.setCon((mpa) -> {
|
||||
// System.out.println("添加本地IPv6链路:"+mpa);
|
||||
try {
|
||||
if (!checkIsSelf(mpa))
|
||||
addRemoteLines(mpa);
|
||||
} catch (UnknownHostException e) {
|
||||
}
|
||||
});
|
||||
ipd.start();
|
||||
ipmd.add(ipd);
|
||||
} else if (bidr instanceof Inet4Address) {
|
||||
// bidr=InetAddress.getByName("0.0.0.0");
|
||||
IPMulticastDiscovery ipd2 = new IPMulticastDiscovery(
|
||||
new InetSocketAddress(bidr, DISCOVERY_PORT),
|
||||
new InetSocketAddress(InetAddress.getByName("224.0.0.86"),
|
||||
DISCOVERY_PORT),
|
||||
networkInterface, selflineTable,nodeuuid, 10000L);
|
||||
ipd2.setCon((mpa) -> {
|
||||
// System.out.println("添加本地IPv4链路:"+mpa);
|
||||
try {
|
||||
if (!checkIsSelf(mpa))
|
||||
addRemoteLines(mpa);
|
||||
} catch (UnknownHostException e) {
|
||||
}
|
||||
});
|
||||
ipd2.start();
|
||||
ipmd.add(ipd2);
|
||||
}
|
||||
if(debug)
|
||||
System.out.println("开启网卡地址广播:" + networkInterface);
|
||||
} catch (BindException e) {
|
||||
// e.printStackTrace();
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
List<NetworkInterface> interfaceList = networkInterfaceManager.getAllAvaliableNetworkInterface();
|
||||
for(NetworkInterface networkInterface:interfaceList){
|
||||
List<InetAddress> addressList= networkInterfaceManager.getNetworkInterfaceAddress(networkInterface);
|
||||
loop:for (InetAddress bidr:addressList) {
|
||||
|
||||
for (IPMulticastDiscovery ipMulticastDiscovery : ipmd) {
|
||||
if (networkInterface.equals(ipMulticastDiscovery.getInterface())
|
||||
&& bidr.equals(ipMulticastDiscovery.getBind().getAddress())) {
|
||||
continue loop;
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// InetAddress bidr=InetAddress.getByName("::0");
|
||||
|
||||
if (bidr instanceof Inet6Address) {
|
||||
IPMulticastDiscovery ipd = new IPMulticastDiscovery(new InetSocketAddress(bidr,DISCOVERY_PORT),
|
||||
new InetSocketAddress(InetAddress.getByName("ff02::2486"),
|
||||
DISCOVERY_PORT),
|
||||
networkInterface, listensSocketAddress, nodeuuid, 10000L);
|
||||
ipd.setCon((mpa) -> {
|
||||
if (debug)
|
||||
System.out.println("添加本地IPv6链路:" + mpa);
|
||||
try {
|
||||
if (!checkIsSelf(mpa))
|
||||
addRemoteLines(mpa);
|
||||
} catch (UnknownHostException e) {
|
||||
}
|
||||
});
|
||||
ipd.start();
|
||||
ipmd.add(ipd);
|
||||
} else if (bidr instanceof Inet4Address) {
|
||||
// bidr=InetAddress.getByName("0.0.0.0");
|
||||
IPMulticastDiscovery ipd2 = new IPMulticastDiscovery(new InetSocketAddress(bidr,DISCOVERY_PORT),
|
||||
new InetSocketAddress(InetAddress.getByName("224.0.0.86"),
|
||||
DISCOVERY_PORT),
|
||||
networkInterface, listensSocketAddress, nodeuuid, 10000L);
|
||||
ipd2.setCon((mpa) -> {
|
||||
if (debug)
|
||||
System.out.println("添加本地IPv4链路:" + mpa);
|
||||
try {
|
||||
if (!checkIsSelf(mpa))
|
||||
addRemoteLines(mpa);
|
||||
} catch (UnknownHostException e) {
|
||||
}
|
||||
});
|
||||
ipd2.start();
|
||||
ipmd.add(ipd2);
|
||||
}
|
||||
if (debug)
|
||||
System.out.println("开启网卡地址广播:" + networkInterface);
|
||||
} catch (BindException e) {
|
||||
// e.printStackTrace();
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private boolean checkIsSelf(MultipurposeSocketAddress inetAddress) throws UnknownHostException {
|
||||
private boolean checkIsSelf(MultiProtocolSocketAddress inetAddress) throws UnknownHostException {
|
||||
|
||||
return inetAddress.getInetAddress().isAnyLocalAddress() || inetAddress.getInetAddress().isLoopbackAddress()
|
||||
|| selflineTable.contains(inetAddress);
|
||||
@@ -345,16 +311,16 @@ public class KLALBController {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
List<MultipurposeSocketAddress> nt = ntptable;
|
||||
List<MultiProtocolSocketAddress> nt = ntptable;
|
||||
// System.out.println("srv6 ip"+nb);
|
||||
if (nvc2 != null) {
|
||||
Set<NTPPeer> sp = nvc2.getPeers();
|
||||
for (MultipurposeSocketAddress server : nt) {
|
||||
for (MultiProtocolSocketAddress server : nt) {
|
||||
sp.add(new NTPPeer(server, NTPv4Packet.NTP_CLIENT));
|
||||
|
||||
}
|
||||
sp.removeIf((p) -> {
|
||||
for (MultipurposeSocketAddress server : nt) {
|
||||
for (MultiProtocolSocketAddress server : nt) {
|
||||
if (server.equals(p.getAddress())) {
|
||||
return false;
|
||||
}
|
||||
@@ -365,33 +331,30 @@ public class KLALBController {
|
||||
}
|
||||
};
|
||||
|
||||
private TimerTask tsk3 = new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (srv6Router != null && routingProtocol != null) {
|
||||
Set<IPv6AddressGroup> nb = srv6Router.getLocators();
|
||||
for (Iterator<IPv6AddressGroup> iterator = nb.iterator(); iterator.hasNext();) {
|
||||
IPv6AddressGroup neighbor = (IPv6AddressGroup) iterator.next();
|
||||
try {
|
||||
InetSocketAddress iaddr = new InetSocketAddress(neighbor.getAddress().toInet6Address(),
|
||||
KLALBRoutingProtocol.DEFAULT_PORT);
|
||||
apiClient.requestOpenLines(iaddr, (v) -> {
|
||||
ThreadTool.makeVDaemonThreadIfSupport("线路添加任务", () -> {
|
||||
for (MultipurposeSocketAddress msa : v) {
|
||||
// System.out.print(msa);
|
||||
addRemoteLines(msa);
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public void tryConnectMore(){
|
||||
if (srv6Router != null && routingProtocol != null) {
|
||||
Set<IPv6AddressGroup> nb = srv6Router.getLocators();
|
||||
for (Iterator<IPv6AddressGroup> iterator = nb.iterator(); iterator.hasNext();) {
|
||||
IPv6AddressGroup neighbor = (IPv6AddressGroup) iterator.next();
|
||||
try {
|
||||
InetSocketAddress iaddr = new InetSocketAddress(neighbor.getAddress().toInet6Address(),
|
||||
KLALBRoutingProtocol.DEFAULT_PORT);
|
||||
apiClient.requestOpenLines(iaddr, (v) -> {
|
||||
ThreadTool.makeVDaemonThreadIfSupport("线路添加任务", () -> {
|
||||
for (MultiProtocolSocketAddress msa : v) {
|
||||
// System.out.print(msa);
|
||||
addRemoteLines(msa);
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public SpeedAndTrafficMonitorDataImpl getLinkMonitor() {
|
||||
return linkMonitor;
|
||||
@@ -403,6 +366,8 @@ public class KLALBController {
|
||||
|
||||
private SocketType streamSocketType = new KLALBStreamSocketType();
|
||||
|
||||
|
||||
|
||||
public class KLALBStreamSocketType extends SocketType {
|
||||
|
||||
public KLALBStreamSocketType() {
|
||||
@@ -436,7 +401,7 @@ public class KLALBController {
|
||||
}
|
||||
|
||||
|
||||
public List<MultipurposeSocketAddress> getSelflineTable() {
|
||||
public List<MultiProtocolSocketAddress> getSelflineTable() {
|
||||
return selflineTable;
|
||||
}
|
||||
|
||||
@@ -472,13 +437,13 @@ public class KLALBController {
|
||||
|
||||
private KLALBControllerConfigItem configItem;
|
||||
|
||||
public void addRemoteLines(List<MultipurposeSocketAddress> select) {
|
||||
for (MultipurposeSocketAddress target : select) {
|
||||
public void addRemoteLines(List<MultiProtocolSocketAddress> select) {
|
||||
for (MultiProtocolSocketAddress target : select) {
|
||||
addRemoteLines(target);
|
||||
}
|
||||
}
|
||||
|
||||
public List<KLALBRemoteLink> addRemoteLines(MultipurposeSocketAddress target) {
|
||||
public List<KLALBRemoteLink> addRemoteLines(MultiProtocolSocketAddress target) {
|
||||
lineslock.writeLock().lock();
|
||||
try {
|
||||
List<KLALBRemoteLink> added = new ArrayList<>();
|
||||
@@ -492,7 +457,7 @@ public class KLALBController {
|
||||
while (ei.hasMoreElements()) {
|
||||
InetAddress inetAddress = (InetAddress) ei.nextElement();
|
||||
try {
|
||||
MultipurposeSocketAddress bind = new MultipurposeSocketAddress(
|
||||
MultiProtocolSocketAddress bind = new MultiProtocolSocketAddress(
|
||||
inetAddress.getHostAddress(), 0);
|
||||
try {
|
||||
if (target.getInetAddress().isLoopbackAddress()
|
||||
@@ -553,7 +518,7 @@ public class KLALBController {
|
||||
}
|
||||
}
|
||||
|
||||
public List<KLALBRemoteLink> removeRemoteLines(MultipurposeSocketAddress mpsa) {
|
||||
public List<KLALBRemoteLink> removeRemoteLines(MultiProtocolSocketAddress mpsa) {
|
||||
|
||||
List<KLALBRemoteLink> rmved = new ArrayList<>();
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
@@ -569,7 +534,7 @@ public class KLALBController {
|
||||
return rmved;
|
||||
}
|
||||
|
||||
public Inet6Address getRemoteVaddrBySocketAddress(MultipurposeSocketAddress target) throws SocketTimeoutException {
|
||||
public Inet6Address getRemoteVaddrBySocketAddress(MultiProtocolSocketAddress target) throws SocketTimeoutException {
|
||||
KLALBRemoteLink kr = null;
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
IPv6NetworkLink link = iterator.next();
|
||||
@@ -593,7 +558,7 @@ public class KLALBController {
|
||||
return kr.getRemoteVaddr().getAddress().toInet6Address();
|
||||
}
|
||||
|
||||
private boolean checkContainsTargetAndBind(MultipurposeSocketAddress target, MultipurposeSocketAddress bind) {
|
||||
private boolean checkContainsTargetAndBind(MultiProtocolSocketAddress target, MultiProtocolSocketAddress bind) {
|
||||
boolean b = false;
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
IPv6NetworkLink link = iterator.next();
|
||||
@@ -609,7 +574,7 @@ public class KLALBController {
|
||||
return b;
|
||||
}
|
||||
|
||||
private boolean checkContainsTarget(MultipurposeSocketAddress target) {
|
||||
private boolean checkContainsTarget(MultiProtocolSocketAddress target) {
|
||||
boolean b = false;
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
IPv6NetworkLink link = iterator.next();
|
||||
@@ -639,8 +604,8 @@ public class KLALBController {
|
||||
|
||||
private String generateSelfLineTable() {
|
||||
StringBuilder sbd = new StringBuilder();
|
||||
for (Iterator<MultipurposeSocketAddress> iterator = selflineTable.iterator(); iterator.hasNext();) {
|
||||
MultipurposeSocketAddress klalbRemoteLine = (MultipurposeSocketAddress) iterator.next();
|
||||
for (Iterator<MultiProtocolSocketAddress> iterator = selflineTable.iterator(); iterator.hasNext();) {
|
||||
MultiProtocolSocketAddress klalbRemoteLine = (MultiProtocolSocketAddress) iterator.next();
|
||||
sbd.append(klalbRemoteLine.toString());
|
||||
sbd.append('\n');
|
||||
}
|
||||
@@ -668,7 +633,11 @@ public class KLALBController {
|
||||
}
|
||||
|
||||
private void loadSRv6ProtocolStack(IPv6AddressGroup selfx, boolean enableVirtualAdapter) {
|
||||
networkInterfaceManager.getInetAddressesExcept().add(selfx.getAddress().toInet6Address());
|
||||
srv6Router = new SRv6Router(selfx, clock);
|
||||
if(configItem!=null) {
|
||||
srv6Router.setPerformanceStrategy(PerformanceStrategy.fromDescription(configItem.getPerformanceStrategy()));
|
||||
}
|
||||
srv6Router.runKLALBRouteProtocol();
|
||||
routingProtocol = srv6Router.getKlalbRouteProtol();
|
||||
routingProtocol.addReceiver((addr, packet) -> {
|
||||
@@ -715,7 +684,7 @@ public class KLALBController {
|
||||
// System.out.println(context);
|
||||
try {
|
||||
NTPv4Protocol nvc = new NTPv4Protocol(context,
|
||||
new MultipurposeSocketAddress("{" + iproxyname + "_Datagram}0.0.0.0:123"));
|
||||
new MultiProtocolSocketAddress(iproxyname + "_Datagram","0.0.0.0",123));
|
||||
srv6Router.addSRv6RouterListener(new SRv6RouterListener() {
|
||||
|
||||
@Override
|
||||
@@ -726,7 +695,7 @@ public class KLALBController {
|
||||
for (Neighbor neighbor : nb) {
|
||||
if (neighbor.getLocator() != null)
|
||||
sp.add(new NTPPeer(
|
||||
new MultipurposeSocketAddress(iproxyname + "_Datagram",
|
||||
new MultiProtocolSocketAddress(iproxyname + "_Datagram",
|
||||
neighbor.getLocator().getAddress().toString(), 123),
|
||||
NTPv4Packet.NTP_SYMMETRIC_ACTIVE));
|
||||
|
||||
@@ -747,7 +716,7 @@ public class KLALBController {
|
||||
});
|
||||
}
|
||||
});
|
||||
nvc2 = new NTPv4Protocol(context, new MultipurposeSocketAddress("{UDP}0.0.0.0:0"));// 106.55.184.199
|
||||
nvc2 = new NTPv4Protocol(context, new MultiProtocolSocketAddress("udp","0.0.0.0",0));
|
||||
|
||||
System.out.println(" Loaded: NTP Module");
|
||||
} catch (UnknownHostException e) {
|
||||
@@ -764,7 +733,6 @@ public class KLALBController {
|
||||
this.apiClient = new KLALBRoutingProtocolAPIClient(routingProtocol);
|
||||
twk.schedule(tsk1, 5000, 5000);
|
||||
twk.schedule(tsk2, 5000, 5000);
|
||||
twk.schedule(tsk3, 5000, 5000);
|
||||
}
|
||||
|
||||
public KLALBController() {
|
||||
@@ -830,18 +798,18 @@ public class KLALBController {
|
||||
getIpv6Router().setASN(vasn);
|
||||
}
|
||||
|
||||
List<MultipurposeSocketAddress> linele = configItem.getLineTable();
|
||||
List<MultiProtocolSocketAddress> linele = configItem.getLineTable();
|
||||
if (linele != null) {
|
||||
getSelflineTable().addAll(linele);
|
||||
}
|
||||
List<MultipurposeSocketAddress> linetoc = configItem.getConnectLineTable();
|
||||
List<MultiProtocolSocketAddress> linetoc = configItem.getConnectLineTable();
|
||||
if (linetoc != null) {
|
||||
linetoc.forEach((aline) -> {
|
||||
addRemoteLines(aline);
|
||||
});
|
||||
}
|
||||
|
||||
List<MultipurposeSocketAddress> ntps = configItem.getNtpServerTable();
|
||||
List<MultiProtocolSocketAddress> ntps = configItem.getNtpServerTable();
|
||||
if (ntps != null) {
|
||||
getNTPTable().addAll(ntps);
|
||||
}
|
||||
@@ -1004,24 +972,19 @@ public class KLALBController {
|
||||
|
||||
|
||||
|
||||
private List<MultipurposeSocketAddress> listens = new CopyOnWriteArrayList<>();
|
||||
|
||||
|
||||
public void registerToProxyTypeAs(String proxyname) {
|
||||
MultipurposeSocketAddress.getSocketTypeRegister().put(proxyname + "_Stream", streamSocketType);
|
||||
MultipurposeSocketAddress.getSocketTypeRegister().put(proxyname + "_Datagram", datagramSocketType);
|
||||
MultiProtocolSocketAddress.getSocketTypeRegister().put(proxyname + "_Stream", streamSocketType);
|
||||
MultiProtocolSocketAddress.getSocketTypeRegister().put(proxyname + "_Datagram", datagramSocketType);
|
||||
// ProxyProfileEntry.getRegister().put(proxyname, this);
|
||||
}
|
||||
|
||||
public List<MultipurposeSocketAddress> getListenSocketAddress() {
|
||||
return listens;
|
||||
}
|
||||
|
||||
private List<MultipurposeSocketAddress> ntptable = new CopyOnWriteArrayList();
|
||||
private List<MultiProtocolSocketAddress> ntptable = new CopyOnWriteArrayList();
|
||||
|
||||
private KLALBRoutingProtocol routingProtocol;
|
||||
|
||||
public List<MultipurposeSocketAddress> getNTPTable() {
|
||||
public List<MultiProtocolSocketAddress> getNTPTable() {
|
||||
return ntptable;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,32 +3,42 @@ package org.kne.cloud.network.klalb;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
|
||||
public class KLALBControllerConfigItem extends KLALBConfigItem {
|
||||
private String language;
|
||||
private boolean nogui;
|
||||
private String VirtualAddress;
|
||||
private String VirtualAddress=KLALBUtils.randomKLALBIPv6Address().toString();
|
||||
private Long VirtualASN;
|
||||
private List<InetAddress> DNS;
|
||||
private MultipurposeSocketAddress TCPListen;
|
||||
private MultipurposeSocketAddress UDPListen;
|
||||
private MultiProtocolSocketAddress TCPListen=new MultiProtocolSocketAddress("0.0.0.0",4565);
|
||||
private MultiProtocolSocketAddress UDPListen=new MultiProtocolSocketAddress("udp","0.0.0.0",4565);
|
||||
private String VirtualSocketName;
|
||||
private List<MultipurposeSocketAddress>LineTable=new ArrayList<>();
|
||||
private List<MultipurposeSocketAddress>ConnectLineTable=new ArrayList<>();
|
||||
private List<MultipurposeSocketAddress>ntpServerTable=new ArrayList<>();
|
||||
private List<MultiProtocolSocketAddress>LineTable=new ArrayList<>();
|
||||
private List<MultiProtocolSocketAddress>ConnectLineTable=new ArrayList<>();
|
||||
private List<MultiProtocolSocketAddress>ntpServerTable=new ArrayList<>();
|
||||
private boolean denyLineTableQuery=false;
|
||||
private boolean denyLineTableBroadcast=false;
|
||||
private String congestionAlgorithm="BBR";
|
||||
private double burstLimit=1.20;
|
||||
private double burstLimit=1.50;
|
||||
private double delayUpperBound=1.20;
|
||||
private double delayLowerBound=1.15;
|
||||
private long nagleDelayTime=1000000L;
|
||||
private long linkNagleDelayTime=1000000L;
|
||||
private int linkConnectionsCount=1;
|
||||
private String TUNName=CONST.KLALB_S_RV6;
|
||||
|
||||
private String performanceStrategy="multifill";
|
||||
|
||||
public String getPerformanceStrategy() {
|
||||
return performanceStrategy;
|
||||
}
|
||||
|
||||
public void setPerformanceStrategy(String performanceStrategy) {
|
||||
this.performanceStrategy = performanceStrategy;
|
||||
}
|
||||
|
||||
public void setNetworkInterfaceExcepts(List<String> networkInterfaceExcepts) {
|
||||
NetworkInterfaceExcepts = networkInterfaceExcepts;
|
||||
}
|
||||
@@ -52,8 +62,8 @@ public class KLALBControllerConfigItem extends KLALBConfigItem {
|
||||
|
||||
|
||||
|
||||
public KLALBControllerConfigItem(String type) {
|
||||
super(type);
|
||||
public KLALBControllerConfigItem() {
|
||||
super("KLALBController");
|
||||
}
|
||||
|
||||
|
||||
@@ -124,62 +134,62 @@ public class KLALBControllerConfigItem extends KLALBConfigItem {
|
||||
|
||||
|
||||
|
||||
public MultipurposeSocketAddress getTCPListen() {
|
||||
public MultiProtocolSocketAddress getTCPListen() {
|
||||
return TCPListen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setTCPListen(MultipurposeSocketAddress tCPListen) {
|
||||
public void setTCPListen(MultiProtocolSocketAddress tCPListen) {
|
||||
TCPListen = tCPListen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public MultipurposeSocketAddress getUDPListen() {
|
||||
public MultiProtocolSocketAddress getUDPListen() {
|
||||
return UDPListen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setUDPListen(MultipurposeSocketAddress uDPListen) {
|
||||
public void setUDPListen(MultiProtocolSocketAddress uDPListen) {
|
||||
UDPListen = uDPListen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<MultipurposeSocketAddress> getLineTable() {
|
||||
public List<MultiProtocolSocketAddress> getLineTable() {
|
||||
return LineTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setLineTable(List<MultipurposeSocketAddress> lineTable) {
|
||||
public void setLineTable(List<MultiProtocolSocketAddress> lineTable) {
|
||||
LineTable = lineTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<MultipurposeSocketAddress> getConnectLineTable() {
|
||||
public List<MultiProtocolSocketAddress> getConnectLineTable() {
|
||||
return ConnectLineTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setConnectLineTable(List<MultipurposeSocketAddress> connectLineTable) {
|
||||
public void setConnectLineTable(List<MultiProtocolSocketAddress> connectLineTable) {
|
||||
ConnectLineTable = connectLineTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<MultipurposeSocketAddress> getNtpServerTable() {
|
||||
public List<MultiProtocolSocketAddress> getNtpServerTable() {
|
||||
return ntpServerTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setNtpServerTable(List<MultipurposeSocketAddress> ntpServerTable) {
|
||||
public void setNtpServerTable(List<MultiProtocolSocketAddress> ntpServerTable) {
|
||||
this.ntpServerTable = ntpServerTable;
|
||||
}
|
||||
|
||||
@@ -306,146 +316,43 @@ public class KLALBControllerConfigItem extends KLALBConfigItem {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KLALBControllerConfigItem [language=" + language + ", nogui=" + nogui + ", VirtualAddress="
|
||||
+ VirtualAddress + ", VirtualASN=" + VirtualASN + ", DNS=" + DNS + ", TCPListen=" + TCPListen
|
||||
+ ", UDPListen=" + UDPListen + ", VirtualSocketName=" + VirtualSocketName + ", LineTable=" + LineTable
|
||||
+ ", ConnectLineTable=" + ConnectLineTable + ", ntpServerTable=" + ntpServerTable
|
||||
+ ", denyLineTableQuery=" + denyLineTableQuery + ", denyLineTableBroadcast=" + denyLineTableBroadcast
|
||||
+ ", congestionAlgorithm=" + congestionAlgorithm + ", delayUpperBound=" + delayUpperBound
|
||||
+ ", delayLowerBound=" + delayLowerBound + ", nagleDelayTime=" + nagleDelayTime
|
||||
+ ", linkNagleDelayTime=" + linkNagleDelayTime + ", linkConnectionsCount=" + linkConnectionsCount
|
||||
+ ", TUNName=" + TUNName + ", NetworkInterfaceExcepts=" + NetworkInterfaceExcepts + "]";
|
||||
return "KLALBControllerConfigItem{" +
|
||||
"language='" + language + '\'' +
|
||||
", nogui=" + nogui +
|
||||
", VirtualAddress='" + VirtualAddress + '\'' +
|
||||
", VirtualASN=" + VirtualASN +
|
||||
", DNS=" + DNS +
|
||||
", TCPListen=" + TCPListen +
|
||||
", UDPListen=" + UDPListen +
|
||||
", VirtualSocketName='" + VirtualSocketName + '\'' +
|
||||
", LineTable=" + LineTable +
|
||||
", ConnectLineTable=" + ConnectLineTable +
|
||||
", ntpServerTable=" + ntpServerTable +
|
||||
", denyLineTableQuery=" + denyLineTableQuery +
|
||||
", denyLineTableBroadcast=" + denyLineTableBroadcast +
|
||||
", congestionAlgorithm='" + congestionAlgorithm + '\'' +
|
||||
", burstLimit=" + burstLimit +
|
||||
", delayUpperBound=" + delayUpperBound +
|
||||
", delayLowerBound=" + delayLowerBound +
|
||||
", nagleDelayTime=" + nagleDelayTime +
|
||||
", linkNagleDelayTime=" + linkNagleDelayTime +
|
||||
", linkConnectionsCount=" + linkConnectionsCount +
|
||||
", TUNName='" + TUNName + '\'' +
|
||||
", performanceStrategy='" + performanceStrategy + '\'' +
|
||||
", NetworkInterfaceExcepts=" + NetworkInterfaceExcepts +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
KLALBControllerConfigItem that = (KLALBControllerConfigItem) o;
|
||||
return nogui == that.nogui && denyLineTableQuery == that.denyLineTableQuery && denyLineTableBroadcast == that.denyLineTableBroadcast && Double.compare(burstLimit, that.burstLimit) == 0 && Double.compare(delayUpperBound, that.delayUpperBound) == 0 && Double.compare(delayLowerBound, that.delayLowerBound) == 0 && nagleDelayTime == that.nagleDelayTime && linkNagleDelayTime == that.linkNagleDelayTime && linkConnectionsCount == that.linkConnectionsCount && Objects.equals(language, that.language) && Objects.equals(VirtualAddress, that.VirtualAddress) && Objects.equals(VirtualASN, that.VirtualASN) && Objects.equals(DNS, that.DNS) && Objects.equals(TCPListen, that.TCPListen) && Objects.equals(UDPListen, that.UDPListen) && Objects.equals(VirtualSocketName, that.VirtualSocketName) && Objects.equals(LineTable, that.LineTable) && Objects.equals(ConnectLineTable, that.ConnectLineTable) && Objects.equals(ntpServerTable, that.ntpServerTable) && Objects.equals(congestionAlgorithm, that.congestionAlgorithm) && Objects.equals(TUNName, that.TUNName) && Objects.equals(performanceStrategy, that.performanceStrategy) && Objects.equals(NetworkInterfaceExcepts, that.NetworkInterfaceExcepts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((ConnectLineTable == null) ? 0 : ConnectLineTable.hashCode());
|
||||
result = prime * result + ((DNS == null) ? 0 : DNS.hashCode());
|
||||
result = prime * result + ((LineTable == null) ? 0 : LineTable.hashCode());
|
||||
result = prime * result + ((NetworkInterfaceExcepts == null) ? 0 : NetworkInterfaceExcepts.hashCode());
|
||||
result = prime * result + ((TCPListen == null) ? 0 : TCPListen.hashCode());
|
||||
result = prime * result + ((TUNName == null) ? 0 : TUNName.hashCode());
|
||||
result = prime * result + ((UDPListen == null) ? 0 : UDPListen.hashCode());
|
||||
result = prime * result + ((VirtualASN == null) ? 0 : VirtualASN.hashCode());
|
||||
result = prime * result + ((VirtualAddress == null) ? 0 : VirtualAddress.hashCode());
|
||||
result = prime * result + ((VirtualSocketName == null) ? 0 : VirtualSocketName.hashCode());
|
||||
result = prime * result + ((congestionAlgorithm == null) ? 0 : congestionAlgorithm.hashCode());
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(delayLowerBound);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(delayUpperBound);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
result = prime * result + (denyLineTableBroadcast ? 1231 : 1237);
|
||||
result = prime * result + (denyLineTableQuery ? 1231 : 1237);
|
||||
result = prime * result + ((language == null) ? 0 : language.hashCode());
|
||||
result = prime * result + linkConnectionsCount;
|
||||
result = prime * result + (int) (linkNagleDelayTime ^ (linkNagleDelayTime >>> 32));
|
||||
result = prime * result + (int) (nagleDelayTime ^ (nagleDelayTime >>> 32));
|
||||
result = prime * result + (nogui ? 1231 : 1237);
|
||||
result = prime * result + ((ntpServerTable == null) ? 0 : ntpServerTable.hashCode());
|
||||
return result;
|
||||
return Objects.hash(super.hashCode(), language, nogui, VirtualAddress, VirtualASN, DNS, TCPListen, UDPListen, VirtualSocketName, LineTable, ConnectLineTable, ntpServerTable, denyLineTableQuery, denyLineTableBroadcast, congestionAlgorithm, burstLimit, delayUpperBound, delayLowerBound, nagleDelayTime, linkNagleDelayTime, linkConnectionsCount, TUNName, performanceStrategy, NetworkInterfaceExcepts);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
KLALBControllerConfigItem other = (KLALBControllerConfigItem) obj;
|
||||
if (ConnectLineTable == null) {
|
||||
if (other.ConnectLineTable != null)
|
||||
return false;
|
||||
} else if (!ConnectLineTable.equals(other.ConnectLineTable))
|
||||
return false;
|
||||
if (DNS == null) {
|
||||
if (other.DNS != null)
|
||||
return false;
|
||||
} else if (!DNS.equals(other.DNS))
|
||||
return false;
|
||||
if (LineTable == null) {
|
||||
if (other.LineTable != null)
|
||||
return false;
|
||||
} else if (!LineTable.equals(other.LineTable))
|
||||
return false;
|
||||
if (NetworkInterfaceExcepts == null) {
|
||||
if (other.NetworkInterfaceExcepts != null)
|
||||
return false;
|
||||
} else if (!NetworkInterfaceExcepts.equals(other.NetworkInterfaceExcepts))
|
||||
return false;
|
||||
if (TCPListen == null) {
|
||||
if (other.TCPListen != null)
|
||||
return false;
|
||||
} else if (!TCPListen.equals(other.TCPListen))
|
||||
return false;
|
||||
if (TUNName == null) {
|
||||
if (other.TUNName != null)
|
||||
return false;
|
||||
} else if (!TUNName.equals(other.TUNName))
|
||||
return false;
|
||||
if (UDPListen == null) {
|
||||
if (other.UDPListen != null)
|
||||
return false;
|
||||
} else if (!UDPListen.equals(other.UDPListen))
|
||||
return false;
|
||||
if (VirtualASN == null) {
|
||||
if (other.VirtualASN != null)
|
||||
return false;
|
||||
} else if (!VirtualASN.equals(other.VirtualASN))
|
||||
return false;
|
||||
if (VirtualAddress == null) {
|
||||
if (other.VirtualAddress != null)
|
||||
return false;
|
||||
} else if (!VirtualAddress.equals(other.VirtualAddress))
|
||||
return false;
|
||||
if (VirtualSocketName == null) {
|
||||
if (other.VirtualSocketName != null)
|
||||
return false;
|
||||
} else if (!VirtualSocketName.equals(other.VirtualSocketName))
|
||||
return false;
|
||||
if (congestionAlgorithm == null) {
|
||||
if (other.congestionAlgorithm != null)
|
||||
return false;
|
||||
} else if (!congestionAlgorithm.equals(other.congestionAlgorithm))
|
||||
return false;
|
||||
if (Double.doubleToLongBits(delayLowerBound) != Double.doubleToLongBits(other.delayLowerBound))
|
||||
return false;
|
||||
if (Double.doubleToLongBits(delayUpperBound) != Double.doubleToLongBits(other.delayUpperBound))
|
||||
return false;
|
||||
if (denyLineTableBroadcast != other.denyLineTableBroadcast)
|
||||
return false;
|
||||
if (denyLineTableQuery != other.denyLineTableQuery)
|
||||
return false;
|
||||
if (language == null) {
|
||||
if (other.language != null)
|
||||
return false;
|
||||
} else if (!language.equals(other.language))
|
||||
return false;
|
||||
if (linkConnectionsCount != other.linkConnectionsCount)
|
||||
return false;
|
||||
if (linkNagleDelayTime != other.linkNagleDelayTime)
|
||||
return false;
|
||||
if (nagleDelayTime != other.nagleDelayTime)
|
||||
return false;
|
||||
if (nogui != other.nogui)
|
||||
return false;
|
||||
if (ntpServerTable == null) {
|
||||
if (other.ntpServerTable != null)
|
||||
return false;
|
||||
} else if (!ntpServerTable.equals(other.ntpServerTable))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -11,7 +13,7 @@ import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.SocketChannelListener;
|
||||
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
||||
import org.kne.cloud.network.ipv6.RouteItem;
|
||||
@@ -87,6 +89,7 @@ public class KLALBMain {
|
||||
System.out.println(" links-remove <addr:port>: remove link");
|
||||
System.out.println(" links-reconnect: reconnect all link");
|
||||
System.out.println(" kltp-state: query kltp states");
|
||||
System.out.println(" interfaces: show all network interfaces");
|
||||
System.out.println(" route: display internal route table");
|
||||
System.out.println(" kperf <addr:port>: performance benchmark");
|
||||
System.out.println(" exit: Exit");
|
||||
@@ -115,7 +118,7 @@ public class KLALBMain {
|
||||
break;
|
||||
case "links-add":
|
||||
if(sc.length>=2) {
|
||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress(sc[1]);
|
||||
MultiProtocolSocketAddress mpsa=new MultiProtocolSocketAddress(sc[1]);
|
||||
List<KLALBRemoteLink>addl=kpcje.getKlalbController().addRemoteLines(mpsa);
|
||||
if(addl.isEmpty()) {
|
||||
//System.out.println("添加失败,线路已存在!");
|
||||
@@ -135,7 +138,7 @@ public class KLALBMain {
|
||||
break;
|
||||
case "links-remove":
|
||||
if(sc.length>=2) {
|
||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress(sc[1]);
|
||||
MultiProtocolSocketAddress mpsa=new MultiProtocolSocketAddress(sc[1]);
|
||||
List<KLALBRemoteLink>rmvl=kpcje.getKlalbController().removeRemoteLines(mpsa);
|
||||
if(rmvl.isEmpty()) {
|
||||
System.out.println("No matched link has been found.");
|
||||
@@ -161,6 +164,18 @@ public class KLALBMain {
|
||||
case "kltp-state":
|
||||
System.out.println(kpcje.getKlalbController().getKLTPregister().toString());
|
||||
break;
|
||||
case "interfaces":
|
||||
NetworkInterfaceManager networkInterfaceManager= kpcje.getKlalbController().getNetworkInterfaceManager();
|
||||
List<NetworkInterface> interfaceList=networkInterfaceManager.getAllAvaliableNetworkInterface();
|
||||
System.out.println("Network interface detected:");
|
||||
for(NetworkInterface networkInterface:interfaceList){
|
||||
System.out.println(networkInterface.getName()+"("+networkInterface.getDisplayName()+")");
|
||||
List<InetAddress> lst= networkInterfaceManager.getNetworkInterfaceAddress(networkInterface);
|
||||
for(InetAddress address :lst){
|
||||
System.out.println(" "+address.getHostAddress());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "route":
|
||||
List<RouteItem> lri=new ArrayList<>( kpcje.getKlalbController().getIpv6Router().getCurrentRouteTabel());
|
||||
Collections.sort(lri);
|
||||
@@ -174,7 +189,7 @@ public class KLALBMain {
|
||||
break;
|
||||
case "kperf":
|
||||
if(sc.length>=2) {
|
||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress(sc[1]);
|
||||
MultiProtocolSocketAddress mpsa=new MultiProtocolSocketAddress(sc[1]);
|
||||
Kperf kp=new Kperf(mpsa);
|
||||
kp.startPerfing();
|
||||
}else {
|
||||
|
||||
@@ -2,12 +2,6 @@ package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
|
||||
public interface KLALBPacketLink {
|
||||
public void writeKLALBPacket(KLALBPacket kp) throws IOException;
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.net.UnknownHostException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.kne.cloud.network.KLALBDetectorItem;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.ProtocolDetector;
|
||||
import org.kne.cloud.network.ProtocolDetectorServerSocket;
|
||||
import org.kne.cloud.network.ProtocolDetectorSocket;
|
||||
@@ -30,8 +30,8 @@ public class KLALBProtocolDetectSocketListener extends SocketListener {
|
||||
super.open();
|
||||
}
|
||||
|
||||
public KLALBProtocolDetectSocketListener(MultipurposeSocketAddress multipurposeSocketAddress,KLALBController klalbc) throws IOException {
|
||||
super(multipurposeSocketAddress);
|
||||
public KLALBProtocolDetectSocketListener(MultiProtocolSocketAddress multiProtocolSocketAddress, KLALBController klalbc) throws IOException {
|
||||
super(multiProtocolSocketAddress);
|
||||
this.klalbController=klalbc;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class KLALBProxySystem {
|
||||
private File jsonFile;
|
||||
{
|
||||
GsonBuilder gb=new GsonBuilder().setPrettyPrinting();
|
||||
MultipurposeSocketAddress.registerToGsonBuilder(gb);
|
||||
MultiProtocolSocketAddress.registerToGsonBuilder(gb);
|
||||
KLALBConfigItem.registerToGsonBuilder(gb);
|
||||
gson=gb.create();
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class KLALBProxySystem {
|
||||
}
|
||||
}
|
||||
|
||||
public void enableRemoteManagement(MultipurposeSocketAddress bind) throws IOException {
|
||||
public void enableRemoteManagement(MultiProtocolSocketAddress bind) throws IOException {
|
||||
if(krm==null) {
|
||||
krm=new KLALBRemoteManagement(this,bind);
|
||||
}else {
|
||||
@@ -84,13 +84,17 @@ public class KLALBProxySystem {
|
||||
|
||||
public void loadConfigJson(File jsonFile) throws IOException {
|
||||
this.jsonFile=jsonFile;
|
||||
FileReader fr = null;
|
||||
try {
|
||||
fr=new FileReader(jsonFile);
|
||||
loadConfigJson(fr);
|
||||
}finally {
|
||||
if(fr!=null)
|
||||
fr.close();
|
||||
if(jsonFile.exists()) {
|
||||
FileReader fr = null;
|
||||
try {
|
||||
fr = new FileReader(jsonFile);
|
||||
loadConfigJson(fr);
|
||||
} finally {
|
||||
if (fr != null)
|
||||
fr.close();
|
||||
}
|
||||
}else{
|
||||
loadConfig(KLALBConfig.getDefault());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -128,9 +132,9 @@ public class KLALBProxySystem {
|
||||
|
||||
String vsne=kcci.getVirtualSocketName();
|
||||
//if(vsne!=null) {
|
||||
MultipurposeSocketAddress.getSocketTypeRegister().put(vsne, klalbController.getStreamSocketType());
|
||||
MultiProtocolSocketAddress.getSocketTypeRegister().put(vsne, klalbController.getStreamSocketType());
|
||||
//}
|
||||
MultipurposeSocketAddress tcple=kcci.getTCPListen();
|
||||
MultiProtocolSocketAddress tcple=kcci.getTCPListen();
|
||||
if(tcple!=null) {
|
||||
|
||||
SocketChannelListener tcpl = null;
|
||||
@@ -148,13 +152,13 @@ public class KLALBProxySystem {
|
||||
}
|
||||
|
||||
});
|
||||
MultipurposeSocketAddress mpsa2=new MultipurposeSocketAddress(tcple.getType(), tcple.getHost(),((InetSocketAddress)tcpl.getServerSocketChannel().getLocalAddress()).getPort());
|
||||
MultiProtocolSocketAddress mpsa2=new MultiProtocolSocketAddress(tcple.getProtocol(), tcple.getHost(),((InetSocketAddress)tcpl.getServerSocketChannel().getLocalAddress()).getPort());
|
||||
klalbController.getListenSocketAddress().add(mpsa2);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
MultipurposeSocketAddress udple=kcci.getUDPListen();
|
||||
MultiProtocolSocketAddress udple=kcci.getUDPListen();
|
||||
if(udple!=null) {
|
||||
DatagramSocketListener udpl = null;
|
||||
try {
|
||||
@@ -171,7 +175,7 @@ public class KLALBProxySystem {
|
||||
}
|
||||
|
||||
});
|
||||
MultipurposeSocketAddress mpsau2=new MultipurposeSocketAddress(udple.getType(), udple.getHost(),((InetSocketAddress)(udpl.getDatagramServerSocket().getLocalSocketAddress())).getPort());
|
||||
MultiProtocolSocketAddress mpsau2=new MultiProtocolSocketAddress(udple.getProtocol(), udple.getHost(),((InetSocketAddress)(udpl.getDatagramServerSocket().getLocalSocketAddress())).getPort());
|
||||
//klalbController.getListenSocketAddress().add(mpsau2);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
|
||||
@@ -2,6 +2,9 @@ package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.net.BindException;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.channels.UnresolvedAddressException;
|
||||
import java.security.SecureRandom;
|
||||
@@ -21,7 +24,7 @@ import org.kne.cloud.clock.HighAccuracyClock;
|
||||
import org.kne.cloud.clock.NTPTimestamps;
|
||||
import org.kne.cloud.clock.ReliabilityBackoffTimeClock;
|
||||
import org.kne.cloud.clock.WatchDogTimer;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
import org.kne.cloud.network.congestion.BBRCongestionAlgorithm;
|
||||
import org.kne.cloud.network.congestion.CongestionAlgorithm;
|
||||
@@ -100,8 +103,8 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
||||
private LinkStatus status=new LinkStatus();
|
||||
private SpeedAndTrafficAndDelayMonitorDataImpl monitor;
|
||||
private volatile KLALBPacketLink kplink;
|
||||
private MultipurposeSocketAddress bindAddress;
|
||||
private MultipurposeSocketAddress socketAddress;
|
||||
private MultiProtocolSocketAddress bindAddress;
|
||||
private MultiProtocolSocketAddress socketAddress;
|
||||
|
||||
|
||||
public void setKplink(KLALBPacketLink kplink) {
|
||||
@@ -112,11 +115,11 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
||||
return kplink;
|
||||
}
|
||||
|
||||
public MultipurposeSocketAddress getSocketAddress() {
|
||||
public MultiProtocolSocketAddress getSocketAddress() {
|
||||
return socketAddress;
|
||||
}
|
||||
|
||||
public MultipurposeSocketAddress getBindAddress() {
|
||||
public MultiProtocolSocketAddress getBindAddress() {
|
||||
return bindAddress;
|
||||
}
|
||||
|
||||
@@ -134,7 +137,7 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
||||
return peerAddress;
|
||||
}
|
||||
|
||||
public KLALBRemoteLink(KLALBController controller, MultipurposeSocketAddress mpa, IPv6AddressGroup address) {
|
||||
public KLALBRemoteLink(KLALBController controller, MultiProtocolSocketAddress mpa, IPv6AddressGroup address) {
|
||||
this(controller,mpa, null,address);
|
||||
}
|
||||
|
||||
@@ -147,7 +150,7 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
||||
name=kpl.toString();
|
||||
}
|
||||
|
||||
private KLALBRemoteLink(KLALBController controller,MultipurposeSocketAddress mpa, MultipurposeSocketAddress bindaddr, IPv6AddressGroup address) {
|
||||
private KLALBRemoteLink(KLALBController controller, MultiProtocolSocketAddress mpa, MultiProtocolSocketAddress bindaddr, IPv6AddressGroup address) {
|
||||
this.klalbController=controller;
|
||||
sysclk = klalbController.getClock();
|
||||
this.socketAddress = mpa;
|
||||
@@ -162,11 +165,11 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
||||
}
|
||||
|
||||
|
||||
public KLALBRemoteLink(KLALBController controller,MultipurposeSocketAddress mpa, MultipurposeSocketAddress bind) {
|
||||
public KLALBRemoteLink(KLALBController controller, MultiProtocolSocketAddress mpa, MultiProtocolSocketAddress bind) {
|
||||
this(controller,mpa, bind, null);
|
||||
}
|
||||
|
||||
public KLALBRemoteLink(KLALBController controller,MultipurposeSocketAddress mpa) {
|
||||
public KLALBRemoteLink(KLALBController controller, MultiProtocolSocketAddress mpa) {
|
||||
this(controller,mpa, (IPv6AddressGroup) null);
|
||||
}
|
||||
|
||||
@@ -283,7 +286,7 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
||||
sendLock.unlock();
|
||||
}
|
||||
}
|
||||
tlock.parkNanos(1000000L);
|
||||
tlock.parkNanos(10000000L);
|
||||
|
||||
}
|
||||
} catch (StreamCorruptedException sce) {
|
||||
@@ -569,7 +572,9 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
||||
public void run() {
|
||||
while (!closed) {
|
||||
status.updateReliability();
|
||||
monitor.update();
|
||||
if(status.getState()!=LinkStatus.DOWN) {
|
||||
monitor.update();
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
@@ -579,7 +584,7 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
private RemoteSender sender;
|
||||
private RemoteReceiver receiver;
|
||||
@@ -674,7 +679,23 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
||||
}
|
||||
} catch (StreamCorruptedException sce) {
|
||||
sce.printStackTrace();
|
||||
} catch (IOException | UnresolvedAddressException e) {
|
||||
}catch(BindException e) {
|
||||
close();
|
||||
if (debug)
|
||||
e.printStackTrace();
|
||||
}catch(NoRouteToHostException e){
|
||||
close();
|
||||
if (debug)
|
||||
e.printStackTrace();
|
||||
} catch(SocketException e) {
|
||||
String massage = e.getMessage();
|
||||
if (massage.toLowerCase().contains("unreachable")) {
|
||||
close();
|
||||
} else {
|
||||
if (debug)
|
||||
e.printStackTrace();
|
||||
}
|
||||
}catch (IOException | UnresolvedAddressException e) {
|
||||
if (debug)
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
@@ -929,23 +950,25 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
||||
public List<RouteItem> getRouteItems() {
|
||||
List<RouteItem> rlist = new ArrayList<>();
|
||||
|
||||
if(isUp()) {
|
||||
IPv6AddressGroup adg = addressGroup;
|
||||
/*if (adg != null)
|
||||
rlist.add(new RouteItem(new IPv6AddressGroup(adg.getAddress(), 128), adg.getAddress(), this, "Direct", 0, 0,
|
||||
null, "D", true));*/
|
||||
|
||||
for (Iterator<Neighbor> iteratorx = getNeighborsInfo().iterator(); iteratorx.hasNext();) {
|
||||
for (Iterator<Neighbor> iteratorx = getNeighborsInfo().iterator(); iteratorx.hasNext(); ) {
|
||||
Neighbor addresses = (Neighbor) iteratorx.next();
|
||||
RouteItem ri = new RouteItem(new IPv6AddressGroup(addresses.getAddress().getAddress(), 128),
|
||||
addresses.getAddress().getAddress(), this, "Direct", 0, 128,CostSupplierFactory.expectedDelaySupplier((DelayMonitorData) addresses.getMonitor(),status,algorithm::getRTO), "D", false);
|
||||
addresses.getAddress().getAddress(), this, "Direct", 0, 128, CostSupplierFactory.expectedDelaySupplier((DelayMonitorData) addresses.getMonitor(), status, algorithm::getRTO), "D", false);
|
||||
rlist.add(ri);
|
||||
|
||||
if (addresses.getLocator() != null) {
|
||||
RouteItem ris = new RouteItem(addresses.getLocator(), addresses.getLocator().getAddress(), this,
|
||||
"KLALB SRv6", 13, 128,CostSupplierFactory.expectedDelaySupplier((DelayMonitorData) addresses.getMonitor(),status,algorithm::getRTO), "D", false);
|
||||
"KLALB SRv6", 13, 128, CostSupplierFactory.expectedDelaySupplier((DelayMonitorData) addresses.getMonitor(), status, algorithm::getRTO), "D", false);
|
||||
rlist.add(ris);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rlist;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.nio.charset.Charset;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.SocketListener;
|
||||
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
||||
import org.kne.cloud.network.monitor.LinkStatus;
|
||||
@@ -20,9 +20,9 @@ public class KLALBRemoteManagement {
|
||||
SocketListener slr;
|
||||
private KLALBProxySystem klalbProxySystem;
|
||||
public KLALBRemoteManagement(KLALBProxySystem klalbProxySystem) throws IOException {
|
||||
this(klalbProxySystem,new MultipurposeSocketAddress("127.9.9.9", 49573));
|
||||
this(klalbProxySystem,new MultiProtocolSocketAddress("127.9.9.9", 49573));
|
||||
}
|
||||
public KLALBRemoteManagement(KLALBProxySystem klalbProxySystem,MultipurposeSocketAddress listen) throws IOException {
|
||||
public KLALBRemoteManagement(KLALBProxySystem klalbProxySystem, MultiProtocolSocketAddress listen) throws IOException {
|
||||
this.klalbProxySystem=klalbProxySystem;
|
||||
slr=new SocketListener(listen);
|
||||
slr.setCon((srcv)->{
|
||||
@@ -97,18 +97,18 @@ public class KLALBRemoteManagement {
|
||||
String mip=jreq.getAsJsonPrimitive("ipport").getAsString();
|
||||
try {
|
||||
|
||||
jrsp.addProperty ("Vaddr",klalbProxySystem.getKlalbController().getRemoteVaddrBySocketAddress(new MultipurposeSocketAddress(mip)).getHostAddress());
|
||||
jrsp.addProperty ("Vaddr",klalbProxySystem.getKlalbController().getRemoteVaddrBySocketAddress(new MultiProtocolSocketAddress(mip)).getHostAddress());
|
||||
} catch (SocketTimeoutException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case "GETSELFLINES":
|
||||
JsonArray lines2=new JsonArray();
|
||||
List<MultipurposeSocketAddress>selflineslist=klalbProxySystem.getKlalbController().getSelflineTable();
|
||||
List<MultiProtocolSocketAddress>selflineslist=klalbProxySystem.getKlalbController().getSelflineTable();
|
||||
synchronized (selflineslist) {
|
||||
for (Iterator<MultipurposeSocketAddress> iterator = selflineslist.iterator(); iterator.hasNext();) {
|
||||
MultipurposeSocketAddress multipurposeSocketAddress = (MultipurposeSocketAddress) iterator.next();
|
||||
lines2.add(new JsonPrimitive(multipurposeSocketAddress.toString()));
|
||||
for (Iterator<MultiProtocolSocketAddress> iterator = selflineslist.iterator(); iterator.hasNext();) {
|
||||
MultiProtocolSocketAddress multiProtocolSocketAddress = (MultiProtocolSocketAddress) iterator.next();
|
||||
lines2.add(new JsonPrimitive(multiProtocolSocketAddress.toString()));
|
||||
}
|
||||
}
|
||||
jrsp.add("table", lines2);
|
||||
@@ -116,16 +116,16 @@ public class KLALBRemoteManagement {
|
||||
break;
|
||||
case "ADDSELFLINE":
|
||||
String mips=jreq.getAsJsonPrimitive("ipport").getAsString();
|
||||
List<MultipurposeSocketAddress>selflineslist2=klalbProxySystem.getKlalbController().getSelflineTable();
|
||||
List<MultiProtocolSocketAddress>selflineslist2=klalbProxySystem.getKlalbController().getSelflineTable();
|
||||
synchronized (selflineslist2) {
|
||||
selflineslist2.add(new MultipurposeSocketAddress(mips));
|
||||
selflineslist2.add(new MultiProtocolSocketAddress(mips));
|
||||
}
|
||||
break;
|
||||
case "REMOVESELFLINE":
|
||||
String mipsr=jreq.getAsJsonPrimitive("ipport").getAsString();
|
||||
List<MultipurposeSocketAddress>selflineslist21=klalbProxySystem.getKlalbController().getSelflineTable();
|
||||
List<MultiProtocolSocketAddress>selflineslist21=klalbProxySystem.getKlalbController().getSelflineTable();
|
||||
synchronized (selflineslist21) {
|
||||
selflineslist21.add(new MultipurposeSocketAddress(mipsr));
|
||||
selflineslist21.add(new MultiProtocolSocketAddress(mipsr));
|
||||
}
|
||||
break;
|
||||
case "GETLINKMONITOR":
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.jctools.counters.CountersFactory;
|
||||
import org.jctools.counters.FixedSizeStripedLongCounter;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.ipv6.IPv6Address;
|
||||
|
||||
public class KLALBUtils {
|
||||
@@ -208,7 +208,7 @@ public class KLALBUtils {
|
||||
return col;
|
||||
}
|
||||
|
||||
public static KLALBPacketLink createKLALBPacketLink(MultipurposeSocketAddress bindAddress, MultipurposeSocketAddress targetAddress,boolean buffered)
|
||||
public static KLALBPacketLink createKLALBPacketLink(MultiProtocolSocketAddress bindAddress, MultiProtocolSocketAddress targetAddress, boolean buffered)
|
||||
throws IOException {
|
||||
if (targetAddress.isStream()) {
|
||||
if (targetAddress.supportNIO()) {
|
||||
@@ -235,8 +235,8 @@ public class KLALBUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
public static KLALBPacketLink createKLALBPacketLink(MultipurposeSocketAddress bindAddress,
|
||||
MultipurposeSocketAddress targetAddress,boolean buffered, int timeout) throws UnknownHostException, IOException {
|
||||
public static KLALBPacketLink createKLALBPacketLink(MultiProtocolSocketAddress bindAddress,
|
||||
MultiProtocolSocketAddress targetAddress, boolean buffered, int timeout) throws UnknownHostException, IOException {
|
||||
if (targetAddress.isStream()) {
|
||||
if (targetAddress.supportNIO()) {
|
||||
if (bindAddress != null) {
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
public class NetworkInterfaceManager {
|
||||
private List<NetworkInterface> networkInterfaceExcept = new ArrayList<>();
|
||||
private List<InetAddress> inetAddressesExcept = new ArrayList<>();
|
||||
|
||||
public List<NetworkInterface> getNetworkInterfaceExcept() {
|
||||
return networkInterfaceExcept;
|
||||
}
|
||||
|
||||
|
||||
public List<InetAddress> getInetAddressesExcept() {
|
||||
return inetAddressesExcept;
|
||||
}
|
||||
|
||||
public List<NetworkInterface> getAllAvaliableNetworkInterface() throws SocketException {
|
||||
List<NetworkInterface> interfaces = new ArrayList<NetworkInterface>();
|
||||
Enumeration<NetworkInterface> eu = NetworkInterface.getNetworkInterfaces();
|
||||
while (eu.hasMoreElements()) {
|
||||
NetworkInterface networkInterface = (NetworkInterface) eu.nextElement();
|
||||
|
||||
if (networkInterface.getDisplayName()
|
||||
.startsWith(CONST.KLALB_DECENTRALIZED_S_RV6_NETWORK)) {
|
||||
continue;
|
||||
}
|
||||
if (networkInterfaceExcept.contains(networkInterface)) {
|
||||
continue;
|
||||
}
|
||||
if (networkInterface.isUp()) {
|
||||
interfaces.add(networkInterface);
|
||||
}
|
||||
}
|
||||
return interfaces;
|
||||
}
|
||||
|
||||
public List<InetAddress> getAllNetworkInterfaceAddress() throws SocketException {
|
||||
List<NetworkInterface> interfaces=getAllAvaliableNetworkInterface();
|
||||
List<InetAddress> addresses = new ArrayList<InetAddress>();
|
||||
for (NetworkInterface nif:interfaces){
|
||||
addresses.addAll( getNetworkInterfaceAddress(nif));
|
||||
}
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public List<InetAddress> getNetworkInterfaceAddress(NetworkInterface networkInterface) throws SocketException {
|
||||
List<InetAddress> addresses = new ArrayList<InetAddress>();
|
||||
// System.out.println(networkInterface+" "+networkInterface.isUp());
|
||||
Enumeration<InetAddress> ei = networkInterface.getInetAddresses();
|
||||
while (ei.hasMoreElements()) {
|
||||
InetAddress inetAddress = (InetAddress) ei.nextElement();
|
||||
|
||||
if (inetAddress.isLoopbackAddress()){
|
||||
continue;
|
||||
}
|
||||
if (inetAddressesExcept.contains( inetAddress)) {
|
||||
continue;
|
||||
}
|
||||
addresses.add(inetAddress);
|
||||
}
|
||||
|
||||
return addresses;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import org.kne.cloud.network.klalb.ui.UIEnv;
|
||||
|
||||
public enum PerformanceStrategy {
|
||||
SINGLE_CORE("singlecore"),
|
||||
MULTI_FILL("multifill"),
|
||||
MULTI_SCATTER("multiscatter");
|
||||
|
||||
private String description;
|
||||
|
||||
private PerformanceStrategy(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 description 查找对应的枚举对象。
|
||||
*
|
||||
* @param description 描述文本(资源包key)
|
||||
* @return 对应的枚举对象
|
||||
*/
|
||||
public static PerformanceStrategy fromDescription(String description) {
|
||||
for (PerformanceStrategy strategy : values()) {
|
||||
if (strategy.description.equals(description)) {
|
||||
return strategy;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,23 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.channels.MulticastChannel;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.kne.cloud.network.DefaultMinecraftSocketBridgeFactory;
|
||||
import org.kne.cloud.network.DefaultSocketBridgeFactory;
|
||||
import org.kne.cloud.network.HostPortMap;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.Proxy;
|
||||
import org.kne.cloud.network.SocketBridgeFactory;
|
||||
import org.kne.cloud.network.SocketToSocketProxy;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
public class SocketBridgeConfigItem extends KLALBConfigItem {
|
||||
private MultipurposeSocketAddress Listen;
|
||||
private MultiProtocolSocketAddress Listen;
|
||||
|
||||
private LinkedHashMap<String, String>Bridge=new LinkedHashMap<>();
|
||||
private HostPortMap Connect=new HostPortMap();
|
||||
|
||||
public SocketBridgeConfigItem( MultipurposeSocketAddress listen,
|
||||
public SocketBridgeConfigItem( MultiProtocolSocketAddress listen,
|
||||
LinkedHashMap<String, String> bridge, HostPortMap connect) {
|
||||
super("SocketBridge");
|
||||
Listen = listen;
|
||||
@@ -85,12 +68,12 @@ public class SocketBridgeConfigItem extends KLALBConfigItem {
|
||||
public Proxy createProxy(KLALBController controller) throws IOException {
|
||||
HostPortMap mapp=new HostPortMap();
|
||||
LinkedHashMap<String, SocketBridgeFactory>mapb=new LinkedHashMap<>();
|
||||
MultipurposeSocketAddress l=Listen;
|
||||
MultiProtocolSocketAddress l=Listen;
|
||||
SocketBridgeFactory bdg=getDefaultBridgeFactory(Bridge,mapb,controller);
|
||||
MultipurposeSocketAddress r=getDefaultConnect(Connect,mapp);
|
||||
return new SocketToSocketProxy(l ,new MultipurposeSocketAddress("0.0.0.0:0"), r,mapp,bdg,mapb);
|
||||
MultiProtocolSocketAddress r=getDefaultConnect(Connect,mapp);
|
||||
return new SocketToSocketProxy(l ,new MultiProtocolSocketAddress("0.0.0.0:0"), r,mapp,bdg,mapb);
|
||||
}
|
||||
private MultipurposeSocketAddress getDefaultConnect(HostPortMap connect2, LinkedHashMap<String, MultipurposeSocketAddress> mapp) {
|
||||
private MultiProtocolSocketAddress getDefaultConnect(HostPortMap connect2, LinkedHashMap<String, MultiProtocolSocketAddress> mapp) {
|
||||
connect2.entrySet().forEach((en)->{
|
||||
mapp.put(en.getKey(), en.getValue());
|
||||
});
|
||||
|
||||
@@ -116,29 +116,20 @@ public class DatagramKLALBPacketLink implements KLALBPacketLink {
|
||||
}*/
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.kne.cloud.network.DatagramServerSocket;
|
||||
import org.kne.cloud.network.DatagramServerSocket.SubDatagramSocket;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
import org.kne.cloud.network.PacketRebuilder;
|
||||
import org.kne.cloud.network.PacketSpliter;
|
||||
import org.kne.cloud.network.SpeedLimiter;
|
||||
import org.kne.debug.TimeDebugger;
|
||||
|
||||
public class SplitedDatagramKLALBPacketLink extends AbstractKLALBPacketLink implements KLALBPacketLink {
|
||||
private PacketSpliter pslr;
|
||||
@@ -146,7 +137,7 @@ public class SplitedDatagramKLALBPacketLink extends AbstractKLALBPacketLink impl
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new MultipurposeSocketAddress("UDP",(InetSocketAddress)ds.getLocalSocketAddress())+"←"+new MultipurposeSocketAddress("UDP",(InetSocketAddress)ds.getRemoteSocketAddress());
|
||||
return new MultiProtocolSocketAddress("UDP",(InetSocketAddress)ds.getLocalSocketAddress())+"←"+new MultiProtocolSocketAddress("UDP",(InetSocketAddress)ds.getRemoteSocketAddress());
|
||||
}
|
||||
|
||||
private DatagramSocket ds;
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.kne.cloud.network.BufferedChannel;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
import org.kne.io.KNEChannels;
|
||||
@@ -45,7 +45,7 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return new MultipurposeSocketAddress("TCP",(InetSocketAddress)connectSocket.getLocalAddress())+"←"+new MultipurposeSocketAddress("TCP",(InetSocketAddress)connectSocket.getRemoteAddress());
|
||||
return new MultiProtocolSocketAddress((InetSocketAddress)connectSocket.getLocalAddress())+"←"+new MultiProtocolSocketAddress((InetSocketAddress)connectSocket.getRemoteAddress());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "?←?";
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
|
||||
public class StreamKLALBPacketLink extends AbstractKLALBPacketLink implements KLALBPacketLink {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new MultipurposeSocketAddress("TCP",(InetSocketAddress)connectSocket.getLocalSocketAddress())+"←"+new MultipurposeSocketAddress("TCP",(InetSocketAddress)connectSocket.getRemoteSocketAddress());
|
||||
return new MultiProtocolSocketAddress((InetSocketAddress)connectSocket.getLocalSocketAddress())+"←"+new MultiProtocolSocketAddress((InetSocketAddress)connectSocket.getRemoteSocketAddress());
|
||||
}
|
||||
|
||||
private Socket connectSocket;
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.jfree.chart.plot.dial.*;
|
||||
import org.jfree.data.general.DefaultValueDataset;
|
||||
import org.kne.cloud.clock.HighAccuracyClock;
|
||||
import org.kne.cloud.klalb.uitool.*;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.ipv6.IPv6Address;
|
||||
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
||||
import org.kne.cloud.network.klalb.*;
|
||||
@@ -80,7 +80,7 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
private JTextField textFieldLocate; // 定位地址输入框
|
||||
private JTextField asnField2; // ASN显示框
|
||||
private JTextArea dnsAreaSet; // DNS服务器设置区域
|
||||
private JComboBox comboPerformance; // 性能策略选择框
|
||||
private JComboBox<PerformanceStrategyItem> comboPerformance; // 性能策略选择框
|
||||
private JComboBox comboCongestion; // 拥塞控制算法选择框
|
||||
private JTextField tcpListeningSet; // TCP监听设置
|
||||
private JTextField udpListeningSet; // UDP监听设置
|
||||
@@ -597,7 +597,7 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
JButton btnNewButton = new JButton(UIEnv.getRsb().getString("addline"));
|
||||
btnNewButton.addActionListener(e -> {
|
||||
try {
|
||||
MultipurposeSocketAddress mpsa= new MultipurposeSocketAddress(textField.getText());
|
||||
MultiProtocolSocketAddress mpsa= new MultiProtocolSocketAddress(textField.getText());
|
||||
Thread t=new Thread(()->{
|
||||
kc.addRemoteLines(mpsa);
|
||||
});
|
||||
@@ -892,8 +892,10 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
performanceStrategy = new ComboSettingItem(UIEnv.getRsb().getString("performancestrategy"),
|
||||
CONST.itemwidth, CONST.settingheight);
|
||||
comboPerformance = performanceStrategy.getComboBox();
|
||||
comboPerformance.addItem("1");
|
||||
comboPerformance.addItem("2");
|
||||
comboPerformance.addItem(new PerformanceStrategyItem(PerformanceStrategy.SINGLE_CORE));
|
||||
comboPerformance.addItem(new PerformanceStrategyItem(PerformanceStrategy.MULTI_FILL));
|
||||
comboPerformance.addItem(new PerformanceStrategyItem(PerformanceStrategy.MULTI_SCATTER));
|
||||
comboPerformance.setSelectedIndex(1);
|
||||
settings.getView().add(performanceStrategy);
|
||||
|
||||
|
||||
@@ -1008,7 +1010,7 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
private void saveConfig() {
|
||||
if (config == null) {
|
||||
config = new KLALBConfig();
|
||||
config.add(new KLALBControllerConfigItem("KLALBController"));
|
||||
config.add(new KLALBControllerConfigItem());
|
||||
}
|
||||
|
||||
for (KLALBConfigItem item : config) {
|
||||
@@ -1084,7 +1086,7 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
kck.setTCPListen(null);
|
||||
} else {
|
||||
try {
|
||||
kck.setTCPListen(new MultipurposeSocketAddress(tcptext));
|
||||
kck.setTCPListen(new MultiProtocolSocketAddress(tcptext));
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(this, UIEnv.getRsb().getString("invaildtcplisten"),
|
||||
@@ -1099,7 +1101,7 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
kck.setUDPListen(null);
|
||||
} else {
|
||||
try {
|
||||
kck.setUDPListen(new MultipurposeSocketAddress(udptext));
|
||||
kck.setUDPListen(new MultiProtocolSocketAddress(udptext));
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
JOptionPane.showMessageDialog(this, UIEnv.getRsb().getString("invaildudplisten"),
|
||||
@@ -1110,13 +1112,13 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
|
||||
// 保存开放线路表
|
||||
String[] splt1 = openLineTabelSet.getText().split("\n");
|
||||
List<MultipurposeSocketAddress> iaddr1 = new ArrayList<>();
|
||||
List<MultiProtocolSocketAddress> iaddr1 = new ArrayList<>();
|
||||
boolean show1 = true;
|
||||
for (String str : splt1) {
|
||||
try {
|
||||
str = str.trim();
|
||||
if (!str.isEmpty())
|
||||
iaddr1.add(new MultipurposeSocketAddress(str));
|
||||
iaddr1.add(new MultiProtocolSocketAddress(str));
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
if (show1) {
|
||||
@@ -1131,13 +1133,13 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
|
||||
// 保存自动连接线路表
|
||||
String[] splt11 = connectLineTabelSet.getText().split("\n");
|
||||
List<MultipurposeSocketAddress> iaddr11 = new ArrayList<>();
|
||||
List<MultiProtocolSocketAddress> iaddr11 = new ArrayList<>();
|
||||
boolean show11 = true;
|
||||
for (String str : splt11) {
|
||||
try {
|
||||
str = str.trim();
|
||||
if (!str.isEmpty())
|
||||
iaddr11.add(new MultipurposeSocketAddress(str));
|
||||
iaddr11.add(new MultiProtocolSocketAddress(str));
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
if (show11) {
|
||||
@@ -1152,13 +1154,13 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
|
||||
// 保存NTP服务器表
|
||||
String[] splt111 = ntpServerSet.getText().split("\n");
|
||||
List<MultipurposeSocketAddress> iaddr111 = new ArrayList<>();
|
||||
List<MultiProtocolSocketAddress> iaddr111 = new ArrayList<>();
|
||||
boolean show111 = true;
|
||||
for (String str : splt111) {
|
||||
try {
|
||||
str = str.trim();
|
||||
if (!str.isEmpty())
|
||||
iaddr111.add(new MultipurposeSocketAddress(str));
|
||||
iaddr111.add(new MultiProtocolSocketAddress(str));
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
if (show111) {
|
||||
@@ -1183,7 +1185,12 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
kck.setDenyLineTableQuery(denyQuery.isSelected());
|
||||
|
||||
kck.setDenyLineTableBroadcast(denyBroadcast.isSelected());
|
||||
|
||||
|
||||
PerformanceStrategyItem psi=((PerformanceStrategyItem)comboPerformance.getSelectedItem());
|
||||
if(psi!=null) {
|
||||
kck.setPerformanceStrategy(psi.getStrategy().toString());
|
||||
}
|
||||
|
||||
kck.setCongestionAlgorithm((String) congestions.getComboBox().getSelectedItem());
|
||||
|
||||
kck.setBurstLimit(1.0+burstLimit.getSlider().getValue()/1000.0);
|
||||
@@ -1217,58 +1224,60 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
tsk = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
Object[] kll = kc.getLines().toArray();
|
||||
if (isVisible()) {
|
||||
Object[] kll = kc.getLines().toArray();
|
||||
|
||||
// 遍历所有线路,更新或添加TPanel2
|
||||
for (Object obj : kll) {
|
||||
IPv6NetworkLink link = (IPv6NetworkLink) obj;
|
||||
if (!(link instanceof KLALBRemoteLink)) {
|
||||
continue;
|
||||
// 遍历所有线路,更新或添加TPanel2
|
||||
for (Object obj : kll) {
|
||||
IPv6NetworkLink link = (IPv6NetworkLink) obj;
|
||||
if (!(link instanceof KLALBRemoteLink)) {
|
||||
continue;
|
||||
}
|
||||
KLALBRemoteLink ent = (KLALBRemoteLink) link;
|
||||
|
||||
Component[] count = ysp.getView().getComponents();
|
||||
boolean found = false;
|
||||
|
||||
// 查找是否已有对应线路的面板
|
||||
for (Component tp : count) {
|
||||
if (tp instanceof TPanel2) {
|
||||
if (((TPanel2) tp).getTunnel().equals(ent)) {
|
||||
tp.setVisible(showoffline.isSelected() || (
|
||||
ent.getState() != LinkStatus.DOWN));
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有找到,创建新面板
|
||||
if (!found) {
|
||||
TPanel2 tp = new TPanel2(ent, kc);
|
||||
tp.setVisible(showoffline.isSelected() || (
|
||||
ent.getState() != LinkStatus.DOWN));
|
||||
ysp.getView().add(tp);
|
||||
}
|
||||
}
|
||||
KLALBRemoteLink ent = (KLALBRemoteLink) link;
|
||||
|
||||
// 更新所有面板并移除不存在的线路
|
||||
Component[] count = ysp.getView().getComponents();
|
||||
boolean found = false;
|
||||
|
||||
// 查找是否已有对应线路的面板
|
||||
for (Component tp : count) {
|
||||
if (tp instanceof TPanel2) {
|
||||
if (((TPanel2) tp).getTunnel().equals(ent)) {
|
||||
tp.setVisible(showoffline.isSelected() || (
|
||||
ent.getState() != LinkStatus.DOWN));
|
||||
found = true;
|
||||
break;
|
||||
if (kc.getLines().contains(((TPanel2) tp).getTunnel())) {
|
||||
try {
|
||||
if (tp.isVisible())
|
||||
((TPanel2) tp).updateTraffic();
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
ysp.getView().remove(tp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有找到,创建新面板
|
||||
if (!found) {
|
||||
TPanel2 tp = new TPanel2(ent, kc);
|
||||
tp.setVisible(showoffline.isSelected() || (
|
||||
ent.getState()!= LinkStatus.DOWN));
|
||||
ysp.getView().add(tp);
|
||||
}
|
||||
|
||||
ysp.updateScrool();
|
||||
}
|
||||
|
||||
// 更新所有面板并移除不存在的线路
|
||||
Component[] count = ysp.getView().getComponents();
|
||||
for (Component tp : count) {
|
||||
if (tp instanceof TPanel2) {
|
||||
if (kc.getLines().contains(((TPanel2) tp).getTunnel())) {
|
||||
try {
|
||||
if (tp.isVisible())
|
||||
((TPanel2) tp).updateTraffic();
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
ysp.getView().remove(tp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ysp.updateScrool();
|
||||
}
|
||||
};
|
||||
t.scheduleAtFixedRate(tsk, 1000, 1000);
|
||||
@@ -1460,23 +1469,23 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
tunDeviceName.setText(tunname!=null?tunname:"");
|
||||
|
||||
// 加载TCP监听
|
||||
MultipurposeSocketAddress mpat = kck.getTCPListen();
|
||||
MultiProtocolSocketAddress mpat = kck.getTCPListen();
|
||||
tcpListeningSet.setText(mpat != null ? mpat.toString() : "");
|
||||
|
||||
// 加载UDP监听
|
||||
MultipurposeSocketAddress mpau = kck.getUDPListen();
|
||||
MultiProtocolSocketAddress mpau = kck.getUDPListen();
|
||||
udpListeningSet.setText(mpau != null ? mpau.toString() : "");
|
||||
|
||||
// 加载开放线路表
|
||||
List<MultipurposeSocketAddress> linet = kck.getLineTable();
|
||||
List<MultiProtocolSocketAddress> linet = kck.getLineTable();
|
||||
openLineTabelSet.setText(listToStr2(linet));
|
||||
|
||||
// 加载自动连接线路表
|
||||
List<MultipurposeSocketAddress> clinet = kck.getConnectLineTable();
|
||||
List<MultiProtocolSocketAddress> clinet = kck.getConnectLineTable();
|
||||
connectLineTabelSet.setText(listToStr2(clinet));
|
||||
|
||||
// 加载NTP服务器表
|
||||
List<MultipurposeSocketAddress> ntps = kck.getNtpServerTable();
|
||||
List<MultiProtocolSocketAddress> ntps = kck.getNtpServerTable();
|
||||
ntpServerSet.setText(listToStr2(ntps));
|
||||
|
||||
// 加载网络接口排除列表
|
||||
@@ -1500,7 +1509,18 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
denyQuery.setSelected( kck.isDenyLineTableQuery());
|
||||
|
||||
denyBroadcast.setSelected( kck.isDenyLineTableBroadcast());
|
||||
|
||||
|
||||
String stategy= kck.getPerformanceStrategy();
|
||||
PerformanceStrategy pfs=PerformanceStrategy.fromDescription(stategy);
|
||||
if(pfs!=null) {
|
||||
for (int i=0;i<comboPerformance.getItemCount();i++){
|
||||
if(((PerformanceStrategyItem)comboPerformance.getModel().getElementAt(i)).getStrategy().equals(pfs)) {
|
||||
comboPerformance.setSelectedIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String con=kck.getCongestionAlgorithm();
|
||||
if(con==null) {
|
||||
congestions.getComboBox().setSelectedItem("BBR");
|
||||
|
||||
@@ -8,7 +8,7 @@ import javax.swing.border.LineBorder;
|
||||
|
||||
import org.jfree.chart.plot.dial.DialTextAnnotation;
|
||||
import org.jfree.data.general.DefaultValueDataset;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.klalb.CONST;
|
||||
import org.kne.cloud.network.klalb.KLALBUtils;
|
||||
import org.kne.cloud.network.monitor.SpeedAndTrafficAndDelayMonitorDataImpl;
|
||||
@@ -143,9 +143,9 @@ public class KperfGUI extends XFrame{
|
||||
if(kperf==null) {
|
||||
try {
|
||||
String tar=targetAddressField.getText();
|
||||
MultipurposeSocketAddress msa=new MultipurposeSocketAddress(tar);
|
||||
MultiProtocolSocketAddress msa=new MultiProtocolSocketAddress(tar);
|
||||
String sour=sourceAddressField.getText();
|
||||
MultipurposeSocketAddress msas=new MultipurposeSocketAddress(sour);
|
||||
MultiProtocolSocketAddress msas=new MultiProtocolSocketAddress(sour);
|
||||
kperf=new Kperf(msa,msas);
|
||||
kperf.setReports(reports);
|
||||
kperf.startPerfing();
|
||||
@@ -650,10 +650,10 @@ public class KperfGUI extends XFrame{
|
||||
startButton.setText(UIEnv.getRsb().getString("stoptest"));
|
||||
}
|
||||
}
|
||||
public void setTarget(MultipurposeSocketAddress target) {
|
||||
public void setTarget(MultiProtocolSocketAddress target) {
|
||||
targetAddressField.setText(target.toString());
|
||||
}
|
||||
public void setTarget(MultipurposeSocketAddress target,MultipurposeSocketAddress source) {
|
||||
public void setTarget(MultiProtocolSocketAddress target, MultiProtocolSocketAddress source) {
|
||||
targetAddressField.setText(target.toString());
|
||||
sourceAddressField.setText(source.toString());
|
||||
}
|
||||
|
||||
@@ -1,48 +1,25 @@
|
||||
package org.kne.cloud.network.klalb.ui;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.geom.Dimension2D;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.ipv6.IPv6Address;
|
||||
import org.kne.cloud.network.klalb.KLALBController;
|
||||
import org.kne.cloud.network.klalb.KLALBUtils;
|
||||
import org.kne.cloud.network.srv6.KLALBRoutingProtocol;
|
||||
import org.kne.cloud.network.srv6.KLALBRoutingProtocol.LinkDirection;
|
||||
|
||||
public class NetworkGraphPanel extends GraphPanel {
|
||||
@@ -105,8 +82,8 @@ public class NetworkGraphPanel extends GraphPanel {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
KperfGUI kpfg=new KperfGUI();
|
||||
kpfg.setVisible(true);
|
||||
MultipurposeSocketAddress source=new MultipurposeSocketAddress("KLALB_Stream",controller.getIpv6Router().getLocator().getAddress().toString(),0);
|
||||
MultipurposeSocketAddress target=new MultipurposeSocketAddress("KLALB_Stream", address.toString(), 4564);
|
||||
MultiProtocolSocketAddress source=new MultiProtocolSocketAddress("KLALB_Stream",controller.getIpv6Router().getLocator().getAddress().toString(),0);
|
||||
MultiProtocolSocketAddress target=new MultiProtocolSocketAddress("KLALB_Stream", address.toString(), 4564);
|
||||
kpfg.setTarget(target,source);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,24 +5,21 @@ import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import org.kne.cloud.klalb.uitool.XDefaultListModel;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.ipv6.IPv6Address;
|
||||
import org.kne.cloud.network.klalb.KLALBController;
|
||||
import org.kne.cloud.network.srv6.KLALBRoutingProtocol;
|
||||
@@ -30,7 +27,6 @@ import org.kne.cloud.network.srv6.KLALBRoutingProtocolAPIClient;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -43,7 +39,7 @@ public class NodeInformationPanel extends JPanel {
|
||||
private KLALBController controller;
|
||||
private Image image;
|
||||
|
||||
private XDefaultListModel<MultipurposeSocketAddress> listModel=new XDefaultListModel<>();
|
||||
private XDefaultListModel<MultiProtocolSocketAddress> listModel=new XDefaultListModel<>();
|
||||
public KLALBController getController() {
|
||||
return controller;
|
||||
}
|
||||
@@ -73,7 +69,7 @@ public class NodeInformationPanel extends JPanel {
|
||||
panel_1.setLayout(new BorderLayout(0, 0));
|
||||
panel_1.add(scrollPane);
|
||||
|
||||
JList<MultipurposeSocketAddress> list = new JList<MultipurposeSocketAddress>(listModel);
|
||||
JList<MultiProtocolSocketAddress> list = new JList<MultiProtocolSocketAddress>(listModel);
|
||||
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
scrollPane.setViewportView(list);
|
||||
tabbedPane.addTab(UIEnv.getRsb().getString("openlinetable"), null, panel_1, null);
|
||||
@@ -81,7 +77,7 @@ public class NodeInformationPanel extends JPanel {
|
||||
JButton btnNewButton = new JButton(UIEnv.getRsb().getString("addline"));
|
||||
btnNewButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<MultipurposeSocketAddress> select=list.getSelectedValuesList();
|
||||
List<MultiProtocolSocketAddress> select=list.getSelectedValuesList();
|
||||
controller.addRemoteLines(select);
|
||||
}
|
||||
});
|
||||
@@ -93,7 +89,7 @@ public class NodeInformationPanel extends JPanel {
|
||||
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
List<MultipurposeSocketAddress> select=list.getSelectedValuesList();
|
||||
List<MultiProtocolSocketAddress> select=list.getSelectedValuesList();
|
||||
btnNewButton.setEnabled( !select.isEmpty()) ;
|
||||
copy.setEnabled(!select.isEmpty());
|
||||
}
|
||||
@@ -103,9 +99,9 @@ public class NodeInformationPanel extends JPanel {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
StringBuilder sb=new StringBuilder();
|
||||
List<MultipurposeSocketAddress> select=list.getSelectedValuesList();
|
||||
for (MultipurposeSocketAddress multipurposeSocketAddress : select) {
|
||||
sb.append(multipurposeSocketAddress);
|
||||
List<MultiProtocolSocketAddress> select=list.getSelectedValuesList();
|
||||
for (MultiProtocolSocketAddress multiProtocolSocketAddress : select) {
|
||||
sb.append(multiProtocolSocketAddress);
|
||||
sb.append('\n');
|
||||
}
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(sb.toString()), null);
|
||||
@@ -152,8 +148,8 @@ public class NodeInformationPanel extends JPanel {
|
||||
try {
|
||||
client.requestOpenLines(new InetSocketAddress( address.toInet6Address(), KLALBRoutingProtocol.DEFAULT_PORT), (result)->{
|
||||
listModel.clear();
|
||||
for (MultipurposeSocketAddress multipurposeSocketAddress : result) {
|
||||
listModel.addElement(multipurposeSocketAddress);
|
||||
for (MultiProtocolSocketAddress multiProtocolSocketAddress : result) {
|
||||
listModel.addElement(multiProtocolSocketAddress);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.kne.cloud.network.klalb.ui;
|
||||
|
||||
import org.kne.cloud.network.klalb.PerformanceStrategy;
|
||||
|
||||
public class PerformanceStrategyItem {
|
||||
private PerformanceStrategy strategy;
|
||||
|
||||
public PerformanceStrategyItem(PerformanceStrategy strategy) {
|
||||
this.strategy = strategy;
|
||||
}
|
||||
|
||||
public PerformanceStrategy getStrategy() {
|
||||
return strategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return UIEnv.getRsb().getString(strategy.toString());
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import java.awt.Dimension;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.MultiProtocolSocketAddress;
|
||||
import org.kne.cloud.network.ipv6.IPv6AddressGroup;
|
||||
import org.kne.cloud.network.klalb.CONST;
|
||||
import org.kne.cloud.network.klalb.KLALBController;
|
||||
@@ -219,7 +219,7 @@ public class TPanel2 extends JPanel {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
MultipurposeSocketAddress mtar=tunnel.getSocketAddress();
|
||||
MultiProtocolSocketAddress mtar=tunnel.getSocketAddress();
|
||||
if(mtar!=null) {
|
||||
kc.removeRemoteLines(mtar);
|
||||
}else {
|
||||
|
||||
Reference in New Issue
Block a user