forked from KNEMC/KLALB
优化代码,性能暴涨
This commit is contained in:
@@ -14,18 +14,21 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ACKTPacket extends KLALBPacket implements PortPacket {
|
||||
|
||||
private static final int HEADER_LENGTH=28;
|
||||
|
||||
public ACKTPacket(int sport,int dport,long number,boolean avaliable,int sendcount) {
|
||||
super(ACKT);
|
||||
header.putInt(sport);
|
||||
header.putInt(dport);
|
||||
header.putLong(number);
|
||||
header.put((byte) sendcount);
|
||||
header.put((byte) (avaliable?1:0));
|
||||
public ACKTPacket(int sport,int dport,long number,boolean avaliable,boolean congress,long rcvSpeed,int sendcount) {
|
||||
super(ACKT,HEADER_LENGTH);
|
||||
klalbHeader.putInt(sport);
|
||||
klalbHeader.putInt(dport);
|
||||
klalbHeader.putLong(number);
|
||||
klalbHeader.put((byte) sendcount);
|
||||
klalbHeader.put((byte) (avaliable?1:0));
|
||||
klalbHeader.put((byte) (congress?1:0));
|
||||
klalbHeader.putLong(rcvSpeed);
|
||||
}
|
||||
|
||||
public ACKTPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,28 +37,30 @@ public class ACKTPacket extends KLALBPacket implements PortPacket {
|
||||
}
|
||||
|
||||
public int getSport() {
|
||||
return header.getInt(1);
|
||||
return klalbHeader.getInt(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeaderSize() {
|
||||
return super.getHeaderSize()+18;
|
||||
public boolean isCongress() {
|
||||
return klalbHeader.get(19)!=0;
|
||||
}
|
||||
|
||||
|
||||
public int getDport() {
|
||||
return header.getInt(5);
|
||||
return klalbHeader.getInt(5);
|
||||
}
|
||||
|
||||
public long getNumber() {
|
||||
return header.getLong(9);
|
||||
return klalbHeader.getLong(9);
|
||||
}
|
||||
|
||||
public boolean isAvaliable() {
|
||||
return header.get(18)!=0;
|
||||
return klalbHeader.get(18)!=0;
|
||||
}
|
||||
|
||||
|
||||
public int getSendcount() {
|
||||
return header.getInt(17);
|
||||
return klalbHeader.getInt(17);
|
||||
}
|
||||
public long getRcvSpeed() {
|
||||
return klalbHeader.getLong(20);
|
||||
}
|
||||
}
|
||||
@@ -16,19 +16,20 @@ import java.nio.charset.Charset;
|
||||
public class ADDLINESPacket extends KLALBPacket {
|
||||
private String lines;
|
||||
|
||||
private static final int HEADER_LENGTH=3;
|
||||
|
||||
public String getLines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
public ADDLINESPacket(String lines) {
|
||||
super(ADDLINES);
|
||||
super(ADDLINES,HEADER_LENGTH);
|
||||
this.lines=lines;
|
||||
}
|
||||
|
||||
|
||||
public ADDLINESPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +43,7 @@ public class ADDLINESPacket extends KLALBPacket {
|
||||
@Override
|
||||
protected void writeToChannel(WritableByteChannel dto) throws IOException {
|
||||
byte[]bta=lines.getBytes(Charset.forName("UTF-8"));
|
||||
header.putChar(1,(char) bta.length);
|
||||
klalbHeader.putChar(1,(char) bta.length);
|
||||
super.writeToChannel(dto);
|
||||
dto.write(ByteBuffer.wrap(bta));
|
||||
}
|
||||
@@ -50,7 +51,7 @@ public class ADDLINESPacket extends KLALBPacket {
|
||||
@Override
|
||||
protected void readFromChannel(ReadableByteChannel din) throws IOException {
|
||||
super.readFromChannel(din);
|
||||
int lth=header.getChar(1);
|
||||
int lth=klalbHeader.getChar(1);
|
||||
byte[]b=new byte[lth];
|
||||
ByteBuffer wp= ByteBuffer.wrap(b);
|
||||
while(wp.hasRemaining()){
|
||||
@@ -61,14 +62,9 @@ public class ADDLINESPacket extends KLALBPacket {
|
||||
lines=new String(b, Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeaderSize() {
|
||||
return super.getHeaderSize()+2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLength() {
|
||||
return super.getLength()+2+lines.getBytes(Charset.forName("UTF-8")).length;
|
||||
return HEADER_LENGTH+lines.getBytes(Charset.forName("UTF-8")).length;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.kne.cloud.network.ipv6.Inet6AddressGroup;
|
||||
|
||||
public class ADDRPacket extends KLALBPacket {
|
||||
private static final int HEADER_LENGTH=18;
|
||||
public Inet6AddressGroup getAddr() {
|
||||
byte[]b=new byte[16];
|
||||
klalbHeader.get(1, b);
|
||||
try {
|
||||
return new Inet6AddressGroup( (Inet6Address) Inet6Address.getByAddress(b),klalbHeader.get(17)&0xff);
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ADDRPacket(Inet6AddressGroup addr) {
|
||||
super(ADDR,HEADER_LENGTH);
|
||||
klalbHeader.put(1, addr.getAddress().getAddress());
|
||||
klalbHeader.put(17,(byte) addr.getPrefixLength());
|
||||
}
|
||||
|
||||
public ADDRPacket(ByteBuffer bb) {
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ADDR "+getAddr();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class ADDRREQPacket extends KLALBPacket {
|
||||
|
||||
private static final int HEADER_LENGTH=1;
|
||||
|
||||
public ADDRREQPacket() {
|
||||
super(ADDRREQ,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
public ADDRREQPacket(ByteBuffer bb) {
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ADDRREQ";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,14 +9,14 @@ import java.nio.ByteBuffer;
|
||||
|
||||
public class BWINFPacket extends KLALBPacket {
|
||||
|
||||
|
||||
private static final int HEADER_LENGTH=17;
|
||||
|
||||
public long getUpSpeed() {
|
||||
return header.getLong(1);
|
||||
return klalbHeader.getLong(1);
|
||||
}
|
||||
|
||||
public long getDownSpeed() {
|
||||
return header.getLong(9);
|
||||
return klalbHeader.getLong(9);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -24,18 +24,13 @@ public class BWINFPacket extends KLALBPacket {
|
||||
return super.getLength()+16;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeaderSize() {
|
||||
return super.getHeaderSize()+16;
|
||||
}
|
||||
|
||||
public BWINFPacket(long upSpeed,long downSpeed) {
|
||||
super( BWINF,-1);
|
||||
header.putLong(upSpeed);
|
||||
header.putLong(downSpeed);
|
||||
super( BWINF,HEADER_LENGTH,-1);
|
||||
klalbHeader.putLong(upSpeed);
|
||||
klalbHeader.putLong(downSpeed);
|
||||
}
|
||||
public BWINFPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class ByteArrayPool {
|
||||
private ArrayBlockingQueue<byte[]>rec;
|
||||
private Queue<byte[]> rec;
|
||||
private int maxcount;
|
||||
private int length;
|
||||
public ByteArrayPool(int maxcount, int length) {
|
||||
super();
|
||||
this.maxcount = maxcount;
|
||||
this.length = length;
|
||||
rec=new ArrayBlockingQueue<byte[]>(length);
|
||||
rec=new ConcurrentLinkedQueue<byte[]>();
|
||||
}
|
||||
public void back(byte[]b) {
|
||||
if(b.length!=length)
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.kne.concurrent.SpinLock;
|
||||
import org.kne.debug.TimeDebugger;
|
||||
/*
|
||||
public class ByteBufferPool {
|
||||
private ArrayBlockingQueue<ByteBuffer>rec;
|
||||
private Queue<ByteBuffer> rec;
|
||||
private int maxcount;
|
||||
private int length;
|
||||
private boolean direct;
|
||||
@@ -14,7 +22,7 @@ public class ByteBufferPool {
|
||||
this.maxcount = maxcount;
|
||||
this.length = length;
|
||||
this.direct=direct;
|
||||
rec=new ArrayBlockingQueue<ByteBuffer>(length);
|
||||
rec=new ConcurrentLinkedQueue<ByteBuffer>();
|
||||
}
|
||||
public ByteBufferPool(int maxcount, int length) {
|
||||
this(maxcount, length, true);
|
||||
@@ -42,4 +50,64 @@ public class ByteBufferPool {
|
||||
return length;
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
public class ByteBufferPool {
|
||||
private ByteBuffer[]rec;
|
||||
private volatile int pos=0;
|
||||
private Lock lock=new SpinLock();
|
||||
|
||||
private int maxcount;
|
||||
private int length;
|
||||
private int mcj;
|
||||
private boolean direct;
|
||||
public ByteBufferPool(int maxcount, int length,boolean direct) {
|
||||
super();
|
||||
this.maxcount = maxcount;
|
||||
this.length = length;
|
||||
this.direct=direct;
|
||||
rec=new ByteBuffer[maxcount];
|
||||
mcj=rec.length-1;
|
||||
}
|
||||
public ByteBufferPool(int maxcount, int length) {
|
||||
this(maxcount, length, true);
|
||||
}
|
||||
public void back(ByteBuffer b) {
|
||||
if(b.capacity()!=length)
|
||||
throw new IllegalArgumentException("wrong length");
|
||||
b.clear();
|
||||
lock.lock();
|
||||
try {
|
||||
if(pos<mcj)
|
||||
rec[++pos]= b;
|
||||
}finally{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
public ByteBuffer borrow() {
|
||||
ByteBuffer b=null;
|
||||
lock.lock();
|
||||
try {
|
||||
if(pos>0) {
|
||||
b=rec[pos--];
|
||||
//rec[pos--]=null;
|
||||
}
|
||||
}finally{
|
||||
lock.unlock();
|
||||
}
|
||||
if(b==null) {
|
||||
if(direct)
|
||||
b=ByteBuffer.allocateDirect(length);
|
||||
else
|
||||
b=ByteBuffer.allocate(length);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
public int getMaxCount() {
|
||||
return maxcount;
|
||||
}
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
public class CONST {
|
||||
public static String klalb="KLALB";
|
||||
public static String klalbver="2.3";
|
||||
public static final String klalb="KLALB";
|
||||
public static final String klalbver="3.0";
|
||||
public static final int bversion=3;
|
||||
public static final int sversion=0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CannotAssociateException extends IOException {
|
||||
|
||||
public CannotAssociateException() {
|
||||
super();
|
||||
// TODO 自动生成的构造函数存根
|
||||
}
|
||||
|
||||
public CannotAssociateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO 自动生成的构造函数存根
|
||||
}
|
||||
|
||||
public CannotAssociateException(String message) {
|
||||
super(message);
|
||||
// TODO 自动生成的构造函数存根
|
||||
}
|
||||
|
||||
public CannotAssociateException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO 自动生成的构造函数存根
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,84 +1,76 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.Objects;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
import javax.sound.sampled.Port;
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
|
||||
public class DATATPacket extends KLALBPacket implements PortPacket{
|
||||
/*private int sport,dport;
|
||||
private long number;
|
||||
private int size;
|
||||
private int size;
|
||||
private byte[]data;
|
||||
private int sendcount;*/
|
||||
|
||||
@Override
|
||||
protected int getHeaderSize() {
|
||||
return super.getHeaderSize()+19;
|
||||
}
|
||||
private static final int HEADER_LENGTH=20;
|
||||
|
||||
@Override
|
||||
public long getLength() {
|
||||
return super.getLength()+19+data.limit();
|
||||
return HEADER_LENGTH+dataBuffer.limit();
|
||||
}
|
||||
|
||||
volatile long resendtimer=System.nanoTime();
|
||||
|
||||
private ByteBuffer data=KLALBPacket.databufferpool.borrow();
|
||||
private ByteBuffer dataBuffer;//=NetworkPacket.databufferpool_65535.borrow();
|
||||
|
||||
public DATATPacket(int sport,int dport,long number,int mtulimit) {
|
||||
super(DATAT);
|
||||
super(DATAT,HEADER_LENGTH);
|
||||
/*this.sport=sport;
|
||||
this.dport=dport;
|
||||
this.number=number;
|
||||
this.data=data;
|
||||
this.size=size;*/
|
||||
header.putInt(sport);
|
||||
header.putInt(dport);
|
||||
header.putLong(number);
|
||||
header.put((byte) 0);
|
||||
header.putChar((char) 0);
|
||||
klalbHeader.putInt(sport);
|
||||
klalbHeader.putInt(dport);
|
||||
klalbHeader.putLong(number);
|
||||
numberc=number;
|
||||
klalbHeader.put((byte) 0);
|
||||
klalbHeader.putChar((char) 0);
|
||||
|
||||
data.limit(mtulimit);
|
||||
//dataBuffer.limit(mtulimit);
|
||||
dataBuffer=ByteBuffer.allocate(mtulimit);
|
||||
}
|
||||
|
||||
public int getSendcount() {
|
||||
return header.get(17);
|
||||
return klalbHeader.get(17);
|
||||
}
|
||||
|
||||
public DATATPacket() {
|
||||
super(DATAT);
|
||||
super(DATAT,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
public DATATPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
public int getSport() {
|
||||
return header.getInt(1);
|
||||
return klalbHeader.getInt(1);
|
||||
}
|
||||
|
||||
public int getDport() {
|
||||
return header.getInt(5);
|
||||
return klalbHeader.getInt(5);
|
||||
}
|
||||
|
||||
private long numberc=Long.MIN_VALUE;
|
||||
public long getNumber() {
|
||||
return header.getLong(9);
|
||||
if(numberc!=Long.MIN_VALUE) {
|
||||
return numberc;
|
||||
}
|
||||
return (numberc= klalbHeader.getLong(9));
|
||||
}
|
||||
|
||||
public ByteBuffer getDataBuffer() {
|
||||
return data;
|
||||
return dataBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,37 +96,40 @@ public class DATATPacket extends KLALBPacket implements PortPacket{
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return data.limit();
|
||||
return dataBuffer.limit();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeToChannel(WritableByteChannel dto) throws IOException {
|
||||
header.put(17, (byte) getSendRecord().size());
|
||||
header.putChar(18, (char) data.limit());
|
||||
klalbHeader.put(17, (byte) getSendCounter());
|
||||
klalbHeader.putChar(18, (char) dataBuffer.limit());
|
||||
super.writeToChannel(dto);
|
||||
dto.write(data.slice(0, data.limit()));
|
||||
//System.out.println(dataBuffer);
|
||||
dto.write(dataBuffer.slice(0, dataBuffer.limit()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readFromChannel(ReadableByteChannel din) throws IOException {
|
||||
super.readFromChannel(din);
|
||||
data.clear();
|
||||
data.limit(header.getChar(18));
|
||||
while(data.hasRemaining()){
|
||||
if(din.read(data)==-1) {
|
||||
numberc=Long.MIN_VALUE;
|
||||
int limit=klalbHeader.getChar(18);
|
||||
//dataBuffer.clear();
|
||||
//dataBuffer.limit();
|
||||
dataBuffer=ByteBuffer.allocate(limit);
|
||||
while(dataBuffer.hasRemaining()){
|
||||
if(din.read(dataBuffer)==-1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
}
|
||||
data.flip();
|
||||
dataBuffer.flip();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
ByteBuffer datan=data;
|
||||
data=null;
|
||||
KLALBPacket.databufferpool.back(datan);
|
||||
/*ByteBuffer datan=dataBuffer;
|
||||
dataBuffer=null;
|
||||
NetworkPacket.databufferpool_65535.back(datan);*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
import org.kne.cloud.network.ipv6.IPv6Packet;
|
||||
|
||||
public class IPv6OverKLALBPacket extends KLALBPacket {
|
||||
private static final int HEADER_LENGTH=9;
|
||||
@Override
|
||||
public boolean isSomeDisposed() {
|
||||
return super.isDisposed()||ipv6Packet.isSomeDisposed();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void lockAll() {
|
||||
super.lockAll();
|
||||
ipv6Packet.lockAll();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void unlockAll() {
|
||||
ipv6Packet.unlockAll();
|
||||
super.unlockAll();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getLength() {
|
||||
return HEADER_LENGTH+ipv6Packet.getLength();
|
||||
}
|
||||
|
||||
private IPv6Packet ipv6Packet;
|
||||
|
||||
public IPv6OverKLALBPacket(IPv6Packet ipv6Packet) {
|
||||
super(IPV6OVERKLALB,HEADER_LENGTH);
|
||||
klalbHeader.putLong((int) ipv6Packet.getLength());
|
||||
this.ipv6Packet=ipv6Packet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IPv6OverKLALBPacket() {
|
||||
super(IPV6OVERKLALB,HEADER_LENGTH);
|
||||
this.ipv6Packet=new IPv6Packet();
|
||||
}
|
||||
|
||||
public IPv6OverKLALBPacket(ByteBuffer bb) {
|
||||
super(bb,HEADER_LENGTH);
|
||||
this.ipv6Packet=new IPv6Packet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeAll() {
|
||||
super.disposeAll();
|
||||
ipv6Packet.disposeAll();
|
||||
}
|
||||
|
||||
public IPv6Packet getIPv6Packet() {
|
||||
return ipv6Packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IPv6 "+ipv6Packet.getSourceAddress().getHostAddress()+"->"+ipv6Packet.getDestinationAddress().getHostAddress()+" type:"+ipv6Packet.getPayload().getProtocolNumber()+"["+getSize()+"]";
|
||||
}
|
||||
|
||||
|
||||
public long getSize() {
|
||||
return ipv6Packet.getLength();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeToChannel(WritableByteChannel dto) throws IOException {
|
||||
klalbHeader.putLong(1, ipv6Packet.getLength());
|
||||
super.writeToChannel(dto);
|
||||
ipv6Packet.writeToChannel(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readFromChannel(ReadableByteChannel din,long length) throws IOException {
|
||||
super.readFromChannel(din,length);
|
||||
ipv6Packet.readFromChannel(din, klalbHeader.getLong(1));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void doDisposeAfterSend() {
|
||||
super.doDisposeAfterSend();
|
||||
ipv6Packet.doDisposeAfterSend();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,23 +2,22 @@ package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.BindException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.time.Clock;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -29,46 +28,58 @@ import java.util.Set;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
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 java.util.function.Supplier;
|
||||
|
||||
import javax.management.openmbean.ArrayType;
|
||||
import javax.net.ServerSocketFactory;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
import org.kne.cloud.clock.AdjustedNanoClock;
|
||||
import org.kne.cloud.network.IPMulticastDiscovery;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.NetworkService;
|
||||
import org.kne.cloud.network.Proxy;
|
||||
import org.kne.cloud.network.PortPair;
|
||||
import org.kne.cloud.network.SocketType;
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
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.Inet6AddressGroup;
|
||||
import org.kne.cloud.network.monitor.MonitorData;
|
||||
import org.kne.cloud.network.monitor.SpeedAndTrafficMonitorDataImpl;
|
||||
import org.kne.debug.TimeDebugger;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
import javassist.bytecode.Bytecode;
|
||||
import javassist.bytecode.CodeAttribute;
|
||||
import javassist.bytecode.CodeIterator;
|
||||
import org.kne.cloud.network.srv6.PacketConsumer;
|
||||
import org.kne.cloud.network.srv6.SRv6Router;
|
||||
import org.kne.cloud.network.te.BandwidthDistributer;
|
||||
import org.kne.cloud.network.te.DWRRLoadingBalanceAlgorithm;
|
||||
import org.kne.concurrent.HighPerformanceExecutor;
|
||||
import org.kne.io.KNEChannels;
|
||||
import org.pcap4j.packet.IpV6Packet.IpV6Header;
|
||||
|
||||
public class KLALBController {
|
||||
|
||||
|
||||
private SpeedAndTrafficMonitorDataImpl linkMonitor=new SpeedAndTrafficMonitorDataImpl();
|
||||
|
||||
private SpeedAndTrafficMonitorDataImpl datatMonitor=new SpeedAndTrafficMonitorDataImpl();
|
||||
|
||||
private List<MultipurposeSocketAddress>selflineTable=new ArrayList<>();
|
||||
|
||||
private static final boolean showpacket = false;
|
||||
|
||||
private static final int PREFIX = 112;
|
||||
private static final int DISCOVERY_PORT=4569;
|
||||
|
||||
private static List<IPMulticastDiscovery> ipmd=new ArrayList<>();
|
||||
|
||||
private Timer twk=new Timer("网卡检测扫描计时器", true);
|
||||
{
|
||||
|
||||
@@ -76,16 +87,23 @@ public class KLALBController {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
|
||||
|
||||
|
||||
Enumeration<NetworkInterface>eu= NetworkInterface.getNetworkInterfaces();
|
||||
while (eu.hasMoreElements()) {
|
||||
NetworkInterface networkInterface = (NetworkInterface) eu.nextElement();
|
||||
if(networkInterface.getDisplayName().startsWith(IPv6TUNLoopbackNetworkLink.KLALB_DECENTRALIZED_S_RV6_NETWORK)) {
|
||||
continue;
|
||||
}
|
||||
if(networkInterface.isUp()) {
|
||||
//System.out.println(networkInterface+" "+networkInterface.isUp());
|
||||
Enumeration<InetAddress>ei= networkInterface.getInetAddresses();
|
||||
while (ei.hasMoreElements()) {
|
||||
InetAddress inetAddress = (InetAddress) ei.nextElement();
|
||||
|
||||
if(!inetAddress.isLoopbackAddress())
|
||||
for (Iterator<MultipurposeSocketAddress> iterator = listens.iterator(); iterator.hasNext();) {
|
||||
MultipurposeSocketAddress tcpl = (MultipurposeSocketAddress) iterator.next();
|
||||
|
||||
@@ -107,11 +125,15 @@ public class KLALBController {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
}
|
||||
lineslock.writeLock().lock();
|
||||
try {
|
||||
|
||||
List<MultipurposeSocketAddress>localaddress=new ArrayList<>();
|
||||
Enumeration<NetworkInterface>eu= NetworkInterface.getNetworkInterfaces();
|
||||
while (eu.hasMoreElements()) {
|
||||
@@ -169,7 +191,82 @@ public class KLALBController {
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<IPMulticastDiscovery> iterator = ipmd.iterator(); iterator.hasNext();) {
|
||||
IPMulticastDiscovery ipMulticastDiscovery = (IPMulticastDiscovery) iterator.next();
|
||||
if(ipMulticastDiscovery.isClosed()||(!ipMulticastDiscovery.getNinterface().isUp())) {
|
||||
iterator.remove();
|
||||
try {
|
||||
ipMulticastDiscovery.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("移除网卡:"+ipMulticastDiscovery.getNinterface());
|
||||
}
|
||||
}
|
||||
Enumeration<NetworkInterface>eu2= NetworkInterface.getNetworkInterfaces();
|
||||
while (eu2.hasMoreElements()) {
|
||||
NetworkInterface networkInterface = (NetworkInterface) eu2.nextElement();
|
||||
if(networkInterface.getDisplayName().startsWith(IPv6TUNLoopbackNetworkLink.KLALB_DECENTRALIZED_S_RV6_NETWORK)) {
|
||||
continue;
|
||||
}
|
||||
if(networkInterface.isUp()) {
|
||||
boolean b=true;
|
||||
for (Iterator<IPMulticastDiscovery> iterator = ipmd.iterator(); iterator.hasNext();) {
|
||||
IPMulticastDiscovery ipMulticastDiscovery = (IPMulticastDiscovery) iterator.next();
|
||||
if(networkInterface.equals(ipMulticastDiscovery.getNinterface())) {
|
||||
b=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(b) {
|
||||
/*InetAddress bidr=null;
|
||||
Enumeration<InetAddress>ei= networkInterface.getInetAddresses();
|
||||
while (ei.hasMoreElements()) {
|
||||
InetAddress inetAddress = (InetAddress) ei.nextElement();
|
||||
if(inetAddress instanceof Inet6Address) {
|
||||
Inet6Address i6=(Inet6Address) inetAddress;
|
||||
if(i6.getHostAddress().startsWith("fe80")) {
|
||||
bidr=i6;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if(bidr!=null)*/
|
||||
try {
|
||||
InetAddress bidr=InetAddress.getByName("::0");
|
||||
IPMulticastDiscovery ipd=new IPMulticastDiscovery(new InetSocketAddress(bidr,DISCOVERY_PORT), new InetSocketAddress(InetAddress.getByName("ff02::2486"),DISCOVERY_PORT), networkInterface,selflineTable);
|
||||
ipd.setCon((mpa)->{
|
||||
//System.out.println("添加本地IPv6链路:"+mpa);
|
||||
addRemoteLines(mpa);
|
||||
});
|
||||
ipd.start();
|
||||
ipmd.add(ipd);
|
||||
|
||||
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);
|
||||
ipd2.setCon((mpa)->{
|
||||
//System.out.println("添加本地IPv4链路:"+mpa);
|
||||
addRemoteLines(mpa);
|
||||
});
|
||||
ipd2.start();
|
||||
ipmd.add(ipd2);
|
||||
|
||||
System.out.println("添加网卡:"+networkInterface);
|
||||
}catch(BindException e) {
|
||||
//e.printStackTrace();
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SocketException e) {
|
||||
}finally {
|
||||
lineslock.writeLock().unlock();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -229,13 +326,13 @@ public class KLALBController {
|
||||
}
|
||||
|
||||
|
||||
private Inet6Address self;
|
||||
private Inet6AddressGroup self;
|
||||
|
||||
public Inet6Address getSelf() {
|
||||
return self;
|
||||
return self.getAddress();
|
||||
}
|
||||
private List<KLALBRemoteLine> lines=new CopyOnWriteArrayList<>();
|
||||
//private ReadWriteLock lineslock=new ReentrantReadWriteLock();
|
||||
private ReadWriteLock lineslock=new ReentrantReadWriteLock();
|
||||
|
||||
public List<KLALBRemoteLine> getLines() {
|
||||
return lines;
|
||||
@@ -256,50 +353,35 @@ public class KLALBController {
|
||||
}
|
||||
|
||||
private PacketReceiver prc=new PacketReceiver();
|
||||
private class PacketReceiver implements KLALBPacketConsumer{
|
||||
private class PacketReceiver implements Consumer<KLALBPacket>{
|
||||
|
||||
@Override
|
||||
public void accept(KLALBRemoteLine krs, KLALBPacket rec) {
|
||||
try {
|
||||
if(rec instanceof PortPacket&&krs.getRemoteVaddr()!=null) {
|
||||
PortPacket pt=(PortPacket) rec;
|
||||
if(!streamPortBinder.distributePacketToConsumer(krs, pt)) {
|
||||
if(!(pt instanceof RSTPacket))
|
||||
sendPacketToAddress(krs.getRemoteVaddr(), new RSTPacket(pt.getDport(), pt.getSport()),2);
|
||||
}
|
||||
}else {
|
||||
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);
|
||||
try {
|
||||
addRemoteLines(msa);
|
||||
} catch (SocketTimeoutException e) {
|
||||
} catch (SocketException e) {
|
||||
}
|
||||
|
||||
}
|
||||
}).start();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}).start();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public void addRemoteLines(MultipurposeSocketAddress target) throws SocketTimeoutException, SocketException {
|
||||
|
||||
|
||||
public List<KLALBRemoteLine> addRemoteLines(MultipurposeSocketAddress target) {
|
||||
List<KLALBRemoteLine>added=new ArrayList<>();
|
||||
try {
|
||||
Enumeration<NetworkInterface>eu= NetworkInterface.getNetworkInterfaces();
|
||||
while (eu.hasMoreElements()) {
|
||||
@@ -320,19 +402,35 @@ public class KLALBController {
|
||||
} catch (UnknownHostException e) {
|
||||
}
|
||||
if(!checkContainsTargetAndBind(target,bind)) {
|
||||
//System.out.println(target+" "+bind);
|
||||
addRemoteLine( new KLALBRemoteLine(target,bind));
|
||||
KLALBRemoteLine line=new KLALBRemoteLine(target,bind);
|
||||
addRemoteLine(line );
|
||||
added.add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
if(!checkContainsTarget(target))
|
||||
addRemoteLine( new KLALBRemoteLine(target));
|
||||
if(!checkContainsTarget(target)) {
|
||||
KLALBRemoteLine line= new KLALBRemoteLine(target);
|
||||
addRemoteLine(line);
|
||||
added.add(line);
|
||||
}
|
||||
//throw e;
|
||||
}
|
||||
|
||||
|
||||
return added;
|
||||
}
|
||||
public List<KLALBRemoteLine> removeRemoteLines(MultipurposeSocketAddress mpsa) {
|
||||
|
||||
List<KLALBRemoteLine>rmved=new ArrayList<>();
|
||||
for (Iterator<KLALBRemoteLine> iterator = lines.iterator(); iterator.hasNext();) {
|
||||
KLALBRemoteLine klalbRemoteLine = (KLALBRemoteLine) iterator.next();
|
||||
if(mpsa.equals( klalbRemoteLine.getSocketAddress())){
|
||||
klalbRemoteLine.close();
|
||||
rmved.add(klalbRemoteLine);
|
||||
}
|
||||
}
|
||||
return rmved;
|
||||
}
|
||||
public Inet6Address getRemoteVaddrBySocketAddress(MultipurposeSocketAddress target) throws SocketTimeoutException {
|
||||
KLALBRemoteLine kr=null;
|
||||
@@ -352,7 +450,7 @@ public class KLALBController {
|
||||
kr.reconnectImmediately();
|
||||
kr.waitForRemoteVaddrAvaliable(20000);
|
||||
}
|
||||
return kr.getRemoteVaddr();
|
||||
return kr.getRemoteVaddr().getAddress();
|
||||
}
|
||||
private boolean checkContainsTargetAndBind(MultipurposeSocketAddress target,MultipurposeSocketAddress bind) {
|
||||
boolean b=false;
|
||||
@@ -386,7 +484,12 @@ public class KLALBController {
|
||||
String selflineTable=generateSelfLineTable();
|
||||
if(selflineTable!=null&&!selflineTable.equals(""))
|
||||
krs.sendPacket(new ADDLINESPacket(selflineTable));
|
||||
lineslock.writeLock().lock();
|
||||
try {
|
||||
lines.add(krs);
|
||||
}finally {
|
||||
lineslock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -401,11 +504,77 @@ public class KLALBController {
|
||||
}
|
||||
|
||||
public KLALBController(Inet6Address self) {
|
||||
this.self = self;
|
||||
this.self =new Inet6AddressGroup(self, PREFIX);
|
||||
loadSRv6ProtocolStack();
|
||||
}
|
||||
private class KLALBProtocolPacketConsumer implements PacketConsumer{
|
||||
|
||||
@Override
|
||||
public void accept(IPv6Packet packx) throws IOException {
|
||||
HighPerformanceExecutor.defaultExecutor.execute(()->{
|
||||
|
||||
/*System.out.println("RCV:"+packx.getPayload().getData());
|
||||
byte[]b=new byte[packx.getPayload().getData().limit()];
|
||||
packx.getPayload().getData().get(0, b);
|
||||
System.out.println(Arrays.toString(b));*/
|
||||
IPv6Payload pl=packx.getPayload();
|
||||
packx.putTimePassport("unpacked");
|
||||
packx.printPassport();
|
||||
if(pl instanceof KLALBPacket) {
|
||||
KLALBPacket rec=(KLALBPacket) pl;
|
||||
//KLALBPacket rec=KLALBPacket.createByBuffer(packx.getPayload().getData());
|
||||
if(showpacket)
|
||||
System.out.println("KLALB_RX:"+rec);
|
||||
if(rec instanceof PortPacket) {
|
||||
rec.setCE(packx.isCE());
|
||||
Inet6Address srcA=packx.getSourceAddress();
|
||||
PortPacket pt=(PortPacket) rec;
|
||||
if(!streamPortBinder.distributePacketToConsumer( srcA,pt)) {
|
||||
if(!(pt instanceof RSTPacket))
|
||||
try {
|
||||
sendPacketToAddress(srcA,0, new RSTPacket(pt.getDport(), pt.getSport()),2);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
packx.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
private void loadSRv6ProtocolStack() {
|
||||
srv6Router=new SRv6Router(self);
|
||||
try {
|
||||
IPv6TUNLoopbackNetworkLink tunlink=new IPv6TUNLoopbackNetworkLink(new Inet6AddressGroup( srv6Router.getLocator().getAddress(),32),SRv6Router.MTU);
|
||||
tunlink.setMonitor(datatMonitor);
|
||||
srv6Router.getLinkTabel().add(tunlink);
|
||||
Thread.sleep(100);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
srv6Router.runKLALBRouteProtocol();
|
||||
srv6Router.getProtocolNumberRegister().put(KLALBPacket.KLALB_PROTOCOL_NUMBER,new KLALBProtocolPacketConsumer());
|
||||
System.out.println("SRv6协议栈已加载");
|
||||
}
|
||||
|
||||
public KLALBController() {
|
||||
this.self=KLALBUtils.uuidToIP(UUID.randomUUID());
|
||||
SecureRandom sc=new SecureRandom();
|
||||
byte[]v=new byte[16];
|
||||
sc.nextBytes(v);
|
||||
v[0]=(byte)0x24;
|
||||
v[1]=(byte) 0x86;
|
||||
v[2]=0;
|
||||
v[3]=1;
|
||||
v[14]=0;
|
||||
v[15]=1;
|
||||
try {
|
||||
this.self=new Inet6AddressGroup( (Inet6Address) InetAddress.getByAddress(v),PREFIX);
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
loadSRv6ProtocolStack();
|
||||
}
|
||||
|
||||
protected KLALBVirtualSocketImpl createVirtualImpl() {
|
||||
@@ -416,9 +585,16 @@ public class KLALBController {
|
||||
|
||||
|
||||
|
||||
protected void sendPacketToAddress(Inet6Address addr, KLALBPacket packet)
|
||||
protected void sendPacketToLinkAddress(Inet6Address addr, KLALBPacket packet)
|
||||
throws IOException {
|
||||
sendPacketToAddress(addr, packet, 1);
|
||||
sendPacketToLinkAddress(addr, packet, 1);
|
||||
}
|
||||
|
||||
private SRv6Router srv6Router;
|
||||
|
||||
|
||||
public SRv6Router getIpv6Router() {
|
||||
return srv6Router;
|
||||
}
|
||||
|
||||
private Timer trtr=new Timer("路由表刷新计时器", true);
|
||||
@@ -427,35 +603,55 @@ private Timer trtr=new Timer("路由表刷新计时器", true);
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Map<Inet6Address,List<KLALBRemoteLine>> lines2 =new ConcurrentHashMap<>();
|
||||
Map<Inet6Address,DWRRLoadingBalanceAlgorithm<KLALBRemoteLine>> lines2 =new ConcurrentHashMap<>();
|
||||
for (Iterator<KLALBRemoteLine> iterator = lines.iterator(); iterator.hasNext();) {
|
||||
KLALBRemoteLine klalbRemoteLine = (KLALBRemoteLine) iterator.next();
|
||||
if(klalbRemoteLine.isClosed()) {
|
||||
lineslock.writeLock().lock();
|
||||
try {
|
||||
lines.remove(klalbRemoteLine);
|
||||
}finally{
|
||||
lineslock.writeLock().unlock();
|
||||
}
|
||||
}else {
|
||||
if(klalbRemoteLine.getRemoteVaddr()!=null&&klalbRemoteLine.getMonitor().getState()==MonitorData.ONLINE) {
|
||||
if(lines2.containsKey(klalbRemoteLine.getRemoteVaddr())) {
|
||||
lines2.get(klalbRemoteLine.getRemoteVaddr()).add(klalbRemoteLine);
|
||||
lines2.get(klalbRemoteLine.getRemoteVaddr()).getEntries().add(klalbRemoteLine);
|
||||
}else {
|
||||
ArrayList<KLALBRemoteLine>al1=new ArrayList<>();
|
||||
al1.add(klalbRemoteLine);
|
||||
lines2.put(klalbRemoteLine.getRemoteVaddr(), al1);
|
||||
lines2.put(klalbRemoteLine.getRemoteVaddr().getAddress(), new DWRRLoadingBalanceAlgorithm<>(al1));
|
||||
}
|
||||
if(!srv6Router.getLinkTabel().contains(klalbRemoteLine)) {
|
||||
srv6Router.getLinkTabel().add(klalbRemoteLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Iterator<Entry<Inet6Address, List<KLALBRemoteLine>>> iterator = lines2.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<Inet6Address, List<KLALBRemoteLine>> klalbRemoteLine = (Entry<Inet6Address, List<KLALBRemoteLine>>) iterator.next();
|
||||
klalbRemoteLine.getValue().forEach((r)->{
|
||||
for (Iterator<Entry<Inet6Address, DWRRLoadingBalanceAlgorithm<KLALBRemoteLine>>> iterator = lines2.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<Inet6Address, DWRRLoadingBalanceAlgorithm<KLALBRemoteLine>> klalbRemoteLine = (Entry<Inet6Address, DWRRLoadingBalanceAlgorithm<KLALBRemoteLine>>) iterator.next();
|
||||
List<KLALBRemoteLine> lineList=klalbRemoteLine.getValue().getEntries();
|
||||
lineList.forEach((r)->{
|
||||
r.runPredict();
|
||||
});
|
||||
Collections.sort(klalbRemoteLine.getValue());
|
||||
Collections.sort(lineList);
|
||||
for (int i = 0; i < lineList.size(); i++) {
|
||||
KLALBRemoteLine krl=lineList.get(i);
|
||||
krl.noticeRank(i);
|
||||
}
|
||||
|
||||
}
|
||||
KLALBController.this.lines2=lines2;
|
||||
if(srv6Router!=null) {
|
||||
srv6Router.getLinkTabel().removeIf((v)->{
|
||||
return (v instanceof KLALBRemoteLine)&&(!v.isUp());
|
||||
});
|
||||
srv6Router.updateRouteTabel();
|
||||
}
|
||||
}
|
||||
}, 5, 5);
|
||||
}, 1, 1);
|
||||
}
|
||||
private void updateLines2(Inet6Address addr) throws SocketTimeoutException {
|
||||
/*private void updateLines2(Inet6Address addr) throws SocketTimeoutException {
|
||||
List<KLALBRemoteLine> l=new ArrayList();
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
KLALBRemoteLine klalbRemoteLine = lines.get(i);
|
||||
@@ -478,11 +674,11 @@ private Timer trtr=new Timer("路由表刷新计时器", true);
|
||||
Collections.sort(l);
|
||||
lines2.put(addr, l);
|
||||
}
|
||||
}
|
||||
private Map<Inet6Address,List<KLALBRemoteLine>> lines2 = new ConcurrentHashMap<>();
|
||||
}*/
|
||||
private Map<Inet6Address, DWRRLoadingBalanceAlgorithm<KLALBRemoteLine>> lines2 = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
protected void sendPacketToAddress(Inet6Address addr, KLALBPacket packet, int count)
|
||||
protected void sendPacketToLinkAddress(Inet6Address addr, KLALBPacket packet, int count)
|
||||
throws IOException {
|
||||
if(packet==null)
|
||||
throw new NullPointerException("packet is null!");
|
||||
@@ -491,7 +687,7 @@ private Timer trtr=new Timer("路由表刷新计时器", true);
|
||||
|
||||
//tdb.putTime("start");
|
||||
packet.genseq();
|
||||
loop:while(true) {
|
||||
/*loop:while(true) {
|
||||
if(packet.isDisposed())
|
||||
return;
|
||||
List<KLALBRemoteLine> lines2x;
|
||||
@@ -508,8 +704,9 @@ private Timer trtr=new Timer("路由表刷新计时器", true);
|
||||
KLALBRemoteLine krst =lines2x.get(i);
|
||||
if(krst.getMonitor().getState()==MonitorData.ONLINE)
|
||||
if(!packet.getSendRecord().contains(krst)) {
|
||||
if(krst.getQueue().size()<3) {
|
||||
if(krst.getQueue().size()<10) {
|
||||
packet.getSendRecord().add(krst);
|
||||
//System.out.println(krst);
|
||||
krst.sendPacket(packet);
|
||||
count0--;
|
||||
if (count0 <= 0)
|
||||
@@ -521,8 +718,9 @@ private Timer trtr=new Timer("路由表刷新计时器", true);
|
||||
KLALBRemoteLine krst =lines2x.get(i);
|
||||
if(krst.getMonitor().getState()==MonitorData.ONLINE)
|
||||
if(packet.getSendRecord().contains(krst)) {
|
||||
if(krst.getQueue().size()<3) {
|
||||
if(krst.getQueue().size()<10) {
|
||||
packet.getSendRecord().add(krst);
|
||||
//System.out.println(krst);
|
||||
krst.sendPacket(packet);
|
||||
count0--;
|
||||
if (count0 <= 0)
|
||||
@@ -532,7 +730,7 @@ private Timer trtr=new Timer("路由表刷新计时器", true);
|
||||
}
|
||||
LockSupport.parkNanos(50000);
|
||||
//tdb.putTime("sendfailed");
|
||||
}
|
||||
}*/
|
||||
//tdb.putTime("sendsuccess");
|
||||
//tdb.print();
|
||||
|
||||
@@ -545,17 +743,160 @@ private Timer trtr=new Timer("路由表刷新计时器", true);
|
||||
KLALBRemoteLine kr= lines2x.get(0);
|
||||
kr.sendPacket(packet);
|
||||
packet.getSendRecord().add(kr);*/
|
||||
|
||||
/*loop:while(true) {
|
||||
if(packet.isDisposed())
|
||||
return;
|
||||
DWRRLoadingBalanceAlgorithm<KLALBRemoteLine> dwrlines2x;
|
||||
|
||||
dwrlines2x=lines2.get(addr);
|
||||
|
||||
if (dwrlines2x == null || dwrlines2x.getEntries().isEmpty()) {
|
||||
throw new NoRouteToHostException("address unreachable: " + addr);
|
||||
}
|
||||
|
||||
List<KLALBRemoteLine>lines2x=dwrlines2x.roundEntriesList();
|
||||
|
||||
int count0 = Math.min(count, lines2x.size());
|
||||
|
||||
for (int i = 0; i < lines2x.size(); i++) {
|
||||
KLALBRemoteLine krst =lines2x.get(i);
|
||||
if(krst.getMonitor().getState()==MonitorData.ONLINE)
|
||||
if(!packet.getSendRecord().contains(krst)) {
|
||||
if(krst.getQueue().size()<5) {
|
||||
packet.getSendRecord().add(krst);
|
||||
//System.out.println(krst);
|
||||
krst.sendPacket(packet);
|
||||
count0--;
|
||||
if (count0 <= 0)
|
||||
break loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < lines2x.size(); i++) {
|
||||
KLALBRemoteLine krst =lines2x.get(i);
|
||||
if(krst.getMonitor().getState()==MonitorData.ONLINE)
|
||||
if(packet.getSendRecord().contains(krst)) {
|
||||
if(krst.getQueue().size()<5) {
|
||||
packet.getSendRecord().add(krst);
|
||||
//System.out.println(krst);
|
||||
krst.sendPacket(packet);
|
||||
count0--;
|
||||
if (count0 <= 0)
|
||||
break loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
LockSupport.parkNanos(50000);
|
||||
//tdb.putTime("sendfailed");
|
||||
}*/
|
||||
}
|
||||
/*protected void removeFromSend(Inet6Address addr,KLALBPacket klalbPacket) {
|
||||
for (Iterator iterator = lines.iterator(); iterator.hasNext();) {
|
||||
KLALBRemoteLine klalbRemoteLine = (KLALBRemoteLine) iterator.next();
|
||||
klalbRemoteLine.remoeFromSendQueue(klalbPacket);
|
||||
|
||||
|
||||
|
||||
|
||||
protected void sendPacketToAddress(Inet6Address addr,int flowlabel, KLALBPacket packet)
|
||||
throws IOException {
|
||||
sendPacketToAddress(addr,flowlabel, packet, 1);
|
||||
}
|
||||
|
||||
protected void sendPacketToAddress(Inet6Address addr, int flowlabel,KLALBPacket packet, int count)
|
||||
throws IOException {
|
||||
HighPerformanceExecutor.defaultExecutor.execute(()->{
|
||||
|
||||
IPv6Packet ipv=new IPv6Packet();
|
||||
packet.getDisposeLock().lock();
|
||||
try {
|
||||
if(packet.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
if(showpacket)
|
||||
System.out.println("KLALB_TX:"+packet);
|
||||
|
||||
ipv.setVersion(6);
|
||||
ipv.setTrafficClass(0);
|
||||
ipv.setFlowLabel(flowlabel);
|
||||
ipv.setHopLimit(255);
|
||||
ipv.setSourceAddress(self.getAddress());
|
||||
ipv.setDestinationAddress(addr);
|
||||
ipv.setPriority(packet.getPriority());
|
||||
ipv.enableECN();
|
||||
ipv.setPayload(packet);
|
||||
//System.out.println(ipv.getPayload().getProtocolNumber());
|
||||
/*System.out.println("SND:"+ipv.getPayload().getData());
|
||||
byte[]b=new byte[ipv.getPayload().getData().limit()];
|
||||
ipv.getPayload().getData().get(0, b);
|
||||
System.out.println(Arrays.toString(b));*/
|
||||
//packet.getSendRecord().add(null);
|
||||
packet.incSendCounter();
|
||||
}finally {
|
||||
packet.getDisposeLock().unlock();
|
||||
}
|
||||
packet.putTimePassport("packedInIPv6");
|
||||
packet.printPassport();
|
||||
ipv.putTimePassport("packed");
|
||||
srv6Router.putProtocolNumberPacketAndInsertSRH(ipv);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private Map<Inet6Address,BandwidthDistributer<PortPair>> bandwidthDistrmap=new ConcurrentHashMap<>();
|
||||
|
||||
private Lock bdmLock=new ReentrantLock();
|
||||
|
||||
protected Map<Inet6Address, BandwidthDistributer<PortPair>> getBandwidthDistrmap() {
|
||||
return bandwidthDistrmap;
|
||||
}
|
||||
|
||||
protected void registerDistUpdateConsumer(Inet6Address targetaAddress,PortPair portp, Consumer<Long> updateConsumer) {
|
||||
if(updateConsumer==null) {
|
||||
System.out.println("连接"+targetaAddress.getHostAddress()+" "+portp+" 释放带宽!");
|
||||
bdmLock.lock();
|
||||
try {
|
||||
BandwidthDistributer<PortPair> bdr= bandwidthDistrmap.get(targetaAddress);
|
||||
if(bdr!=null) {
|
||||
bdr.setDistrUpdateConsumer(portp, updateConsumer);
|
||||
bdr.setBandwidthRequest(portp, 0L);
|
||||
if(bdr.getDistrUpdateConsumerMap().isEmpty()) {
|
||||
bandwidthDistrmap.remove(targetaAddress);
|
||||
}
|
||||
}
|
||||
}finally {
|
||||
bdmLock.unlock();
|
||||
}
|
||||
}else {
|
||||
System.out.println("连接"+targetaAddress.getHostAddress()+" "+portp+" 申请带宽!");
|
||||
bdmLock.lock();
|
||||
try {
|
||||
BandwidthDistributer<PortPair> bdr= bandwidthDistrmap.get(targetaAddress);
|
||||
if(bdr==null) {
|
||||
bandwidthDistrmap.put(targetaAddress, bdr=new BandwidthDistributer<>(1024*20000L*1024));
|
||||
}
|
||||
|
||||
}*/
|
||||
bdr.setDistrUpdateConsumer(portp, updateConsumer);
|
||||
}finally {
|
||||
bdmLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateBandwidthRequest(Inet6Address targetaAddress,PortPair portp,long bandwidth) {
|
||||
if(bandwidth<0) {
|
||||
throw new IllegalArgumentException(bandwidth+"<0");
|
||||
}
|
||||
//System.out.println("连接"+targetaAddress.getHostAddress()+" "+portp+" 调整带宽到"+bandwidth/1024 +"KB/s!");
|
||||
BandwidthDistributer<PortPair> bdr= bandwidthDistrmap.get(targetaAddress);
|
||||
|
||||
if(bdr!=null) {
|
||||
bdr.setBandwidthRequest(portp, bandwidth);
|
||||
}else {
|
||||
throw new NullPointerException("连接"+targetaAddress.getHostAddress()+" "+portp+" 未申请带宽!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Timer t=new Timer("数据包重传计时器", true);
|
||||
public Timer getResendTimer() {
|
||||
protected Timer getResendTimer() {
|
||||
return t;
|
||||
}
|
||||
private Timer t2=new Timer("数据包粘包计时器", true);
|
||||
|
||||
@@ -20,8 +20,8 @@ public class KLALBInputStream extends DataInputStream {
|
||||
}
|
||||
int bv=readInt();
|
||||
int sv=readInt();
|
||||
if(bv!=2)
|
||||
throw new StreamCorruptedException("remote version is V"+bv+"."+sv+",not V2.0");
|
||||
if(bv!=CONST.bversion)
|
||||
throw new StreamCorruptedException("remote version is V"+bv+"."+sv+",not V"+CONST.klalbver);
|
||||
}
|
||||
public KLALBPacket readPacket() throws IOException {
|
||||
return KLALBPacket.readKLALBPacketFromStream(this);
|
||||
|
||||
@@ -2,13 +2,34 @@ package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.SocketChannelListener;
|
||||
import org.kne.cloud.network.SocketListener;
|
||||
import org.kne.cloud.network.ipv6.RouteItem;
|
||||
import org.kne.cloud.network.klalb.ui.KLALBStateGUI2;
|
||||
import org.kne.cloud.network.klalb.ui.UIEnv;
|
||||
import org.kne.cloud.network.perf.Kperf;
|
||||
import org.kne.debug.Debuger;
|
||||
|
||||
public class KLALBMain {
|
||||
public static KLALBStateGUI2 ksg;
|
||||
public static void main(String[] args) throws IOException {
|
||||
try {
|
||||
UIEnv.inituie();
|
||||
}catch(Exception e) {
|
||||
|
||||
}
|
||||
System.out.println(CONST.klalb+" V"+CONST.klalbver);
|
||||
Scanner scn=new Scanner(System.in);
|
||||
|
||||
@@ -16,31 +37,51 @@ public class KLALBMain {
|
||||
|
||||
KLALBProxySystem kpcje=new KLALBProxySystem();
|
||||
kpcje.loadConfigJson(configJson);
|
||||
MultipurposeSocketAddress mpa=new MultipurposeSocketAddress("127.9.9.9", 49573);
|
||||
System.out.println("SRv6地址:"+kpcje.getKlalbController().getSelf().getHostAddress());
|
||||
try {
|
||||
openGUI(kpcje);
|
||||
}catch(RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
/*MultipurposeSocketAddress mpa=new MultipurposeSocketAddress("127.9.9.9", 49573);
|
||||
kpcje.enableRemoteManagement(mpa);
|
||||
System.out.println("远程管理端口已在"+mpa+"端口上开启");
|
||||
System.out.println("远程管理端口已在"+mpa+"端口上开启");*/
|
||||
/*if(true)
|
||||
return;*/
|
||||
ServerSocketChannel kpsvr=KLALBVirtualServerSocketChannel.open(kpcje.getKlalbController());
|
||||
kpsvr.bind(new InetSocketAddress("::0", 4564));
|
||||
SocketChannelListener stlr=new SocketChannelListener(kpsvr);
|
||||
stlr.setCon((scl)->{
|
||||
try {
|
||||
new Kperf(new StreamChannelKLALBPacketLink(scl)).startPerfing();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
while(true) {
|
||||
String s=scn.next();
|
||||
String[]sc=s.split(" ");
|
||||
try {
|
||||
String s=scn.nextLine();
|
||||
String[]sc=s.trim().split(" ");
|
||||
switch(sc[0]) {
|
||||
case "?":
|
||||
case "help":
|
||||
System.out.println("help:查看命令使用说明");
|
||||
System.out.println("state:查看线路状态");
|
||||
//System.out.println("reload:重新加载线路配置文件");
|
||||
System.out.println("reconnect:所有离线线路跳过重连等待时间立即尝试重连");
|
||||
System.out.println("monitor:显示监视器图形界面");
|
||||
System.out.println("lines-state:查看线路状态");
|
||||
System.out.println("lines-add <地址:端口>:添加线路");
|
||||
System.out.println("lines-remove <地址:端口>:删除线路");
|
||||
System.out.println("lines-reconnect:所有离线线路立即尝试重连");
|
||||
System.out.println("route:显示路由表");
|
||||
System.out.println("kperf <地址:端口>:网络性能测试");
|
||||
System.out.println("stop:退出程序");
|
||||
|
||||
break;
|
||||
|
||||
case "monitor":
|
||||
if(ksg==null)
|
||||
ksg=kpcje.getKLALBGUI();
|
||||
ksg.setVisible(true);
|
||||
openGUI(kpcje);
|
||||
break;
|
||||
case "state":
|
||||
System.out.println("状态\t可靠性\t上传流量\t下载流量\t上传速度\t下载速度\t上传延迟\t下载延迟\t上传抖动\t下载抖动");
|
||||
case "lines-state":
|
||||
System.out.println("线路状态:");
|
||||
System.out.println("状态\t上传流量\t下载流量\t上传速度\t下载速度\t上传延迟\t下载延迟\t上传抖动\t下载抖动");
|
||||
synchronized (kpcje.getKlalbController().getLines()) {
|
||||
for (Iterator<KLALBRemoteLine> iterator = kpcje.getKlalbController().getLines().iterator(); iterator.hasNext();) {
|
||||
KLALBRemoteLine hostPort = iterator.next();
|
||||
@@ -49,17 +90,90 @@ public class KLALBMain {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "lines-add":
|
||||
if(sc.length>=2) {
|
||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress(sc[1]);
|
||||
List<KLALBRemoteLine>addl=kpcje.getKlalbController().addRemoteLines(mpsa);
|
||||
if(addl.isEmpty()) {
|
||||
System.out.println("添加失败,线路已存在!");
|
||||
}else {
|
||||
for (Iterator<KLALBRemoteLine> iterator = addl.iterator(); iterator.hasNext();) {
|
||||
KLALBRemoteLine klalbRemoteLine = (KLALBRemoteLine) iterator.next();
|
||||
|
||||
System.out.println("添加成功:"+klalbRemoteLine.getMonitor().getName());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
System.out.println("请输入要添加地址:端口!");
|
||||
}
|
||||
break;
|
||||
case "lines-remove":
|
||||
if(sc.length>=2) {
|
||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress(sc[1]);
|
||||
List<KLALBRemoteLine>rmvl=kpcje.getKlalbController().removeRemoteLines(mpsa);
|
||||
if(rmvl.isEmpty()) {
|
||||
System.out.println("未找到匹配移除项");
|
||||
}else {
|
||||
for (Iterator iterator = rmvl.iterator(); iterator.hasNext();) {
|
||||
KLALBRemoteLine klalbRemoteLine = (KLALBRemoteLine) iterator.next();
|
||||
|
||||
System.out.println("移除成功:"+klalbRemoteLine.getMonitor().getName());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
System.out.println("请输入要添加地址:端口!");
|
||||
}
|
||||
break;
|
||||
case "stop":
|
||||
System.out.println("已退出程序");
|
||||
System.exit(0);
|
||||
break;
|
||||
case "reconnect":
|
||||
case "lines-reconnect":
|
||||
System.out.println("尝试重连断开的线路");
|
||||
kpcje.getKlalbController().reconnectImmediately();
|
||||
break;
|
||||
case "route":
|
||||
List<RouteItem> lri=new ArrayList<>( kpcje.getKlalbController().getIpv6Router().getCurrentRouteTabel());
|
||||
Collections.sort(lri);
|
||||
System.out.println("路由表:");
|
||||
System.out.println("前缀\t协议\t优先级\t开销\t标志\t下一跳\t接口");
|
||||
for (Iterator<RouteItem> iterator = lri.iterator(); iterator.hasNext();) {
|
||||
RouteItem routeItem = (RouteItem) iterator.next();
|
||||
System.out.println(routeItem.getDestination()+"\t"+routeItem.getProto()+"\t"+routeItem.getPre()+"\t"+routeItem.getCost()+"\t"+routeItem.getFlag()+"\t"+routeItem.getNexthop().getHostAddress()+"\t"+routeItem.getDestlink().getName());
|
||||
}
|
||||
|
||||
break;
|
||||
case "kperf":
|
||||
if(sc.length>=2) {
|
||||
MultipurposeSocketAddress mpsa=new MultipurposeSocketAddress(sc[1]);
|
||||
Kperf kp=new Kperf(mpsa);
|
||||
kp.startPerfing();
|
||||
}else {
|
||||
System.out.println("请输入测速服务端地址:端口!");
|
||||
}
|
||||
|
||||
break;
|
||||
//case "$$SYSTEM:":
|
||||
//System.out.println();
|
||||
//break;
|
||||
default:
|
||||
System.out.println("未知命令,请输入help以查询命令说明");
|
||||
}
|
||||
}catch(RuntimeException e) {
|
||||
System.out.println("错误!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private static void openGUI(KLALBProxySystem kpcje) throws RuntimeException{
|
||||
/*JFrame jf=new JFrame();
|
||||
jf.setSize(200, 200);
|
||||
jf.setVisible(true);*/
|
||||
if(ksg==null)
|
||||
ksg=kpcje.getKLALBGUI();
|
||||
ksg.setVisible(true);
|
||||
//System.out.println("UI loaded");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ public class KLALBOutputStream extends DataOutputStream {
|
||||
super(out);
|
||||
byte[]b=new byte[] {'K','L','A','L','B'};
|
||||
write(b);
|
||||
writeInt(2);
|
||||
writeInt(1);
|
||||
writeInt(CONST.bversion);
|
||||
writeInt(CONST.sversion);
|
||||
flush();
|
||||
}
|
||||
public void writePacket(KLALBPacket klb) throws IOException {
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.Externalizable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public abstract class KLALBPacket implements Comparable<KLALBPacket>{
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
import org.kne.cloud.network.ipv6.IPv6Packet;
|
||||
|
||||
public abstract class KLALBPacket extends IPv6Packet.IPv6Payload {
|
||||
public static final int KLALB_PROTOCOL_NUMBER=254;
|
||||
|
||||
|
||||
public static final int PING=0;
|
||||
public static final int PONG=1;
|
||||
public static final int BWINF=2;
|
||||
@@ -36,139 +35,112 @@ public abstract class KLALBPacket implements Comparable<KLALBPacket>{
|
||||
public static final int TEST=11;
|
||||
public static final int VADDRACK=12;
|
||||
public static final int VADDRREQ=13;
|
||||
|
||||
public static final int IPV6OVERKLALB=14;
|
||||
public static final int ADDR=15;
|
||||
public static final int ADDRREQ=16;
|
||||
|
||||
private static final int HEADER_CAPACITY = 32;
|
||||
public static final ByteBufferPool headerbufferpool=new ByteBufferPool(1000, HEADER_CAPACITY);
|
||||
public static final ByteBufferPool databufferpool=new ByteBufferPool(1000, 65535);
|
||||
//private static final int HEADER_CAPACITY = 32;
|
||||
|
||||
private int headerLength=1;
|
||||
|
||||
//public static final ByteArrayPool dataarraypool=new ByteArrayPool(5000, 8192);
|
||||
|
||||
protected volatile ByteBuffer header;
|
||||
protected volatile ByteBuffer klalbHeader;
|
||||
|
||||
|
||||
|
||||
protected KLALBPacket(ByteBuffer header) {
|
||||
super();
|
||||
this.header = header;
|
||||
protected KLALBPacket(ByteBuffer klalbHeader,int headerLength) {
|
||||
super(KLALB_PROTOCOL_NUMBER,false);
|
||||
this.klalbHeader = klalbHeader;
|
||||
this.headerLength=headerLength;
|
||||
}
|
||||
|
||||
public KLALBPacket(int type) {
|
||||
super();
|
||||
header=headerbufferpool.borrow();
|
||||
header.put((byte) type);
|
||||
public KLALBPacket(int type,int headerLength) {
|
||||
super(KLALB_PROTOCOL_NUMBER,false);
|
||||
klalbHeader=ByteBuffer.allocate(headerLength);
|
||||
klalbHeader.put((byte) type);
|
||||
this.headerLength=headerLength;
|
||||
}
|
||||
public KLALBPacket(int type, long priority) {
|
||||
this(type);
|
||||
this.priority=priority;
|
||||
public KLALBPacket(int type,int headerLength, long priority) {
|
||||
this(type,headerLength);
|
||||
setPriority(priority);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KLALBPacket [type=" + getType() + "]";
|
||||
}
|
||||
public int getType() {
|
||||
return header.get(0)&0xff;
|
||||
return klalbHeader.get(0)&0xff;
|
||||
}
|
||||
|
||||
private long sndtime,rcvtime;
|
||||
|
||||
private long joinqueuetime;
|
||||
|
||||
|
||||
protected void writeToChannel(WritableByteChannel dto) throws IOException {
|
||||
sndtime=System.nanoTime();
|
||||
dto.write(header.slice(0, getHeaderSize()));
|
||||
public void markJoinqueuetime() {
|
||||
joinqueuetime=System.nanoTime();
|
||||
}
|
||||
|
||||
protected void readFromChannel(ReadableByteChannel din) throws IOException {
|
||||
rcvtime=System.nanoTime();
|
||||
header.limit(getHeaderSize());
|
||||
while(header.hasRemaining()){
|
||||
if(din.read(header)==-1) {
|
||||
public long getJoinqueuetime() {
|
||||
return joinqueuetime;
|
||||
}
|
||||
|
||||
protected void writeToChannel(WritableByteChannel dto) throws IOException {
|
||||
sndtime=System.nanoTime();
|
||||
dto.write(klalbHeader.slice(0, headerLength));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needEndPosition() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void readFromChannel(ReadableByteChannel din,long length) throws IOException {
|
||||
klalbHeader.limit(headerLength);
|
||||
while(klalbHeader.hasRemaining()){
|
||||
if(din.read(klalbHeader)==-1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
}
|
||||
rcvtime=System.nanoTime();
|
||||
}
|
||||
|
||||
protected int getHeaderSize() {
|
||||
return 1;
|
||||
}
|
||||
public long getSndtime() {
|
||||
return sndtime;
|
||||
}
|
||||
public long getRcvtime() {
|
||||
return rcvtime;
|
||||
}
|
||||
public long getLength() {
|
||||
return getHeaderSize();
|
||||
public long getLength() {//缓冲区limit,实际长度
|
||||
return headerLength;
|
||||
}
|
||||
|
||||
public long getPriority() {
|
||||
return priority;
|
||||
}
|
||||
public void setPriority(long priority) {
|
||||
this.priority = priority;
|
||||
}
|
||||
public long getSendseq() {
|
||||
return sendseq;
|
||||
}
|
||||
|
||||
|
||||
//private List<KLALBRemoteLine> sendRecord=new ArrayList<>(2);
|
||||
|
||||
private AtomicInteger sendCounter=new AtomicInteger(0);
|
||||
|
||||
private long priority;
|
||||
private long sendseq;
|
||||
private static final AtomicLong seqgen=new AtomicLong();
|
||||
|
||||
@Override
|
||||
public int compareTo(KLALBPacket o) {
|
||||
if(priority>o.priority) {
|
||||
return 1;
|
||||
}else if(priority<o.priority){
|
||||
return -1;
|
||||
}else {
|
||||
if(sendseq>o.sendseq) {
|
||||
return 1;
|
||||
}else if(sendseq<o.sendseq){
|
||||
return -1;
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public int getSendCounter() {
|
||||
return sendCounter.get();
|
||||
}
|
||||
|
||||
|
||||
protected void genseq() {
|
||||
this.sendseq=seqgen.getAndIncrement();
|
||||
public void incSendCounter() {
|
||||
sendCounter.incrementAndGet();
|
||||
}
|
||||
|
||||
private List<KLALBRemoteLine> sendRecord=new ArrayList<>(2);
|
||||
private volatile boolean disposed;
|
||||
private volatile ReentrantLock disposeLock=new ReentrantLock();
|
||||
public boolean isDisposed() {
|
||||
return disposed;
|
||||
}
|
||||
|
||||
public List<KLALBRemoteLine> getSendRecord() {
|
||||
/*public List<KLALBRemoteLine> getSendRecord() {
|
||||
return sendRecord;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
public ReentrantLock getDisposeLock() {
|
||||
return disposeLock;
|
||||
}
|
||||
|
||||
protected ByteBuffer getHeader() {
|
||||
return header;
|
||||
protected ByteBuffer getKLALBHeader() {
|
||||
return klalbHeader;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
disposeLock.lock();
|
||||
try {
|
||||
disposed=true;
|
||||
}finally {
|
||||
disposeLock.unlock();
|
||||
}
|
||||
ByteBuffer headerx=header;
|
||||
header=null;
|
||||
KLALBPacket.headerbufferpool.back(headerx);
|
||||
super.dispose();
|
||||
/* ByteBuffer datax=klalbHeader;
|
||||
klalbHeader=null;
|
||||
if(datax!=null)
|
||||
KLALBPacket.databufferpool_40.back(datax);*/
|
||||
}
|
||||
|
||||
public static KLALBPacket readKLALBPacketFromStream(DataInputStream in) throws IOException {
|
||||
@@ -176,7 +148,8 @@ public abstract class KLALBPacket implements Comparable<KLALBPacket>{
|
||||
}
|
||||
|
||||
public static KLALBPacket readKLALBPacketFromChannel(ReadableByteChannel in) throws IOException {
|
||||
ByteBuffer bb=headerbufferpool.borrow();
|
||||
while(true) {
|
||||
ByteBuffer bb=databufferpool_40.borrow();
|
||||
bb.limit(1);
|
||||
while(bb.hasRemaining()){
|
||||
if(in.read(bb)==-1) {
|
||||
@@ -235,8 +208,22 @@ public abstract class KLALBPacket implements Comparable<KLALBPacket>{
|
||||
klp=new VADDRREQPacket(bb);
|
||||
klp.readFromChannel(in);
|
||||
return klp;
|
||||
case IPV6OVERKLALB:
|
||||
klp=new IPv6OverKLALBPacket(bb);
|
||||
klp.readFromChannel(in);
|
||||
return klp;
|
||||
case ADDR:
|
||||
klp=new ADDRPacket(bb);
|
||||
klp.readFromChannel(in);
|
||||
return klp;
|
||||
case ADDRREQ:
|
||||
klp=new ADDRREQPacket(bb);
|
||||
klp.readFromChannel(in);
|
||||
return klp;
|
||||
}
|
||||
throw new StreamCorruptedException("unknown package type:"+type);
|
||||
//throw new StreamCorruptedException("unknown package type:"+type);
|
||||
System.err.println("ignore unknown KLALBPacket type:"+type);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeKLALBPacketToStream(DataOutputStream out,KLALBPacket klb) throws IOException {
|
||||
@@ -245,4 +232,20 @@ public abstract class KLALBPacket implements Comparable<KLALBPacket>{
|
||||
public static void writeKLALBPacketToChannel(WritableByteChannel writableByteChannel,KLALBPacket klb) throws IOException {
|
||||
klb.writeToChannel(writableByteChannel);
|
||||
}
|
||||
|
||||
public static KLALBPacket createByBuffer(ByteBuffer data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void doDisposeAfterSend() {
|
||||
if(isDisposeAfterSend())
|
||||
dispose();
|
||||
}
|
||||
private boolean ce=false;
|
||||
public void setCE(boolean ce) {
|
||||
this.ce=ce;
|
||||
}
|
||||
public boolean isCE() {
|
||||
return ce;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.net.Inet6Address;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface KLALBPacketConsumer extends BiConsumer<KLALBRemoteLine, KLALBPacket> {
|
||||
public interface KLALBPacketConsumer extends BiConsumer<Inet6Address, KLALBPacket> {
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.kne.cloud.network.klalb;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
|
||||
public interface KLALBPacketLink {
|
||||
public void writePacket(KLALBPacket kp) throws IOException;
|
||||
public void flush() throws IOException;
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
@@ -19,6 +20,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.kne.cloud.network.*;
|
||||
import org.kne.cloud.network.klalb.ui.KLALBStateGUI2;
|
||||
import org.kne.cloud.network.minecraft.MinecraftSocketBridge;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -109,6 +111,7 @@ public class KLALBProxySystem {
|
||||
switch (entry.get("Type").getAsString()) {
|
||||
case "KLALBController":
|
||||
JsonElement vase= entry.get("VirtualAddress");
|
||||
//System.out.println(vase);
|
||||
if(vase!=null) {
|
||||
try {
|
||||
klalbController=new KLALBController((Inet6Address) InetAddress.getByName(vase.getAsString()));
|
||||
@@ -141,7 +144,8 @@ public class KLALBProxySystem {
|
||||
}
|
||||
|
||||
});
|
||||
klalbController.getListenSocketAddress().add(mpsa);
|
||||
MultipurposeSocketAddress mpsa2=new MultipurposeSocketAddress(mpsa.getType(), mpsa.getHost(),((InetSocketAddress)tcpl.getServerSocketChannel().getLocalAddress()).getPort());
|
||||
klalbController.getListenSocketAddress().add(mpsa2);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
@@ -164,7 +168,8 @@ public class KLALBProxySystem {
|
||||
}
|
||||
|
||||
});
|
||||
//klalbController.getListenSocketAddress().add(mpsa);
|
||||
MultipurposeSocketAddress mpsau2=new MultipurposeSocketAddress(mpsa.getType(), mpsa.getHost(),((InetSocketAddress)(udpl.getDatagramServerSocket().getLocalSocketAddress())).getPort());
|
||||
//klalbController.getListenSocketAddress().add(mpsau2);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
@@ -181,13 +186,7 @@ public class KLALBProxySystem {
|
||||
if(linetoc!=null) {
|
||||
JsonArray jary=(JsonArray)linetoc;
|
||||
jary.forEach((aline)->{
|
||||
try {
|
||||
klalbController.addRemoteLines(new MultipurposeSocketAddress(aline.getAsString()));
|
||||
} catch (SocketTimeoutException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
klalbController.addRemoteLines(new MultipurposeSocketAddress(aline.getAsString()));
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -5,55 +5,50 @@ import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.BindException;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.channels.UnresolvedAddressException;
|
||||
import java.time.Clock;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.management.monitor.Monitor;
|
||||
|
||||
import org.kne.cloud.clock.AdjustedNanoClock;
|
||||
import org.kne.cloud.clock.ExponentialBackoffTimeClock;
|
||||
import org.kne.cloud.clock.ReliabilityBackoffTimeClock;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.SpeedLimiter;
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
import org.kne.cloud.network.ipv6.IPv6NetworkLink;
|
||||
import org.kne.cloud.network.ipv6.IPv6Packet;
|
||||
import org.kne.cloud.network.ipv6.Inet6AddressGroup;
|
||||
import org.kne.cloud.network.ipv6.Neighbor;
|
||||
import org.kne.cloud.network.monitor.MonitorData;
|
||||
import org.kne.cloud.network.monitor.QueueingMonitorDataImpl;
|
||||
import org.kne.cloud.network.monitor.SpeedAndTrafficAndDelayMonitorDataImpl;
|
||||
import org.kne.cloud.network.monitor.SpeedAndTrafficMonitorDataImpl;
|
||||
import org.kne.debug.TimeDebugger;
|
||||
import org.kne.cloud.network.te.LoadingBalanceEntry;
|
||||
|
||||
public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
public class KLALBRemoteLine implements IPv6NetworkLink,Comparable<KLALBRemoteLine> ,LoadingBalanceEntry<KLALBRemoteLine>{
|
||||
|
||||
private static final boolean debug = true;
|
||||
private static final boolean debug = false;
|
||||
|
||||
private static final boolean showpacket = false;
|
||||
|
||||
private ReliabilityBackoffTimeClock coll = new ReliabilityBackoffTimeClock();
|
||||
private volatile boolean closed = false;
|
||||
|
||||
private volatile Supplier<Inet6Address> localVaddrSupplier;
|
||||
private volatile Supplier<Inet6AddressGroup> localVaddrSupplier;
|
||||
|
||||
private volatile KLALBController klalbController;
|
||||
|
||||
@@ -64,21 +59,21 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
public void setKlalbController(KLALBController klalbController) {
|
||||
this.klalbController = klalbController;
|
||||
if (klalbController != null && remoteVaddr != null) {
|
||||
adjnc = klalbController.getAdjustedClockByVaddr(remoteVaddr);
|
||||
adjnc = klalbController.getAdjustedClockByVaddr(remoteVaddr.getAddress());
|
||||
}
|
||||
}
|
||||
|
||||
public Supplier<Inet6Address> getLocalVaddrSupplier() {
|
||||
public Supplier<Inet6AddressGroup> getLocalVaddrSupplier() {
|
||||
return localVaddrSupplier;
|
||||
}
|
||||
|
||||
public void setLocalVaddrSupplier(Supplier<Inet6Address> localVaddrSupplier) {
|
||||
public void setLocalVaddrSupplier(Supplier<Inet6AddressGroup> localVaddrSupplier) {
|
||||
this.localVaddrSupplier = localVaddrSupplier;
|
||||
}
|
||||
|
||||
private volatile Inet6Address remoteVaddr;
|
||||
private volatile Inet6AddressGroup remoteVaddr;
|
||||
|
||||
public Inet6Address getRemoteVaddr() {
|
||||
public Inet6AddressGroup getRemoteVaddr() {
|
||||
return remoteVaddr;
|
||||
}
|
||||
|
||||
@@ -98,7 +93,7 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
}
|
||||
}
|
||||
|
||||
public SpeedAndTrafficAndDelayMonitorDataImpl getMonitor() {
|
||||
public QueueingMonitorDataImpl getMonitor() {
|
||||
return monitor;
|
||||
}
|
||||
|
||||
@@ -106,7 +101,7 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
return remoteVaddr + "\t" + monitor.toString();
|
||||
}
|
||||
|
||||
private SpeedAndTrafficAndDelayMonitorDataImpl monitor;
|
||||
private QueueingMonitorDataImpl monitor;
|
||||
private volatile KLALBPacketLink kplink;
|
||||
private MultipurposeSocketAddress bindAddress;
|
||||
private MultipurposeSocketAddress socketAddress;
|
||||
@@ -129,56 +124,43 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
return bindAddress;
|
||||
}
|
||||
|
||||
protected static KLALBPacketLink createLink(MultipurposeSocketAddress bindAddress, MultipurposeSocketAddress mpa)
|
||||
throws IOException {
|
||||
if (mpa.isStream()) {
|
||||
if (mpa.supportNIO()) {
|
||||
if (bindAddress != null) {
|
||||
return new StreamChannelKLALBPacketLink(mpa
|
||||
.connectSocketChannel(InetAddress.getByName(bindAddress.getHost()), bindAddress.getPort()));
|
||||
} else {
|
||||
return new StreamChannelKLALBPacketLink(mpa.connectSocketChannel());
|
||||
}
|
||||
} else {
|
||||
if (bindAddress != null) {
|
||||
return new StreamKLALBPacketLink(
|
||||
mpa.connectSocket(InetAddress.getByName(bindAddress.getHost()), bindAddress.getPort()));
|
||||
} else {
|
||||
return new StreamKLALBPacketLink(mpa.connectSocket());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (bindAddress != null) {
|
||||
return new SplitedDatagramKLALBPacketLink(
|
||||
mpa.connectDatagramSocket(InetAddress.getByName(bindAddress.getHost()), bindAddress.getPort()));
|
||||
} else {
|
||||
return new SplitedDatagramKLALBPacketLink(mpa.connectDatagramSocket());
|
||||
}
|
||||
}
|
||||
private Inet6AddressGroup addressGroup;
|
||||
private Inet6AddressGroup peerAddress;
|
||||
@Override
|
||||
public Inet6AddressGroup getAddressGroup() {
|
||||
return addressGroup;
|
||||
}
|
||||
|
||||
public Inet6AddressGroup getPeerAddress() {
|
||||
return peerAddress;
|
||||
}
|
||||
|
||||
public KLALBRemoteLine(MultipurposeSocketAddress mpa) {
|
||||
this(mpa, new SpeedAndTrafficAndDelayMonitorDataImpl());
|
||||
|
||||
|
||||
public KLALBRemoteLine(MultipurposeSocketAddress mpa, Inet6AddressGroup address) {
|
||||
this(mpa,address, new QueueingMonitorDataImpl());
|
||||
}
|
||||
|
||||
public KLALBRemoteLine(MultipurposeSocketAddress mpa, SpeedAndTrafficAndDelayMonitorDataImpl monitor) {
|
||||
this(mpa, null, monitor);
|
||||
public KLALBRemoteLine(MultipurposeSocketAddress mpa, Inet6AddressGroup address, QueueingMonitorDataImpl monitor) {
|
||||
this(mpa, null,address, monitor);
|
||||
}
|
||||
|
||||
public KLALBRemoteLine(KLALBPacketLink kpl) {
|
||||
this(kpl, new SpeedAndTrafficAndDelayMonitorDataImpl());
|
||||
public KLALBRemoteLine(KLALBPacketLink kpl, Inet6AddressGroup address) {
|
||||
this(kpl,address, new QueueingMonitorDataImpl());
|
||||
}
|
||||
|
||||
public KLALBRemoteLine(KLALBPacketLink kpl, SpeedAndTrafficAndDelayMonitorDataImpl monitor) {
|
||||
public KLALBRemoteLine(KLALBPacketLink kpl, Inet6AddressGroup address,QueueingMonitorDataImpl monitor) {
|
||||
this.kplink = kpl;
|
||||
this.addressGroup=address;
|
||||
this.monitor = monitor;
|
||||
monitor.setName(kpl.toString());
|
||||
}
|
||||
|
||||
public KLALBRemoteLine(MultipurposeSocketAddress mpa, MultipurposeSocketAddress bindaddr,
|
||||
SpeedAndTrafficAndDelayMonitorDataImpl monitor) {
|
||||
public KLALBRemoteLine(MultipurposeSocketAddress mpa, MultipurposeSocketAddress bindaddr,Inet6AddressGroup address,
|
||||
QueueingMonitorDataImpl monitor) {
|
||||
this.socketAddress = mpa;
|
||||
this.bindAddress = bindaddr;
|
||||
this.addressGroup=address;
|
||||
this.monitor = monitor;
|
||||
if (bindaddr == null) {
|
||||
monitor.setName("→" + mpa.toString());
|
||||
@@ -187,8 +169,20 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
}
|
||||
}
|
||||
|
||||
public KLALBRemoteLine(MultipurposeSocketAddress mpa, MultipurposeSocketAddress bindaddr) {
|
||||
this(mpa, bindaddr, new SpeedAndTrafficAndDelayMonitorDataImpl());
|
||||
public KLALBRemoteLine(MultipurposeSocketAddress mpa, MultipurposeSocketAddress bindaddr, Inet6AddressGroup address) {
|
||||
this(mpa, bindaddr,address, new QueueingMonitorDataImpl());
|
||||
}
|
||||
|
||||
public KLALBRemoteLine(MultipurposeSocketAddress mpa, MultipurposeSocketAddress bind) {
|
||||
this(mpa, bind, null);
|
||||
}
|
||||
|
||||
public KLALBRemoteLine(MultipurposeSocketAddress mpa) {
|
||||
this(mpa,(Inet6AddressGroup)null);
|
||||
}
|
||||
|
||||
public KLALBRemoteLine(KLALBPacketLink link) {
|
||||
this(link, (Inet6AddressGroup)null);
|
||||
}
|
||||
|
||||
PrintStream pw;
|
||||
@@ -225,13 +219,15 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private SpeedLimiter congress = new SpeedLimiter();
|
||||
|
||||
private static long MIN_SPEED=256*1024L;
|
||||
private SpeedLimiter congress = new SpeedLimiter(MIN_SPEED,10000000L);
|
||||
private long congressSpeed = 0;
|
||||
private double increaceFactor = 1.2;
|
||||
private double loadPercent = 1.01;
|
||||
|
||||
protected void startIO() {
|
||||
ThreadTool.makeVDaemonThreadIfSupport("远程接收线程", () -> {
|
||||
//Thread.currentThread().setPriority(Thread.NORM_PRIORITY+1);
|
||||
while (true) {
|
||||
try {
|
||||
|
||||
@@ -241,13 +237,34 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
close();
|
||||
break;
|
||||
}
|
||||
if(addressGroup==null) {
|
||||
byte[]addr=new byte[16];
|
||||
SecureRandom scr=new SecureRandom();
|
||||
scr.nextBytes(addr);
|
||||
addr[0]=(byte)0x24;
|
||||
addr[1]=(byte) 0x86;
|
||||
addr[2]=0;
|
||||
addr[3]=2;
|
||||
addr[14]=0;
|
||||
addr[15]=1;
|
||||
Inet6Address i6a=(Inet6Address) Inet6Address.getByAddress(addr);
|
||||
addressGroup=new Inet6AddressGroup(i6a, 112);
|
||||
}
|
||||
} else {
|
||||
kplink = createLink(bindAddress, socketAddress);
|
||||
kplink = KLALBUtils. createKLALBPacketLink(bindAddress, socketAddress);
|
||||
}
|
||||
startRecord();
|
||||
kplink.setSoTimeout(10000);
|
||||
//startRecord();
|
||||
kplink.setSoTimeout(20000);
|
||||
Thread t = ThreadTool.makeVDaemonThreadIfSupport("远程发送线程", () -> {
|
||||
tlock = Thread.currentThread();
|
||||
//tlock.setPriority(Thread.NORM_PRIORITY+1);
|
||||
try {
|
||||
writePacketToKPL(new ADDRREQPacket());
|
||||
writePacketToKPL(new ADDRREQPacket());
|
||||
if(addressGroup!=null) {
|
||||
writePacketToKPL(new ADDRPacket(addressGroup));
|
||||
writePacketToKPL(new ADDRPacket(addressGroup));
|
||||
}
|
||||
writePacketToKPL(new VADDRREQPacket());
|
||||
writePacketToKPL(new VADDRREQPacket());
|
||||
writePacketToKPL(new VADDRPacket(localVaddrSupplier.get()));
|
||||
@@ -257,20 +274,22 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
while ((!kplink.isClosed()) && (!closed)) {
|
||||
// TimeDebugger tdb=new TimeDebugger();
|
||||
// tdb.putTime("start");
|
||||
|
||||
boolean flsh = false;
|
||||
if (checkPingTime()) {
|
||||
if(checkBandwidthReportTime()) {
|
||||
sendIPacket(new BWINFPacket(monitor.getOutSpeedAvg2(), monitor.getInSpeedAvg2()));
|
||||
}
|
||||
if (checkPingTimeSleep()) {
|
||||
writePacketToKPL(new PINGPacket(System.nanoTime()));
|
||||
if (remoteVaddr == null)
|
||||
writePacketToKPL(new VADDRREQPacket());
|
||||
monitor.updateSpeedSync();
|
||||
flsh = true;
|
||||
}
|
||||
if(peerAddress==null)
|
||||
writePacketToKPL(new ADDRREQPacket());
|
||||
|
||||
}else {
|
||||
KLALBPacket kpip = IsendDequeList.poll();
|
||||
if (kpip != null) {
|
||||
writePacketToKPL(kpip);
|
||||
flsh = true;
|
||||
}
|
||||
|
||||
}else {
|
||||
|
||||
// tdb.putTime("Isend");
|
||||
|
||||
@@ -278,32 +297,45 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
do {
|
||||
kpp = sendDequeList.poll();
|
||||
} while (kpp != null && kpp.isDisposed());
|
||||
if(kpp==null) {
|
||||
monitor.setQueueingDelay(0);
|
||||
}
|
||||
}
|
||||
// System.out.println(sendDequeList.size());
|
||||
if (kpp != null) {
|
||||
kpp.getDisposeLock().lock();
|
||||
// TimeDebugger tdb=new TimeDebugger();
|
||||
//tdb.putTime("start");
|
||||
KLALBPacket kppt=kpp;
|
||||
kppt.lockAll();
|
||||
try {
|
||||
if (kpp.isDisposed()) {
|
||||
kpp.getDisposeLock().unlock();
|
||||
if (kpp.isSomeDisposed()) {
|
||||
kpp = null;
|
||||
} else {
|
||||
if (congress.checkTransmit(kpp.getLength())) {
|
||||
|
||||
// if (congress.checkTransmit(length)) {
|
||||
|
||||
writePacketToKPL(kpp);
|
||||
if (kpp instanceof DATATPacket) {
|
||||
resetSleepTimer();
|
||||
if (checkPingTime()) {
|
||||
writePacketToKPL(new PINGPacket(System.nanoTime()));
|
||||
}
|
||||
flsh = true;
|
||||
kpp.getDisposeLock().unlock();
|
||||
monitor.setQueueingDelay( System.nanoTime()- kpp.getJoinqueuetime());
|
||||
/*if (kpp instanceof DATATPacket||kpp instanceof IPv6OverKLALBPacket) {
|
||||
resetSleepTimer();
|
||||
}*/
|
||||
kpp.doDisposeAfterSend();
|
||||
kpp = null;
|
||||
}
|
||||
}
|
||||
//}
|
||||
} finally {
|
||||
if(kpp!=null)
|
||||
kpp.getDisposeLock().unlock();
|
||||
kppt.unlockAll();
|
||||
}
|
||||
//tdb.putTime("sendToLink");
|
||||
//tdb.print();
|
||||
}else {
|
||||
LockSupport.parkNanos(1000000);
|
||||
}
|
||||
if (flsh) {
|
||||
}
|
||||
}
|
||||
/*if (flsh) {
|
||||
flushKPL();
|
||||
} else {
|
||||
|
||||
@@ -320,7 +352,7 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
}
|
||||
|
||||
// tdb.putTime("park");
|
||||
}
|
||||
}*/
|
||||
|
||||
// tdb.print();
|
||||
// System.out.println(sendDequeList.isEmpty());
|
||||
@@ -343,26 +375,26 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
while ((!kplink.isClosed()) && (!closed)) {
|
||||
long readStart = System.nanoTime();
|
||||
KLALBPacket kpp = readPacketFromKPL();
|
||||
long readTime = System.nanoTime() - readStart;
|
||||
/*long readTime = System.nanoTime() - readStart;
|
||||
readTime *= 10;
|
||||
if (readTime > stime) {
|
||||
stime = readTime;
|
||||
} else {
|
||||
stime = (stime * 99 + readTime) / 100;
|
||||
stime = (stime * 999 + readTime) / 1000;
|
||||
}
|
||||
if (stime < 2000000000L) {
|
||||
stime = 2000000000L;
|
||||
}
|
||||
}*/
|
||||
|
||||
// System.out.println(readTime);
|
||||
// kplink.setSoTimeout(5000);
|
||||
kplink.setSoTimeout(3000);
|
||||
kplink.setSoTimeout((int) (stime / 1000000));
|
||||
if (kpp == null)
|
||||
if (kpp == null) {
|
||||
break;
|
||||
}
|
||||
switch (kpp.getType()) {
|
||||
case KLALBPacket.PING:
|
||||
sendIPacket(new PONGPacket(((PINGPacket) kpp).getTime() ,kpp.getRcvtime(), System.nanoTime()));
|
||||
sendIPacket(new BWINFPacket(monitor.getOutSpeed(), monitor.getInSpeed()));
|
||||
break;
|
||||
case KLALBPacket.PONG:
|
||||
PONGPacket png = (PONGPacket) kpp;
|
||||
@@ -401,10 +433,10 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
monitor.setOutDelay(DsndDelayFactor);
|
||||
monitor.setInDelay(DrcvDelayFactor);
|
||||
monitor.setRecentPingNanoTime(png.getTimepingsnd());
|
||||
pingInterval = monitor.getOutDelayMin();
|
||||
//pingInterval = monitor.getLatencyAvg()+2000000L;
|
||||
|
||||
double load = 1 - monitor.getOutDelayMin() / (double) monitor.getOutDelay();
|
||||
increaceFactor =Math.max( 2.0 - load*2,1.0);
|
||||
//double load = 1 - monitor.getOutDelayMin() / (double) monitor.getOutDelay();
|
||||
loadPercent =Math.max( 1.2,0.4);
|
||||
}
|
||||
|
||||
LockSupport.unpark(tlock);
|
||||
@@ -416,19 +448,32 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
} else {
|
||||
congressSpeed = (congressSpeed * 999 + bwi.getDownSpeed()) / 1000;
|
||||
}
|
||||
congress.setLimitspeed((long) (congressSpeed * increaceFactor) + 32768);
|
||||
congress.setLimitspeed(Math.max(MIN_SPEED,(long) (congressSpeed * loadPercent)) );
|
||||
// System.out.println(congressSpeed);
|
||||
break;
|
||||
case KLALBPacket.ADDRREQ:
|
||||
if(addressGroup!=null)
|
||||
sendIPacket(new ADDRPacket(addressGroup));
|
||||
break;
|
||||
case KLALBPacket.ADDR:
|
||||
peerAddress = ((ADDRPacket) kpp).getAddr();
|
||||
if(addressGroup==null) {
|
||||
byte[]ab=peerAddress.getAddress().getAddress();
|
||||
ab[15]=2;
|
||||
Inet6AddressGroup ardg2=new Inet6AddressGroup((Inet6Address) InetAddress.getByAddress(ab),peerAddress.getPrefixLength());
|
||||
addressGroup=ardg2;
|
||||
}
|
||||
break;
|
||||
case KLALBPacket.VADDRREQ:
|
||||
sendIPacket(new VADDRPacket(localVaddrSupplier.get()));
|
||||
break;
|
||||
case KLALBPacket.VADDR:
|
||||
Inet6Address vdr = ((VADDRPacket) kpp).getVaddr();
|
||||
Inet6AddressGroup vdr = ((VADDRPacket) kpp).getVaddr();
|
||||
|
||||
remoteVaddr = vdr;
|
||||
sendIPacket(new VADDRACKPacket());
|
||||
if (klalbController != null) {
|
||||
adjnc = klalbController.getAdjustedClockByVaddr(remoteVaddr);
|
||||
adjnc = klalbController.getAdjustedClockByVaddr(remoteVaddr.getAddress());
|
||||
}
|
||||
if (fst) {
|
||||
// coll.resetCoolingTime();
|
||||
@@ -440,11 +485,21 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
break;
|
||||
case KLALBPacket.TEST:
|
||||
break;
|
||||
case KLALBPacket.IPV6OVERKLALB:
|
||||
if(ipv6con!=null) {
|
||||
IPv6OverKLALBPacket ivk=(IPv6OverKLALBPacket) kpp;
|
||||
IPv6Packet iv6= ivk.getIPv6Packet();
|
||||
ivk.putTimePassport("unpacked");
|
||||
ivk.printPassport();
|
||||
iv6.putTimePassport("unpackFromLink");
|
||||
ipv6con.accept(iv6);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
while (rec == null) {
|
||||
Thread.sleep(1);
|
||||
}
|
||||
rec.accept(KLALBRemoteLine.this, kpp);
|
||||
rec.accept( kpp);
|
||||
break;
|
||||
}
|
||||
Thread.yield();
|
||||
@@ -463,17 +518,17 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
KLALBPacket pack;
|
||||
/*KLALBPacket pack;
|
||||
while((pack=sendDequeList.poll())!=null) {
|
||||
try {
|
||||
if(remoteVaddr!=null) {
|
||||
klalbController.sendPacketToAddress(remoteVaddr, pack);
|
||||
klalbController.sendPacketToLinkAddress(remoteVaddr, pack);
|
||||
if(debug)
|
||||
System.out.println("RETRY:"+pack);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
if (closed) {
|
||||
@@ -499,29 +554,56 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
if (showpacket) {
|
||||
if (!(packet instanceof PINGPacket))
|
||||
if (!(packet instanceof PONGPacket))
|
||||
if (!(packet instanceof BWINFPacket))
|
||||
System.out.println("RX:" + packet);
|
||||
}
|
||||
if (packet != null) {
|
||||
monitor.getInTrafficAL().addAndGet(packet.getLength());
|
||||
packet.putTimePassport("received");
|
||||
long length=packet.getLength();
|
||||
monitor.getInTrafficAL().addAndGet(length);
|
||||
monitor.getInPacketCounterAL().incrementAndGet();
|
||||
if (klalbController != null)
|
||||
klalbController.getLinkMonitor().getInTrafficAL().addAndGet(packet.getLength());
|
||||
klalbController.getLinkMonitor().getInTrafficAL().addAndGet(length);
|
||||
klalbController.getLinkMonitor().getInPacketCounterAL().incrementAndGet();
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
private void writePacketToKPL(KLALBPacket packet) throws IOException {
|
||||
monitor.getOutTrafficAL().addAndGet(packet.getLength());
|
||||
long length=packet.getLength();
|
||||
monitor.getOutTrafficAL().addAndGet(length);
|
||||
monitor.getOutPacketCounterAL().incrementAndGet();
|
||||
if (klalbController != null)
|
||||
klalbController.getLinkMonitor().getOutTrafficAL().addAndGet(packet.getLength());
|
||||
klalbController.getLinkMonitor().getOutTrafficAL().addAndGet(length);
|
||||
klalbController.getLinkMonitor().getOutPacketCounterAL().incrementAndGet();
|
||||
kplink.writePacket(packet);
|
||||
packet.putTimePassport("sended");
|
||||
packet.printPassport();
|
||||
|
||||
if (showpacket) {
|
||||
if (!(packet instanceof PINGPacket))
|
||||
if (!(packet instanceof PONGPacket))
|
||||
if (!(packet instanceof BWINFPacket))
|
||||
System.err.println("TX:" + packet);
|
||||
}
|
||||
}
|
||||
|
||||
private void writePacketToKPL(KLALBPacket packet,long length) throws IOException {
|
||||
monitor.getOutTrafficAL().addAndGet(length);
|
||||
monitor.getOutPacketCounterAL().incrementAndGet();
|
||||
if (klalbController != null)
|
||||
klalbController.getLinkMonitor().getOutTrafficAL().addAndGet(length);
|
||||
klalbController.getLinkMonitor().getOutPacketCounterAL().incrementAndGet();
|
||||
kplink.writePacket(packet);
|
||||
|
||||
if (showpacket) {
|
||||
if (!(packet instanceof PINGPacket))
|
||||
if (!(packet instanceof PONGPacket))
|
||||
if (!(packet instanceof BWINFPacket))
|
||||
System.err.println("TX:" + packet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void close() {
|
||||
closed = true;
|
||||
monitor.setState(MonitorData.OFFLINE);
|
||||
@@ -538,28 +620,48 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
return closed;
|
||||
}
|
||||
|
||||
private volatile long timeTurnSleep = System.nanoTime();
|
||||
|
||||
private volatile long time = System.nanoTime();
|
||||
private volatile long pingInterval = 50000000L;
|
||||
private volatile long pingInterval = 10000000L;
|
||||
private volatile long pingIntervalSleep = 200000000L;
|
||||
|
||||
private void resetSleepTimer() {
|
||||
timeTurnSleep = System.nanoTime();
|
||||
}
|
||||
|
||||
private boolean checkPingTime() {
|
||||
long cu = System.nanoTime();
|
||||
if (cu - time > ((System.nanoTime() - timeTurnSleep > 500000000) ? pingIntervalSleep
|
||||
: Math.min(pingIntervalSleep, pingInterval))) {
|
||||
time = cu;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (cu - time > pingInterval) {
|
||||
time = cu;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private volatile BiConsumer<KLALBRemoteLine, KLALBPacket> rec;
|
||||
private boolean checkPingTimeSleep() {
|
||||
long cu = System.nanoTime();
|
||||
if (cu - time > pingIntervalSleep) {
|
||||
time = cu;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private volatile long bwtime = System.nanoTime();
|
||||
private volatile long bwpingInterval = 10000000L;
|
||||
private volatile long bwpingIntervalSleep = 100000000L;
|
||||
private boolean checkBandwidthReportTime(){
|
||||
long cu = System.nanoTime();
|
||||
if (cu - bwtime > bwpingIntervalSleep) {
|
||||
bwtime = cu;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private volatile Consumer<KLALBPacket> rec;
|
||||
|
||||
private volatile Thread tlock;
|
||||
|
||||
@@ -572,6 +674,7 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
}
|
||||
|
||||
protected void sendPacket(KLALBPacket blk) {
|
||||
blk.markJoinqueuetime();
|
||||
sendDequeList.add(blk);
|
||||
LockSupport.unpark(tlock);
|
||||
}
|
||||
@@ -581,7 +684,7 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
LockSupport.unpark(tlock);
|
||||
}
|
||||
|
||||
public void setPacketReceiver(BiConsumer<KLALBRemoteLine, KLALBPacket> rec) {
|
||||
public void setPacketReceiver(Consumer< KLALBPacket> rec) {
|
||||
this.rec = rec;
|
||||
}
|
||||
|
||||
@@ -641,7 +744,7 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
}
|
||||
}
|
||||
|
||||
private static final TESTPacket testPacket = new TESTPacket();
|
||||
private static final TESTPacket testPacket = new TESTPacket(60000);
|
||||
private volatile boolean pressure = false;
|
||||
private SpeedLimiter pressureSpeed = new SpeedLimiter(32768);
|
||||
|
||||
@@ -671,4 +774,111 @@ public class KLALBRemoteLine implements Comparable<KLALBRemoteLine> {
|
||||
return predictTime;
|
||||
}
|
||||
|
||||
private List<Double>ranks=new ArrayList<Double>();
|
||||
|
||||
private Consumer<IPv6Packet> ipv6con;
|
||||
@Override
|
||||
public void noticeRank(int rank) {
|
||||
while(rank>=ranks.size()) {
|
||||
ranks.add(0.5);
|
||||
}
|
||||
for (int i = 0; i < ranks.size(); i++) {
|
||||
if(i==rank) {
|
||||
ranks.set(i, (ranks.get(i)*99.0+1.0D)/100.0);
|
||||
}else {
|
||||
ranks.set(i, ranks.get(i)*99.0/100.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getWeightAtRank(int rank) {
|
||||
while(rank>=ranks.size()) {
|
||||
ranks.add(0.5);
|
||||
}
|
||||
return ranks.get(rank);
|
||||
}
|
||||
|
||||
public List<Double> getRanks() {
|
||||
|
||||
return ranks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoopBack() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Neighbor> getNeighborsInfo() {
|
||||
List<Neighbor>hs=new ArrayList<>();
|
||||
if(peerAddress!=null) {
|
||||
hs.add(new Neighbor(peerAddress, remoteVaddr, monitor));
|
||||
//System.out.println(peerAddress+" "+addressGroup);
|
||||
}
|
||||
return hs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void sendPacket(IPv6Packet pack, Inet6Address inet6Address) throws IOException {
|
||||
pack.lockAll();
|
||||
try {
|
||||
if(pack.isSomeDisposed()) {
|
||||
return;
|
||||
}
|
||||
if(inet6Address.equals(remoteVaddr.getAddress())||inet6Address.equals(peerAddress.getAddress())) {
|
||||
IPv6OverKLALBPacket kipv6=new IPv6OverKLALBPacket(pack);
|
||||
kipv6.setPriority(pack.getPriority());
|
||||
kipv6.setDisposeAfterSend(true);
|
||||
pack.putTimePassport("packdInLink");
|
||||
pack.printPassport();
|
||||
sendPacketToLink(kipv6);
|
||||
}
|
||||
}finally {
|
||||
pack.unlockAll();
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacketToLink(KLALBPacket packet) {
|
||||
packet.genseq();
|
||||
//packet.getSendRecord().add(this);
|
||||
sendPacket(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCongress(IPv6Packet iPv6Packet) {
|
||||
int size=getQueue().size();
|
||||
if(size>30) {
|
||||
return true;
|
||||
}else {
|
||||
return !congress.checkTransmit(iPv6Packet.getLength());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return monitor.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUp() {
|
||||
return (!isClosed())&&getMonitor().getState()==MonitorData.ONLINE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSend(IPv6Packet iPv6Packet) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReceiveConsumer(Consumer<IPv6Packet> ipv6con) {
|
||||
this.ipv6con=ipv6con;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class KLALBRemoteManagement {
|
||||
jklbrl.addProperty("ipport", klalbRemoteLine.getSocketAddress().toString());
|
||||
jklbrl.addProperty("state",MonitorData.parseStateToString( klalbRemoteLine.getMonitor().getState()));
|
||||
|
||||
jklbrl.addProperty("Vaddr", klalbRemoteLine.getRemoteVaddr().getHostAddress());
|
||||
jklbrl.addProperty("Vaddr", klalbRemoteLine.getRemoteVaddr().getAddress().getHostAddress());
|
||||
|
||||
jklbrl.addProperty("uploadspeed", klalbRemoteLine.getMonitor().getOutSpeed());
|
||||
jklbrl.addProperty("downloadspeed", klalbRemoteLine.getMonitor().getInSpeed());
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
|
||||
public class KLALBUtils {
|
||||
public static Inet6Address uuidToIP(UUID uuid) {
|
||||
@@ -34,15 +39,15 @@ public class KLALBUtils {
|
||||
}
|
||||
public static String bytesUnit(long v) {
|
||||
if (v >= 1024L * 1024 * 1024 * 1024 * 1024) {
|
||||
return String.format("%.1f", v / (1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0)) + "PB";
|
||||
return String.format("%.2f", v / (1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0)) + "PB";
|
||||
} else if (v >= 1024L * 1024 * 1024 * 1024) {
|
||||
return String.format("%.1f", v / (1024.0 * 1024.0 * 1024.0 * 1024.0)) + "TB";
|
||||
return String.format("%.2f", v / (1024.0 * 1024.0 * 1024.0 * 1024.0)) + "TB";
|
||||
} else if (v >= 1024L * 1024 * 1024) {
|
||||
return String.format("%.1f", v / (1024.0 * 1024.0 * 1024.0)) + "GB";
|
||||
return String.format("%.2f", v / (1024.0 * 1024.0 * 1024.0)) + "GB";
|
||||
} else if (v >= 1024L * 1024) {
|
||||
return String.format("%.1f", v / (1024.0 * 1024.0)) + "MB";
|
||||
return String.format("%.2f", v / (1024.0 * 1024.0)) + "MB";
|
||||
} else if (v >= 1024L) {
|
||||
return String.format("%.1f", v / (1024.0)) + "KB";
|
||||
return String.format("%.2f", v / (1024.0)) + "KB";
|
||||
} else {
|
||||
return v + "B";
|
||||
}
|
||||
@@ -62,6 +67,24 @@ public class KLALBUtils {
|
||||
return v+"B";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String defaultUnit(long v) {
|
||||
if(v>=1024L*1024*1024*1024*1024) {
|
||||
return format( v/(1024.0*1024.0*1024.0*1024.0*1024.0))+"P";
|
||||
}else if(v>=1024L*1024*1024*1024) {
|
||||
return format (v/(1024.0*1024.0*1024.0*1024.0))+"T";
|
||||
}else if(v>=1024L*1024*1024) {
|
||||
return format( v/(1024.0*1024.0*1024.0))+"G";
|
||||
}else if(v>=1024L*1024) {
|
||||
return format( v/(1024.0*1024.0))+"M";
|
||||
}else if(v>=1024L) {
|
||||
return format( v/(1024.0))+"K";
|
||||
}else {
|
||||
return Long.toString(v) ;
|
||||
}
|
||||
}
|
||||
|
||||
private static String format( double d) {
|
||||
String fmt=String.format( "%.2f",d);
|
||||
if(fmt.length()>4) {
|
||||
@@ -92,4 +115,82 @@ public class KLALBUtils {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public static Color getColorByLoadPercentage(float f) {
|
||||
int r=0;
|
||||
int g=255;
|
||||
if(f<50f) {
|
||||
r+=f/50f*255f;
|
||||
}else {
|
||||
r=255;
|
||||
g-=(f-50f)/50f*255f;
|
||||
}
|
||||
if(r>255)
|
||||
r=255;
|
||||
if(r<0)
|
||||
r=0;
|
||||
if(g>255)
|
||||
g=255;
|
||||
if(g<0)
|
||||
g=0;
|
||||
Color col=new Color( r,g,0);
|
||||
return col;
|
||||
}
|
||||
|
||||
public static KLALBPacketLink createKLALBPacketLink(MultipurposeSocketAddress bindAddress, MultipurposeSocketAddress targetAddress)
|
||||
throws IOException {
|
||||
if (targetAddress.isStream()) {
|
||||
if (targetAddress.supportNIO()) {
|
||||
if (bindAddress != null) {
|
||||
return new StreamChannelKLALBPacketLink(targetAddress
|
||||
.connectSocketChannel(InetAddress.getByName(bindAddress.getHost()), bindAddress.getPort()));
|
||||
} else {
|
||||
return new StreamChannelKLALBPacketLink(targetAddress.connectSocketChannel());
|
||||
}
|
||||
} else {
|
||||
if (bindAddress != null) {
|
||||
return new StreamKLALBPacketLink(
|
||||
targetAddress.connectSocket(InetAddress.getByName(bindAddress.getHost()), bindAddress.getPort()));
|
||||
} else {
|
||||
return new StreamKLALBPacketLink(targetAddress.connectSocket());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (bindAddress != null) {
|
||||
return new SplitedDatagramKLALBPacketLink(
|
||||
targetAddress.connectDatagramSocket(InetAddress.getByName(bindAddress.getHost()), bindAddress.getPort()));
|
||||
} else {
|
||||
return new SplitedDatagramKLALBPacketLink(targetAddress.connectDatagramSocket());
|
||||
}
|
||||
}
|
||||
}
|
||||
public static KLALBPacketLink createKLALBPacketLink(MultipurposeSocketAddress bindAddress,
|
||||
MultipurposeSocketAddress targetAddress, int timeout) throws UnknownHostException, IOException {
|
||||
if (targetAddress.isStream()) {
|
||||
if (targetAddress.supportNIO()) {
|
||||
if (bindAddress != null) {
|
||||
return new StreamChannelKLALBPacketLink(targetAddress
|
||||
.connectSocketChannel(InetAddress.getByName(bindAddress.getHost()), bindAddress.getPort(),timeout));
|
||||
} else {
|
||||
return new StreamChannelKLALBPacketLink(targetAddress.connectSocketChannel(timeout));
|
||||
}
|
||||
} else {
|
||||
if (bindAddress != null) {
|
||||
return new StreamKLALBPacketLink(
|
||||
targetAddress.connectSocket(InetAddress.getByName(bindAddress.getHost()), bindAddress.getPort(),timeout));
|
||||
} else {
|
||||
return new StreamKLALBPacketLink(targetAddress.connectSocket(timeout));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (bindAddress != null) {
|
||||
return new SplitedDatagramKLALBPacketLink(
|
||||
targetAddress.connectDatagramSocket(InetAddress.getByName(bindAddress.getHost()), bindAddress.getPort()));
|
||||
} else {
|
||||
return new SplitedDatagramKLALBPacketLink(targetAddress.connectDatagramSocket());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -34,10 +34,12 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
@@ -54,10 +56,12 @@ import java.util.zip.Inflater;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
import org.kne.acclerate.FastLib;
|
||||
import org.kne.cloud.network.PortPair;
|
||||
import org.kne.cloud.network.SpeedLimiter;
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
import org.kne.cloud.network.VirtualSocketImpl;
|
||||
import org.kne.cloud.network.monitor.SpeedAndTrafficAndDelayMonitorDataImpl;
|
||||
import org.kne.concurrent.SpinLock;
|
||||
import org.kne.debug.TimeDebugger;
|
||||
import org.kne.io.Data;
|
||||
|
||||
@@ -82,6 +86,8 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
|
||||
private SpeedAndTrafficAndDelayMonitorDataImpl socketMonitor=new SpeedAndTrafficAndDelayMonitorDataImpl();
|
||||
|
||||
private SpeedAndTrafficAndDelayMonitorDataImpl socketRawMonitor=new SpeedAndTrafficAndDelayMonitorDataImpl();
|
||||
|
||||
private KLALBController controller;
|
||||
|
||||
protected int getInputchachesize() {
|
||||
@@ -100,16 +106,29 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
this.outputchachesize = outputchachesize;
|
||||
}
|
||||
|
||||
//private Speed
|
||||
//60000 30 30
|
||||
private static final int MTU=8192;
|
||||
|
||||
private volatile int inputchachesize = MTU * 2000;
|
||||
private volatile int outputchachesize = MTU * 50;
|
||||
private volatile int reallimit = MTU * 40;
|
||||
//private SpeedLimiter spdlmt=new SpeedLimiter(1024*1024);
|
||||
//4000 100 100
|
||||
//10000 500 500
|
||||
private volatile int inputchachesize = MTU * 4000;
|
||||
private volatile int outputchachesize = MTU * 240;//500
|
||||
private volatile int reallimit = MTU * 240;
|
||||
|
||||
private final long MIN_RTTVAR=50000000L;
|
||||
private final long MIN_LIMIT_SPEED=64*1024L;
|
||||
private volatile long rcvSpeed=MIN_LIMIT_SPEED;
|
||||
private volatile long requestSpeed=MIN_LIMIT_SPEED;
|
||||
private SpeedLimiter spdlmt=new SpeedLimiter(MIN_LIMIT_SPEED,1000000L);
|
||||
private volatile long congressSpeed=0;
|
||||
private volatile double congressFactor=2;
|
||||
|
||||
//private double[] congressFactors=new double[] {0.95,0.95,0.95,1.2,0.8};
|
||||
//private int congressFactorsState=0;
|
||||
//private volatile double maxutilization=0.8;
|
||||
|
||||
private volatile boolean nodelay=false;
|
||||
private volatile long delaytime=1;
|
||||
private volatile boolean nodelay=true;
|
||||
private volatile long delaytime=2;
|
||||
|
||||
public long getDelaytime() {
|
||||
return delaytime;
|
||||
@@ -131,9 +150,13 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
private ReentrantLock backlogQueuelock=new ReentrantLock();
|
||||
|
||||
private volatile Thread sendDequeLock;
|
||||
private Queue<DATATPacket> sendDeque = new ArrayBlockingQueue<DATATPacket>(20000);
|
||||
private Queue<DATATPacket> recvQueue = new ConcurrentLinkedQueue<DATATPacket>();
|
||||
private AtomicInteger recvQueueUsed=new AtomicInteger(0);
|
||||
//private AtomicInteger recvCounter=new AtomicInteger(0);
|
||||
|
||||
|
||||
private Map<Long,DATATPacket> sendmap=new ConcurrentHashMap();
|
||||
private AtomicInteger sendmapWindowUsed=new AtomicInteger(0);
|
||||
//private ReentrantReadWriteLock sendmaplock=new ReentrantReadWriteLock();
|
||||
|
||||
private volatile Thread sendthread;
|
||||
@@ -142,27 +165,29 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
private class SendCheckTask extends TimerTask{
|
||||
|
||||
public void run() {
|
||||
/*sendmaplock.writeLock().lock();
|
||||
try {*/
|
||||
|
||||
|
||||
|
||||
try {
|
||||
Collection<DATATPacket> cdp=sendmap.values();
|
||||
for (Iterator iterator = cdp.iterator(); iterator.hasNext();) {
|
||||
DATATPacket dtp = (DATATPacket) iterator.next();
|
||||
try {
|
||||
long x=System.nanoTime();
|
||||
long dt=x-dtp.resendtimer;
|
||||
long limit= (long) (Math.pow(2, dtp.getSendRecord().size()-1)*(RTTMin*20+100000L));
|
||||
long limit= (long) (Math.pow(2, dtp.getSendCounter()-1)*(RTO));
|
||||
if(dt>limit) {
|
||||
if(dtp.getSendRecord().size()>=10) {
|
||||
if(dtp.getSendCounter()>=10) {
|
||||
throw new IOException("send error!");
|
||||
}
|
||||
/*if(reallimit>LIMIT*2) {
|
||||
reallimit=reallimit-4096;
|
||||
System.out.println(reallimit+" -4096");
|
||||
}*/
|
||||
/*if(spdlmt.getLimitspeed()>LIMIT*2)
|
||||
spdlmt.setLimitspeed(spdlmt.getLimitspeed()-4096);*/
|
||||
|
||||
if(dtp.isDisposed())
|
||||
continue;
|
||||
dtp.setPriority(4);
|
||||
controller.sendPacketToAddress((Inet6Address) remoteaddr,dtp,1);
|
||||
long length= dtp.getLength();
|
||||
socketRawMonitor.getOutTrafficAL().addAndGet(length);
|
||||
spdlmt.forceTransmit(length);
|
||||
controller.sendPacketToAddress((Inet6Address) remoteaddr,0,dtp,1);
|
||||
//System.out.println("第"+(dtp.getSendRecord().size()-1)+"次重传:"+dtp+" "+dt+">"+limit);
|
||||
dtp.resendtimer=x;
|
||||
|
||||
@@ -178,10 +203,11 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
}
|
||||
}
|
||||
|
||||
/*}finally {
|
||||
sendmaplock.writeLock().unlock();
|
||||
}*/
|
||||
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(portp!=null)
|
||||
updateBandwidthReq(requestSpeed);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -191,11 +217,12 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(sendDeque.isEmpty()) {
|
||||
try {if(getLocalPort()!=0&&getPort()!=0)
|
||||
if(recvQueue.isEmpty()) {
|
||||
try {
|
||||
if(getLocalPort()!=0&&getPort()!=0)
|
||||
if(remoteaddr instanceof Inet6Address&&(!remoteaddr.isAnyLocalAddress()))
|
||||
controller.sendPacketToAddress((Inet6Address) remoteaddr, new ACKTPacket(getLocalPort(),getPort(), -1,
|
||||
true,0));
|
||||
controller.sendPacketToAddress((Inet6Address) remoteaddr,0, new ACKTPacket(getLocalPort(),getPort(), -1,
|
||||
true,false,socketMonitor.getInSpeedMax(),0));
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
close0(true);
|
||||
@@ -215,15 +242,23 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
return backlogQueue != null;
|
||||
}
|
||||
|
||||
//private int inputcross = 0;
|
||||
private List<Object> inputchache = new ArrayList<>();
|
||||
private ReentrantLock inputchachelock=new ReentrantLock();
|
||||
//private List<Object> inputchache = new RangeArrayList<>();
|
||||
private Map<Long,DATATPacket> inputchache=new ConcurrentHashMap();
|
||||
private Lock inputchachelock=new SpinLock();
|
||||
|
||||
private long inputcount = 0;
|
||||
private volatile boolean avaliable = true;
|
||||
|
||||
private AtomicBoolean firstUpdate=new AtomicBoolean(true);
|
||||
private volatile long RTTMin=1000000000L;
|
||||
private volatile long RTTVar=1000000000L;
|
||||
private volatile long RTTAvg=1000000000L;
|
||||
private volatile long RTO=1000000000L;
|
||||
|
||||
private volatile long QueueingAvg=1000000000L;
|
||||
|
||||
private volatile long RunningSpeed=spdlmt.getLimitspeed();
|
||||
|
||||
private long RTTMin=1000000000L;
|
||||
private volatile boolean ignoreBindCheck;
|
||||
private boolean connected;
|
||||
|
||||
@@ -307,7 +342,9 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
protected void connect(InetAddress address, int port) throws IOException {
|
||||
connect(new InetSocketAddress(address, port), 10000);
|
||||
}
|
||||
|
||||
|
||||
private PortPair portp;
|
||||
|
||||
@Override
|
||||
protected void connect(SocketAddress address, int timeout) throws IOException {
|
||||
if(!ignoreBindCheck)
|
||||
@@ -317,13 +354,14 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
port = ((InetSocketAddress) address).getPort();
|
||||
this.address=this.remoteaddr = (Inet6Address) ((InetSocketAddress) address).getAddress();
|
||||
|
||||
|
||||
if(connected)
|
||||
throw new SocketException("already connected");
|
||||
controller.getStreamPortBinder().connect(this);
|
||||
|
||||
connectionPending=true;
|
||||
|
||||
controller.getResendTimer().schedule(sendCheckTask, 50, 50);
|
||||
controller.getResendTimer().schedule(sendCheckTask, 10, 10);
|
||||
//controller.sendPacketToAddress((Inet6Address) this.remoteaddr, new SYNTPacket(localport, port), 0,1);
|
||||
try {
|
||||
getKVSIOutputStream().write(compress);
|
||||
@@ -345,6 +383,16 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
}
|
||||
|
||||
connected=true;
|
||||
|
||||
PortPair portpx=new PortPair(localport, port);
|
||||
controller.registerDistUpdateConsumer(remoteaddr, portpx, (c)->{
|
||||
//System.out.println(c);
|
||||
spdlmt.setLimitspeed(Math.max(MIN_LIMIT_SPEED,c));
|
||||
});
|
||||
updateBandwidthReq(requestSpeed);
|
||||
|
||||
this.portp=portpx;
|
||||
|
||||
}catch(SocketTimeoutException e) {
|
||||
throw new SocketTimeoutException("connect time out");
|
||||
}catch(NoRouteToHostException e) {
|
||||
@@ -357,6 +405,11 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
|
||||
controller.getResendTimer().schedule(flowControlTask, 5000, 5000);
|
||||
}
|
||||
private void updateBandwidthReq(long requestSpeed) {
|
||||
if(remoteaddr!=null&&portp!=null)
|
||||
controller.updateBandwidthRequest(remoteaddr, portp,requestSpeed );
|
||||
}
|
||||
|
||||
public boolean isConnectionPending() {
|
||||
return connectionPending;
|
||||
}
|
||||
@@ -424,7 +477,7 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
kvsi.remoteaddr=(Inet6Address) isa.getAddress();
|
||||
|
||||
kvsi.bind(localaddr, localport,true);
|
||||
kvsi.accept((KLALBRemoteLine)p[1],(KLALBPacket) p[2]);
|
||||
kvsi.accept((Inet6Address)p[1],(KLALBPacket) p[2]);
|
||||
kvsi.connect(isa, 5000);
|
||||
/*kvsi.port = isa.getPort();
|
||||
kvsi.localport = localport;
|
||||
@@ -463,26 +516,30 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
while (true) {
|
||||
if (isClosed())
|
||||
throw new SocketException("Socket is closed");
|
||||
DATATPacket dtp2 = sendDeque.poll();
|
||||
DATATPacket dtp2 = recvQueue.poll();
|
||||
if (dtp2 != null) {
|
||||
recvQueueUsed.addAndGet(-dtp2.getSize());
|
||||
//System.out.println("PULL:"+dtp2);
|
||||
dataPack = dtp2;
|
||||
socketMonitor.getInTrafficAL().addAndGet(dtp2.getSize());
|
||||
socketMonitor.getInPacketCounterAL().incrementAndGet();
|
||||
controller.getDatatMonitor().getInTrafficAL().addAndGet(dtp2.getSize());
|
||||
checkFlowControl(dtp2);
|
||||
controller.getDatatMonitor().getInPacketCounterAL().incrementAndGet();
|
||||
//checkFlowControl(dtp2);
|
||||
break;
|
||||
}
|
||||
sendDequeLock=Thread.currentThread();
|
||||
LockSupport.parkNanos(1000000);
|
||||
}
|
||||
//System.out.println("sorted:"+dataPack);
|
||||
return dataPack;
|
||||
}
|
||||
private void checkFlowControl(DATATPacket dtp2) throws IOException {
|
||||
if(sendDeque.size() >= inputchachesize/MTU-4) {
|
||||
controller.sendPacketToAddress(remoteaddr, new ACKTPacket(dtp2.getDport(), dtp2.getSport(), dtp2.getNumber(),
|
||||
/*private void checkFlowControl(DATATPacket dtp2) throws IOException {
|
||||
if(recvQueue.size() >= inputchachesize/MTU-4) {
|
||||
controller.sendPacketToAddress(remoteaddr,0,KLALB_PROTOCOL_NUMBER, new ACKTPacket(dtp2.getDport(), dtp2.getSport(), dtp2.getNumber(),
|
||||
true,dtp2.getSendcount()));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
@Override
|
||||
@@ -501,6 +558,8 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
dst.limit(dst.position()+len);
|
||||
dst.put( dataPack.getDataBuffer().get()) ;
|
||||
if(!dataPack.getDataBuffer().hasRemaining()) {
|
||||
dataPack.putTimePassport("unpacked");
|
||||
dataPack.printPassport();
|
||||
dataPack.dispose();
|
||||
dataPack=null;
|
||||
}
|
||||
@@ -523,6 +582,8 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
i+=min;
|
||||
//b[off + i]= dtp.getData()[count++] ;
|
||||
if(!dataPack.getDataBuffer().hasRemaining()) {
|
||||
dataPack.putTimePassport("unpacked");
|
||||
dataPack.printPassport();
|
||||
dataPack.dispose();
|
||||
dataPack=null;
|
||||
}
|
||||
@@ -558,6 +619,8 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
len = Math.min(len, available());
|
||||
b[off]= dataPack.getDataBuffer().get() ;
|
||||
if(!dataPack.getDataBuffer().hasRemaining()) {
|
||||
dataPack.putTimePassport("unpacked");
|
||||
dataPack.printPassport();
|
||||
dataPack.dispose();
|
||||
dataPack=null;
|
||||
}
|
||||
@@ -578,6 +641,8 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
i+=min;
|
||||
//b[off + i]= dtp.getData()[count++] ;
|
||||
if(!dataPack.getDataBuffer().hasRemaining()) {
|
||||
dataPack.putTimePassport("unpacked");
|
||||
dataPack.printPassport();
|
||||
dataPack.dispose();
|
||||
dataPack=null;
|
||||
}
|
||||
@@ -601,13 +666,13 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
}
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
AtomicInteger i = new AtomicInteger(0);
|
||||
sendDeque.forEach((V) -> {
|
||||
i.addAndGet(V.getSize());
|
||||
});
|
||||
int i = recvQueueUsed.get();
|
||||
/*for(DATATPacket V:recvQueue) {
|
||||
i+=(V.getSize());
|
||||
}*/
|
||||
if (dataPack != null)
|
||||
i.addAndGet(dataPack.getDataBuffer().remaining());
|
||||
return i.get();
|
||||
i+=dataPack.getDataBuffer().remaining();
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -629,7 +694,6 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
this.compress = compress;
|
||||
}
|
||||
|
||||
private static final int MTU=60000;
|
||||
protected class KVSIOutputStream extends OutputStream implements WritableByteChannel{
|
||||
DATATPacket dataPack=new DATATPacket(localport, port, outputcount++,MTU);
|
||||
|
||||
@@ -730,7 +794,7 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
throw new SocketException("Socket is closed");
|
||||
if(sendmap.isEmpty())
|
||||
break;
|
||||
if(timeout!=0&&(System.nanoTime()-start>timeout*1000000))
|
||||
if(timeout!=0&&(System.nanoTime()-start>timeout*1000000L))
|
||||
throw new SocketTimeoutException("wait for acknowledged timout");
|
||||
sendthread=Thread.currentThread();
|
||||
LockSupport.parkNanos(1000000L);
|
||||
@@ -794,6 +858,7 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
}
|
||||
//TimeDebugger td=new TimeDebugger();
|
||||
//td.putTime("start");
|
||||
dataPack.putTimePassport("packed");
|
||||
while (!avaliable) {
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
@@ -801,35 +866,46 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
dataPack.putTimePassport("waitForAvaliable");
|
||||
//td.putTime("waitForAvaliable");
|
||||
while(true){
|
||||
if (isClosed())
|
||||
throw new SocketException("Socket is closed");
|
||||
//System.out.println(sendmap.size());
|
||||
boolean b=sendmap.size()<=reallimit/MTU;
|
||||
boolean b=sendmapWindowUsed.get()<=reallimit;
|
||||
//boolean b=sendmap.size()<=reallimit/MTU;
|
||||
if(b)
|
||||
break;
|
||||
sendthread=Thread.currentThread();
|
||||
LockSupport.parkNanos(1000000L);
|
||||
}
|
||||
dataPack.putTimePassport("waitForWindow");
|
||||
//td.putTime("waitForCache");
|
||||
DATATPacket pack=dataPack;
|
||||
dataPack=new DATATPacket(localport, port, outputcount++,MTU);
|
||||
dataPack.putTimePassport("buildHeader");
|
||||
pack.getDataBuffer().flip();
|
||||
//System.out.println(pack.getDataBuffer());
|
||||
//cacheCreateTime=System.nanoTime();
|
||||
//td.putTime("flushBuffer");
|
||||
//spdlmt.transmit(count);
|
||||
spdlmt.transmit(pack.getDataBuffer().limit());
|
||||
socketMonitor.getOutTrafficAL().addAndGet(pack.getDataBuffer().limit());
|
||||
socketMonitor.getOutPacketCounterAL().incrementAndGet();
|
||||
controller.getDatatMonitor().getOutTrafficAL().addAndGet(pack.getDataBuffer().limit());
|
||||
controller.getDatatMonitor().getOutPacketCounterAL().incrementAndGet();
|
||||
//td.putTime("doStatistic");
|
||||
pack.setPriority(5);
|
||||
pack.resendtimer=System.nanoTime();
|
||||
controller.sendPacketToAddress(remoteaddr,pack);
|
||||
socketRawMonitor.getOutTrafficAL().addAndGet(pack.getLength());
|
||||
controller.sendPacketToAddress(remoteaddr,0,pack);
|
||||
//td.putTime("doSend");
|
||||
/* sendmaplock.readLock().lock();
|
||||
try{*/
|
||||
pack.resendtimer=System.nanoTime();
|
||||
sendmap.put(pack.getNumber(),pack);
|
||||
DATATPacket prv= sendmap.put(pack.getNumber(),pack);
|
||||
sendmapWindowUsed.addAndGet(pack.getSize());
|
||||
if(prv!=null)
|
||||
sendmapWindowUsed.addAndGet(-prv.getSize());
|
||||
//System.out.println("PUSH:"+pack);
|
||||
/*}finally {
|
||||
sendmaplock.readLock().unlock();
|
||||
@@ -849,20 +925,24 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
}
|
||||
private void close0() throws IOException {
|
||||
//outputclosed=true;
|
||||
if(isClosed())
|
||||
return;
|
||||
olock.lock();
|
||||
try {
|
||||
flush0();
|
||||
}finally {
|
||||
olock.unlock();
|
||||
}
|
||||
|
||||
DATATPacket pack=new DATATPacket(localport, port, outputcount++,MTU);
|
||||
pack.setPriority(5);
|
||||
pack.getDataBuffer(). flip();
|
||||
controller.sendPacketToAddress(remoteaddr,pack);
|
||||
controller.sendPacketToAddress(remoteaddr,0,pack);
|
||||
/*sendmaplock.readLock().lock();
|
||||
try{*/
|
||||
pack.resendtimer=System.nanoTime();
|
||||
sendmap.put(pack.getNumber(),pack);
|
||||
sendmapWindowUsed.addAndGet(pack.getSize());
|
||||
/*}finally {
|
||||
sendmaplock.readLock().unlock();
|
||||
}*/
|
||||
@@ -958,6 +1038,7 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
private void close0(boolean b) throws IOException {
|
||||
if ( !isClosed()) {
|
||||
closed = true;
|
||||
|
||||
if(!isListening() ) {
|
||||
sendCheckTask.cancel();
|
||||
flowControlTask.cancel();
|
||||
@@ -965,11 +1046,17 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
if(remoteaddr!=null)
|
||||
try {
|
||||
|
||||
controller.sendPacketToAddress(remoteaddr, new RSTPacket(super.localport, super.port),
|
||||
controller.sendPacketToAddress(remoteaddr,0, new RSTPacket(super.localport, super.port),
|
||||
2);
|
||||
} catch (NoRouteToHostException e) {
|
||||
}
|
||||
controller.getStreamPortBinder().disconnect(this);
|
||||
if(portp!=null) {
|
||||
PortPair portpx=portp;
|
||||
portp=null;
|
||||
controller.updateBandwidthRequest(remoteaddr, portpx, 0L);
|
||||
controller.registerDistUpdateConsumer(remoteaddr, portpx, null);
|
||||
}
|
||||
}else {
|
||||
//System.out.println("unlisten"+getLocalPort());
|
||||
controller.getStreamPortBinder().unlisten(this);
|
||||
@@ -1001,18 +1088,22 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
InputStream is=getInputStream();
|
||||
OutputStream os=getOutputStream();
|
||||
if((!(is instanceof KVSIInputStream))||(!(os instanceof KVSIOutputStream))) {
|
||||
throw new SocketException("cant use association because compress is enabled");
|
||||
throw new CannotAssociateException("cant use association because compress is enabled");
|
||||
}
|
||||
KVSIInputStream kis=(KVSIInputStream) is;
|
||||
KVSIOutputStream kos=(KVSIOutputStream) os;
|
||||
Thread t1=ThreadTool.makeVThreadIfSupport("本地发送线程", ()->{
|
||||
boolean onError=false;
|
||||
try {
|
||||
DATATPacket dp;
|
||||
while((dp=kis.nextPacket()).getSize()!=0) {
|
||||
b.write(dp.getDataBuffer());
|
||||
dp.putTimePassport("unpacked");
|
||||
dp.printPassport();
|
||||
dp.dispose();
|
||||
}
|
||||
}catch(IOException e) {
|
||||
onError=true;
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
@@ -1025,23 +1116,68 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(true) {
|
||||
try {
|
||||
b.close();
|
||||
} catch (IOException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
close();
|
||||
} catch (IOException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Thread t2=ThreadTool.makeVThreadIfSupport("本地接收线程", ()->{
|
||||
boolean onError=false;
|
||||
try {
|
||||
ByteBuffer tst=ByteBuffer.allocateDirect(MTU);
|
||||
while(true) {
|
||||
if(b.read(kos.dataPack.getDataBuffer())==-1) {
|
||||
if(nodelay) {
|
||||
if(b.read(kos.dataPack.getDataBuffer())==-1) {
|
||||
break;
|
||||
}
|
||||
kos.flush0();
|
||||
}else {
|
||||
if(b.read(tst)==-1) {
|
||||
break;
|
||||
}
|
||||
tst.flip();
|
||||
|
||||
kos.olock.lock();
|
||||
try {
|
||||
kos.flush0();
|
||||
kos.dataPack.getDataBuffer().put(tst);
|
||||
/*if(b.read(kos.dataPack.getDataBuffer())==-1) {
|
||||
break;
|
||||
}*/
|
||||
}finally {
|
||||
kos.olock.unlock();
|
||||
|
||||
}
|
||||
if(kos.dataPack.getDataBuffer().hasRemaining()) {
|
||||
kos.olock.lock();
|
||||
try {
|
||||
kos.flush();
|
||||
}finally {
|
||||
kos.olock.unlock();
|
||||
}
|
||||
}else {
|
||||
kos.olock.lock();
|
||||
try {
|
||||
kos.flush0();
|
||||
}finally {
|
||||
kos.olock.unlock();
|
||||
}
|
||||
}
|
||||
tst.clear();
|
||||
}
|
||||
}
|
||||
}catch(IOException e) {
|
||||
onError=true;
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
@@ -1054,6 +1190,20 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(true) {
|
||||
try {
|
||||
b.close();
|
||||
} catch (IOException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
close();
|
||||
} catch (IOException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
t1.start();
|
||||
@@ -1064,6 +1214,7 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
b.close();
|
||||
close();
|
||||
}
|
||||
|
||||
@@ -1077,18 +1228,22 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
InputStream is=getInputStream();
|
||||
OutputStream os=getOutputStream();
|
||||
if((!(is instanceof KVSIInputStream))||(!(os instanceof KVSIOutputStream))) {
|
||||
throw new SocketException("cant use association because compress is enabled");
|
||||
throw new CannotAssociateException("cant use association because compress is enabled");
|
||||
}
|
||||
KVSIInputStream kis=(KVSIInputStream) is;
|
||||
KVSIOutputStream kos=(KVSIOutputStream) os;
|
||||
Thread t1=ThreadTool.makeVThreadIfSupport("本地发送线程", ()->{
|
||||
boolean onError=false;
|
||||
try {
|
||||
DATATPacket dp;
|
||||
while((dp=kis.nextPacket()).getSize()!=0) {
|
||||
orc.write(dp.getDataBuffer());
|
||||
dp.putTimePassport("unpacked");
|
||||
dp.printPassport();
|
||||
dp.dispose();
|
||||
}
|
||||
}catch(IOException e) {
|
||||
onError=true;
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
@@ -1101,23 +1256,68 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(true) {
|
||||
try {
|
||||
associateSocket.close();
|
||||
} catch (IOException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
close();
|
||||
} catch (IOException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Thread t2=ThreadTool.makeVThreadIfSupport("本地接收线程", ()->{
|
||||
boolean onError=false;
|
||||
try {
|
||||
ByteBuffer tst=ByteBuffer.allocateDirect(MTU);
|
||||
while(true) {
|
||||
if(irc.read(kos.dataPack.getDataBuffer())==-1) {
|
||||
break;
|
||||
}
|
||||
if(nodelay) {
|
||||
if(irc.read(kos.dataPack.getDataBuffer())==-1) {
|
||||
break;
|
||||
}
|
||||
kos.flush0();
|
||||
}else {
|
||||
if(irc.read(tst)==-1) {
|
||||
break;
|
||||
}
|
||||
tst.flip();
|
||||
|
||||
kos.olock.lock();
|
||||
try {
|
||||
kos.dataPack.getDataBuffer().put(tst);
|
||||
/*if(irc.read(kos.dataPack.getDataBuffer())==-1) {
|
||||
break;
|
||||
}*/
|
||||
}finally {
|
||||
kos.olock.unlock();
|
||||
|
||||
}
|
||||
if(kos.dataPack.getDataBuffer().hasRemaining()) {
|
||||
kos.olock.lock();
|
||||
try {
|
||||
kos.flush();
|
||||
}finally {
|
||||
kos.olock.unlock();
|
||||
}
|
||||
}else {
|
||||
kos.olock.lock();
|
||||
try {
|
||||
kos.flush0();
|
||||
}finally {
|
||||
kos.olock.unlock();
|
||||
|
||||
}
|
||||
}
|
||||
tst.clear();
|
||||
}
|
||||
}
|
||||
}catch(IOException e) {
|
||||
onError=true;
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
@@ -1130,6 +1330,20 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(true) {
|
||||
try {
|
||||
associateSocket.close();
|
||||
} catch (IOException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
close();
|
||||
} catch (IOException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
t1.start();
|
||||
@@ -1140,11 +1354,12 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
associateSocket.close();
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(KLALBRemoteLine from, KLALBPacket u) {
|
||||
public void accept(Inet6Address from, KLALBPacket u) {
|
||||
try {
|
||||
//System.out.println(this+" "+u);
|
||||
switch (u.getType()) {
|
||||
@@ -1155,13 +1370,15 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
break;
|
||||
case KLALBPacket.DATAT:
|
||||
DATATPacket dtp = (DATATPacket) u;
|
||||
|
||||
socketRawMonitor.getInTrafficAL().addAndGet(dtp.getLength());
|
||||
if(isListening()) {
|
||||
if(dtp.getNumber()==0) {
|
||||
backlogQueuelock.lock();
|
||||
try{
|
||||
|
||||
//controller.getStreamPortBinder().checkIsConnected(new Pair);
|
||||
InetSocketAddress is=new InetSocketAddress(from.getRemoteVaddr(), dtp.getSport());
|
||||
InetSocketAddress is=new InetSocketAddress(from, dtp.getSport());
|
||||
AtomicBoolean ab=new AtomicBoolean(true);
|
||||
for (Iterator iterator = backlogQueue.iterator(); iterator.hasNext();) {
|
||||
Object[] objects = (Object[]) iterator.next();
|
||||
@@ -1171,7 +1388,7 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
}
|
||||
}
|
||||
if(ab.get()) {
|
||||
if(controller.getStreamPortBinder().checkIsConnect(this,new InetSocketAddress(from.getRemoteVaddr(), dtp.getSport()))) {
|
||||
if(controller.getStreamPortBinder().checkIsConnect(this,new InetSocketAddress(from, dtp.getSport()))) {
|
||||
ab.set(false);
|
||||
}
|
||||
}
|
||||
@@ -1182,7 +1399,7 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
/* controller.sendPacketToAddress(from.getRemoteVaddr(), new ACKTPacket(dtp.getDport(), dtp.getSport(),dtp.getNumber(),true,0),
|
||||
0,2);*/
|
||||
}else {
|
||||
controller.sendPacketToAddress(from.getRemoteVaddr(), new RSTPacket(dtp.getDport(), dtp.getSport()),
|
||||
controller.sendPacketToAddress(from,0, new RSTPacket(dtp.getDport(), dtp.getSport()),
|
||||
2);
|
||||
}
|
||||
|
||||
@@ -1191,96 +1408,185 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
backlogQueuelock.unlock();
|
||||
}
|
||||
}else {
|
||||
controller.sendPacketToAddress(from.getRemoteVaddr(), new RSTPacket(dtp.getDport(), dtp.getSport()),
|
||||
controller.sendPacketToAddress(from,0, new RSTPacket(dtp.getDport(), dtp.getSport()),
|
||||
2);
|
||||
}
|
||||
}else {
|
||||
controller.sendPacketToAddress(from.getRemoteVaddr(), new ACKTPacket(dtp.getDport(), dtp.getSport(), dtp.getNumber(),
|
||||
sendDeque.size() < inputchachesize/MTU,dtp.getSendcount()), 1);
|
||||
inputchachelock.lock();
|
||||
try{
|
||||
if (dtp.getNumber() >= inputcount) {
|
||||
int currindex=(int) (dtp.getNumber()-inputcount);
|
||||
//System.out.println(dtp.isCE());
|
||||
controller.sendPacketToAddress(from,0, new ACKTPacket(dtp.getDport(), dtp.getSport(), dtp.getNumber(),
|
||||
recvQueueUsed.get() < inputchachesize,dtp.isCE(),socketMonitor.getInSpeedMax(),dtp.getSendcount()), 1);
|
||||
|
||||
boolean added=false;
|
||||
|
||||
long number=dtp.getNumber();
|
||||
if (number >= inputcount) {
|
||||
|
||||
inputchache.putIfAbsent(number, dtp);
|
||||
|
||||
/*inputchachelock.lock();
|
||||
try{
|
||||
int currindex=(int) (number-inputcount);
|
||||
int reqsize=1+currindex;
|
||||
|
||||
while(reqsize>inputchache.size()) {
|
||||
inputchache.add(new AtomicInteger());
|
||||
}
|
||||
for (int i = 0; i < currindex; i++) {
|
||||
Object o=inputchache.get(i);
|
||||
if(o instanceof AtomicInteger) {
|
||||
((AtomicInteger) o).incrementAndGet();
|
||||
/*if(((AtomicInteger) o).get()==30) {
|
||||
controller.sendPacketToAddress(from.getRemoteVaddr(), new NACKTPacket(dtp.getDport(), dtp.getSport(), inputcount+i),1);
|
||||
//System.out.println("请求快速重传:"+(inputcount+i));
|
||||
}*/
|
||||
}
|
||||
}
|
||||
inputchache.set(currindex, dtp);
|
||||
|
||||
Iterator<Object>itr=inputchache.iterator();
|
||||
while (itr.hasNext()) {
|
||||
Object datatPacket = itr.next();
|
||||
if(datatPacket instanceof DATATPacket) {
|
||||
itr.remove();
|
||||
sendDeque.add((DATATPacket) datatPacket);
|
||||
LockSupport.unpark(sendDequeLock);
|
||||
inputcount++;
|
||||
}else {
|
||||
break;
|
||||
}
|
||||
|
||||
inputchache.add(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(currindex>=0) {
|
||||
DATATPacket old=(DATATPacket) inputchache.get(currindex);
|
||||
if(old==null) {
|
||||
inputchache.set(currindex, dtp);
|
||||
}else {
|
||||
dtp.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int spos=inputchache.size();
|
||||
for (int i = 0; i < inputchache.size(); i++) {
|
||||
DATATPacket datatPacket=(DATATPacket) inputchache.get(i);
|
||||
if(datatPacket==null) {
|
||||
spos=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < spos; i++) {
|
||||
DATATPacket datatPacket = (DATATPacket)inputchache.get(i);
|
||||
recvQueueUsed.addAndGet(datatPacket.getSize());
|
||||
recvQueue.add(datatPacket);
|
||||
added=true;
|
||||
inputcount++;
|
||||
}
|
||||
((RangeArrayList)inputchache).removeRange(0,spos);
|
||||
|
||||
}finally{
|
||||
inputchachelock.unlock();
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}else {
|
||||
dtp.dispose();
|
||||
}
|
||||
}finally{
|
||||
|
||||
inputchachelock.lock();
|
||||
try {
|
||||
DATATPacket datatPacket = inputchache.remove(inputcount);
|
||||
if(datatPacket!=null) {
|
||||
inputcount++;
|
||||
recvQueueUsed.addAndGet(datatPacket.getSize());
|
||||
recvQueue.add(datatPacket);
|
||||
added=true;
|
||||
}
|
||||
}finally {
|
||||
inputchachelock.unlock();
|
||||
}
|
||||
if(added) {
|
||||
LockSupport.unpark(sendDequeLock);
|
||||
}
|
||||
|
||||
//dbg.println(from.getMonitor()+","+dtp.getNumber());
|
||||
}
|
||||
break;
|
||||
case KLALBPacket.ACKT:
|
||||
ACKTPacket ackt = (ACKTPacket) u;
|
||||
if(isListening()) {
|
||||
controller.sendPacketToAddress(from.getRemoteVaddr(), new RSTPacket(ackt.getDport(), ackt.getSport()),
|
||||
controller.sendPacketToAddress(from,0, new RSTPacket(ackt.getDport(), ackt.getSport()),
|
||||
2);
|
||||
}else {
|
||||
avaliable = ackt.isAvaliable();
|
||||
|
||||
|
||||
rcvSpeed=ackt.getRcvSpeed();
|
||||
|
||||
/*if(rcvSpeed>=congressSpeed) {
|
||||
congressSpeed=rcvSpeed;
|
||||
}else {
|
||||
congressSpeed=(congressSpeed*99+rcvSpeed)/100;
|
||||
}*/
|
||||
|
||||
|
||||
if(ackt.isCongress()) {
|
||||
congressFactor=1.2;
|
||||
if(reallimit>MTU*2) {
|
||||
reallimit-=8192;
|
||||
//System.out.println(reallimit+" -2048");
|
||||
}
|
||||
}else {
|
||||
if(sendmapWindowUsed.get()*2L>=reallimit) {
|
||||
reallimit+=1024;
|
||||
//System.out.println(reallimit+" +1024");
|
||||
}
|
||||
}
|
||||
requestSpeed=(long) (Math.max(MIN_LIMIT_SPEED, rcvSpeed)*congressFactor);
|
||||
|
||||
//System.out.println(spdlmt.getLimitspeed()/1024+"K "+ackt.getRcvSpeed()/1024+"K");
|
||||
DATATPacket kl=null;
|
||||
/*sendmaplock.readLock().lock();
|
||||
try{*/
|
||||
|
||||
|
||||
kl=sendmap.remove(ackt.getNumber());
|
||||
|
||||
/* }finally {
|
||||
sendmaplock.readLock().unlock();
|
||||
}*/
|
||||
if(kl!=null) {
|
||||
sendmapWindowUsed.addAndGet(-kl.getSize());
|
||||
}
|
||||
|
||||
if(kl!=null) {
|
||||
if(sendthread!=null)
|
||||
LockSupport.unpark(sendthread);
|
||||
//controller.removeFromSend(from.getRemoteVaddr(),kl);
|
||||
if(kl.getSendRecord().size()==1) {
|
||||
if(kl.getSendCounter()==1) {
|
||||
long RTTC=ackt.getRcvtime()- kl.getSndtime();
|
||||
if(RTTC<=RTTMin) {
|
||||
RTTMin=RTTC;
|
||||
}else {
|
||||
RTTMin= (RTTMin*9999+RTTC)/10000;
|
||||
RTTMin= (RTTMin*99999+RTTC)/100000;
|
||||
}
|
||||
|
||||
/*if(RTTC>RTTMin*2) {
|
||||
if(reallimit>MTU*3) {
|
||||
reallimit=reallimit-512;
|
||||
}
|
||||
|
||||
long queueing=RTTC-RTTMin;
|
||||
QueueingAvg=(QueueingAvg*99999+queueing)/100000;
|
||||
|
||||
if(firstUpdate.compareAndSet(true, false)) {
|
||||
RTTAvg=RTTC;
|
||||
RTTVar=RTTC/2;
|
||||
|
||||
}else {
|
||||
RTTVar=(RTTVar*3+Math.abs(RTTAvg-RTTC))/4;
|
||||
RTTAvg= (RTTAvg*7+RTTC)/8;
|
||||
}
|
||||
RTO=RTTAvg+Math.max(MIN_RTTVAR, RTTVar*4);//RTTVar*4
|
||||
|
||||
|
||||
|
||||
/*if(RTTC>RTO) {
|
||||
congressFactor=Math.min( 0.9,congressFactor);
|
||||
}else {
|
||||
if(reallimit<outputchachesize)
|
||||
reallimit+=512;
|
||||
}*/
|
||||
if(congressFactor<1.1)
|
||||
congressFactor+=0.001;
|
||||
} */
|
||||
|
||||
|
||||
//System.out.println(congressFactor);
|
||||
//spdlmt.setLimitspeed(1024*1024);
|
||||
//reallimit=Math.max(MTU*2,(int) (congressSpeed*RTTMin*4/1000000000L));
|
||||
//System.out.println(reallimit/MTU);
|
||||
/*long nspd=(long) (congressSpeed*congressFactor);
|
||||
spdlmt.setLimitspeed(Math.max(nspd,MIN_LIMIT_SPEED));*/
|
||||
|
||||
|
||||
// System.out.println("RwqSpeed:"+(requestSpeed/1024)+"K MaxSpeed:"+(congressSpeed/1024)+"K LimitSpeed:"+(spdlmt.getLimitspeed()/1024)+"K");
|
||||
//System.out.println("RTTMin:"+RTTMin/1000000L+"ms RTTAvg:"+RTTAvg/1000000L+"ms");
|
||||
|
||||
|
||||
}
|
||||
kl.dispose();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
ackt.dispose();
|
||||
break;
|
||||
@@ -1302,7 +1608,7 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
//System.out.println("快速重传:"+st);
|
||||
|
||||
st.setPriority(4);
|
||||
controller.sendPacketToAddress(remoteaddr,st);
|
||||
controller.sendPacketToAddress(remoteaddr,0,st);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -10,16 +10,17 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class NACKTPacket extends KLALBPacket implements PortPacket{
|
||||
|
||||
private static final int HEADER_LENGTH=18;
|
||||
|
||||
public NACKTPacket(int sport,int dport,long number) {
|
||||
super(NACKT);
|
||||
header.putInt(sport);
|
||||
header.putInt(dport);
|
||||
header.putLong(number);
|
||||
super(NACKT,HEADER_LENGTH);
|
||||
klalbHeader.putInt(sport);
|
||||
klalbHeader.putInt(dport);
|
||||
klalbHeader.putLong(number);
|
||||
}
|
||||
|
||||
public NACKTPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,25 +29,15 @@ public class NACKTPacket extends KLALBPacket implements PortPacket{
|
||||
}
|
||||
|
||||
public int getSport() {
|
||||
return header.getInt(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeaderSize() {
|
||||
return super.getHeaderSize()+17;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLength() {
|
||||
return super.getLength()+17;
|
||||
return klalbHeader.getInt(1);
|
||||
}
|
||||
|
||||
public int getDport() {
|
||||
return header.getInt(5);
|
||||
return klalbHeader.getInt(5);
|
||||
}
|
||||
|
||||
public long getNumber() {
|
||||
return header.getLong(9);
|
||||
return klalbHeader.getLong(9);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,30 +9,20 @@ import java.nio.ByteBuffer;
|
||||
|
||||
public class PINGPacket extends KLALBPacket {
|
||||
|
||||
|
||||
private static final int HEADER_LENGTH=9;
|
||||
|
||||
public long getTime() {
|
||||
return header.getLong(1);
|
||||
return klalbHeader.getLong(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public long getLength() {
|
||||
return super.getLength()+8;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeaderSize() {
|
||||
return super.getHeaderSize()+8;
|
||||
}
|
||||
|
||||
public PINGPacket(long time) {
|
||||
super(PING,-1);
|
||||
header.putLong(time);
|
||||
super(PING,HEADER_LENGTH,-1);
|
||||
klalbHeader.putLong(time);
|
||||
}
|
||||
public PINGPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,40 +9,37 @@ import java.nio.ByteBuffer;
|
||||
|
||||
public class PONGPacket extends KLALBPacket {
|
||||
|
||||
private static final int HEADER_LENGTH=25;
|
||||
|
||||
public long getTimepingsnd() {
|
||||
return header.getLong(1);
|
||||
return klalbHeader.getLong(1);
|
||||
}
|
||||
|
||||
public long getTimepingrcv() {
|
||||
return header.getLong(9);
|
||||
return klalbHeader.getLong(9);
|
||||
}
|
||||
|
||||
public long getTimepongsnd() {
|
||||
return header.getLong(17);
|
||||
return klalbHeader.getLong(17);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected int getHeaderSize() {
|
||||
return super.getHeaderSize()+24;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getLength() {
|
||||
return super.getLength()+24;
|
||||
return HEADER_LENGTH;
|
||||
}
|
||||
|
||||
public PONGPacket( long timepingsnd,long timepingrcv, long timepongsnd) {
|
||||
super(PONG,-1);
|
||||
header.putLong(timepingsnd);
|
||||
header.putLong(timepingrcv);
|
||||
header.putLong(timepongsnd);
|
||||
super(PONG,HEADER_LENGTH,-1);
|
||||
klalbHeader.putLong(timepingsnd);
|
||||
klalbHeader.putLong(timepingrcv);
|
||||
klalbHeader.putLong(timepongsnd);
|
||||
}
|
||||
|
||||
public PONGPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -204,29 +204,29 @@ public class PortBinder {
|
||||
}
|
||||
return b;
|
||||
}*/
|
||||
public boolean distributePacketToConsumer(KLALBRemoteLine krl,PortPacket packet) throws SocketTimeoutException {
|
||||
public boolean distributePacketToConsumer(Inet6Address srcAddr,PortPacket packet) {
|
||||
InetSocketAddress local=new InetSocketAddress(controller.getSelf(), packet.getDport());
|
||||
InetSocketAddress remote=new InetSocketAddress(krl.getRemoteVaddr(), packet.getSport());
|
||||
InetSocketAddress remote=new InetSocketAddress(srcAddr, packet.getSport());
|
||||
BindableKLALBPacketConsumer bkc=connectMap.get(new Pair<InetSocketAddress, InetSocketAddress>(local, remote));
|
||||
if(bkc!=null) {
|
||||
bkc.accept(krl, (KLALBPacket) packet);
|
||||
bkc.accept(srcAddr, (KLALBPacket) packet);
|
||||
return true;
|
||||
}
|
||||
InetSocketAddress localany=new InetSocketAddress(ANYLA, packet.getDport());
|
||||
bkc=connectMap.get(new Pair<InetSocketAddress, InetSocketAddress>(localany, remote));
|
||||
if(bkc!=null) {
|
||||
bkc.accept(krl, (KLALBPacket) packet);
|
||||
bkc.accept(srcAddr, (KLALBPacket) packet);
|
||||
return true;
|
||||
}
|
||||
|
||||
bkc=listenMap.get(local);
|
||||
if(bkc!=null) {
|
||||
bkc.accept(krl, (KLALBPacket) packet);
|
||||
bkc.accept(srcAddr, (KLALBPacket) packet);
|
||||
return true;
|
||||
}
|
||||
bkc=listenMap.get(localany);
|
||||
if(bkc!=null) {
|
||||
bkc.accept(krl, (KLALBPacket) packet);
|
||||
bkc.accept(srcAddr, (KLALBPacket) packet);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,33 +8,24 @@ import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class RSTPacket extends KLALBPacket implements PortPacket{
|
||||
private static final int HEADER_LENGTH=9;
|
||||
public RSTPacket(int sport,int dport) {
|
||||
super(RST);
|
||||
header.putInt(sport);
|
||||
header.putInt(dport);
|
||||
super(RST,HEADER_LENGTH);
|
||||
klalbHeader.putInt(sport);
|
||||
klalbHeader.putInt(dport);
|
||||
}
|
||||
|
||||
public RSTPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLength() {
|
||||
return super.getLength()+8;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeaderSize() {
|
||||
return super.getHeaderSize()+8;
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
public int getSport() {
|
||||
return header.getInt(1);
|
||||
return klalbHeader.getInt(1);
|
||||
}
|
||||
|
||||
public int getDport() {
|
||||
return header.getInt(5);
|
||||
return klalbHeader.getInt(5);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RangeArrayList<E> extends ArrayList<E>{
|
||||
|
||||
@Override
|
||||
protected void removeRange(int fromIndex, int toIndex) {
|
||||
// TODO 自动生成的方法存根
|
||||
super.removeRange(fromIndex, toIndex);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.SocketBridge;
|
||||
import org.kne.cloud.network.SocketListener;
|
||||
import org.kne.cloud.network.SocketToSocketProxy;
|
||||
import org.kne.cloud.network.klalb.ui.KLALBStateGUI2;
|
||||
import org.kne.util.AutoProperties;
|
||||
|
||||
public class SimpleKLALBClient {
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.kne.cloud.network.SocketBridge;
|
||||
import org.kne.cloud.network.SocketListener;
|
||||
import org.kne.cloud.network.SocketToSocketProxy;
|
||||
import org.kne.cloud.network.SocketType;
|
||||
import org.kne.cloud.network.klalb.ui.KLALBStateGUI2;
|
||||
|
||||
public class SimpleKLALBServer {
|
||||
public static KLALBStateGUI2 ksg;
|
||||
|
||||
@@ -24,7 +24,27 @@ import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.TimeoutTimer;
|
||||
|
||||
public class StreamChannelKLALBPacketLink implements KLALBPacketLink {
|
||||
private static TimeoutTimer tmoTimer=new TimeoutTimer();
|
||||
private volatile long timeoutTimer;
|
||||
private volatile boolean timerenabled=false;
|
||||
private Thread timeouter=new Thread() {
|
||||
public void run() {
|
||||
timeoutTimer=System.nanoTime();
|
||||
while(connectSocket.isOpen()) {
|
||||
if(timerenabled&&(System.nanoTime()-timeoutTimer>sotimeout*1000000L)) {
|
||||
if(connectSocket!=null)
|
||||
try {
|
||||
connectSocket.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
@@ -38,9 +58,10 @@ public class StreamChannelKLALBPacketLink implements KLALBPacketLink {
|
||||
private int sotimeout;
|
||||
public StreamChannelKLALBPacketLink(SocketChannel connectSocket) throws IOException {
|
||||
this.connectSocket=connectSocket;
|
||||
connectSocket.setOption(StandardSocketOptions.TCP_NODELAY,true);
|
||||
timeouter.start();
|
||||
new KLALBOutputStream(Channels.newOutputStream(connectSocket));
|
||||
new KLALBInputStream(Channels.newInputStream(connectSocket));
|
||||
connectSocket.setOption(StandardSocketOptions.TCP_NODELAY,true);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,19 +72,21 @@ public class StreamChannelKLALBPacketLink implements KLALBPacketLink {
|
||||
|
||||
@Override
|
||||
public KLALBPacket readPacket() throws IOException {
|
||||
TimerTask tsk= tmoTimer.createTimeOutTask(connectSocket, sotimeout);
|
||||
timeoutTimer=System.nanoTime();
|
||||
timerenabled=true;
|
||||
KLALBPacket res;
|
||||
try {
|
||||
res=KLALBPacket.readKLALBPacketFromChannel(connectSocket);
|
||||
}finally {
|
||||
if(tsk!=null)
|
||||
tsk.cancel();
|
||||
timerenabled=false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
//System.out.println("连接被关闭");
|
||||
//new Exception().printStackTrace();
|
||||
connectSocket.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,53 +4,69 @@ import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
|
||||
public class TESTPacket extends KLALBPacket {
|
||||
private static ByteBuffer K=ByteBuffer.allocateDirect(1024);
|
||||
|
||||
private static final int HEADER_LENGTH=3;
|
||||
|
||||
private ByteBuffer dataBuffer;//=NetworkPacket.databufferpool_65535.borrow();
|
||||
@Override
|
||||
public long getLength() {
|
||||
return super.getLength()+K.limit();
|
||||
return HEADER_LENGTH+dataBuffer.limit();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int getHeaderSize() {
|
||||
return super.getHeaderSize();
|
||||
public TESTPacket(int limit) {
|
||||
super(TEST,HEADER_LENGTH);
|
||||
//dataBuffer.limit(limit);
|
||||
dataBuffer=ByteBuffer.allocate(limit);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public TESTPacket() {
|
||||
super(TEST);
|
||||
public ByteBuffer getDataBuffer() {
|
||||
return dataBuffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void writeToChannel(WritableByteChannel dto) throws IOException {
|
||||
klalbHeader.putChar(1, (char) dataBuffer.limit());
|
||||
super.writeToChannel(dto);
|
||||
dto.write(K.slice());
|
||||
//System.out.println(dataBuffer);
|
||||
dto.write(dataBuffer.slice(0, dataBuffer.limit()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void readFromChannel(ReadableByteChannel din) throws IOException {
|
||||
super.readFromChannel(din);
|
||||
din.read(K.slice());
|
||||
int limit=klalbHeader.getChar(1);
|
||||
//dataBuffer.clear();
|
||||
//dataBuffer.limit(limit);
|
||||
dataBuffer=ByteBuffer.allocate(limit);
|
||||
while(dataBuffer.hasRemaining()){
|
||||
if(din.read(dataBuffer)==-1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
}
|
||||
dataBuffer.flip();
|
||||
}
|
||||
|
||||
|
||||
public TESTPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TEST";
|
||||
return "TEST["+dataBuffer.limit()+"]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,12 +4,13 @@ import java.nio.ByteBuffer;
|
||||
|
||||
public class VADDRACKPacket extends KLALBPacket {
|
||||
|
||||
private static final int HEADER_LENGTH=1;
|
||||
public VADDRACKPacket() {
|
||||
super(VADDRACK);
|
||||
super(VADDRACK,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
public VADDRACKPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,40 +9,34 @@ import java.net.Inet6Address;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.kne.cloud.network.ipv6.Inet6AddressGroup;
|
||||
|
||||
public class VADDRPacket extends KLALBPacket {
|
||||
public Inet6Address getVaddr() {
|
||||
private static final int HEADER_LENGTH=18;
|
||||
public Inet6AddressGroup getVaddr() {
|
||||
byte[]b=new byte[16];
|
||||
header.get(1, b);
|
||||
klalbHeader.get(1, b);
|
||||
try {
|
||||
return (Inet6Address) Inet6Address.getByAddress(b);
|
||||
return new Inet6AddressGroup( (Inet6Address) Inet6Address.getByAddress(b),klalbHeader.get(17)&0xff);
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public VADDRPacket(Inet6Address vaddr) {
|
||||
super(VADDR);
|
||||
header.put(1, vaddr.getAddress());
|
||||
public VADDRPacket(Inet6AddressGroup vaddr) {
|
||||
super(VADDR,HEADER_LENGTH);
|
||||
klalbHeader.put(1, vaddr.getAddress().getAddress());
|
||||
klalbHeader.put(17,(byte) vaddr.getPrefixLength());
|
||||
}
|
||||
|
||||
public VADDRPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VADDR "+getVaddr().getHostAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeaderSize() {
|
||||
return super.getHeaderSize()+16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLength() {
|
||||
return super.getLength()+16;
|
||||
return "VADDR "+getVaddr();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ import java.nio.ByteBuffer;
|
||||
|
||||
public class VADDRREQPacket extends KLALBPacket {
|
||||
|
||||
private static final int HEADER_LENGTH=1;
|
||||
|
||||
public VADDRREQPacket() {
|
||||
super(VADDRREQ);
|
||||
super(VADDRREQ,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
public VADDRREQPacket(ByteBuffer bb) {
|
||||
super(bb);
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-1
@@ -1,4 +1,4 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
package org.kne.cloud.network.klalb.ui;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Color;
|
||||
@@ -21,6 +21,9 @@ import javax.imageio.ImageIO;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import org.kne.cloud.network.klalb.CONST;
|
||||
import org.kne.cloud.network.klalb.KLALBController;
|
||||
import org.kne.cloud.network.klalb.KLALBRemoteLine;
|
||||
import org.kne.ui.XFrame;
|
||||
import org.kne.ui.YScrollPane;
|
||||
|
||||
+449
-91
@@ -1,45 +1,42 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
package org.kne.cloud.network.klalb.ui;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.MenuItem;
|
||||
import java.awt.PopupMenu;
|
||||
import java.awt.SystemTray;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.TrayIcon;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.management.monitor.Monitor;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import org.jfree.chart.ChartFactory;
|
||||
import org.jfree.chart.ChartPanel;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.chart.plot.dial.DialLayer;
|
||||
import org.jfree.chart.plot.dial.DialPlot;
|
||||
import org.jfree.chart.plot.dial.DialPointer;
|
||||
import org.jfree.chart.plot.dial.DialTextAnnotation;
|
||||
@@ -47,35 +44,20 @@ import org.jfree.chart.plot.dial.StandardDialFrame;
|
||||
import org.jfree.chart.plot.dial.StandardDialRange;
|
||||
import org.jfree.chart.plot.dial.StandardDialScale;
|
||||
import org.jfree.chart.ui.RectangleEdge;
|
||||
import org.jfree.chart.ui.RectangleInsets;
|
||||
import org.jfree.data.general.Dataset;
|
||||
import org.jfree.data.general.DefaultValueDataset;
|
||||
import org.jfree.data.general.ValueDataset;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.SocketBridge;
|
||||
import org.kne.cloud.network.SocketListener;
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
import org.kne.cloud.network.klalb.CONST;
|
||||
import org.kne.cloud.network.klalb.KLALBController;
|
||||
import org.kne.cloud.network.klalb.KLALBRemoteLine;
|
||||
import org.kne.cloud.network.klalb.KLALBUtils;
|
||||
import org.kne.cloud.network.monitor.MonitorData;
|
||||
import org.kne.ui.XFrame;
|
||||
import org.kne.ui.YScrollPane;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.border.LineBorder;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JRadioButtonMenuItem;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Image;
|
||||
import java.awt.FlowLayout;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.SwingConstants;
|
||||
import java.awt.Font;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
public class KLALBStateGUI2 extends XFrame {
|
||||
|
||||
private TimerTask tsk,tsk2,tsk3;
|
||||
private TimerTask tsk,tsk2,tsk3,tsk4,tsk5;
|
||||
|
||||
private SystemTray st;
|
||||
|
||||
@@ -83,7 +65,7 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
|
||||
private long rate=200;
|
||||
|
||||
private Timer t,t2;
|
||||
private Timer t,t2,t3;
|
||||
|
||||
private JCheckBoxMenuItem showoffline;
|
||||
|
||||
@@ -96,42 +78,57 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
|
||||
private DefaultValueDataset downSpeed;
|
||||
|
||||
private DefaultValueDataset upEfficiency;
|
||||
|
||||
private DefaultValueDataset upPPS;
|
||||
|
||||
private DialTextAnnotation upPPSText;
|
||||
|
||||
private DialTextAnnotation downPPSText;
|
||||
|
||||
private DefaultValueDataset downPPS;
|
||||
|
||||
private DefaultValueDataset upDataSpeed;
|
||||
|
||||
private DefaultValueDataset downDataSpeed;
|
||||
|
||||
private DefaultValueDataset upDataPPS;
|
||||
|
||||
private DefaultValueDataset downDataPPS;
|
||||
|
||||
/*private DefaultValueDataset upEfficiency;
|
||||
|
||||
private DialTextAnnotation upEfficiencyText;
|
||||
|
||||
private DialTextAnnotation downEfficiencyText;
|
||||
|
||||
private DefaultValueDataset downEfficiency;
|
||||
private DefaultValueDataset downEfficiency;*/
|
||||
|
||||
private YScrollPane ysp;
|
||||
|
||||
private static BufferedImage bi;
|
||||
|
||||
public static Image getKLALBIcon() {
|
||||
if(bi==null)
|
||||
try {
|
||||
bi = ImageIO.read(KLALBStateGUI2.class.getResourceAsStream("/assets/KNEL.png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return bi;
|
||||
}
|
||||
private JTextField devicesOnline;
|
||||
private JTextField textField;
|
||||
private JTextField addressField;
|
||||
|
||||
private NetworkGraphPanel graph;
|
||||
|
||||
|
||||
public KLALBStateGUI2(KLALBController kpcje) {
|
||||
this(kpcje ,CONST.klalb+" network accelerator V"+CONST.klalbver);
|
||||
}
|
||||
/**
|
||||
* @wbp.parser.constructor
|
||||
*/
|
||||
public KLALBStateGUI2(KLALBController kpcje) {
|
||||
this(kpcje ,CONST.klalb+" SRv6 network accelerator V"+CONST.klalbver);
|
||||
}
|
||||
|
||||
|
||||
public KLALBStateGUI2(KLALBController kc,String title) {
|
||||
//setResizable(false);
|
||||
Image bix=getKLALBIcon();
|
||||
if(bix!=null)
|
||||
setIconImage(bix);
|
||||
setTitleColor(new Color(255, 255, 255, 250));
|
||||
//getTitlelabel().setFont(UIEnv.getFont().deriveFont(17.0f));
|
||||
setIconImage(UIEnv.getIcon());
|
||||
//setTitleColor(new Color(255, 255, 255, 250));
|
||||
setTitleColor(UIEnv.getDefaultTitleColor());
|
||||
getContentPane().setBackground(UIEnv.getDefaultBackgroundColor());
|
||||
getTitlelabel().setFont(UIEnv.getFont().deriveFont(17.0f));
|
||||
getTitlepanel().setBorder(new LineBorder(Color.LIGHT_GRAY));
|
||||
getTitlelabel().setForeground(Color.WHITE);
|
||||
//getContentPane().setBackground(new Color(0,0,0,0));
|
||||
/*setTitleColor(new Color(0,0,0,80));
|
||||
getContentPane().setBackground(new Color(0,0,0,80));
|
||||
@@ -145,13 +142,21 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
overview.setOpaque(false);
|
||||
tabbedPane.addTab("Overview", null, overview, null);
|
||||
overview.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JPanel dashboard = new JPanel();
|
||||
dashboard.setOpaque(false);
|
||||
overview.add(dashboard, BorderLayout.CENTER);
|
||||
dashboard.setBorder(new LineBorder(new Color(0, 0, 0)));
|
||||
JPanel dashs = new JPanel();
|
||||
dashs.setOpaque(false);
|
||||
overview.add(dashboard,BorderLayout.CENTER);
|
||||
dashboard.setLayout(new BorderLayout(0, 0));
|
||||
dashboard.add(dashs);
|
||||
{
|
||||
upSpeed = new DefaultValueDataset(0);
|
||||
upDataSpeed=new DefaultValueDataset(0);
|
||||
DialPlot dpup=new DialPlot();
|
||||
dpup.setDataset(upSpeed);
|
||||
dpup.setDataset(1,upSpeed);
|
||||
dpup.setDataset(0, upDataSpeed);
|
||||
StandardDialFrame sdfs=new StandardDialFrame();
|
||||
sdfs.setVisible(false);
|
||||
dpup.setDialFrame(sdfs);
|
||||
@@ -175,19 +180,29 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
sdrr3.setOuterRadius(0.83);
|
||||
dpup.addLayer(sdrr3);
|
||||
|
||||
DialPointer.Pointer dpd=new DialPointer.Pointer();
|
||||
dpd.setRadius(0.7);
|
||||
dpd.setFillPaint(new Color(127, 0, 0,0));
|
||||
dpd.setOutlinePaint(new Color(127, 0, 0));
|
||||
dpd.setDatasetIndex(0);
|
||||
dpup.addLayer(dpd);
|
||||
|
||||
DialPointer.Pointer dp=new DialPointer.Pointer();
|
||||
dp.setRadius(0.7);
|
||||
dp.setFillPaint(Color.RED);
|
||||
dp.setOutlinePaint(Color.RED);
|
||||
dp.setDatasetIndex(1);
|
||||
dpup.addLayer(dp);
|
||||
|
||||
|
||||
upSpeedText = new DialTextAnnotation("0%");
|
||||
upSpeedText.setFont(upSpeedText.getFont().deriveFont(12));
|
||||
upSpeedText.setFont(UIEnv.getFont().deriveFont(16.0f));
|
||||
dpup.addLayer(upSpeedText);
|
||||
|
||||
JFreeChart jfup= new JFreeChart(dpup);
|
||||
jfup.setBorderPaint(Color.WHITE);
|
||||
jfup.setTitle("Upload speed");
|
||||
jfup.getTitle().setFont(UIEnv.getFont().deriveFont(20.0f));
|
||||
jfup.getTitle().setPosition(RectangleEdge.BOTTOM);
|
||||
dpup.setView(0, 0, 1, 1);
|
||||
ChartPanel cpup=new ChartPanel(jfup);
|
||||
@@ -195,7 +210,7 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
cpup.setSize(cpup.getPreferredSize());
|
||||
cpup.setBackground(Color.WHITE);
|
||||
cpup.setBorder(new LineBorder(Color.LIGHT_GRAY));
|
||||
dashboard.add(cpup);
|
||||
dashs.add(cpup);
|
||||
|
||||
|
||||
|
||||
@@ -203,8 +218,10 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
|
||||
|
||||
downSpeed = new DefaultValueDataset(0);
|
||||
downDataSpeed=new DefaultValueDataset(0);
|
||||
DialPlot dpup1=new DialPlot();
|
||||
dpup1.setDataset(downSpeed);
|
||||
dpup1.setDataset(1,downSpeed);
|
||||
dpup1.setDataset(0,downDataSpeed);
|
||||
StandardDialFrame sdfs1=new StandardDialFrame();
|
||||
sdfs1.setVisible(false);
|
||||
dpup1.setDialFrame(sdfs1);
|
||||
@@ -228,19 +245,29 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
sdrr31.setOuterRadius(0.83);
|
||||
dpup1.addLayer(sdrr31);
|
||||
|
||||
|
||||
DialPointer.Pointer dp11=new DialPointer.Pointer();
|
||||
dp11.setRadius(0.7);
|
||||
dp11.setFillPaint(new Color(0,127,0,0));
|
||||
dp11.setOutlinePaint(new Color(0,127,0));
|
||||
dp11.setDatasetIndex(0);
|
||||
dpup1.addLayer(dp11);
|
||||
|
||||
DialPointer.Pointer dp1=new DialPointer.Pointer();
|
||||
dp1.setRadius(0.7);
|
||||
dp1.setFillPaint(Color.GREEN);
|
||||
dp1.setOutlinePaint(Color.GREEN);
|
||||
dp1.setDatasetIndex(1);
|
||||
dpup1.addLayer(dp1);
|
||||
|
||||
downSpeedText = new DialTextAnnotation("0%");
|
||||
downSpeedText.setFont(downSpeedText.getFont().deriveFont(12));
|
||||
downSpeedText.setFont(UIEnv.getFont().deriveFont(16.0f));
|
||||
dpup1.addLayer(downSpeedText);
|
||||
|
||||
JFreeChart jfup1= new JFreeChart(dpup1);
|
||||
jfup1.setBorderPaint(Color.WHITE);
|
||||
jfup1.setTitle("Download speed");
|
||||
jfup1.getTitle().setFont(UIEnv.getFont().deriveFont(20.0f));
|
||||
jfup1.getTitle().setPosition(RectangleEdge.BOTTOM);
|
||||
dpup1.setView(0, 0, 1, 1);
|
||||
ChartPanel cpup1=new ChartPanel(jfup1);
|
||||
@@ -248,15 +275,140 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
cpup1.setSize(cpup1.getPreferredSize());
|
||||
cpup1.setBackground(Color.WHITE);
|
||||
cpup1.setBorder(new LineBorder(Color.LIGHT_GRAY));
|
||||
dashboard.add(cpup1);
|
||||
dashs.add(cpup1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
upPPS = new DefaultValueDataset(0);
|
||||
upDataPPS=new DefaultValueDataset(0);
|
||||
DialPlot dpup=new DialPlot();
|
||||
dpup.setDataset(1,upPPS);
|
||||
dpup.setDataset(0,upDataPPS);
|
||||
StandardDialFrame sdfs=new StandardDialFrame();
|
||||
sdfs.setVisible(false);
|
||||
dpup.setDialFrame(sdfs);
|
||||
StandardDialScale sds=new StandardDialScale(0, 100, -120, -300, 10, 5);
|
||||
sds.setTickRadius(0.8);
|
||||
sds.setTickLabelsVisible(false);
|
||||
dpup.addScale(0, sds);
|
||||
|
||||
StandardDialRange sdrr=new StandardDialRange(0, 70,Color.GREEN);
|
||||
sdrr.setInnerRadius(0.82);
|
||||
sdrr.setOuterRadius(0.83);
|
||||
dpup.addLayer(sdrr);
|
||||
|
||||
StandardDialRange sdrr2=new StandardDialRange(70, 90,Color.YELLOW);
|
||||
sdrr2.setInnerRadius(0.82);
|
||||
sdrr2.setOuterRadius(0.83);
|
||||
dpup.addLayer(sdrr2);
|
||||
|
||||
StandardDialRange sdrr3=new StandardDialRange(90, 100,Color.RED);
|
||||
sdrr3.setInnerRadius(0.82);
|
||||
sdrr3.setOuterRadius(0.83);
|
||||
dpup.addLayer(sdrr3);
|
||||
|
||||
DialPointer.Pointer dp1=new DialPointer.Pointer();
|
||||
dp1.setRadius(0.7);
|
||||
dp1.setFillPaint(new Color(127,0,0,0));
|
||||
dp1.setOutlinePaint(new Color(127,0,0));
|
||||
dp1.setDatasetIndex(0);
|
||||
dpup.addLayer(dp1);
|
||||
|
||||
DialPointer.Pointer dp=new DialPointer.Pointer();
|
||||
dp.setRadius(0.7);
|
||||
dp.setFillPaint(Color.RED);
|
||||
dp.setOutlinePaint(Color.RED);
|
||||
dp.setDatasetIndex(1);
|
||||
dpup.addLayer(dp);
|
||||
|
||||
|
||||
upPPSText = new DialTextAnnotation("0PPS");
|
||||
upPPSText.setFont(UIEnv.getFont().deriveFont(16.0f));
|
||||
dpup.addLayer(upPPSText);
|
||||
|
||||
JFreeChart jfup= new JFreeChart(dpup);
|
||||
jfup.setBorderPaint(Color.WHITE);
|
||||
jfup.setTitle("Upload PPS");
|
||||
jfup.getTitle().setFont(UIEnv.getFont().deriveFont(20.0f));
|
||||
jfup.getTitle().setPosition(RectangleEdge.BOTTOM);
|
||||
dpup.setView(0, 0, 1, 1);
|
||||
ChartPanel cpup=new ChartPanel(jfup);
|
||||
cpup.setPreferredSize(new Dimension(150, 165));
|
||||
cpup.setSize(cpup.getPreferredSize());
|
||||
cpup.setBackground(Color.WHITE);
|
||||
cpup.setBorder(new LineBorder(Color.LIGHT_GRAY));
|
||||
dashs.add(cpup);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
downPPS = new DefaultValueDataset(0);
|
||||
downDataPPS=new DefaultValueDataset(0);
|
||||
DialPlot dpup1=new DialPlot();
|
||||
dpup1.setDataset(1,downPPS);
|
||||
dpup1.setDataset(0,downDataPPS);
|
||||
StandardDialFrame sdfs1=new StandardDialFrame();
|
||||
sdfs1.setVisible(false);
|
||||
dpup1.setDialFrame(sdfs1);
|
||||
StandardDialScale sds1=new StandardDialScale(0, 100, -120, -300, 10, 5);
|
||||
sds1.setTickRadius(0.8);
|
||||
sds1.setTickLabelsVisible(false);
|
||||
dpup1.addScale(0, sds1);
|
||||
|
||||
StandardDialRange sdrr1=new StandardDialRange(0, 70,Color.GREEN);
|
||||
sdrr1.setInnerRadius(0.82);
|
||||
sdrr1.setOuterRadius(0.83);
|
||||
dpup1.addLayer(sdrr1);
|
||||
|
||||
StandardDialRange sdrr21=new StandardDialRange(70, 90,Color.YELLOW);
|
||||
sdrr21.setInnerRadius(0.82);
|
||||
sdrr21.setOuterRadius(0.83);
|
||||
dpup1.addLayer(sdrr21);
|
||||
|
||||
StandardDialRange sdrr31=new StandardDialRange(90, 100,Color.RED);
|
||||
sdrr31.setInnerRadius(0.82);
|
||||
sdrr31.setOuterRadius(0.83);
|
||||
dpup1.addLayer(sdrr31);
|
||||
|
||||
DialPointer.Pointer dp111=new DialPointer.Pointer();
|
||||
dp111.setRadius(0.7);
|
||||
dp111.setFillPaint(new Color(0,127,0,0));
|
||||
dp111.setOutlinePaint(new Color(0,127,0));
|
||||
dp111.setDatasetIndex(0);
|
||||
dpup1.addLayer(dp111);
|
||||
DialPointer.Pointer dp11=new DialPointer.Pointer();
|
||||
dp11.setRadius(0.7);
|
||||
dp11.setFillPaint(Color.GREEN);
|
||||
dp11.setOutlinePaint(Color.GREEN);
|
||||
dp11.setDatasetIndex(1);
|
||||
dpup1.addLayer(dp11);
|
||||
|
||||
|
||||
|
||||
downPPSText = new DialTextAnnotation("0PPS");
|
||||
downPPSText.setFont(UIEnv.getFont().deriveFont(16.0f));
|
||||
dpup1.addLayer(downPPSText);
|
||||
|
||||
JFreeChart jfup1= new JFreeChart(dpup1);
|
||||
jfup1.setBorderPaint(Color.WHITE);
|
||||
jfup1.setTitle("Download PPS");
|
||||
jfup1.getTitle().setFont(UIEnv.getFont().deriveFont(20.0f));
|
||||
jfup1.getTitle().setPosition(RectangleEdge.BOTTOM);
|
||||
dpup1.setView(0, 0, 1, 1);
|
||||
ChartPanel cpup1=new ChartPanel(jfup1);
|
||||
cpup1.setPreferredSize(new Dimension(150, 165));
|
||||
cpup1.setSize(cpup1.getPreferredSize());
|
||||
cpup1.setBackground(Color.WHITE);
|
||||
cpup1.setBorder(new LineBorder(Color.LIGHT_GRAY));
|
||||
dashs.add(cpup1);
|
||||
}
|
||||
|
||||
|
||||
/*{
|
||||
upEfficiency = new DefaultValueDataset(0);
|
||||
DialPlot dpup=new DialPlot();
|
||||
dpup.setDataset(upEfficiency);
|
||||
@@ -290,12 +442,13 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
dpup.addLayer(dp);
|
||||
|
||||
upEfficiencyText = new DialTextAnnotation("0%");
|
||||
upEfficiencyText.setFont(upEfficiencyText.getFont().deriveFont(12));
|
||||
upEfficiencyText.setFont(UIEnv.getFont().deriveFont(16.0f));
|
||||
dpup.addLayer(upEfficiencyText);
|
||||
|
||||
JFreeChart jfup= new JFreeChart(dpup);
|
||||
jfup.setBorderPaint(Color.WHITE);
|
||||
jfup.setTitle("Upload bandwidth efficiency");
|
||||
jfup.getTitle().setFont(UIEnv.getFont().deriveFont(20.0f));
|
||||
jfup.getTitle().setPosition(RectangleEdge.BOTTOM);
|
||||
dpup.setView(0, 0, 1, 1);
|
||||
ChartPanel cpup=new ChartPanel(jfup);
|
||||
@@ -303,7 +456,7 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
cpup.setSize(cpup.getPreferredSize());
|
||||
cpup.setBackground(Color.WHITE);
|
||||
cpup.setBorder(new LineBorder(Color.LIGHT_GRAY));
|
||||
dashboard.add(cpup);
|
||||
dashs.add(cpup);
|
||||
|
||||
|
||||
|
||||
@@ -343,12 +496,13 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
dpup1.addLayer(dp1);
|
||||
|
||||
downEfficiencyText = new DialTextAnnotation("0%");
|
||||
downEfficiencyText.setFont(downEfficiencyText.getFont().deriveFont(12));
|
||||
downEfficiencyText.setFont(UIEnv.getFont().deriveFont(16.0f));
|
||||
dpup1.addLayer(downEfficiencyText);
|
||||
|
||||
JFreeChart jfup1= new JFreeChart(dpup1);
|
||||
jfup1.setBorderPaint(Color.WHITE);
|
||||
jfup1.setTitle("Download bandwidth efficiency");
|
||||
jfup1.getTitle().setFont(UIEnv.getFont().deriveFont(20.0f));
|
||||
jfup1.getTitle().setPosition(RectangleEdge.BOTTOM);
|
||||
dpup1.setView(0, 0, 1, 1);
|
||||
ChartPanel cpup1=new ChartPanel(jfup1);
|
||||
@@ -356,13 +510,68 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
cpup1.setSize(cpup1.getPreferredSize());
|
||||
cpup1.setBackground(Color.WHITE);
|
||||
cpup1.setBorder(new LineBorder(Color.LIGHT_GRAY));
|
||||
dashboard.add(cpup1);
|
||||
}
|
||||
dashs.add(cpup1);
|
||||
}*/
|
||||
|
||||
JLabel ashboard = new JLabel("Dashboard");
|
||||
ashboard.setFont(new Font("宋体", Font.PLAIN, 18));
|
||||
ashboard.setFont(UIEnv.getFont().deriveFont(20.0f));
|
||||
ashboard.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
overview.add(ashboard, BorderLayout.NORTH);
|
||||
dashboard.add(ashboard, BorderLayout.NORTH);
|
||||
JPanel panelp = new JPanel();
|
||||
panelp.setOpaque(false);
|
||||
JPanel panel = new JPanel();
|
||||
panel.setOpaque(false);
|
||||
panel.setBorder(new LineBorder(Color.GRAY));
|
||||
overview.add(panelp, BorderLayout.SOUTH);
|
||||
panelp.setLayout(new GridLayout(0, 1, 0, 0));
|
||||
|
||||
JPanel panel_2x = new JPanel();
|
||||
panel_2x.setOpaque(false);
|
||||
|
||||
|
||||
|
||||
JPanel panel_2 = new JPanel();
|
||||
panel_2.setOpaque(false);
|
||||
panelp.add(panel_2x);
|
||||
panel_2x.setLayout(new GridLayout(2, 1, 0, 0));
|
||||
JLabel lblNewLabel = new JLabel("IPv6 addresss");
|
||||
lblNewLabel.setFont(UIEnv.getFont().deriveFont(20.0f));
|
||||
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel_2x.add(lblNewLabel);
|
||||
panel_2x.add(panel_2);
|
||||
panel_2.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
addressField = new JTextField();
|
||||
addressField.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
addressField.setOpaque(false);
|
||||
panel_2.add(addressField);
|
||||
addressField.setColumns(10);
|
||||
addressField.setFont(UIEnv.getFont().deriveFont(20.0f));
|
||||
|
||||
JButton btnNewButton_1 = new JButton("Copy");
|
||||
btnNewButton_1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(addressField.getText()), null);
|
||||
}
|
||||
});
|
||||
panel_2.add(btnNewButton_1, BorderLayout.EAST);
|
||||
|
||||
|
||||
panelp.add(panel);
|
||||
panel.setLayout(new GridLayout(2, 2, 0, 0));
|
||||
|
||||
JLabel jlb = new JLabel("Devices Online");
|
||||
jlb.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
jlb.setFont(UIEnv.getFont().deriveFont(20.0f));
|
||||
panel.add(jlb);
|
||||
|
||||
devicesOnline = new JTextField();
|
||||
devicesOnline.setOpaque(false);
|
||||
devicesOnline.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
devicesOnline.setFont(UIEnv.getFont().deriveFont(20.0f));
|
||||
devicesOnline.setEditable(false);
|
||||
panel.add(devicesOnline);
|
||||
devicesOnline.setColumns(10);
|
||||
|
||||
|
||||
|
||||
@@ -370,14 +579,16 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
|
||||
|
||||
|
||||
|
||||
JPanel linesPanel=new JPanel();
|
||||
linesPanel.setOpaque(false);
|
||||
tabbedPane.add(linesPanel);
|
||||
tabbedPane.setTitleAt(1, "Remote lines");
|
||||
linesPanel.setLayout(new BorderLayout());
|
||||
|
||||
ysp = new YScrollPane(730);
|
||||
ysp.setOpaque(false);
|
||||
tabbedPane.add(ysp);
|
||||
tabbedPane.setTitleAt(1, "Remote lines");
|
||||
JPanel wv = ysp.getView();
|
||||
|
||||
linesPanel.add(ysp,BorderLayout.CENTER);
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
getContentPane().add(menuBar, BorderLayout.NORTH);
|
||||
|
||||
@@ -481,10 +692,9 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
//setVisible(true);
|
||||
|
||||
if (SystemTray.isSupported()) {
|
||||
st = SystemTray.getSystemTray();
|
||||
ti = new TrayIcon(bi);
|
||||
ti = new TrayIcon(UIEnv.getIcon());
|
||||
ti.setImageAutoSize(true);
|
||||
PopupMenu jpm = new PopupMenu();
|
||||
MenuItem mix = new MenuItem("open");
|
||||
@@ -518,9 +728,73 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
|
||||
//repaint();
|
||||
|
||||
t3 = new Timer("监视器刷新线程",true);
|
||||
t2 = new Timer("仪表盘刷新线程",true);
|
||||
t = new Timer("状态刷新线程",true);
|
||||
createRefreshTask(kc, ysp);
|
||||
|
||||
JPanel panel_1 = new JPanel();
|
||||
panel_1.setOpaque(false);
|
||||
linesPanel.add(panel_1, BorderLayout.NORTH);
|
||||
panel_1.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
textField = new JTextField();
|
||||
panel_1.add(textField);
|
||||
textField.setColumns(10);
|
||||
textField.setToolTipText("Line address:port");
|
||||
|
||||
JButton btnNewButton = new JButton("Add line");
|
||||
btnNewButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
kc.addRemoteLines(new MultipurposeSocketAddress(textField.getText()));
|
||||
}catch(RuntimeException ex) {
|
||||
JOptionPane.showMessageDialog(KLALBStateGUI2.this, "Input format error", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
panel_1.add(btnNewButton, BorderLayout.EAST);
|
||||
|
||||
JButton btnReconnect = new JButton("ReconnectAll");
|
||||
btnReconnect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
kc.reconnectImmediately();
|
||||
}
|
||||
});
|
||||
panel_1.add(btnReconnect, BorderLayout.WEST);
|
||||
|
||||
JPanel panel_3 = new JPanel();
|
||||
panel_3.setBackground(new Color(255, 255, 255));
|
||||
tabbedPane.addTab("Network graph", null, panel_3, null);
|
||||
panel_3.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JPanel panel_4 = new JPanel();
|
||||
panel_3.add(panel_4, BorderLayout.NORTH);
|
||||
|
||||
graph = new NetworkGraphPanel(kc.getIpv6Router().getKlalbRouteProtol());
|
||||
graph.setOpaque(false);
|
||||
JScrollPane jsp=new JScrollPane(graph);
|
||||
panel_3.add(jsp, BorderLayout.CENTER);
|
||||
textField.addKeyListener(new KeyListener() {
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
// TODO 自动生成的方法存根
|
||||
|
||||
if(e.getKeyCode()==KeyEvent.VK_ENTER) {
|
||||
btnNewButton.doClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
private void createRefreshTask(KLALBController kc, YScrollPane ysp) {
|
||||
if(tsk!=null) {
|
||||
@@ -548,7 +822,7 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
}
|
||||
}
|
||||
}
|
||||
TPanel2 tp=new TPanel2(ent);
|
||||
TPanel2 tp=new TPanel2(ent,kc);
|
||||
tp.setVisible(showoffline.isSelected()||ent.getMonitor().getState()==MonitorData.ONLINE);
|
||||
ysp.getView().add(tp);
|
||||
}
|
||||
@@ -563,6 +837,7 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
}*/
|
||||
if(kc.getLines().contains(((TPanel2) tp).getTunnel())) {
|
||||
try {
|
||||
if(tp.isVisible())
|
||||
((TPanel2) tp).updateTraffic();
|
||||
}catch(RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
@@ -576,7 +851,7 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
//repaint();
|
||||
}
|
||||
};
|
||||
t.scheduleAtFixedRate(tsk, 200, 100);
|
||||
t.scheduleAtFixedRate(tsk, 200, 500);
|
||||
if(tsk2!=null) {
|
||||
tsk2.cancel();
|
||||
}
|
||||
@@ -584,13 +859,53 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
double outload=kc.getLinkMonitor().getOutSpeed()*100.0/kc.getLinkMonitor().getOutSpeedMax2();
|
||||
if(Double.isFinite(outload)) {
|
||||
upSpeedText.setLabel(KLALBUtils.bytesUnit(kc.getLinkMonitor().getOutSpeedAvg())+"/s");
|
||||
upSpeed.setValue(upSpeed.getValue().doubleValue()*0.95+kc.getLinkMonitor().getOutSpeed()*100.0/(50*1024*1024)*0.05);
|
||||
|
||||
downSpeedText.setLabel(KLALBUtils.bytesUnit(kc.getLinkMonitor().getInSpeedAvg())+"/s");
|
||||
downSpeed.setValue(downSpeed.getValue().doubleValue()*0.95+kc.getLinkMonitor().getInSpeed()*100.0/(50*1024*1024)*0.05);
|
||||
upSpeed.setValue(Math.min(upSpeed.getValue().doubleValue()*0.98+outload*0.02,101.0));
|
||||
}
|
||||
|
||||
double outefi=kc.getDatatMonitor().getOutSpeedAvg2()*100.0D/kc.getLinkMonitor().getOutSpeedAvg2();
|
||||
double inload=kc.getLinkMonitor().getInSpeed()*100.0/kc.getLinkMonitor().getInSpeedMax2();
|
||||
if(Double.isFinite(inload)) {
|
||||
downSpeedText.setLabel(KLALBUtils.bytesUnit(kc.getLinkMonitor().getInSpeedAvg())+"/s");
|
||||
downSpeed.setValue(Math.min(downSpeed.getValue().doubleValue()*0.98+inload*0.02,101.0));
|
||||
}
|
||||
|
||||
double outPPSload=kc.getLinkMonitor().getOutPPS()*100.0/kc.getLinkMonitor().getOutPPSMax2();
|
||||
if(Double.isFinite(outPPSload)) {
|
||||
upPPSText.setLabel(KLALBUtils.defaultUnit(kc.getLinkMonitor().getOutPPSAvg())+"PPS");
|
||||
upPPS.setValue(Math.min(upPPS.getValue().doubleValue()*0.98+outPPSload*0.02,101.0));
|
||||
}
|
||||
|
||||
double inPPSload=kc.getLinkMonitor().getInPPS()*100.0/kc.getLinkMonitor().getInPPSMax2();
|
||||
if(Double.isFinite(inPPSload)) {
|
||||
downPPSText.setLabel(KLALBUtils.defaultUnit(kc.getLinkMonitor().getInPPSAvg())+"PPS");
|
||||
downPPS.setValue(Math.min(downPPS.getValue().doubleValue()*0.98+inPPSload*0.02,101.0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
double outload1=kc.getDatatMonitor().getOutSpeed()*100.0/kc.getLinkMonitor().getOutSpeedMax2();
|
||||
if(Double.isFinite(outload1)) {
|
||||
upDataSpeed.setValue(Math.min(upDataSpeed.getValue().doubleValue()*0.98+outload1*0.02,101.0));
|
||||
}
|
||||
|
||||
double inload1=kc.getDatatMonitor().getInSpeed()*100.0/kc.getLinkMonitor().getInSpeedMax2();
|
||||
if(Double.isFinite(inload1)) {
|
||||
downDataSpeed.setValue(Math.min(downDataSpeed.getValue().doubleValue()*0.98+inload1*0.02,101.0));
|
||||
}
|
||||
|
||||
double outPPSload1=kc.getDatatMonitor().getOutPPS()*100.0/kc.getLinkMonitor().getOutPPSMax2();
|
||||
if(Double.isFinite(outPPSload1)) {
|
||||
upDataPPS.setValue(Math.min(upDataPPS.getValue().doubleValue()*0.98+outPPSload1*0.02,101.0));
|
||||
}
|
||||
|
||||
double inPPSload1=kc.getDatatMonitor().getInPPS()*100.0/kc.getLinkMonitor().getInPPSMax2();
|
||||
if(Double.isFinite(inPPSload1)) {
|
||||
downDataPPS.setValue(Math.min(downDataPPS.getValue().doubleValue()*0.98+inPPSload1*0.02,101.0));
|
||||
}
|
||||
|
||||
/*double outefi=kc.getDatatMonitor().getOutSpeedAvg2()*100.0D/kc.getLinkMonitor().getOutSpeedAvg2();
|
||||
if(Double.isFinite(outefi)) {
|
||||
upEfficiency.setValue(upEfficiency.getValue().doubleValue()*0.95+ outefi*0.05);
|
||||
upEfficiencyText.setLabel(String.format("%.1f", upEfficiency.getValue().doubleValue())+"%");
|
||||
@@ -600,6 +915,14 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
if(Double.isFinite(inefi)) {
|
||||
downEfficiency.setValue(downEfficiency.getValue().doubleValue()*0.95+ inefi*0.05);
|
||||
downEfficiencyText.setLabel(String.format("%.1f", downEfficiency.getValue().doubleValue())+"%");
|
||||
}*/
|
||||
String contt=Long.toString( kc.getIpv6Router().getKlalbRouteProtol().getDevicesFound());
|
||||
if(!contt.equals(devicesOnline.getText())) {
|
||||
devicesOnline.setText(contt);
|
||||
}
|
||||
String address=kc.getSelf().getHostAddress();
|
||||
if(!address.equals(addressField.getText())) {
|
||||
addressField.setText(address);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -625,7 +948,42 @@ public class KLALBStateGUI2 extends XFrame {
|
||||
}
|
||||
}
|
||||
};
|
||||
t.scheduleAtFixedRate(tsk3, 200, 20);
|
||||
t3.scheduleAtFixedRate(tsk3, 200, 200);
|
||||
|
||||
if(tsk4!=null) {
|
||||
tsk4.cancel();
|
||||
}
|
||||
tsk4=new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Component[] count=ysp.getView().getComponents();
|
||||
for (int i = 0; i < count.length; i++) {
|
||||
Component tp=count[i];
|
||||
if(tp instanceof TPanel2) {
|
||||
try {
|
||||
((TPanel2) tp).getMdg().recordData();
|
||||
}catch(RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
t3.scheduleAtFixedRate(tsk4, 200, 10);
|
||||
if(tsk5!=null) {
|
||||
tsk5.cancel();
|
||||
}
|
||||
tsk5=new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(graph.isVisible())
|
||||
graph.repaint();
|
||||
}
|
||||
};
|
||||
t.scheduleAtFixedRate(tsk5, 200, 2000);
|
||||
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
+46
-26
@@ -1,4 +1,4 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
package org.kne.cloud.network.klalb.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
@@ -16,12 +16,15 @@ import javax.swing.border.LineBorder;
|
||||
|
||||
import org.jfree.chart.ChartFactory;
|
||||
import org.jfree.chart.ChartPanel;
|
||||
import org.jfree.chart.ChartRenderingInfo;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.data.time.Millisecond;
|
||||
import org.jfree.data.time.RegularTimePeriod;
|
||||
import org.jfree.data.time.TimePeriod;
|
||||
import org.jfree.data.time.TimeSeries;
|
||||
import org.jfree.data.time.TimeSeriesCollection;
|
||||
import org.kne.cloud.network.ipv6.Inet6AddressGroup;
|
||||
import org.kne.cloud.network.klalb.KLALBRemoteLine;
|
||||
import org.kne.cloud.network.monitor.MonitorData;
|
||||
import org.kne.ui.XFrame;
|
||||
|
||||
@@ -44,8 +47,8 @@ public class LineMonitorGUI extends XFrame{
|
||||
private TimeSeries delayup=new TimeSeries("Upload delay");
|
||||
private TimeSeries delaydown=new TimeSeries("Download delay");
|
||||
|
||||
private TimeSeries delayupmin=new TimeSeries("Upload delay minimum");
|
||||
private TimeSeries delaydownmin=new TimeSeries("Download delay minimum");
|
||||
//private TimeSeries delayupmin=new TimeSeries("Upload delay minimum");
|
||||
//private TimeSeries delaydownmin=new TimeSeries("Download delay minimum");
|
||||
|
||||
private KLALBRemoteLine tr;
|
||||
private JTextField vaddrs;
|
||||
@@ -60,12 +63,11 @@ public class LineMonitorGUI extends XFrame{
|
||||
setSize(700, 700);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
Image bi=KLALBStateGUI2.getKLALBIcon();
|
||||
if(bi!=null)
|
||||
setIconImage(bi);
|
||||
setIconImage(UIEnv.getIcon());
|
||||
setTitle("Line Monitor:"+t.getMonitor().getName());
|
||||
setTitleColor(new Color(255, 255, 255, 250));
|
||||
//getTitlelabel().setFont(UIEnv.getFont().deriveFont(17.0f));
|
||||
setTitleColor(UIEnv.getDefaultTitleColor());
|
||||
getContentPane().setBackground(UIEnv.getDefaultBackgroundColor());
|
||||
getTitlelabel().setFont(UIEnv.getFont().deriveFont(17.0f));
|
||||
getTitlepanel().setBorder(new LineBorder(Color.LIGHT_GRAY));
|
||||
|
||||
JPanel jp=new JPanel();
|
||||
@@ -80,6 +82,7 @@ public class LineMonitorGUI extends XFrame{
|
||||
jfc.getXYPlot().setBackgroundPaint(Color.BLACK);
|
||||
jfc.getXYPlot().getRenderer().setSeriesPaint(0,Color.RED);
|
||||
jfc.getXYPlot().getRenderer().setSeriesPaint(1,Color.GREEN);
|
||||
changeFont(jfc);
|
||||
spdp = new JLabel();
|
||||
spdp.setBorder(new LineBorder(Color.DARK_GRAY));
|
||||
jp.add(spdp);
|
||||
@@ -88,8 +91,8 @@ public class LineMonitorGUI extends XFrame{
|
||||
tsce.addSeries(delayup);
|
||||
tsce.addSeries(delaydown);
|
||||
|
||||
tsce.addSeries(delayupmin);
|
||||
tsce.addSeries(delaydownmin);
|
||||
//tsce.addSeries(delayupmin);
|
||||
//tsce.addSeries(delaydownmin);
|
||||
jfce = ChartFactory.createTimeSeriesChart("Delay monitor", "Time(s)", "Delay(ms)", tsce);
|
||||
jfce.getXYPlot().getDomainAxis().setFixedAutoRange(5000);
|
||||
jfce.getXYPlot().setBackgroundPaint(Color.BLACK);
|
||||
@@ -97,10 +100,11 @@ public class LineMonitorGUI extends XFrame{
|
||||
jfce.getXYPlot().getRenderer().setSeriesPaint(1,Color.GREEN);
|
||||
|
||||
BasicStroke dotted = new BasicStroke(2, BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND, 0, new float[]{0,6,0,6}, 0);
|
||||
jfce.getXYPlot().getRenderer().setSeriesPaint(2,Color.RED);
|
||||
/*jfce.getXYPlot().getRenderer().setSeriesPaint(2,Color.RED);
|
||||
jfce.getXYPlot().getRenderer().setSeriesStroke(2, dotted);
|
||||
jfce.getXYPlot().getRenderer().setSeriesPaint(3,Color.GREEN);
|
||||
jfce.getXYPlot().getRenderer().setSeriesStroke(3, dotted);
|
||||
jfce.getXYPlot().getRenderer().setSeriesStroke(3, dotted);*/
|
||||
changeFont(jfce);
|
||||
delp = new JLabel();
|
||||
delp.setBorder(new LineBorder(Color.DARK_GRAY));
|
||||
jp.add(delp);
|
||||
@@ -118,6 +122,7 @@ public class LineMonitorGUI extends XFrame{
|
||||
vaddrs.setColumns(10);
|
||||
|
||||
JPanel panel_1 = new JPanel();
|
||||
panel_1.setOpaque(false);
|
||||
panel.add(panel_1);
|
||||
Dimension dms=new Dimension(140, 20);
|
||||
JButton btnNewButton = new JButton("Force disconnect");
|
||||
@@ -140,7 +145,7 @@ public class LineMonitorGUI extends XFrame{
|
||||
btnNewButton_1.setForeground(Color.GREEN);
|
||||
panel_1.add(btnNewButton_1);
|
||||
|
||||
JButton btnNewButton_2 = new JButton("Pressure test");
|
||||
/*JButton btnNewButton_2 = new JButton("Pressure test");
|
||||
btnNewButton_2.setPreferredSize(dms);
|
||||
btnNewButton_2.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -148,7 +153,15 @@ public class LineMonitorGUI extends XFrame{
|
||||
}
|
||||
});
|
||||
panel_1.add(btnNewButton_2);
|
||||
btnNewButton_2.setForeground(Color.BLUE);
|
||||
btnNewButton_2.setForeground(Color.BLUE);*/
|
||||
}
|
||||
private void changeFont(JFreeChart jfc2) {
|
||||
jfc2.getTitle().setFont(UIEnv.getFont().deriveFont(16.0f));
|
||||
jfc2.getLegend().setItemFont(UIEnv.getFont());
|
||||
jfc2.getXYPlot().getRangeAxis().setLabelFont(UIEnv.getFont());
|
||||
jfc2.getXYPlot().getRangeAxis().setTickLabelFont(UIEnv.getFont());
|
||||
jfc2.getXYPlot().getDomainAxis().setLabelFont(UIEnv.getFont());
|
||||
jfc2.getXYPlot().getDomainAxis().setTickLabelFont(UIEnv.getFont());
|
||||
}
|
||||
public void recordData() {
|
||||
if(isVisible()) {
|
||||
@@ -157,13 +170,13 @@ public class LineMonitorGUI extends XFrame{
|
||||
spddown.addOrUpdate(ms, tr.getMonitor().getInSpeed()/1024.0);
|
||||
|
||||
|
||||
Millisecond msu= new Millisecond(new Date(System.currentTimeMillis()-(System.nanoTime()- tr.getMonitor().getRecentPingNanoTime())/1000000L));
|
||||
delayup.addOrUpdate(msu, tr.getMonitor().getOutDelay()/1000000.0);
|
||||
delaydown.addOrUpdate(msu, tr.getMonitor().getInDelay()/1000000.0);
|
||||
//Millisecond msu= new Millisecond(new Date(System.currentTimeMillis()-(System.nanoTime()- tr.getMonitor().getRecentPingNanoTime())/1000000L));
|
||||
delayup.addOrUpdate(ms, (tr.getMonitor().getOutDelay()+tr.getMonitor().getQueueingDelay())/1000000.0);
|
||||
delaydown.addOrUpdate(ms, tr.getMonitor().getInDelay()/1000000.0);
|
||||
|
||||
//Millisecond msup= new Millisecond(new Date( tr.getMonitor().getUpdateDelayTime()+tr.getMonitor().getOutDelay()/1000000L));
|
||||
delayupmin.addOrUpdate(ms, tr.getMonitor().getOutDelayPredicted()/1000000.0);
|
||||
delaydownmin.addOrUpdate(ms, tr.getMonitor().getInDelayPredicted()/1000000.0);
|
||||
//delayupmin.addOrUpdate(ms, tr.getMonitor().getQueueingDelay()/1000000.0);
|
||||
//delaydownmin.addOrUpdate(ms, tr.getMonitor().getInDelayPredicted()/1000000.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,26 +191,33 @@ public class LineMonitorGUI extends XFrame{
|
||||
case MonitorData.ONLINE:
|
||||
getTitlelabel().setForeground(Color.GREEN);
|
||||
|
||||
recordData();
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(isVisible()) {
|
||||
//long ax=System.nanoTime();
|
||||
ImageIcon i1=new ImageIcon(jfc.createBufferedImage(spdp.getWidth(), spdp.getHeight()));
|
||||
ImageIcon i2=new ImageIcon(jfce.createBufferedImage(delp.getWidth(), delp.getHeight()));
|
||||
//System.out.println(System.nanoTime()-ax);
|
||||
spdp.setIcon(i1);
|
||||
delp.setIcon(i2);
|
||||
//spddown.fireSeriesChanged();
|
||||
//delaydown.fireSeriesChanged();
|
||||
|
||||
Inet6Address i6a= tr.getRemoteVaddr();
|
||||
if(i6a==null) {
|
||||
vaddrs.setText("unknown");
|
||||
Inet6AddressGroup irg=tr.getRemoteVaddr();
|
||||
String text;
|
||||
if(irg==null) {
|
||||
|
||||
text="unknown";
|
||||
}else {
|
||||
vaddrs.setText(i6a.getHostAddress());
|
||||
Inet6Address i6a= irg.getAddress();
|
||||
|
||||
text=i6a.getHostAddress();
|
||||
|
||||
}
|
||||
if(!vaddrs.getText().equals(text)) {
|
||||
vaddrs.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,298 @@
|
||||
package org.kne.cloud.network.klalb.ui;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
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.geom.Dimension2D;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.net.Inet6Address;
|
||||
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.JPanel;
|
||||
|
||||
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 JPanel {
|
||||
private KLALBRoutingProtocol routingProtocol;
|
||||
private Map<Inet6Address,GraphNode> nodes=new HashMap<Inet6Address,GraphNode>();
|
||||
private List<GraphEdgeGroup> edgeGroups=new ArrayList<GraphEdgeGroup>();
|
||||
private static final int nodesize=80;
|
||||
private class GraphNode{
|
||||
private String text;
|
||||
private Color color;
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
public GraphNode(String text, Color color, int x, int y) {
|
||||
super();
|
||||
this.text = text;
|
||||
this.color = color;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public GraphNode() {
|
||||
super();
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void paint(Graphics2D g) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.setStroke(new BasicStroke(2.0f));
|
||||
g.drawOval(x-nodesize/2, y-nodesize/2, nodesize, nodesize);
|
||||
g.setFont(UIEnv.getFont().deriveFont(10.0f));
|
||||
g.drawString(text, x+nodesize/2, y-nodesize/3);
|
||||
}
|
||||
}
|
||||
private class GraphEdge{
|
||||
private GraphNode from;
|
||||
private GraphNode to;
|
||||
private LinkDirection linkPath;
|
||||
|
||||
public GraphEdge(GraphNode nfrom, GraphNode nto,LinkDirection lp) {
|
||||
this.from=nfrom;
|
||||
this.to=nto;
|
||||
this.linkPath=lp;
|
||||
}
|
||||
|
||||
}
|
||||
private class GraphEdgeGroup{
|
||||
private static final double gap=3;
|
||||
private GraphNode nodeA,nodeB;
|
||||
private List<GraphEdge> edges=new ArrayList<>();
|
||||
|
||||
private boolean match(GraphNode a,GraphNode b) {
|
||||
if(a.equals( nodeA)&&b.equals( nodeB))
|
||||
return true;
|
||||
if(b.equals( nodeA)&&a.equals( nodeB))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public GraphEdgeGroup(GraphNode nodeA, GraphNode nodeB) {
|
||||
super();
|
||||
this.nodeA = nodeA;
|
||||
this.nodeB = nodeB;
|
||||
}
|
||||
public List<GraphEdge> getPaths() {
|
||||
return edges;
|
||||
}
|
||||
public void paint(Graphics2D g) {
|
||||
g.setStroke(new BasicStroke(1.0f));
|
||||
|
||||
Vector2 nodeAv=new Vector2(nodeA.getX(), nodeA.getY());
|
||||
Vector2 nodeBv=new Vector2(nodeB.getX(), nodeB.getY());
|
||||
Vector2 vecDir=nodeBv.subtract(nodeAv);
|
||||
Vector2 vecDirnor=vecDir.normalize();
|
||||
Vector2 vecR=vecDirnor.multi(nodesize/2);
|
||||
|
||||
Vector2 vec90nor=new Vector2( -vecDir.y, vecDir.x).normalize();
|
||||
|
||||
double width=gap*(edges.size()-1);
|
||||
|
||||
Vector2 startPoint=nodeAv.add(vecR).add(vec90nor.multi(width/2));
|
||||
Vector2 endPoint=nodeBv.subtract(vecR).add(vec90nor.multi(width/2));
|
||||
//System.out.println(width);
|
||||
for (Iterator<GraphEdge> iterator = edges.iterator(); iterator.hasNext();) {
|
||||
GraphEdge graphEdge = (GraphEdge) iterator.next();
|
||||
|
||||
//System.out.println(vec90nor);
|
||||
|
||||
g.setColor(KLALBUtils.getColorByLoadPercentage(graphEdge.linkPath.getSpeed()*100f/graphEdge.linkPath.getBandwidth()));
|
||||
|
||||
if(graphEdge.from.equals( nodeA)&&graphEdge.to.equals(nodeB) )
|
||||
drawAL((int)startPoint.x, (int)startPoint.y, (int)endPoint.x, (int)endPoint.y,g);
|
||||
|
||||
|
||||
if(graphEdge.to.equals( nodeA)&&graphEdge.from.equals(nodeB) )
|
||||
drawAL((int)endPoint.x, (int)endPoint.y, (int)startPoint.x, (int)startPoint.y,g);
|
||||
|
||||
startPoint=startPoint.subtract(vec90nor.multi(gap));
|
||||
endPoint=endPoint.subtract(vec90nor.multi(gap));
|
||||
}
|
||||
|
||||
//g.drawLine(nodeA.getX(), nodeA.getY(), nodeB.getX(), nodeB.getY());
|
||||
|
||||
}
|
||||
|
||||
public static void drawAL(int sx, int sy, int ex, int ey, Graphics2D g2)
|
||||
{
|
||||
|
||||
double H = 5; // 箭头高度
|
||||
double L = 2; // 底边的一半
|
||||
int x3 = 0;
|
||||
int y3 = 0;
|
||||
int x4 = 0;
|
||||
int y4 = 0;
|
||||
double awrad = Math.atan(L / H); // 箭头角度
|
||||
double arraow_len = Math.sqrt(L * L + H * H); // 箭头的长度
|
||||
double[] arrXY_1 = rotateVec(ex - sx, ey - sy, awrad, true, arraow_len);
|
||||
double[] arrXY_2 = rotateVec(ex - sx, ey - sy, -awrad, true, arraow_len);
|
||||
double x_3 = ex - arrXY_1[0]; // (x3,y3)是第一端点
|
||||
double y_3 = ey - arrXY_1[1];
|
||||
double x_4 = ex - arrXY_2[0]; // (x4,y4)是第二端点
|
||||
double y_4 = ey - arrXY_2[1];
|
||||
|
||||
Double X3 = new Double(x_3);
|
||||
x3 = X3.intValue();
|
||||
Double Y3 = new Double(y_3);
|
||||
y3 = Y3.intValue();
|
||||
Double X4 = new Double(x_4);
|
||||
x4 = X4.intValue();
|
||||
Double Y4 = new Double(y_4);
|
||||
y4 = Y4.intValue();
|
||||
// 画线
|
||||
g2.drawLine(sx, sy, ex, ey);
|
||||
//
|
||||
GeneralPath triangle = new GeneralPath();
|
||||
triangle.moveTo(ex, ey);
|
||||
triangle.lineTo(x3, y3);
|
||||
triangle.lineTo(x4, y4);
|
||||
triangle.closePath();
|
||||
//实心箭头
|
||||
g2.fill(triangle);
|
||||
//非实心箭头
|
||||
//g2.draw(triangle);
|
||||
|
||||
}
|
||||
|
||||
// 计算
|
||||
public static double[] rotateVec(int px, int py, double ang,
|
||||
boolean isChLen, double newLen) {
|
||||
|
||||
double mathstr[] = new double[2];
|
||||
// 矢量旋转函数,参数含义分别是x分量、y分量、旋转角、是否改变长度、新长度
|
||||
double vx = px * Math.cos(ang) - py * Math.sin(ang);
|
||||
double vy = px * Math.sin(ang) + py * Math.cos(ang);
|
||||
if (isChLen) {
|
||||
double d = Math.sqrt(vx * vx + vy * vy);
|
||||
vx = vx / d * newLen;
|
||||
vy = vy / d * newLen;
|
||||
mathstr[0] = vx;
|
||||
mathstr[1] = vy;
|
||||
}
|
||||
return mathstr;
|
||||
}
|
||||
|
||||
}
|
||||
public NetworkGraphPanel(KLALBRoutingProtocol routingProtocol) {
|
||||
super();
|
||||
this.routingProtocol = routingProtocol;
|
||||
//setSize(10000, 10000);
|
||||
//setPreferredSize(getSize());
|
||||
}
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
loadNodes();
|
||||
|
||||
Graphics2D g2d=(Graphics2D)g;
|
||||
|
||||
for (Iterator<GraphEdgeGroup> iterator = edgeGroups.iterator(); iterator.hasNext();) {
|
||||
GraphEdgeGroup graphNode = (GraphEdgeGroup) iterator.next();
|
||||
graphNode.paint(g2d);
|
||||
}
|
||||
|
||||
for (Iterator<GraphNode> iterator = nodes.values().iterator(); iterator.hasNext();) {
|
||||
GraphNode graphNode = (GraphNode) iterator.next();
|
||||
graphNode.paint(g2d);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Random r=new Random();
|
||||
private void loadNodes() {
|
||||
Map<Inet6Address, Long> addr= routingProtocol.getAddresses();
|
||||
Set<Inet6Address> ks=addr.keySet();
|
||||
for (Iterator<Inet6Address> iterator = ks.iterator(); iterator.hasNext();) {
|
||||
Inet6Address inet6Address = (Inet6Address) iterator.next();
|
||||
if(!nodes.containsKey(inet6Address))
|
||||
nodes.put(inet6Address,new GraphNode(inet6Address.getHostAddress(),Color.BLACK,r.nextInt(50,getWidth()-100),r.nextInt(50,getHeight()-50)));
|
||||
}
|
||||
Set<Inet6Address> kns=nodes.keySet();
|
||||
for (Iterator<Inet6Address> iterator = kns.iterator(); iterator.hasNext();) {
|
||||
Inet6Address inet6Address = (Inet6Address) iterator.next();
|
||||
if(!addr.containsKey(inet6Address)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
//System.out.println("------------------------------------");
|
||||
edgeGroups.clear();
|
||||
Map<Inet6Address, Set<LinkDirection>> addr1= routingProtocol.getPaths();
|
||||
Set<Entry<Inet6Address, Set<LinkDirection>>> salink=addr1.entrySet();
|
||||
for (Iterator<Entry<Inet6Address, Set<LinkDirection>>> iterator = salink.iterator(); iterator.hasNext();) {
|
||||
Entry<Inet6Address, Set<LinkDirection>> entry = (Entry<Inet6Address, Set<LinkDirection>>) iterator.next();
|
||||
Set<LinkDirection>lps=entry.getValue();
|
||||
for (Iterator<LinkDirection> iterator2 = lps.iterator(); iterator2.hasNext();) {
|
||||
LinkDirection linkPath = (LinkDirection) iterator2.next();
|
||||
//System.out.println(linkPath);
|
||||
GraphNode nfrom=nodes.get(linkPath.getFromLocator());
|
||||
GraphNode nto=nodes.get(linkPath.getToLocator());
|
||||
GraphEdgeGroup group=getGroup(nfrom, nto);
|
||||
group.getPaths().add(new GraphEdge(nfrom,nto,linkPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GraphEdgeGroup getGroup(GraphNode a,GraphNode b) {
|
||||
for (Iterator iterator = edgeGroups.iterator(); iterator.hasNext();) {
|
||||
GraphEdgeGroup graphEdgeGroup = (GraphEdgeGroup) iterator.next();
|
||||
if(graphEdgeGroup.match(a,b)) {
|
||||
return graphEdgeGroup;
|
||||
}
|
||||
}
|
||||
GraphEdgeGroup ng=new GraphEdgeGroup(a, b);
|
||||
edgeGroups.add(ng);
|
||||
return ng;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
package org.kne.cloud.network.klalb.ui;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JLabel;
|
||||
@@ -8,6 +8,7 @@ import java.awt.Color;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import org.kne.cloud.network.klalb.KLALBRemoteLine;
|
||||
import org.kne.cloud.network.monitor.MonitorData;
|
||||
|
||||
import java.awt.Font;
|
||||
+35
-13
@@ -1,4 +1,4 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
package org.kne.cloud.network.klalb.ui;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JLabel;
|
||||
@@ -9,10 +9,15 @@ import java.awt.Dimension;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.klalb.KLALBController;
|
||||
import org.kne.cloud.network.klalb.KLALBRemoteLine;
|
||||
import org.kne.cloud.network.klalb.KLALBUtils;
|
||||
import org.kne.cloud.network.monitor.MonitorData;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.Image;
|
||||
import java.awt.MenuItem;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -66,7 +71,7 @@ public class TPanel2 extends JPanel {
|
||||
/**
|
||||
* @wbp.parser.constructor
|
||||
*/
|
||||
public TPanel2(KLALBRemoteLine t) {
|
||||
public TPanel2(KLALBRemoteLine t,KLALBController kc) {
|
||||
this.tunnel = t;
|
||||
//setOpaque(false);
|
||||
setBackground(Color.WHITE);
|
||||
@@ -183,6 +188,19 @@ public class TPanel2 extends JPanel {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
mntmNewMenuItem3 = new JMenuItem("Try reconnect");
|
||||
popupMenu.add(mntmNewMenuItem3);
|
||||
mntmNewMenuItem3.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tunnel.reconnectImmediately();
|
||||
|
||||
}
|
||||
});
|
||||
mntmNewMenuItem3.setForeground(Color.GREEN);
|
||||
mntmNewMenuItem2 = new JMenuItem("Force disconnect");
|
||||
popupMenu.add(mntmNewMenuItem2);
|
||||
mntmNewMenuItem2.addActionListener(new ActionListener() {
|
||||
@@ -194,17 +212,21 @@ public class TPanel2 extends JPanel {
|
||||
});
|
||||
mntmNewMenuItem2.setForeground(Color.RED);
|
||||
|
||||
mntmNewMenuItem3 = new JMenuItem("Force reconnect");
|
||||
popupMenu.add(mntmNewMenuItem3);
|
||||
mntmNewMenuItem3.addActionListener(new ActionListener() {
|
||||
JMenuItem mi=new JMenuItem("Remove line");
|
||||
popupMenu.add(mi);
|
||||
mi.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tunnel.reconnectImmediately();
|
||||
|
||||
MultipurposeSocketAddress mtar=tunnel.getSocketAddress();
|
||||
if(mtar!=null) {
|
||||
kc.removeRemoteLines(mtar);
|
||||
}else {
|
||||
tunnel.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
mntmNewMenuItem3.setForeground(Color.GREEN);
|
||||
});
|
||||
mi.setForeground(Color.RED);
|
||||
|
||||
mdg=new LineMonitorGUI(t);
|
||||
addMouseListener(new MouseListener() {
|
||||
@@ -282,10 +304,10 @@ public class TPanel2 extends JPanel {
|
||||
|
||||
|
||||
private void updateText() {
|
||||
targup.setText(KLALBUtils. bytesUnit(tunnel.getMonitor().getOutTraffic()) + "\u2191 " + KLALBUtils. bytesUnit(tunnel.getMonitor().getOutSpeed()) + "/s\u2191 "+ String.format("%.1f", tunnel.getMonitor().getOutDelay()/1000000.0) + "ms");
|
||||
targdown.setText(KLALBUtils. bytesUnit(tunnel.getMonitor().getInTraffic()) + "\u2193 " + KLALBUtils. bytesUnit(tunnel.getMonitor().getInSpeed()) + "/s\u2193 " + String.format("%.1f", tunnel.getMonitor().getInDelay()/1000000.0) + "ms");
|
||||
targup.setText(KLALBUtils. bytesUnit(tunnel.getMonitor().getOutTraffic()) + "\u2191 " + KLALBUtils. bytesUnit(tunnel.getMonitor().getOutSpeedAvg()) + "/s\u2191 "+ String.format("%.1f", tunnel.getMonitor().getOutDelay()/1000000.0) + "ms");
|
||||
targdown.setText(KLALBUtils. bytesUnit(tunnel.getMonitor().getInTraffic()) + "\u2193 " + KLALBUtils. bytesUnit(tunnel.getMonitor().getInSpeedAvg()) + "/s\u2193 " + String.format("%.1f", tunnel.getMonitor().getInDelay()/1000000.0) + "ms");
|
||||
|
||||
if(tunnel.getMonitor().getOutSpeed()>2048||tunnel.getMonitor().getInSpeed()>2048) {
|
||||
if(tunnel.getMonitor().getOutSpeed()>4096||tunnel.getMonitor().getInSpeed()>4096) {
|
||||
lblNewLabel_2.setBackground(Color.ORANGE);
|
||||
}else {
|
||||
lblNewLabel_2.setBackground(Color.LIGHT_GRAY);
|
||||
@@ -327,7 +349,7 @@ public class TPanel2 extends JPanel {
|
||||
lblNewLabel_1.setBackground(Color.GREEN);
|
||||
|
||||
|
||||
Inet6Address unvar=tunnel.getRemoteVaddr();
|
||||
Inet6Address unvar=tunnel.getRemoteVaddr().getAddress();
|
||||
if(unvar==null) {
|
||||
this.vaddr.setText("unknown");
|
||||
}else {
|
||||
@@ -0,0 +1,144 @@
|
||||
package org.kne.cloud.network.klalb.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.PropertyResourceBundle;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JColorChooser;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import javax.swing.plaf.ColorChooserUI;
|
||||
public class UIEnv {
|
||||
private static Font font;
|
||||
private static Image icon ;
|
||||
private static Color defaultcolor=new Color(207,218,223);//new Color(207,218,223)
|
||||
private static Color selectedcolor=new Color(207/2,218/2,223/2);
|
||||
|
||||
private static ResourceBundle rsb;
|
||||
public static void setRsb(String xrsb) throws IOException {
|
||||
rsb=new PropertyResourceBundle(UIEnv.class.getResourceAsStream("/knemcl_"+xrsb+".properties"));
|
||||
}
|
||||
|
||||
public static void setRsb(ResourceBundle xrsb) {
|
||||
rsb=xrsb;
|
||||
}
|
||||
public static ResourceBundle getRsb() {
|
||||
if(rsb==null) {
|
||||
try {
|
||||
rsb=new PropertyResourceBundle(UIEnv.class.getResourceAsStream("/knemcl_en_US.properties"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return rsb;
|
||||
}
|
||||
//private static Color tpccolor=new Color(250,250,250,190);
|
||||
public static Color getDefaultcolor() {
|
||||
return defaultcolor;
|
||||
}
|
||||
public static void setDefaultColor(Color defaultcolor) {
|
||||
UIEnv.defaultcolor = defaultcolor;
|
||||
}
|
||||
|
||||
public static Color titlecolor=new Color(0,0,100,200);
|
||||
|
||||
public static Color backgroundcolor=new Color(0,0,100,255);
|
||||
public static Color getDefaultTitleColor() {
|
||||
return titlecolor;
|
||||
}
|
||||
|
||||
public static Color getDefaultBackgroundColor() {
|
||||
return backgroundcolor;
|
||||
}
|
||||
|
||||
public static Color getHalfTransparentDefaultColor() {
|
||||
return new Color(defaultcolor.getRed(), defaultcolor.getGreen(), defaultcolor.getBlue(), 210);
|
||||
}
|
||||
public static void inituie(){
|
||||
/*try {
|
||||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
|
||||
} catch (ClassNotFoundException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
} catch (UnsupportedLookAndFeelException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
font=new Font("微软雅黑",Font.PLAIN , 12);
|
||||
/*try {
|
||||
font = Font.createFont(Font.PLAIN, UIEnv.class.getResourceAsStream("/assets/SourceHanSansCN-Light.otf")).deriveFont(13f);
|
||||
} catch (FontFormatException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e1.printStackTrace();
|
||||
}*/
|
||||
|
||||
java.util.Enumeration keys = UIManager.getDefaults().keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
Object key = keys.nextElement();
|
||||
Object value = UIManager.get(key);
|
||||
if (value instanceof javax.swing.plaf.FontUIResource) {
|
||||
UIManager.put(key, font);
|
||||
}
|
||||
}
|
||||
icon=Toolkit.getDefaultToolkit().getImage(
|
||||
UIEnv.class.getResource("/assets/KLALB.png"));
|
||||
}
|
||||
public static void defbut(JButton start) {
|
||||
if(font==null)
|
||||
inituie();
|
||||
start.setBorderPainted(false);
|
||||
start.setForeground(Color.WHITE);
|
||||
start.setFont(font.deriveFont(Font.BOLD, 18));
|
||||
start.setBackground(defaultcolor);
|
||||
}
|
||||
public static void defbut(JButton start,int fontsize) {
|
||||
if(font==null)
|
||||
inituie();
|
||||
start.setBorderPainted(false);
|
||||
start.setForeground(Color.WHITE);
|
||||
start.setFont(font.deriveFont(Font.BOLD, fontsize));
|
||||
start.setBackground(defaultcolor);
|
||||
}
|
||||
public static Font getFont(){
|
||||
if(icon==null)
|
||||
inituie();
|
||||
return font;
|
||||
}
|
||||
public static Image getIcon(){
|
||||
if(icon==null)
|
||||
inituie();
|
||||
return icon;
|
||||
}
|
||||
|
||||
public static Color getSelectedcolor() {
|
||||
return selectedcolor;
|
||||
}
|
||||
public static void setSelectedcolor(Color selectedcolor) {
|
||||
UIEnv.selectedcolor = selectedcolor;
|
||||
}
|
||||
/*public static Color getHalfTransparentColor() {
|
||||
return tpccolor;
|
||||
}*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package org.kne.cloud.network.klalb.ui;
|
||||
|
||||
|
||||
public class Vector2 {
|
||||
public double x,y;
|
||||
|
||||
public Vector2(double x, double y) {
|
||||
super();
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Vector2 Set(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector2 normalize()//ʹ����Ϊ1����Ϊ��λ����
|
||||
{
|
||||
double l=Math.sqrt(x*x+y*y);
|
||||
return l==0?new Vector2(0,0): new Vector2(x / l, y / l);
|
||||
}
|
||||
public Vector2 normalizeold()//ʹ����Ϊ1����Ϊ��λ����
|
||||
{
|
||||
double l=Math.sqrt(x*x+y*y);
|
||||
if(l==0){
|
||||
x=y=0;
|
||||
}else{
|
||||
this.x = x / l;
|
||||
this.y = y / l;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Vector2 add(Vector2 vec)//��
|
||||
{
|
||||
|
||||
return new Vector2(this.x + vec.x,this.y + vec.y);
|
||||
}
|
||||
public Vector2 subtract(Vector2 vec)//��
|
||||
{
|
||||
return new Vector2(this.x - vec.x,this.y - vec.y);
|
||||
}
|
||||
public Vector2 multi(double m)//��������
|
||||
{
|
||||
return new Vector2(this.x*m, this.y*m);
|
||||
}
|
||||
public double dot(Vector2 vec)//�������
|
||||
{
|
||||
return vec.x*x + vec.y*y ;
|
||||
}
|
||||
public Vector2 opposite(){//�෴
|
||||
return new Vector2(-x, -y);
|
||||
}
|
||||
public Vector2 signs() {//��������
|
||||
return new Vector2(signs(x),signs(y));
|
||||
}
|
||||
|
||||
public static int signs(double z2) {
|
||||
return z2>0?1:(z2<0?-1:0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Vector2 rotate(Vector2 degree){
|
||||
|
||||
double sita=sita()+degree.sita();
|
||||
double l=Length();
|
||||
return new Vector2(l*Math.cos(sita), l*Math.sin(sita));
|
||||
}
|
||||
public Vector2 rotate(float degree){
|
||||
|
||||
double sita=sita()+degree;
|
||||
double l=Length();
|
||||
return new Vector2(l*Math.cos(sita), l*Math.sin(sita));
|
||||
}
|
||||
public float sita() {
|
||||
double sita;
|
||||
if(x<0){
|
||||
sita=Math.atan(y/x)-180;
|
||||
}else if(x>0){
|
||||
sita=Math.atan(y/x);
|
||||
}else{
|
||||
sita=y>=0?90:90-180;
|
||||
}
|
||||
return (float) sita;
|
||||
}
|
||||
public double Length() {
|
||||
|
||||
return Math.sqrt(x*x+y*y);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Vector2 [x="+x+", y="+y+"]";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user