@@ -10,11 +10,14 @@ import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.locks.LockSupport ;
import org.kne.cloud.clock.AdjustedNanoClock ;
import org.kne.cloud.clock.HighAccuracyClock ;
import org.kne.cloud.network.MultipurposeSocketAddress ;
import org.kne.cloud.network.SpeedLimiter ;
import org.kne.cloud.network.ThreadTool ;
import org.kne.cloud.network.ipv6.IPv6Packet ;
import org.kne.cloud.network.ipv6.Inet6AddressGroup ;
import org.kne.cloud.network.ipv6.PacketID ;
import org.kne.cloud.network.ipv6.PacketIDGenerator ;
import org.kne.cloud.network.ipv6.IPv6AddressGroup ;
import org.kne.cloud.network.klalb.ADDRPacket ;
import org.kne.cloud.network.klalb.ADDRREQPacket ;
import org.kne.cloud.network.klalb.BWINFPacket ;
@@ -28,7 +31,9 @@ import org.kne.cloud.network.klalb.VADDRACKPacket;
import org.kne.cloud.network.klalb.VADDRPacket ;
import org.kne.cloud.network.klalb.VADDRREQPacket ;
import org.kne.cloud.network.monitor.MonitorData ;
import org.kne.cloud.network.monitor.QueueingMonitorDataImpl ;
import org.kne.cloud.network.monitor.SpeedAndTrafficAndDelayMonitorDataImpl ;
import com.github.f4b6a3.uuid.UuidCreator ;
public class Kperf implements Runnable {
@@ -47,7 +52,7 @@ public class Kperf implements Runnable{
private MultipurposeSocketAddress bindAddress ;
private volatile boolean connected = false ;
private volatile KLALBPacketLink link ;
private QueueingMonitorDataImpl monitor = new QueueingMonitorDataImpl ( ) ;
private SpeedAndTrafficAndDelayMonitorDataImpl monitor = new SpeedAndTrafficAndDelayMonitorDataImpl ( HighAccuracyClock . SYSTEM_CLOCK ) ;
private volatile boolean closed = false ;
@@ -117,11 +122,11 @@ public class Kperf implements Runnable{
Thread . sleep ( 1000 ) ;
updateUsedTime ( ) ;
}
System . out . printf ( " 上传延迟 最小:%.3fms 平均:%.3fms 抖动:%.3fms \ n " , monitor . getOutDelayMin ( ) / 1000000 . 0 , monitor . getOutDelayAvg ( ) / 1000000 . 0 , monitor . getOutJitter ( ) / 1000000 . 0 ) ;
System . out . printf ( " 下载延迟 最小:%.3fms 平均:%.3fms 抖动:%.3fms \ n " , monitor . getInDelayMin ( ) / 1000000 . 0 , monitor . getInDelayAvg ( ) / 1000000 . 0 , monitor . getInJitter ( ) / 1000000 . 0 ) ;
System . out . printf ( " 上传延迟 最小:%.3fms 平均:%.3fms 抖动:%.3fms \ n " , monitor . getOutDelay ( ) / 1000000 . 0 , monitor . getOutDelay ( ) / 1000000 . 0 , monitor . getOutJitter ( ) / 1000000 . 0 ) ;
System . out . printf ( " 下载延迟 最小:%.3fms 平均:%.3fms 抖动:%.3fms \ n " , monitor . getInDelay ( ) / 1000000 . 0 , monitor . getInDelay ( ) / 1000000 . 0 , monitor . getInJitter ( ) / 1000000 . 0 ) ;
if ( reports ! = null ) {
monitor . setOutDelay ( monitor . getOutDelayAvg ( ) ) ;
monitor . setInDelay ( monitor . getInDelayAvg ( ) ) ;
reports . uploadDelayFinish ( monitor . getOutDelay ( ) ) ;
reports . downloadDelayFinish ( monitor . getInDelay ( ) ) ;
}
System . out . println ( " 等待时间 " + wtimes + " s " ) ;
Thread . sleep ( wtimes * 1000 ) ;
@@ -134,13 +139,13 @@ public class Kperf implements Runnable{
testPacket = new TESTNPacket ( 60000 ) ;
for ( int i = 0 ; i < 20 ; i + + ) {
System . out . printf ( " %.2fs \ t " , ( System . nanoTime ( ) - startTime ) / 1000000000 . 0 ) ;
System . out . printf ( " 下载带宽:%s/s \ n " , KLALBUtils . convertIBUint ( monitor . getInSpeedAvg ( ) ) ) ;
System . out . printf ( " 下载带宽:%s/s \ n " , KLALBUtils . convertIBUint ( monitor . getInSpeed ( ) ) ) ;
Thread . sleep ( 1000 ) ;
}
System . out . printf ( " 下载带宽 平均:%s/s 最大 : %s/s \ n " , KLALBUtils . convertIBUint ( monitor . getInSpeedAvg2 ( ) ) , KLALBUtils . convertIBUint ( monitor . getInSpeedMax2 ( ) ) ) ;
System . out . printf ( " 下载带宽:%s/s " , KLALBUtils . convertIBUint ( monitor . getInSpeed ( ) ) ) ;
if ( reports ! = null ) {
reports . downloadSpeedFinish ( monitor . getInSpeedAvg2 ( ) ) ;
reports . downloadSpeedFinish ( monitor . getInSpeed ( ) ) ;
}
} else {
System . out . println ( " 测试2/5:上传带宽测试 " ) ;
@@ -148,12 +153,12 @@ public class Kperf implements Runnable{
testPacket = new TESTNPacket ( 60000 ) ;
for ( int i = 0 ; i < 20 ; i + + ) {
System . out . printf ( " %.2fs \ t " , ( System . nanoTime ( ) - startTime ) / 1000000000 . 0 ) ;
System . out . printf ( " 上传带宽:%s/s \ n " , KLALBUtils . convertIBUint ( monitor . getOutSpeedAvg ( ) ) ) ;
System . out . printf ( " 上传带宽:%s/s \ n " , KLALBUtils . convertIBUint ( monitor . getOutSpeed ( ) ) ) ;
Thread . sleep ( 1000 ) ;
}
System . out . printf ( " 上传带宽 平均:%s/s 最大 : %s/s \ n " , KLALBUtils . convertIBUint ( monitor . getOutSpeedAvg2 ( ) ) , KLALBUtils . convertIBUint ( monitor . getOutSpeedMax2 ( ) ) ) ;
System . out . printf ( " 上传带宽:%s/s \ n " , KLALBUtils . convertIBUint ( monitor . getOutSpeed ( ) ) ) ;
if ( reports ! = null ) {
reports . uploadSpeedFinish ( monitor . getOutSpeedAvg2 ( ) ) ;
reports . uploadSpeedFinish ( monitor . getOutSpeed ( ) ) ;
}
}
System . out . println ( " 等待时间 " + wtimes + " s " ) ;
@@ -168,12 +173,12 @@ public class Kperf implements Runnable{
testPacket = new TESTNPacket ( 60000 ) ;
for ( int i = 0 ; i < 20 ; i + + ) {
System . out . printf ( " %.2fs \ t " , ( System . nanoTime ( ) - startTime ) / 1000000000 . 0 ) ;
System . out . printf ( " 上传带宽:%s/s \ n " , KLALBUtils . convertIBUint ( monitor . getOutSpeedAvg ( ) ) ) ;
System . out . printf ( " 上传带宽:%s/s \ n " , KLALBUtils . convertIBUint ( monitor . getOutSpeed ( ) ) ) ;
Thread . sleep ( 1000 ) ;
}
System . out . printf ( " 上传带宽 平均:%s/s 最大 : %s/s \ n " , KLALBUtils . convertIBUint ( monitor . getOutSpeedAvg2 ( ) ) , KLALBUtils . convertIBUint ( monitor . getOutSpeedMax2 ( ) ) ) ;
System . out . printf ( " 上传带宽:%s/s \ n " , KLALBUtils . convertIBUint ( monitor . getOutSpeed ( ) ) ) ;
if ( reports ! = null ) {
reports . uploadSpeedFinish ( monitor . getOutSpeedAvg2 ( ) ) ;
reports . uploadSpeedFinish ( monitor . getOutSpeed ( ) ) ;
}
} else {
System . out . println ( " 测试3/5:下载带宽测试 " ) ;
@@ -181,12 +186,12 @@ public class Kperf implements Runnable{
testPacket = new TESTNPacket ( 60000 ) ;
for ( int i = 0 ; i < 20 ; i + + ) {
System . out . printf ( " %.2fs \ t " , ( System . nanoTime ( ) - startTime ) / 1000000000 . 0 ) ;
System . out . printf ( " 下载带宽:%s/s \ n " , KLALBUtils . convertIBUint ( monitor . getInSpeedAvg ( ) ) ) ;
System . out . printf ( " 下载带宽:%s/s \ n " , KLALBUtils . convertIBUint ( monitor . getInSpeed ( ) ) ) ;
Thread . sleep ( 1000 ) ;
}
System . out . printf ( " 下载带宽 平均:%s/s 最大 : %s/s \ n " , KLALBUtils . convertIBUint ( monitor . getInSpeedAvg2 ( ) ) , KLALBUtils . convertIBUint ( monitor . getInSpeedMax2 ( ) ) ) ;
System . out . printf ( " 下载带宽:%s/s \ n " , KLALBUtils . convertIBUint ( monitor . getInSpeed ( ) ) ) ;
if ( reports ! = null ) {
reports . downloadSpeedFinish ( monitor . getInSpeedAvg2 ( ) ) ;
reports . downloadSpeedFinish ( monitor . getInSpeed ( ) ) ;
}
}
@@ -204,7 +209,7 @@ public class Kperf implements Runnable{
Thread . sleep ( 1000 ) ;
}
if ( reports ! = null ) {
reports . downloadPPSFinish ( monitor . getInPPSAvg ( ) ) ;
reports . downloadPPSFinish ( monitor . getInPPS ( ) ) ;
}
} else {
System . out . println ( " 测试4/5:上传包转发率测试 " ) ;
@@ -216,7 +221,7 @@ public class Kperf implements Runnable{
Thread . sleep ( 1000 ) ;
}
if ( reports ! = null ) {
reports . uploadPPSFinish ( monitor . getOutPPSAvg ( ) ) ;
reports . uploadPPSFinish ( monitor . getOutPPS ( ) ) ;
}
}
System . out . println ( " 等待时间 " + wtimes + " s " ) ;
@@ -234,7 +239,7 @@ public class Kperf implements Runnable{
}
if ( reports ! = null ) {
reports . uploadPPSFinish ( monitor . getOutPPSAvg ( ) ) ;
reports . uploadPPSFinish ( monitor . getOutPPS ( ) ) ;
}
} else {
System . out . println ( " 测试5/5:下载包转发率测试 " ) ;
@@ -246,7 +251,7 @@ public class Kperf implements Runnable{
Thread . sleep ( 1000 ) ;
}
if ( reports ! = null ) {
reports . downloadPPSFinish ( monitor . getInPPSAvg ( ) ) ;
reports . downloadPPSFinish ( monitor . getInPPS ( ) ) ;
}
}
@@ -264,7 +269,7 @@ public class Kperf implements Runnable{
}
} ) ;
try {
monitor . setState ( MonitorData . CONNECTING ) ;
monitor . setState ( MonitorData . UNSTABLE ) ;
if ( link = = null )
link = KLALBUtils . createKLALBPacketLink ( bindAddress , targetAddress , false , 20000 ) ;
@@ -281,10 +286,10 @@ public class Kperf implements Runnable{
// TimeDebugger tdb=new TimeDebugger();
// tdb.putTime("start");
if ( checkBandwidthReportTime ( ) ) {
writePacketToKPL ( new BWINFPacket ( monitor . getOutSpeedAvg ( ) , monitor . getInSpeedAvg ( ) ) ) ;
writePacketToKPL ( new BWINFPacket ( monitor . getOutSpeed ( ) , monitor . getInSpeed ( ) ) ) ;
}
if ( checkPingTimeSleep ( ) ) {
writePacketToKPL ( new PINGPacket ( System . nanoTime ( ) ) ) ;
writePacketToKPL ( new PINGPacket ( System . nanoTime ( ) , monitor . getOutSpeed ( ) , monitor . getInSpeed ( ) ) ) ;
} else {
KLALBPacket kpip = IsendDequeList . poll ( ) ;
@@ -329,13 +334,13 @@ public class Kperf implements Runnable{
}
switch ( kpp . getType ( ) ) {
case KLALBPacket . PING :
sendIPacket ( new PONGPacket ( ( ( PINGPacket ) kpp ) . getTime ( ) , kpp . getRcvtime ( ) , System . nanoTime ( ) ) ) ;
sendIPacket ( new PONGPacket ( ( ( PINGPacket ) kpp ) . getTime ( ) , kpp . getRcvtime ( ) , System . nanoTime ( ) , monitor . getOutSpeed ( ) , monitor . getInSpeed ( ) ) ) ;
break ;
case KLALBPacket . PONG :
if ( fst ) {
// coll.resetCoolingTime();
monitor . setState ( MonitorData . ONLINE ) ;
monitor . setState ( MonitorData . UP ) ;
connected = true ;
if ( targetAddress ! = null ) {
System . out . println ( " 连接地址 " + targetAddress + " 成功! " ) ;
@@ -379,9 +384,6 @@ public class Kperf implements Runnable{
}
if ( DsndDelayFactor > = 0 & & DrcvDelayFactor > = 0 ) {
monitor . setOutDelay ( DsndDelayFactor ) ;
monitor . setInDelay ( DrcvDelayFactor ) ;
monitor . setRecentPingNanoTime ( png . getTimepingsnd ( ) ) ;
//pingInterval = monitor.getLatencyAvg()+2000000L;
//double load = 1 - monitor.getOutDelayMin() / (double) monitor.getOutDelay();
@@ -409,13 +411,13 @@ public class Kperf implements Runnable{
Thread . yield ( ) ;
}
} catch ( IOException e ) {
if ( monitor . getState ( ) = = MonitorData . CONNECTING )
if ( monitor . getState ( ) = = MonitorData . UNSTABLE )
System . out . println ( " 连接目标地址失败! " ) ;
if ( debug )
e . printStackTrace ( ) ;
} finally {
monitor . setState ( MonitorData . OFFLINE ) ;
monitor . setState ( MonitorData . DOWN ) ;
if ( link ! = null ) {
try {
link . close ( ) ;
@@ -483,7 +485,7 @@ public class Kperf implements Runnable{
public void close ( ) {
closed = true ;
monitor . setState ( MonitorData . OFFLINE ) ;
monitor . setState ( MonitorData . DOWN ) ;
try {
if ( link ! = null )
link . close ( ) ;
@@ -504,7 +506,6 @@ public class Kperf implements Runnable{
LockSupport . unpark ( tlock ) ;
}
private KLALBPacket readPacketFromKPL ( ) throws IOException {
KLALBPacket packet = link . readKLALBPacket ( ) ;
if ( showpacket ) {
@@ -514,16 +515,14 @@ public class Kperf implements Runnable{
if ( packet ! = null ) {
packet . putTimePassport ( " received " ) ;
long length = packet . getTotalLength ( ) ;
monitor . getInTrafficAL ( ) . add ( length ) ;
monitor . getInPacketCounterAL ( ) . add ( 1 ) ;
monitor . getDownloadBandwidth ( ) . recordPacket ( KLALBUtils . createGlobalUUID ( ) , ( int ) length ) ;
}
return packet ;
}
private void writePacketToKPL ( KLALBPacket packet ) throws IOException {
long length = packet . getTotalLength ( ) ;
monitor . getOutTrafficAL ( ) . add ( length ) ;
monitor . getOutPacketCounterAL ( ) . add ( 1 ) ;
monitor . getUploadBandwidth ( ) . recordPacket ( KLALBUtils . createGlobalUUID ( ) , ( int ) length ) ;
link . writeKLALBPacket ( packet ) ;
link . flush ( ) ;
packet . putTimePassport ( " sended " ) ;