forked from KNEMC/KLALB
Changes
This commit is contained in:
@@ -7,42 +7,32 @@ import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.security.SecureRandom;
|
||||
import java.nio.channels.AsynchronousSocketChannel;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.kne.cloud.clock.AdjustedNanoClock;
|
||||
import org.kne.cloud.clock.HighAccuracyClock;
|
||||
import org.kne.cloud.network.IPMulticastDiscovery;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
@@ -50,41 +40,27 @@ import org.kne.cloud.network.PortPair;
|
||||
import org.kne.cloud.network.SocketType;
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
import org.kne.cloud.network.ipv6.IPv6Address;
|
||||
import org.kne.cloud.network.ipv6.IPv6AddressGroup;
|
||||
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
||||
import org.kne.cloud.network.ipv6.IPv6Packet;
|
||||
import org.kne.cloud.network.ipv6.IPv6Packet.IPv6ExtHeader;
|
||||
import org.kne.cloud.network.ipv6.IPv6Packet.IPv6Payload;
|
||||
import org.kne.cloud.network.ipv6.IPv6TUNLoopbackNetworkLink;
|
||||
import org.kne.cloud.network.ipv6.IPv6AddressGroup;
|
||||
import org.kne.cloud.network.ipv6.LoopbackIPv6NetworkLink;
|
||||
import org.kne.cloud.network.ipv6.Neighbor;
|
||||
import org.kne.cloud.network.ipv6.PacketID;
|
||||
import org.kne.cloud.network.kltp.KLTPPacket;
|
||||
import org.kne.cloud.network.kltp.KLTPProtocolRegister;
|
||||
import org.kne.cloud.network.monitor.HashMapTimestampMonitor;
|
||||
import org.kne.cloud.network.monitor.MonitorData;
|
||||
import org.kne.cloud.network.monitor.SpeedAndTrafficMonitorDataImpl;
|
||||
import org.kne.cloud.network.monitor.TimestampMonitor;
|
||||
import org.kne.cloud.network.ntp.NTPContext;
|
||||
import org.kne.cloud.network.ntp.NTPv4Packet;
|
||||
import org.kne.cloud.network.ntp.NTPv4Protocol;
|
||||
import org.kne.cloud.network.ntp.NTPv4Protocol.NTPPeer;
|
||||
import org.kne.cloud.network.srv6.JsonDataPacket;
|
||||
import org.kne.cloud.network.srv6.KLALBRoutingProtocol;
|
||||
import org.kne.cloud.network.srv6.KLALBRoutingProtocolAPIClient;
|
||||
import org.kne.cloud.network.srv6.KLALBRoutingProtocolAPIServer;
|
||||
import org.kne.cloud.network.srv6.KLALBRoutingProtocolJsonData;
|
||||
import org.kne.cloud.network.srv6.PacketConsumer;
|
||||
import org.kne.cloud.network.srv6.SRv6Router;
|
||||
import org.kne.cloud.network.srv6.SRv6RouterListener;
|
||||
import org.kne.cloud.network.tcp.UDPPacket;
|
||||
import org.kne.cloud.network.tcp.UDPProtocolRegister;
|
||||
import org.kne.cloud.network.te.BandwidthDistributer;
|
||||
import org.kne.cloud.network.te.DWRRLoadingBalanceAlgorithm;
|
||||
import org.kne.concurrent.DisruptorExecutor;
|
||||
import org.kne.concurrent.HighPerformanceExecutor;
|
||||
import org.kne.io.KNEChannels;
|
||||
import org.pcap4j.packet.IpV6Packet.IpV6Header;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
public class KLALBController {
|
||||
private UUID nodeuuid=UUID.randomUUID();
|
||||
@@ -93,14 +69,14 @@ public class KLALBController {
|
||||
public HighAccuracyClock getClock() {
|
||||
return clock;
|
||||
}
|
||||
|
||||
private final long TIME_WINDOW=5000000000L;
|
||||
private SpeedAndTrafficMonitorDataImpl linkMonitor = new SpeedAndTrafficMonitorDataImpl(
|
||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "up", 100, 500000000L),
|
||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "down", 100, 500000000L));
|
||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "up", 100,TIME_WINDOW ),
|
||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "down", 100, TIME_WINDOW));
|
||||
|
||||
private SpeedAndTrafficMonitorDataImpl datatMonitor = new SpeedAndTrafficMonitorDataImpl(
|
||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "up", 100, 500000000L),
|
||||
new HashMapTimestampMonitor<UUID>(HighAccuracyClock.SYSTEM_CLOCK, "down", 100, 500000000L));
|
||||
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<>();
|
||||
|
||||
@@ -123,6 +99,17 @@ public class KLALBController {
|
||||
public List<InetAddress> getDnsAddresses() {
|
||||
return dnsAddresses;
|
||||
}
|
||||
private ScheduledExecutorService scheduleTimer=Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors(),new ThreadFactory() {
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
return ThreadTool.makeVDaemonThreadIfSupport("计时器线程", r);
|
||||
}
|
||||
});
|
||||
|
||||
public ScheduledExecutorService getScheduleTimer() {
|
||||
return scheduleTimer;
|
||||
}
|
||||
|
||||
private Timer twk = new Timer("网卡检测扫描计时器", true);
|
||||
|
||||
@@ -193,8 +180,8 @@ public class KLALBController {
|
||||
Set<MultipurposeSocketAddress> st = new HashSet<>();
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
IPv6NetworkLink link = iterator.next();
|
||||
if (link instanceof KLALBRemoteLine) {
|
||||
KLALBRemoteLine multipurposeSocketAddress = (KLALBRemoteLine) link;
|
||||
if (link instanceof KLALBRemoteLink) {
|
||||
KLALBRemoteLink multipurposeSocketAddress = (KLALBRemoteLink) link;
|
||||
if (multipurposeSocketAddress.getSocketAddress() != null)
|
||||
st.add(multipurposeSocketAddress.getSocketAddress());
|
||||
}
|
||||
@@ -206,8 +193,8 @@ public class KLALBController {
|
||||
}
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
IPv6NetworkLink link = iterator.next();
|
||||
if (link instanceof KLALBRemoteLine) {
|
||||
KLALBRemoteLine reml = (KLALBRemoteLine) link;
|
||||
if (link instanceof KLALBRemoteLink) {
|
||||
KLALBRemoteLink reml = (KLALBRemoteLink) link;
|
||||
if (reml.getSocketAddress() != null) {
|
||||
if (reml.getBindAddress() != null || reml.getRemoteVaddr() != null)
|
||||
try {
|
||||
@@ -237,6 +224,8 @@ public class KLALBController {
|
||||
|
||||
updateBroadcastNetworkInterface();
|
||||
} catch (SocketException e) {
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,21 +437,11 @@ public class KLALBController {
|
||||
return datagramSocketType;
|
||||
}
|
||||
|
||||
// private Supplier<String> selflineTableSupplier=()->{return null;};
|
||||
|
||||
/*
|
||||
* public Supplier<String> getSelflineTableSupplier() { return
|
||||
* selflineTableSupplier; }
|
||||
*
|
||||
* public void setSelflineTableSupplier(Supplier<String> selflineTableSupplier)
|
||||
* { this.selflineTableSupplier = selflineTableSupplier; }
|
||||
*/
|
||||
|
||||
public List<MultipurposeSocketAddress> getSelflineTable() {
|
||||
return selflineTable;
|
||||
}
|
||||
|
||||
// private Inet6AddressGroup self;
|
||||
|
||||
public IPv6AddressGroup getSelf() {
|
||||
return srv6Router.getLocator();
|
||||
@@ -474,30 +453,14 @@ public class KLALBController {
|
||||
return srv6Router.getLinkTabel();
|
||||
}
|
||||
|
||||
private PortBinder streamPortBinder = new PortBinder(this);
|
||||
|
||||
private PortBinder datagramPortBinder = new PortBinder(this);
|
||||
|
||||
private PortBinder rawPortBinder = new PortBinder(this);
|
||||
|
||||
protected PortBinder getStreamPortBinder() {
|
||||
return streamPortBinder;
|
||||
}
|
||||
|
||||
protected PortBinder getDatagramPortBinder() {
|
||||
return datagramPortBinder;
|
||||
}
|
||||
|
||||
protected PortBinder getRawPortBinder() {
|
||||
return rawPortBinder;
|
||||
}
|
||||
|
||||
public void reconnectImmediately() {
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
IPv6NetworkLink val = iterator.next();
|
||||
if (val instanceof KLALBRemoteLine) {
|
||||
if (val instanceof KLALBRemoteLink) {
|
||||
|
||||
KLALBRemoteLine klalbRemoteLine = (KLALBRemoteLine) val;
|
||||
KLALBRemoteLink klalbRemoteLine = (KLALBRemoteLink) val;
|
||||
klalbRemoteLine.reconnectImmediately();
|
||||
}
|
||||
}
|
||||
@@ -510,34 +473,17 @@ public class KLALBController {
|
||||
private KLALBRoutingProtocolAPIClient apiClient;
|
||||
|
||||
private KLALBControllerConfigItem configItem;
|
||||
|
||||
/*
|
||||
* private PacketReceiver prc = new PacketReceiver(); private class
|
||||
* PacketReceiver implements Consumer<KLALBPacket> {
|
||||
*
|
||||
* @Override public void accept(KLALBPacket rec) { switch (rec.getType()) { case
|
||||
* KLALBPacket.ADDLINES: ADDLINESPacket lpt = (ADDLINESPacket) rec; String s =
|
||||
* lpt.getLines(); ThreadTool.makeVDaemonThreadIfSupport("线路添加任务", () -> {
|
||||
* Scanner scn = new Scanner(s); while (scn.hasNext()) { String sn =
|
||||
* scn.nextLine(); MultipurposeSocketAddress msa = new
|
||||
* MultipurposeSocketAddress(sn); addRemoteLines(msa);
|
||||
*
|
||||
* } }).start(); break; default: break;
|
||||
*
|
||||
* } }
|
||||
*
|
||||
* }
|
||||
*/
|
||||
|
||||
public void addRemoteLines(List<MultipurposeSocketAddress> select) {
|
||||
for (MultipurposeSocketAddress target : select) {
|
||||
addRemoteLines(target);
|
||||
}
|
||||
}
|
||||
|
||||
public List<KLALBRemoteLine> addRemoteLines(MultipurposeSocketAddress target) {
|
||||
public List<KLALBRemoteLink> addRemoteLines(MultipurposeSocketAddress target) {
|
||||
lineslock.writeLock().lock();
|
||||
try {
|
||||
List<KLALBRemoteLine> added = new ArrayList<>();
|
||||
List<KLALBRemoteLink> added = new ArrayList<>();
|
||||
try {
|
||||
Enumeration<NetworkInterface> eu = NetworkInterface.getNetworkInterfaces();
|
||||
while (eu.hasMoreElements()) {
|
||||
@@ -583,7 +529,7 @@ public class KLALBController {
|
||||
count=1;
|
||||
}
|
||||
for(int i=0;i<count;i++) {
|
||||
KLALBRemoteLine line = new KLALBRemoteLine(this, target, bind);
|
||||
KLALBRemoteLink line = new KLALBRemoteLink(this, target, bind);
|
||||
addRemoteLine(line);
|
||||
added.add(line);
|
||||
}
|
||||
@@ -596,7 +542,7 @@ public class KLALBController {
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
if (!checkContainsTarget(target)) {
|
||||
KLALBRemoteLine line = new KLALBRemoteLine(this, target);
|
||||
KLALBRemoteLink line = new KLALBRemoteLink(this, target);
|
||||
addRemoteLine(line);
|
||||
added.add(line);
|
||||
}
|
||||
@@ -609,13 +555,13 @@ public class KLALBController {
|
||||
}
|
||||
}
|
||||
|
||||
public List<KLALBRemoteLine> removeRemoteLines(MultipurposeSocketAddress mpsa) {
|
||||
public List<KLALBRemoteLink> removeRemoteLines(MultipurposeSocketAddress mpsa) {
|
||||
|
||||
List<KLALBRemoteLine> rmved = new ArrayList<>();
|
||||
List<KLALBRemoteLink> rmved = new ArrayList<>();
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
IPv6NetworkLink link = iterator.next();
|
||||
if (link instanceof KLALBRemoteLine) {
|
||||
KLALBRemoteLine klalbRemoteLine = (KLALBRemoteLine) link;
|
||||
if (link instanceof KLALBRemoteLink) {
|
||||
KLALBRemoteLink klalbRemoteLine = (KLALBRemoteLink) link;
|
||||
if (mpsa.equals(klalbRemoteLine.getSocketAddress())) {
|
||||
klalbRemoteLine.close();
|
||||
rmved.add(klalbRemoteLine);
|
||||
@@ -626,11 +572,11 @@ public class KLALBController {
|
||||
}
|
||||
|
||||
public Inet6Address getRemoteVaddrBySocketAddress(MultipurposeSocketAddress target) throws SocketTimeoutException {
|
||||
KLALBRemoteLine kr = null;
|
||||
KLALBRemoteLink kr = null;
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
IPv6NetworkLink link = iterator.next();
|
||||
if (link instanceof KLALBRemoteLine) {
|
||||
KLALBRemoteLine klalbRemoteLine = (KLALBRemoteLine) link;
|
||||
if (link instanceof KLALBRemoteLink) {
|
||||
KLALBRemoteLink klalbRemoteLine = (KLALBRemoteLink) link;
|
||||
if (target.equals(klalbRemoteLine.getSocketAddress()) && klalbRemoteLine.getBindAddress() == null) {
|
||||
kr = klalbRemoteLine;
|
||||
break;
|
||||
@@ -639,7 +585,7 @@ public class KLALBController {
|
||||
}
|
||||
|
||||
if (kr == null) {
|
||||
kr = new KLALBRemoteLine(this, target);
|
||||
kr = new KLALBRemoteLink(this, target);
|
||||
addRemoteLine(kr);
|
||||
kr.waitForRemoteVaddrAvaliable(20000);
|
||||
} else {
|
||||
@@ -653,8 +599,8 @@ public class KLALBController {
|
||||
boolean b = false;
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
IPv6NetworkLink link = iterator.next();
|
||||
if (link instanceof KLALBRemoteLine) {
|
||||
KLALBRemoteLine klalbRemoteLine = (KLALBRemoteLine) link;
|
||||
if (link instanceof KLALBRemoteLink) {
|
||||
KLALBRemoteLink klalbRemoteLine = (KLALBRemoteLink) link;
|
||||
if (bind.equals2(klalbRemoteLine.getBindAddress())
|
||||
&& target.equals2(klalbRemoteLine.getSocketAddress())) {
|
||||
b = true;
|
||||
@@ -669,8 +615,8 @@ public class KLALBController {
|
||||
boolean b = false;
|
||||
for (Iterator<IPv6NetworkLink> iterator = srv6Router.getLinkTabel().iterator(); iterator.hasNext();) {
|
||||
IPv6NetworkLink link = iterator.next();
|
||||
if (link instanceof KLALBRemoteLine) {
|
||||
KLALBRemoteLine klalbRemoteLine = (KLALBRemoteLine) link;
|
||||
if (link instanceof KLALBRemoteLink) {
|
||||
KLALBRemoteLink klalbRemoteLine = (KLALBRemoteLink) link;
|
||||
if (target.equals(klalbRemoteLine.getSocketAddress())) {
|
||||
b = true;
|
||||
break;
|
||||
@@ -680,12 +626,9 @@ public class KLALBController {
|
||||
return b;
|
||||
}
|
||||
|
||||
public void addRemoteLine(KLALBRemoteLine krs) {
|
||||
public void addRemoteLine(KLALBRemoteLink krs) {
|
||||
lineslock.writeLock().lock();
|
||||
try {
|
||||
krs.setLocalVaddrSupplier(() -> {
|
||||
return getSelf();
|
||||
});
|
||||
krs.startIO();
|
||||
String selflineTable = generateSelfLineTable();
|
||||
if (selflineTable != null && !selflineTable.equals(""))
|
||||
@@ -706,63 +649,26 @@ public class KLALBController {
|
||||
return sbd.toString();
|
||||
}
|
||||
|
||||
private class UDPProtocolPacketConsumer implements PacketConsumer {
|
||||
|
||||
@Override
|
||||
public boolean accept(IPv6Packet packx) throws IOException {
|
||||
|
||||
IPv6Payload pl = packx.getPayload();
|
||||
packx.putTimePassport("unpacked");
|
||||
packx.printPassport();
|
||||
if (pl instanceof UDPPacket) {
|
||||
UDPPacket rec = (UDPPacket) pl;
|
||||
if (showpacket)
|
||||
System.out.println("UDP_RX:" + rec);
|
||||
IPv6Address srcA = packx.getSourceAddress();
|
||||
PortPacket pt = (PortPacket) rec;
|
||||
if (datagramPortBinder.distributePacketToConsumer(srcA, pt)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
// packx.dispose();
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
|
||||
private UDPProtocolRegister udpr;
|
||||
public UDPProtocolRegister getUDPregister() {
|
||||
return udpr;
|
||||
}
|
||||
|
||||
private KLTPProtocolRegister kltpr;
|
||||
public KLTPProtocolRegister getKLTPregister() {
|
||||
return kltpr;
|
||||
}
|
||||
|
||||
private class KLALBProtocolPacketConsumer implements PacketConsumer {
|
||||
|
||||
@Override
|
||||
public boolean accept(IPv6Packet packx) throws IOException {
|
||||
IPv6Payload pl = packx.getPayload();
|
||||
packx.putTimePassport("unpacked");
|
||||
packx.printPassport();
|
||||
if (pl instanceof KLALBPacket) {
|
||||
KLALBPacket rec = (KLALBPacket) pl;
|
||||
if (showpacket)
|
||||
System.out.println("KLALB_RX:" + rec);
|
||||
if (rec instanceof PortPacket) {
|
||||
rec.setCE(packx.isCE());
|
||||
IPv6Address srcA = packx.getSourceAddress();
|
||||
PortPacket pt = (PortPacket) rec;
|
||||
if (streamPortBinder.distributePacketToConsumer(srcA, pt)) {
|
||||
} else {
|
||||
if (!(pt instanceof RSTPacket)) {
|
||||
srv6Router.enqueuePacketSendTask(() -> {
|
||||
return createPacketToAddress(srcA, 0, new RSTPacket(pt.getDstPort(), pt.getSrcPort()),
|
||||
2);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
// packx.dispose();
|
||||
}
|
||||
private PortBinder rawPortBinder ;
|
||||
|
||||
protected PortBinder getRawPortBinder() {
|
||||
return rawPortBinder;
|
||||
}
|
||||
|
||||
|
||||
private void loadSRv6ProtocolStack(IPv6AddressGroup selfx, boolean enableVirtualAdapter) {
|
||||
srv6Router = new SRv6Router(selfx, clock);
|
||||
srv6Router.runKLALBRouteProtocol();
|
||||
@@ -770,11 +676,12 @@ public class KLALBController {
|
||||
routingProtocol.addReceiver((addr, packet) -> {
|
||||
|
||||
});
|
||||
|
||||
rawPortBinder= new PortBinder(this.getSelf().getAddress());
|
||||
System.out.println(" Loaded: SRv6 Stack");
|
||||
|
||||
String name=(configItem!=null)?configItem.getTUNName():CONST.KLALB_S_RV6;
|
||||
if (enableVirtualAdapter&&(name!=null)) {
|
||||
Thread t=new Thread(()->{
|
||||
try {
|
||||
IPv6TUNLoopbackNetworkLink tunlink = new IPv6TUNLoopbackNetworkLink(name,
|
||||
new IPv6AddressGroup(srv6Router.getLocator().getAddress(), 32), SRv6Router.MTU, dnsAddresses);
|
||||
@@ -787,18 +694,23 @@ public class KLALBController {
|
||||
System.err.println("挂载虚拟网卡失败,可能是无管理员权限?请尝试使用管理员权限运行软件");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}else {
|
||||
System.out.println(" Tun Adapter Disbaled");
|
||||
|
||||
}
|
||||
srv6Router.getinLoopback().getProtocolNumberRegister().put(UDPPacket.UDP_PROTOCOL_NUMBER,
|
||||
new UDPProtocolPacketConsumer());
|
||||
udpr=new UDPProtocolRegister(this);
|
||||
srv6Router.getinLoopback().getProtocolNumberRegister()[UDPPacket.UDP_PROTOCOL_NUMBER]=
|
||||
udpr;
|
||||
System.out.println(" Loaded: UDP Protocol");
|
||||
srv6Router.getinLoopback().getProtocolNumberRegister().put(KLALBPacket.KLALB_PROTOCOL_NUMBER,
|
||||
new KLALBProtocolPacketConsumer());
|
||||
System.out.println(" Loaded: KLALB Protocol");
|
||||
kltpr=new KLTPProtocolRegister(this);
|
||||
srv6Router.getinLoopback().getProtocolNumberRegister()[KLTPPacket.KLTP_PROTOCOL_NUMBER]=
|
||||
kltpr;
|
||||
System.out.println(" Loaded: KLTP Protocol");
|
||||
String iproxyname = "KLALB_" + UUID.randomUUID();
|
||||
registerToProxyTypeAs(iproxyname);
|
||||
System.out.println(" Loaded: KLALB Protocol");
|
||||
|
||||
NTPContext context = new NTPContext(clock);
|
||||
context.syncToSystem();
|
||||
@@ -812,7 +724,6 @@ public class KLALBController {
|
||||
public void onLinkChanged(SRv6Router router, IPv6NetworkLink link) {
|
||||
|
||||
List<Neighbor> nb = router.getNeighbors();
|
||||
// System.out.println("srv6 ip"+nb);
|
||||
Set<NTPPeer> sp = nvc.getPeers();
|
||||
for (Neighbor neighbor : nb) {
|
||||
if (neighbor.getLocator() != null)
|
||||
@@ -873,6 +784,17 @@ public class KLALBController {
|
||||
}
|
||||
|
||||
protected void initKLALB(boolean enableVirtualAdapter, IPv6AddressGroup selfg) {
|
||||
ThreadTool.makeVDaemonThread("线路性能采样线程", ()->{
|
||||
while(true) {
|
||||
linkMonitor.update();
|
||||
datatMonitor.update();
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
loadSRv6ProtocolStack(selfg, enableVirtualAdapter);
|
||||
loadController();
|
||||
}
|
||||
@@ -973,7 +895,7 @@ public class KLALBController {
|
||||
public void run() {
|
||||
if (srv6Router != null) {
|
||||
srv6Router.getLinkTabel().removeIf((v) -> {
|
||||
return (v instanceof KLALBRemoteLine) && ((KLALBRemoteLine) v).isClosed();
|
||||
return (v instanceof KLALBRemoteLink) && ((KLALBRemoteLink) v).isClosed();
|
||||
});
|
||||
srv6Router.updateRouteTabel();
|
||||
}
|
||||
@@ -992,13 +914,12 @@ public class KLALBController {
|
||||
}, 10, 10);
|
||||
}
|
||||
|
||||
protected IPv6Packet createPacketToAddress(IPv6Address addr, int flowlabel, IPv6Packet.IPv6Payload packet) {
|
||||
public IPv6Packet createPacketToAddress(IPv6Address addr, int flowlabel, IPv6Packet.IPv6Payload packet) {
|
||||
return createPacketToAddress(addr, flowlabel, packet, 1);
|
||||
}
|
||||
|
||||
protected IPv6Packet createPacketToAddress(IPv6Address addr, int flowlabel, IPv6Packet.IPv6Payload packet,
|
||||
public IPv6Packet createPacketToAddress(IPv6Address addr, int flowlabel, IPv6Packet.IPv6Payload packet,
|
||||
int count) {
|
||||
// HighPerformanceExecutor.defaultExecutor.execute(() -> {
|
||||
|
||||
IPv6Packet ipv = new IPv6Packet();
|
||||
|
||||
@@ -1006,23 +927,17 @@ public class KLALBController {
|
||||
System.out.println("KLALB_TX:" + packet);
|
||||
|
||||
ipv.setVersion(6);
|
||||
ipv.setTrafficClass(0);
|
||||
ipv.setTrafficClass(0b10);
|
||||
ipv.setFlowLabel(flowlabel);
|
||||
ipv.setHopLimit(255);
|
||||
ipv.setSourceAddress(getSelf().getAddress());
|
||||
ipv.setDestinationAddress(addr);
|
||||
|
||||
ipv.enableECN();
|
||||
|
||||
ipv.setPayload(packet);
|
||||
packet.setParent(ipv);
|
||||
|
||||
if (packet instanceof KLALBPacket)
|
||||
((KLALBPacket) packet).incSendCounter();
|
||||
|
||||
|
||||
packet.putTimePassport("packedInIPv6");
|
||||
packet.printPassport();
|
||||
ipv.putTimePassport("packed");
|
||||
return ipv;
|
||||
}
|
||||
|
||||
@@ -1088,19 +1003,11 @@ public class KLALBController {
|
||||
|
||||
}
|
||||
|
||||
private Timer t = new Timer("数据包重传计时器", true);
|
||||
|
||||
|
||||
protected Timer getResendTimer() {
|
||||
return t;
|
||||
}
|
||||
|
||||
private Timer t2 = new Timer("数据包粘包计时器", true);
|
||||
|
||||
private List<MultipurposeSocketAddress> listens = new CopyOnWriteArrayList<>();
|
||||
|
||||
public Timer getNagleTimer() {
|
||||
return t2;
|
||||
}
|
||||
|
||||
public void registerToProxyTypeAs(String proxyname) {
|
||||
MultipurposeSocketAddress.getSocketTypeRegister().put(proxyname + "_Stream", streamSocketType);
|
||||
@@ -1117,34 +1024,15 @@ public class KLALBController {
|
||||
private KLALBRoutingProtocol routingProtocol;
|
||||
|
||||
public List<MultipurposeSocketAddress> getNTPTable() {
|
||||
return ntptable;// nvc2.getPeers().add(new NTPPeer("{UDP}106.55.184.199:123",
|
||||
// NTPv4Packet.NTP_CLIENT));
|
||||
return ntptable;
|
||||
}
|
||||
|
||||
public KLALBControllerConfigItem getConfigItem() {
|
||||
return configItem;
|
||||
}
|
||||
|
||||
/*
|
||||
* @Override public void listen(MultipurposeSocketAddress msa) { // TODO
|
||||
* 自动生成的方法存根
|
||||
*
|
||||
* }
|
||||
*
|
||||
* @Override public void unlisten(MultipurposeSocketAddress msc) { // TODO
|
||||
* 自动生成的方法存根
|
||||
*
|
||||
* }
|
||||
*
|
||||
* @Override public void connect(MultipurposeSocketAddress msa) { // TODO
|
||||
* 自动生成的方法存根
|
||||
*
|
||||
* }
|
||||
*
|
||||
* @Override public void unconnect(MultipurposeSocketAddress msc) { // TODO
|
||||
* 自动生成的方法存根
|
||||
*
|
||||
* }
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user